settings_gui.cpp

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