# settings_gui.cpp

Go to the documentation of this file.

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