# settings_gui.cpp

Go to the documentation of this file.

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