settings_gui.cpp

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