settings_gui.cpp

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

Generated on Fri Dec 31 17:15:38 2010 for OpenTTD by  doxygen 1.6.1