(svn r25074) -Cleanup: Simplify currency selection code slightly
[openttd/fttd.git] / src / settings_gui.cpp
blob50b0b880c0d20eb6463cb64799a9f7d71b3d37da
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 _units_dropdown[] = {
43 STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL,
44 STR_GAME_OPTIONS_MEASURING_UNITS_METRIC,
45 STR_GAME_OPTIONS_MEASURING_UNITS_SI,
46 INVALID_STRING_ID
49 static const StringID _driveside_dropdown[] = {
50 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT,
51 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT,
52 INVALID_STRING_ID
55 static const StringID _autosave_dropdown[] = {
56 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
57 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH,
58 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS,
59 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS,
60 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS,
61 INVALID_STRING_ID,
64 int _nb_orig_names = SPECSTR_TOWNNAME_LAST - SPECSTR_TOWNNAME_START + 1; ///< Number of original town names.
65 static StringID *_grf_names = NULL; ///< Pointer to town names defined by NewGRFs.
66 static int _nb_grf_names = 0; ///< Number of town names defined by NewGRFs.
68 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd);
70 /** Allocate memory for the NewGRF town names. */
71 void InitGRFTownGeneratorNames()
73 free(_grf_names);
74 _grf_names = GetGRFTownNameList();
75 _nb_grf_names = 0;
76 for (StringID *s = _grf_names; *s != INVALID_STRING_ID; s++) _nb_grf_names++;
79 /**
80 * Get a town name.
81 * @param town_name Number of the wanted town name.
82 * @return Name of the town as string ID.
84 static inline StringID TownName(int town_name)
86 if (town_name < _nb_orig_names) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + town_name;
87 town_name -= _nb_orig_names;
88 if (town_name < _nb_grf_names) return _grf_names[town_name];
89 return STR_UNDEFINED;
92 /**
93 * Get index of the current screen resolution.
94 * @return Index of the current screen resolution if it is a known resolution, #_num_resolutions otherwise.
96 static int GetCurRes()
98 int i;
100 for (i = 0; i != _num_resolutions; i++) {
101 if ((int)_resolutions[i].width == _screen.width &&
102 (int)_resolutions[i].height == _screen.height) {
103 break;
106 return i;
109 static void ShowCustCurrency();
111 template <class T>
112 static DropDownList *BuiltSetDropDownList(int *selected_index)
114 int n = T::GetNumSets();
115 *selected_index = T::GetIndexOfUsedSet();
117 DropDownList *list = new DropDownList();
118 for (int i = 0; i < n; i++) {
119 list->push_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, (_game_mode == GM_MENU) ? false : (*selected_index != i)));
122 return list;
125 /** Window for displaying the textfile of a BaseSet. */
126 template <class TBaseSet>
127 struct BaseSetTextfileWindow : public TextfileWindow {
128 const TBaseSet* baseset; ///< View the textfile of this BaseSet.
129 StringID content_type; ///< STR_CONTENT_TYPE_xxx for title.
131 BaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type) : TextfileWindow(file_type), baseset(baseset), content_type(content_type)
133 const char *textfile = this->baseset->GetTextfile(file_type);
134 this->LoadTextfile(textfile, BASESET_DIR);
137 /* virtual */ void SetStringParameters(int widget) const
139 if (widget == WID_TF_CAPTION) {
140 SetDParam(0, content_type);
141 SetDParamStr(1, this->baseset->name);
147 * Open the BaseSet version of the textfile window.
148 * @param file_type The type of textfile to display.
149 * @param baseset The BaseSet to use.
150 * @param content_type STR_CONTENT_TYPE_xxx for title.
152 template <class TBaseSet>
153 void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
155 DeleteWindowByClass(WC_TEXTFILE);
156 new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
159 struct GameOptionsWindow : Window {
160 GameSettings *opt;
161 bool reload;
163 GameOptionsWindow(const WindowDesc *desc) : Window()
165 this->opt = &GetGameSettings();
166 this->reload = false;
168 this->InitNested(desc, WN_GAME_OPTIONS_GAME_OPTIONS);
169 this->OnInvalidateData(0);
172 ~GameOptionsWindow()
174 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
175 if (this->reload) _switch_mode = SM_MENU;
179 * Build the dropdown list for a specific widget.
180 * @param widget Widget to build list for
181 * @param selected_index Currently selected item
182 * @return the built dropdown list, or NULL if the widget has no dropdown menu.
184 DropDownList *BuildDropDownList(int widget, int *selected_index) const
186 DropDownList *list = NULL;
187 switch (widget) {
188 case WID_GO_CURRENCY_DROPDOWN: { // Setup currencies dropdown
189 list = new DropDownList();
190 *selected_index = this->opt->locale.currency;
191 StringID *items = BuildCurrencyDropdown();
192 uint disabled = _game_mode == GM_MENU ? 0 : ~GetMaskOfAllowedCurrencies();
194 /* Add non-custom currencies; sorted naturally */
195 for (uint i = 0; i < CURRENCY_END; items++, i++) {
196 if (i == CURRENCY_CUSTOM) continue;
197 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
199 list->sort(DropDownListStringItem::NatSortFunc);
201 /* Append custom currency at the end */
202 list->push_back(new DropDownListItem(-1, false)); // separator line
203 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM)));
204 break;
207 case WID_GO_DISTANCE_DROPDOWN: { // Setup distance unit dropdown
208 list = new DropDownList();
209 *selected_index = this->opt->locale.units;
210 const StringID *items = _units_dropdown;
211 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
212 list->push_back(new DropDownListStringItem(*items, i, false));
214 break;
217 case WID_GO_ROADSIDE_DROPDOWN: { // Setup road-side dropdown
218 list = new DropDownList();
219 *selected_index = this->opt->vehicle.road_side;
220 const StringID *items = _driveside_dropdown;
221 uint disabled = 0;
223 /* You can only change the drive side if you are in the menu or ingame with
224 * no vehicles present. In a networking game only the server can change it */
225 extern bool RoadVehiclesAreBuilt();
226 if ((_game_mode != GM_MENU && RoadVehiclesAreBuilt()) || (_networking && !_network_server)) {
227 disabled = ~(1 << this->opt->vehicle.road_side); // disable the other value
230 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
231 list->push_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
233 break;
236 case WID_GO_TOWNNAME_DROPDOWN: { // Setup townname dropdown
237 list = new DropDownList();
238 *selected_index = this->opt->game_creation.town_name;
240 int enabled_item = (_game_mode == GM_MENU || Town::GetNumItems() == 0) ? -1 : *selected_index;
242 /* Add and sort original townnames generators */
243 for (int i = 0; i < _nb_orig_names; i++) {
244 list->push_back(new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH + i, i, enabled_item != i && enabled_item >= 0));
246 list->sort(DropDownListStringItem::NatSortFunc);
248 /* Add and sort newgrf townnames generators */
249 DropDownList newgrf_names;
250 for (int i = 0; i < _nb_grf_names; i++) {
251 int result = _nb_orig_names + i;
252 newgrf_names.push_back(new DropDownListStringItem(_grf_names[i], result, enabled_item != result && enabled_item >= 0));
254 newgrf_names.sort(DropDownListStringItem::NatSortFunc);
256 /* Insert newgrf_names at the top of the list */
257 if (newgrf_names.size() > 0) {
258 newgrf_names.push_back(new DropDownListItem(-1, false)); // separator line
259 list->splice(list->begin(), newgrf_names);
261 break;
264 case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
265 list = new DropDownList();
266 *selected_index = _settings_client.gui.autosave;
267 const StringID *items = _autosave_dropdown;
268 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
269 list->push_back(new DropDownListStringItem(*items, i, false));
271 break;
274 case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
275 list = new DropDownList();
276 for (uint i = 0; i < _languages.Length(); i++) {
277 if (&_languages[i] == _current_language) *selected_index = i;
278 list->push_back(new DropDownListStringItem(SPECSTR_LANGUAGE_START + i, i, false));
280 list->sort(DropDownListStringItem::NatSortFunc);
281 break;
284 case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
285 list = new DropDownList();
286 *selected_index = GetCurRes();
287 for (int i = 0; i < _num_resolutions; i++) {
288 list->push_back(new DropDownListStringItem(SPECSTR_RESOLUTION_START + i, i, false));
290 break;
292 case WID_GO_SCREENSHOT_DROPDOWN: // Setup screenshot format dropdown
293 list = new DropDownList();
294 *selected_index = _cur_screenshot_format;
295 for (uint i = 0; i < _num_screenshot_formats; i++) {
296 if (!GetScreenshotFormatSupports_32bpp(i) && BlitterFactoryBase::GetCurrentBlitter()->GetScreenDepth() == 32) continue;
297 list->push_back(new DropDownListStringItem(SPECSTR_SCREENSHOT_START + i, i, false));
299 break;
301 case WID_GO_BASE_GRF_DROPDOWN:
302 list = BuiltSetDropDownList<BaseGraphics>(selected_index);
303 break;
305 case WID_GO_BASE_SFX_DROPDOWN:
306 list = BuiltSetDropDownList<BaseSounds>(selected_index);
307 break;
309 case WID_GO_BASE_MUSIC_DROPDOWN:
310 list = BuiltSetDropDownList<BaseMusic>(selected_index);
311 break;
313 default:
314 return NULL;
317 return list;
320 virtual void SetStringParameters(int widget) const
322 switch (widget) {
323 case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
324 case WID_GO_DISTANCE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_MEASURING_UNITS_IMPERIAL + this->opt->locale.units); break;
325 case WID_GO_ROADSIDE_DROPDOWN: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT + this->opt->vehicle.road_side); break;
326 case WID_GO_TOWNNAME_DROPDOWN: SetDParam(0, TownName(this->opt->game_creation.town_name)); break;
327 case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
328 case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
329 case WID_GO_RESOLUTION_DROPDOWN: SetDParam(0, GetCurRes() == _num_resolutions ? STR_GAME_OPTIONS_RESOLUTION_OTHER : SPECSTR_RESOLUTION_START + GetCurRes()); break;
330 case WID_GO_SCREENSHOT_DROPDOWN: SetDParam(0, SPECSTR_SCREENSHOT_START + _cur_screenshot_format); break;
331 case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name); break;
332 case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
333 case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name); break;
334 case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name); break;
335 case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
339 virtual void DrawWidget(const Rect &r, int widget) const
341 switch (widget) {
342 case WID_GO_BASE_GRF_DESCRIPTION:
343 SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
344 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
345 break;
347 case WID_GO_BASE_SFX_DESCRIPTION:
348 SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
349 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
350 break;
352 case WID_GO_BASE_MUSIC_DESCRIPTION:
353 SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
354 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
355 break;
359 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
361 switch (widget) {
362 case WID_GO_BASE_GRF_DESCRIPTION:
363 /* Find the biggest description for the default size. */
364 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
365 SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
366 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
368 break;
370 case WID_GO_BASE_GRF_STATUS:
371 /* Find the biggest description for the default size. */
372 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
373 uint invalid_files = BaseGraphics::GetSet(i)->GetNumInvalid();
374 if (invalid_files == 0) continue;
376 SetDParam(0, invalid_files);
377 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_GRF_STATUS));
379 break;
381 case WID_GO_BASE_SFX_DESCRIPTION:
382 /* Find the biggest description for the default size. */
383 for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
384 SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
385 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
387 break;
389 case WID_GO_BASE_MUSIC_DESCRIPTION:
390 /* Find the biggest description for the default size. */
391 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
392 SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
393 size->height = max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
395 break;
397 case WID_GO_BASE_MUSIC_STATUS:
398 /* Find the biggest description for the default size. */
399 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
400 uint invalid_files = BaseMusic::GetSet(i)->GetNumInvalid();
401 if (invalid_files == 0) continue;
403 SetDParam(0, invalid_files);
404 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_MUSIC_STATUS));
406 break;
408 default: {
409 int selected;
410 DropDownList *list = this->BuildDropDownList(widget, &selected);
411 if (list != NULL) {
412 /* Find the biggest item for the default size. */
413 for (DropDownList::iterator it = list->begin(); it != list->end(); it++) {
414 static const Dimension extra = {WD_DROPDOWNTEXT_LEFT + WD_DROPDOWNTEXT_RIGHT, WD_DROPDOWNTEXT_TOP + WD_DROPDOWNTEXT_BOTTOM};
415 Dimension string_dim;
416 int width = (*it)->Width();
417 string_dim.width = width + extra.width;
418 string_dim.height = (*it)->Height(width) + extra.height;
419 *size = maxdim(*size, string_dim);
420 delete *it;
422 delete list;
428 virtual void OnClick(Point pt, int widget, int click_count)
430 if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_END) {
431 if (BaseGraphics::GetUsedSet() == NULL) return;
433 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
434 return;
436 if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_END) {
437 if (BaseSounds::GetUsedSet() == NULL) return;
439 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
440 return;
442 if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_END) {
443 if (BaseMusic::GetUsedSet() == NULL) return;
445 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
446 return;
448 switch (widget) {
449 case WID_GO_FULLSCREEN_BUTTON: // Click fullscreen on/off
450 /* try to toggle full-screen on/off */
451 if (!ToggleFullScreen(!_fullscreen)) {
452 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
454 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
455 this->SetDirty();
456 break;
458 default: {
459 int selected;
460 DropDownList *list = this->BuildDropDownList(widget, &selected);
461 if (list != NULL) {
462 ShowDropDownList(this, list, selected, widget);
464 break;
470 * Set the base media set.
471 * @param index the index of the media set
472 * @tparam T class of media set
474 template <class T>
475 void SetMediaSet(int index)
477 if (_game_mode == GM_MENU) {
478 const char *name = T::GetSet(index)->name;
480 free(T::ini_set);
481 T::ini_set = strdup(name);
483 T::SetSet(name);
484 this->reload = true;
485 this->InvalidateData();
489 virtual void OnDropdownSelect(int widget, int index)
491 switch (widget) {
492 case WID_GO_CURRENCY_DROPDOWN: // Currency
493 if (index == CURRENCY_CUSTOM) ShowCustCurrency();
494 this->opt->locale.currency = index;
495 ReInitAllWindows();
496 break;
498 case WID_GO_DISTANCE_DROPDOWN: // Measuring units
499 this->opt->locale.units = index;
500 MarkWholeScreenDirty();
501 break;
503 case WID_GO_ROADSIDE_DROPDOWN: // Road side
504 if (this->opt->vehicle.road_side != index) { // only change if setting changed
505 uint i;
506 if (GetSettingFromName("vehicle.road_side", &i) == NULL) NOT_REACHED();
507 SetSettingValue(i, index);
508 MarkWholeScreenDirty();
510 break;
512 case WID_GO_TOWNNAME_DROPDOWN: // Town names
513 if (_game_mode == GM_MENU || Town::GetNumItems() == 0) {
514 this->opt->game_creation.town_name = index;
515 SetWindowDirty(WC_GAME_OPTIONS, WN_GAME_OPTIONS_GAME_OPTIONS);
517 break;
519 case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
520 _settings_client.gui.autosave = index;
521 this->SetDirty();
522 break;
524 case WID_GO_LANG_DROPDOWN: // Change interface language
525 ReadLanguagePack(&_languages[index]);
526 DeleteWindowByClass(WC_QUERY_STRING);
527 CheckForMissingGlyphs();
528 UpdateAllVirtCoords();
529 ReInitAllWindows();
530 break;
532 case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
533 if (index < _num_resolutions && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
534 this->SetDirty();
536 break;
538 case WID_GO_SCREENSHOT_DROPDOWN: // Change screenshot format
539 SetScreenshotFormat(index);
540 this->SetDirty();
541 break;
543 case WID_GO_BASE_GRF_DROPDOWN:
544 this->SetMediaSet<BaseGraphics>(index);
545 break;
547 case WID_GO_BASE_SFX_DROPDOWN:
548 this->SetMediaSet<BaseSounds>(index);
549 break;
551 case WID_GO_BASE_MUSIC_DROPDOWN:
552 this->SetMediaSet<BaseMusic>(index);
553 break;
558 * Some data on this window has become invalid.
559 * @param data Information about the changed data. @see GameOptionsInvalidationData
560 * @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.
562 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
564 if (!gui_scope) return;
565 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
567 bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
568 this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
570 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
571 this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == NULL || BaseGraphics::GetUsedSet()->GetTextfile(tft) == NULL);
572 this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == NULL || BaseSounds::GetUsedSet()->GetTextfile(tft) == NULL);
573 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == NULL || BaseMusic::GetUsedSet()->GetTextfile(tft) == NULL);
576 missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
577 this->GetWidget<NWidgetCore>(WID_GO_BASE_MUSIC_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_MUSIC_STATUS, STR_NULL);
581 static const NWidgetPart _nested_game_options_widgets[] = {
582 NWidget(NWID_HORIZONTAL),
583 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
584 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
585 EndContainer(),
586 NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
587 NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
588 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
589 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
590 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),
591 EndContainer(),
592 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME, STR_NULL),
593 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),
594 EndContainer(),
595 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
596 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),
597 EndContainer(),
598 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL),
599 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),
600 NWidget(NWID_HORIZONTAL),
601 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
602 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
603 EndContainer(),
604 EndContainer(),
605 EndContainer(),
607 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
608 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_MEASURING_UNITS_FRAME, STR_NULL),
609 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_DISTANCE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_MEASURING_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
610 EndContainer(),
611 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME, STR_NULL),
612 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),
613 EndContainer(),
614 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
615 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),
616 EndContainer(),
617 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_SCREENSHOT_FORMAT, STR_NULL),
618 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),
619 EndContainer(),
620 NWidget(NWID_SPACER), SetMinimalSize(0, 0), SetFill(0, 1),
621 EndContainer(),
622 EndContainer(),
624 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
625 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
626 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
627 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
628 EndContainer(),
629 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),
630 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
631 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),
632 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),
633 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),
634 EndContainer(),
635 EndContainer(),
637 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10),
638 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
639 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP),
640 NWidget(NWID_SPACER), SetFill(1, 0),
641 EndContainer(),
642 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),
643 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
644 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),
645 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),
646 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),
647 EndContainer(),
648 EndContainer(),
650 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10),
651 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
652 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP),
653 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
654 EndContainer(),
655 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),
656 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
657 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),
658 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),
659 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),
660 EndContainer(),
661 EndContainer(),
662 EndContainer(),
665 static const WindowDesc _game_options_desc(
666 WDP_CENTER, 0, 0,
667 WC_GAME_OPTIONS, WC_NONE,
669 _nested_game_options_widgets, lengthof(_nested_game_options_widgets)
672 /** Open the game options window. */
673 void ShowGameOptions()
675 DeleteWindowByClass(WC_GAME_OPTIONS);
676 new GameOptionsWindow(&_game_options_desc);
679 static int SETTING_HEIGHT = 11; ///< Height of a single setting in the tree view in pixels
680 static const int LEVEL_WIDTH = 15; ///< Indenting width of a sub-page in pixels
683 * Flags for #SettingEntry
684 * @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
686 enum SettingEntryFlags {
687 SEF_LEFT_DEPRESSED = 0x01, ///< Of a numeric setting entry, the left button is depressed
688 SEF_RIGHT_DEPRESSED = 0x02, ///< Of a numeric setting entry, the right button is depressed
689 SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED), ///< Bit-mask for button flags
691 SEF_LAST_FIELD = 0x04, ///< This entry is the last one in a (sub-)page
692 SEF_FILTERED = 0x08, ///< Entry is hidden by the string filter
694 /* Entry kind */
695 SEF_SETTING_KIND = 0x10, ///< Entry kind: Entry is a setting
696 SEF_SUBTREE_KIND = 0x20, ///< Entry kind: Entry is a sub-tree
697 SEF_KIND_MASK = (SEF_SETTING_KIND | SEF_SUBTREE_KIND), ///< Bit-mask for fetching entry kind
700 struct SettingsPage; // Forward declaration
702 /** Data fields for a sub-page (#SEF_SUBTREE_KIND kind)*/
703 struct SettingEntrySubtree {
704 SettingsPage *page; ///< Pointer to the sub-page
705 bool folded; ///< Sub-page is folded (not visible except for its title)
706 StringID title; ///< Title of the sub-page
709 /** Data fields for a single setting (#SEF_SETTING_KIND kind) */
710 struct SettingEntrySetting {
711 const char *name; ///< Name of the setting
712 const SettingDesc *setting; ///< Setting description of the setting
713 uint index; ///< Index of the setting in the settings table
716 /** How the list of advanced settings is filtered. */
717 enum RestrictionMode {
718 RM_BASIC, ///< Display settings associated to the "basic" list.
719 RM_ADVANCED, ///< Display settings associated to the "advanced" list.
720 RM_ALL, ///< List all settings regardless of the default/newgame/... values.
721 RM_CHANGED_AGAINST_DEFAULT, ///< Show only settings which are different compared to default values.
722 RM_CHANGED_AGAINST_NEW, ///< Show only settings which are different compared to the user's new game setting values.
723 RM_END, ///< End for iteration.
726 /** Filter for settings list. */
727 struct SettingFilter {
728 StringFilter string; ///< Filter string.
729 RestrictionMode mode; ///< Filter based on category.
730 SettingType type; ///< Filter based on type.
733 /** Data structure describing a single setting in a tab */
734 struct SettingEntry {
735 byte flags; ///< Flags of the setting entry. @see SettingEntryFlags
736 byte level; ///< Nesting level of this setting entry
737 union {
738 SettingEntrySetting entry; ///< Data fields if entry is a setting
739 SettingEntrySubtree sub; ///< Data fields if entry is a sub-page
740 } d; ///< Data fields for each kind
742 SettingEntry(const char *nm);
743 SettingEntry(SettingsPage *sub, StringID title);
745 void Init(byte level);
746 void FoldAll();
747 void UnFoldAll();
748 void SetButtons(byte new_val);
751 * Set whether this is the last visible entry of the parent node.
752 * @param last_field Value to set
754 void SetLastField(bool last_field) { if (last_field) SETBITS(this->flags, SEF_LAST_FIELD); else CLRBITS(this->flags, SEF_LAST_FIELD); }
756 uint Length() const;
757 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
758 bool IsVisible(const SettingEntry *item) const;
759 SettingEntry *FindEntry(uint row, uint *cur_row);
760 uint GetMaxHelpHeight(int maxw);
762 bool IsFiltered() const;
763 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
765 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);
768 * Get the help text of a single setting.
769 * @return The requested help text.
771 inline StringID GetHelpText()
773 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
774 return this->d.entry.setting->desc.str_help;
777 void SetValueDParams(uint first_param, int32 value);
779 private:
780 void DrawSetting(GameSettings *settings_ptr, int x, int y, int max_x, int state, bool highlight);
781 bool IsVisibleByRestrictionMode(RestrictionMode mode) const;
784 /** Data structure describing one page of settings in the settings window. */
785 struct SettingsPage {
786 SettingEntry *entries; ///< Array of setting entries of the page.
787 byte num; ///< Number of entries on the page (statically filled).
789 void Init(byte level = 0);
790 void FoldAll();
791 void UnFoldAll();
793 uint Length() const;
794 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
795 bool IsVisible(const SettingEntry *item) const;
796 SettingEntry *FindEntry(uint row, uint *cur_row) const;
797 uint GetMaxHelpHeight(int maxw);
799 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
801 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;
805 /* == SettingEntry methods == */
808 * Constructor for a single setting in the 'advanced settings' window
809 * @param nm Name of the setting in the setting table
811 SettingEntry::SettingEntry(const char *nm)
813 this->flags = SEF_SETTING_KIND;
814 this->level = 0;
815 this->d.entry.name = nm;
816 this->d.entry.setting = NULL;
817 this->d.entry.index = 0;
821 * Constructor for a sub-page in the 'advanced settings' window
822 * @param sub Sub-page
823 * @param title Title of the sub-page
825 SettingEntry::SettingEntry(SettingsPage *sub, StringID title)
827 this->flags = SEF_SUBTREE_KIND;
828 this->level = 0;
829 this->d.sub.page = sub;
830 this->d.sub.folded = true;
831 this->d.sub.title = title;
835 * Initialization of a setting entry
836 * @param level Page nesting level of this entry
838 void SettingEntry::Init(byte level)
840 this->level = level;
842 switch (this->flags & SEF_KIND_MASK) {
843 case SEF_SETTING_KIND:
844 this->d.entry.setting = GetSettingFromName(this->d.entry.name, &this->d.entry.index);
845 assert(this->d.entry.setting != NULL);
846 break;
847 case SEF_SUBTREE_KIND:
848 this->d.sub.page->Init(level + 1);
849 break;
850 default: NOT_REACHED();
854 /** Recursively close all (filtered) folds of sub-pages */
855 void SettingEntry::FoldAll()
857 if (this->IsFiltered()) return;
858 switch (this->flags & SEF_KIND_MASK) {
859 case SEF_SETTING_KIND:
860 break;
862 case SEF_SUBTREE_KIND:
863 this->d.sub.folded = true;
864 this->d.sub.page->FoldAll();
865 break;
867 default: NOT_REACHED();
871 /** Recursively open all (filtered) folds of sub-pages */
872 void SettingEntry::UnFoldAll()
874 if (this->IsFiltered()) return;
875 switch (this->flags & SEF_KIND_MASK) {
876 case SEF_SETTING_KIND:
877 break;
879 case SEF_SUBTREE_KIND:
880 this->d.sub.folded = false;
881 this->d.sub.page->UnFoldAll();
882 break;
884 default: NOT_REACHED();
889 * Recursively accumulate the folding state of the (filtered) tree.
890 * @param[in,out] all_folded Set to false, if one entry is not folded.
891 * @param[in,out] all_unfolded Set to false, if one entry is folded.
893 void SettingEntry::GetFoldingState(bool &all_folded, bool &all_unfolded) const
895 if (this->IsFiltered()) return;
896 switch (this->flags & SEF_KIND_MASK) {
897 case SEF_SETTING_KIND:
898 break;
900 case SEF_SUBTREE_KIND:
901 if (this->d.sub.folded) {
902 all_unfolded = false;
903 } else {
904 all_folded = false;
906 this->d.sub.page->GetFoldingState(all_folded, all_unfolded);
907 break;
909 default: NOT_REACHED();
914 * Check whether an entry is visible and not folded or filtered away.
915 * Note: This does not consider the scrolling range; it might still require scrolling to make the setting really visible.
916 * @param item Entry to search for.
917 * @return true if entry is visible.
919 bool SettingEntry::IsVisible(const SettingEntry *item) const
921 if (this->IsFiltered()) return false;
922 if (this == item) return true;
924 switch (this->flags & SEF_KIND_MASK) {
925 case SEF_SETTING_KIND:
926 return false;
928 case SEF_SUBTREE_KIND:
929 return !this->d.sub.folded && this->d.sub.page->IsVisible(item);
931 default: NOT_REACHED();
936 * Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
937 * @param new_val New value for the button flags
938 * @see SettingEntryFlags
940 void SettingEntry::SetButtons(byte new_val)
942 assert((new_val & ~SEF_BUTTONS_MASK) == 0); // Should not touch any flags outside the buttons
943 this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
946 /** Return numbers of rows needed to display the (filtered) entry */
947 uint SettingEntry::Length() const
949 if (this->IsFiltered()) return 0;
950 switch (this->flags & SEF_KIND_MASK) {
951 case SEF_SETTING_KIND:
952 return 1;
953 case SEF_SUBTREE_KIND:
954 if (this->d.sub.folded) return 1; // Only displaying the title
956 return 1 + this->d.sub.page->Length(); // 1 extra row for the title
957 default: NOT_REACHED();
962 * Find setting entry at row \a row_num
963 * @param row_num Index of entry to return
964 * @param cur_row Current row number
965 * @return The requested setting entry or \c NULL if it not found (folded or filtered)
967 SettingEntry *SettingEntry::FindEntry(uint row_num, uint *cur_row)
969 if (this->IsFiltered()) return NULL;
970 if (row_num == *cur_row) return this;
972 switch (this->flags & SEF_KIND_MASK) {
973 case SEF_SETTING_KIND:
974 (*cur_row)++;
975 break;
976 case SEF_SUBTREE_KIND:
977 (*cur_row)++; // add one for row containing the title
978 if (this->d.sub.folded) {
979 break;
982 /* sub-page is visible => search it too */
983 return this->d.sub.page->FindEntry(row_num, cur_row);
984 default: NOT_REACHED();
986 return NULL;
990 * Get the biggest height of the help text(s), if the width is at least \a maxw. Help text gets wrapped if needed.
991 * @param maxw Maximal width of a line help text.
992 * @return Biggest height needed to display any help text of this node (and its descendants).
994 uint SettingEntry::GetMaxHelpHeight(int maxw)
996 switch (this->flags & SEF_KIND_MASK) {
997 case SEF_SETTING_KIND: return GetStringHeight(this->GetHelpText(), maxw);
998 case SEF_SUBTREE_KIND: return this->d.sub.page->GetMaxHelpHeight(maxw);
999 default: NOT_REACHED();
1004 * Check whether an entry is hidden due to filters
1005 * @return true if hidden.
1007 bool SettingEntry::IsFiltered() const
1009 return (this->flags & SEF_FILTERED) != 0;
1013 * Checks whether an entry shall be made visible based on the restriction mode.
1014 * @param mode The current status of the restriction drop down box.
1015 * @return true if the entry shall be visible.
1017 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
1019 /* There shall not be any restriction, i.e. all settings shall be visible. */
1020 if (mode == RM_ALL) return true;
1022 GameSettings *settings_ptr = &GetGameSettings();
1023 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
1024 const SettingDesc *sd = this->d.entry.setting;
1026 if (mode == RM_BASIC) return (this->d.entry.setting->desc.cat & SC_BASIC_LIST) != 0;
1027 if (mode == RM_ADVANCED) return (this->d.entry.setting->desc.cat & SC_ADVANCED_LIST) != 0;
1029 /* Read the current value. */
1030 const void *var = ResolveVariableAddress(settings_ptr, sd);
1031 int64 current_value = ReadValue(var, sd->save.conv);
1033 int64 filter_value;
1035 if (mode == RM_CHANGED_AGAINST_DEFAULT) {
1036 /* This entry shall only be visible, if the value deviates from its default value. */
1038 /* Read the default value. */
1039 filter_value = ReadValue(&sd->desc.def, sd->save.conv);
1040 } else {
1041 assert(mode == RM_CHANGED_AGAINST_NEW);
1042 /* This entry shall only be visible, if the value deviates from
1043 * its value is used when starting a new game. */
1045 /* Make sure we're not comparing the new game settings against itself. */
1046 assert(settings_ptr != &_settings_newgame);
1048 /* Read the new game's value. */
1049 var = ResolveVariableAddress(&_settings_newgame, sd);
1050 filter_value = ReadValue(var, sd->save.conv);
1053 return current_value != filter_value;
1057 * Update the filter state.
1058 * @param filter Filter
1059 * @param force_visible Whether to force all items visible, no matter what (due to filter text; not affected by restriction drop down box).
1060 * @return true if item remains visible
1062 bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
1064 CLRBITS(this->flags, SEF_FILTERED);
1066 bool visible = true;
1067 switch (this->flags & SEF_KIND_MASK) {
1068 case SEF_SETTING_KIND: {
1069 const SettingDesc *sd = this->d.entry.setting;
1070 if (!force_visible && !filter.string.IsEmpty()) {
1071 /* Process the search text filter for this item. */
1072 filter.string.ResetState();
1074 const SettingDescBase *sdb = &sd->desc;
1076 SetDParam(0, STR_EMPTY);
1077 filter.string.AddLine(sdb->str);
1078 filter.string.AddLine(this->GetHelpText());
1080 visible = filter.string.GetState();
1082 if (filter.type != ST_ALL) visible = visible && sd->GetType() == filter.type;
1083 visible = visible && this->IsVisibleByRestrictionMode(filter.mode);
1084 break;
1086 case SEF_SUBTREE_KIND: {
1087 if (!force_visible && !filter.string.IsEmpty()) {
1088 filter.string.ResetState();
1089 filter.string.AddLine(this->d.sub.title);
1090 force_visible = filter.string.GetState();
1092 visible = this->d.sub.page->UpdateFilterState(filter, force_visible);
1093 break;
1095 default: NOT_REACHED();
1098 if (!visible) SETBITS(this->flags, SEF_FILTERED);
1099 return visible;
1105 * Draw a row in the settings panel.
1107 * See SettingsPage::Draw() for an explanation about how drawing is performed.
1109 * The \a parent_last parameter ensures that the vertical lines at the left are
1110 * only drawn when another entry follows, that it prevents output like
1111 * \verbatim
1112 * |-- setting
1113 * |-- (-) - Title
1114 * | |-- setting
1115 * | |-- setting
1116 * \endverbatim
1117 * The left-most vertical line is not wanted. It is prevented by setting the
1118 * appropriate bit in the \a parent_last parameter.
1120 * @param settings_ptr Pointer to current values of all settings
1121 * @param left Left-most position in window/panel to start drawing \a first_row
1122 * @param right Right-most x position to draw strings at.
1123 * @param base_y Upper-most position in window/panel to start drawing \a first_row
1124 * @param first_row First row number to draw
1125 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1126 * @param cur_row Current row number (internal variable)
1127 * @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)
1128 * @param selected Selected entry by the user.
1129 * @return Row number of the next row to draw
1131 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)
1133 if (this->IsFiltered()) return cur_row;
1134 if (cur_row >= max_row) return cur_row;
1136 bool rtl = _current_text_dir == TD_RTL;
1137 int offset = rtl ? -4 : 4;
1138 int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
1140 int x = rtl ? right : left;
1141 int y = base_y;
1142 if (cur_row >= first_row) {
1143 int colour = _colour_gradient[COLOUR_ORANGE][4];
1144 y = base_y + (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
1146 /* Draw vertical for parent nesting levels */
1147 for (uint lvl = 0; lvl < this->level; lvl++) {
1148 if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
1149 x += level_width;
1151 /* draw own |- prefix */
1152 int halfway_y = y + SETTING_HEIGHT / 2;
1153 int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
1154 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
1155 /* Small horizontal line from the last vertical line */
1156 GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
1157 x += level_width;
1160 switch (this->flags & SEF_KIND_MASK) {
1161 case SEF_SETTING_KIND:
1162 if (cur_row >= first_row) {
1163 this->DrawSetting(settings_ptr, rtl ? left : x, rtl ? x : right, y, this->flags & SEF_BUTTONS_MASK,
1164 this == selected);
1166 cur_row++;
1167 break;
1168 case SEF_SUBTREE_KIND:
1169 if (cur_row >= first_row) {
1170 DrawSprite((this->d.sub.folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? x - 8 : x, y + (SETTING_HEIGHT - 11) / 2);
1171 DrawString(rtl ? left : x + 12, rtl ? x - 12 : right, y, this->d.sub.title);
1173 cur_row++;
1174 if (!this->d.sub.folded) {
1175 if (this->flags & SEF_LAST_FIELD) {
1176 assert(this->level < sizeof(parent_last));
1177 SetBit(parent_last, this->level); // Add own last-field state
1180 cur_row = this->d.sub.page->Draw(settings_ptr, left, right, base_y, first_row, max_row, selected, cur_row, parent_last);
1182 break;
1183 default: NOT_REACHED();
1185 return cur_row;
1188 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
1190 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
1191 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
1192 return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
1193 } else {
1194 return GetVariableAddress(&_settings_client.company, &sd->save);
1196 } else {
1197 return GetVariableAddress(settings_ptr, &sd->save);
1202 * Set the DParams for drawing the value of a setting.
1203 * @param first_param First DParam to use
1204 * @param value Setting value to set params for.
1206 void SettingEntry::SetValueDParams(uint first_param, int32 value)
1208 assert((this->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
1209 const SettingDescBase *sdb = &this->d.entry.setting->desc;
1210 if (sdb->cmd == SDT_BOOLX) {
1211 SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
1212 } else {
1213 if ((sdb->flags & SGF_MULTISTRING) != 0) {
1214 SetDParam(first_param++, sdb->str_val - sdb->min + value);
1215 } else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
1216 SetDParam(first_param++, sdb->str_val + ((value >= 0) ? 1 : 0));
1217 value = abs(value);
1218 } else {
1219 SetDParam(first_param++, sdb->str_val + ((value == 0 && (sdb->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
1221 SetDParam(first_param++, value);
1226 * Private function to draw setting value (button + text + current value)
1227 * @param settings_ptr Pointer to current values of all settings
1228 * @param left Left-most position in window/panel to start drawing
1229 * @param right Right-most position in window/panel to draw
1230 * @param y Upper-most position in window/panel to start drawing
1231 * @param state State of the left + right arrow buttons to draw for the setting
1232 * @param highlight Highlight entry.
1234 void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, int state, bool highlight)
1236 const SettingDesc *sd = this->d.entry.setting;
1237 const SettingDescBase *sdb = &sd->desc;
1238 const void *var = ResolveVariableAddress(settings_ptr, sd);
1240 bool rtl = _current_text_dir == TD_RTL;
1241 uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
1242 uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + 5);
1243 uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + 5 : 0);
1244 uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
1246 /* We do not allow changes of some items when we are a client in a networkgame */
1247 bool editable = sd->IsEditable();
1249 SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
1250 int32 value = (int32)ReadValue(var, sd->save.conv);
1251 if (sdb->cmd == SDT_BOOLX) {
1252 /* Draw checkbox for boolean-value either on/off */
1253 DrawBoolButton(buttons_left, button_y, value != 0, editable);
1254 } else if ((sdb->flags & SGF_MULTISTRING) != 0) {
1255 /* Draw [v] button for settings of an enum-type */
1256 DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
1257 } else {
1258 /* Draw [<][>] boxes for settings of an integer-type */
1259 DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
1260 editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
1262 this->SetValueDParams(1, value);
1263 DrawString(text_left, text_right, y, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
1267 /* == SettingsPage methods == */
1270 * Initialization of an entire setting page
1271 * @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
1273 void SettingsPage::Init(byte level)
1275 for (uint field = 0; field < this->num; field++) {
1276 this->entries[field].Init(level);
1280 /** Recursively close all folds of sub-pages */
1281 void SettingsPage::FoldAll()
1283 for (uint field = 0; field < this->num; field++) {
1284 this->entries[field].FoldAll();
1288 /** Recursively open all folds of sub-pages */
1289 void SettingsPage::UnFoldAll()
1291 for (uint field = 0; field < this->num; field++) {
1292 this->entries[field].UnFoldAll();
1297 * Recursively accumulate the folding state of the tree.
1298 * @param[in,out] all_folded Set to false, if one entry is not folded.
1299 * @param[in,out] all_unfolded Set to false, if one entry is folded.
1301 void SettingsPage::GetFoldingState(bool &all_folded, bool &all_unfolded) const
1303 for (uint field = 0; field < this->num; field++) {
1304 this->entries[field].GetFoldingState(all_folded, all_unfolded);
1309 * Update the filter state.
1310 * @param filter Filter
1311 * @param force_visible Whether to force all items visible, no matter what
1312 * @return true if item remains visible
1314 bool SettingsPage::UpdateFilterState(SettingFilter &filter, bool force_visible)
1316 bool visible = false;
1317 bool first_visible = true;
1318 for (int field = this->num - 1; field >= 0; field--) {
1319 visible |= this->entries[field].UpdateFilterState(filter, force_visible);
1320 this->entries[field].SetLastField(first_visible);
1321 if (visible && first_visible) first_visible = false;
1323 return visible;
1328 * Check whether an entry is visible and not folded or filtered away.
1329 * Note: This does not consider the scrolling range; it might still require scrolling ot make the setting really visible.
1330 * @param item Entry to search for.
1331 * @return true if entry is visible.
1333 bool SettingsPage::IsVisible(const SettingEntry *item) const
1335 for (uint field = 0; field < this->num; field++) {
1336 if (this->entries[field].IsVisible(item)) return true;
1338 return false;
1341 /** Return number of rows needed to display the whole page */
1342 uint SettingsPage::Length() const
1344 uint length = 0;
1345 for (uint field = 0; field < this->num; field++) {
1346 length += this->entries[field].Length();
1348 return length;
1352 * Find the setting entry at row number \a row_num
1353 * @param row_num Index of entry to return
1354 * @param cur_row Variable used for keeping track of the current row number. Should point to memory initialized to \c 0 when first called.
1355 * @return The requested setting entry or \c NULL if it does not exist
1357 SettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row) const
1359 SettingEntry *pe = NULL;
1361 for (uint field = 0; field < this->num; field++) {
1362 pe = this->entries[field].FindEntry(row_num, cur_row);
1363 if (pe != NULL) {
1364 break;
1367 return pe;
1371 * Get the biggest height of the help texts, if the width is at least \a maxw. Help text gets wrapped if needed.
1372 * @param maxw Maximal width of a line help text.
1373 * @return Biggest height needed to display any help text of this (sub-)tree.
1375 uint SettingsPage::GetMaxHelpHeight(int maxw)
1377 uint biggest = 0;
1378 for (uint field = 0; field < this->num; field++) {
1379 biggest = max(biggest, this->entries[field].GetMaxHelpHeight(maxw));
1381 return biggest;
1385 * Draw a selected part of the settings page.
1387 * The scrollbar uses rows of the page, while the page data structure is a tree of #SettingsPage and #SettingEntry objects.
1388 * 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.
1389 * Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
1391 * @param settings_ptr Pointer to current values of all settings
1392 * @param left Left-most position in window/panel to start drawing of each setting row
1393 * @param right Right-most position in window/panel to draw at
1394 * @param base_y Upper-most position in window/panel to start drawing of row number \a first_row
1395 * @param first_row Number of first row to draw
1396 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1397 * @param cur_row Current row number (internal variable)
1398 * @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)
1399 * @param selected Selected entry by the user.
1400 * @return Row number of the next row to draw
1402 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
1404 if (cur_row >= max_row) return cur_row;
1406 for (uint i = 0; i < this->num; i++) {
1407 cur_row = this->entries[i].Draw(settings_ptr, left, right, base_y, first_row, max_row, cur_row, parent_last, selected);
1408 if (cur_row >= max_row) {
1409 break;
1412 return cur_row;
1416 static SettingEntry _settings_ui_display[] = {
1417 SettingEntry("gui.date_format_in_default_names"),
1418 SettingEntry("gui.population_in_label"),
1419 SettingEntry("gui.measure_tooltip"),
1420 SettingEntry("gui.loading_indicators"),
1421 SettingEntry("gui.liveries"),
1422 SettingEntry("gui.show_track_reservation"),
1423 SettingEntry("gui.expenses_layout"),
1424 SettingEntry("gui.smallmap_land_colour"),
1425 SettingEntry("gui.zoom_min"),
1426 SettingEntry("gui.zoom_max"),
1427 SettingEntry("gui.graph_line_thickness"),
1429 /** Display options sub-page */
1430 static SettingsPage _settings_ui_display_page = {_settings_ui_display, lengthof(_settings_ui_display)};
1432 static SettingEntry _settings_ui_interaction[] = {
1433 SettingEntry("gui.window_snap_radius"),
1434 SettingEntry("gui.window_soft_limit"),
1435 SettingEntry("gui.link_terraform_toolbar"),
1436 SettingEntry("gui.prefer_teamchat"),
1437 SettingEntry("gui.auto_scrolling"),
1438 SettingEntry("gui.reverse_scroll"),
1439 SettingEntry("gui.smooth_scroll"),
1440 SettingEntry("gui.left_mouse_btn_scrolling"),
1441 /* While the horizontal scrollwheel scrolling is written as general code, only
1442 * the cocoa (OSX) driver generates input for it.
1443 * Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
1444 SettingEntry("gui.scrollwheel_scrolling"),
1445 SettingEntry("gui.scrollwheel_multiplier"),
1446 SettingEntry("gui.osk_activation"),
1447 #ifdef __APPLE__
1448 /* We might need to emulate a right mouse button on mac */
1449 SettingEntry("gui.right_mouse_btn_emulation"),
1450 #endif
1452 /** Interaction sub-page */
1453 static SettingsPage _settings_ui_interaction_page = {_settings_ui_interaction, lengthof(_settings_ui_interaction)};
1455 static SettingEntry _settings_ui_sound[] = {
1456 SettingEntry("sound.click_beep"),
1457 SettingEntry("sound.confirm"),
1458 SettingEntry("sound.news_ticker"),
1459 SettingEntry("sound.news_full"),
1460 SettingEntry("sound.new_year"),
1461 SettingEntry("sound.disaster"),
1462 SettingEntry("sound.vehicle"),
1463 SettingEntry("sound.ambient"),
1465 /** Sound effects sub-page */
1466 static SettingsPage _settings_ui_sound_page = {_settings_ui_sound, lengthof(_settings_ui_sound)};
1468 static SettingEntry _settings_ui_news[] = {
1469 SettingEntry("news_display.arrival_player"),
1470 SettingEntry("news_display.arrival_other"),
1471 SettingEntry("news_display.accident"),
1472 SettingEntry("news_display.company_info"),
1473 SettingEntry("news_display.open"),
1474 SettingEntry("news_display.close"),
1475 SettingEntry("news_display.economy"),
1476 SettingEntry("news_display.production_player"),
1477 SettingEntry("news_display.production_other"),
1478 SettingEntry("news_display.production_nobody"),
1479 SettingEntry("news_display.advice"),
1480 SettingEntry("news_display.new_vehicles"),
1481 SettingEntry("news_display.acceptance"),
1482 SettingEntry("news_display.subsidies"),
1483 SettingEntry("news_display.general"),
1484 SettingEntry("gui.coloured_news_year"),
1486 /** News sub-page */
1487 static SettingsPage _settings_ui_news_page = {_settings_ui_news, lengthof(_settings_ui_news)};
1489 static SettingEntry _settings_ui[] = {
1490 SettingEntry(&_settings_ui_display_page, STR_CONFIG_SETTING_DISPLAY_OPTIONS),
1491 SettingEntry(&_settings_ui_interaction_page, STR_CONFIG_SETTING_INTERACTION),
1492 SettingEntry(&_settings_ui_sound_page, STR_CONFIG_SETTING_SOUND),
1493 SettingEntry(&_settings_ui_news_page, STR_CONFIG_SETTING_NEWS),
1494 SettingEntry("gui.show_finances"),
1495 SettingEntry("gui.errmsg_duration"),
1496 SettingEntry("gui.hover_delay"),
1497 SettingEntry("gui.toolbar_pos"),
1498 SettingEntry("gui.statusbar_pos"),
1499 SettingEntry("gui.newgrf_default_palette"),
1500 SettingEntry("gui.pause_on_newgame"),
1501 SettingEntry("gui.advanced_vehicle_list"),
1502 SettingEntry("gui.timetable_in_ticks"),
1503 SettingEntry("gui.timetable_arrival_departure"),
1504 SettingEntry("gui.quick_goto"),
1505 SettingEntry("gui.default_rail_type"),
1506 SettingEntry("gui.disable_unsuitable_building"),
1507 SettingEntry("gui.persistent_buildingtools"),
1509 /** Interface subpage */
1510 static SettingsPage _settings_ui_page = {_settings_ui, lengthof(_settings_ui)};
1512 static SettingEntry _settings_construction_signals[] = {
1513 SettingEntry("construction.train_signal_side"),
1514 SettingEntry("gui.enable_signal_gui"),
1515 SettingEntry("gui.drag_signals_fixed_distance"),
1516 SettingEntry("gui.semaphore_build_before"),
1517 SettingEntry("gui.default_signal_type"),
1518 SettingEntry("gui.cycle_signal_types"),
1520 /** Signals subpage */
1521 static SettingsPage _settings_construction_signals_page = {_settings_construction_signals, lengthof(_settings_construction_signals)};
1523 static SettingEntry _settings_construction[] = {
1524 SettingEntry(&_settings_construction_signals_page, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS),
1525 SettingEntry("construction.build_on_slopes"),
1526 SettingEntry("construction.autoslope"),
1527 SettingEntry("construction.extra_dynamite"),
1528 SettingEntry("construction.max_bridge_length"),
1529 SettingEntry("construction.max_tunnel_length"),
1530 SettingEntry("station.never_expire_airports"),
1531 SettingEntry("construction.freeform_edges"),
1532 SettingEntry("construction.extra_tree_placement"),
1533 SettingEntry("construction.command_pause_level"),
1535 /** Construction sub-page */
1536 static SettingsPage _settings_construction_page = {_settings_construction, lengthof(_settings_construction)};
1538 static SettingEntry _settings_stations_cargo[] = {
1539 SettingEntry("order.improved_load"),
1540 SettingEntry("order.gradual_loading"),
1541 SettingEntry("order.selectgoods"),
1543 /** Cargo handling sub-page */
1544 static SettingsPage _settings_stations_cargo_page = {_settings_stations_cargo, lengthof(_settings_stations_cargo)};
1546 static SettingEntry _settings_stations[] = {
1547 SettingEntry(&_settings_stations_cargo_page, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING),
1548 SettingEntry("station.adjacent_stations"),
1549 SettingEntry("station.distant_join_stations"),
1550 SettingEntry("station.station_spread"),
1551 SettingEntry("economy.station_noise_level"),
1552 SettingEntry("station.modified_catchment"),
1553 SettingEntry("construction.road_stop_on_town_road"),
1554 SettingEntry("construction.road_stop_on_competitor_road"),
1556 /** Stations sub-page */
1557 static SettingsPage _settings_stations_page = {_settings_stations, lengthof(_settings_stations)};
1559 static SettingEntry _settings_economy_towns[] = {
1560 SettingEntry("difficulty.town_council_tolerance"),
1561 SettingEntry("economy.bribe"),
1562 SettingEntry("economy.exclusive_rights"),
1563 SettingEntry("economy.fund_roads"),
1564 SettingEntry("economy.fund_buildings"),
1565 SettingEntry("economy.town_layout"),
1566 SettingEntry("economy.allow_town_roads"),
1567 SettingEntry("economy.allow_town_level_crossings"),
1568 SettingEntry("economy.found_town"),
1569 SettingEntry("economy.mod_road_rebuild"),
1570 SettingEntry("economy.town_growth_rate"),
1571 SettingEntry("economy.larger_towns"),
1572 SettingEntry("economy.initial_city_size"),
1574 /** Towns sub-page */
1575 static SettingsPage _settings_economy_towns_page = {_settings_economy_towns, lengthof(_settings_economy_towns)};
1577 static SettingEntry _settings_economy_industries[] = {
1578 SettingEntry("construction.raw_industry_construction"),
1579 SettingEntry("construction.industry_platform"),
1580 SettingEntry("economy.multiple_industry_per_town"),
1581 SettingEntry("game_creation.oil_refinery_limit"),
1583 /** Industries sub-page */
1584 static SettingsPage _settings_economy_industries_page = {_settings_economy_industries, lengthof(_settings_economy_industries)};
1587 static SettingEntry _settings_economy[] = {
1588 SettingEntry(&_settings_economy_towns_page, STR_CONFIG_SETTING_ECONOMY_TOWNS),
1589 SettingEntry(&_settings_economy_industries_page, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES),
1590 SettingEntry("economy.inflation"),
1591 SettingEntry("difficulty.initial_interest"),
1592 SettingEntry("difficulty.max_loan"),
1593 SettingEntry("difficulty.subsidy_multiplier"),
1594 SettingEntry("difficulty.economy"),
1595 SettingEntry("economy.smooth_economy"),
1596 SettingEntry("economy.feeder_payment_share"),
1597 SettingEntry("economy.infrastructure_maintenance"),
1598 SettingEntry("difficulty.vehicle_costs"),
1599 SettingEntry("difficulty.construction_cost"),
1600 SettingEntry("difficulty.disasters"),
1602 /** Economy sub-page */
1603 static SettingsPage _settings_economy_page = {_settings_economy, lengthof(_settings_economy)};
1605 static SettingEntry _settings_ai_npc[] = {
1606 SettingEntry("script.settings_profile"),
1607 SettingEntry("script.script_max_opcode_till_suspend"),
1608 SettingEntry("difficulty.competitor_speed"),
1609 SettingEntry("ai.ai_in_multiplayer"),
1610 SettingEntry("ai.ai_disable_veh_train"),
1611 SettingEntry("ai.ai_disable_veh_roadveh"),
1612 SettingEntry("ai.ai_disable_veh_aircraft"),
1613 SettingEntry("ai.ai_disable_veh_ship"),
1615 /** Computer players sub-page */
1616 static SettingsPage _settings_ai_npc_page = {_settings_ai_npc, lengthof(_settings_ai_npc)};
1618 static SettingEntry _settings_ai[] = {
1619 SettingEntry(&_settings_ai_npc_page, STR_CONFIG_SETTING_AI_NPC),
1620 SettingEntry("economy.give_money"),
1621 SettingEntry("economy.allow_shares"),
1623 /** AI sub-page */
1624 static SettingsPage _settings_ai_page = {_settings_ai, lengthof(_settings_ai)};
1626 static SettingEntry _settings_vehicles_routing[] = {
1627 SettingEntry("pf.pathfinder_for_trains"),
1628 SettingEntry("pf.forbid_90_deg"),
1629 SettingEntry("pf.pathfinder_for_roadvehs"),
1630 SettingEntry("pf.roadveh_queue"),
1631 SettingEntry("pf.pathfinder_for_ships"),
1633 /** Autorenew sub-page */
1634 static SettingsPage _settings_vehicles_routing_page = {_settings_vehicles_routing, lengthof(_settings_vehicles_routing)};
1636 static SettingEntry _settings_vehicles_autorenew[] = {
1637 SettingEntry("company.engine_renew"),
1638 SettingEntry("company.engine_renew_months"),
1639 SettingEntry("company.engine_renew_money"),
1641 /** Autorenew sub-page */
1642 static SettingsPage _settings_vehicles_autorenew_page = {_settings_vehicles_autorenew, lengthof(_settings_vehicles_autorenew)};
1644 static SettingEntry _settings_vehicles_servicing[] = {
1645 SettingEntry("vehicle.servint_ispercent"),
1646 SettingEntry("vehicle.servint_trains"),
1647 SettingEntry("vehicle.servint_roadveh"),
1648 SettingEntry("vehicle.servint_ships"),
1649 SettingEntry("vehicle.servint_aircraft"),
1650 SettingEntry("difficulty.vehicle_breakdowns"),
1651 SettingEntry("order.no_servicing_if_no_breakdowns"),
1652 SettingEntry("order.serviceathelipad"),
1654 /** Servicing sub-page */
1655 static SettingsPage _settings_vehicles_servicing_page = {_settings_vehicles_servicing, lengthof(_settings_vehicles_servicing)};
1657 static SettingEntry _settings_vehicles_trains[] = {
1658 SettingEntry("difficulty.line_reverse_mode"),
1659 SettingEntry("pf.reverse_at_signals"),
1660 SettingEntry("vehicle.train_acceleration_model"),
1661 SettingEntry("vehicle.train_slope_steepness"),
1662 SettingEntry("vehicle.max_train_length"),
1663 SettingEntry("vehicle.wagon_speed_limits"),
1664 SettingEntry("vehicle.disable_elrails"),
1665 SettingEntry("vehicle.freight_trains"),
1666 SettingEntry("gui.stop_location"),
1668 /** Trains sub-page */
1669 static SettingsPage _settings_vehicles_trains_page = {_settings_vehicles_trains, lengthof(_settings_vehicles_trains)};
1671 static SettingEntry _settings_vehicles[] = {
1672 SettingEntry(&_settings_vehicles_routing_page, STR_CONFIG_SETTING_VEHICLES_ROUTING),
1673 SettingEntry(&_settings_vehicles_autorenew_page, STR_CONFIG_SETTING_VEHICLES_AUTORENEW),
1674 SettingEntry(&_settings_vehicles_servicing_page, STR_CONFIG_SETTING_VEHICLES_SERVICING),
1675 SettingEntry(&_settings_vehicles_trains_page, STR_CONFIG_SETTING_VEHICLES_TRAINS),
1676 SettingEntry("gui.new_nonstop"),
1677 SettingEntry("gui.order_review_system"),
1678 SettingEntry("gui.vehicle_income_warn"),
1679 SettingEntry("gui.lost_vehicle_warn"),
1680 SettingEntry("vehicle.never_expire_vehicles"),
1681 SettingEntry("vehicle.max_trains"),
1682 SettingEntry("vehicle.max_roadveh"),
1683 SettingEntry("vehicle.max_aircraft"),
1684 SettingEntry("vehicle.max_ships"),
1685 SettingEntry("vehicle.plane_speed"),
1686 SettingEntry("vehicle.plane_crashes"),
1687 SettingEntry("vehicle.dynamic_engines"),
1688 SettingEntry("vehicle.roadveh_acceleration_model"),
1689 SettingEntry("vehicle.roadveh_slope_steepness"),
1690 SettingEntry("vehicle.smoke_amount"),
1692 /** Vehicles sub-page */
1693 static SettingsPage _settings_vehicles_page = {_settings_vehicles, lengthof(_settings_vehicles)};
1695 static SettingEntry _settings_main[] = {
1696 SettingEntry(&_settings_ui_page, STR_CONFIG_SETTING_GUI),
1697 SettingEntry(&_settings_construction_page, STR_CONFIG_SETTING_CONSTRUCTION),
1698 SettingEntry(&_settings_vehicles_page, STR_CONFIG_SETTING_VEHICLES),
1699 SettingEntry(&_settings_stations_page, STR_CONFIG_SETTING_STATIONS),
1700 SettingEntry(&_settings_economy_page, STR_CONFIG_SETTING_ECONOMY),
1701 SettingEntry(&_settings_ai_page, STR_CONFIG_SETTING_AI),
1704 /** Main page, holding all advanced settings */
1705 static SettingsPage _settings_main_page = {_settings_main, lengthof(_settings_main)};
1707 static const StringID _game_settings_restrict_dropdown[] = {
1708 STR_CONFIG_SETTING_RESTRICT_BASIC, // RM_BASIC
1709 STR_CONFIG_SETTING_RESTRICT_ADVANCED, // RM_ADVANCED
1710 STR_CONFIG_SETTING_RESTRICT_ALL, // RM_ALL
1711 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT, // RM_CHANGED_AGAINST_DEFAULT
1712 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW, // RM_CHANGED_AGAINST_NEW
1714 assert_compile(lengthof(_game_settings_restrict_dropdown) == RM_END);
1716 struct GameSettingsWindow : Window {
1717 static const int SETTINGTREE_LEFT_OFFSET = 5; ///< Position of left edge of setting values
1718 static const int SETTINGTREE_RIGHT_OFFSET = 5; ///< Position of right edge of setting values
1719 static const int SETTINGTREE_TOP_OFFSET = 5; ///< Position of top edge of setting values
1720 static const int SETTINGTREE_BOTTOM_OFFSET = 5; ///< Position of bottom edge of setting values
1722 static GameSettings *settings_ptr; ///< Pointer to the game settings being displayed and modified.
1724 SettingEntry *valuewindow_entry; ///< If non-NULL, pointer to setting for which a value-entering window has been opened.
1725 SettingEntry *clicked_entry; ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button).
1726 SettingEntry *last_clicked; ///< If non-NULL, pointer to the last clicked setting.
1727 SettingEntry *valuedropdown_entry; ///< If non-NULL, pointer to the value for which a dropdown window is currently opened.
1728 bool closing_dropdown; ///< True, if the dropdown list is currently closing.
1730 SettingFilter filter; ///< Filter for the list.
1731 QueryString filter_editbox; ///< Filter editbox;
1732 bool manually_changed_folding; ///< Whether the user expanded/collapsed something manually.
1734 Scrollbar *vscroll;
1736 GameSettingsWindow(const WindowDesc *desc) : filter_editbox(50)
1738 static bool first_time = true;
1740 filter.mode = (RestrictionMode)_settings_client.gui.settings_restriction_mode;
1741 filter.type = ST_ALL;
1742 settings_ptr = &GetGameSettings();
1744 /* Build up the dynamic settings-array only once per OpenTTD session */
1745 if (first_time) {
1746 _settings_main_page.Init();
1747 first_time = false;
1748 } else {
1749 _settings_main_page.FoldAll(); // Close all sub-pages
1752 this->valuewindow_entry = NULL; // No setting entry for which a entry window is opened
1753 this->clicked_entry = NULL; // No numeric setting buttons are depressed
1754 this->last_clicked = NULL;
1755 this->valuedropdown_entry = NULL;
1756 this->closing_dropdown = false;
1757 this->manually_changed_folding = false;
1759 this->CreateNestedTree(desc);
1760 this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
1761 this->FinishInitNested(desc, WN_GAME_OPTIONS_GAME_SETTINGS);
1763 this->querystrings[WID_GS_FILTER] = &this->filter_editbox;
1764 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
1765 this->SetFocusedWidget(WID_GS_FILTER);
1767 this->InvalidateData();
1770 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
1772 switch (widget) {
1773 case WID_GS_OPTIONSPANEL:
1774 resize->height = SETTING_HEIGHT = max(11, FONT_HEIGHT_NORMAL + 1);
1775 resize->width = 1;
1777 size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET;
1778 break;
1780 case WID_GS_HELP_TEXT: {
1781 static const StringID setting_types[] = {
1782 STR_CONFIG_SETTING_TYPE_CLIENT,
1783 STR_CONFIG_SETTING_TYPE_COMPANY_MENU, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME,
1784 STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
1786 for (uint i = 0; i < lengthof(setting_types); i++) {
1787 SetDParam(0, setting_types[i]);
1788 size->width = max(size->width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width);
1790 size->height = 2 * FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL +
1791 max(size->height, _settings_main_page.GetMaxHelpHeight(size->width));
1792 break;
1795 default:
1796 break;
1800 virtual void OnPaint()
1802 if (this->closing_dropdown) {
1803 this->closing_dropdown = false;
1804 assert(this->valuedropdown_entry != NULL);
1805 this->valuedropdown_entry->SetButtons(0);
1806 this->valuedropdown_entry = NULL;
1808 this->DrawWidgets();
1811 virtual void SetStringParameters(int widget) const
1813 switch (widget) {
1814 case WID_GS_RESTRICT_DROPDOWN:
1815 SetDParam(0, _game_settings_restrict_dropdown[this->filter.mode]);
1816 break;
1818 case WID_GS_TYPE_DROPDOWN:
1819 switch (this->filter.type) {
1820 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME); break;
1821 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME); break;
1822 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT); break;
1823 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL); break;
1825 break;
1829 DropDownList *BuildDropDownList(int widget) const
1831 DropDownList *list = NULL;
1832 switch (widget) {
1833 case WID_GS_RESTRICT_DROPDOWN:
1834 list = new DropDownList();
1836 for (int mode = 0; mode != RM_END; mode++) {
1837 /* If we are in adv. settings screen for the new game's settings,
1838 * we don't want to allow comparing with new game's settings. */
1839 bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame;
1841 list->push_back(new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled));
1843 break;
1845 case WID_GS_TYPE_DROPDOWN:
1846 list = new DropDownList();
1847 list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false));
1848 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));
1849 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));
1850 list->push_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false));
1851 break;
1853 return list;
1856 virtual void DrawWidget(const Rect &r, int widget) const
1858 switch (widget) {
1859 case WID_GS_OPTIONSPANEL:
1860 _settings_main_page.Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, r.top + SETTINGTREE_TOP_OFFSET,
1861 this->vscroll->GetPosition(), this->vscroll->GetPosition() + this->vscroll->GetCapacity(), this->last_clicked);
1862 break;
1864 case WID_GS_HELP_TEXT:
1865 if (this->last_clicked != NULL) {
1866 const SettingDesc *sd = this->last_clicked->d.entry.setting;
1868 int y = r.top;
1869 switch (sd->GetType()) {
1870 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
1871 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT); break;
1872 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
1873 default: NOT_REACHED();
1875 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
1876 y += FONT_HEIGHT_NORMAL;
1878 int32 default_value = ReadValue(&sd->desc.def, sd->save.conv);
1879 this->last_clicked->SetValueDParams(0, default_value);
1880 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
1881 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
1883 DrawStringMultiLine(r.left, r.right, y, r.bottom, this->last_clicked->GetHelpText(), TC_WHITE);
1885 break;
1887 default:
1888 break;
1893 * Set the entry that should have its help text displayed, and mark the window dirty so it gets repainted.
1894 * @param pe Setting to display help text of, use \c NULL to stop displaying help of the currently displayed setting.
1896 void SetDisplayedHelpText(SettingEntry *pe)
1898 if (this->last_clicked != pe) this->SetDirty();
1899 this->last_clicked = pe;
1902 virtual void OnClick(Point pt, int widget, int click_count)
1904 switch (widget) {
1905 case WID_GS_EXPAND_ALL:
1906 this->manually_changed_folding = true;
1907 _settings_main_page.UnFoldAll();
1908 this->InvalidateData();
1909 break;
1911 case WID_GS_COLLAPSE_ALL:
1912 this->manually_changed_folding = true;
1913 _settings_main_page.FoldAll();
1914 this->InvalidateData();
1915 break;
1917 case WID_GS_RESTRICT_DROPDOWN: {
1918 DropDownList *list = this->BuildDropDownList(widget);
1919 if (list != NULL) {
1920 ShowDropDownList(this, list, this->filter.mode, widget);
1922 break;
1925 case WID_GS_TYPE_DROPDOWN: {
1926 DropDownList *list = this->BuildDropDownList(widget);
1927 if (list != NULL) {
1928 ShowDropDownList(this, list, this->filter.type, widget);
1930 break;
1934 if (widget != WID_GS_OPTIONSPANEL) return;
1936 uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET);
1937 if (btn == INT_MAX) return;
1939 uint cur_row = 0;
1940 SettingEntry *pe = _settings_main_page.FindEntry(btn, &cur_row);
1942 if (pe == NULL) return; // Clicked below the last setting of the page
1944 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
1945 if (x < 0) return; // Clicked left of the entry
1947 if ((pe->flags & SEF_KIND_MASK) == SEF_SUBTREE_KIND) {
1948 this->SetDisplayedHelpText(NULL);
1949 pe->d.sub.folded = !pe->d.sub.folded; // Flip 'folded'-ness of the sub-page
1951 this->manually_changed_folding = true;
1953 this->InvalidateData();
1954 return;
1957 assert((pe->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
1958 const SettingDesc *sd = pe->d.entry.setting;
1960 /* return if action is only active in network, or only settable by server */
1961 if (!sd->IsEditable()) {
1962 this->SetDisplayedHelpText(pe);
1963 return;
1966 const void *var = ResolveVariableAddress(settings_ptr, sd);
1967 int32 value = (int32)ReadValue(var, sd->save.conv);
1969 /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
1970 if (x < SETTING_BUTTON_WIDTH && (sd->desc.flags & SGF_MULTISTRING)) {
1971 const SettingDescBase *sdb = &sd->desc;
1972 this->SetDisplayedHelpText(pe);
1974 if (this->valuedropdown_entry == pe) {
1975 /* unclick the dropdown */
1976 HideDropDownMenu(this);
1977 this->closing_dropdown = false;
1978 this->valuedropdown_entry->SetButtons(0);
1979 this->valuedropdown_entry = NULL;
1980 } else {
1981 if (this->valuedropdown_entry != NULL) this->valuedropdown_entry->SetButtons(0);
1982 this->closing_dropdown = false;
1984 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
1985 int rel_y = (pt.y - (int)wid->pos_y - SETTINGTREE_TOP_OFFSET) % wid->resize_y;
1987 Rect wi_rect;
1988 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
1989 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
1990 wi_rect.top = pt.y - rel_y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
1991 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
1993 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
1994 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
1995 this->valuedropdown_entry = pe;
1996 this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
1998 DropDownList *list = new DropDownList();
1999 for (int i = sdb->min; i <= (int)sdb->max; i++) {
2000 list->push_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false));
2003 ShowDropDownListAt(this, list, value, -1, wi_rect, COLOUR_ORANGE, true);
2006 this->SetDirty();
2007 } else if (x < SETTING_BUTTON_WIDTH) {
2008 this->SetDisplayedHelpText(pe);
2009 const SettingDescBase *sdb = &sd->desc;
2010 int32 oldvalue = value;
2012 switch (sdb->cmd) {
2013 case SDT_BOOLX: value ^= 1; break;
2014 case SDT_ONEOFMANY:
2015 case SDT_NUMX: {
2016 /* Add a dynamic step-size to the scroller. In a maximum of
2017 * 50-steps you should be able to get from min to max,
2018 * unless specified otherwise in the 'interval' variable
2019 * of the current setting. */
2020 uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
2021 if (step == 0) step = 1;
2023 /* don't allow too fast scrolling */
2024 if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
2025 _left_button_clicked = false;
2026 return;
2029 /* Increase or decrease the value and clamp it to extremes */
2030 if (x >= SETTING_BUTTON_WIDTH / 2) {
2031 value += step;
2032 if (sdb->min < 0) {
2033 assert((int32)sdb->max >= 0);
2034 if (value > (int32)sdb->max) value = (int32)sdb->max;
2035 } else {
2036 if ((uint32)value > sdb->max) value = (int32)sdb->max;
2038 if (value < sdb->min) value = sdb->min; // skip between "disabled" and minimum
2039 } else {
2040 value -= step;
2041 if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
2044 /* Set up scroller timeout for numeric values */
2045 if (value != oldvalue) {
2046 if (this->clicked_entry != NULL) { // Release previous buttons if any
2047 this->clicked_entry->SetButtons(0);
2049 this->clicked_entry = pe;
2050 this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
2051 this->SetTimeout();
2052 _left_button_clicked = false;
2054 break;
2057 default: NOT_REACHED();
2060 if (value != oldvalue) {
2061 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2062 SetCompanySetting(pe->d.entry.index, value);
2063 } else {
2064 SetSettingValue(pe->d.entry.index, value);
2066 this->SetDirty();
2068 } else {
2069 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
2070 if (this->last_clicked == pe && sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
2071 /* Show the correct currency-translated value */
2072 if (sd->desc.flags & SGF_CURRENCY) value *= _currency->rate;
2074 this->valuewindow_entry = pe;
2075 SetDParam(0, value);
2076 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 10, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
2078 this->SetDisplayedHelpText(pe);
2082 virtual void OnTimeout()
2084 if (this->clicked_entry != NULL) { // On timeout, release any depressed buttons
2085 this->clicked_entry->SetButtons(0);
2086 this->clicked_entry = NULL;
2087 this->SetDirty();
2091 virtual void OnQueryTextFinished(char *str)
2093 /* The user pressed cancel */
2094 if (str == NULL) return;
2096 assert(this->valuewindow_entry != NULL);
2097 assert((this->valuewindow_entry->flags & SEF_KIND_MASK) == SEF_SETTING_KIND);
2098 const SettingDesc *sd = this->valuewindow_entry->d.entry.setting;
2100 int32 value;
2101 if (!StrEmpty(str)) {
2102 value = atoi(str);
2104 /* Save the correct currency-translated value */
2105 if (sd->desc.flags & SGF_CURRENCY) value /= _currency->rate;
2106 } else {
2107 value = (int32)(size_t)sd->desc.def;
2110 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2111 SetCompanySetting(this->valuewindow_entry->d.entry.index, value);
2112 } else {
2113 SetSettingValue(this->valuewindow_entry->d.entry.index, value);
2115 this->SetDirty();
2118 virtual void OnDropdownSelect(int widget, int index)
2120 switch (widget) {
2121 case WID_GS_RESTRICT_DROPDOWN:
2122 this->filter.mode = (RestrictionMode)index;
2123 if (this->filter.mode == RM_CHANGED_AGAINST_DEFAULT ||
2124 this->filter.mode == RM_CHANGED_AGAINST_NEW) {
2126 if (!this->manually_changed_folding) {
2127 /* Expand all when selecting 'changes'. Update the filter state first, in case it becomes less restrictive in some cases. */
2128 _settings_main_page.UpdateFilterState(this->filter, false);
2129 _settings_main_page.UnFoldAll();
2131 } else {
2132 /* Non-'changes' filter. Save as default. */
2133 _settings_client.gui.settings_restriction_mode = this->filter.mode;
2135 this->InvalidateData();
2136 break;
2138 case WID_GS_TYPE_DROPDOWN:
2139 this->filter.type = (SettingType)index;
2140 this->InvalidateData();
2141 break;
2143 default:
2144 if (widget < 0) {
2145 /* Deal with drop down boxes on the panel. */
2146 assert(this->valuedropdown_entry != NULL);
2147 const SettingDesc *sd = this->valuedropdown_entry->d.entry.setting;
2148 assert(sd->desc.flags & SGF_MULTISTRING);
2150 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2151 SetCompanySetting(this->valuedropdown_entry->d.entry.index, index);
2152 } else {
2153 SetSettingValue(this->valuedropdown_entry->d.entry.index, index);
2156 this->SetDirty();
2158 break;
2162 virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
2164 if (widget >= 0) {
2165 /* Normally the default implementation of OnDropdownClose() takes care of
2166 * a few things. We want that behaviour here too, but only for
2167 * "normal" dropdown boxes. The special dropdown boxes added for every
2168 * setting that needs one can't have this call. */
2169 Window::OnDropdownClose(pt, widget, index, instant_close);
2170 } else {
2171 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
2172 * the same dropdown button was clicked again, and then not open the dropdown again.
2173 * So, we only remember that it was closed, and process it on the next OnPaint, which is
2174 * after OnClick. */
2175 assert(this->valuedropdown_entry != NULL);
2176 this->closing_dropdown = true;
2177 this->SetDirty();
2181 virtual void OnInvalidateData(int data = 0, bool gui_scope = true)
2183 if (!gui_scope) return;
2185 _settings_main_page.UpdateFilterState(this->filter, false);
2187 this->vscroll->SetCount(_settings_main_page.Length());
2189 if (this->last_clicked != NULL && !_settings_main_page.IsVisible(this->last_clicked)) {
2190 this->SetDisplayedHelpText(NULL);
2193 bool all_folded = true;
2194 bool all_unfolded = true;
2195 _settings_main_page.GetFoldingState(all_folded, all_unfolded);
2196 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL, all_unfolded);
2197 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
2200 virtual void OnEditboxChanged(int wid)
2202 if (wid == WID_GS_FILTER) {
2203 this->filter.string.SetFilterTerm(this->filter_editbox.text.buf);
2204 if (!this->filter.string.IsEmpty() && !this->manually_changed_folding) {
2205 /* User never expanded/collapsed single pages and entered a filter term.
2206 * Expand everything, to save weird expand clicks, */
2207 _settings_main_page.UnFoldAll();
2209 this->InvalidateData();
2213 virtual void OnResize()
2215 this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
2219 GameSettings *GameSettingsWindow::settings_ptr = NULL;
2221 static const NWidgetPart _nested_settings_selection_widgets[] = {
2222 NWidget(NWID_HORIZONTAL),
2223 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
2224 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2225 EndContainer(),
2226 NWidget(WWT_PANEL, COLOUR_MAUVE),
2227 NWidget(NWID_HORIZONTAL), SetPadding(WD_TEXTPANEL_TOP, 0, WD_TEXTPANEL_BOTTOM, 0),
2228 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
2229 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_GS_RESTRICT_LABEL), SetDataTip(STR_CONFIG_SETTING_RESTRICT_LABEL, STR_NULL),
2230 NWidget(NWID_VERTICAL), SetPIP(0, WD_PAR_VSEP_NORMAL, 0),
2231 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),
2232 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),
2233 EndContainer(),
2234 EndContainer(),
2235 NWidget(NWID_HORIZONTAL), SetPadding(0, 0, WD_TEXTPANEL_BOTTOM, 0),
2236 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
2237 NWidget(WWT_TEXT, COLOUR_MAUVE), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE, STR_NULL),
2238 NWidget(WWT_EDITBOX, COLOUR_MAUVE, WID_GS_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
2239 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
2240 EndContainer(),
2241 EndContainer(),
2242 NWidget(NWID_HORIZONTAL),
2243 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
2244 NWidget(NWID_VERTICAL),
2245 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
2246 EndContainer(),
2247 EndContainer(),
2248 NWidget(WWT_PANEL, COLOUR_MAUVE), SetMinimalSize(400, 40),
2249 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GS_HELP_TEXT), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
2250 SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT),
2251 NWidget(NWID_HORIZONTAL),
2252 NWidget(WWT_PANEL, COLOUR_MAUVE),
2253 NWidget(NWID_HORIZONTAL),
2254 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_EXPAND_ALL), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL, STR_NULL),
2255 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_COLLAPSE_ALL), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL, STR_NULL),
2256 NWidget(NWID_SPACER, INVALID_COLOUR), SetFill(1, 1), SetResize(1, 0),
2257 EndContainer(),
2258 EndContainer(),
2259 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
2260 EndContainer(),
2261 EndContainer(),
2264 static const WindowDesc _settings_selection_desc(
2265 WDP_CENTER, 510, 450,
2266 WC_GAME_OPTIONS, WC_NONE,
2268 _nested_settings_selection_widgets, lengthof(_nested_settings_selection_widgets)
2271 /** Open advanced settings window. */
2272 void ShowGameSettings()
2274 DeleteWindowByClass(WC_GAME_OPTIONS);
2275 new GameSettingsWindow(&_settings_selection_desc);
2280 * Draw [<][>] boxes.
2281 * @param x the x position to draw
2282 * @param y the y position to draw
2283 * @param button_colour the colour of the button
2284 * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked
2285 * @param clickable_left is the left button clickable?
2286 * @param clickable_right is the right button clickable?
2288 void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
2290 int colour = _colour_gradient[button_colour][2];
2292 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
2293 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);
2294 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
2295 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + SETTING_BUTTON_WIDTH / 2, y + WD_IMGBTN_TOP);
2297 /* Grey out the buttons that aren't clickable */
2298 bool rtl = _current_text_dir == TD_RTL;
2299 if (rtl ? !clickable_right : !clickable_left) {
2300 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH / 2 - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
2302 if (rtl ? !clickable_left : !clickable_right) {
2303 GfxFillRect(x + SETTING_BUTTON_WIDTH / 2 + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
2308 * Draw a dropdown button.
2309 * @param x the x position to draw
2310 * @param y the y position to draw
2311 * @param button_colour the colour of the button
2312 * @param state true = lowered
2313 * @param clickable is the button clickable?
2315 void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
2317 static const char *DOWNARROW = "\xEE\x8A\xAA";
2319 int colour = _colour_gradient[button_colour][2];
2321 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, state ? FR_LOWERED : FR_NONE);
2322 DrawString(x + (state ? 1 : 0), x + SETTING_BUTTON_WIDTH - (state ? 0 : 1), y + (state ? 2 : 1), DOWNARROW, TC_BLACK, SA_HOR_CENTER);
2324 if (!clickable) {
2325 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
2330 * Draw a toggle button.
2331 * @param x the x position to draw
2332 * @param y the y position to draw
2333 * @param state true = lowered
2334 * @param clickable is the button clickable?
2336 void DrawBoolButton(int x, int y, bool state, bool clickable)
2338 static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
2339 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
2342 struct CustomCurrencyWindow : Window {
2343 int query_widget;
2345 CustomCurrencyWindow(const WindowDesc *desc) : Window()
2347 this->InitNested(desc);
2349 SetButtonState();
2352 void SetButtonState()
2354 this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1);
2355 this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX);
2356 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
2357 this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
2360 virtual void SetStringParameters(int widget) const
2362 switch (widget) {
2363 case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
2364 case WID_CC_SEPARATOR: SetDParamStr(0, _custom_currency.separator); break;
2365 case WID_CC_PREFIX: SetDParamStr(0, _custom_currency.prefix); break;
2366 case WID_CC_SUFFIX: SetDParamStr(0, _custom_currency.suffix); break;
2367 case WID_CC_YEAR:
2368 SetDParam(0, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
2369 SetDParam(1, _custom_currency.to_euro);
2370 break;
2372 case WID_CC_PREVIEW:
2373 SetDParam(0, 10000);
2374 break;
2378 virtual void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize)
2380 switch (widget) {
2381 /* Set the appropriate width for the edit 'buttons' */
2382 case WID_CC_SEPARATOR_EDIT:
2383 case WID_CC_PREFIX_EDIT:
2384 case WID_CC_SUFFIX_EDIT:
2385 size->width = this->GetWidget<NWidgetBase>(WID_CC_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(WID_CC_RATE_UP)->smallest_x;
2386 break;
2388 /* Make sure the window is wide enough for the widest exchange rate */
2389 case WID_CC_RATE:
2390 SetDParam(0, 1);
2391 SetDParam(1, INT32_MAX);
2392 *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
2393 break;
2397 virtual void OnClick(Point pt, int widget, int click_count)
2399 int line = 0;
2400 int len = 0;
2401 StringID str = 0;
2402 CharSetFilter afilter = CS_ALPHANUMERAL;
2404 switch (widget) {
2405 case WID_CC_RATE_DOWN:
2406 if (_custom_currency.rate > 1) _custom_currency.rate--;
2407 if (_custom_currency.rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
2408 this->EnableWidget(WID_CC_RATE_UP);
2409 break;
2411 case WID_CC_RATE_UP:
2412 if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
2413 if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
2414 this->EnableWidget(WID_CC_RATE_DOWN);
2415 break;
2417 case WID_CC_RATE:
2418 SetDParam(0, _custom_currency.rate);
2419 str = STR_JUST_INT;
2420 len = 5;
2421 line = WID_CC_RATE;
2422 afilter = CS_NUMERAL;
2423 break;
2425 case WID_CC_SEPARATOR_EDIT:
2426 case WID_CC_SEPARATOR:
2427 SetDParamStr(0, _custom_currency.separator);
2428 str = STR_JUST_RAW_STRING;
2429 len = 1;
2430 line = WID_CC_SEPARATOR;
2431 break;
2433 case WID_CC_PREFIX_EDIT:
2434 case WID_CC_PREFIX:
2435 SetDParamStr(0, _custom_currency.prefix);
2436 str = STR_JUST_RAW_STRING;
2437 len = 12;
2438 line = WID_CC_PREFIX;
2439 break;
2441 case WID_CC_SUFFIX_EDIT:
2442 case WID_CC_SUFFIX:
2443 SetDParamStr(0, _custom_currency.suffix);
2444 str = STR_JUST_RAW_STRING;
2445 len = 12;
2446 line = WID_CC_SUFFIX;
2447 break;
2449 case WID_CC_YEAR_DOWN:
2450 _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
2451 if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
2452 this->EnableWidget(WID_CC_YEAR_UP);
2453 break;
2455 case WID_CC_YEAR_UP:
2456 _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
2457 if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
2458 this->EnableWidget(WID_CC_YEAR_DOWN);
2459 break;
2461 case WID_CC_YEAR:
2462 SetDParam(0, _custom_currency.to_euro);
2463 str = STR_JUST_INT;
2464 len = 7;
2465 line = WID_CC_YEAR;
2466 afilter = CS_NUMERAL;
2467 break;
2470 if (len != 0) {
2471 this->query_widget = line;
2472 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
2475 this->SetTimeout();
2476 this->SetDirty();
2479 virtual void OnQueryTextFinished(char *str)
2481 if (str == NULL) return;
2483 switch (this->query_widget) {
2484 case WID_CC_RATE:
2485 _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
2486 break;
2488 case WID_CC_SEPARATOR: // Thousands separator
2489 strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
2490 break;
2492 case WID_CC_PREFIX:
2493 strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
2494 break;
2496 case WID_CC_SUFFIX:
2497 strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
2498 break;
2500 case WID_CC_YEAR: { // Year to switch to euro
2501 int val = atoi(str);
2503 _custom_currency.to_euro = (val < 2000 ? CF_NOEURO : min(val, MAX_YEAR));
2504 break;
2507 MarkWholeScreenDirty();
2508 SetButtonState();
2511 virtual void OnTimeout()
2513 this->SetDirty();
2517 static const NWidgetPart _nested_cust_currency_widgets[] = {
2518 NWidget(NWID_HORIZONTAL),
2519 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2520 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2521 EndContainer(),
2522 NWidget(WWT_PANEL, COLOUR_GREY),
2523 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
2524 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2525 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
2526 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
2527 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2528 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
2529 EndContainer(),
2530 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2531 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
2532 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2533 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
2534 EndContainer(),
2535 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2536 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
2537 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2538 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
2539 EndContainer(),
2540 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2541 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
2542 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2543 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
2544 EndContainer(),
2545 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2546 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
2547 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
2548 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2549 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
2550 EndContainer(),
2551 EndContainer(),
2552 NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
2553 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
2554 EndContainer(),
2557 static const WindowDesc _cust_currency_desc(
2558 WDP_CENTER, 0, 0,
2559 WC_CUSTOM_CURRENCY, WC_NONE,
2561 _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
2564 /** Open custom currency window. */
2565 static void ShowCustCurrency()
2567 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
2568 new CustomCurrencyWindow(&_cust_currency_desc);