# settings_gui.cpp

Go to the documentation of this file.

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