(svn r25652) -Fix: Improve text caret movement for complex scripts.
[openttd/fttd.git] / src / settings_gui.cpp
blobefd95809523ead857aee338c1920cf0b8ca90fd5
1 /* $Id$ */
3 /*
4 * This file is part of OpenTTD.
5 * 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.
6 * 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.
7 * 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/>.
8 */
10 /** @file settings_gui.cpp GUI for settings. */
12 #include "stdafx.h"
13 #include "currency.h"
14 #include "error.h"
15 #include "settings_gui.h"
16 #include "textbuf_gui.h"
17 #include "command_func.h"
18 #include "screenshot.h"
19 #include "network/network.h"
20 #include "town.h"
21 #include "settings_internal.h"
22 #include "newgrf_townname.h"
23 #include "strings_func.h"
24 #include "window_func.h"
25 #include "string_func.h"
26 #include "widgets/dropdown_type.h"
27 #include "widgets/dropdown_func.h"
28 #include "highscore.h"
29 #include "base_media_base.h"
30 #include "company_base.h"
31 #include "company_func.h"
32 #include "viewport_func.h"
33 #include "core/geometry_func.hpp"
34 #include "ai/ai.hpp"
35 #include "blitter/factory.hpp"
36 #include "language.h"
37 #include "textfile_gui.h"
38 #include "stringfilter_type.h"
39 #include "querystring_gui.h"
42 static const StringID _driveside_dropdown[] = {
43 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT,
44 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT,
45 INVALID_STRING_ID
48 static const StringID _autosave_dropdown[] = {
49 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
50 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH,
51 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS,
52 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS,
53 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS,
54 INVALID_STRING_ID,
57 int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; ///< Number of original town names.
58 static StringID *_grf_names = NULL; ///< Pointer to town names defined by NewGRFs.
59 static int _nb_grf_names = 0; ///< Number of town names defined by NewGRFs.
61 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd);
63 /** Allocate memory for the NewGRF town names. */
64 void InitGRFTownGeneratorNames()
66 free(_grf_names);
67 _grf_names = GetGRFTownNameList();
68 _nb_grf_names = 0;
69 for (StringID *s = _grf_names; *s != INVALID_STRING_ID; s++) _nb_grf_names++;
72 /**
73 * Get a town name.
74 * @param town_name Number of the wanted town name.
75 * @return Name of the town as string ID.
77 static inline StringID TownName(int town_name)
79 if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
80 town_name -= _nb_orig_names;
81 if (town_name < _nb_grf_names) return _grf_names[town_name];
82 return STR_UNDEFINED;
85 /**
86 * Get index of the current screen resolution.
87 * @return Index of the current screen resolution if it is a known resolution, #_num_resolutions otherwise.
89 static int GetCurRes()
91 int i;
93 for (i = 0; i != _num_resolutions; i++) {
94 if ((int)_resolutions[i].width == _screen.width &&
95 (int)_resolutions[i].height == _screen.height) {
96 break;
99 return i;
102 static void ShowCustCurrency();
104 template <class T>
105 static DropDownList *BuiltSetDropDownList(int *selected_index)
107 int n = T::GetNumSets();
108 *selected_index = T::GetIndexOfUsedSet();
110 DropDownList *list = new DropDownList();
111 for (int i = 0; i < n; i++) {
112 list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i)));
115 return list;
118 /** Window for displaying the textfile of a BaseSet. */
119 template <class TBaseSet>
120 struct BaseSetTextfileWindow : public TextfileWindow {
121 const TBaseSet* baseset; ///< View the textfile of this BaseSet.
122 StringID content_type; ///< STR_CONTENT_TYPE_xxx for title.
124 BaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type) : TextfileWindow(file_type), baseset(baseset), content_type(content_type)
126 const char *textfile = this->baseset->GetTextfile(file_type);
127 this->LoadTextfile(textfile, BASESET_DIR);
130 /* virtual */ void SetStringParameters(int widget) const
132 if (widget == WID_TF_CAPTION) {
133 SetDParam(0, content_type);
134 SetDParamStr(1, this->baseset->name);
140 * Open the BaseSet version of the textfile window.
141 * @param file_type The type of textfile to display.
142 * @param baseset The BaseSet to use.
143 * @param content_type STR_CONTENT_TYPE_xxx for title.
145 template <class TBaseSet>
146 void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
148 DeleteWindowByClass(WC_TEXTFILE);
149 new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
152 struct GameOptionsWindow : Window {
153 GameSettings *opt;
154 bool reload;
156 GameOptionsWindow(WindowDesc *desc) : Window(desc)
158 this->opt = &GetGameSettings();
159 this->reload = false;
161 this->InitNested(WN_GAME_OPTIONS_GAME_OPTIONS);
162 this->OnInvalidateData(0);
165 ~GameOptionsWindow()
167 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
168 if (this->reload) _switch_mode = SM_MENU;
172 * Build the dropdown list for a specific widget.
173 * @param widget Widget to build list for
174 * @param selected_index Currently selected item
175 * @return the built dropdown list, or NULL if the widget has no dropdown menu.
177 DropDownList *BuildDropDownList(int widget, int *selected_index) const
179 DropDownList *list = NULL;
180 switch (widget) {
181 case WID_GO_CURRENCY_DROPDOWN: { // Setup currencies dropdown
182 list = new DropDownList();
183 *selected_index = this->opt->locale.currency;
184 StringID *items = BuildCurrencyDropdown();
185 uint64 disabled = _game_mode == GM_MENU ? 0LL : ~GetMaskOfAllowedCurrencies();
187 /* Add non-custom currencies; sorted naturally */
188 for (uint i = 0; i < CURRENCY_END; items++, i++) {
189 if (i == CURRENCY_CUSTOM) continue;
190 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
192 list->sort(DropDownListStringItem::NatSortFunc);
194 /* Append custom currency at the end */
195 list->push_back(new DropDownListItem(-1, false)); // separator line
196 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM)));
197 break;
200 case WID_GO_ROADSIDE_DROPDOWN: { // Setup road-side dropdown
201 list = new DropDownList();
202 *selected_index = this->opt->vehicle.road_side;
203 const StringID *items = _driveside_dropdown;
204 uint disabled = 0;
206 /* You can only change the drive side if you are in the menu or ingame with
207 * no vehicles present. In a networking game only the server can change it */
208 extern bool RoadVehiclesAreBuilt();
209 if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
210 disabled = ~(1 << this->opt->vehicle.road_side); // disable the other value
213 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
214 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
216 break;
219 case WID_GO_TOWNNAME_DROPDOWN: { // Setup townname dropdown
220 list = new DropDownList();
221 *selected_index = this->opt->game_creation.town_name;
223 int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
225 /* Add and sort original townnames generators */
226 for (int i = 0; i < _nb_orig_names; i++) {
227 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
229 list->sort(DropDownListStringItem::NatSortFunc);
231 /* Add and sort newgrf townnames generators */
232 DropDownList newgrf_names;
233 for (int i = 0; i < _nb_grf_names; i++) {
234 int result = _nb_orig_names + i;
235 newgrf_names.push_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
237 newgrf_names.sort(DropDownListStringItem::NatSortFunc);
239 /* Insert newgrf_names at the top of the list */
240 if (newgrf_names.size() > 0) {
241 newgrf_names.push_back(new DropDownListItem(-1, false)); // separator line
242 list->splice(list->begin(), newgrf_names);
244 break;
247 case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
248 list = new DropDownList();
249 *selected_index = _settings_client.gui.autosave;
250 const StringID *items = _autosave_dropdown;
251 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
252 list->push_back(new DropDownListStringItem(*items, i, false));
254 break;
257 case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
258 list = new DropDownList();
259 for (uint i = 0; i < _languages.Length(); i++) {
260 if (&_languages[i] == _current_language) *selected_index = i;
261 list->push_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false));
263 list->sort(DropDownListStringItem::NatSortFunc);
264 break;
267 case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
268 list = new DropDownList();
269 *selected_index = GetCurRes();
270 for (int i = 0; i < _num_resolutions; i++) {
271 list->push_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
273 break;
275 case WID_GO_SCREENSHOT_DROPDOWN: // Setup screenshot format dropdown
276 list = new DropDownList();
277 *selected_index = _cur_screenshot_format;
278 for (uint i = 0; i < _num_screenshot_formats; i++) {
279 if (!GetScreenshotFormatSupports_32bpp(i) && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) continue;
280 list->push_back(new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false));
282 break;
284 case WID_GO_BASE_GRF_DROPDOWN:
285 list = BuiltSetDropDownList<BaseGraphics>(selected_index);
286 break;
288 case WID_GO_BASE_SFX_DROPDOWN:
289 list = BuiltSetDropDownList<BaseSounds>(selected_index);
290 break;
292 case WID_GO_BASE_MUSIC_DROPDOWN:
293 list = BuiltSetDropDownList<BaseMusic>(selected_index);
294 break;
296 default:
297 return NULL;
300 return list;
303 virtual void SetStringParameters(int widget) const
305 switch (widget) {
306 case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
307 case WID_GO_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
308 case WID_GO_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_name)); break;
309 case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
310 case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
311 case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
312 case WID_GO_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
313 case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
314 case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
315 case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
316 case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
317 case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
321 virtual void DrawWidget(const Rect &r, int widget) const
323 switch (widget) {
324 case WID_GO_BASE_GRF_DESCRIPTION:
325 SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
326 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
327 break;
329 case WID_GO_BASE_SFX_DESCRIPTION:
330 SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
331 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
332 break;
334 case WID_GO_BASE_MUSIC_DESCRIPTION:
335 SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
336 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
337 break;
341 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
343 switch (widget) {
344 case WID_GO_BASE_GRF_DESCRIPTION:
345 /* Find the biggest description for the default size. */
346 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
347 SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
348 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
350 break;
352 case WID_GO_BASE_GRF_STATUS:
353 /* Find the biggest description for the default size. */
354 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
355 uint invalid_files = BaseGraphics::GetSet(i)->GetNumInvalid();
356 if (invalid_files == 0) continue;
358 SetDParam(0, invalid_files);
359 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_GRF_STATUS));
361 break;
363 case WID_GO_BASE_SFX_DESCRIPTION:
364 /* Find the biggest description for the default size. */
365 for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
366 SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
367 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
369 break;
371 case WID_GO_BASE_MUSIC_DESCRIPTION:
372 /* Find the biggest description for the default size. */
373 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
374 SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
375 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
377 break;
379 case WID_GO_BASE_MUSIC_STATUS:
380 /* Find the biggest description for the default size. */
381 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
382 uint invalid_files = BaseMusic::GetSet(i)->GetNumInvalid();
383 if (invalid_files == 0) continue;
385 SetDParam(0, invalid_files);
386 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_MUSIC_STATUS));
388 break;
390 default: {
391 int selected;
392 DropDownList *list = this->BuildDropDownList(widget, &selected);
393 if (list != NULL) {
394 /* Find the biggest item for the default size. */
395 for (DropDownList::iterator it = list->begin(); it != list->end(); it++) {
396 static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM};
397 Dimension string_dim;
398 int width = (*it)->Width();
399 string_dim.width = width + extra.width;
400 string_dim.height = (*it)->Height(width) + extra.height;
401 *size = maxdim(*size, string_dim);
402 delete *it;
404 delete list;
410 virtual void OnClick(Point pt, int widget, int click_count)
412 if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_END) {
413 if (BaseGraphics::GetUsedSet() == NULL) return;
415 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
416 return;
418 if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_END) {
419 if (BaseSounds::GetUsedSet() == NULL) return;
421 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
422 return;
424 if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_END) {
425 if (BaseMusic::GetUsedSet() == NULL) return;
427 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
428 return;
430 switch (widget) {
431 case WID_GO_FULLSCREEN_BUTTON: // Click fullscreen on/off
432 /* try to toggle full-screen on/off */
433 if (!ToggleFullScreen(!_fullscreen)) {
434 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
436 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
437 this->SetDirty();
438 break;
440 default: {
441 int selected;
442 DropDownList *list = this->BuildDropDownList(widget, &selected);
443 if (list != NULL) {
444 ShowDropDownList(this, list, selected, widget);
446 break;
452 * Set the base media set.
453 * @param index the index of the media set
454 * @tparam T class of media set
456 template <class T>
457 void SetMediaSet(int index)
459 if (_game_mode == GM_MENU) {
460 const char *name = T::GetSet(index)->name;
462 free(T::ini_set);
463 T::ini_set = strdup(name);
465 T::SetSet(name);
466 this->reload = true;
467 this->InvalidateData();
471 virtual void OnDropdownSelect(int widget, int index)
473 switch (widget) {
474 case WID_GO_CURRENCY_DROPDOWN: // Currency
475 if (index == CURRENCY_CUSTOM) ShowCustCurrency();
476 this->opt->locale.currency = index;
477 ReInitAllWindows();
478 break;
480 case WID_GO_ROADSIDE_DROPDOWN: // Road side
481 if (this->opt->vehicle.road_side != index) { // only change if setting changed
482 uint i;
483 if (GetSettingFromName("vehicle.road_side", &i) == NULL) NOT_REACHED();
484 SetSettingValue(i, index);
485 MarkWholeScreenDirty();
487 break;
489 case WID_GO_TOWNNAME_DROPDOWN: // Town names
490 if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
491 this->opt->game_creation.town_name = index;
492 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
494 break;
496 case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
497 _settings_client.gui.autosave = index;
498 this->SetDirty();
499 break;
501 case WID_GO_LANG_DROPDOWN: // Change interface language
502 ReadLanguagePack(&_languages[index]);
503 DeleteWindowByClass(WC_QUERY_STRING);
504 CheckForMissingGlyphs();
505 UpdateAllVirtCoords();
506 ReInitAllWindows();
507 break;
509 case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
510 if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
511 this->SetDirty();
513 break;
515 case WID_GO_SCREENSHOT_DROPDOWN: // Change screenshot format
516 SetScreenshotFormat(index);
517 this->SetDirty();
518 break;
520 case WID_GO_BASE_GRF_DROPDOWN:
521 this->SetMediaSet<BaseGraphics>(index);
522 break;
524 case WID_GO_BASE_SFX_DROPDOWN:
525 this->SetMediaSet<BaseSounds>(index);
526 break;
528 case WID_GO_BASE_MUSIC_DROPDOWN:
529 this->SetMediaSet<BaseMusic>(index);
530 break;
535 * Some data on this window has become invalid.
536 * @param data Information about the changed data. @see GameOptionsInvalidationData
537 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
539 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
541 if (!gui_scope) return;
542 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
544 bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
545 this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
547 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
548 this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->GetTextfile(tft) == NULL);
549 this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == NULL || BaseSounds::GetUsedSet()->GetTextfile(tft) == NULL);
550 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == NULL || BaseMusic::GetUsedSet()->GetTextfile(tft) == NULL);
553 missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
554 this->GetWidget<NWidgetCore>(WID_GO_BASE_MUSIC_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_MUSIC_STATUS, STR_NULL);
558 static const NWidgetPart _nested_game_options_widgets[] = {
559 NWidget(NWID_HORIZONTAL),
560 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
561 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
562 EndContainer(),
563 NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
564 NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
565 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
566 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
567 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_CURRENCY_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
568 EndContainer(),
569 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME, STR_NULL),
570 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_ROADSIDE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_TOOLTIP), SetFill(1, 0),
571 EndContainer(),
572 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
573 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_AUTOSAVE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP), SetFill(1, 0),
574 EndContainer(),
575 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL),
576 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_RESOLUTION_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_RESOLUTION_TOOLTIP), SetFill(1, 0), SetPadding(0, 0, 3, 0),
577 NWidget(NWID_HORIZONTAL),
578 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
579 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
580 EndContainer(),
581 EndContainer(),
582 EndContainer(),
584 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
585 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL),
586 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_TOWNNAME_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_TOWN_NAMES_DROPDOWN_TOOLTIP), SetFill(1, 0),
587 EndContainer(),
588 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
589 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_LANG_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0),
590 EndContainer(),
591 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_SCREENSHOT_FORMAT, STR_NULL),
592 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_SCREENSHOT_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_SCREENSHOT_FORMAT_TOOLTIP), SetFill(1, 0),
593 EndContainer(),
594 NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1),
595 EndContainer(),
596 EndContainer(),
598 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
599 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
600 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
601 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
602 EndContainer(),
603 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
604 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
605 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
606 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
607 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
608 EndContainer(),
609 EndContainer(),
611 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10),
612 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
613 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP),
614 NWidget(NWID_SPACER), SetFill(1, 0),
615 EndContainer(),
616 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
617 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
618 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
619 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
620 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
621 EndContainer(),
622 EndContainer(),
624 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10),
625 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
626 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP),
627 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
628 EndContainer(),
629 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
630 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
631 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
632 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
633 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
634 EndContainer(),
635 EndContainer(),
636 EndContainer(),
639 static WindowDesc _game_options_desc(
640 WDP_CENTER, "settings_game", 0, 0,
641 WC_GAME_OPTIONS, WC_NONE,
643 _nested_game_options_widgets, lengthof(_nested_game_options_widgets)
646 /** Open the game options window. */
647 void ShowGameOptions()
649 DeleteWindowByClass(WC_GAME_OPTIONS);
650 new GameOptionsWindow(&_game_options_desc);
653 static int SETTING_HEIGHT = 11; ///< Height of a single setting in the tree view in pixels
654 static const int LEVEL_WIDTH = 15; ///< Indenting width of a sub-page in pixels
657 * Flags for #SettingEntry
658 * @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
660 enum SettingEntryFlags {
661 SEF_LEFT_DEPRESSED = 0x01, ///< Of a numeric setting entry, the left button is depressed
662 SEF_RIGHT_DEPRESSED = 0x02, ///< Of a numeric setting entry, the right button is depressed
663 SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED), ///< Bit-mask for button flags
665 SEF_LAST_FIELD = 0x04, ///< This entry is the last one in a (sub-)page
666 SEF_FILTERED = 0x08, ///< Entry is hidden by the string filter
668 /* Entry kind */
669 SEF_SETTING_KIND = 0x10, ///< Entry kind: Entry is a setting
670 SEF_SUBTREE_KIND = 0x20, ///< Entry kind: Entry is a sub-tree
671 SEF_KIND_MASK = (SEF_SETTING_KIND | SEF_SUBTREE_KIND), ///< Bit-mask for fetching entry kind
674 struct SettingsPage; // Forward declaration
676 /** Data fields for a sub-page (#SEF_SUBTREE_KIND kind)*/
677 struct SettingEntrySubtree {
678 SettingsPage *page; ///< Pointer to the sub-page
679 bool folded; ///< Sub-page is folded (not visible except for its title)
680 StringID title; ///< Title of the sub-page
683 /** Data fields for a single setting (#SEF_SETTING_KIND kind) */
684 struct SettingEntrySetting {
685 const char *name; ///< Name of the setting
686 const SettingDesc *setting; ///< Setting description of the setting
687 uint index; ///< Index of the setting in the settings table
690 /** How the list of advanced settings is filtered. */
691 enum RestrictionMode {
692 RM_BASIC, ///< Display settings associated to the "basic" list.
693 RM_ADVANCED, ///< Display settings associated to the "advanced" list.
694 RM_ALL, ///< List all settings regardless of the default/newgame/... values.
695 RM_CHANGED_AGAINST_DEFAULT, ///< Show only settings which are different compared to default values.
696 RM_CHANGED_AGAINST_NEW, ///< Show only settings which are different compared to the user's new game setting values.
697 RM_END, ///< End for iteration.
700 /** Filter for settings list. */
701 struct SettingFilter {
702 StringFilter string; ///< Filter string.
703 RestrictionMode mode; ///< Filter based on category.
704 SettingType type; ///< Filter based on type.
707 /** Data structure describing a single setting in a tab */
708 struct SettingEntry {
709 byte flags; ///< Flags of the setting entry. @see SettingEntryFlags
710 byte level; ///< Nesting level of this setting entry
711 union {
712 SettingEntrySetting entry; ///< Data fields if entry is a setting
713 SettingEntrySubtree sub; ///< Data fields if entry is a sub-page
714 } d; ///< Data fields for each kind
716 SettingEntry(const char *nm);
717 SettingEntry(SettingsPage *sub, StringID title);
719 void Init(byte level);
720 void FoldAll();
721 void UnFoldAll();
722 void SetButtons(byte new_val);
725 * Set whether this is the last visible entry of the parent node.
726 * @param last_field Value to set
728 void SetLastField(bool last_field) { if (last_field) SETBITS(this->flags, SEF_LAST_FIELD); else CLRBITS(this->flags, SEF_LAST_FIELD); }
730 uint Length() const;
731 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
732 bool IsVisible(const SettingEntry *item) const;
733 SettingEntry *FindEntry(uint row, uint *cur_row);
734 uint GetMaxHelpHeight(int maxw);
736 bool IsFiltered() const;
737 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
739 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, SettingEntry *selected);
742 * Get the help text of a single setting.
743 * @return The requested help text.
745 inline StringID GetHelpText()
747 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
748 return this->d.entry.setting->desc.str_help;
751 void SetValueDParams(uint first_param, int32 value);
753 private:
754 void DrawSetting(GameSettings *settings_ptr, int x, int y, int max_x, int state, bool highlight);
755 bool IsVisibleByRestrictionMode(RestrictionMode mode) const;
758 /** Data structure describing one page of settings in the settings window. */
759 struct SettingsPage {
760 SettingEntry *entries; ///< Array of setting entries of the page.
761 byte num; ///< Number of entries on the page (statically filled).
763 void Init(byte level = 0);
764 void FoldAll();
765 void UnFoldAll();
767 uint Length() const;
768 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
769 bool IsVisible(const SettingEntry *item) const;
770 SettingEntry *FindEntry(uint row, uint *cur_row) const;
771 uint GetMaxHelpHeight(int maxw);
773 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
775 uint Draw(GameSettings *settings_ptr, int base_x, int base_y, int max_x, uint first_row, uint max_row, SettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
779 /* == SettingEntry methods == */
782 * Constructor for a single setting in the 'advanced settings' window
783 * @param nm Name of the setting in the setting table
785 SettingEntry::SettingEntry(const char *nm)
787 this->flags = SEF_SETTING_KIND;
788 this->level = 0;
789 this->d.entry.name = nm;
790 this->d.entry.setting = NULL;
791 this->d.entry.index = 0;
795 * Constructor for a sub-page in the 'advanced settings' window
796 * @param sub Sub-page
797 * @param title Title of the sub-page
799 SettingEntry::SettingEntry(SettingsPage *sub, StringID title)
801 this->flags = SEF_SUBTREE_KIND;
802 this->level = 0;
803 this->d.sub.page = sub;
804 this->d.sub.folded = true;
805 this->d.sub.title = title;
809 * Initialization of a setting entry
810 * @param level Page nesting level of this entry
812 void SettingEntry::Init(byte level)
814 this->level = level;
816 switch (this->flags & SEF_KIND_MASK) {
817 case SEF_SETTING_KIND:
818 this->d.entry.setting = GetSettingFromName(this->d.entry.name, &this->d.entry.index);
819 assert(this->d.entry.setting != NULL);
820 break;
821 case SEF_SUBTREE_KIND:
822 this->d.sub.page->Init(level + 1);
823 break;
824 default: NOT_REACHED();
828 /** Recursively close all (filtered) folds of sub-pages */
829 void SettingEntry::FoldAll()
831 if (this->IsFiltered()) return;
832 switch (this->flags & SEF_KIND_MASK) {
833 case SEF_SETTING_KIND:
834 break;
836 case SEF_SUBTREE_KIND:
837 this->d.sub.folded = true;
838 this->d.sub.page->FoldAll();
839 break;
841 default: NOT_REACHED();
845 /** Recursively open all (filtered) folds of sub-pages */
846 void SettingEntry::UnFoldAll()
848 if (this->IsFiltered()) return;
849 switch (this->flags & SEF_KIND_MASK) {
850 case SEF_SETTING_KIND:
851 break;
853 case SEF_SUBTREE_KIND:
854 this->d.sub.folded = false;
855 this->d.sub.page->UnFoldAll();
856 break;
858 default: NOT_REACHED();
863 * Recursively accumulate the folding state of the (filtered) tree.
864 * @param[in,out] all_folded Set to false, if one entry is not folded.
865 * @param[in,out] all_unfolded Set to false, if one entry is folded.
867 void SettingEntry::GetFoldingState(bool &all_folded, bool &all_unfolded) const
869 if (this->IsFiltered()) return;
870 switch (this->flags & SEF_KIND_MASK) {
871 case SEF_SETTING_KIND:
872 break;
874 case SEF_SUBTREE_KIND:
875 if (this->d.sub.folded) {
876 all_unfolded = false;
877 } else {
878 all_folded = false;
880 this->d.sub.page->GetFoldingState(all_folded, all_unfolded);
881 break;
883 default: NOT_REACHED();
888 * Check whether an entry is visible and not folded or filtered away.
889 * Note: This does not consider the scrolling range; it might still require scrolling to make the setting really visible.
890 * @param item Entry to search for.
891 * @return true if entry is visible.
893 bool SettingEntry::IsVisible(const SettingEntry *item) const
895 if (this->IsFiltered()) return false;
896 if (this == item) return true;
898 switch (this->flags & SEF_KIND_MASK) {
899 case SEF_SETTING_KIND:
900 return false;
902 case SEF_SUBTREE_KIND:
903 return !this->d.sub.folded && this->d.sub.page->IsVisible(item);
905 default: NOT_REACHED();
910 * Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
911 * @param new_val New value for the button flags
912 * @see SettingEntryFlags
914 void SettingEntry::SetButtons(byte new_val)
916 assert((new_val & ~SEF_BUTTONS_MASK) == 0); // Should not touch any flags outside the buttons
917 this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
920 /** Return numbers of rows needed to display the (filtered) entry */
921 uint SettingEntry::Length() const
923 if (this->IsFiltered()) return 0;
924 switch (this->flags & SEF_KIND_MASK) {
925 case SEF_SETTING_KIND:
926 return 1;
927 case SEF_SUBTREE_KIND:
928 if (this->d.sub.folded) return 1; // Only displaying the title
930 return 1 + this->d.sub.page->Length(); // 1 extra row for the title
931 default: NOT_REACHED();
936 * Find setting entry at row \a row_num
937 * @param row_num Index of entry to return
938 * @param cur_row Current row number
939 * @return The requested setting entry or \c NULL if it not found (folded or filtered)
941 SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
943 if (this->IsFiltered()) return NULL;
944 if (row_num == *cur_row) return this;
946 switch (this->flags & SEF_KIND_MASK) {
947 case SEF_SETTING_KIND:
948 (*cur_row)++;
949 break;
950 case SEF_SUBTREE_KIND:
951 (*cur_row)++; // add one for row containing the title
952 if (this->d.sub.folded) {
953 break;
956 /* sub-page is visible => search it too */
957 return this->d.sub.page->FindEntry(row_num, cur_row);
958 default: NOT_REACHED();
960 return NULL;
964 * Get the biggest height of the help text(s), if the width is at least \a maxw. Help text gets wrapped if needed.
965 * @param maxw Maximal width of a line help text.
966 * @return Biggest height needed to display any help text of this node (and its descendants).
968 uint SettingEntry::GetMaxHelpHeight(int maxw)
970 switch (this->flags & SEF_KIND_MASK) {
971 case SEF_SETTING_KIND: return GetStringHeight(this->GetHelpText(), maxw);
972 case SEF_SUBTREE_KIND: return this->d.sub.page->GetMaxHelpHeight(maxw);
973 default: NOT_REACHED();
978 * Check whether an entry is hidden due to filters
979 * @return true if hidden.
981 bool SettingEntry::IsFiltered() const
983 return (this->flags & SEF_FILTERED) != 0;
987 * Checks whether an entry shall be made visible based on the restriction mode.
988 * @param mode The current status of the restriction drop down box.
989 * @return true if the entry shall be visible.
991 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
993 /* There shall not be any restriction, i.e. all settings shall be visible. */
994 if (mode == RM_ALL) return true;
996 GameSettings *settings_ptr = &GetGameSettings();
997 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
998 const SettingDesc *sd = this->d.entry.setting;
1000 if (mode == RM_BASIC) return (this->d.entry.setting->desc.cat & SC_BASIC_LIST) != 0;
1001 if (mode == RM_ADVANCED) return (this->d.entry.setting->desc.cat & SC_ADVANCED_LIST) != 0;
1003 /* Read the current value. */
1004 const void *var = ResolveVariableAddress(settings_ptr, sd);
1005 int64 current_value = ReadValue(var, sd->save.conv);
1007 int64 filter_value;
1009 if (mode == RM_CHANGED_AGAINST_DEFAULT) {
1010 /* This entry shall only be visible, if the value deviates from its default value. */
1012 /* Read the default value. */
1013 filter_value = ReadValue(&sd->desc.def, sd->save.conv);
1014 } else {
1015 assert(mode == RM_CHANGED_AGAINST_NEW);
1016 /* This entry shall only be visible, if the value deviates from
1017 * its value is used when starting a new game. */
1019 /* Make sure we're not comparing the new game settings against itself. */
1020 assert(settings_ptr != &_settings_newgame);
1022 /* Read the new game's value. */
1023 var = ResolveVariableAddress(&_settings_newgame, sd);
1024 filter_value = ReadValue(var, sd->save.conv);
1027 return current_value != filter_value;
1031 * Update the filter state.
1032 * @param filter Filter
1033 * @param force_visible Whether to force all items visible, no matter what (due to filter text; not affected by restriction drop down box).
1034 * @return true if item remains visible
1036 bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
1038 CLRBITS(this->flags, SEF_FILTERED);
1040 bool visible = true;
1041 switch (this->flags & SEF_KIND_MASK) {
1042 case SEF_SETTING_KIND: {
1043 const SettingDesc *sd = this->d.entry.setting;
1044 if (!force_visible && !filter.string.IsEmpty()) {
1045 /* Process the search text filter for this item. */
1046 filter.string.ResetState();
1048 const SettingDescBase *sdb = &sd->desc;
1050 SetDParam(0, STR_EMPTY);
1051 filter.string.AddLine(sdb->str);
1052 filter.string.AddLine(this->GetHelpText());
1054 visible = filter.string.GetState();
1056 if (filter.type != ST_ALL) visible = visible && sd->GetType() == filter.type;
1057 visible = visible && this->IsVisibleByRestrictionMode(filter.mode);
1058 break;
1060 case SEF_SUBTREE_KIND: {
1061 if (!force_visible && !filter.string.IsEmpty()) {
1062 filter.string.ResetState();
1063 filter.string.AddLine(this->d.sub.title);
1064 force_visible = filter.string.GetState();
1066 visible = this->d.sub.page->UpdateFilterState(filter, force_visible);
1067 break;
1069 default: NOT_REACHED();
1072 if (!visible) SETBITS(this->flags, SEF_FILTERED);
1073 return visible;
1079 * Draw a row in the settings panel.
1081 * See SettingsPage::Draw() for an explanation about how drawing is performed.
1083 * The \a parent_last parameter ensures that the vertical lines at the left are
1084 * only drawn when another entry follows, that it prevents output like
1085 * \verbatim
1086 * |-- setting
1087 * |-- (-) - Title
1088 * | |-- setting
1089 * | |-- setting
1090 * \endverbatim
1091 * The left-most vertical line is not wanted. It is prevented by setting the
1092 * appropriate bit in the \a parent_last parameter.
1094 * @param settings_ptr Pointer to current values of all settings
1095 * @param left Left-most position in window/panel to start drawing \a first_row
1096 * @param right Right-most x position to draw strings at.
1097 * @param base_y Upper-most position in window/panel to start drawing \a first_row
1098 * @param first_row First row number to draw
1099 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1100 * @param cur_row Current row number (internal variable)
1101 * @param parent_last Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
1102 * @param selected Selected entry by the user.
1103 * @return Row number of the next row to draw
1105 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, SettingEntry *selected)
1107 if (this->IsFiltered()) return cur_row;
1108 if (cur_row >= max_row) return cur_row;
1110 bool rtl = _current_text_dir == TD_RTL;
1111 int offset = rtl ? -4 : 4;
1112 int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
1114 int x = rtl ? right : left;
1115 int y = base_y;
1116 if (cur_row >= first_row) {
1117 int colour = _colour_gradient[COLOUR_ORANGE][4];
1118 y = base_y + (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
1120 /* Draw vertical for parent nesting levels */
1121 for (uint lvl = 0; lvl < this->level; lvl++) {
1122 if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
1123 x += level_width;
1125 /* draw own |- prefix */
1126 int halfway_y = y + SETTING_HEIGHT / 2;
1127 int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
1128 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
1129 /* Small horizontal line from the last vertical line */
1130 GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
1131 x += level_width;
1134 switch (this->flags & SEF_KIND_MASK) {
1135 case SEF_SETTING_KIND:
1136 if (cur_row >= first_row) {
1137 this->DrawSetting(settings_ptr, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK,
1138 this == selected);
1140 cur_row++;
1141 break;
1142 case SEF_SUBTREE_KIND:
1143 if (cur_row >= first_row) {
1144 DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
1145 DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
1147 cur_row++;
1148 if (!this->d.sub.folded) {
1149 if (this->flags & SEF_LAST_FIELD) {
1150 assert(this->level < sizeof(parent_last));
1151 SetBit(parent_last, this->level); // Add own last-field state
1154 cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, selected, cur_row, parent_last);
1156 break;
1157 default: NOT_REACHED();
1159 return cur_row;
1162 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
1164 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
1165 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
1166 return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
1167 } else {
1168 return GetVariableAddress(&_settings_client.company, &sd->save);
1170 } else {
1171 return GetVariableAddress(settings_ptr, &sd->save);
1176 * Set the DParams for drawing the value of a setting.
1177 * @param first_param First DParam to use
1178 * @param value Setting value to set params for.
1180 void SettingEntry::SetValueDParams(uint first_param, int32 value)
1182 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
1183 const SettingDescBase *sdb = &this->d.entry.setting->desc;
1184 if (sdb->cmd == SDT_BOOLX) {
1185 SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
1186 } else {
1187 if ((sdb->flags & SGF_MULTISTRING) != 0) {
1188 SetDParam(first_param++, sdb->str_val - sdb->min + value);
1189 } else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
1190 SetDParam(first_param++, sdb->str_val + ((value >= 0) ? 1 : 0));
1191 value = abs(value);
1192 } else {
1193 SetDParam(first_param++, sdb->str_val + ((value == 0 && (sdb->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
1195 SetDParam(first_param++, value);
1200 * Private function to draw setting value (button + text + current value)
1201 * @param settings_ptr Pointer to current values of all settings
1202 * @param left Left-most position in window/panel to start drawing
1203 * @param right Right-most position in window/panel to draw
1204 * @param y Upper-most position in window/panel to start drawing
1205 * @param state State of the left + right arrow buttons to draw for the setting
1206 * @param highlight Highlight entry.
1208 void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, int state, bool highlight)
1210 const SettingDesc *sd = this->d.entry.setting;
1211 const SettingDescBase *sdb = &sd->desc;
1212 const void *var = ResolveVariableAddress(settings_ptr, sd);
1214 bool rtl = _current_text_dir == TD_RTL;
1215 uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
1216 uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + 5);
1217 uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + 5 : 0);
1218 uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
1220 /* We do not allow changes of some items when we are a client in a networkgame */
1221 bool editable = sd->IsEditable();
1223 SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
1224 int32 value = (int32)ReadValue(var, sd->save.conv);
1225 if (sdb->cmd == SDT_BOOLX) {
1226 /* Draw checkbox for boolean-value either on/off */
1227 DrawBoolButton(buttons_left, button_y, value != 0, editable);
1228 } else if ((sdb->flags & SGF_MULTISTRING) != 0) {
1229 /* Draw [v] button for settings of an enum-type */
1230 DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
1231 } else {
1232 /* Draw [<][>] boxes for settings of an integer-type */
1233 DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
1234 editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
1236 this->SetValueDParams(1, value);
1237 DrawString(text_left, text_right, y, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
1241 /* == SettingsPage methods == */
1244 * Initialization of an entire setting page
1245 * @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
1247 void SettingsPage::Init(byte level)
1249 for (uint field = 0; field < this->num; field++) {
1250 this->entries[field].Init(level);
1254 /** Recursively close all folds of sub-pages */
1255 void SettingsPage::FoldAll()
1257 for (uint field = 0; field < this->num; field++) {
1258 this->entries[field].FoldAll();
1262 /** Recursively open all folds of sub-pages */
1263 void SettingsPage::UnFoldAll()
1265 for (uint field = 0; field < this->num; field++) {
1266 this->entries[field].UnFoldAll();
1271 * Recursively accumulate the folding state of the tree.
1272 * @param[in,out] all_folded Set to false, if one entry is not folded.
1273 * @param[in,out] all_unfolded Set to false, if one entry is folded.
1275 void SettingsPage::GetFoldingState(bool &all_folded, bool &all_unfolded) const
1277 for (uint field = 0; field < this->num; field++) {
1278 this->entries[field].GetFoldingState(all_folded, all_unfolded);
1283 * Update the filter state.
1284 * @param filter Filter
1285 * @param force_visible Whether to force all items visible, no matter what
1286 * @return true if item remains visible
1288 bool SettingsPage::UpdateFilterState(SettingFilter &filter, bool force_visible)
1290 bool visible = false;
1291 bool first_visible = true;
1292 for (int field = this->num - 1; field >= 0; field--) {
1293 visible |= this->entries[field].UpdateFilterState(filter, force_visible);
1294 this->entries[field].SetLastField(first_visible);
1295 if (visible && first_visible) first_visible = false;
1297 return visible;
1302 * Check whether an entry is visible and not folded or filtered away.
1303 * Note: This does not consider the scrolling range; it might still require scrolling ot make the setting really visible.
1304 * @param item Entry to search for.
1305 * @return true if entry is visible.
1307 bool SettingsPage::IsVisible(const SettingEntry *item) const
1309 for (uint field = 0; field < this->num; field++) {
1310 if (this->entries[field].IsVisible(item)) return true;
1312 return false;
1315 /** Return number of rows needed to display the whole page */
1316 uint SettingsPage::Length() const
1318 uint length = 0;
1319 for (uint field = 0; field < this->num; field++) {
1320 length += this->entries[field].Length();
1322 return length;
1326 * Find the setting entry at row number \a row_num
1327 * @param row_num Index of entry to return
1328 * @param cur_row Variable used for keeping track of the current row number. Should point to memory initialized to \c 0 when first called.
1329 * @return The requested setting entry or \c NULL if it does not exist
1331 SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
1333 SettingEntry *pe = NULL;
1335 for (uint field = 0; field < this->num; field++) {
1336 pe = this->entries[field].FindEntry(row_num, cur_row);
1337 if (pe != NULL) {
1338 break;
1341 return pe;
1345 * Get the biggest height of the help texts, if the width is at least \a maxw. Help text gets wrapped if needed.
1346 * @param maxw Maximal width of a line help text.
1347 * @return Biggest height needed to display any help text of this (sub-)tree.
1349 uint SettingsPage::GetMaxHelpHeight(int maxw)
1351 uint biggest = 0;
1352 for (uint field = 0; field < this->num; field++) {
1353 biggest = max(biggest, this->entries[field].GetMaxHelpHeight(maxw));
1355 return biggest;
1359 * Draw a selected part of the settings page.
1361 * The scrollbar uses rows of the page, while the page data structure is a tree of #SettingsPage and #SettingEntry objects.
1362 * As a result, the drawing routing traverses the tree from top to bottom, counting rows in \a cur_row until it reaches \a first_row.
1363 * Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
1365 * @param settings_ptr Pointer to current values of all settings
1366 * @param left Left-most position in window/panel to start drawing of each setting row
1367 * @param right Right-most position in window/panel to draw at
1368 * @param base_y Upper-most position in window/panel to start drawing of row number \a first_row
1369 * @param first_row Number of first row to draw
1370 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1371 * @param cur_row Current row number (internal variable)
1372 * @param parent_last Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
1373 * @param selected Selected entry by the user.
1374 * @return Row number of the next row to draw
1376 uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int base_y, uint first_row, uint max_row, SettingEntry *selected, uint cur_row, uint parent_last) const
1378 if (cur_row >= max_row) return cur_row;
1380 for (uint i = 0; i < this->num; i++) {
1381 cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last, selected);
1382 if (cur_row >= max_row) {
1383 break;
1386 return cur_row;
1390 static SettingEntry _settings_ui_localisation[] = {
1391 SettingEntry("locale.units_velocity"),
1392 SettingEntry("locale.units_power"),
1393 SettingEntry("locale.units_weight"),
1394 SettingEntry("locale.units_volume"),
1395 SettingEntry("locale.units_force"),
1396 SettingEntry("locale.units_height"),
1398 /** Localisation options sub-page */
1399 static SettingsPage _settings_ui_localisation_page = {_settings_ui_localisation, lengthof(_settings_ui_localisation)};
1401 static SettingEntry _settings_ui_display[] = {
1402 SettingEntry("gui.date_format_in_default_names"),
1403 SettingEntry("gui.population_in_label"),
1404 SettingEntry("gui.measure_tooltip"),
1405 SettingEntry("gui.loading_indicators"),
1406 SettingEntry("gui.liveries"),
1407 SettingEntry("gui.show_track_reservation"),
1408 SettingEntry("gui.expenses_layout"),
1409 SettingEntry("gui.smallmap_land_colour"),
1410 SettingEntry("gui.zoom_min"),
1411 SettingEntry("gui.zoom_max"),
1412 SettingEntry("gui.graph_line_thickness"),
1414 /** Display options sub-page */
1415 static SettingsPage _settings_ui_display_page = {_settings_ui_display, lengthof(_settings_ui_display)};
1417 static SettingEntry _settings_ui_interaction[] = {
1418 SettingEntry("gui.window_snap_radius"),
1419 SettingEntry("gui.window_soft_limit"),
1420 SettingEntry("gui.link_terraform_toolbar"),
1421 SettingEntry("gui.prefer_teamchat"),
1422 SettingEntry("gui.auto_scrolling"),
1423 SettingEntry("gui.reverse_scroll"),
1424 SettingEntry("gui.smooth_scroll"),
1425 SettingEntry("gui.left_mouse_btn_scrolling"),
1426 /* While the horizontal scrollwheel scrolling is written as general code, only
1427 * the cocoa (OSX) driver generates input for it.
1428 * Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
1429 SettingEntry("gui.scrollwheel_scrolling"),
1430 SettingEntry("gui.scrollwheel_multiplier"),
1431 SettingEntry("gui.osk_activation"),
1432 #ifdef __APPLE__
1433 /* We might need to emulate a right mouse button on mac */
1434 SettingEntry("gui.right_mouse_btn_emulation"),
1435 #endif
1437 /** Interaction sub-page */
1438 static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)};
1440 static SettingEntry _settings_ui_sound[] = {
1441 SettingEntry("sound.click_beep"),
1442 SettingEntry("sound.confirm"),
1443 SettingEntry("sound.news_ticker"),
1444 SettingEntry("sound.news_full"),
1445 SettingEntry("sound.new_year"),
1446 SettingEntry("sound.disaster"),
1447 SettingEntry("sound.vehicle"),
1448 SettingEntry("sound.ambient"),
1450 /** Sound effects sub-page */
1451 static SettingsPage _settings_ui_sound_page = {_settings_ui_sound, lengthof(_settings_ui_sound)};
1453 static SettingEntry _settings_ui_news[] = {
1454 SettingEntry("news_display.arrival_player"),
1455 SettingEntry("news_display.arrival_other"),
1456 SettingEntry("news_display.accident"),
1457 SettingEntry("news_display.company_info"),
1458 SettingEntry("news_display.open"),
1459 SettingEntry("news_display.close"),
1460 SettingEntry("news_display.economy"),
1461 SettingEntry("news_display.production_player"),
1462 SettingEntry("news_display.production_other"),
1463 SettingEntry("news_display.production_nobody"),
1464 SettingEntry("news_display.advice"),
1465 SettingEntry("news_display.new_vehicles"),
1466 SettingEntry("news_display.acceptance"),
1467 SettingEntry("news_display.subsidies"),
1468 SettingEntry("news_display.general"),
1469 SettingEntry("gui.coloured_news_year"),
1471 /** News sub-page */
1472 static SettingsPage _settings_ui_news_page = {_settings_ui_news, lengthof(_settings_ui_news)};
1474 static SettingEntry _settings_ui[] = {
1475 SettingEntry(&_settings_ui_localisation_page, STR_CONFIG_SETTING_LOCALISATION),
1476 SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS),
1477 SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION),
1478 SettingEntry(&_settings_ui_sound_page, STR_CONFIG_SETTING_SOUND),
1479 SettingEntry(&_settings_ui_news_page, STR_CONFIG_SETTING_NEWS),
1480 SettingEntry("gui.show_finances"),
1481 SettingEntry("gui.errmsg_duration"),
1482 SettingEntry("gui.hover_delay"),
1483 SettingEntry("gui.toolbar_pos"),
1484 SettingEntry("gui.statusbar_pos"),
1485 SettingEntry("gui.newgrf_default_palette"),
1486 SettingEntry("gui.pause_on_newgame"),
1487 SettingEntry("gui.advanced_vehicle_list"),
1488 SettingEntry("gui.timetable_in_ticks"),
1489 SettingEntry("gui.timetable_arrival_departure"),
1490 SettingEntry("gui.quick_goto"),
1491 SettingEntry("gui.default_rail_type"),
1492 SettingEntry("gui.disable_unsuitable_building"),
1493 SettingEntry("gui.persistent_buildingtools"),
1495 /** Interface subpage */
1496 static SettingsPage _settings_ui_page = {_settings_ui, lengthof(_settings_ui)};
1498 static SettingEntry _settings_construction_signals[] = {
1499 SettingEntry("construction.train_signal_side"),
1500 SettingEntry("gui.enable_signal_gui"),
1501 SettingEntry("gui.drag_signals_fixed_distance"),
1502 SettingEntry("gui.semaphore_build_before"),
1503 SettingEntry("gui.default_signal_type"),
1504 SettingEntry("gui.cycle_signal_types"),
1506 /** Signals subpage */
1507 static SettingsPage _settings_construction_signals_page = {_settings_construction_signals, lengthof(_settings_construction_signals)};
1509 static SettingEntry _settings_construction[] = {
1510 SettingEntry(&_settings_construction_signals_page, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS),
1511 SettingEntry("construction.build_on_slopes"),
1512 SettingEntry("construction.autoslope"),
1513 SettingEntry("construction.extra_dynamite"),
1514 SettingEntry("construction.max_bridge_length"),
1515 SettingEntry("construction.max_tunnel_length"),
1516 SettingEntry("station.never_expire_airports"),
1517 SettingEntry("construction.freeform_edges"),
1518 SettingEntry("construction.extra_tree_placement"),
1519 SettingEntry("construction.command_pause_level"),
1521 /** Construction sub-page */
1522 static SettingsPage _settings_construction_page = {_settings_construction, lengthof(_settings_construction)};
1524 static SettingEntry _settings_stations_cargo[] = {
1525 SettingEntry("order.improved_load"),
1526 SettingEntry("order.gradual_loading"),
1527 SettingEntry("order.selectgoods"),
1529 /** Cargo handling sub-page */
1530 static SettingsPage _settings_stations_cargo_page = {_settings_stations_cargo, lengthof(_settings_stations_cargo)};
1532 static SettingEntry _settings_stations[] = {
1533 SettingEntry(&_settings_stations_cargo_page, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING),
1534 SettingEntry("station.adjacent_stations"),
1535 SettingEntry("station.distant_join_stations"),
1536 SettingEntry("station.station_spread"),
1537 SettingEntry("economy.station_noise_level"),
1538 SettingEntry("station.modified_catchment"),
1539 SettingEntry("construction.road_stop_on_town_road"),
1540 SettingEntry("construction.road_stop_on_competitor_road"),
1542 /** Stations sub-page */
1543 static SettingsPage _settings_stations_page = {_settings_stations, lengthof(_settings_stations)};
1545 static SettingEntry _settings_economy_towns[] = {
1546 SettingEntry("difficulty.town_council_tolerance"),
1547 SettingEntry("economy.bribe"),
1548 SettingEntry("economy.exclusive_rights"),
1549 SettingEntry("economy.fund_roads"),
1550 SettingEntry("economy.fund_buildings"),
1551 SettingEntry("economy.town_layout"),
1552 SettingEntry("economy.allow_town_roads"),
1553 SettingEntry("economy.allow_town_level_crossings"),
1554 SettingEntry("economy.found_town"),
1555 SettingEntry("economy.mod_road_rebuild"),
1556 SettingEntry("economy.town_growth_rate"),
1557 SettingEntry("economy.larger_towns"),
1558 SettingEntry("economy.initial_city_size"),
1560 /** Towns sub-page */
1561 static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
1563 static SettingEntry _settings_economy_industries[] = {
1564 SettingEntry("construction.raw_industry_construction"),
1565 SettingEntry("construction.industry_platform"),
1566 SettingEntry("economy.multiple_industry_per_town"),
1567 SettingEntry("game_creation.oil_refinery_limit"),
1569 /** Industries sub-page */
1570 static SettingsPage _settings_economy_industries_page = {_settings_economy_industries, lengthof(_settings_economy_industries)};
1573 static SettingEntry _settings_economy[] = {
1574 SettingEntry(&_settings_economy_towns_page, STR_CONFIG_SETTING_ECONOMY_TOWNS),
1575 SettingEntry(&_settings_economy_industries_page, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES),
1576 SettingEntry("economy.inflation"),
1577 SettingEntry("difficulty.initial_interest"),
1578 SettingEntry("difficulty.max_loan"),
1579 SettingEntry("difficulty.subsidy_multiplier"),
1580 SettingEntry("difficulty.economy"),
1581 SettingEntry("economy.smooth_economy"),
1582 SettingEntry("economy.feeder_payment_share"),
1583 SettingEntry("economy.infrastructure_maintenance"),
1584 SettingEntry("difficulty.vehicle_costs"),
1585 SettingEntry("difficulty.construction_cost"),
1586 SettingEntry("difficulty.disasters"),
1588 /** Economy sub-page */
1589 static SettingsPage _settings_economy_page = {_settings_economy, lengthof(_settings_economy)};
1591 static SettingEntry _settings_linkgraph[] = {
1592 SettingEntry("linkgraph.recalc_time"),
1593 SettingEntry("linkgraph.recalc_interval"),
1594 SettingEntry("linkgraph.distribution_pax"),
1595 SettingEntry("linkgraph.distribution_mail"),
1596 SettingEntry("linkgraph.distribution_armoured"),
1597 SettingEntry("linkgraph.distribution_default"),
1598 SettingEntry("linkgraph.accuracy"),
1599 SettingEntry("linkgraph.demand_distance"),
1600 SettingEntry("linkgraph.demand_size"),
1601 SettingEntry("linkgraph.short_path_saturation"),
1603 /** Linkgraph sub-page */
1604 static SettingsPage _settings_linkgraph_page = {_settings_linkgraph, lengthof(_settings_linkgraph)};
1606 static SettingEntry _settings_ai_npc[] = {
1607 SettingEntry("script.settings_profile"),
1608 SettingEntry("script.script_max_opcode_till_suspend"),
1609 SettingEntry("difficulty.competitor_speed"),
1610 SettingEntry("ai.ai_in_multiplayer"),
1611 SettingEntry("ai.ai_disable_veh_train"),
1612 SettingEntry("ai.ai_disable_veh_roadveh"),
1613 SettingEntry("ai.ai_disable_veh_aircraft"),
1614 SettingEntry("ai.ai_disable_veh_ship"),
1616 /** Computer players sub-page */
1617 static SettingsPage _settings_ai_npc_page = {_settings_ai_npc, lengthof(_settings_ai_npc)};
1619 static SettingEntry _settings_ai[] = {
1620 SettingEntry(&_settings_ai_npc_page, STR_CONFIG_SETTING_AI_NPC),
1621 SettingEntry("economy.give_money"),
1622 SettingEntry("economy.allow_shares"),
1624 /** AI sub-page */
1625 static SettingsPage _settings_ai_page = {_settings_ai, lengthof(_settings_ai)};
1627 static SettingEntry _settings_vehicles_routing[] = {
1628 SettingEntry("pf.pathfinder_for_trains"),
1629 SettingEntry("pf.forbid_90_deg"),
1630 SettingEntry("pf.pathfinder_for_roadvehs"),
1631 SettingEntry("pf.roadveh_queue"),
1632 SettingEntry("pf.pathfinder_for_ships"),
1634 /** Autorenew sub-page */
1635 static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
1637 static SettingEntry _settings_vehicles_autorenew[] = {
1638 SettingEntry("company.engine_renew"),
1639 SettingEntry("company.engine_renew_months"),
1640 SettingEntry("company.engine_renew_money"),
1642 /** Autorenew sub-page */
1643 static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
1645 static SettingEntry _settings_vehicles_servicing[] = {
1646 SettingEntry("vehicle.servint_ispercent"),
1647 SettingEntry("vehicle.servint_trains"),
1648 SettingEntry("vehicle.servint_roadveh"),
1649 SettingEntry("vehicle.servint_ships"),
1650 SettingEntry("vehicle.servint_aircraft"),
1651 SettingEntry("difficulty.vehicle_breakdowns"),
1652 SettingEntry("order.no_servicing_if_no_breakdowns"),
1653 SettingEntry("order.serviceathelipad"),
1655 /** Servicing sub-page */
1656 static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)};
1658 static SettingEntry _settings_vehicles_trains[] = {
1659 SettingEntry("difficulty.line_reverse_mode"),
1660 SettingEntry("pf.reverse_at_signals"),
1661 SettingEntry("vehicle.train_acceleration_model"),
1662 SettingEntry("vehicle.train_slope_steepness"),
1663 SettingEntry("vehicle.max_train_length"),
1664 SettingEntry("vehicle.wagon_speed_limits"),
1665 SettingEntry("vehicle.disable_elrails"),
1666 SettingEntry("vehicle.freight_trains"),
1667 SettingEntry("gui.stop_location"),
1669 /** Trains sub-page */
1670 static SettingsPage _settings_vehicles_trains_page = {_settings_vehicles_trains, lengthof(_settings_vehicles_trains)};
1672 static SettingEntry _settings_vehicles[] = {
1673 SettingEntry(&_settings_vehicles_routing_page, STR_CONFIG_SETTING_VEHICLES_ROUTING),
1674 SettingEntry(&_settings_vehicles_autorenew_page, STR_CONFIG_SETTING_VEHICLES_AUTORENEW),
1675 SettingEntry(&_settings_vehicles_servicing_page, STR_CONFIG_SETTING_VEHICLES_SERVICING),
1676 SettingEntry(&_settings_vehicles_trains_page, STR_CONFIG_SETTING_VEHICLES_TRAINS),
1677 SettingEntry("gui.new_nonstop"),
1678 SettingEntry("gui.order_review_system"),
1679 SettingEntry("gui.vehicle_income_warn"),
1680 SettingEntry("gui.lost_vehicle_warn"),
1681 SettingEntry("vehicle.never_expire_vehicles"),
1682 SettingEntry("vehicle.max_trains"),
1683 SettingEntry("vehicle.max_roadveh"),
1684 SettingEntry("vehicle.max_aircraft"),
1685 SettingEntry("vehicle.max_ships"),
1686 SettingEntry("vehicle.plane_speed"),
1687 SettingEntry("vehicle.plane_crashes"),
1688 SettingEntry("vehicle.dynamic_engines"),
1689 SettingEntry("vehicle.roadveh_acceleration_model"),
1690 SettingEntry("vehicle.roadveh_slope_steepness"),
1691 SettingEntry("vehicle.smoke_amount"),
1693 /** Vehicles sub-page */
1694 static SettingsPage _settings_vehicles_page = {_settings_vehicles, lengthof(_settings_vehicles)};
1696 static SettingEntry _settings_main[] = {
1697 SettingEntry(&_settings_ui_page, STR_CONFIG_SETTING_GUI),
1698 SettingEntry(&_settings_construction_page, STR_CONFIG_SETTING_CONSTRUCTION),
1699 SettingEntry(&_settings_vehicles_page, STR_CONFIG_SETTING_VEHICLES),
1700 SettingEntry(&_settings_stations_page, STR_CONFIG_SETTING_STATIONS),
1701 SettingEntry(&_settings_economy_page, STR_CONFIG_SETTING_ECONOMY),
1702 SettingEntry(&_settings_linkgraph_page, STR_CONFIG_SETTING_LINKGRAPH),
1703 SettingEntry(&_settings_ai_page, STR_CONFIG_SETTING_AI),
1706 /** Main page, holding all advanced settings */
1707 static SettingsPage _settings_main_page = {_settings_main, lengthof(_settings_main)};
1709 static const StringID _game_settings_restrict_dropdown[] = {
1710 STR_CONFIG_SETTING_RESTRICT_BASIC, // RM_BASIC
1711 STR_CONFIG_SETTING_RESTRICT_ADVANCED, // RM_ADVANCED
1712 STR_CONFIG_SETTING_RESTRICT_ALL, // RM_ALL
1713 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT, // RM_CHANGED_AGAINST_DEFAULT
1714 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW, // RM_CHANGED_AGAINST_NEW
1716 assert_compile(lengthof(_game_settings_restrict_dropdown) == RM_END);
1718 struct GameSettingsWindow : Window {
1719 static const int SETTINGTREE_LEFT_OFFSET = 5; ///< Position of left edge of setting values
1720 static const int SETTINGTREE_RIGHT_OFFSET = 5; ///< Position of right edge of setting values
1721 static const int SETTINGTREE_TOP_OFFSET = 5; ///< Position of top edge of setting values
1722 static const int SETTINGTREE_BOTTOM_OFFSET = 5; ///< Position of bottom edge of setting values
1724 static GameSettings *settings_ptr; ///< Pointer to the game settings being displayed and modified.
1726 SettingEntry *valuewindow_entry; ///< If non-NULL, pointer to setting for which a value-entering window has been opened.
1727 SettingEntry *clicked_entry; ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button).
1728 SettingEntry *last_clicked; ///< If non-NULL, pointer to the last clicked setting.
1729 SettingEntry *valuedropdown_entry; ///< If non-NULL, pointer to the value for which a dropdown window is currently opened.
1730 bool closing_dropdown; ///< True, if the dropdown list is currently closing.
1732 SettingFilter filter; ///< Filter for the list.
1733 QueryString filter_editbox; ///< Filter editbox;
1734 bool manually_changed_folding; ///< Whether the user expanded/collapsed something manually.
1736 Scrollbar *vscroll;
1738 GameSettingsWindow(WindowDesc *desc) : Window(desc), filter_editbox(50)
1740 static bool first_time = true;
1742 filter.mode = (RestrictionMode)_settings_client.gui.settings_restriction_mode;
1743 filter.type = ST_ALL;
1744 settings_ptr = &GetGameSettings();
1746 /* Build up the dynamic settings-array only once per OpenTTD session */
1747 if (first_time) {
1748 _settings_main_page.Init();
1749 first_time = false;
1750 } else {
1751 _settings_main_page.FoldAll(); // Close all sub-pages
1754 this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
1755 this->clicked_entry = NULL; // No numeric setting buttons are depressed
1756 this->last_clicked = NULL;
1757 this->valuedropdown_entry = NULL;
1758 this->closing_dropdown = false;
1759 this->manually_changed_folding = false;
1761 this->CreateNestedTree();
1762 this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
1763 this->FinishInitNested(WN_GAME_OPTIONS_GAME_SETTINGS);
1765 this->querystrings[WID_GS_FILTER] = &this->filter_editbox;
1766 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
1767 this->SetFocusedWidget(WID_GS_FILTER);
1769 this->InvalidateData();
1772 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1774 switch (widget) {
1775 case WID_GS_OPTIONSPANEL:
1776 resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1);
1777 resize->width = 1;
1779 size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET;
1780 break;
1782 case WID_GS_HELP_TEXT: {
1783 static const StringID setting_types[] = {
1784 STR_CONFIG_SETTING_TYPE_CLIENT,
1785 STR_CONFIG_SETTING_TYPE_COMPANY_MENU, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME,
1786 STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
1788 for (uint i = 0; i < lengthof(setting_types); i++) {
1789 SetDParam(0, setting_types[i]);
1790 size->width = max(size->width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width);
1792 size->height = 2 * FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL +
1793 max(size->height, _settings_main_page.GetMaxHelpHeight(size->width));
1794 break;
1797 default:
1798 break;
1802 virtual void OnPaint()
1804 if (this->closing_dropdown) {
1805 this->closing_dropdown = false;
1806 assert(this->valuedropdown_entry != NULL);
1807 this->valuedropdown_entry->SetButtons(0);
1808 this->valuedropdown_entry = NULL;
1810 this->DrawWidgets();
1813 virtual void SetStringParameters(int widget) const
1815 switch (widget) {
1816 case WID_GS_RESTRICT_DROPDOWN:
1817 SetDParam(0, _game_settings_restrict_dropdown[this->filter.mode]);
1818 break;
1820 case WID_GS_TYPE_DROPDOWN:
1821 switch (this->filter.type) {
1822 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME); break;
1823 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME); break;
1824 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT); break;
1825 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL); break;
1827 break;
1831 DropDownList *BuildDropDownList(int widget) const
1833 DropDownList *list = NULL;
1834 switch (widget) {
1835 case WID_GS_RESTRICT_DROPDOWN:
1836 list = new DropDownList();
1838 for (int mode = 0; mode != RM_END; mode++) {
1839 /* If we are in adv. settings screen for the new game's settings,
1840 * we don't want to allow comparing with new game's settings. */
1841 bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame;
1843 list->push_back(new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled));
1845 break;
1847 case WID_GS_TYPE_DROPDOWN:
1848 list = new DropDownList();
1849 list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false));
1850 list->push_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME, false));
1851 list->push_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY, false));
1852 list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false));
1853 break;
1855 return list;
1858 virtual void DrawWidget(const Rect &r, int widget) const
1860 switch (widget) {
1861 case WID_GS_OPTIONSPANEL:
1862 _settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
1863 this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->last_clicked);
1864 break;
1866 case WID_GS_HELP_TEXT:
1867 if (this->last_clicked != NULL) {
1868 const SettingDesc *sd = this->last_clicked->d.entry.setting;
1870 int y = r.top;
1871 switch (sd->GetType()) {
1872 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
1873 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT); break;
1874 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
1875 default: NOT_REACHED();
1877 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
1878 y += FONT_HEIGHT_NORMAL;
1880 int32 default_value = ReadValue(&sd->desc.def, sd->save.conv);
1881 this->last_clicked->SetValueDParams(0, default_value);
1882 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
1883 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
1885 DrawStringMultiLine(r.left, r.right, y, r.bottom, this->last_clicked->GetHelpText(), TC_WHITE);
1887 break;
1889 default:
1890 break;
1895 * Set the entry that should have its help text displayed, and mark the window dirty so it gets repainted.
1896 * @param pe Setting to display help text of, use \c NULL to stop displaying help of the currently displayed setting.
1898 void SetDisplayedHelpText(SettingEntry *pe)
1900 if (this->last_clicked != pe) this->SetDirty();
1901 this->last_clicked = pe;
1904 virtual void OnClick(Point pt, int widget, int click_count)
1906 switch (widget) {
1907 case WID_GS_EXPAND_ALL:
1908 this->manually_changed_folding = true;
1909 _settings_main_page.UnFoldAll();
1910 this->InvalidateData();
1911 break;
1913 case WID_GS_COLLAPSE_ALL:
1914 this->manually_changed_folding = true;
1915 _settings_main_page.FoldAll();
1916 this->InvalidateData();
1917 break;
1919 case WID_GS_RESTRICT_DROPDOWN: {
1920 DropDownList *list = this->BuildDropDownList(widget);
1921 if (list != NULL) {
1922 ShowDropDownList(this, list, this->filter.mode, widget);
1924 break;
1927 case WID_GS_TYPE_DROPDOWN: {
1928 DropDownList *list = this->BuildDropDownList(widget);
1929 if (list != NULL) {
1930 ShowDropDownList(this, list, this->filter.type, widget);
1932 break;
1936 if (widget != WID_GS_OPTIONSPANEL) return;
1938 uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET);
1939 if (btn == INT_MAX) return;
1941 uint cur_row = 0;
1942 SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
1944 if (pe == NULL) return; // Clicked below the last setting of the page
1946 int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (pe->level + 1) * LEVEL_WIDTH; // Shift x coordinate
1947 if (x < 0) return; // Clicked left of the entry
1949 if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
1950 this->SetDisplayedHelpText(NULL);
1951 pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
1953 this->manually_changed_folding = true;
1955 this->InvalidateData();
1956 return;
1959 assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
1960 const SettingDesc *sd = pe->d.entry.setting;
1962 /* return if action is only active in network, or only settable by server */
1963 if (!sd->IsEditable()) {
1964 this->SetDisplayedHelpText(pe);
1965 return;
1968 const void *var = ResolveVariableAddress(settings_ptr, sd);
1969 int32 value = (int32)ReadValue(var, sd->save.conv);
1971 /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
1972 if (x < SETTING_BUTTON_WIDTH && (sd->desc.flags & SGF_MULTISTRING)) {
1973 const SettingDescBase *sdb = &sd->desc;
1974 this->SetDisplayedHelpText(pe);
1976 if (this->valuedropdown_entry == pe) {
1977 /* unclick the dropdown */
1978 HideDropDownMenu(this);
1979 this->closing_dropdown = false;
1980 this->valuedropdown_entry->SetButtons(0);
1981 this->valuedropdown_entry = NULL;
1982 } else {
1983 if (this->valuedropdown_entry != NULL) this->valuedropdown_entry->SetButtons(0);
1984 this->closing_dropdown = false;
1986 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
1987 int rel_y = (pt.y - (int)wid->pos_y - SETTINGTREE_TOP_OFFSET) % wid->resize_y;
1989 Rect wi_rect;
1990 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
1991 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
1992 wi_rect.top = pt.y - rel_y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
1993 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
1995 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
1996 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
1997 this->valuedropdown_entry = pe;
1998 this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
2000 DropDownList *list = new DropDownList();
2001 for (int i = sdb->min; i <= (int)sdb->max; i++) {
2002 list->push_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false));
2005 ShowDropDownListAt(this, list, value, -1, wi_rect, COLOUR_ORANGE, true);
2008 this->SetDirty();
2009 } else if (x < SETTING_BUTTON_WIDTH) {
2010 this->SetDisplayedHelpText(pe);
2011 const SettingDescBase *sdb = &sd->desc;
2012 int32 oldvalue = value;
2014 switch (sdb->cmd) {
2015 case SDT_BOOLX: value ^= 1; break;
2016 case SDT_ONEOFMANY:
2017 case SDT_NUMX: {
2018 /* Add a dynamic step-size to the scroller. In a maximum of
2019 * 50-steps you should be able to get from min to max,
2020 * unless specified otherwise in the 'interval' variable
2021 * of the current setting. */
2022 uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
2023 if (step == 0) step = 1;
2025 /* don't allow too fast scrolling */
2026 if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
2027 _left_button_clicked = false;
2028 return;
2031 /* Increase or decrease the value and clamp it to extremes */
2032 if (x >= SETTING_BUTTON_WIDTH / 2) {
2033 value += step;
2034 if (sdb->min < 0) {
2035 assert((int32)sdb->max >= 0);
2036 if (value > (int32)sdb->max) value = (int32)sdb->max;
2037 } else {
2038 if ((uint32)value > sdb->max) value = (int32)sdb->max;
2040 if (value < sdb->min) value = sdb->min; // skip between "disabled" and minimum
2041 } else {
2042 value -= step;
2043 if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
2046 /* Set up scroller timeout for numeric values */
2047 if (value != oldvalue) {
2048 if (this->clicked_entry != NULL) { // Release previous buttons if any
2049 this->clicked_entry->SetButtons(0);
2051 this->clicked_entry = pe;
2052 this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
2053 this->SetTimeout();
2054 _left_button_clicked = false;
2056 break;
2059 default: NOT_REACHED();
2062 if (value != oldvalue) {
2063 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2064 SetCompanySetting(pe->d.entry.index, value);
2065 } else {
2066 SetSettingValue(pe->d.entry.index, value);
2068 this->SetDirty();
2070 } else {
2071 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
2072 if (this->last_clicked == pe && sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
2073 /* Show the correct currency-translated value */
2074 if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
2076 this->valuewindow_entry = pe;
2077 SetDParam(0, value);
2078 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
2080 this->SetDisplayedHelpText(pe);
2084 virtual void OnTimeout()
2086 if (this->clicked_entry != NULL) { // On timeout, release any depressed buttons
2087 this->clicked_entry->SetButtons(0);
2088 this->clicked_entry = NULL;
2089 this->SetDirty();
2093 virtual void OnQueryTextFinished(char *str)
2095 /* The user pressed cancel */
2096 if (str == NULL) return;
2098 assert(this->valuewindow_entry != NULL);
2099 assert((this->valuewindow_entry->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
2100 const SettingDesc *sd = this->valuewindow_entry->d.entry.setting;
2102 int32 value;
2103 if (!StrEmpty(str)) {
2104 value = atoi(str);
2106 /* Save the correct currency-translated value */
2107 if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
2108 } else {
2109 value = (int32)(size_t)sd->desc.def;
2112 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2113 SetCompanySetting(this->valuewindow_entry->d.entry.index, value);
2114 } else {
2115 SetSettingValue(this->valuewindow_entry->d.entry.index, value);
2117 this->SetDirty();
2120 virtual void OnDropdownSelect(int widget, int index)
2122 switch (widget) {
2123 case WID_GS_RESTRICT_DROPDOWN:
2124 this->filter.mode = (RestrictionMode)index;
2125 if (this->filter.mode == RM_CHANGED_AGAINST_DEFAULT ||
2126 this->filter.mode == RM_CHANGED_AGAINST_NEW) {
2128 if (!this->manually_changed_folding) {
2129 /* Expand all when selecting 'changes'. Update the filter state first, in case it becomes less restrictive in some cases. */
2130 _settings_main_page.UpdateFilterState(this->filter, false);
2131 _settings_main_page.UnFoldAll();
2133 } else {
2134 /* Non-'changes' filter. Save as default. */
2135 _settings_client.gui.settings_restriction_mode = this->filter.mode;
2137 this->InvalidateData();
2138 break;
2140 case WID_GS_TYPE_DROPDOWN:
2141 this->filter.type = (SettingType)index;
2142 this->InvalidateData();
2143 break;
2145 default:
2146 if (widget < 0) {
2147 /* Deal with drop down boxes on the panel. */
2148 assert(this->valuedropdown_entry != NULL);
2149 const SettingDesc *sd = this->valuedropdown_entry->d.entry.setting;
2150 assert(sd->desc.flags & SGF_MULTISTRING);
2152 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2153 SetCompanySetting(this->valuedropdown_entry->d.entry.index, index);
2154 } else {
2155 SetSettingValue(this->valuedropdown_entry->d.entry.index, index);
2158 this->SetDirty();
2160 break;
2164 virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
2166 if (widget >= 0) {
2167 /* Normally the default implementation of OnDropdownClose() takes care of
2168 * a few things. We want that behaviour here too, but only for
2169 * "normal" dropdown boxes. The special dropdown boxes added for every
2170 * setting that needs one can't have this call. */
2171 Window::OnDropdownClose(pt, widget, index, instant_close);
2172 } else {
2173 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
2174 * the same dropdown button was clicked again, and then not open the dropdown again.
2175 * So, we only remember that it was closed, and process it on the next OnPaint, which is
2176 * after OnClick. */
2177 assert(this->valuedropdown_entry != NULL);
2178 this->closing_dropdown = true;
2179 this->SetDirty();
2183 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
2185 if (!gui_scope) return;
2187 _settings_main_page.UpdateFilterState(this->filter, false);
2189 this->vscroll->SetCount(_settings_main_page.Length());
2191 if (this->last_clicked != NULL && !_settings_main_page.IsVisible(this->last_clicked)) {
2192 this->SetDisplayedHelpText(NULL);
2195 bool all_folded = true;
2196 bool all_unfolded = true;
2197 _settings_main_page.GetFoldingState(all_folded, all_unfolded);
2198 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL, all_unfolded);
2199 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
2202 virtual void OnEditboxChanged(int wid)
2204 if (wid == WID_GS_FILTER) {
2205 this->filter.string.SetFilterTerm(this->filter_editbox.text.buf);
2206 if (!this->filter.string.IsEmpty() && !this->manually_changed_folding) {
2207 /* User never expanded/collapsed single pages and entered a filter term.
2208 * Expand everything, to save weird expand clicks, */
2209 _settings_main_page.UnFoldAll();
2211 this->InvalidateData();
2215 virtual void OnResize()
2217 this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
2221 GameSettings *GameSettingsWindow::settings_ptr = NULL;
2223 static const NWidgetPart _nested_settings_selection_widgets[] = {
2224 NWidget(NWID_HORIZONTAL),
2225 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
2226 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2227 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
2228 EndContainer(),
2229 NWidget(WWT_PANEL, COLOUR_MAUVE),
2230 NWidget(NWID_HORIZONTAL), SetPadding(WD_TEXTPANEL_TOP, 0, WD_TEXTPANEL_BOTTOM, 0),
2231 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
2232 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_GS_RESTRICT_LABEL), SetDataTip(STR_CONFIG_SETTING_RESTRICT_LABEL, STR_NULL),
2233 NWidget(NWID_VERTICAL), SetPIP(0, WD_PAR_VSEP_NORMAL, 0),
2234 NWidget(WWT_DROPDOWN, COLOUR_MAUVE, WID_GS_RESTRICT_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_BLACK_STRING, STR_CONFIG_SETTING_RESTRICT_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
2235 NWidget(WWT_DROPDOWN, COLOUR_MAUVE, WID_GS_TYPE_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_BLACK_STRING, STR_CONFIG_SETTING_TYPE_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
2236 EndContainer(),
2237 EndContainer(),
2238 NWidget(NWID_HORIZONTAL), SetPadding(0, 0, WD_TEXTPANEL_BOTTOM, 0),
2239 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
2240 NWidget(WWT_TEXT, COLOUR_MAUVE), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE, STR_NULL),
2241 NWidget(WWT_EDITBOX, COLOUR_MAUVE, WID_GS_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
2242 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
2243 EndContainer(),
2244 EndContainer(),
2245 NWidget(NWID_HORIZONTAL),
2246 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
2247 NWidget(NWID_VERTICAL),
2248 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
2249 EndContainer(),
2250 EndContainer(),
2251 NWidget(WWT_PANEL, COLOUR_MAUVE), SetMinimalSize(400, 40),
2252 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GS_HELP_TEXT), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
2253 SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT),
2254 NWidget(NWID_HORIZONTAL),
2255 NWidget(WWT_PANEL, COLOUR_MAUVE),
2256 NWidget(NWID_HORIZONTAL),
2257 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_EXPAND_ALL), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL, STR_NULL),
2258 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_COLLAPSE_ALL), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL, STR_NULL),
2259 NWidget(NWID_SPACER, INVALID_COLOUR), SetFill(1, 1), SetResize(1, 0),
2260 EndContainer(),
2261 EndContainer(),
2262 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
2263 EndContainer(),
2264 EndContainer(),
2267 static WindowDesc _settings_selection_desc(
2268 WDP_CENTER, "settings", 510, 450,
2269 WC_GAME_OPTIONS, WC_NONE,
2271 _nested_settings_selection_widgets, lengthof(_nested_settings_selection_widgets)
2274 /** Open advanced settings window. */
2275 void ShowGameSettings()
2277 DeleteWindowByClass(WC_GAME_OPTIONS);
2278 new GameSettingsWindow(&_settings_selection_desc);
2283 * Draw [<][>] boxes.
2284 * @param x the x position to draw
2285 * @param y the y position to draw
2286 * @param button_colour the colour of the button
2287 * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked
2288 * @param clickable_left is the left button clickable?
2289 * @param clickable_right is the right button clickable?
2291 void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
2293 int colour = _colour_gradient[button_colour][2];
2295 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
2296 DrawFrameRect(x + SETTING_BUTTON_WIDTH / 2, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
2297 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
2298 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + SETTING_BUTTON_WIDTH / 2, y + WD_IMGBTN_TOP);
2300 /* Grey out the buttons that aren't clickable */
2301 bool rtl = _current_text_dir == TD_RTL;
2302 if (rtl ? !clickable_right : !clickable_left) {
2303 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
2305 if (rtl ? !clickable_left : !clickable_right) {
2306 GfxFillRect(x + SETTING_BUTTON_WIDTH / 2 + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
2311 * Draw a dropdown button.
2312 * @param x the x position to draw
2313 * @param y the y position to draw
2314 * @param button_colour the colour of the button
2315 * @param state true = lowered
2316 * @param clickable is the button clickable?
2318 void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
2320 static const char *DOWNARROW = "\xEE\x8A\xAA";
2322 int colour = _colour_gradient[button_colour][2];
2324 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, state ? FR_LOWERED : FR_NONE);
2325 DrawString(x + (state ? 1 : 0), x + SETTING_BUTTON_WIDTH - (state ? 0 : 1), y + (state ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER);
2327 if (!clickable) {
2328 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
2333 * Draw a toggle button.
2334 * @param x the x position to draw
2335 * @param y the y position to draw
2336 * @param state true = lowered
2337 * @param clickable is the button clickable?
2339 void DrawBoolButton(int x, int y, bool state, bool clickable)
2341 static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
2342 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
2345 struct CustomCurrencyWindow : Window {
2346 int query_widget;
2348 CustomCurrencyWindow(WindowDesc *desc) : Window(desc)
2350 this->InitNested();
2352 SetButtonState();
2355 void SetButtonState()
2357 this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1);
2358 this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX);
2359 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
2360 this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
2363 virtual void SetStringParameters(int widget) const
2365 switch (widget) {
2366 case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
2367 case WID_CC_SEPARATOR: SetDParamStr(0, _custom_currency.separator); break;
2368 case WID_CC_PREFIX: SetDParamStr(0, _custom_currency.prefix); break;
2369 case WID_CC_SUFFIX: SetDParamStr(0, _custom_currency.suffix); break;
2370 case WID_CC_YEAR:
2371 SetDParam(0, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
2372 SetDParam(1, _custom_currency.to_euro);
2373 break;
2375 case WID_CC_PREVIEW:
2376 SetDParam(0, 10000);
2377 break;
2381 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
2383 switch (widget) {
2384 /* Set the appropriate width for the edit 'buttons' */
2385 case WID_CC_SEPARATOR_EDIT:
2386 case WID_CC_PREFIX_EDIT:
2387 case WID_CC_SUFFIX_EDIT:
2388 size->width = this->GetWidget<NWidgetBase>(WID_CC_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(WID_CC_RATE_UP)->smallest_x;
2389 break;
2391 /* Make sure the window is wide enough for the widest exchange rate */
2392 case WID_CC_RATE:
2393 SetDParam(0, 1);
2394 SetDParam(1, INT32_MAX);
2395 *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
2396 break;
2400 virtual void OnClick(Point pt, int widget, int click_count)
2402 int line = 0;
2403 int len = 0;
2404 StringID str = 0;
2405 CharSetFilter afilter = CS_ALPHANUMERAL;
2407 switch (widget) {
2408 case WID_CC_RATE_DOWN:
2409 if (_custom_currency.rate > 1) _custom_currency.rate--;
2410 if (_custom_currency.rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
2411 this->EnableWidget(WID_CC_RATE_UP);
2412 break;
2414 case WID_CC_RATE_UP:
2415 if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
2416 if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
2417 this->EnableWidget(WID_CC_RATE_DOWN);
2418 break;
2420 case WID_CC_RATE:
2421 SetDParam(0, _custom_currency.rate);
2422 str = STR_JUST_INT;
2423 len = 5;
2424 line = WID_CC_RATE;
2425 afilter = CS_NUMERAL;
2426 break;
2428 case WID_CC_SEPARATOR_EDIT:
2429 case WID_CC_SEPARATOR:
2430 SetDParamStr(0, _custom_currency.separator);
2431 str = STR_JUST_RAW_STRING;
2432 len = 1;
2433 line = WID_CC_SEPARATOR;
2434 break;
2436 case WID_CC_PREFIX_EDIT:
2437 case WID_CC_PREFIX:
2438 SetDParamStr(0, _custom_currency.prefix);
2439 str = STR_JUST_RAW_STRING;
2440 len = 12;
2441 line = WID_CC_PREFIX;
2442 break;
2444 case WID_CC_SUFFIX_EDIT:
2445 case WID_CC_SUFFIX:
2446 SetDParamStr(0, _custom_currency.suffix);
2447 str = STR_JUST_RAW_STRING;
2448 len = 12;
2449 line = WID_CC_SUFFIX;
2450 break;
2452 case WID_CC_YEAR_DOWN:
2453 _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
2454 if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
2455 this->EnableWidget(WID_CC_YEAR_UP);
2456 break;
2458 case WID_CC_YEAR_UP:
2459 _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
2460 if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
2461 this->EnableWidget(WID_CC_YEAR_DOWN);
2462 break;
2464 case WID_CC_YEAR:
2465 SetDParam(0, _custom_currency.to_euro);
2466 str = STR_JUST_INT;
2467 len = 7;
2468 line = WID_CC_YEAR;
2469 afilter = CS_NUMERAL;
2470 break;
2473 if (len != 0) {
2474 this->query_widget = line;
2475 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
2478 this->SetTimeout();
2479 this->SetDirty();
2482 virtual void OnQueryTextFinished(char *str)
2484 if (str == NULL) return;
2486 switch (this->query_widget) {
2487 case WID_CC_RATE:
2488 _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
2489 break;
2491 case WID_CC_SEPARATOR: // Thousands separator
2492 strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
2493 break;
2495 case WID_CC_PREFIX:
2496 strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
2497 break;
2499 case WID_CC_SUFFIX:
2500 strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
2501 break;
2503 case WID_CC_YEAR: { // Year to switch to euro
2504 int val = atoi(str);
2506 _custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
2507 break;
2510 MarkWholeScreenDirty();
2511 SetButtonState();
2514 virtual void OnTimeout()
2516 this->SetDirty();
2520 static const NWidgetPart _nested_cust_currency_widgets[] = {
2521 NWidget(NWID_HORIZONTAL),
2522 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2523 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2524 EndContainer(),
2525 NWidget(WWT_PANEL, COLOUR_GREY),
2526 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
2527 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2528 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
2529 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
2530 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2531 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
2532 EndContainer(),
2533 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2534 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
2535 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2536 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
2537 EndContainer(),
2538 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2539 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
2540 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2541 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
2542 EndContainer(),
2543 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2544 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
2545 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2546 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
2547 EndContainer(),
2548 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2549 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
2550 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
2551 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2552 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
2553 EndContainer(),
2554 EndContainer(),
2555 NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
2556 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
2557 EndContainer(),
2560 static WindowDesc _cust_currency_desc(
2561 WDP_CENTER, NULL, 0, 0,
2562 WC_CUSTOM_CURRENCY, WC_NONE,
2564 _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
2567 /** Open custom currency window. */
2568 static void ShowCustCurrency()
2570 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
2571 new CustomCurrencyWindow(&_cust_currency_desc);