settings_gui.cpp

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

Generated on Thu Feb 4 17:20:28 2010 for OpenTTD by  doxygen 1.5.6