settings_gui.cpp

Go to the documentation of this file.
00001 /* $Id: settings_gui.cpp 23601 2011-12-19 20:50:21Z truebrain $ */
00002 
00003 /*
00004  * This file is part of OpenTTD.
00005  * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
00006  * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
00007  * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
00008  */
00009 
00012 #include "stdafx.h"
00013 #include "currency.h"
00014 #include "error.h"
00015 #include "gui.h"
00016 #include "textbuf_gui.h"
00017 #include "command_func.h"
00018 #include "screenshot.h"
00019 #include "network/network.h"
00020 #include "town.h"
00021 #include "settings_internal.h"
00022 #include "newgrf_townname.h"
00023 #include "strings_func.h"
00024 #include "window_func.h"
00025 #include "string_func.h"
00026 #include "widgets/dropdown_type.h"
00027 #include "widgets/dropdown_func.h"
00028 #include "highscore.h"
00029 #include "base_media_base.h"
00030 #include "company_base.h"
00031 #include "company_func.h"
00032 #include "viewport_func.h"
00033 #include "core/geometry_func.hpp"
00034 #include "ai/ai.hpp"
00035 #include "language.h"
00036 
00037 #include "widgets/settings_widget.h"
00038 
00039 #include "table/sprites.h"
00040 #include "table/strings.h"
00041 #include <map>
00042 
00043 static const StringID _units_dropdown[] = {
00044   STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL,
00045   STR_GAME_OPTIONS_MEASURING_UNITS_METRIC,
00046   STR_GAME_OPTIONS_MEASURING_UNITS_SI,
00047   INVALID_STRING_ID
00048 };
00049 
00050 static const StringID _driveside_dropdown[] = {
00051   STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT,
00052   STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT,
00053   INVALID_STRING_ID
00054 };
00055 
00056 static const StringID _autosave_dropdown[] = {
00057   STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
00058   STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH,
00059   STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS,
00060   STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS,
00061   STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS,
00062   INVALID_STRING_ID,
00063 };
00064 
00065 int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; 
00066 static StringID *_grf_names = NULL; 
00067 static int _nb_grf_names = 0;       
00068 
00070 void InitGRFTownGeneratorNames()
00071 {
00072   free(_grf_names);
00073   _grf_names = GetGRFTownNameList();
00074   _nb_grf_names = 0;
00075   for (StringID *s = _grf_names; *s != INVALID_STRING_ID; s++) _nb_grf_names++;
00076 }
00077 
00083 static inline StringID TownName(int town_name)
00084 {
00085   if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
00086   town_name -= _nb_orig_names;
00087   if (town_name < _nb_grf_names) return _grf_names[town_name];
00088   return STR_UNDEFINED;
00089 }
00090 
00095 static int GetCurRes()
00096 {
00097   int i;
00098 
00099   for (i = 0; i != _num_resolutions; i++) {
00100     if ((int)_resolutions[i].width == _screen.width &&
00101         (int)_resolutions[i].height == _screen.height) {
00102       break;
00103     }
00104   }
00105   return i;
00106 }
00107 
00108 static void ShowCustCurrency();
00109 
00110 template <class T>
00111 static DropDownList *BuiltSetDropDownList(int *selected_index)
00112 {
00113   int n = T::GetNumSets();
00114   *selected_index = T::GetIndexOfUsedSet();
00115 
00116   DropDownList *list = new DropDownList();
00117   for (int i = 0; i < n; i++) {
00118     list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i)));
00119   }
00120 
00121   return list;
00122 }
00123 
00124 struct GameOptionsWindow : Window {
00125   GameSettings *opt;
00126   bool reload;
00127 
00128   GameOptionsWindow(const WindowDesc *desc) : Window()
00129   {
00130     this->opt = &GetGameSettings();
00131     this->reload = false;
00132 
00133     this->InitNested(desc, WN_GAME_OPTIONS_GAME_OPTIONS);
00134     this->OnInvalidateData(0);
00135   }
00136 
00137   ~GameOptionsWindow()
00138   {
00139     DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
00140     if (this->reload) _switch_mode = SM_MENU;
00141   }
00142 
00149   DropDownList *BuildDropDownList(int widget, int *selected_index) const
00150   {
00151     DropDownList *list = NULL;
00152     switch (widget) {
00153       case WID_GO_CURRENCY_DROPDOWN: { // Setup currencies dropdown
00154         list = new DropDownList();
00155         *selected_index = this->opt->locale.currency;
00156         StringID *items = BuildCurrencyDropdown();
00157         uint disabled = _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies();
00158         int custom_index = -1;
00159 
00160         /* Add non-custom currencies; sorted naturally */
00161         for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00162           if (*items == STR_GAME_OPTIONS_CURRENCY_CUSTOM) {
00163             custom_index = i;
00164           } else {
00165             list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
00166           }
00167         }
00168         list->sort(DropDownListStringItem::NatSortFunc);
00169 
00170         /* Append custom currency at the end */
00171         if (custom_index >= 0) {
00172           list->push_back(new DropDownListItem(-1, false)); // separator line
00173           list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, custom_index, HasBit(disabled, custom_index)));
00174         }
00175         break;
00176       }
00177 
00178       case WID_GO_DISTANCE_DROPDOWN: { // Setup distance unit dropdown
00179         list = new DropDownList();
00180         *selected_index = this->opt->locale.units;
00181         const StringID *items = _units_dropdown;
00182         for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00183           list->push_back(new DropDownListStringItem(*items, i, false));
00184         }
00185         break;
00186       }
00187 
00188       case WID_GO_ROADSIDE_DROPDOWN: { // Setup road-side dropdown
00189         list = new DropDownList();
00190         *selected_index = this->opt->vehicle.road_side;
00191         const StringID *items = _driveside_dropdown;
00192         uint disabled = 0;
00193 
00194         /* You can only change the drive side if you are in the menu or ingame with
00195          * no vehicles present. In a networking game only the server can change it */
00196         extern bool RoadVehiclesAreBuilt();
00197         if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
00198           disabled = ~(1 << this->opt->vehicle.road_side); // disable the other value
00199         }
00200 
00201         for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00202           list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
00203         }
00204         break;
00205       }
00206 
00207       case WID_GO_TOWNNAME_DROPDOWN: { // Setup townname dropdown
00208         list = new DropDownList();
00209         *selected_index = this->opt->game_creation.town_name;
00210 
00211         int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
00212 
00213         /* Add and sort original townnames generators */
00214         for (int i = 0; i < _nb_orig_names; i++) {
00215           list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
00216         }
00217         list->sort(DropDownListStringItem::NatSortFunc);
00218 
00219         /* Add and sort newgrf townnames generators */
00220         DropDownList newgrf_names;
00221         for (int i = 0; i < _nb_grf_names; i++) {
00222           int result = _nb_orig_names + i;
00223           newgrf_names.push_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
00224         }
00225         newgrf_names.sort(DropDownListStringItem::NatSortFunc);
00226 
00227         /* Insert newgrf_names at the top of the list */
00228         if (newgrf_names.size() > 0) {
00229           newgrf_names.push_back(new DropDownListItem(-1, false)); // separator line
00230           list->splice(list->begin(), newgrf_names);
00231         }
00232         break;
00233       }
00234 
00235       case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
00236         list = new DropDownList();
00237         *selected_index = _settings_client.gui.autosave;
00238         const StringID *items = _autosave_dropdown;
00239         for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
00240           list->push_back(new DropDownListStringItem(*items, i, false));
00241         }
00242         break;
00243       }
00244 
00245       case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
00246         list = new DropDownList();
00247         for (uint i = 0; i < _languages.Length(); i++) {
00248           if (&_languages[i] == _current_language) *selected_index = i;
00249           list->push_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false));
00250         }
00251         list->sort(DropDownListStringItem::NatSortFunc);
00252         break;
00253       }
00254 
00255       case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
00256         list = new DropDownList();
00257         *selected_index = GetCurRes();
00258         for (int i = 0; i < _num_resolutions; i++) {
00259           list->push_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
00260         }
00261         break;
00262 
00263       case WID_GO_SCREENSHOT_DROPDOWN: // Setup screenshot format dropdown
00264         list = new DropDownList();
00265         *selected_index = _cur_screenshot_format;
00266         for (uint i = 0; i < _num_screenshot_formats; i++) {
00267           list->push_back(new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false));
00268         }
00269         break;
00270 
00271       case WID_GO_BASE_GRF_DROPDOWN:
00272         list = BuiltSetDropDownList<BaseGraphics>(selected_index);
00273         break;
00274 
00275       case WID_GO_BASE_SFX_DROPDOWN:
00276         list = BuiltSetDropDownList<BaseSounds>(selected_index);
00277         break;
00278 
00279       case WID_GO_BASE_MUSIC_DROPDOWN:
00280         list = BuiltSetDropDownList<BaseMusic>(selected_index);
00281         break;
00282 
00283       default:
00284         return NULL;
00285     }
00286 
00287     return list;
00288   }
00289 
00290   virtual void SetStringParameters(int widget) const
00291   {
00292     switch (widget) {
00293       case WID_GO_CURRENCY_DROPDOWN:   SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
00294       case WID_GO_DISTANCE_DROPDOWN:   SetDParam(0, STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL + this->opt->locale.units); break;
00295       case WID_GO_ROADSIDE_DROPDOWN:   SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
00296       case WID_GO_TOWNNAME_DROPDOWN:   SetDParam(0, TownName(this->opt->game_creation.town_name)); break;
00297       case WID_GO_AUTOSAVE_DROPDOWN:   SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
00298       case WID_GO_LANG_DROPDOWN:       SetDParamStr(0, _current_language->own_name); break;
00299       case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
00300       case WID_GO_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
00301       case WID_GO_BASE_GRF_DROPDOWN:   SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
00302       case WID_GO_BASE_GRF_STATUS:     SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
00303       case WID_GO_BASE_SFX_DROPDOWN:   SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
00304       case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
00305       case WID_GO_BASE_MUSIC_STATUS:   SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
00306     }
00307   }
00308 
00309   virtual void DrawWidget(const Rect &r, int widget) const
00310   {
00311     switch (widget) {
00312       case WID_GO_BASE_GRF_DESCRIPTION:
00313         SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00314         DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00315         break;
00316 
00317       case WID_GO_BASE_SFX_DESCRIPTION:
00318         SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00319         DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00320         break;
00321 
00322       case WID_GO_BASE_MUSIC_DESCRIPTION:
00323         SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
00324         DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
00325         break;
00326     }
00327   }
00328 
00329   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00330   {
00331     switch (widget) {
00332       case WID_GO_BASE_GRF_DESCRIPTION:
00333         /* Find the biggest description for the default size. */
00334         for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
00335           SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00336           size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00337         }
00338         break;
00339 
00340       case WID_GO_BASE_GRF_STATUS:
00341         /* Find the biggest description for the default size. */
00342         for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
00343           uint invalid_files = BaseGraphics::GetSet(i)->GetNumInvalid();
00344           if (invalid_files == 0) continue;
00345 
00346           SetDParam(0, invalid_files);
00347           *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_GRF_STATUS));
00348         }
00349         break;
00350 
00351       case WID_GO_BASE_SFX_DESCRIPTION:
00352         /* Find the biggest description for the default size. */
00353         for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
00354           SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00355           size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00356         }
00357         break;
00358 
00359       case WID_GO_BASE_MUSIC_DESCRIPTION:
00360         /* Find the biggest description for the default size. */
00361         for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
00362           SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
00363           size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
00364         }
00365         break;
00366 
00367       case WID_GO_BASE_MUSIC_STATUS:
00368         /* Find the biggest description for the default size. */
00369         for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
00370           uint invalid_files = BaseMusic::GetSet(i)->GetNumInvalid();
00371           if (invalid_files == 0) continue;
00372 
00373           SetDParam(0, invalid_files);
00374           *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_MUSIC_STATUS));
00375         }
00376         break;
00377 
00378       default: {
00379         int selected;
00380         DropDownList *list = this->BuildDropDownList(widget, &selected);
00381         if (list != NULL) {
00382           /* Find the biggest item for the default size. */
00383           for (DropDownList::iterator it = list->begin(); it != list->end(); it++) {
00384             static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM};
00385             Dimension string_dim;
00386             int width = (*it)->Width();
00387             string_dim.width = width + extra.width;
00388             string_dim.height = (*it)->Height(width) + extra.height;
00389             *size = maxdim(*size, string_dim);
00390             delete *it;
00391           }
00392           delete list;
00393         }
00394       }
00395     }
00396   }
00397 
00398   virtual void OnClick(Point pt, int widget, int click_count)
00399   {
00400     switch (widget) {
00401       case WID_GO_FULLSCREEN_BUTTON: // Click fullscreen on/off
00402         /* try to toggle full-screen on/off */
00403         if (!ToggleFullScreen(!_fullscreen)) {
00404           ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
00405         }
00406         this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
00407         this->SetDirty();
00408         break;
00409 
00410       default: {
00411         int selected;
00412         DropDownList *list = this->BuildDropDownList(widget, &selected);
00413         if (list != NULL) {
00414           ShowDropDownList(this, list, selected, widget);
00415         }
00416         break;
00417       }
00418     }
00419   }
00420 
00426   template <class T>
00427   void SetMediaSet(int index)
00428   {
00429     if (_game_mode == GM_MENU) {
00430       const char *name = T::GetSet(index)->name;
00431 
00432       free(T::ini_set);
00433       T::ini_set = strdup(name);
00434 
00435       T::SetSet(name);
00436       this->reload = true;
00437       this->InvalidateData();
00438     }
00439   }
00440 
00441   virtual void OnDropdownSelect(int widget, int index)
00442   {
00443     switch (widget) {
00444       case WID_GO_CURRENCY_DROPDOWN: // Currency
00445         if (index == CUSTOM_CURRENCY_ID) ShowCustCurrency();
00446         this->opt->locale.currency = index;
00447         ReInitAllWindows();
00448         break;
00449 
00450       case WID_GO_DISTANCE_DROPDOWN: // Measuring units
00451         this->opt->locale.units = index;
00452         MarkWholeScreenDirty();
00453         break;
00454 
00455       case WID_GO_ROADSIDE_DROPDOWN: // Road side
00456         if (this->opt->vehicle.road_side != index) { // only change if setting changed
00457           uint i;
00458           if (GetSettingFromName("vehicle.road_side", &i) == NULL) NOT_REACHED();
00459           SetSettingValue(i, index);
00460           MarkWholeScreenDirty();
00461         }
00462         break;
00463 
00464       case WID_GO_TOWNNAME_DROPDOWN: // Town names
00465         if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
00466           this->opt->game_creation.town_name = index;
00467           SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
00468         }
00469         break;
00470 
00471       case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
00472         _settings_client.gui.autosave = index;
00473         this->SetDirty();
00474         break;
00475 
00476       case WID_GO_LANG_DROPDOWN: // Change interface language
00477         ReadLanguagePack(&_languages[index]);
00478         DeleteWindowByClass(WC_QUERY_STRING);
00479         CheckForMissingGlyphs();
00480         UpdateAllVirtCoords();
00481         ReInitAllWindows();
00482         break;
00483 
00484       case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
00485         if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
00486           this->SetDirty();
00487         }
00488         break;
00489 
00490       case WID_GO_SCREENSHOT_DROPDOWN: // Change screenshot format
00491         SetScreenshotFormat(index);
00492         this->SetDirty();
00493         break;
00494 
00495       case WID_GO_BASE_GRF_DROPDOWN:
00496         this->SetMediaSet<BaseGraphics>(index);
00497         break;
00498 
00499       case WID_GO_BASE_SFX_DROPDOWN:
00500         this->SetMediaSet<BaseSounds>(index);
00501         break;
00502 
00503       case WID_GO_BASE_MUSIC_DROPDOWN:
00504         this->SetMediaSet<BaseMusic>(index);
00505         break;
00506     }
00507   }
00508 
00514   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00515   {
00516     if (!gui_scope) return;
00517     this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
00518 
00519     bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
00520     this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
00521 
00522     missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
00523     this->GetWidget<NWidgetCore>(WID_GO_BASE_MUSIC_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_MUSIC_STATUS, STR_NULL);
00524   }
00525 };
00526 
00527 static const NWidgetPart _nested_game_options_widgets[] = {
00528   NWidget(NWID_HORIZONTAL),
00529     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
00530     NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00531   EndContainer(),
00532   NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
00533     NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
00534       NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
00535         NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
00536           NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_CURRENCY_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
00537         EndContainer(),
00538         NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME, STR_NULL),
00539           NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_ROADSIDE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_TOOLTIP), SetFill(1, 0),
00540         EndContainer(),
00541         NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
00542           NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_AUTOSAVE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP), SetFill(1, 0),
00543         EndContainer(),
00544         NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL),
00545           NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_RESOLUTION_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_RESOLUTION_TOOLTIP), SetFill(1, 0), SetPadding(0, 0, 3, 0),
00546           NWidget(NWID_HORIZONTAL),
00547             NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
00548             NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
00549           EndContainer(),
00550         EndContainer(),
00551       EndContainer(),
00552 
00553       NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
00554         NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_MEASURING_UNITS_FRAME, STR_NULL),
00555           NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_DISTANCE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_MEASURING_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
00556         EndContainer(),
00557         NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL),
00558           NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_TOWNNAME_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_TOWN_NAMES_DROPDOWN_TOOLTIP), SetFill(1, 0),
00559         EndContainer(),
00560         NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
00561           NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_LANG_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0),
00562         EndContainer(),
00563         NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_SCREENSHOT_FORMAT, STR_NULL),
00564           NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_SCREENSHOT_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_SCREENSHOT_FORMAT_TOOLTIP), SetFill(1, 0),
00565         EndContainer(),
00566         NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1),
00567       EndContainer(),
00568     EndContainer(),
00569 
00570     NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
00571       NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00572         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
00573         NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
00574       EndContainer(),
00575       NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 0, 0),
00576     EndContainer(),
00577 
00578     NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10),
00579       NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00580         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP),
00581         NWidget(NWID_SPACER), SetFill(1, 0),
00582       EndContainer(),
00583       NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 0, 0),
00584     EndContainer(),
00585 
00586     NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10),
00587       NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
00588         NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP),
00589         NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
00590       EndContainer(),
00591       NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 0, 0),
00592     EndContainer(),
00593   EndContainer(),
00594 };
00595 
00596 static const WindowDesc _game_options_desc(
00597   WDP_CENTER, 0, 0,
00598   WC_GAME_OPTIONS, WC_NONE,
00599   WDF_UNCLICK_BUTTONS,
00600   _nested_game_options_widgets, lengthof(_nested_game_options_widgets)
00601 );
00602 
00604 void ShowGameOptions()
00605 {
00606   DeleteWindowByClass(WC_GAME_OPTIONS);
00607   new GameOptionsWindow(&_game_options_desc);
00608 }
00609 
00610 extern void StartupEconomy();
00611 
00612 void SetDifficultyLevel(int mode, DifficultySettings *gm_opt);
00613 
00614 class GameDifficultyWindow : public Window {
00615 private:
00616   /* Temporary holding place of values in the difficulty window until 'Save' is clicked */
00617   GameSettings opt_mod_temp;
00618 
00619 public:
00621   static const uint GAME_DIFFICULTY_NUM = 18;
00623   static const uint WIDGETS_PER_DIFFICULTY = 3;
00624 
00625   GameDifficultyWindow(const WindowDesc *desc) : Window()
00626   {
00627     this->InitNested(desc, WN_GAME_OPTIONS_GAME_DIFFICULTY);
00628 
00629     /* Setup disabled buttons when creating window
00630      * disable all other difficulty buttons during gameplay except for 'custom' */
00631     this->SetWidgetsDisabledState(_game_mode != GM_MENU,
00632       WID_GD_LVL_EASY,
00633       WID_GD_LVL_MEDIUM,
00634       WID_GD_LVL_HARD,
00635       WID_GD_LVL_CUSTOM,
00636       WIDGET_LIST_END);
00637     this->SetWidgetDisabledState(WID_GD_HIGHSCORE, _game_mode == GM_EDITOR || _networking); // highscore chart in multiplayer
00638     this->SetWidgetDisabledState(WID_GD_ACCEPT, _networking && !_network_server); // Save-button in multiplayer (and if client)
00639 
00640     /* Read data */
00641     this->OnInvalidateData(GOID_DIFFICULTY_CHANGED);
00642   }
00643 
00644   virtual void SetStringParameters(int widget) const
00645   {
00646     widget -= WID_GD_OPTIONS_START;
00647     if (widget < 0 || (widget % 3) != 2) return;
00648 
00649     widget /= 3;
00650 
00651     uint i;
00652     const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + widget;
00653     int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00654     SetDParam(0, sd->desc.val_str + value);
00655   }
00656 
00657   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
00658   {
00659     /* Only for the 'descriptions' */
00660     int index = widget - WID_GD_OPTIONS_START;
00661     if (index < 0 || (index % 3) != 2) return;
00662 
00663     index /= 3;
00664 
00665     uint i;
00666     const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + index;
00667     const SettingDescBase *sdb = &sd->desc;
00668 
00669     /* Get the string and try all strings from the smallest to the highest value */
00670     StringID str = this->GetWidget<NWidgetCore>(widget)->widget_data;
00671     for (int32 value = sdb->min; (uint32)value <= sdb->max; value += sdb->interval) {
00672       SetDParam(0, sdb->val_str + value);
00673       *size = maxdim(*size, GetStringBoundingBox(str));
00674     }
00675   }
00676 
00677   virtual void OnClick(Point pt, int widget, int click_count)
00678   {
00679     if (widget >= WID_GD_OPTIONS_START) {
00680       widget -= WID_GD_OPTIONS_START;
00681       if ((widget % 3) == 2) return;
00682 
00683       /* Don't allow clients to make any changes */
00684       if (_networking && !_network_server) return;
00685 
00686       uint i;
00687       const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i) + (widget / 3);
00688       const SettingDescBase *sdb = &sd->desc;
00689 
00690       int32 val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00691       if (widget % 3 == 1) {
00692         /* Increase button clicked */
00693         val = min(val + sdb->interval, (int32)sdb->max);
00694       } else {
00695         /* Decrease button clicked */
00696         val -= sdb->interval;
00697         val = max(val, sdb->min);
00698       }
00699 
00700       /* save value in temporary variable */
00701       WriteValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv, val);
00702       this->RaiseWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00703       SetDifficultyLevel(3, &this->opt_mod_temp.difficulty); // set difficulty level to custom
00704       this->LowerWidget(WID_GD_LVL_CUSTOM);
00705       this->InvalidateData();
00706 
00707       if (widget / 3 == 0 &&
00708           AI::GetInfoList()->size() == 0 &&
00709           this->opt_mod_temp.difficulty.max_no_competitors != 0) {
00710         ShowErrorMessage(STR_WARNING_NO_SUITABLE_AI, INVALID_STRING_ID, WL_CRITICAL);
00711       }
00712       return;
00713     }
00714 
00715     switch (widget) {
00716       case WID_GD_LVL_EASY:
00717       case WID_GD_LVL_MEDIUM:
00718       case WID_GD_LVL_HARD:
00719       case WID_GD_LVL_CUSTOM:
00720         /* temporarily change difficulty level */
00721         this->RaiseWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00722         SetDifficultyLevel(widget - WID_GD_LVL_EASY, &this->opt_mod_temp.difficulty);
00723         this->LowerWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00724         this->InvalidateData();
00725         break;
00726 
00727       case WID_GD_HIGHSCORE: // Highscore Table
00728         ShowHighscoreTable(this->opt_mod_temp.difficulty.diff_level, -1);
00729         break;
00730 
00731       case WID_GD_ACCEPT: { // Save button - save changes
00732         GameSettings *opt_ptr = &GetGameSettings();
00733 
00734         uint i;
00735         GetSettingFromName("difficulty.diff_level", &i);
00736         DoCommandP(0, i, this->opt_mod_temp.difficulty.diff_level, CMD_CHANGE_SETTING);
00737 
00738         const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00739         for (uint btn = 0; btn != GAME_DIFFICULTY_NUM; btn++, sd++) {
00740           int32 new_val = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00741           int32 cur_val = (int32)ReadValue(GetVariableAddress(opt_ptr, &sd->save), sd->save.conv);
00742           /* if setting has changed, change it */
00743           if (new_val != cur_val) {
00744             DoCommandP(0, i + btn, new_val, CMD_CHANGE_SETTING);
00745           }
00746         }
00747         delete this;
00748         /* If we are in the editor, we should reload the economy.
00749          * This way when you load a game, the max loan and interest rate
00750          * are loaded correctly. */
00751         if (_game_mode == GM_EDITOR) StartupEconomy();
00752         break;
00753       }
00754 
00755       case WID_GD_CANCEL: // Cancel button - close window, abandon changes
00756         delete this;
00757         break;
00758     }
00759   }
00760 
00766   virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
00767   {
00768     if (!gui_scope) return;
00769 
00770     if (data == GOID_DIFFICULTY_CHANGED) {
00771       /* Window was created or settings were changed on server. Reread everything. */
00772 
00773       /* Copy current settings (ingame or in intro) to temporary holding place
00774        * change that when setting stuff, copy back on clicking 'OK' */
00775       this->opt_mod_temp = GetGameSettings();
00776 
00777       this->LowerWidget(WID_GD_LVL_EASY + this->opt_mod_temp.difficulty.diff_level);
00778     }
00779 
00780     uint i;
00781     const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00782     for (i = 0; i < GAME_DIFFICULTY_NUM; i++, sd++) {
00783       const SettingDescBase *sdb = &sd->desc;
00784       /* skip deprecated difficulty options */
00785       if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
00786       int32 value = (int32)ReadValue(GetVariableAddress(&this->opt_mod_temp, &sd->save), sd->save.conv);
00787       bool disable = (sd->desc.flags & SGF_NEWGAME_ONLY) &&
00788           (_game_mode == GM_NORMAL ||
00789           (_game_mode == GM_EDITOR && (sd->desc.flags & SGF_SCENEDIT_TOO) == 0));
00790 
00791       this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 0, disable || sdb->min == value);
00792       this->SetWidgetDisabledState(WID_GD_OPTIONS_START + i * 3 + 1, disable || sdb->max == (uint32)value);
00793     }
00794   }
00795 };
00796 
00797 static NWidgetBase *MakeDifficultyOptionsWidgets(int *biggest_index)
00798 {
00799   NWidgetVertical *vert_desc = new NWidgetVertical;
00800 
00801   int widnum = WID_GD_OPTIONS_START;
00802   uint i, j;
00803   const SettingDesc *sd = GetSettingFromName("difficulty.max_no_competitors", &i);
00804 
00805   for (i = 0, j = 0; i < GameDifficultyWindow::GAME_DIFFICULTY_NUM; i++, sd++, widnum += GameDifficultyWindow::WIDGETS_PER_DIFFICULTY) {
00806     if (!SlIsObjectCurrentlyValid(sd->save.version_from, sd->save.version_to)) continue;
00807 
00808     NWidgetHorizontal *hor = new NWidgetHorizontal;
00809 
00810     /* [<] button. */
00811     NWidgetLeaf *leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum, AWV_DECREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
00812     hor->Add(leaf);
00813 
00814     /* [>] button. */
00815     leaf = new NWidgetLeaf(WWT_PUSHARROWBTN, COLOUR_YELLOW, widnum + 1, AWV_INCREASE, STR_TOOLTIP_HSCROLL_BAR_SCROLLS_LIST);
00816     hor->Add(leaf);
00817 
00818     /* Some spacing between the text and the description */
00819     NWidgetSpacer *spacer = new NWidgetSpacer(5, 0);
00820     hor->Add(spacer);
00821 
00822     /* Descriptive text. */
00823     leaf = new NWidgetLeaf(WWT_TEXT, COLOUR_YELLOW, widnum + 2, STR_DIFFICULTY_LEVEL_SETTING_MAXIMUM_NO_COMPETITORS + (j++), STR_NULL);
00824     leaf->SetFill(1, 0);
00825     hor->Add(leaf);
00826     vert_desc->Add(hor);
00827 
00828     /* Space vertically */
00829     vert_desc->Add(new NWidgetSpacer(0, 2));
00830   }
00831   *biggest_index = widnum - 1;
00832   return vert_desc;
00833 }
00834 
00835 
00837 static const NWidgetPart _nested_game_difficulty_widgets[] = {
00838   NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_DIFFICULTY_LEVEL_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
00839   NWidget(WWT_PANEL, COLOUR_MAUVE),
00840     NWidget(NWID_VERTICAL), SetPIP(2, 0, 2),
00841       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
00842         NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_EASY), SetDataTip(STR_DIFFICULTY_LEVEL_EASY, STR_NULL), SetFill(1, 0),
00843         NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_MEDIUM), SetDataTip(STR_DIFFICULTY_LEVEL_MEDIUM, STR_NULL), SetFill(1, 0),
00844         NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_HARD), SetDataTip(STR_DIFFICULTY_LEVEL_HARD, STR_NULL), SetFill(1, 0),
00845         NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GD_LVL_CUSTOM), SetDataTip(STR_DIFFICULTY_LEVEL_CUSTOM, STR_NULL), SetFill(1, 0),
00846       EndContainer(),
00847       NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 10),
00848         NWidget(WWT_PUSHTXTBTN, COLOUR_GREEN, WID_GD_HIGHSCORE), SetDataTip(STR_DIFFICULTY_LEVEL_HIGH_SCORE_BUTTON, STR_NULL), SetFill(1, 0),
00849       EndContainer(),
00850     EndContainer(),
00851   EndContainer(),
00852   NWidget(WWT_PANEL, COLOUR_MAUVE),
00853     NWidget(NWID_VERTICAL), SetPIP(3, 0, 1),
00854       NWidget(NWID_HORIZONTAL), SetPIP(5, 0, 5),
00855         NWidgetFunction(MakeDifficultyOptionsWidgets),
00856       EndContainer(),
00857     EndContainer(),
00858   EndContainer(),
00859   NWidget(WWT_PANEL, COLOUR_MAUVE),
00860     NWidget(NWID_VERTICAL), SetPIP(2, 0, 2),
00861       NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(10, 0, 10),
00862         NWidget(NWID_SPACER), SetFill(1, 0),
00863         NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GD_ACCEPT), SetDataTip(STR_DIFFICULTY_LEVEL_SAVE, STR_NULL), SetFill(1, 0),
00864         NWidget(WWT_PUSHTXTBTN, COLOUR_YELLOW, WID_GD_CANCEL), SetDataTip(STR_BUTTON_CANCEL, STR_NULL), SetFill(1, 0),
00865         NWidget(NWID_SPACER), SetFill(1, 0),
00866       EndContainer(),
00867     EndContainer(),
00868   EndContainer(),
00869 };
00870 
00872 static const WindowDesc _game_difficulty_desc(
00873   WDP_CENTER, 0, 0,
00874   WC_GAME_OPTIONS, WC_NONE,
00875   WDF_UNCLICK_BUTTONS,
00876   _nested_game_difficulty_widgets, lengthof(_nested_game_difficulty_widgets)
00877 );
00878 
00880 void ShowGameDifficulty()
00881 {
00882   DeleteWindowByClass(WC_GAME_OPTIONS);
00883   new GameDifficultyWindow(&_game_difficulty_desc);
00884 }
00885 
00886 static int SETTING_HEIGHT = 11;    
00887 static const int LEVEL_WIDTH = 15; 
00888 
00893 enum SettingEntryFlags {
00894   SEF_LEFT_DEPRESSED  = 0x01, 
00895   SEF_RIGHT_DEPRESSED = 0x02, 
00896   SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED), 
00897 
00898   SEF_LAST_FIELD = 0x04, 
00899 
00900   /* Entry kind */
00901   SEF_SETTING_KIND = 0x10, 
00902   SEF_SUBTREE_KIND = 0x20, 
00903   SEF_KIND_MASK    = (SEF_SETTING_KIND | SEF_SUBTREE_KIND), 
00904 };
00905 
00906 struct SettingsPage; // Forward declaration
00907 
00909 struct SettingEntrySubtree {
00910   SettingsPage *page; 
00911   bool folded;        
00912   StringID title;     
00913 };
00914 
00916 struct SettingEntrySetting {
00917   const char *name;           
00918   const SettingDesc *setting; 
00919   uint index;                 
00920 };
00921 
00923 struct SettingEntry {
00924   byte flags; 
00925   byte level; 
00926   union {
00927     SettingEntrySetting entry; 
00928     SettingEntrySubtree sub;   
00929   } d; 
00930 
00931   SettingEntry(const char *nm);
00932   SettingEntry(SettingsPage *sub, StringID title);
00933 
00934   void Init(byte level, bool last_field);
00935   void FoldAll();
00936   void SetButtons(byte new_val);
00937 
00938   uint Length() const;
00939   SettingEntry *FindEntry(uint row, uint *cur_row);
00940 
00941   uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row, uint parent_last);
00942 
00943 private:
00944   void DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int x, int y, int max_x, int state);
00945 };
00946 
00948 struct SettingsPage {
00949   SettingEntry *entries; 
00950   byte num;              
00951 
00952   void Init(byte level = 0);
00953   void FoldAll();
00954 
00955   uint Length() const;
00956   SettingEntry *FindEntry(uint row, uint *cur_row) const;
00957 
00958   uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, uint cur_row = 0, uint parent_last = 0) const;
00959 };
00960 
00961 
00962 /* == SettingEntry methods == */
00963 
00968 SettingEntry::SettingEntry(const char *nm)
00969 {
00970   this->flags = SEF_SETTING_KIND;
00971   this->level = 0;
00972   this->d.entry.name = nm;
00973   this->d.entry.setting = NULL;
00974   this->d.entry.index = 0;
00975 }
00976 
00982 SettingEntry::SettingEntry(SettingsPage *sub, StringID title)
00983 {
00984   this->flags = SEF_SUBTREE_KIND;
00985   this->level = 0;
00986   this->d.sub.page = sub;
00987   this->d.sub.folded = true;
00988   this->d.sub.title = title;
00989 }
00990 
00996 void SettingEntry::Init(byte level, bool last_field)
00997 {
00998   this->level = level;
00999   if (last_field) this->flags |= SEF_LAST_FIELD;
01000 
01001   switch (this->flags & SEF_KIND_MASK) {
01002     case SEF_SETTING_KIND:
01003       this->d.entry.setting = GetSettingFromName(this->d.entry.name, &this->d.entry.index);
01004       assert(this->d.entry.setting != NULL);
01005       break;
01006     case SEF_SUBTREE_KIND:
01007       this->d.sub.page->Init(level + 1);
01008       break;
01009     default: NOT_REACHED();
01010   }
01011 }
01012 
01014 void SettingEntry::FoldAll()
01015 {
01016   switch (this->flags & SEF_KIND_MASK) {
01017     case SEF_SETTING_KIND:
01018       break;
01019 
01020     case SEF_SUBTREE_KIND:
01021       this->d.sub.folded = true;
01022       this->d.sub.page->FoldAll();
01023       break;
01024 
01025     default: NOT_REACHED();
01026   }
01027 }
01028 
01029 
01035 void SettingEntry::SetButtons(byte new_val)
01036 {
01037   assert((new_val & ~SEF_BUTTONS_MASK) == 0); // Should not touch any flags outside the buttons
01038   this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
01039 }
01040 
01042 uint SettingEntry::Length() const
01043 {
01044   switch (this->flags & SEF_KIND_MASK) {
01045     case SEF_SETTING_KIND:
01046       return 1;
01047     case SEF_SUBTREE_KIND:
01048       if (this->d.sub.folded) return 1; // Only displaying the title
01049 
01050       return 1 + this->d.sub.page->Length(); // 1 extra row for the title
01051     default: NOT_REACHED();
01052   }
01053 }
01054 
01061 SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
01062 {
01063   if (row_num == *cur_row) return this;
01064 
01065   switch (this->flags & SEF_KIND_MASK) {
01066     case SEF_SETTING_KIND:
01067       (*cur_row)++;
01068       break;
01069     case SEF_SUBTREE_KIND:
01070       (*cur_row)++; // add one for row containing the title
01071       if (this->d.sub.folded) {
01072         break;
01073       }
01074 
01075       /* sub-page is visible => search it too */
01076       return this->d.sub.page->FindEntry(row_num, cur_row);
01077     default: NOT_REACHED();
01078   }
01079   return NULL;
01080 }
01081 
01108 uint SettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last)
01109 {
01110   if (cur_row >= max_row) return cur_row;
01111 
01112   bool rtl = _current_text_dir == TD_RTL;
01113   int offset = rtl ? -4 : 4;
01114   int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
01115 
01116   int x = rtl ? right : left;
01117   int y = base_y;
01118   if (cur_row >= first_row) {
01119     int colour = _colour_gradient[COLOUR_ORANGE][4];
01120     y = base_y + (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
01121 
01122     /* Draw vertical for parent nesting levels */
01123     for (uint lvl = 0; lvl < this->level; lvl++) {
01124       if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
01125       x += level_width;
01126     }
01127     /* draw own |- prefix */
01128     int halfway_y = y + SETTING_HEIGHT / 2;
01129     int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
01130     GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
01131     /* Small horizontal line from the last vertical line */
01132     GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
01133     x += level_width;
01134   }
01135 
01136   switch (this->flags & SEF_KIND_MASK) {
01137     case SEF_SETTING_KIND:
01138       if (cur_row >= first_row) {
01139         DrawSetting(settings_ptr, this->d.entry.setting, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK);
01140       }
01141       cur_row++;
01142       break;
01143     case SEF_SUBTREE_KIND:
01144       if (cur_row >= first_row) {
01145         DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
01146         DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
01147       }
01148       cur_row++;
01149       if (!this->d.sub.folded) {
01150         if (this->flags & SEF_LAST_FIELD) {
01151           assert(this->level < sizeof(parent_last));
01152           SetBit(parent_last, this->level); // Add own last-field state
01153         }
01154 
01155         cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last);
01156       }
01157       break;
01158     default: NOT_REACHED();
01159   }
01160   return cur_row;
01161 }
01162 
01163 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
01164 {
01165   if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01166     if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
01167       return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
01168     } else {
01169       return GetVariableAddress(&_settings_client.company, &sd->save);
01170     }
01171   } else {
01172     return GetVariableAddress(settings_ptr, &sd->save);
01173   }
01174 }
01175 
01185 void SettingEntry::DrawSetting(GameSettings *settings_ptr, const SettingDesc *sd, int left, int right, int y, int state)
01186 {
01187   const SettingDescBase *sdb = &sd->desc;
01188   const void *var = ResolveVariableAddress(settings_ptr, sd);
01189   bool editable = true;
01190   bool disabled = false;
01191 
01192   bool rtl = _current_text_dir == TD_RTL;
01193   uint buttons_left = rtl ? right - 19 : left;
01194   uint text_left  = left + (rtl ? 0 : 25);
01195   uint text_right = right - (rtl ? 25 : 0);
01196   uint button_y = y + (SETTING_HEIGHT - 11) / 2;
01197 
01198   /* We do not allow changes of some items when we are a client in a networkgame */
01199   if (!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sdb->flags & SGF_PER_COMPANY)) editable = false;
01200   if ((sdb->flags & SGF_NETWORK_ONLY) && !_networking) editable = false;
01201   if ((sdb->flags & SGF_NO_NETWORK) && _networking) editable = false;
01202 
01203   if (sdb->cmd == SDT_BOOLX) {
01204     static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
01205     /* Draw checkbox for boolean-value either on/off */
01206     bool on = ReadValue(var, sd->save.conv) != 0;
01207 
01208     DrawFrameRect(buttons_left, button_y, buttons_left + 19, button_y + 8, _bool_ctabs[!!on][!!editable], on ? FR_LOWERED : FR_NONE);
01209     SetDParam(0, on ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
01210   } else {
01211     int32 value;
01212 
01213     value = (int32)ReadValue(var, sd->save.conv);
01214 
01215     /* Draw [<][>] boxes for settings of an integer-type */
01216     DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state, editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
01217 
01218     disabled = (value == 0) && (sdb->flags & SGF_0ISDISABLED);
01219     if (disabled) {
01220       SetDParam(0, STR_CONFIG_SETTING_DISABLED);
01221     } else {
01222       if (sdb->flags & SGF_CURRENCY) {
01223         SetDParam(0, STR_JUST_CURRENCY_LONG);
01224       } else if (sdb->flags & SGF_MULTISTRING) {
01225         SetDParam(0, sdb->val_str - sdb->min + value);
01226       } else {
01227         SetDParam(0, (sdb->flags & SGF_NOCOMMA) ? STR_JUST_INT : STR_JUST_COMMA);
01228       }
01229       SetDParam(1, value);
01230     }
01231   }
01232   DrawString(text_left, text_right, y, (sdb->str) + disabled);
01233 }
01234 
01235 
01236 /* == SettingsPage methods == */
01237 
01242 void SettingsPage::Init(byte level)
01243 {
01244   for (uint field = 0; field < this->num; field++) {
01245     this->entries[field].Init(level, field + 1 == num);
01246   }
01247 }
01248 
01250 void SettingsPage::FoldAll()
01251 {
01252   for (uint field = 0; field < this->num; field++) {
01253     this->entries[field].FoldAll();
01254   }
01255 }
01256 
01258 uint SettingsPage::Length() const
01259 {
01260   uint length = 0;
01261   for (uint field = 0; field < this->num; field++) {
01262     length += this->entries[field].Length();
01263   }
01264   return length;
01265 }
01266 
01273 SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
01274 {
01275   SettingEntry *pe = NULL;
01276 
01277   for (uint field = 0; field < this->num; field++) {
01278     pe = this->entries[field].FindEntry(row_num, cur_row);
01279     if (pe != NULL) {
01280       break;
01281     }
01282   }
01283   return pe;
01284 }
01285 
01303 uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, uint cur_row, uint parent_last) const
01304 {
01305   if (cur_row >= max_row) return cur_row;
01306 
01307   for (uint i = 0; i < this->num; i++) {
01308     cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last);
01309     if (cur_row >= max_row) {
01310       break;
01311     }
01312   }
01313   return cur_row;
01314 }
01315 
01316 
01317 static SettingEntry _settings_ui_display[] = {
01318   SettingEntry("gui.date_format_in_default_names"),
01319   SettingEntry("gui.population_in_label"),
01320   SettingEntry("gui.measure_tooltip"),
01321   SettingEntry("gui.loading_indicators"),
01322   SettingEntry("gui.liveries"),
01323   SettingEntry("gui.show_track_reservation"),
01324   SettingEntry("gui.expenses_layout"),
01325   SettingEntry("gui.smallmap_land_colour"),
01326   SettingEntry("gui.zoom_min"),
01327   SettingEntry("gui.zoom_max"),
01328   SettingEntry("gui.graph_line_thickness"),
01329 };
01331 static SettingsPage _settings_ui_display_page = {_settings_ui_display, lengthof(_settings_ui_display)};
01332 
01333 static SettingEntry _settings_ui_interaction[] = {
01334   SettingEntry("gui.window_snap_radius"),
01335   SettingEntry("gui.window_soft_limit"),
01336   SettingEntry("gui.link_terraform_toolbar"),
01337   SettingEntry("gui.prefer_teamchat"),
01338   SettingEntry("gui.autoscroll"),
01339   SettingEntry("gui.reverse_scroll"),
01340   SettingEntry("gui.smooth_scroll"),
01341   SettingEntry("gui.left_mouse_btn_scrolling"),
01342   /* While the horizontal scrollwheel scrolling is written as general code, only
01343    *  the cocoa (OSX) driver generates input for it.
01344    *  Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
01345   SettingEntry("gui.scrollwheel_scrolling"),
01346   SettingEntry("gui.scrollwheel_multiplier"),
01347 #ifdef __APPLE__
01348   /* We might need to emulate a right mouse button on mac */
01349   SettingEntry("gui.right_mouse_btn_emulation"),
01350 #endif
01351 };
01353 static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)};
01354 
01355 static SettingEntry _settings_ui[] = {
01356   SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS),
01357   SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION),
01358   SettingEntry("gui.show_finances"),
01359   SettingEntry("gui.errmsg_duration"),
01360   SettingEntry("gui.hover_delay"),
01361   SettingEntry("gui.toolbar_pos"),
01362   SettingEntry("gui.statusbar_pos"),
01363   SettingEntry("gui.newgrf_default_palette"),
01364   SettingEntry("gui.pause_on_newgame"),
01365   SettingEntry("gui.advanced_vehicle_list"),
01366   SettingEntry("gui.timetable_in_ticks"),
01367   SettingEntry("gui.timetable_arrival_departure"),
01368   SettingEntry("gui.quick_goto"),
01369   SettingEntry("gui.default_rail_type"),
01370   SettingEntry("gui.disable_unsuitable_building"),
01371   SettingEntry("gui.persistent_buildingtools"),
01372   SettingEntry("gui.coloured_news_year"),
01373 };
01375 static SettingsPage _settings_ui_page = {_settings_ui, lengthof(_settings_ui)};
01376 
01377 static SettingEntry _settings_construction_signals[] = {
01378   SettingEntry("construction.signal_side"),
01379   SettingEntry("gui.enable_signal_gui"),
01380   SettingEntry("gui.drag_signals_density"),
01381   SettingEntry("gui.semaphore_build_before"),
01382   SettingEntry("gui.default_signal_type"),
01383   SettingEntry("gui.cycle_signal_types"),
01384 };
01386 static SettingsPage _settings_construction_signals_page = {_settings_construction_signals, lengthof(_settings_construction_signals)};
01387 
01388 static SettingEntry _settings_construction[] = {
01389   SettingEntry(&_settings_construction_signals_page, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS),
01390   SettingEntry("construction.build_on_slopes"),
01391   SettingEntry("construction.autoslope"),
01392   SettingEntry("construction.extra_dynamite"),
01393   SettingEntry("construction.max_bridge_length"),
01394   SettingEntry("construction.max_tunnel_length"),
01395   SettingEntry("station.never_expire_airports"),
01396   SettingEntry("construction.freeform_edges"),
01397   SettingEntry("construction.extra_tree_placement"),
01398   SettingEntry("construction.command_pause_level"),
01399 };
01401 static SettingsPage _settings_construction_page = {_settings_construction, lengthof(_settings_construction)};
01402 
01403 static SettingEntry _settings_stations_cargo[] = {
01404   SettingEntry("order.improved_load"),
01405   SettingEntry("order.gradual_loading"),
01406   SettingEntry("order.selectgoods"),
01407 };
01409 static SettingsPage _settings_stations_cargo_page = {_settings_stations_cargo, lengthof(_settings_stations_cargo)};
01410 
01411 static SettingEntry _settings_stations[] = {
01412   SettingEntry(&_settings_stations_cargo_page, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING),
01413   SettingEntry("station.adjacent_stations"),
01414   SettingEntry("station.distant_join_stations"),
01415   SettingEntry("station.station_spread"),
01416   SettingEntry("economy.station_noise_level"),
01417   SettingEntry("station.modified_catchment"),
01418   SettingEntry("construction.road_stop_on_town_road"),
01419   SettingEntry("construction.road_stop_on_competitor_road"),
01420 };
01422 static SettingsPage _settings_stations_page = {_settings_stations, lengthof(_settings_stations)};
01423 
01424 static SettingEntry _settings_economy_towns[] = {
01425   SettingEntry("economy.bribe"),
01426   SettingEntry("economy.exclusive_rights"),
01427   SettingEntry("economy.fund_roads"),
01428   SettingEntry("economy.fund_buildings"),
01429   SettingEntry("economy.town_layout"),
01430   SettingEntry("economy.allow_town_roads"),
01431   SettingEntry("economy.allow_town_level_crossings"),
01432   SettingEntry("economy.found_town"),
01433   SettingEntry("economy.mod_road_rebuild"),
01434   SettingEntry("economy.town_growth_rate"),
01435   SettingEntry("economy.larger_towns"),
01436   SettingEntry("economy.initial_city_size"),
01437 };
01439 static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
01440 
01441 static SettingEntry _settings_economy_industries[] = {
01442   SettingEntry("construction.raw_industry_construction"),
01443   SettingEntry("construction.industry_platform"),
01444   SettingEntry("economy.multiple_industry_per_town"),
01445   SettingEntry("game_creation.oil_refinery_limit"),
01446 };
01448 static SettingsPage _settings_economy_industries_page = {_settings_economy_industries, lengthof(_settings_economy_industries)};
01449 
01450 static SettingEntry _settings_economy_scripts[] = {
01451   SettingEntry("script.script_max_opcode_till_suspend"),
01452 };
01454 static SettingsPage _settings_economy_scripts_page = {_settings_economy_scripts, lengthof(_settings_economy_scripts)};
01455 
01456 static SettingEntry _settings_economy[] = {
01457   SettingEntry(&_settings_economy_towns_page, STR_CONFIG_SETTING_ECONOMY_TOWNS),
01458   SettingEntry(&_settings_economy_industries_page, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES),
01459   SettingEntry(&_settings_economy_scripts_page, STR_CONFIG_SETTING_ECONOMY_SCRIPTS),
01460   SettingEntry("economy.inflation"),
01461   SettingEntry("economy.smooth_economy"),
01462   SettingEntry("economy.feeder_payment_share"),
01463   SettingEntry("economy.infrastructure_maintenance"),
01464 };
01466 static SettingsPage _settings_economy_page = {_settings_economy, lengthof(_settings_economy)};
01467 
01468 static SettingEntry _settings_ai_npc[] = {
01469   SettingEntry("ai.ai_in_multiplayer"),
01470   SettingEntry("ai.ai_disable_veh_train"),
01471   SettingEntry("ai.ai_disable_veh_roadveh"),
01472   SettingEntry("ai.ai_disable_veh_aircraft"),
01473   SettingEntry("ai.ai_disable_veh_ship"),
01474 };
01476 static SettingsPage _settings_ai_npc_page = {_settings_ai_npc, lengthof(_settings_ai_npc)};
01477 
01478 static SettingEntry _settings_ai[] = {
01479   SettingEntry(&_settings_ai_npc_page, STR_CONFIG_SETTING_AI_NPC),
01480   SettingEntry("economy.give_money"),
01481   SettingEntry("economy.allow_shares"),
01482 };
01484 static SettingsPage _settings_ai_page = {_settings_ai, lengthof(_settings_ai)};
01485 
01486 static SettingEntry _settings_vehicles_routing[] = {
01487   SettingEntry("pf.pathfinder_for_trains"),
01488   SettingEntry("pf.forbid_90_deg"),
01489   SettingEntry("pf.pathfinder_for_roadvehs"),
01490   SettingEntry("pf.roadveh_queue"),
01491   SettingEntry("pf.pathfinder_for_ships"),
01492 };
01494 static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
01495 
01496 static SettingEntry _settings_vehicles_autorenew[] = {
01497   SettingEntry("company.engine_renew"),
01498   SettingEntry("company.engine_renew_months"),
01499   SettingEntry("company.engine_renew_money"),
01500 };
01502 static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
01503 
01504 static SettingEntry _settings_vehicles_servicing[] = {
01505   SettingEntry("vehicle.servint_ispercent"),
01506   SettingEntry("vehicle.servint_trains"),
01507   SettingEntry("vehicle.servint_roadveh"),
01508   SettingEntry("vehicle.servint_ships"),
01509   SettingEntry("vehicle.servint_aircraft"),
01510   SettingEntry("order.no_servicing_if_no_breakdowns"),
01511   SettingEntry("order.serviceathelipad"),
01512 };
01514 static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)};
01515 
01516 static SettingEntry _settings_vehicles_trains[] = {
01517   SettingEntry("pf.reverse_at_signals"),
01518   SettingEntry("vehicle.train_acceleration_model"),
01519   SettingEntry("vehicle.train_slope_steepness"),
01520   SettingEntry("vehicle.max_train_length"),
01521   SettingEntry("vehicle.wagon_speed_limits"),
01522   SettingEntry("vehicle.disable_elrails"),
01523   SettingEntry("vehicle.freight_trains"),
01524   SettingEntry("gui.stop_location"),
01525 };
01527 static SettingsPage _settings_vehicles_trains_page = {_settings_vehicles_trains, lengthof(_settings_vehicles_trains)};
01528 
01529 static SettingEntry _settings_vehicles[] = {
01530   SettingEntry(&_settings_vehicles_routing_page, STR_CONFIG_SETTING_VEHICLES_ROUTING),
01531   SettingEntry(&_settings_vehicles_autorenew_page, STR_CONFIG_SETTING_VEHICLES_AUTORENEW),
01532   SettingEntry(&_settings_vehicles_servicing_page, STR_CONFIG_SETTING_VEHICLES_SERVICING),
01533   SettingEntry(&_settings_vehicles_trains_page, STR_CONFIG_SETTING_VEHICLES_TRAINS),
01534   SettingEntry("gui.new_nonstop"),
01535   SettingEntry("gui.order_review_system"),
01536   SettingEntry("gui.vehicle_income_warn"),
01537   SettingEntry("gui.lost_vehicle_warn"),
01538   SettingEntry("vehicle.never_expire_vehicles"),
01539   SettingEntry("vehicle.max_trains"),
01540   SettingEntry("vehicle.max_roadveh"),
01541   SettingEntry("vehicle.max_aircraft"),
01542   SettingEntry("vehicle.max_ships"),
01543   SettingEntry("vehicle.plane_speed"),
01544   SettingEntry("vehicle.plane_crashes"),
01545   SettingEntry("vehicle.dynamic_engines"),
01546   SettingEntry("vehicle.roadveh_acceleration_model"),
01547   SettingEntry("vehicle.roadveh_slope_steepness"),
01548   SettingEntry("vehicle.smoke_amount"),
01549 };
01551 static SettingsPage _settings_vehicles_page = {_settings_vehicles, lengthof(_settings_vehicles)};
01552 
01553 static SettingEntry _settings_main[] = {
01554   SettingEntry(&_settings_ui_page,           STR_CONFIG_SETTING_GUI),
01555   SettingEntry(&_settings_construction_page, STR_CONFIG_SETTING_CONSTRUCTION),
01556   SettingEntry(&_settings_vehicles_page,     STR_CONFIG_SETTING_VEHICLES),
01557   SettingEntry(&_settings_stations_page,     STR_CONFIG_SETTING_STATIONS),
01558   SettingEntry(&_settings_economy_page,      STR_CONFIG_SETTING_ECONOMY),
01559   SettingEntry(&_settings_ai_page,           STR_CONFIG_SETTING_AI),
01560 };
01561 
01563 static SettingsPage _settings_main_page = {_settings_main, lengthof(_settings_main)};
01564 
01565 struct GameSettingsWindow : Window {
01566   static const int SETTINGTREE_LEFT_OFFSET   = 5; 
01567   static const int SETTINGTREE_RIGHT_OFFSET  = 5; 
01568   static const int SETTINGTREE_TOP_OFFSET    = 5; 
01569   static const int SETTINGTREE_BOTTOM_OFFSET = 5; 
01570 
01571   static GameSettings *settings_ptr;  
01572 
01573   SettingEntry *valuewindow_entry; 
01574   SettingEntry *clicked_entry; 
01575 
01576   Scrollbar *vscroll;
01577 
01578   GameSettingsWindow(const WindowDesc *desc) : Window()
01579   {
01580     static bool first_time = true;
01581 
01582     settings_ptr = &GetGameSettings();
01583 
01584     /* Build up the dynamic settings-array only once per OpenTTD session */
01585     if (first_time) {
01586       _settings_main_page.Init();
01587       first_time = false;
01588     } else {
01589       _settings_main_page.FoldAll(); // Close all sub-pages
01590     }
01591 
01592     this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
01593     this->clicked_entry = NULL; // No numeric setting buttons are depressed
01594 
01595     this->CreateNestedTree(desc);
01596     this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
01597     this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
01598 
01599     this->vscroll->SetCount(_settings_main_page.Length());
01600   }
01601 
01602   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
01603   {
01604     if (widget != WID_GS_OPTIONSPANEL) return;
01605 
01606     resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1);
01607     resize->width  = 1;
01608 
01609     size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET;
01610   }
01611 
01612   virtual void DrawWidget(const Rect &r, int widget) const
01613   {
01614     if (widget != WID_GS_OPTIONSPANEL) return;
01615 
01616     _settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
01617         this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity());
01618   }
01619 
01620   virtual void OnClick(Point pt, int widget, int click_count)
01621   {
01622     if (widget != WID_GS_OPTIONSPANEL) return;
01623 
01624     uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET - 1);
01625     if (btn == INT_MAX) return;
01626 
01627     uint cur_row = 0;
01628     SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
01629 
01630     if (pe == NULL) return;  // Clicked below the last setting of the page
01631 
01632     int x = (_current_text_dir == TD_RTL ? this->width - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH;  // Shift x coordinate
01633     if (x < 0) return;  // Clicked left of the entry
01634 
01635     if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
01636       pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
01637 
01638       this->vscroll->SetCount(_settings_main_page.Length());
01639       this->SetDirty();
01640       return;
01641     }
01642 
01643     assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01644     const SettingDesc *sd = pe->d.entry.setting;
01645 
01646     /* return if action is only active in network, or only settable by server */
01647     if (!(sd->save.conv & SLF_NO_NETWORK_SYNC) && _networking && !_network_server && !(sd->desc.flags & SGF_PER_COMPANY)) return;
01648     if ((sd->desc.flags & SGF_NETWORK_ONLY) && !_networking) return;
01649     if ((sd->desc.flags & SGF_NO_NETWORK) && _networking) return;
01650 
01651     const void *var = ResolveVariableAddress(settings_ptr, sd);
01652     int32 value = (int32)ReadValue(var, sd->save.conv);
01653 
01654     /* clicked on the icon on the left side. Either scroller or bool on/off */
01655     if (x < 21) {
01656       const SettingDescBase *sdb = &sd->desc;
01657       int32 oldvalue = value;
01658 
01659       switch (sdb->cmd) {
01660         case SDT_BOOLX: value ^= 1; break;
01661         case SDT_ONEOFMANY:
01662         case SDT_NUMX: {
01663           /* Add a dynamic step-size to the scroller. In a maximum of
01664            * 50-steps you should be able to get from min to max,
01665            * unless specified otherwise in the 'interval' variable
01666            * of the current setting. */
01667           uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
01668           if (step == 0) step = 1;
01669 
01670           /* don't allow too fast scrolling */
01671           if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
01672             _left_button_clicked = false;
01673             return;
01674           }
01675 
01676           /* Increase or decrease the value and clamp it to extremes */
01677           if (x >= 10) {
01678             value += step;
01679             if (sdb->min < 0) {
01680               assert((int32)sdb->max >= 0);
01681               if (value > (int32)sdb->max) value = (int32)sdb->max;
01682             } else {
01683               if ((uint32)value > sdb->max) value = (int32)sdb->max;
01684             }
01685             if (value < sdb->min) value = sdb->min; // skip between "disabled" and minimum
01686           } else {
01687             value -= step;
01688             if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
01689           }
01690 
01691           /* Set up scroller timeout for numeric values */
01692           if (value != oldvalue && !(sd->desc.flags & SGF_MULTISTRING)) {
01693             if (this->clicked_entry != NULL) { // Release previous buttons if any
01694               this->clicked_entry->SetButtons(0);
01695             }
01696             this->clicked_entry = pe;
01697             this->clicked_entry->SetButtons((x >= 10) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
01698             this->SetTimeout();
01699             _left_button_clicked = false;
01700           }
01701           break;
01702         }
01703 
01704         default: NOT_REACHED();
01705       }
01706 
01707       if (value != oldvalue) {
01708         if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01709           SetCompanySetting(pe->d.entry.index, value);
01710         } else {
01711           SetSettingValue(pe->d.entry.index, value);
01712         }
01713         this->SetDirty();
01714       }
01715     } else {
01716       /* only open editbox for types that its sensible for */
01717       if (sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
01718         /* Show the correct currency-translated value */
01719         if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
01720 
01721         this->valuewindow_entry = pe;
01722         SetDParam(0, value);
01723         ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
01724       }
01725     }
01726   }
01727 
01728   virtual void OnTimeout()
01729   {
01730     if (this->clicked_entry != NULL) { // On timeout, release any depressed buttons
01731       this->clicked_entry->SetButtons(0);
01732       this->clicked_entry = NULL;
01733       this->SetDirty();
01734     }
01735   }
01736 
01737   virtual void OnQueryTextFinished(char *str)
01738   {
01739     /* The user pressed cancel */
01740     if (str == NULL) return;
01741 
01742     assert(this->valuewindow_entry != NULL);
01743     assert((this->valuewindow_entry->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
01744     const SettingDesc *sd = this->valuewindow_entry->d.entry.setting;
01745 
01746     int32 value;
01747     if (!StrEmpty(str)) {
01748       value = atoi(str);
01749 
01750       /* Save the correct currency-translated value */
01751       if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
01752     } else {
01753       value = (int32)(size_t)sd->desc.def;
01754     }
01755 
01756     if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
01757       SetCompanySetting(this->valuewindow_entry->d.entry.index, value);
01758     } else {
01759       SetSettingValue(this->valuewindow_entry->d.entry.index, value);
01760     }
01761     this->SetDirty();
01762   }
01763 
01764   virtual void OnResize()
01765   {
01766     this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
01767   }
01768 };
01769 
01770 GameSettings *GameSettingsWindow::settings_ptr = NULL;
01771 
01772 static const NWidgetPart _nested_settings_selection_widgets[] = {
01773   NWidget(NWID_HORIZONTAL),
01774     NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
01775     NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
01776   EndContainer(),
01777   NWidget(NWID_HORIZONTAL),
01778     NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
01779     NWidget(NWID_VERTICAL),
01780       NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
01781       NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
01782     EndContainer(),
01783   EndContainer(),
01784 };
01785 
01786 static const WindowDesc _settings_selection_desc(
01787   WDP_CENTER, 450, 397,
01788   WC_GAME_OPTIONS, WC_NONE,
01789   0,
01790   _nested_settings_selection_widgets, lengthof(_nested_settings_selection_widgets)
01791 );
01792 
01794 void ShowGameSettings()
01795 {
01796   DeleteWindowByClass(WC_GAME_OPTIONS);
01797   new GameSettingsWindow(&_settings_selection_desc);
01798 }
01799 
01800 
01810 void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
01811 {
01812   int colour = _colour_gradient[button_colour][2];
01813 
01814   DrawFrameRect(x,      y + 1, x +  9, y + 9, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
01815   DrawFrameRect(x + 10, y + 1, x + 19, y + 9, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
01816   DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
01817   DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + 10, y + WD_IMGBTN_TOP);
01818 
01819   /* Grey out the buttons that aren't clickable */
01820   bool rtl = _current_text_dir == TD_RTL;
01821   if (rtl ? !clickable_right : !clickable_left) {
01822     GfxFillRect(x +  1, y + 1, x +  1 + 8, y + 8, colour, FILLRECT_CHECKER);
01823   }
01824   if (rtl ? !clickable_left : !clickable_right) {
01825     GfxFillRect(x + 11, y + 1, x + 11 + 8, y + 8, colour, FILLRECT_CHECKER);
01826   }
01827 }
01828 
01829 struct CustomCurrencyWindow : Window {
01830   int query_widget;
01831 
01832   CustomCurrencyWindow(const WindowDesc *desc) : Window()
01833   {
01834     this->InitNested(desc);
01835 
01836     SetButtonState();
01837   }
01838 
01839   void SetButtonState()
01840   {
01841     this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1);
01842     this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX);
01843     this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
01844     this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
01845   }
01846 
01847   virtual void SetStringParameters(int widget) const
01848   {
01849     switch (widget) {
01850       case WID_CC_RATE:      SetDParam(0, 1); SetDParam(1, 1);            break;
01851       case WID_CC_SEPARATOR: SetDParamStr(0, _custom_currency.separator); break;
01852       case WID_CC_PREFIX:    SetDParamStr(0, _custom_currency.prefix);    break;
01853       case WID_CC_SUFFIX:    SetDParamStr(0, _custom_currency.suffix);    break;
01854       case WID_CC_YEAR:
01855         SetDParam(0, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
01856         SetDParam(1, _custom_currency.to_euro);
01857         break;
01858 
01859       case WID_CC_PREVIEW:
01860         SetDParam(0, 10000);
01861         break;
01862     }
01863   }
01864 
01865   virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
01866   {
01867     switch (widget) {
01868       /* Set the appropriate width for the edit 'buttons' */
01869       case WID_CC_SEPARATOR_EDIT:
01870       case WID_CC_PREFIX_EDIT:
01871       case WID_CC_SUFFIX_EDIT:
01872         size->width  = this->GetWidget<NWidgetBase>(WID_CC_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(WID_CC_RATE_UP)->smallest_x;
01873         break;
01874 
01875       /* Make sure the window is wide enough for the widest exchange rate */
01876       case WID_CC_RATE:
01877         SetDParam(0, 1);
01878         SetDParam(1, INT32_MAX);
01879         *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
01880         break;
01881     }
01882   }
01883 
01884   virtual void OnClick(Point pt, int widget, int click_count)
01885   {
01886     int line = 0;
01887     int len = 0;
01888     StringID str = 0;
01889     CharSetFilter afilter = CS_ALPHANUMERAL;
01890 
01891     switch (widget) {
01892       case WID_CC_RATE_DOWN:
01893         if (_custom_currency.rate > 1) _custom_currency.rate--;
01894         if (_custom_currency.rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
01895         this->EnableWidget(WID_CC_RATE_UP);
01896         break;
01897 
01898       case WID_CC_RATE_UP:
01899         if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
01900         if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
01901         this->EnableWidget(WID_CC_RATE_DOWN);
01902         break;
01903 
01904       case WID_CC_RATE:
01905         SetDParam(0, _custom_currency.rate);
01906         str = STR_JUST_INT;
01907         len = 5;
01908         line = WID_CC_RATE;
01909         afilter = CS_NUMERAL;
01910         break;
01911 
01912       case WID_CC_SEPARATOR_EDIT:
01913       case WID_CC_SEPARATOR:
01914         SetDParamStr(0, _custom_currency.separator);
01915         str = STR_JUST_RAW_STRING;
01916         len = 1;
01917         line = WID_CC_SEPARATOR;
01918         break;
01919 
01920       case WID_CC_PREFIX_EDIT:
01921       case WID_CC_PREFIX:
01922         SetDParamStr(0, _custom_currency.prefix);
01923         str = STR_JUST_RAW_STRING;
01924         len = 12;
01925         line = WID_CC_PREFIX;
01926         break;
01927 
01928       case WID_CC_SUFFIX_EDIT:
01929       case WID_CC_SUFFIX:
01930         SetDParamStr(0, _custom_currency.suffix);
01931         str = STR_JUST_RAW_STRING;
01932         len = 12;
01933         line = WID_CC_SUFFIX;
01934         break;
01935 
01936       case WID_CC_YEAR_DOWN:
01937         _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
01938         if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
01939         this->EnableWidget(WID_CC_YEAR_UP);
01940         break;
01941 
01942       case WID_CC_YEAR_UP:
01943         _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
01944         if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
01945         this->EnableWidget(WID_CC_YEAR_DOWN);
01946         break;
01947 
01948       case WID_CC_YEAR:
01949         SetDParam(0, _custom_currency.to_euro);
01950         str = STR_JUST_INT;
01951         len = 7;
01952         line = WID_CC_YEAR;
01953         afilter = CS_NUMERAL;
01954         break;
01955     }
01956 
01957     if (len != 0) {
01958       this->query_widget = line;
01959       ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
01960     }
01961 
01962     this->SetTimeout();
01963     this->SetDirty();
01964   }
01965 
01966   virtual void OnQueryTextFinished(char *str)
01967   {
01968     if (str == NULL) return;
01969 
01970     switch (this->query_widget) {
01971       case WID_CC_RATE:
01972         _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
01973         break;
01974 
01975       case WID_CC_SEPARATOR: // Thousands seperator
01976         strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
01977         break;
01978 
01979       case WID_CC_PREFIX:
01980         strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
01981         break;
01982 
01983       case WID_CC_SUFFIX:
01984         strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
01985         break;
01986 
01987       case WID_CC_YEAR: { // Year to switch to euro
01988         int val = atoi(str);
01989 
01990         _custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
01991         break;
01992       }
01993     }
01994     MarkWholeScreenDirty();
01995     SetButtonState();
01996   }
01997 
01998   virtual void OnTimeout()
01999   {
02000     this->SetDirty();
02001   }
02002 };
02003 
02004 static const NWidgetPart _nested_cust_currency_widgets[] = {
02005   NWidget(NWID_HORIZONTAL),
02006     NWidget(WWT_CLOSEBOX, COLOUR_GREY),
02007     NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
02008   EndContainer(),
02009   NWidget(WWT_PANEL, COLOUR_GREY),
02010     NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
02011       NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02012         NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
02013         NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
02014         NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02015         NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
02016       EndContainer(),
02017       NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02018         NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
02019         NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02020         NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
02021       EndContainer(),
02022       NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02023         NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
02024         NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02025         NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
02026       EndContainer(),
02027       NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02028         NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
02029         NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02030         NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
02031       EndContainer(),
02032       NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
02033         NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02034         NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
02035         NWidget(NWID_SPACER), SetMinimalSize(5, 0),
02036         NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
02037       EndContainer(),
02038     EndContainer(),
02039     NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
02040                 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
02041   EndContainer(),
02042 };
02043 
02044 static const WindowDesc _cust_currency_desc(
02045   WDP_CENTER, 0, 0,
02046   WC_CUSTOM_CURRENCY, WC_NONE,
02047   WDF_UNCLICK_BUTTONS,
02048   _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
02049 );
02050 
02052 static void ShowCustCurrency()
02053 {
02054   DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
02055   new CustomCurrencyWindow(&_cust_currency_desc);
02056 }