Codechange: Store custom station layouts in a map instead of nested vectors. (#12898)
[openttd-github.git] / src / settings_gui.cpp
blobfb5c08ec8668b331aac0d1aeaa6bc491985369d7
1 /*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
8 /** @file settings_gui.cpp GUI for settings. */
10 #include "stdafx.h"
11 #include "currency.h"
12 #include "error.h"
13 #include "settings_gui.h"
14 #include "textbuf_gui.h"
15 #include "command_func.h"
16 #include "network/network.h"
17 #include "network/network_content.h"
18 #include "town.h"
19 #include "settings_internal.h"
20 #include "strings_func.h"
21 #include "window_func.h"
22 #include "string_func.h"
23 #include "dropdown_type.h"
24 #include "dropdown_func.h"
25 #include "dropdown_common_type.h"
26 #include "slider_func.h"
27 #include "highscore.h"
28 #include "base_media_base.h"
29 #include "company_base.h"
30 #include "company_func.h"
31 #include "viewport_func.h"
32 #include "core/geometry_func.hpp"
33 #include "ai/ai.hpp"
34 #include "blitter/factory.hpp"
35 #include "language.h"
36 #include "textfile_gui.h"
37 #include "stringfilter_type.h"
38 #include "querystring_gui.h"
39 #include "fontcache.h"
40 #include "zoom_func.h"
41 #include "rev.h"
42 #include "video/video_driver.hpp"
43 #include "music/music_driver.hpp"
44 #include "gui.h"
45 #include "mixer.h"
46 #include "newgrf_config.h"
47 #include "network/core/config.h"
48 #include "network/network_gui.h"
49 #include "network/network_survey.h"
50 #include "video/video_driver.hpp"
51 #include "social_integration.h"
52 #include "sound_func.h"
54 #include "safeguards.h"
57 #if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
58 # define HAS_TRUETYPE_FONT
59 #endif
61 static const StringID _autosave_dropdown[] = {
62 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
63 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_10_MINUTES,
64 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_30_MINUTES,
65 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_60_MINUTES,
66 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_120_MINUTES,
67 INVALID_STRING_ID,
70 /** Available settings for autosave intervals. */
71 static const uint32_t _autosave_dropdown_to_minutes[] = {
72 0, ///< never
73 10,
74 30,
75 60,
76 120,
79 static Dimension _circle_size; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.
81 static const void *ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd);
83 /**
84 * Get index of the current screen resolution.
85 * @return Index of the current screen resolution if it is a known resolution, _resolutions.size() otherwise.
87 static uint GetCurrentResolutionIndex()
89 auto it = std::find(_resolutions.begin(), _resolutions.end(), Dimension(_screen.width, _screen.height));
90 return std::distance(_resolutions.begin(), it);
93 static void ShowCustCurrency();
95 /** Window for displaying the textfile of a BaseSet. */
96 struct BaseSetTextfileWindow : public TextfileWindow {
97 const std::string name; ///< Name of the content.
98 const StringID content_type; ///< STR_CONTENT_TYPE_xxx for title.
100 BaseSetTextfileWindow(TextfileType file_type, const std::string &name, const std::string &textfile, StringID content_type) : TextfileWindow(file_type), name(name), content_type(content_type)
102 this->ConstructWindow();
103 this->LoadTextfile(textfile, BASESET_DIR);
106 void SetStringParameters(WidgetID widget) const override
108 if (widget == WID_TF_CAPTION) {
109 SetDParam(0, content_type);
110 SetDParamStr(1, this->name);
116 * Open the BaseSet version of the textfile window.
117 * @param file_type The type of textfile to display.
118 * @param baseset The BaseSet to use.
119 * @param content_type STR_CONTENT_TYPE_xxx for title.
121 template <class TBaseSet>
122 void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet *baseset, StringID content_type)
124 CloseWindowById(WC_TEXTFILE, file_type);
125 new BaseSetTextfileWindow(file_type, baseset->name, *baseset->GetTextfile(file_type), content_type);
128 template <class T>
129 DropDownList BuildSetDropDownList(int *selected_index)
131 int n = T::GetNumSets();
132 *selected_index = T::GetIndexOfUsedSet();
133 DropDownList list;
134 for (int i = 0; i < n; i++) {
135 list.push_back(MakeDropDownListStringItem(T::GetSet(i)->GetListLabel(), i));
137 return list;
140 std::set<int> _refresh_rates = { 30, 60, 75, 90, 100, 120, 144, 240 };
143 * Add the refresh rate from the config and the refresh rates from all the monitors to
144 * our list of refresh rates shown in the GUI.
146 static void AddCustomRefreshRates()
148 /* Add the refresh rate as selected in the config. */
149 _refresh_rates.insert(_settings_client.gui.refresh_rate);
151 /* Add all the refresh rates of all monitors connected to the machine. */
152 std::vector<int> monitorRates = VideoDriver::GetInstance()->GetListOfMonitorRefreshRates();
153 std::copy(monitorRates.begin(), monitorRates.end(), std::inserter(_refresh_rates, _refresh_rates.end()));
156 static const int SCALE_NMARKS = (MAX_INTERFACE_SCALE - MIN_INTERFACE_SCALE) / 25 + 1; // Show marks at 25% increments
157 static const int VOLUME_NMARKS = 9; // Show 5 values and 4 empty marks.
159 static StringID ScaleMarkFunc(int, int, int value)
161 /* Label only every 100% mark. */
162 if (value % 100 != 0) return STR_NULL;
164 SetDParam(0, value / 100);
165 SetDParam(1, 0);
166 return STR_GAME_OPTIONS_GUI_SCALE_MARK;
169 static StringID VolumeMarkFunc(int, int mark, int value)
171 /* Label only every other mark. */
172 if (mark % 2 != 0) return STR_NULL;
174 SetDParam(0, value / 31 * 25); // 0-127 does not map nicely to 0-100. Dividing first gives us nice round numbers.
175 return STR_GAME_OPTIONS_VOLUME_MARK;
178 static constexpr NWidgetPart _nested_social_plugins_widgets[] = {
179 NWidget(NWID_HORIZONTAL),
180 NWidget(WWT_FRAME, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_TITLE), SetDataTip(STR_JUST_STRING2, STR_NULL),
181 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
182 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_PLATFORM, STR_NULL),
183 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_PLATFORM), SetMinimalSize(100, 12), SetDataTip(STR_JUST_RAW_STRING, STR_NULL), SetAlignment(SA_RIGHT),
184 EndContainer(),
185 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
186 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE, STR_NULL),
187 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_STATE), SetMinimalSize(100, 12), SetDataTip(STR_JUST_STRING1, STR_NULL), SetAlignment(SA_RIGHT),
188 EndContainer(),
189 EndContainer(),
190 EndContainer(),
193 static constexpr NWidgetPart _nested_social_plugins_none_widgets[] = {
194 NWidget(NWID_HORIZONTAL),
195 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGINS_NONE, STR_NULL),
196 EndContainer(),
199 class NWidgetSocialPlugins : public NWidgetVertical {
200 public:
201 NWidgetSocialPlugins()
203 this->plugins = SocialIntegration::GetPlugins();
205 if (this->plugins.empty()) {
206 auto widget = MakeNWidgets(_nested_social_plugins_none_widgets, nullptr);
207 this->Add(std::move(widget));
208 } else {
209 for (size_t i = 0; i < this->plugins.size(); i++) {
210 auto widget = MakeNWidgets(_nested_social_plugins_widgets, nullptr);
211 this->Add(std::move(widget));
215 this->SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0);
218 void FillWidgetLookup(WidgetLookup &widget_lookup) override
220 widget_lookup[WID_GO_SOCIAL_PLUGINS] = this;
221 NWidgetVertical::FillWidgetLookup(widget_lookup);
224 void SetupSmallestSize(Window *w) override
226 this->current_index = -1;
227 NWidgetVertical::SetupSmallestSize(w);
231 * Find of all the plugins the one where the member is the widest (in pixels).
233 * @param member The member to check with.
234 * @return The plugin that has the widest value (in pixels) for the given member.
236 template <typename T>
237 std::string &GetWidestPlugin(T SocialIntegrationPlugin::*member) const
239 std::string *longest = &(this->plugins[0]->*member);
240 int longest_length = 0;
242 for (auto *plugin : this->plugins) {
243 int length = GetStringBoundingBox(plugin->*member).width;
244 if (length > longest_length) {
245 longest_length = length;
246 longest = &(plugin->*member);
250 return *longest;
253 void SetStringParameters(int widget) const
255 switch (widget) {
256 case WID_GO_SOCIAL_PLUGIN_TITLE:
257 /* For SetupSmallestSize, use the longest string we have. */
258 if (this->current_index < 0) {
259 SetDParamStr(0, GetWidestPlugin(&SocialIntegrationPlugin::name));
260 SetDParamStr(1, GetWidestPlugin(&SocialIntegrationPlugin::version));
261 break;
264 if (this->plugins[this->current_index]->name.empty()) {
265 SetDParam(0, STR_JUST_RAW_STRING);
266 SetDParamStr(1, this->plugins[this->current_index]->basepath);
267 } else {
268 SetDParam(0, STR_GAME_OPTIONS_SOCIAL_PLUGIN_TITLE);
269 SetDParamStr(1, this->plugins[this->current_index]->name);
270 SetDParamStr(2, this->plugins[this->current_index]->version);
272 break;
274 case WID_GO_SOCIAL_PLUGIN_PLATFORM:
275 /* For SetupSmallestSize, use the longest string we have. */
276 if (this->current_index < 0) {
277 SetDParamStr(0, GetWidestPlugin(&SocialIntegrationPlugin::social_platform));
278 break;
281 SetDParamStr(0, this->plugins[this->current_index]->social_platform);
282 break;
284 case WID_GO_SOCIAL_PLUGIN_STATE: {
285 static const std::pair<SocialIntegrationPlugin::State, StringID> state_to_string[] = {
286 { SocialIntegrationPlugin::RUNNING, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_RUNNING },
287 { SocialIntegrationPlugin::FAILED, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_FAILED },
288 { SocialIntegrationPlugin::PLATFORM_NOT_RUNNING, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_PLATFORM_NOT_RUNNING },
289 { SocialIntegrationPlugin::UNLOADED, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_UNLOADED },
290 { SocialIntegrationPlugin::DUPLICATE, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_DUPLICATE },
291 { SocialIntegrationPlugin::UNSUPPORTED_API, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_UNSUPPORTED_API },
292 { SocialIntegrationPlugin::INVALID_SIGNATURE, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_INVALID_SIGNATURE },
295 /* For SetupSmallestSize, use the longest string we have. */
296 if (this->current_index < 0) {
297 auto longest_plugin = GetWidestPlugin(&SocialIntegrationPlugin::social_platform);
299 /* Set the longest plugin when looking for the longest status. */
300 SetDParamStr(0, longest_plugin);
302 StringID longest = STR_NULL;
303 int longest_length = 0;
304 for (auto state : state_to_string) {
305 int length = GetStringBoundingBox(state.second).width;
306 if (length > longest_length) {
307 longest_length = length;
308 longest = state.second;
312 SetDParam(0, longest);
313 SetDParamStr(1, longest_plugin);
314 break;
317 auto plugin = this->plugins[this->current_index];
319 /* Default string, in case no state matches. */
320 SetDParam(0, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_FAILED);
321 SetDParamStr(1, plugin->social_platform);
323 /* Find the string for the state. */
324 for (auto state : state_to_string) {
325 if (plugin->state == state.first) {
326 SetDParam(0, state.second);
327 break;
331 break;
335 void Draw(const Window *w) override
337 this->current_index = 0;
339 for (auto &wid : this->children) {
340 wid->Draw(w);
341 this->current_index++;
345 private:
346 int current_index = -1;
347 std::vector<SocialIntegrationPlugin *> plugins;
350 /** Construct nested container widget for managing the list of social plugins. */
351 std::unique_ptr<NWidgetBase> MakeNWidgetSocialPlugins()
353 return std::make_unique<NWidgetSocialPlugins>();
356 struct GameOptionsWindow : Window {
357 GameSettings *opt;
358 bool reload;
359 int gui_scale;
360 static inline WidgetID active_tab = WID_GO_TAB_GENERAL;
362 GameOptionsWindow(WindowDesc &desc) : Window(desc)
364 this->opt = &GetGameSettings();
365 this->reload = false;
366 this->gui_scale = _gui_scale;
368 AddCustomRefreshRates();
370 this->InitNested(WN_GAME_OPTIONS_GAME_OPTIONS);
371 this->OnInvalidateData(0);
373 this->SetTab(GameOptionsWindow::active_tab);
375 if constexpr (!NetworkSurveyHandler::IsSurveyPossible()) this->GetWidget<NWidgetStacked>(WID_GO_SURVEY_SEL)->SetDisplayedPlane(SZSP_NONE);
378 void Close([[maybe_unused]] int data = 0) override
380 CloseWindowById(WC_CUSTOM_CURRENCY, 0);
381 CloseWindowByClass(WC_TEXTFILE);
382 if (this->reload) _switch_mode = SM_MENU;
383 this->Window::Close();
387 * Build the dropdown list for a specific widget.
388 * @param widget Widget to build list for
389 * @param selected_index Currently selected item
390 * @return the built dropdown list, or nullptr if the widget has no dropdown menu.
392 DropDownList BuildDropDownList(WidgetID widget, int *selected_index) const
394 DropDownList list;
395 switch (widget) {
396 case WID_GO_CURRENCY_DROPDOWN: { // Setup currencies dropdown
397 *selected_index = this->opt->locale.currency;
398 uint64_t disabled = _game_mode == GM_MENU ? 0LL : ~GetMaskOfAllowedCurrencies();
400 /* Add non-custom currencies; sorted naturally */
401 for (const CurrencySpec &currency : _currency_specs) {
402 int i = &currency - _currency_specs.data();
403 if (i == CURRENCY_CUSTOM) continue;
404 if (currency.code.empty()) {
405 list.push_back(MakeDropDownListStringItem(currency.name, i, HasBit(disabled, i)));
406 } else {
407 SetDParam(0, currency.name);
408 SetDParamStr(1, currency.code);
409 list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CODE, i, HasBit(disabled, i)));
412 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
414 /* Append custom currency at the end */
415 list.push_back(MakeDropDownListDividerItem()); // separator line
416 list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM)));
417 break;
420 case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
421 int index = 0;
422 for (auto &minutes : _autosave_dropdown_to_minutes) {
423 index++;
424 if (_settings_client.gui.autosave_interval <= minutes) break;
426 *selected_index = index - 1;
428 const StringID *items = _autosave_dropdown;
429 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
430 list.push_back(MakeDropDownListStringItem(*items, i));
432 break;
435 case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
436 for (uint i = 0; i < _languages.size(); i++) {
437 bool hide_language = IsReleasedVersion() && !_languages[i].IsReasonablyFinished();
438 if (hide_language) continue;
439 bool hide_percentage = IsReleasedVersion() || _languages[i].missing < _settings_client.gui.missing_strings_threshold;
440 if (&_languages[i] == _current_language) {
441 *selected_index = i;
442 SetDParamStr(0, _languages[i].own_name);
443 } else {
444 /* Especially with sprite-fonts, not all localized
445 * names can be rendered. So instead, we use the
446 * international names for anything but the current
447 * selected language. This avoids showing a few ????
448 * entries in the dropdown list. */
449 SetDParamStr(0, _languages[i].name);
451 SetDParam(1, (LANGUAGE_TOTAL_STRINGS - _languages[i].missing) * 100 / LANGUAGE_TOTAL_STRINGS);
452 list.push_back(MakeDropDownListStringItem(hide_percentage ? STR_JUST_RAW_STRING : STR_GAME_OPTIONS_LANGUAGE_PERCENTAGE, i));
454 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
455 break;
458 case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
459 if (_resolutions.empty()) break;
461 *selected_index = GetCurrentResolutionIndex();
462 for (uint i = 0; i < _resolutions.size(); i++) {
463 SetDParam(0, _resolutions[i].width);
464 SetDParam(1, _resolutions[i].height);
465 list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_RESOLUTION_ITEM, i));
467 break;
469 case WID_GO_REFRESH_RATE_DROPDOWN: // Setup refresh rate dropdown
470 for (auto it = _refresh_rates.begin(); it != _refresh_rates.end(); it++) {
471 auto i = std::distance(_refresh_rates.begin(), it);
472 if (*it == _settings_client.gui.refresh_rate) *selected_index = i;
473 SetDParam(0, *it);
474 list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, i));
476 break;
478 case WID_GO_BASE_GRF_DROPDOWN:
479 list = BuildSetDropDownList<BaseGraphics>(selected_index);
480 break;
482 case WID_GO_BASE_SFX_DROPDOWN:
483 list = BuildSetDropDownList<BaseSounds>(selected_index);
484 break;
486 case WID_GO_BASE_MUSIC_DROPDOWN:
487 list = BuildSetDropDownList<BaseMusic>(selected_index);
488 break;
491 return list;
494 void SetStringParameters(WidgetID widget) const override
496 switch (widget) {
497 case WID_GO_CURRENCY_DROPDOWN: {
498 const CurrencySpec &currency = _currency_specs[this->opt->locale.currency];
499 if (currency.code.empty()) {
500 SetDParam(0, currency.name);
501 } else {
502 SetDParam(0, STR_GAME_OPTIONS_CURRENCY_CODE);
503 SetDParam(1, currency.name);
504 SetDParamStr(2, currency.code);
506 break;
508 case WID_GO_AUTOSAVE_DROPDOWN: {
509 int index = 0;
510 for (auto &minutes : _autosave_dropdown_to_minutes) {
511 index++;
512 if (_settings_client.gui.autosave_interval <= minutes) break;
514 SetDParam(0, _autosave_dropdown[index - 1]);
515 break;
517 case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
518 case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->GetListLabel()); break;
519 case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->GetListLabel()); break;
520 case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->GetListLabel()); break;
521 case WID_GO_REFRESH_RATE_DROPDOWN: SetDParam(0, _settings_client.gui.refresh_rate); break;
522 case WID_GO_RESOLUTION_DROPDOWN: {
523 auto current_resolution = GetCurrentResolutionIndex();
525 if (current_resolution == _resolutions.size()) {
526 SetDParam(0, STR_GAME_OPTIONS_RESOLUTION_OTHER);
527 } else {
528 SetDParam(0, STR_GAME_OPTIONS_RESOLUTION_ITEM);
529 SetDParam(1, _resolutions[current_resolution].width);
530 SetDParam(2, _resolutions[current_resolution].height);
532 break;
535 case WID_GO_SOCIAL_PLUGIN_TITLE:
536 case WID_GO_SOCIAL_PLUGIN_PLATFORM:
537 case WID_GO_SOCIAL_PLUGIN_STATE: {
538 const NWidgetSocialPlugins *plugin = this->GetWidget<NWidgetSocialPlugins>(WID_GO_SOCIAL_PLUGINS);
539 assert(plugin != nullptr);
541 plugin->SetStringParameters(widget);
542 break;
547 void DrawWidget(const Rect &r, WidgetID widget) const override
549 switch (widget) {
550 case WID_GO_BASE_GRF_DESCRIPTION:
551 SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
552 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
553 break;
555 case WID_GO_BASE_SFX_DESCRIPTION:
556 SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
557 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
558 break;
560 case WID_GO_BASE_MUSIC_DESCRIPTION:
561 SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
562 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_JUST_RAW_STRING, TC_BLACK);
563 break;
565 case WID_GO_GUI_SCALE:
566 DrawSliderWidget(r, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, SCALE_NMARKS, this->gui_scale, ScaleMarkFunc);
567 break;
569 case WID_GO_VIDEO_DRIVER_INFO:
570 SetDParamStr(0, std::string{VideoDriver::GetInstance()->GetInfoString()});
571 DrawStringMultiLine(r, STR_GAME_OPTIONS_VIDEO_DRIVER_INFO);
572 break;
574 case WID_GO_BASE_SFX_VOLUME:
575 DrawSliderWidget(r, 0, INT8_MAX, VOLUME_NMARKS, _settings_client.music.effect_vol, VolumeMarkFunc);
576 break;
578 case WID_GO_BASE_MUSIC_VOLUME:
579 DrawSliderWidget(r, 0, INT8_MAX, VOLUME_NMARKS, _settings_client.music.music_vol, VolumeMarkFunc);
580 break;
584 void SetTab(WidgetID widget)
586 this->SetWidgetsLoweredState(false, WID_GO_TAB_GENERAL, WID_GO_TAB_GRAPHICS, WID_GO_TAB_SOUND, WID_GO_TAB_SOCIAL);
587 this->LowerWidget(widget);
588 GameOptionsWindow::active_tab = widget;
590 int pane;
591 switch (widget) {
592 case WID_GO_TAB_GENERAL: pane = 0; break;
593 case WID_GO_TAB_GRAPHICS: pane = 1; break;
594 case WID_GO_TAB_SOUND: pane = 2; break;
595 case WID_GO_TAB_SOCIAL: pane = 3; break;
596 default: NOT_REACHED();
599 this->GetWidget<NWidgetStacked>(WID_GO_TAB_SELECTION)->SetDisplayedPlane(pane);
600 this->SetDirty();
603 void OnResize() override
605 bool changed = false;
607 NWidgetResizeBase *wid = this->GetWidget<NWidgetResizeBase>(WID_GO_BASE_GRF_DESCRIPTION);
608 int y = 0;
609 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
610 SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
611 y = std::max(y, GetStringHeight(STR_JUST_RAW_STRING, wid->current_x));
613 changed |= wid->UpdateVerticalSize(y);
615 wid = this->GetWidget<NWidgetResizeBase>(WID_GO_BASE_SFX_DESCRIPTION);
616 y = 0;
617 for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
618 SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
619 y = std::max(y, GetStringHeight(STR_JUST_RAW_STRING, wid->current_x));
621 changed |= wid->UpdateVerticalSize(y);
623 wid = this->GetWidget<NWidgetResizeBase>(WID_GO_BASE_MUSIC_DESCRIPTION);
624 y = 0;
625 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
626 SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
627 y = std::max(y, GetStringHeight(STR_JUST_RAW_STRING, wid->current_x));
629 changed |= wid->UpdateVerticalSize(y);
631 wid = this->GetWidget<NWidgetResizeBase>(WID_GO_VIDEO_DRIVER_INFO);
632 SetDParamStr(0, std::string{VideoDriver::GetInstance()->GetInfoString()});
633 y = GetStringHeight(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, wid->current_x);
634 changed |= wid->UpdateVerticalSize(y);
636 if (changed) this->ReInit(0, 0, this->flags & WF_CENTERED);
639 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
641 switch (widget) {
642 case WID_GO_TEXT_SFX_VOLUME:
643 case WID_GO_TEXT_MUSIC_VOLUME: {
644 Dimension d = maxdim(GetStringBoundingBox(STR_GAME_OPTIONS_SFX_VOLUME), GetStringBoundingBox(STR_GAME_OPTIONS_MUSIC_VOLUME));
645 d.width += padding.width;
646 d.height += padding.height;
647 size = maxdim(size, d);
648 break;
651 case WID_GO_CURRENCY_DROPDOWN:
652 case WID_GO_AUTOSAVE_DROPDOWN:
653 case WID_GO_LANG_DROPDOWN:
654 case WID_GO_RESOLUTION_DROPDOWN:
655 case WID_GO_REFRESH_RATE_DROPDOWN:
656 case WID_GO_BASE_GRF_DROPDOWN:
657 case WID_GO_BASE_SFX_DROPDOWN:
658 case WID_GO_BASE_MUSIC_DROPDOWN: {
659 int selected;
660 size.width = std::max(size.width, GetDropDownListDimension(this->BuildDropDownList(widget, &selected)).width + padding.width);
661 break;
666 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
668 if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_CONTENT_END) {
669 if (BaseGraphics::GetUsedSet() == nullptr) return;
671 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
672 return;
674 if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_CONTENT_END) {
675 if (BaseSounds::GetUsedSet() == nullptr) return;
677 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
678 return;
680 if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_CONTENT_END) {
681 if (BaseMusic::GetUsedSet() == nullptr) return;
683 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
684 return;
686 switch (widget) {
687 case WID_GO_TAB_GENERAL:
688 case WID_GO_TAB_GRAPHICS:
689 case WID_GO_TAB_SOUND:
690 case WID_GO_TAB_SOCIAL:
691 this->SetTab(widget);
692 break;
694 case WID_GO_SURVEY_PARTICIPATE_BUTTON:
695 switch (_settings_client.network.participate_survey) {
696 case PS_ASK:
697 case PS_NO:
698 _settings_client.network.participate_survey = PS_YES;
699 break;
701 case PS_YES:
702 _settings_client.network.participate_survey = PS_NO;
703 break;
706 this->SetWidgetLoweredState(WID_GO_SURVEY_PARTICIPATE_BUTTON, _settings_client.network.participate_survey == PS_YES);
707 this->SetWidgetDirty(WID_GO_SURVEY_PARTICIPATE_BUTTON);
708 break;
710 case WID_GO_SURVEY_LINK_BUTTON:
711 OpenBrowser(NETWORK_SURVEY_DETAILS_LINK);
712 break;
714 case WID_GO_SURVEY_PREVIEW_BUTTON:
715 ShowSurveyResultTextfileWindow();
716 break;
718 case WID_GO_FULLSCREEN_BUTTON: // Click fullscreen on/off
719 /* try to toggle full-screen on/off */
720 if (!ToggleFullScreen(!_fullscreen)) {
721 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
723 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
724 this->SetWidgetDirty(WID_GO_FULLSCREEN_BUTTON);
725 break;
727 case WID_GO_VIDEO_ACCEL_BUTTON:
728 _video_hw_accel = !_video_hw_accel;
729 ShowErrorMessage(STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART, INVALID_STRING_ID, WL_INFO);
730 this->SetWidgetLoweredState(WID_GO_VIDEO_ACCEL_BUTTON, _video_hw_accel);
731 this->SetWidgetDirty(WID_GO_VIDEO_ACCEL_BUTTON);
732 #ifndef __APPLE__
733 this->SetWidgetLoweredState(WID_GO_VIDEO_VSYNC_BUTTON, _video_hw_accel && _video_vsync);
734 this->SetWidgetDisabledState(WID_GO_VIDEO_VSYNC_BUTTON, !_video_hw_accel);
735 this->SetWidgetDirty(WID_GO_VIDEO_VSYNC_BUTTON);
736 #endif
737 break;
739 case WID_GO_VIDEO_VSYNC_BUTTON:
740 if (!_video_hw_accel) break;
742 _video_vsync = !_video_vsync;
743 VideoDriver::GetInstance()->ToggleVsync(_video_vsync);
745 this->SetWidgetLoweredState(WID_GO_VIDEO_VSYNC_BUTTON, _video_vsync);
746 this->SetWidgetDirty(WID_GO_VIDEO_VSYNC_BUTTON);
747 this->SetWidgetDisabledState(WID_GO_REFRESH_RATE_DROPDOWN, _video_vsync);
748 this->SetWidgetDirty(WID_GO_REFRESH_RATE_DROPDOWN);
749 break;
751 case WID_GO_GUI_SCALE_BEVEL_BUTTON: {
752 _settings_client.gui.scale_bevels = !_settings_client.gui.scale_bevels;
754 this->SetWidgetLoweredState(WID_GO_GUI_SCALE_BEVEL_BUTTON, _settings_client.gui.scale_bevels);
755 this->SetDirty();
757 SetupWidgetDimensions();
758 ReInitAllWindows(true);
759 break;
762 #ifdef HAS_TRUETYPE_FONT
763 case WID_GO_GUI_FONT_SPRITE:
764 _fcsettings.prefer_sprite = !_fcsettings.prefer_sprite;
766 this->SetWidgetLoweredState(WID_GO_GUI_FONT_SPRITE, _fcsettings.prefer_sprite);
767 this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
768 this->SetDirty();
770 InitFontCache(false);
771 InitFontCache(true);
772 ClearFontCache();
773 CheckForMissingGlyphs();
774 SetupWidgetDimensions();
775 UpdateAllVirtCoords();
776 ReInitAllWindows(true);
777 break;
779 case WID_GO_GUI_FONT_AA:
780 _fcsettings.global_aa = !_fcsettings.global_aa;
782 this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
783 MarkWholeScreenDirty();
785 ClearFontCache();
786 break;
787 #endif /* HAS_TRUETYPE_FONT */
789 case WID_GO_GUI_SCALE:
790 if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, _ctrl_pressed ? 0 : SCALE_NMARKS, this->gui_scale)) {
791 this->SetWidgetDirty(widget);
794 if (click_count > 0) this->mouse_capture_widget = widget;
795 break;
797 case WID_GO_GUI_SCALE_AUTO:
799 if (_gui_scale_cfg == -1) {
800 _gui_scale_cfg = _gui_scale;
801 this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, false);
802 } else {
803 _gui_scale_cfg = -1;
804 this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, true);
805 if (AdjustGUIZoom(false)) ReInitAllWindows(true);
806 this->gui_scale = _gui_scale;
808 this->SetWidgetDirty(widget);
809 break;
812 case WID_GO_BASE_GRF_PARAMETERS: {
813 auto *used_set = BaseGraphics::GetUsedSet();
814 if (used_set == nullptr || !used_set->IsConfigurable()) break;
815 GRFConfig &extra_cfg = used_set->GetOrCreateExtraConfig();
816 if (extra_cfg.num_params == 0) extra_cfg.SetParameterDefaults();
817 OpenGRFParameterWindow(true, &extra_cfg, _game_mode == GM_MENU);
818 if (_game_mode == GM_MENU) this->reload = true;
819 break;
822 case WID_GO_BASE_SFX_VOLUME:
823 case WID_GO_BASE_MUSIC_VOLUME: {
824 uint8_t &vol = (widget == WID_GO_BASE_MUSIC_VOLUME) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
825 if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, 0, INT8_MAX, 0, vol)) {
826 if (widget == WID_GO_BASE_MUSIC_VOLUME) {
827 MusicDriver::GetInstance()->SetVolume(vol);
828 } else {
829 SetEffectVolume(vol);
831 this->SetWidgetDirty(widget);
832 SetWindowClassesDirty(WC_MUSIC_WINDOW);
835 if (click_count > 0) this->mouse_capture_widget = widget;
836 break;
839 case WID_GO_BASE_MUSIC_JUKEBOX: {
840 ShowMusicWindow();
841 break;
844 case WID_GO_BASE_GRF_OPEN_URL:
845 if (BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->url.empty()) return;
846 OpenBrowser(BaseGraphics::GetUsedSet()->url);
847 break;
849 case WID_GO_BASE_SFX_OPEN_URL:
850 if (BaseSounds::GetUsedSet() == nullptr || BaseSounds::GetUsedSet()->url.empty()) return;
851 OpenBrowser(BaseSounds::GetUsedSet()->url);
852 break;
854 case WID_GO_BASE_MUSIC_OPEN_URL:
855 if (BaseMusic::GetUsedSet() == nullptr || BaseMusic::GetUsedSet()->url.empty()) return;
856 OpenBrowser(BaseMusic::GetUsedSet()->url);
857 break;
859 case WID_GO_BASE_GRF_CONTENT_DOWNLOAD:
860 ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_BASE_GRAPHICS);
861 break;
863 case WID_GO_BASE_SFX_CONTENT_DOWNLOAD:
864 ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_BASE_SOUNDS);
865 break;
867 case WID_GO_BASE_MUSIC_CONTENT_DOWNLOAD:
868 ShowNetworkContentListWindow(nullptr, CONTENT_TYPE_BASE_MUSIC);
869 break;
871 case WID_GO_CURRENCY_DROPDOWN:
872 case WID_GO_AUTOSAVE_DROPDOWN:
873 case WID_GO_LANG_DROPDOWN:
874 case WID_GO_RESOLUTION_DROPDOWN:
875 case WID_GO_REFRESH_RATE_DROPDOWN:
876 case WID_GO_BASE_GRF_DROPDOWN:
877 case WID_GO_BASE_SFX_DROPDOWN:
878 case WID_GO_BASE_MUSIC_DROPDOWN: {
879 int selected;
880 DropDownList list = this->BuildDropDownList(widget, &selected);
881 if (!list.empty()) {
882 ShowDropDownList(this, std::move(list), selected, widget);
883 } else {
884 if (widget == WID_GO_RESOLUTION_DROPDOWN) ShowErrorMessage(STR_ERROR_RESOLUTION_LIST_FAILED, INVALID_STRING_ID, WL_ERROR);
886 break;
891 void OnMouseLoop() override
893 if (_left_button_down || this->gui_scale == _gui_scale) return;
895 _gui_scale_cfg = this->gui_scale;
897 if (AdjustGUIZoom(false)) {
898 ReInitAllWindows(true);
899 this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, false);
900 this->SetDirty();
904 void OnDropdownSelect(WidgetID widget, int index) override
906 switch (widget) {
907 case WID_GO_CURRENCY_DROPDOWN: // Currency
908 if (index == CURRENCY_CUSTOM) ShowCustCurrency();
909 this->opt->locale.currency = index;
910 ReInitAllWindows(false);
911 break;
913 case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
914 _settings_client.gui.autosave_interval = _autosave_dropdown_to_minutes[index];
915 ChangeAutosaveFrequency(false);
916 this->SetDirty();
917 break;
919 case WID_GO_LANG_DROPDOWN: // Change interface language
920 ReadLanguagePack(&_languages[index]);
921 CloseWindowByClass(WC_QUERY_STRING);
922 CheckForMissingGlyphs();
923 ClearAllCachedNames();
924 UpdateAllVirtCoords();
925 CheckBlitter();
926 ReInitAllWindows(false);
927 break;
929 case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
930 if ((uint)index < _resolutions.size() && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
931 this->SetDirty();
933 break;
935 case WID_GO_REFRESH_RATE_DROPDOWN: {
936 _settings_client.gui.refresh_rate = *std::next(_refresh_rates.begin(), index);
937 if (_settings_client.gui.refresh_rate > 60) {
938 /* Show warning to the user that this refresh rate might not be suitable on
939 * larger maps with many NewGRFs and vehicles. */
940 ShowErrorMessage(STR_GAME_OPTIONS_REFRESH_RATE_WARNING, INVALID_STRING_ID, WL_INFO);
942 break;
945 case WID_GO_BASE_GRF_DROPDOWN:
946 if (_game_mode == GM_MENU) {
947 CloseWindowByClass(WC_GRF_PARAMETERS);
948 auto set = BaseGraphics::GetSet(index);
949 BaseGraphics::SetSet(set);
950 this->reload = true;
951 this->InvalidateData();
953 break;
955 case WID_GO_BASE_SFX_DROPDOWN:
956 ChangeSoundSet(index);
957 break;
959 case WID_GO_BASE_MUSIC_DROPDOWN:
960 ChangeMusicSet(index);
961 break;
966 * Some data on this window has become invalid.
967 * @param data Information about the changed data. @see GameOptionsInvalidationData
968 * @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.
970 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
972 if (!gui_scope) return;
973 this->SetWidgetLoweredState(WID_GO_SURVEY_PARTICIPATE_BUTTON, _settings_client.network.participate_survey == PS_YES);
974 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
975 this->SetWidgetLoweredState(WID_GO_VIDEO_ACCEL_BUTTON, _video_hw_accel);
976 this->SetWidgetDisabledState(WID_GO_REFRESH_RATE_DROPDOWN, _video_vsync);
978 #ifndef __APPLE__
979 this->SetWidgetLoweredState(WID_GO_VIDEO_VSYNC_BUTTON, _video_hw_accel && _video_vsync);
980 this->SetWidgetDisabledState(WID_GO_VIDEO_VSYNC_BUTTON, !_video_hw_accel);
981 #endif
983 this->SetWidgetLoweredState(WID_GO_GUI_SCALE_AUTO, _gui_scale_cfg == -1);
984 this->SetWidgetLoweredState(WID_GO_GUI_SCALE_BEVEL_BUTTON, _settings_client.gui.scale_bevels);
985 #ifdef HAS_TRUETYPE_FONT
986 this->SetWidgetLoweredState(WID_GO_GUI_FONT_SPRITE, _fcsettings.prefer_sprite);
987 this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
988 this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
989 #endif /* HAS_TRUETYPE_FONT */
991 this->SetWidgetDisabledState(WID_GO_BASE_GRF_DROPDOWN, _game_mode != GM_MENU);
993 this->SetWidgetDisabledState(WID_GO_BASE_GRF_PARAMETERS, BaseGraphics::GetUsedSet() == nullptr || !BaseGraphics::GetUsedSet()->IsConfigurable());
995 this->SetWidgetDisabledState(WID_GO_BASE_GRF_OPEN_URL, BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->url.empty());
996 this->SetWidgetDisabledState(WID_GO_BASE_SFX_OPEN_URL, BaseSounds::GetUsedSet() == nullptr || BaseSounds::GetUsedSet()->url.empty());
997 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_OPEN_URL, BaseMusic::GetUsedSet() == nullptr || BaseMusic::GetUsedSet()->url.empty());
999 for (TextfileType tft = TFT_CONTENT_BEGIN; tft < TFT_CONTENT_END; tft++) {
1000 this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == nullptr || !BaseGraphics::GetUsedSet()->GetTextfile(tft).has_value());
1001 this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == nullptr || !BaseSounds::GetUsedSet()->GetTextfile(tft).has_value());
1002 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == nullptr || !BaseMusic::GetUsedSet()->GetTextfile(tft).has_value());
1005 this->SetWidgetsDisabledState(!_network_available, WID_GO_BASE_GRF_CONTENT_DOWNLOAD, WID_GO_BASE_SFX_CONTENT_DOWNLOAD, WID_GO_BASE_MUSIC_CONTENT_DOWNLOAD);
1009 static constexpr NWidgetPart _nested_game_options_widgets[] = {
1010 NWidget(NWID_HORIZONTAL),
1011 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
1012 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1013 EndContainer(),
1014 NWidget(WWT_PANEL, COLOUR_GREY),
1015 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPadding(WidgetDimensions::unscaled.sparse),
1016 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GO_TAB_GENERAL), SetMinimalTextLines(2, 0), SetDataTip(STR_GAME_OPTIONS_TAB_GENERAL, STR_GAME_OPTIONS_TAB_GENERAL_TT), SetFill(1, 0),
1017 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GO_TAB_GRAPHICS), SetMinimalTextLines(2, 0), SetDataTip(STR_GAME_OPTIONS_TAB_GRAPHICS, STR_GAME_OPTIONS_TAB_GRAPHICS_TT), SetFill(1, 0),
1018 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GO_TAB_SOUND), SetMinimalTextLines(2, 0), SetDataTip(STR_GAME_OPTIONS_TAB_SOUND, STR_GAME_OPTIONS_TAB_SOUND_TT), SetFill(1, 0),
1019 NWidget(WWT_TEXTBTN, COLOUR_YELLOW, WID_GO_TAB_SOCIAL), SetMinimalTextLines(2, 0), SetDataTip(STR_GAME_OPTIONS_TAB_SOCIAL, STR_GAME_OPTIONS_TAB_SOCIAL_TT), SetFill(1, 0),
1020 EndContainer(),
1021 EndContainer(),
1022 NWidget(WWT_PANEL, COLOUR_GREY),
1023 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GO_TAB_SELECTION),
1024 /* General tab */
1025 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.sparse), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0),
1026 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
1027 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_LANG_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_RAW_STRING, STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0),
1028 EndContainer(),
1030 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
1031 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_AUTOSAVE_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_STRING, STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP), SetFill(1, 0),
1032 EndContainer(),
1034 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
1035 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_CURRENCY_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_STRING2, STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
1036 EndContainer(),
1038 NWidget(NWID_SELECTION, INVALID_COLOUR, WID_GO_SURVEY_SEL),
1039 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_PARTICIPATE_SURVEY_FRAME, STR_NULL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
1040 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1041 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_PARTICIPATE_SURVEY, STR_NULL),
1042 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_SURVEY_PARTICIPATE_BUTTON), SetAspect(WidgetDimensions::ASPECT_SETTINGS_BUTTON), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_PARTICIPATE_SURVEY_TOOLTIP),
1043 EndContainer(),
1044 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1045 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_SURVEY_PREVIEW_BUTTON), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_GAME_OPTIONS_PARTICIPATE_SURVEY_PREVIEW, STR_GAME_OPTIONS_PARTICIPATE_SURVEY_PREVIEW_TOOLTIP),
1046 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_SURVEY_LINK_BUTTON), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_GAME_OPTIONS_PARTICIPATE_SURVEY_LINK, STR_GAME_OPTIONS_PARTICIPATE_SURVEY_LINK_TOOLTIP),
1047 EndContainer(),
1048 EndContainer(),
1049 EndContainer(),
1050 EndContainer(),
1052 /* Graphics tab */
1053 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.sparse), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0),
1054 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GUI_SCALE_FRAME, STR_NULL),
1055 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1056 NWidget(WWT_EMPTY, COLOUR_GREY, WID_GO_GUI_SCALE), SetMinimalSize(67, 0), SetMinimalTextLines(1, 12 + WidgetDimensions::unscaled.vsep_normal, FS_SMALL), SetFill(0, 0), SetDataTip(0x0, STR_GAME_OPTIONS_GUI_SCALE_TOOLTIP),
1057 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1058 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_GUI_SCALE_AUTO, STR_NULL),
1059 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_GUI_SCALE_AUTO), SetAspect(WidgetDimensions::ASPECT_SETTINGS_BUTTON), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_GUI_SCALE_AUTO_TOOLTIP),
1060 EndContainer(),
1061 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1062 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_GUI_SCALE_BEVELS, STR_NULL),
1063 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_GUI_SCALE_BEVEL_BUTTON), SetAspect(WidgetDimensions::ASPECT_SETTINGS_BUTTON), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_GUI_SCALE_BEVELS_TOOLTIP),
1064 EndContainer(),
1065 #ifdef HAS_TRUETYPE_FONT
1066 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1067 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_GUI_FONT_SPRITE, STR_NULL),
1068 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_GUI_FONT_SPRITE), SetAspect(WidgetDimensions::ASPECT_SETTINGS_BUTTON), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_GUI_FONT_SPRITE_TOOLTIP),
1069 EndContainer(),
1070 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1071 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_GUI_FONT_AA, STR_NULL),
1072 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_GUI_FONT_AA), SetAspect(WidgetDimensions::ASPECT_SETTINGS_BUTTON), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_GUI_FONT_AA_TOOLTIP),
1073 EndContainer(),
1074 #endif /* HAS_TRUETYPE_FONT */
1075 EndContainer(),
1076 EndContainer(),
1078 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GRAPHICS, STR_NULL),
1079 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
1080 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1081 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL),
1082 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_RESOLUTION_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_STRING2, STR_GAME_OPTIONS_RESOLUTION_TOOLTIP),
1083 EndContainer(),
1084 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1085 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_REFRESH_RATE, STR_NULL),
1086 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_REFRESH_RATE_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, STR_GAME_OPTIONS_REFRESH_RATE_TOOLTIP),
1087 EndContainer(),
1088 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1089 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL),
1090 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetAspect(WidgetDimensions::ASPECT_SETTINGS_BUTTON), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
1091 EndContainer(),
1092 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1093 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_VIDEO_ACCELERATION, STR_NULL),
1094 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_VIDEO_ACCEL_BUTTON), SetAspect(WidgetDimensions::ASPECT_SETTINGS_BUTTON), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_VIDEO_ACCELERATION_TOOLTIP),
1095 EndContainer(),
1096 #ifndef __APPLE__
1097 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
1098 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_VIDEO_VSYNC, STR_NULL),
1099 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_VIDEO_VSYNC_BUTTON), SetAspect(WidgetDimensions::ASPECT_SETTINGS_BUTTON), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_VIDEO_VSYNC_TOOLTIP),
1100 EndContainer(),
1101 #endif
1102 NWidget(NWID_HORIZONTAL),
1103 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GO_VIDEO_DRIVER_INFO), SetMinimalTextLines(1, 0), SetFill(1, 0),
1104 EndContainer(),
1105 EndContainer(),
1106 EndContainer(),
1108 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0), SetFill(1, 0),
1109 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1110 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP), SetFill(1, 0),
1111 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_PARAMETERS), SetDataTip(STR_NEWGRF_SETTINGS_SET_PARAMETERS, STR_NULL),
1112 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_CONTENT_DOWNLOAD), SetDataTip(STR_GAME_OPTIONS_ONLINE_CONTENT, STR_GAME_OPTIONS_ONLINE_CONTENT_TOOLTIP),
1113 EndContainer(),
1114 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(200, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0),
1115 NWidget(NWID_VERTICAL),
1116 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1117 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1118 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1119 EndContainer(),
1120 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1121 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1122 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1123 EndContainer(),
1124 EndContainer(),
1125 EndContainer(),
1126 EndContainer(),
1128 /* Sound/Music tab */
1129 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.sparse), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0),
1130 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_VOLUME, STR_NULL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0),
1131 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1132 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_TEXT_SFX_VOLUME), SetMinimalSize(0, 12), SetDataTip(STR_GAME_OPTIONS_SFX_VOLUME, STR_NULL),
1133 NWidget(WWT_EMPTY, COLOUR_GREY, WID_GO_BASE_SFX_VOLUME), SetMinimalSize(67, 0), SetMinimalTextLines(1, 12 + WidgetDimensions::unscaled.vsep_normal, FS_SMALL), SetFill(1, 0), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
1134 EndContainer(),
1135 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1136 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_TEXT_MUSIC_VOLUME), SetMinimalSize(0, 12), SetDataTip(STR_GAME_OPTIONS_MUSIC_VOLUME, STR_NULL),
1137 NWidget(WWT_EMPTY, COLOUR_GREY, WID_GO_BASE_MUSIC_VOLUME), SetMinimalSize(67, 0), SetMinimalTextLines(1, 12 + WidgetDimensions::unscaled.vsep_normal, FS_SMALL), SetFill(1, 0), SetDataTip(0x0, STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
1138 EndContainer(),
1139 EndContainer(),
1141 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
1142 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1143 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP), SetFill(1, 0),
1144 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_CONTENT_DOWNLOAD), SetDataTip(STR_GAME_OPTIONS_ONLINE_CONTENT, STR_GAME_OPTIONS_ONLINE_CONTENT_TOOLTIP),
1145 EndContainer(),
1146 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalSize(200, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_NULL, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0),
1147 NWidget(NWID_VERTICAL),
1148 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1149 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1150 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1151 EndContainer(),
1152 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1153 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1154 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1155 EndContainer(),
1156 EndContainer(),
1157 EndContainer(),
1159 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
1160 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1161 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP), SetFill(1, 0),
1162 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_CONTENT_DOWNLOAD), SetDataTip(STR_GAME_OPTIONS_ONLINE_CONTENT, STR_GAME_OPTIONS_ONLINE_CONTENT_TOOLTIP),
1163 EndContainer(),
1164 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
1165 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalSize(200, 0), SetMinimalTextLines(1, 0), SetDataTip(STR_NULL, STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0),
1166 NWidget(NWID_VERTICAL), SetPIPRatio(0, 0, 1),
1167 NWidget(WWT_PUSHIMGBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_JUKEBOX), SetMinimalSize(22, 22), SetDataTip(SPR_IMG_MUSIC, STR_TOOLBAR_TOOLTIP_SHOW_SOUND_MUSIC_WINDOW),
1168 EndContainer(),
1169 EndContainer(),
1170 NWidget(NWID_VERTICAL),
1171 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1172 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetDataTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1173 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1174 EndContainer(),
1175 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
1176 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1177 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1178 EndContainer(),
1179 EndContainer(),
1180 EndContainer(),
1181 EndContainer(),
1183 /* Social tab */
1184 NWidget(NWID_VERTICAL), SetPadding(WidgetDimensions::unscaled.sparse), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0),
1185 NWidgetFunction(MakeNWidgetSocialPlugins),
1186 EndContainer(),
1187 EndContainer(),
1188 EndContainer(),
1191 static WindowDesc _game_options_desc(
1192 WDP_CENTER, nullptr, 0, 0,
1193 WC_GAME_OPTIONS, WC_NONE,
1195 _nested_game_options_widgets
1198 /** Open the game options window. */
1199 void ShowGameOptions()
1201 CloseWindowByClass(WC_GAME_OPTIONS);
1202 new GameOptionsWindow(_game_options_desc);
1205 static int SETTING_HEIGHT = 11; ///< Height of a single setting in the tree view in pixels
1208 * Flags for #SettingEntry
1209 * @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
1211 enum SettingEntryFlags {
1212 SEF_LEFT_DEPRESSED = 0x01, ///< Of a numeric setting entry, the left button is depressed
1213 SEF_RIGHT_DEPRESSED = 0x02, ///< Of a numeric setting entry, the right button is depressed
1214 SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED), ///< Bit-mask for button flags
1216 SEF_LAST_FIELD = 0x04, ///< This entry is the last one in a (sub-)page
1217 SEF_FILTERED = 0x08, ///< Entry is hidden by the string filter
1220 /** How the list of advanced settings is filtered. */
1221 enum RestrictionMode {
1222 RM_BASIC, ///< Display settings associated to the "basic" list.
1223 RM_ADVANCED, ///< Display settings associated to the "advanced" list.
1224 RM_ALL, ///< List all settings regardless of the default/newgame/... values.
1225 RM_CHANGED_AGAINST_DEFAULT, ///< Show only settings which are different compared to default values.
1226 RM_CHANGED_AGAINST_NEW, ///< Show only settings which are different compared to the user's new game setting values.
1227 RM_END, ///< End for iteration.
1229 DECLARE_POSTFIX_INCREMENT(RestrictionMode)
1231 /** Filter for settings list. */
1232 struct SettingFilter {
1233 StringFilter string; ///< Filter string.
1234 RestrictionMode min_cat; ///< Minimum category needed to display all filtered strings (#RM_BASIC, #RM_ADVANCED, or #RM_ALL).
1235 bool type_hides; ///< Whether the type hides filtered strings.
1236 RestrictionMode mode; ///< Filter based on category.
1237 SettingType type; ///< Filter based on type.
1240 /** Data structure describing a single setting in a tab */
1241 struct BaseSettingEntry {
1242 uint8_t flags; ///< Flags of the setting entry. @see SettingEntryFlags
1243 uint8_t level; ///< Nesting level of this setting entry
1245 BaseSettingEntry() : flags(0), level(0) {}
1246 virtual ~BaseSettingEntry() = default;
1248 virtual void Init(uint8_t level = 0);
1249 virtual void FoldAll() {}
1250 virtual void UnFoldAll() {}
1251 virtual void ResetAll() = 0;
1254 * Set whether this is the last visible entry of the parent node.
1255 * @param last_field Value to set
1257 void SetLastField(bool last_field) { if (last_field) SETBITS(this->flags, SEF_LAST_FIELD); else CLRBITS(this->flags, SEF_LAST_FIELD); }
1259 virtual uint Length() const = 0;
1260 virtual void GetFoldingState([[maybe_unused]] bool &all_folded, [[maybe_unused]] bool &all_unfolded) const {}
1261 virtual bool IsVisible(const BaseSettingEntry *item) const;
1262 virtual BaseSettingEntry *FindEntry(uint row, uint *cur_row);
1263 virtual uint GetMaxHelpHeight([[maybe_unused]] int maxw) { return 0; }
1266 * Check whether an entry is hidden due to filters
1267 * @return true if hidden.
1269 bool IsFiltered() const { return (this->flags & SEF_FILTERED) != 0; }
1271 virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible) = 0;
1273 virtual uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
1275 protected:
1276 virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const = 0;
1279 /** Standard setting */
1280 struct SettingEntry : BaseSettingEntry {
1281 const char *name; ///< Name of the setting
1282 const IntSettingDesc *setting; ///< Setting description of the setting
1284 SettingEntry(const char *name);
1286 void Init(uint8_t level = 0) override;
1287 void ResetAll() override;
1288 uint Length() const override;
1289 uint GetMaxHelpHeight(int maxw) override;
1290 bool UpdateFilterState(SettingFilter &filter, bool force_visible) override;
1292 void SetButtons(uint8_t new_val);
1294 protected:
1295 void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const override;
1297 private:
1298 bool IsVisibleByRestrictionMode(RestrictionMode mode) const;
1301 /** Containers for BaseSettingEntry */
1302 struct SettingsContainer {
1303 typedef std::vector<BaseSettingEntry*> EntryVector;
1304 EntryVector entries; ///< Settings on this page
1306 template<typename T>
1307 T *Add(T *item)
1309 this->entries.push_back(item);
1310 return item;
1313 void Init(uint8_t level = 0);
1314 void ResetAll();
1315 void FoldAll();
1316 void UnFoldAll();
1318 uint Length() const;
1319 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
1320 bool IsVisible(const BaseSettingEntry *item) const;
1321 BaseSettingEntry *FindEntry(uint row, uint *cur_row);
1322 uint GetMaxHelpHeight(int maxw);
1324 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
1326 uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
1329 /** Data structure describing one page of settings in the settings window. */
1330 struct SettingsPage : BaseSettingEntry, SettingsContainer {
1331 StringID title; ///< Title of the sub-page
1332 bool folded; ///< Sub-page is folded (not visible except for its title)
1334 SettingsPage(StringID title);
1336 void Init(uint8_t level = 0) override;
1337 void ResetAll() override;
1338 void FoldAll() override;
1339 void UnFoldAll() override;
1341 uint Length() const override;
1342 void GetFoldingState(bool &all_folded, bool &all_unfolded) const override;
1343 bool IsVisible(const BaseSettingEntry *item) const override;
1344 BaseSettingEntry *FindEntry(uint row, uint *cur_row) override;
1345 uint GetMaxHelpHeight(int maxw) override { return SettingsContainer::GetMaxHelpHeight(maxw); }
1347 bool UpdateFilterState(SettingFilter &filter, bool force_visible) override;
1349 uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const override;
1351 protected:
1352 void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const override;
1355 /* == BaseSettingEntry methods == */
1358 * Initialization of a setting entry
1359 * @param level Page nesting level of this entry
1361 void BaseSettingEntry::Init(uint8_t level)
1363 this->level = level;
1367 * Check whether an entry is visible and not folded or filtered away.
1368 * Note: This does not consider the scrolling range; it might still require scrolling to make the setting really visible.
1369 * @param item Entry to search for.
1370 * @return true if entry is visible.
1372 bool BaseSettingEntry::IsVisible(const BaseSettingEntry *item) const
1374 if (this->IsFiltered()) return false;
1375 return this == item;
1379 * Find setting entry at row \a row_num
1380 * @param row_num Index of entry to return
1381 * @param cur_row Current row number
1382 * @return The requested setting entry or \c nullptr if it not found (folded or filtered)
1384 BaseSettingEntry *BaseSettingEntry::FindEntry(uint row_num, uint *cur_row)
1386 if (this->IsFiltered()) return nullptr;
1387 if (row_num == *cur_row) return this;
1388 (*cur_row)++;
1389 return nullptr;
1393 * Draw a row in the settings panel.
1395 * The scrollbar uses rows of the page, while the page data structure is a tree of #SettingsPage and #SettingEntry objects.
1396 * 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.
1397 * Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
1399 * The \a parent_last parameter ensures that the vertical lines at the left are
1400 * only drawn when another entry follows, that it prevents output like
1401 * \verbatim
1402 * |-- setting
1403 * |-- (-) - Title
1404 * | |-- setting
1405 * | |-- setting
1406 * \endverbatim
1407 * The left-most vertical line is not wanted. It is prevented by setting the
1408 * appropriate bit in the \a parent_last parameter.
1410 * @param settings_ptr Pointer to current values of all settings
1411 * @param left Left-most position in window/panel to start drawing \a first_row
1412 * @param right Right-most x position to draw strings at.
1413 * @param y Upper-most position in window/panel to start drawing \a first_row
1414 * @param first_row First row number to draw
1415 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1416 * @param selected Selected entry by the user.
1417 * @param cur_row Current row number (internal variable)
1418 * @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)
1419 * @return Row number of the next row to draw
1421 uint BaseSettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last) const
1423 if (this->IsFiltered()) return cur_row;
1424 if (cur_row >= max_row) return cur_row;
1426 bool rtl = _current_text_dir == TD_RTL;
1427 int offset = (rtl ? -(int)_circle_size.width : (int)_circle_size.width) / 2;
1428 int level_width = rtl ? -WidgetDimensions::scaled.hsep_indent : WidgetDimensions::scaled.hsep_indent;
1430 int x = rtl ? right : left;
1431 if (cur_row >= first_row) {
1432 int colour = GetColourGradient(COLOUR_ORANGE, SHADE_NORMAL);
1433 y += (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
1435 /* Draw vertical for parent nesting levels */
1436 for (uint lvl = 0; lvl < this->level; lvl++) {
1437 if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
1438 x += level_width;
1440 /* draw own |- prefix */
1441 int halfway_y = y + SETTING_HEIGHT / 2;
1442 int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
1443 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
1444 /* Small horizontal line from the last vertical line */
1445 GfxDrawLine(x + offset, halfway_y, x + level_width - (rtl ? -WidgetDimensions::scaled.hsep_normal : WidgetDimensions::scaled.hsep_normal), halfway_y, colour);
1446 x += level_width;
1448 this->DrawSetting(settings_ptr, rtl ? left : x, rtl ? x : right, y, this == selected);
1450 cur_row++;
1452 return cur_row;
1455 /* == SettingEntry methods == */
1458 * Constructor for a single setting in the 'advanced settings' window
1459 * @param name Name of the setting in the setting table
1461 SettingEntry::SettingEntry(const char *name)
1463 this->name = name;
1464 this->setting = nullptr;
1468 * Initialization of a setting entry
1469 * @param level Page nesting level of this entry
1471 void SettingEntry::Init(uint8_t level)
1473 BaseSettingEntry::Init(level);
1474 this->setting = GetSettingFromName(this->name)->AsIntSetting();
1477 /* Sets the given setting entry to its default value */
1478 void SettingEntry::ResetAll()
1480 SetSettingValue(this->setting, this->setting->def);
1484 * Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
1485 * @param new_val New value for the button flags
1486 * @see SettingEntryFlags
1488 void SettingEntry::SetButtons(uint8_t new_val)
1490 assert((new_val & ~SEF_BUTTONS_MASK) == 0); // Should not touch any flags outside the buttons
1491 this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
1494 /** Return number of rows needed to display the (filtered) entry */
1495 uint SettingEntry::Length() const
1497 return this->IsFiltered() ? 0 : 1;
1501 * Get the biggest height of the help text(s), if the width is at least \a maxw. Help text gets wrapped if needed.
1502 * @param maxw Maximal width of a line help text.
1503 * @return Biggest height needed to display any help text of this node (and its descendants).
1505 uint SettingEntry::GetMaxHelpHeight(int maxw)
1507 return GetStringHeight(this->setting->GetHelp(), maxw);
1511 * Checks whether an entry shall be made visible based on the restriction mode.
1512 * @param mode The current status of the restriction drop down box.
1513 * @return true if the entry shall be visible.
1515 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
1517 /* There shall not be any restriction, i.e. all settings shall be visible. */
1518 if (mode == RM_ALL) return true;
1520 const IntSettingDesc *sd = this->setting;
1522 if (mode == RM_BASIC) return (this->setting->cat & SC_BASIC_LIST) != 0;
1523 if (mode == RM_ADVANCED) return (this->setting->cat & SC_ADVANCED_LIST) != 0;
1525 /* Read the current value. */
1526 const void *object = ResolveObject(&GetGameSettings(), sd);
1527 int64_t current_value = sd->Read(object);
1528 int64_t filter_value;
1530 if (mode == RM_CHANGED_AGAINST_DEFAULT) {
1531 /* This entry shall only be visible, if the value deviates from its default value. */
1533 /* Read the default value. */
1534 filter_value = sd->def;
1535 } else {
1536 assert(mode == RM_CHANGED_AGAINST_NEW);
1537 /* This entry shall only be visible, if the value deviates from
1538 * its value is used when starting a new game. */
1540 /* Make sure we're not comparing the new game settings against itself. */
1541 assert(&GetGameSettings() != &_settings_newgame);
1543 /* Read the new game's value. */
1544 filter_value = sd->Read(ResolveObject(&_settings_newgame, sd));
1547 return current_value != filter_value;
1551 * Update the filter state.
1552 * @param filter Filter
1553 * @param force_visible Whether to force all items visible, no matter what (due to filter text; not affected by restriction drop down box).
1554 * @return true if item remains visible
1556 bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
1558 CLRBITS(this->flags, SEF_FILTERED);
1560 bool visible = true;
1562 const IntSettingDesc *sd = this->setting;
1563 if (!force_visible && !filter.string.IsEmpty()) {
1564 /* Process the search text filter for this item. */
1565 filter.string.ResetState();
1567 SetDParam(0, STR_EMPTY);
1568 filter.string.AddLine(sd->GetTitle());
1569 filter.string.AddLine(sd->GetHelp());
1571 visible = filter.string.GetState();
1574 if (visible) {
1575 if (filter.type != ST_ALL && sd->GetType() != filter.type) {
1576 filter.type_hides = true;
1577 visible = false;
1579 if (!this->IsVisibleByRestrictionMode(filter.mode)) {
1580 while (filter.min_cat < RM_ALL && (filter.min_cat == filter.mode || !this->IsVisibleByRestrictionMode(filter.min_cat))) filter.min_cat++;
1581 visible = false;
1585 if (!visible) SETBITS(this->flags, SEF_FILTERED);
1586 return visible;
1589 static const void *ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd)
1591 if ((sd->flags & SF_PER_COMPANY) != 0) {
1592 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
1593 return &Company::Get(_local_company)->settings;
1595 return &_settings_client.company;
1597 return settings_ptr;
1601 * Function to draw setting value (button + text + current value)
1602 * @param settings_ptr Pointer to current values of all settings
1603 * @param left Left-most position in window/panel to start drawing
1604 * @param right Right-most position in window/panel to draw
1605 * @param y Upper-most position in window/panel to start drawing
1606 * @param highlight Highlight entry.
1608 void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const
1610 const IntSettingDesc *sd = this->setting;
1611 int state = this->flags & SEF_BUTTONS_MASK;
1613 bool rtl = _current_text_dir == TD_RTL;
1614 uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
1615 uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide);
1616 uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + WidgetDimensions::scaled.hsep_wide : 0);
1617 uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
1619 /* We do not allow changes of some items when we are a client in a networkgame */
1620 bool editable = sd->IsEditable();
1622 SetDParam(0, STR_CONFIG_SETTING_VALUE);
1623 int32_t value = sd->Read(ResolveObject(settings_ptr, sd));
1624 if (sd->IsBoolSetting()) {
1625 /* Draw checkbox for boolean-value either on/off */
1626 DrawBoolButton(buttons_left, button_y, value != 0, editable);
1627 } else if ((sd->flags & SF_GUI_DROPDOWN) != 0) {
1628 /* Draw [v] button for settings of an enum-type */
1629 DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
1630 } else {
1631 /* Draw [<][>] boxes for settings of an integer-type */
1632 DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
1633 editable && value != (sd->flags & SF_GUI_0_IS_SPECIAL ? 0 : sd->min), editable && (uint32_t)value != sd->max);
1635 sd->SetValueDParams(1, value);
1636 DrawString(text_left, text_right, y + (SETTING_HEIGHT - GetCharacterHeight(FS_NORMAL)) / 2, sd->GetTitle(), highlight ? TC_WHITE : TC_LIGHT_BLUE);
1639 /* == SettingsContainer methods == */
1642 * Initialization of an entire setting page
1643 * @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
1645 void SettingsContainer::Init(uint8_t level)
1647 for (auto &it : this->entries) {
1648 it->Init(level);
1652 /** Resets all settings to their default values */
1653 void SettingsContainer::ResetAll()
1655 for (auto settings_entry : this->entries) {
1656 settings_entry->ResetAll();
1660 /** Recursively close all folds of sub-pages */
1661 void SettingsContainer::FoldAll()
1663 for (auto &it : this->entries) {
1664 it->FoldAll();
1668 /** Recursively open all folds of sub-pages */
1669 void SettingsContainer::UnFoldAll()
1671 for (auto &it : this->entries) {
1672 it->UnFoldAll();
1677 * Recursively accumulate the folding state of the tree.
1678 * @param[in,out] all_folded Set to false, if one entry is not folded.
1679 * @param[in,out] all_unfolded Set to false, if one entry is folded.
1681 void SettingsContainer::GetFoldingState(bool &all_folded, bool &all_unfolded) const
1683 for (auto &it : this->entries) {
1684 it->GetFoldingState(all_folded, all_unfolded);
1689 * Update the filter state.
1690 * @param filter Filter
1691 * @param force_visible Whether to force all items visible, no matter what
1692 * @return true if item remains visible
1694 bool SettingsContainer::UpdateFilterState(SettingFilter &filter, bool force_visible)
1696 bool visible = false;
1697 bool first_visible = true;
1698 for (EntryVector::reverse_iterator it = this->entries.rbegin(); it != this->entries.rend(); ++it) {
1699 visible |= (*it)->UpdateFilterState(filter, force_visible);
1700 (*it)->SetLastField(first_visible);
1701 if (visible && first_visible) first_visible = false;
1703 return visible;
1708 * Check whether an entry is visible and not folded or filtered away.
1709 * Note: This does not consider the scrolling range; it might still require scrolling to make the setting really visible.
1710 * @param item Entry to search for.
1711 * @return true if entry is visible.
1713 bool SettingsContainer::IsVisible(const BaseSettingEntry *item) const
1715 for (const auto &it : this->entries) {
1716 if (it->IsVisible(item)) return true;
1718 return false;
1721 /** Return number of rows needed to display the whole page */
1722 uint SettingsContainer::Length() const
1724 uint length = 0;
1725 for (const auto &it : this->entries) {
1726 length += it->Length();
1728 return length;
1732 * Find the setting entry at row number \a row_num
1733 * @param row_num Index of entry to return
1734 * @param cur_row Variable used for keeping track of the current row number. Should point to memory initialized to \c 0 when first called.
1735 * @return The requested setting entry or \c nullptr if it does not exist
1737 BaseSettingEntry *SettingsContainer::FindEntry(uint row_num, uint *cur_row)
1739 BaseSettingEntry *pe = nullptr;
1740 for (const auto &it : this->entries) {
1741 pe = it->FindEntry(row_num, cur_row);
1742 if (pe != nullptr) {
1743 break;
1746 return pe;
1750 * Get the biggest height of the help texts, if the width is at least \a maxw. Help text gets wrapped if needed.
1751 * @param maxw Maximal width of a line help text.
1752 * @return Biggest height needed to display any help text of this (sub-)tree.
1754 uint SettingsContainer::GetMaxHelpHeight(int maxw)
1756 uint biggest = 0;
1757 for (const auto &it : this->entries) {
1758 biggest = std::max(biggest, it->GetMaxHelpHeight(maxw));
1760 return biggest;
1765 * Draw a row in the settings panel.
1767 * @param settings_ptr Pointer to current values of all settings
1768 * @param left Left-most position in window/panel to start drawing \a first_row
1769 * @param right Right-most x position to draw strings at.
1770 * @param y Upper-most position in window/panel to start drawing \a first_row
1771 * @param first_row First row number to draw
1772 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1773 * @param selected Selected entry by the user.
1774 * @param cur_row Current row number (internal variable)
1775 * @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)
1776 * @return Row number of the next row to draw
1778 uint SettingsContainer::Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last) const
1780 for (const auto &it : this->entries) {
1781 cur_row = it->Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
1782 if (cur_row >= max_row) break;
1784 return cur_row;
1787 /* == SettingsPage methods == */
1790 * Constructor for a sub-page in the 'advanced settings' window
1791 * @param title Title of the sub-page
1793 SettingsPage::SettingsPage(StringID title)
1795 this->title = title;
1796 this->folded = true;
1800 * Initialization of an entire setting page
1801 * @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
1803 void SettingsPage::Init(uint8_t level)
1805 BaseSettingEntry::Init(level);
1806 SettingsContainer::Init(level + 1);
1809 /** Resets all settings to their default values */
1810 void SettingsPage::ResetAll()
1812 for (auto settings_entry : this->entries) {
1813 settings_entry->ResetAll();
1817 /** Recursively close all (filtered) folds of sub-pages */
1818 void SettingsPage::FoldAll()
1820 if (this->IsFiltered()) return;
1821 this->folded = true;
1823 SettingsContainer::FoldAll();
1826 /** Recursively open all (filtered) folds of sub-pages */
1827 void SettingsPage::UnFoldAll()
1829 if (this->IsFiltered()) return;
1830 this->folded = false;
1832 SettingsContainer::UnFoldAll();
1836 * Recursively accumulate the folding state of the (filtered) tree.
1837 * @param[in,out] all_folded Set to false, if one entry is not folded.
1838 * @param[in,out] all_unfolded Set to false, if one entry is folded.
1840 void SettingsPage::GetFoldingState(bool &all_folded, bool &all_unfolded) const
1842 if (this->IsFiltered()) return;
1844 if (this->folded) {
1845 all_unfolded = false;
1846 } else {
1847 all_folded = false;
1850 SettingsContainer::GetFoldingState(all_folded, all_unfolded);
1854 * Update the filter state.
1855 * @param filter Filter
1856 * @param force_visible Whether to force all items visible, no matter what (due to filter text; not affected by restriction drop down box).
1857 * @return true if item remains visible
1859 bool SettingsPage::UpdateFilterState(SettingFilter &filter, bool force_visible)
1861 if (!force_visible && !filter.string.IsEmpty()) {
1862 filter.string.ResetState();
1863 filter.string.AddLine(this->title);
1864 force_visible = filter.string.GetState();
1867 bool visible = SettingsContainer::UpdateFilterState(filter, force_visible);
1868 if (visible) {
1869 CLRBITS(this->flags, SEF_FILTERED);
1870 } else {
1871 SETBITS(this->flags, SEF_FILTERED);
1873 return visible;
1877 * Check whether an entry is visible and not folded or filtered away.
1878 * Note: This does not consider the scrolling range; it might still require scrolling to make the setting really visible.
1879 * @param item Entry to search for.
1880 * @return true if entry is visible.
1882 bool SettingsPage::IsVisible(const BaseSettingEntry *item) const
1884 if (this->IsFiltered()) return false;
1885 if (this == item) return true;
1886 if (this->folded) return false;
1888 return SettingsContainer::IsVisible(item);
1891 /** Return number of rows needed to display the (filtered) entry */
1892 uint SettingsPage::Length() const
1894 if (this->IsFiltered()) return 0;
1895 if (this->folded) return 1; // Only displaying the title
1897 return 1 + SettingsContainer::Length();
1901 * Find setting entry at row \a row_num
1902 * @param row_num Index of entry to return
1903 * @param cur_row Current row number
1904 * @return The requested setting entry or \c nullptr if it not found (folded or filtered)
1906 BaseSettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row)
1908 if (this->IsFiltered()) return nullptr;
1909 if (row_num == *cur_row) return this;
1910 (*cur_row)++;
1911 if (this->folded) return nullptr;
1913 return SettingsContainer::FindEntry(row_num, cur_row);
1917 * Draw a row in the settings panel.
1919 * @param settings_ptr Pointer to current values of all settings
1920 * @param left Left-most position in window/panel to start drawing \a first_row
1921 * @param right Right-most x position to draw strings at.
1922 * @param y Upper-most position in window/panel to start drawing \a first_row
1923 * @param first_row First row number to draw
1924 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1925 * @param selected Selected entry by the user.
1926 * @param cur_row Current row number (internal variable)
1927 * @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)
1928 * @return Row number of the next row to draw
1930 uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last) const
1932 if (this->IsFiltered()) return cur_row;
1933 if (cur_row >= max_row) return cur_row;
1935 cur_row = BaseSettingEntry::Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
1937 if (!this->folded) {
1938 if (this->flags & SEF_LAST_FIELD) {
1939 assert(this->level < 8 * sizeof(parent_last));
1940 SetBit(parent_last, this->level); // Add own last-field state
1943 cur_row = SettingsContainer::Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
1946 return cur_row;
1950 * Function to draw setting value (button + text + current value)
1951 * @param left Left-most position in window/panel to start drawing
1952 * @param right Right-most position in window/panel to draw
1953 * @param y Upper-most position in window/panel to start drawing
1955 void SettingsPage::DrawSetting(GameSettings *, int left, int right, int y, bool) const
1957 bool rtl = _current_text_dir == TD_RTL;
1958 DrawSprite((this->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? right - _circle_size.width : left, y + (SETTING_HEIGHT - _circle_size.height) / 2);
1959 DrawString(rtl ? left : left + _circle_size.width + WidgetDimensions::scaled.hsep_normal, rtl ? right - _circle_size.width - WidgetDimensions::scaled.hsep_normal : right, y + (SETTING_HEIGHT - GetCharacterHeight(FS_NORMAL)) / 2, this->title, TC_ORANGE);
1962 /** Construct settings tree */
1963 static SettingsContainer &GetSettingsTree()
1965 static SettingsContainer *main = nullptr;
1967 if (main == nullptr)
1969 /* Build up the dynamic settings-array only once per OpenTTD session */
1970 main = new SettingsContainer();
1972 SettingsPage *localisation = main->Add(new SettingsPage(STR_CONFIG_SETTING_LOCALISATION));
1974 localisation->Add(new SettingEntry("locale.units_velocity"));
1975 localisation->Add(new SettingEntry("locale.units_velocity_nautical"));
1976 localisation->Add(new SettingEntry("locale.units_power"));
1977 localisation->Add(new SettingEntry("locale.units_weight"));
1978 localisation->Add(new SettingEntry("locale.units_volume"));
1979 localisation->Add(new SettingEntry("locale.units_force"));
1980 localisation->Add(new SettingEntry("locale.units_height"));
1981 localisation->Add(new SettingEntry("gui.date_format_in_default_names"));
1984 SettingsPage *graphics = main->Add(new SettingsPage(STR_CONFIG_SETTING_GRAPHICS));
1986 graphics->Add(new SettingEntry("gui.zoom_min"));
1987 graphics->Add(new SettingEntry("gui.zoom_max"));
1988 graphics->Add(new SettingEntry("gui.sprite_zoom_min"));
1989 graphics->Add(new SettingEntry("gui.smallmap_land_colour"));
1990 graphics->Add(new SettingEntry("gui.linkgraph_colours"));
1991 graphics->Add(new SettingEntry("gui.graph_line_thickness"));
1994 SettingsPage *sound = main->Add(new SettingsPage(STR_CONFIG_SETTING_SOUND));
1996 sound->Add(new SettingEntry("sound.click_beep"));
1997 sound->Add(new SettingEntry("sound.confirm"));
1998 sound->Add(new SettingEntry("sound.news_ticker"));
1999 sound->Add(new SettingEntry("sound.news_full"));
2000 sound->Add(new SettingEntry("sound.new_year"));
2001 sound->Add(new SettingEntry("sound.disaster"));
2002 sound->Add(new SettingEntry("sound.vehicle"));
2003 sound->Add(new SettingEntry("sound.ambient"));
2006 SettingsPage *interface = main->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE));
2008 SettingsPage *general = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_GENERAL));
2010 general->Add(new SettingEntry("gui.osk_activation"));
2011 general->Add(new SettingEntry("gui.hover_delay_ms"));
2012 general->Add(new SettingEntry("gui.errmsg_duration"));
2013 general->Add(new SettingEntry("gui.window_snap_radius"));
2014 general->Add(new SettingEntry("gui.window_soft_limit"));
2015 general->Add(new SettingEntry("gui.right_click_wnd_close"));
2018 SettingsPage *viewports = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_VIEWPORTS));
2020 viewports->Add(new SettingEntry("gui.auto_scrolling"));
2021 viewports->Add(new SettingEntry("gui.scroll_mode"));
2022 viewports->Add(new SettingEntry("gui.smooth_scroll"));
2023 /* While the horizontal scrollwheel scrolling is written as general code, only
2024 * the cocoa (OSX) driver generates input for it.
2025 * Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
2026 viewports->Add(new SettingEntry("gui.scrollwheel_scrolling"));
2027 viewports->Add(new SettingEntry("gui.scrollwheel_multiplier"));
2028 #ifdef __APPLE__
2029 /* We might need to emulate a right mouse button on mac */
2030 viewports->Add(new SettingEntry("gui.right_mouse_btn_emulation"));
2031 #endif
2032 viewports->Add(new SettingEntry("gui.population_in_label"));
2033 viewports->Add(new SettingEntry("gui.liveries"));
2034 viewports->Add(new SettingEntry("construction.train_signal_side"));
2035 viewports->Add(new SettingEntry("gui.measure_tooltip"));
2036 viewports->Add(new SettingEntry("gui.loading_indicators"));
2037 viewports->Add(new SettingEntry("gui.show_track_reservation"));
2040 SettingsPage *construction = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_CONSTRUCTION));
2042 construction->Add(new SettingEntry("gui.link_terraform_toolbar"));
2043 construction->Add(new SettingEntry("gui.persistent_buildingtools"));
2044 construction->Add(new SettingEntry("gui.default_rail_type"));
2045 construction->Add(new SettingEntry("gui.semaphore_build_before"));
2046 construction->Add(new SettingEntry("gui.signal_gui_mode"));
2047 construction->Add(new SettingEntry("gui.cycle_signal_types"));
2048 construction->Add(new SettingEntry("gui.drag_signals_fixed_distance"));
2049 construction->Add(new SettingEntry("gui.auto_remove_signals"));
2052 interface->Add(new SettingEntry("gui.toolbar_pos"));
2053 interface->Add(new SettingEntry("gui.statusbar_pos"));
2054 interface->Add(new SettingEntry("gui.prefer_teamchat"));
2055 interface->Add(new SettingEntry("gui.advanced_vehicle_list"));
2056 interface->Add(new SettingEntry("gui.timetable_mode"));
2057 interface->Add(new SettingEntry("gui.timetable_arrival_departure"));
2058 interface->Add(new SettingEntry("gui.show_newgrf_name"));
2059 interface->Add(new SettingEntry("gui.show_cargo_in_vehicle_lists"));
2062 SettingsPage *advisors = main->Add(new SettingsPage(STR_CONFIG_SETTING_ADVISORS));
2064 advisors->Add(new SettingEntry("gui.coloured_news_year"));
2065 advisors->Add(new SettingEntry("news_display.general"));
2066 advisors->Add(new SettingEntry("news_display.new_vehicles"));
2067 advisors->Add(new SettingEntry("news_display.accident"));
2068 advisors->Add(new SettingEntry("news_display.accident_other"));
2069 advisors->Add(new SettingEntry("news_display.company_info"));
2070 advisors->Add(new SettingEntry("news_display.acceptance"));
2071 advisors->Add(new SettingEntry("news_display.arrival_player"));
2072 advisors->Add(new SettingEntry("news_display.arrival_other"));
2073 advisors->Add(new SettingEntry("news_display.advice"));
2074 advisors->Add(new SettingEntry("gui.order_review_system"));
2075 advisors->Add(new SettingEntry("gui.vehicle_income_warn"));
2076 advisors->Add(new SettingEntry("gui.lost_vehicle_warn"));
2077 advisors->Add(new SettingEntry("gui.old_vehicle_warn"));
2078 advisors->Add(new SettingEntry("gui.show_finances"));
2079 advisors->Add(new SettingEntry("news_display.economy"));
2080 advisors->Add(new SettingEntry("news_display.subsidies"));
2081 advisors->Add(new SettingEntry("news_display.open"));
2082 advisors->Add(new SettingEntry("news_display.close"));
2083 advisors->Add(new SettingEntry("news_display.production_player"));
2084 advisors->Add(new SettingEntry("news_display.production_other"));
2085 advisors->Add(new SettingEntry("news_display.production_nobody"));
2088 SettingsPage *company = main->Add(new SettingsPage(STR_CONFIG_SETTING_COMPANY));
2090 company->Add(new SettingEntry("gui.starting_colour"));
2091 company->Add(new SettingEntry("gui.starting_colour_secondary"));
2092 company->Add(new SettingEntry("company.engine_renew"));
2093 company->Add(new SettingEntry("company.engine_renew_months"));
2094 company->Add(new SettingEntry("company.engine_renew_money"));
2095 company->Add(new SettingEntry("vehicle.servint_ispercent"));
2096 company->Add(new SettingEntry("vehicle.servint_trains"));
2097 company->Add(new SettingEntry("vehicle.servint_roadveh"));
2098 company->Add(new SettingEntry("vehicle.servint_ships"));
2099 company->Add(new SettingEntry("vehicle.servint_aircraft"));
2102 SettingsPage *accounting = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCOUNTING));
2104 accounting->Add(new SettingEntry("difficulty.infinite_money"));
2105 accounting->Add(new SettingEntry("economy.inflation"));
2106 accounting->Add(new SettingEntry("difficulty.initial_interest"));
2107 accounting->Add(new SettingEntry("difficulty.max_loan"));
2108 accounting->Add(new SettingEntry("difficulty.subsidy_multiplier"));
2109 accounting->Add(new SettingEntry("difficulty.subsidy_duration"));
2110 accounting->Add(new SettingEntry("economy.feeder_payment_share"));
2111 accounting->Add(new SettingEntry("economy.infrastructure_maintenance"));
2112 accounting->Add(new SettingEntry("difficulty.vehicle_costs"));
2113 accounting->Add(new SettingEntry("difficulty.construction_cost"));
2116 SettingsPage *vehicles = main->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES));
2118 SettingsPage *physics = vehicles->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES_PHYSICS));
2120 physics->Add(new SettingEntry("vehicle.train_acceleration_model"));
2121 physics->Add(new SettingEntry("vehicle.train_slope_steepness"));
2122 physics->Add(new SettingEntry("vehicle.wagon_speed_limits"));
2123 physics->Add(new SettingEntry("vehicle.freight_trains"));
2124 physics->Add(new SettingEntry("vehicle.roadveh_acceleration_model"));
2125 physics->Add(new SettingEntry("vehicle.roadveh_slope_steepness"));
2126 physics->Add(new SettingEntry("vehicle.smoke_amount"));
2127 physics->Add(new SettingEntry("vehicle.plane_speed"));
2130 SettingsPage *routing = vehicles->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES_ROUTING));
2132 routing->Add(new SettingEntry("vehicle.road_side"));
2133 routing->Add(new SettingEntry("difficulty.line_reverse_mode"));
2134 routing->Add(new SettingEntry("pf.reverse_at_signals"));
2135 routing->Add(new SettingEntry("pf.forbid_90_deg"));
2138 SettingsPage *orders = vehicles->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES_ORDERS));
2140 orders->Add(new SettingEntry("gui.new_nonstop"));
2141 orders->Add(new SettingEntry("gui.quick_goto"));
2142 orders->Add(new SettingEntry("gui.stop_location"));
2146 SettingsPage *limitations = main->Add(new SettingsPage(STR_CONFIG_SETTING_LIMITATIONS));
2148 limitations->Add(new SettingEntry("construction.command_pause_level"));
2149 limitations->Add(new SettingEntry("construction.autoslope"));
2150 limitations->Add(new SettingEntry("construction.extra_dynamite"));
2151 limitations->Add(new SettingEntry("construction.map_height_limit"));
2152 limitations->Add(new SettingEntry("construction.max_bridge_length"));
2153 limitations->Add(new SettingEntry("construction.max_bridge_height"));
2154 limitations->Add(new SettingEntry("construction.max_tunnel_length"));
2155 limitations->Add(new SettingEntry("station.never_expire_airports"));
2156 limitations->Add(new SettingEntry("vehicle.never_expire_vehicles"));
2157 limitations->Add(new SettingEntry("vehicle.max_trains"));
2158 limitations->Add(new SettingEntry("vehicle.max_roadveh"));
2159 limitations->Add(new SettingEntry("vehicle.max_aircraft"));
2160 limitations->Add(new SettingEntry("vehicle.max_ships"));
2161 limitations->Add(new SettingEntry("vehicle.max_train_length"));
2162 limitations->Add(new SettingEntry("station.station_spread"));
2163 limitations->Add(new SettingEntry("station.distant_join_stations"));
2164 limitations->Add(new SettingEntry("station.modified_catchment"));
2165 limitations->Add(new SettingEntry("construction.road_stop_on_town_road"));
2166 limitations->Add(new SettingEntry("construction.road_stop_on_competitor_road"));
2167 limitations->Add(new SettingEntry("construction.crossing_with_competitor"));
2168 limitations->Add(new SettingEntry("vehicle.disable_elrails"));
2169 limitations->Add(new SettingEntry("order.station_length_loading_penalty"));
2172 SettingsPage *disasters = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCIDENTS));
2174 disasters->Add(new SettingEntry("difficulty.disasters"));
2175 disasters->Add(new SettingEntry("difficulty.economy"));
2176 disasters->Add(new SettingEntry("vehicle.plane_crashes"));
2177 disasters->Add(new SettingEntry("difficulty.vehicle_breakdowns"));
2178 disasters->Add(new SettingEntry("order.no_servicing_if_no_breakdowns"));
2179 disasters->Add(new SettingEntry("order.serviceathelipad"));
2182 SettingsPage *genworld = main->Add(new SettingsPage(STR_CONFIG_SETTING_GENWORLD));
2184 genworld->Add(new SettingEntry("game_creation.landscape"));
2185 genworld->Add(new SettingEntry("game_creation.land_generator"));
2186 genworld->Add(new SettingEntry("difficulty.terrain_type"));
2187 genworld->Add(new SettingEntry("game_creation.tgen_smoothness"));
2188 genworld->Add(new SettingEntry("game_creation.variety"));
2189 genworld->Add(new SettingEntry("game_creation.snow_coverage"));
2190 genworld->Add(new SettingEntry("game_creation.snow_line_height"));
2191 genworld->Add(new SettingEntry("game_creation.desert_coverage"));
2192 genworld->Add(new SettingEntry("game_creation.amount_of_rivers"));
2195 SettingsPage *environment = main->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT));
2197 SettingsPage *time = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_TIME));
2199 time->Add(new SettingEntry("economy.timekeeping_units"));
2200 time->Add(new SettingEntry("economy.minutes_per_calendar_year"));
2201 time->Add(new SettingEntry("game_creation.ending_year"));
2202 time->Add(new SettingEntry("gui.pause_on_newgame"));
2203 time->Add(new SettingEntry("gui.fast_forward_speed_limit"));
2206 SettingsPage *authorities = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_AUTHORITIES));
2208 authorities->Add(new SettingEntry("difficulty.town_council_tolerance"));
2209 authorities->Add(new SettingEntry("economy.bribe"));
2210 authorities->Add(new SettingEntry("economy.exclusive_rights"));
2211 authorities->Add(new SettingEntry("economy.fund_roads"));
2212 authorities->Add(new SettingEntry("economy.fund_buildings"));
2213 authorities->Add(new SettingEntry("economy.station_noise_level"));
2216 SettingsPage *towns = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_TOWNS));
2218 towns->Add(new SettingEntry("economy.town_cargo_scale"));
2219 towns->Add(new SettingEntry("economy.town_growth_rate"));
2220 towns->Add(new SettingEntry("economy.allow_town_roads"));
2221 towns->Add(new SettingEntry("economy.allow_town_level_crossings"));
2222 towns->Add(new SettingEntry("economy.found_town"));
2223 towns->Add(new SettingEntry("economy.town_layout"));
2224 towns->Add(new SettingEntry("economy.larger_towns"));
2225 towns->Add(new SettingEntry("economy.initial_city_size"));
2226 towns->Add(new SettingEntry("economy.town_cargogen_mode"));
2229 SettingsPage *industries = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_INDUSTRIES));
2231 industries->Add(new SettingEntry("economy.industry_cargo_scale"));
2232 industries->Add(new SettingEntry("difficulty.industry_density"));
2233 industries->Add(new SettingEntry("construction.raw_industry_construction"));
2234 industries->Add(new SettingEntry("construction.industry_platform"));
2235 industries->Add(new SettingEntry("economy.multiple_industry_per_town"));
2236 industries->Add(new SettingEntry("game_creation.oil_refinery_limit"));
2237 industries->Add(new SettingEntry("economy.type"));
2238 industries->Add(new SettingEntry("station.serve_neutral_industries"));
2241 SettingsPage *cdist = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST));
2243 cdist->Add(new SettingEntry("linkgraph.recalc_time"));
2244 cdist->Add(new SettingEntry("linkgraph.recalc_interval"));
2245 cdist->Add(new SettingEntry("linkgraph.distribution_pax"));
2246 cdist->Add(new SettingEntry("linkgraph.distribution_mail"));
2247 cdist->Add(new SettingEntry("linkgraph.distribution_armoured"));
2248 cdist->Add(new SettingEntry("linkgraph.distribution_default"));
2249 cdist->Add(new SettingEntry("linkgraph.accuracy"));
2250 cdist->Add(new SettingEntry("linkgraph.demand_distance"));
2251 cdist->Add(new SettingEntry("linkgraph.demand_size"));
2252 cdist->Add(new SettingEntry("linkgraph.short_path_saturation"));
2255 SettingsPage *trees = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_TREES));
2257 trees->Add(new SettingEntry("game_creation.tree_placer"));
2258 trees->Add(new SettingEntry("construction.extra_tree_placement"));
2262 SettingsPage *ai = main->Add(new SettingsPage(STR_CONFIG_SETTING_AI));
2264 SettingsPage *npc = ai->Add(new SettingsPage(STR_CONFIG_SETTING_AI_NPC));
2266 npc->Add(new SettingEntry("script.script_max_opcode_till_suspend"));
2267 npc->Add(new SettingEntry("script.script_max_memory_megabytes"));
2268 npc->Add(new SettingEntry("difficulty.competitor_speed"));
2269 npc->Add(new SettingEntry("ai.ai_in_multiplayer"));
2270 npc->Add(new SettingEntry("ai.ai_disable_veh_train"));
2271 npc->Add(new SettingEntry("ai.ai_disable_veh_roadveh"));
2272 npc->Add(new SettingEntry("ai.ai_disable_veh_aircraft"));
2273 npc->Add(new SettingEntry("ai.ai_disable_veh_ship"));
2276 ai->Add(new SettingEntry("economy.give_money"));
2279 SettingsPage *network = main->Add(new SettingsPage(STR_CONFIG_SETTING_NETWORK));
2281 network->Add(new SettingEntry("network.use_relay_service"));
2284 main->Init();
2286 return *main;
2289 static const StringID _game_settings_restrict_dropdown[] = {
2290 STR_CONFIG_SETTING_RESTRICT_BASIC, // RM_BASIC
2291 STR_CONFIG_SETTING_RESTRICT_ADVANCED, // RM_ADVANCED
2292 STR_CONFIG_SETTING_RESTRICT_ALL, // RM_ALL
2293 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT, // RM_CHANGED_AGAINST_DEFAULT
2294 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW, // RM_CHANGED_AGAINST_NEW
2296 static_assert(lengthof(_game_settings_restrict_dropdown) == RM_END);
2298 /** Warnings about hidden search results. */
2299 enum WarnHiddenResult {
2300 WHR_NONE, ///< Nothing was filtering matches away.
2301 WHR_CATEGORY, ///< Category setting filtered matches away.
2302 WHR_TYPE, ///< Type setting filtered matches away.
2303 WHR_CATEGORY_TYPE, ///< Both category and type settings filtered matches away.
2307 * Callback function for the reset all settings button
2308 * @param w Window which is calling this callback
2309 * @param confirmed boolean value, true when yes was clicked, false otherwise
2311 static void ResetAllSettingsConfirmationCallback(Window *w, bool confirmed)
2313 if (confirmed) {
2314 GetSettingsTree().ResetAll();
2315 GetSettingsTree().FoldAll();
2316 w->InvalidateData();
2320 /** Window to edit settings of the game. */
2321 struct GameSettingsWindow : Window {
2322 static GameSettings *settings_ptr; ///< Pointer to the game settings being displayed and modified.
2324 SettingEntry *valuewindow_entry; ///< If non-nullptr, pointer to setting for which a value-entering window has been opened.
2325 SettingEntry *clicked_entry; ///< If non-nullptr, pointer to a clicked numeric setting (with a depressed left or right button).
2326 SettingEntry *last_clicked; ///< If non-nullptr, pointer to the last clicked setting.
2327 SettingEntry *valuedropdown_entry; ///< If non-nullptr, pointer to the value for which a dropdown window is currently opened.
2328 bool closing_dropdown; ///< True, if the dropdown list is currently closing.
2330 SettingFilter filter; ///< Filter for the list.
2331 QueryString filter_editbox; ///< Filter editbox;
2332 bool manually_changed_folding; ///< Whether the user expanded/collapsed something manually.
2333 WarnHiddenResult warn_missing; ///< Whether and how to warn about missing search results.
2334 int warn_lines; ///< Number of lines used for warning about missing search results.
2336 Scrollbar *vscroll;
2338 GameSettingsWindow(WindowDesc &desc) : Window(desc), filter_editbox(50)
2340 this->warn_missing = WHR_NONE;
2341 this->warn_lines = 0;
2342 this->filter.mode = (RestrictionMode)_settings_client.gui.settings_restriction_mode;
2343 this->filter.min_cat = RM_ALL;
2344 this->filter.type = ST_ALL;
2345 this->filter.type_hides = false;
2346 this->settings_ptr = &GetGameSettings();
2348 GetSettingsTree().FoldAll(); // Close all sub-pages
2350 this->valuewindow_entry = nullptr; // No setting entry for which a entry window is opened
2351 this->clicked_entry = nullptr; // No numeric setting buttons are depressed
2352 this->last_clicked = nullptr;
2353 this->valuedropdown_entry = nullptr;
2354 this->closing_dropdown = false;
2355 this->manually_changed_folding = false;
2357 this->CreateNestedTree();
2358 this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
2359 this->FinishInitNested(WN_GAME_OPTIONS_GAME_SETTINGS);
2361 this->querystrings[WID_GS_FILTER] = &this->filter_editbox;
2362 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
2363 this->SetFocusedWidget(WID_GS_FILTER);
2365 this->InvalidateData();
2368 void OnInit() override
2370 _circle_size = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
2373 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
2375 switch (widget) {
2376 case WID_GS_OPTIONSPANEL:
2377 resize.height = SETTING_HEIGHT = std::max({(int)_circle_size.height, SETTING_BUTTON_HEIGHT, GetCharacterHeight(FS_NORMAL)}) + WidgetDimensions::scaled.vsep_normal;
2378 resize.width = 1;
2380 size.height = 5 * resize.height + WidgetDimensions::scaled.framerect.Vertical();
2381 break;
2383 case WID_GS_HELP_TEXT: {
2384 static const StringID setting_types[] = {
2385 STR_CONFIG_SETTING_TYPE_CLIENT,
2386 STR_CONFIG_SETTING_TYPE_COMPANY_MENU, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME,
2387 STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
2389 for (const auto &setting_type : setting_types) {
2390 SetDParam(0, setting_type);
2391 size.width = std::max(size.width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width + padding.width);
2393 size.height = 2 * GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal +
2394 std::max(size.height, GetSettingsTree().GetMaxHelpHeight(size.width));
2395 break;
2398 case WID_GS_RESTRICT_CATEGORY:
2399 case WID_GS_RESTRICT_TYPE:
2400 size.width = std::max(GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_CATEGORY).width, GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_TYPE).width);
2401 break;
2403 default:
2404 break;
2408 void OnPaint() override
2410 if (this->closing_dropdown) {
2411 this->closing_dropdown = false;
2412 assert(this->valuedropdown_entry != nullptr);
2413 this->valuedropdown_entry->SetButtons(0);
2414 this->valuedropdown_entry = nullptr;
2417 /* Reserve the correct number of lines for the 'some search results are hidden' notice in the central settings display panel. */
2418 const Rect panel = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext);
2419 StringID warn_str = STR_CONFIG_SETTING_CATEGORY_HIDES - 1 + this->warn_missing;
2420 int new_warn_lines;
2421 if (this->warn_missing == WHR_NONE) {
2422 new_warn_lines = 0;
2423 } else {
2424 SetDParam(0, _game_settings_restrict_dropdown[this->filter.min_cat]);
2425 new_warn_lines = GetStringLineCount(warn_str, panel.Width());
2427 if (this->warn_lines != new_warn_lines) {
2428 this->vscroll->SetCount(this->vscroll->GetCount() - this->warn_lines + new_warn_lines);
2429 this->warn_lines = new_warn_lines;
2432 this->DrawWidgets();
2434 /* Draw the 'some search results are hidden' notice. */
2435 if (this->warn_missing != WHR_NONE) {
2436 SetDParam(0, _game_settings_restrict_dropdown[this->filter.min_cat]);
2437 DrawStringMultiLine(panel.WithHeight(this->warn_lines * GetCharacterHeight(FS_NORMAL)), warn_str, TC_FROMSTRING, SA_CENTER);
2441 void SetStringParameters(WidgetID widget) const override
2443 switch (widget) {
2444 case WID_GS_RESTRICT_DROPDOWN:
2445 SetDParam(0, _game_settings_restrict_dropdown[this->filter.mode]);
2446 break;
2448 case WID_GS_TYPE_DROPDOWN:
2449 switch (this->filter.type) {
2450 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME); break;
2451 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME); break;
2452 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT); break;
2453 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL); break;
2455 break;
2459 DropDownList BuildDropDownList(WidgetID widget) const
2461 DropDownList list;
2462 switch (widget) {
2463 case WID_GS_RESTRICT_DROPDOWN:
2464 for (int mode = 0; mode != RM_END; mode++) {
2465 /* If we are in adv. settings screen for the new game's settings,
2466 * we don't want to allow comparing with new game's settings. */
2467 bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame;
2469 list.push_back(MakeDropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled));
2471 break;
2473 case WID_GS_TYPE_DROPDOWN:
2474 list.push_back(MakeDropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL));
2475 list.push_back(MakeDropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME));
2476 list.push_back(MakeDropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY));
2477 list.push_back(MakeDropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT));
2478 break;
2480 return list;
2483 void DrawWidget(const Rect &r, WidgetID widget) const override
2485 switch (widget) {
2486 case WID_GS_OPTIONSPANEL: {
2487 Rect tr = r.Shrink(WidgetDimensions::scaled.frametext, WidgetDimensions::scaled.framerect);
2488 tr.top += this->warn_lines * SETTING_HEIGHT;
2489 uint last_row = this->vscroll->GetPosition() + this->vscroll->GetCapacity() - this->warn_lines;
2490 int next_row = GetSettingsTree().Draw(settings_ptr, tr.left, tr.right, tr.top,
2491 this->vscroll->GetPosition(), last_row, this->last_clicked);
2492 if (next_row == 0) DrawString(tr, STR_CONFIG_SETTINGS_NONE);
2493 break;
2496 case WID_GS_HELP_TEXT:
2497 if (this->last_clicked != nullptr) {
2498 const IntSettingDesc *sd = this->last_clicked->setting;
2500 Rect tr = r;
2501 switch (sd->GetType()) {
2502 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
2503 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT); break;
2504 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
2505 default: NOT_REACHED();
2507 DrawString(tr, STR_CONFIG_SETTING_TYPE);
2508 tr.top += GetCharacterHeight(FS_NORMAL);
2510 int32_t def_val = sd->get_def_cb != nullptr ? sd->get_def_cb() : sd->def;
2511 sd->SetValueDParams(0, def_val);
2512 DrawString(tr, STR_CONFIG_SETTING_DEFAULT_VALUE);
2513 tr.top += GetCharacterHeight(FS_NORMAL) + WidgetDimensions::scaled.vsep_normal;
2515 DrawStringMultiLine(tr, sd->GetHelp(), TC_WHITE);
2517 break;
2519 default:
2520 break;
2525 * Set the entry that should have its help text displayed, and mark the window dirty so it gets repainted.
2526 * @param pe Setting to display help text of, use \c nullptr to stop displaying help of the currently displayed setting.
2528 void SetDisplayedHelpText(SettingEntry *pe)
2530 if (this->last_clicked != pe) this->SetDirty();
2531 this->last_clicked = pe;
2534 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2536 switch (widget) {
2537 case WID_GS_EXPAND_ALL:
2538 this->manually_changed_folding = true;
2539 GetSettingsTree().UnFoldAll();
2540 this->InvalidateData();
2541 break;
2543 case WID_GS_COLLAPSE_ALL:
2544 this->manually_changed_folding = true;
2545 GetSettingsTree().FoldAll();
2546 this->InvalidateData();
2547 break;
2549 case WID_GS_RESET_ALL:
2550 ShowQuery(
2551 STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_CAPTION,
2552 STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_TEXT,
2553 this,
2554 ResetAllSettingsConfirmationCallback
2556 break;
2558 case WID_GS_RESTRICT_DROPDOWN: {
2559 DropDownList list = this->BuildDropDownList(widget);
2560 if (!list.empty()) {
2561 ShowDropDownList(this, std::move(list), this->filter.mode, widget);
2563 break;
2566 case WID_GS_TYPE_DROPDOWN: {
2567 DropDownList list = this->BuildDropDownList(widget);
2568 if (!list.empty()) {
2569 ShowDropDownList(this, std::move(list), this->filter.type, widget);
2571 break;
2575 if (widget != WID_GS_OPTIONSPANEL) return;
2577 int32_t btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, WidgetDimensions::scaled.framerect.top);
2578 if (btn == INT32_MAX || btn < this->warn_lines) return;
2579 btn -= this->warn_lines;
2581 uint cur_row = 0;
2582 BaseSettingEntry *clicked_entry = GetSettingsTree().FindEntry(btn, &cur_row);
2584 if (clicked_entry == nullptr) return; // Clicked below the last setting of the page
2586 int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - WidgetDimensions::scaled.frametext.left - (clicked_entry->level + 1) * WidgetDimensions::scaled.hsep_indent; // Shift x coordinate
2587 if (x < 0) return; // Clicked left of the entry
2589 SettingsPage *clicked_page = dynamic_cast<SettingsPage*>(clicked_entry);
2590 if (clicked_page != nullptr) {
2591 this->SetDisplayedHelpText(nullptr);
2592 clicked_page->folded = !clicked_page->folded; // Flip 'folded'-ness of the sub-page
2594 this->manually_changed_folding = true;
2596 this->InvalidateData();
2597 return;
2600 SettingEntry *pe = dynamic_cast<SettingEntry*>(clicked_entry);
2601 assert(pe != nullptr);
2602 const IntSettingDesc *sd = pe->setting;
2604 /* return if action is only active in network, or only settable by server */
2605 if (!sd->IsEditable()) {
2606 this->SetDisplayedHelpText(pe);
2607 return;
2610 int32_t value = sd->Read(ResolveObject(settings_ptr, sd));
2612 /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
2613 if (x < SETTING_BUTTON_WIDTH && (sd->flags & SF_GUI_DROPDOWN)) {
2614 this->SetDisplayedHelpText(pe);
2616 if (this->valuedropdown_entry == pe) {
2617 /* unclick the dropdown */
2618 this->CloseChildWindows(WC_DROPDOWN_MENU);
2619 this->closing_dropdown = false;
2620 this->valuedropdown_entry->SetButtons(0);
2621 this->valuedropdown_entry = nullptr;
2622 } else {
2623 if (this->valuedropdown_entry != nullptr) this->valuedropdown_entry->SetButtons(0);
2624 this->closing_dropdown = false;
2626 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
2627 int rel_y = (pt.y - wid->pos_y - WidgetDimensions::scaled.framerect.top) % wid->resize_y;
2629 Rect wi_rect;
2630 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
2631 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
2632 wi_rect.top = pt.y - rel_y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
2633 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
2635 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
2636 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
2637 this->valuedropdown_entry = pe;
2638 this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
2640 DropDownList list;
2641 for (int i = sd->min; i <= (int)sd->max; i++) {
2642 sd->SetValueDParams(0, i);
2643 list.push_back(MakeDropDownListStringItem(STR_JUST_STRING2, i));
2646 ShowDropDownListAt(this, std::move(list), value, WID_GS_SETTING_DROPDOWN, wi_rect, COLOUR_ORANGE);
2649 this->SetDirty();
2650 } else if (x < SETTING_BUTTON_WIDTH) {
2651 this->SetDisplayedHelpText(pe);
2652 int32_t oldvalue = value;
2654 if (sd->IsBoolSetting()) {
2655 value ^= 1;
2656 } else {
2657 /* Add a dynamic step-size to the scroller. In a maximum of
2658 * 50-steps you should be able to get from min to max,
2659 * unless specified otherwise in the 'interval' variable
2660 * of the current setting. */
2661 uint32_t step = (sd->interval == 0) ? ((sd->max - sd->min) / 50) : sd->interval;
2662 if (step == 0) step = 1;
2664 /* don't allow too fast scrolling */
2665 if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
2666 _left_button_clicked = false;
2667 return;
2670 /* Increase or decrease the value and clamp it to extremes */
2671 if (x >= SETTING_BUTTON_WIDTH / 2) {
2672 value += step;
2673 if (sd->min < 0) {
2674 assert((int32_t)sd->max >= 0);
2675 if (value > (int32_t)sd->max) value = (int32_t)sd->max;
2676 } else {
2677 if ((uint32_t)value > sd->max) value = (int32_t)sd->max;
2679 if (value < sd->min) value = sd->min; // skip between "disabled" and minimum
2680 } else {
2681 value -= step;
2682 if (value < sd->min) value = (sd->flags & SF_GUI_0_IS_SPECIAL) ? 0 : sd->min;
2685 /* Set up scroller timeout for numeric values */
2686 if (value != oldvalue) {
2687 if (this->clicked_entry != nullptr) { // Release previous buttons if any
2688 this->clicked_entry->SetButtons(0);
2690 this->clicked_entry = pe;
2691 this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
2692 this->SetTimeout();
2693 _left_button_clicked = false;
2697 if (value != oldvalue) {
2698 SetSettingValue(sd, value);
2699 this->SetDirty();
2701 } else {
2702 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
2703 if (this->last_clicked == pe && !sd->IsBoolSetting() && !(sd->flags & SF_GUI_DROPDOWN)) {
2704 int64_t value64 = value;
2705 /* Show the correct currency-translated value */
2706 if (sd->flags & SF_GUI_CURRENCY) value64 *= GetCurrency().rate;
2708 CharSetFilter charset_filter = CS_NUMERAL; //default, only numeric input allowed
2709 if (sd->min < 0) charset_filter = CS_NUMERAL_SIGNED; // special case, also allow '-' sign for negative input
2711 this->valuewindow_entry = pe;
2712 SetDParam(0, value64);
2713 /* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */
2714 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QSF_ENABLE_DEFAULT);
2716 this->SetDisplayedHelpText(pe);
2720 void OnTimeout() override
2722 if (this->clicked_entry != nullptr) { // On timeout, release any depressed buttons
2723 this->clicked_entry->SetButtons(0);
2724 this->clicked_entry = nullptr;
2725 this->SetDirty();
2729 void OnQueryTextFinished(std::optional<std::string> str) override
2731 /* The user pressed cancel */
2732 if (!str.has_value()) return;
2734 assert(this->valuewindow_entry != nullptr);
2735 const IntSettingDesc *sd = this->valuewindow_entry->setting;
2737 int32_t value;
2738 if (!str->empty()) {
2739 long long llvalue = atoll(str->c_str());
2741 /* Save the correct currency-translated value */
2742 if (sd->flags & SF_GUI_CURRENCY) llvalue /= GetCurrency().rate;
2744 value = ClampTo<int32_t>(llvalue);
2745 } else if (sd->get_def_cb != nullptr) {
2746 value = sd->get_def_cb();
2747 } else {
2748 value = sd->def;
2751 SetSettingValue(this->valuewindow_entry->setting, value);
2752 this->SetDirty();
2755 void OnDropdownSelect(WidgetID widget, int index) override
2757 switch (widget) {
2758 case WID_GS_RESTRICT_DROPDOWN:
2759 this->filter.mode = (RestrictionMode)index;
2760 if (this->filter.mode == RM_CHANGED_AGAINST_DEFAULT ||
2761 this->filter.mode == RM_CHANGED_AGAINST_NEW) {
2763 if (!this->manually_changed_folding) {
2764 /* Expand all when selecting 'changes'. Update the filter state first, in case it becomes less restrictive in some cases. */
2765 GetSettingsTree().UpdateFilterState(this->filter, false);
2766 GetSettingsTree().UnFoldAll();
2768 } else {
2769 /* Non-'changes' filter. Save as default. */
2770 _settings_client.gui.settings_restriction_mode = this->filter.mode;
2772 this->InvalidateData();
2773 break;
2775 case WID_GS_TYPE_DROPDOWN:
2776 this->filter.type = (SettingType)index;
2777 this->InvalidateData();
2778 break;
2780 case WID_GS_SETTING_DROPDOWN:
2781 /* Deal with drop down boxes on the panel. */
2782 assert(this->valuedropdown_entry != nullptr);
2783 const IntSettingDesc *sd = this->valuedropdown_entry->setting;
2784 assert(sd->flags & SF_GUI_DROPDOWN);
2786 SetSettingValue(sd, index);
2787 this->SetDirty();
2788 break;
2792 void OnDropdownClose(Point pt, WidgetID widget, int index, bool instant_close) override
2794 if (widget != WID_GS_SETTING_DROPDOWN) {
2795 /* Normally the default implementation of OnDropdownClose() takes care of
2796 * a few things. We want that behaviour here too, but only for
2797 * "normal" dropdown boxes. The special dropdown boxes added for every
2798 * setting that needs one can't have this call. */
2799 Window::OnDropdownClose(pt, widget, index, instant_close);
2800 } else {
2801 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
2802 * the same dropdown button was clicked again, and then not open the dropdown again.
2803 * So, we only remember that it was closed, and process it on the next OnPaint, which is
2804 * after OnClick. */
2805 assert(this->valuedropdown_entry != nullptr);
2806 this->closing_dropdown = true;
2807 this->SetDirty();
2811 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
2813 if (!gui_scope) return;
2815 /* Update which settings are to be visible. */
2816 RestrictionMode min_level = (this->filter.mode <= RM_ALL) ? this->filter.mode : RM_BASIC;
2817 this->filter.min_cat = min_level;
2818 this->filter.type_hides = false;
2819 GetSettingsTree().UpdateFilterState(this->filter, false);
2821 if (this->filter.string.IsEmpty()) {
2822 this->warn_missing = WHR_NONE;
2823 } else if (min_level < this->filter.min_cat) {
2824 this->warn_missing = this->filter.type_hides ? WHR_CATEGORY_TYPE : WHR_CATEGORY;
2825 } else {
2826 this->warn_missing = this->filter.type_hides ? WHR_TYPE : WHR_NONE;
2828 this->vscroll->SetCount(GetSettingsTree().Length() + this->warn_lines);
2830 if (this->last_clicked != nullptr && !GetSettingsTree().IsVisible(this->last_clicked)) {
2831 this->SetDisplayedHelpText(nullptr);
2834 bool all_folded = true;
2835 bool all_unfolded = true;
2836 GetSettingsTree().GetFoldingState(all_folded, all_unfolded);
2837 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL, all_unfolded);
2838 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
2841 void OnEditboxChanged(WidgetID wid) override
2843 if (wid == WID_GS_FILTER) {
2844 this->filter.string.SetFilterTerm(this->filter_editbox.text.buf);
2845 if (!this->filter.string.IsEmpty() && !this->manually_changed_folding) {
2846 /* User never expanded/collapsed single pages and entered a filter term.
2847 * Expand everything, to save weird expand clicks, */
2848 GetSettingsTree().UnFoldAll();
2850 this->InvalidateData();
2854 void OnResize() override
2856 this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, WidgetDimensions::scaled.framerect.Vertical());
2860 GameSettings *GameSettingsWindow::settings_ptr = nullptr;
2862 static constexpr NWidgetPart _nested_settings_selection_widgets[] = {
2863 NWidget(NWID_HORIZONTAL),
2864 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
2865 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_TREE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2866 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
2867 EndContainer(),
2868 NWidget(WWT_PANEL, COLOUR_MAUVE),
2869 NWidget(NWID_VERTICAL), SetPIP(WidgetDimensions::unscaled.frametext.top, WidgetDimensions::unscaled.vsep_normal, WidgetDimensions::unscaled.frametext.bottom),
2870 NWidget(NWID_HORIZONTAL), SetPIP(WidgetDimensions::unscaled.frametext.left, WidgetDimensions::unscaled.hsep_wide, WidgetDimensions::unscaled.frametext.right),
2871 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_GS_RESTRICT_CATEGORY), SetDataTip(STR_CONFIG_SETTING_RESTRICT_CATEGORY, STR_NULL),
2872 NWidget(WWT_DROPDOWN, COLOUR_MAUVE, WID_GS_RESTRICT_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_STRING, STR_CONFIG_SETTING_RESTRICT_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
2873 EndContainer(),
2874 NWidget(NWID_HORIZONTAL), SetPIP(WidgetDimensions::unscaled.frametext.left, WidgetDimensions::unscaled.hsep_wide, WidgetDimensions::unscaled.frametext.right),
2875 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_GS_RESTRICT_TYPE), SetDataTip(STR_CONFIG_SETTING_RESTRICT_TYPE, STR_NULL),
2876 NWidget(WWT_DROPDOWN, COLOUR_MAUVE, WID_GS_TYPE_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_JUST_STRING, STR_CONFIG_SETTING_TYPE_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
2877 EndContainer(),
2878 NWidget(NWID_HORIZONTAL), SetPIP(WidgetDimensions::unscaled.frametext.left, WidgetDimensions::unscaled.hsep_wide, WidgetDimensions::unscaled.frametext.right),
2879 NWidget(WWT_TEXT, COLOUR_MAUVE), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE, STR_NULL),
2880 NWidget(WWT_EDITBOX, COLOUR_MAUVE, WID_GS_FILTER), SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
2881 EndContainer(),
2882 EndContainer(),
2883 EndContainer(),
2884 NWidget(NWID_HORIZONTAL),
2885 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
2886 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
2887 EndContainer(),
2888 NWidget(WWT_PANEL, COLOUR_MAUVE),
2889 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GS_HELP_TEXT), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
2890 SetPadding(WidgetDimensions::unscaled.frametext),
2891 EndContainer(),
2892 NWidget(NWID_HORIZONTAL),
2893 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_EXPAND_ALL), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL, STR_NULL),
2894 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_COLLAPSE_ALL), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL, STR_NULL),
2895 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_RESET_ALL), SetDataTip(STR_CONFIG_SETTING_RESET_ALL, STR_NULL),
2896 NWidget(WWT_PANEL, COLOUR_MAUVE), SetFill(1, 0), SetResize(1, 0),
2897 EndContainer(),
2898 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
2899 EndContainer(),
2902 static WindowDesc _settings_selection_desc(
2903 WDP_CENTER, "settings", 510, 450,
2904 WC_GAME_OPTIONS, WC_NONE,
2906 _nested_settings_selection_widgets
2909 /** Open advanced settings window. */
2910 void ShowGameSettings()
2912 CloseWindowByClass(WC_GAME_OPTIONS);
2913 new GameSettingsWindow(_settings_selection_desc);
2918 * Draw [<][>] boxes.
2919 * @param x the x position to draw
2920 * @param y the y position to draw
2921 * @param button_colour the colour of the button
2922 * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked
2923 * @param clickable_left is the left button clickable?
2924 * @param clickable_right is the right button clickable?
2926 void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
2928 int colour = GetColourGradient(button_colour, SHADE_DARKER);
2929 Dimension dim = NWidgetScrollbar::GetHorizontalDimension();
2931 Rect lr = {x, y, x + (int)dim.width - 1, y + (int)dim.height - 1};
2932 Rect rr = {x + (int)dim.width, y, x + (int)dim.width * 2 - 1, y + (int)dim.height - 1};
2934 DrawFrameRect(lr, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
2935 DrawFrameRect(rr, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
2936 DrawSpriteIgnorePadding(SPR_ARROW_LEFT, PAL_NONE, lr, SA_CENTER);
2937 DrawSpriteIgnorePadding(SPR_ARROW_RIGHT, PAL_NONE, rr, SA_CENTER);
2939 /* Grey out the buttons that aren't clickable */
2940 bool rtl = _current_text_dir == TD_RTL;
2941 if (rtl ? !clickable_right : !clickable_left) {
2942 GfxFillRect(lr.Shrink(WidgetDimensions::scaled.bevel), colour, FILLRECT_CHECKER);
2944 if (rtl ? !clickable_left : !clickable_right) {
2945 GfxFillRect(rr.Shrink(WidgetDimensions::scaled.bevel), colour, FILLRECT_CHECKER);
2950 * Draw a dropdown button.
2951 * @param x the x position to draw
2952 * @param y the y position to draw
2953 * @param button_colour the colour of the button
2954 * @param state true = lowered
2955 * @param clickable is the button clickable?
2957 void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
2959 int colour = GetColourGradient(button_colour, SHADE_DARKER);
2961 Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
2963 DrawFrameRect(r, button_colour, state ? FR_LOWERED : FR_NONE);
2964 DrawSpriteIgnorePadding(SPR_ARROW_DOWN, PAL_NONE, r, SA_CENTER);
2966 if (!clickable) {
2967 GfxFillRect(r.Shrink(WidgetDimensions::scaled.bevel), colour, FILLRECT_CHECKER);
2972 * Draw a toggle button.
2973 * @param x the x position to draw
2974 * @param y the y position to draw
2975 * @param state true = lowered
2976 * @param clickable is the button clickable?
2978 void DrawBoolButton(int x, int y, bool state, bool clickable)
2980 static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
2982 Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
2983 DrawFrameRect(r, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
2986 struct CustomCurrencyWindow : Window {
2987 int query_widget;
2989 CustomCurrencyWindow(WindowDesc &desc) : Window(desc)
2991 this->InitNested();
2993 SetButtonState();
2996 void SetButtonState()
2998 this->SetWidgetDisabledState(WID_CC_RATE_DOWN, GetCustomCurrency().rate == 1);
2999 this->SetWidgetDisabledState(WID_CC_RATE_UP, GetCustomCurrency().rate == UINT16_MAX);
3000 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, GetCustomCurrency().to_euro == CF_NOEURO);
3001 this->SetWidgetDisabledState(WID_CC_YEAR_UP, GetCustomCurrency().to_euro == CalendarTime::MAX_YEAR);
3004 void SetStringParameters(WidgetID widget) const override
3006 switch (widget) {
3007 case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
3008 case WID_CC_SEPARATOR: SetDParamStr(0, GetCustomCurrency().separator); break;
3009 case WID_CC_PREFIX: SetDParamStr(0, GetCustomCurrency().prefix); break;
3010 case WID_CC_SUFFIX: SetDParamStr(0, GetCustomCurrency().suffix); break;
3011 case WID_CC_YEAR:
3012 SetDParam(0, (GetCustomCurrency().to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
3013 SetDParam(1, GetCustomCurrency().to_euro);
3014 break;
3016 case WID_CC_PREVIEW:
3017 SetDParam(0, 10000);
3018 break;
3022 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
3024 switch (widget) {
3025 /* Set the appropriate width for the up/down buttons. */
3026 case WID_CC_RATE_DOWN:
3027 case WID_CC_RATE_UP:
3028 case WID_CC_YEAR_DOWN:
3029 case WID_CC_YEAR_UP:
3030 size = maxdim(size, {(uint)SETTING_BUTTON_WIDTH / 2, (uint)SETTING_BUTTON_HEIGHT});
3031 break;
3033 /* Set the appropriate width for the edit buttons. */
3034 case WID_CC_SEPARATOR_EDIT:
3035 case WID_CC_PREFIX_EDIT:
3036 case WID_CC_SUFFIX_EDIT:
3037 size = maxdim(size, {(uint)SETTING_BUTTON_WIDTH, (uint)SETTING_BUTTON_HEIGHT});
3038 break;
3040 /* Make sure the window is wide enough for the widest exchange rate */
3041 case WID_CC_RATE:
3042 SetDParam(0, 1);
3043 SetDParam(1, INT32_MAX);
3044 size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
3045 break;
3049 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
3051 int line = 0;
3052 int len = 0;
3053 StringID str = 0;
3054 CharSetFilter afilter = CS_ALPHANUMERAL;
3056 switch (widget) {
3057 case WID_CC_RATE_DOWN:
3058 if (GetCustomCurrency().rate > 1) GetCustomCurrency().rate--;
3059 if (GetCustomCurrency().rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
3060 this->EnableWidget(WID_CC_RATE_UP);
3061 break;
3063 case WID_CC_RATE_UP:
3064 if (GetCustomCurrency().rate < UINT16_MAX) GetCustomCurrency().rate++;
3065 if (GetCustomCurrency().rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
3066 this->EnableWidget(WID_CC_RATE_DOWN);
3067 break;
3069 case WID_CC_RATE:
3070 SetDParam(0, GetCustomCurrency().rate);
3071 str = STR_JUST_INT;
3072 len = 5;
3073 line = WID_CC_RATE;
3074 afilter = CS_NUMERAL;
3075 break;
3077 case WID_CC_SEPARATOR_EDIT:
3078 case WID_CC_SEPARATOR:
3079 SetDParamStr(0, GetCustomCurrency().separator);
3080 str = STR_JUST_RAW_STRING;
3081 len = 7;
3082 line = WID_CC_SEPARATOR;
3083 break;
3085 case WID_CC_PREFIX_EDIT:
3086 case WID_CC_PREFIX:
3087 SetDParamStr(0, GetCustomCurrency().prefix);
3088 str = STR_JUST_RAW_STRING;
3089 len = 15;
3090 line = WID_CC_PREFIX;
3091 break;
3093 case WID_CC_SUFFIX_EDIT:
3094 case WID_CC_SUFFIX:
3095 SetDParamStr(0, GetCustomCurrency().suffix);
3096 str = STR_JUST_RAW_STRING;
3097 len = 15;
3098 line = WID_CC_SUFFIX;
3099 break;
3101 case WID_CC_YEAR_DOWN:
3102 GetCustomCurrency().to_euro = (GetCustomCurrency().to_euro <= MIN_EURO_YEAR) ? CF_NOEURO : GetCustomCurrency().to_euro - 1;
3103 if (GetCustomCurrency().to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
3104 this->EnableWidget(WID_CC_YEAR_UP);
3105 break;
3107 case WID_CC_YEAR_UP:
3108 GetCustomCurrency().to_euro = Clamp(GetCustomCurrency().to_euro + 1, MIN_EURO_YEAR, CalendarTime::MAX_YEAR);
3109 if (GetCustomCurrency().to_euro == CalendarTime::MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
3110 this->EnableWidget(WID_CC_YEAR_DOWN);
3111 break;
3113 case WID_CC_YEAR:
3114 SetDParam(0, GetCustomCurrency().to_euro);
3115 str = STR_JUST_INT;
3116 len = 7;
3117 line = WID_CC_YEAR;
3118 afilter = CS_NUMERAL;
3119 break;
3122 if (len != 0) {
3123 this->query_widget = line;
3124 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
3127 this->SetTimeout();
3128 this->SetDirty();
3131 void OnQueryTextFinished(std::optional<std::string> str) override
3133 if (!str.has_value()) return;
3135 switch (this->query_widget) {
3136 case WID_CC_RATE:
3137 GetCustomCurrency().rate = Clamp(atoi(str->c_str()), 1, UINT16_MAX);
3138 break;
3140 case WID_CC_SEPARATOR: // Thousands separator
3141 GetCustomCurrency().separator = std::move(*str);
3142 break;
3144 case WID_CC_PREFIX:
3145 GetCustomCurrency().prefix = std::move(*str);
3146 break;
3148 case WID_CC_SUFFIX:
3149 GetCustomCurrency().suffix = std::move(*str);
3150 break;
3152 case WID_CC_YEAR: { // Year to switch to euro
3153 TimerGameCalendar::Year val = atoi(str->c_str());
3155 GetCustomCurrency().to_euro = (val < MIN_EURO_YEAR ? CF_NOEURO : std::min(val, CalendarTime::MAX_YEAR));
3156 break;
3159 MarkWholeScreenDirty();
3160 SetButtonState();
3163 void OnTimeout() override
3165 this->SetDirty();
3169 static constexpr NWidgetPart _nested_cust_currency_widgets[] = {
3170 NWidget(NWID_HORIZONTAL),
3171 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
3172 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
3173 EndContainer(),
3174 NWidget(WWT_PANEL, COLOUR_GREY),
3175 NWidget(NWID_VERTICAL), SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0), SetPadding(WidgetDimensions::unscaled.sparse),
3176 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(0, WidgetDimensions::unscaled.vsep_normal, 0),
3177 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
3178 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
3179 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
3180 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
3181 EndContainer(),
3182 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
3183 EndContainer(),
3184 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
3185 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
3186 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
3187 EndContainer(),
3188 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
3189 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
3190 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
3191 EndContainer(),
3192 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
3193 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
3194 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
3195 EndContainer(),
3196 NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_wide, 0),
3197 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE),
3198 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
3199 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
3200 EndContainer(),
3201 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING1, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
3202 EndContainer(),
3203 EndContainer(),
3204 NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
3205 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP),
3206 EndContainer(),
3207 EndContainer(),
3210 static WindowDesc _cust_currency_desc(
3211 WDP_CENTER, nullptr, 0, 0,
3212 WC_CUSTOM_CURRENCY, WC_NONE,
3214 _nested_cust_currency_widgets
3217 /** Open custom currency window. */
3218 static void ShowCustCurrency()
3220 CloseWindowById(WC_CUSTOM_CURRENCY, 0);
3221 new CustomCurrencyWindow(_cust_currency_desc);