OpenTTD Source 20261112-master-gbcbec5e63f
settings_gui.cpp
Go to the documentation of this file.
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 <https://www.gnu.org/licenses/old-licenses/gpl-2.0>.
6 */
7
9
10#include "stdafx.h"
11#include "currency_func.h"
12#include "error.h"
13#include "settings_gui.h"
14#include "textbuf_gui.h"
15#include "network/network.h"
17#include "settings_internal.h"
18#include "strings_func.h"
19#include "window_func.h"
20#include "dropdown_type.h"
21#include "dropdown_func.h"
22#include "slider_func.h"
23#include "base_media_graphics.h"
24#include "base_media_music.h"
25#include "base_media_sounds.h"
26#include "viewport_func.h"
27#include "core/backup_type.hpp"
29#include "language.h"
30#include "textfile_gui.h"
31#include "stringfilter_type.h"
32#include "querystring_gui.h"
33#include "fontcache.h"
34#include "rev.h"
37#include "gui.h"
38#include "mixer.h"
39#include "newgrf_config.h"
40#include "network/core/config.h"
41#include "network/network_gui.h"
44#include "social_integration.h"
45#include "sound_func.h"
46#include "settingentry_gui.h"
48
50#include "widgets/misc_widget.h"
51
52#include "table/strings.h"
53
55
56#include "safeguards.h"
57
58
59#if defined(WITH_FREETYPE) || defined(_WIN32) || defined(WITH_COCOA)
60# define HAS_TRUETYPE_FONT
61#endif
62
63static const StringID _autosave_dropdown[] = {
64 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
65 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_10_MINUTES,
66 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_30_MINUTES,
67 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_60_MINUTES,
68 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_120_MINUTES,
70};
71
73static const uint32_t _autosave_dropdown_to_minutes[] = {
74 0,
75 10,
76 30,
77 60,
78 120,
79};
80
86{
87 auto it = std::ranges::find(_resolutions, Dimension(_screen.width, _screen.height));
88 return std::distance(_resolutions.begin(), it);
89}
90
91static void ShowCustCurrency();
92
94struct BaseSetTextfileWindow : public TextfileWindow {
95 const std::string name;
97
98 BaseSetTextfileWindow(Window *parent, TextfileType file_type, const std::string &name, const std::string &textfile, StringID content_type) : TextfileWindow(parent, file_type), name(name), content_type(content_type)
99 {
100 this->ConstructWindow();
101 this->LoadTextfile(textfile, Subdirectory::Baseset);
102 }
103
104 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
105 {
106 if (widget == WID_TF_CAPTION) {
107 return GetString(stringid, this->content_type, this->name);
108 }
109
110 return this->Window::GetWidgetString(widget, stringid);
111 }
112};
113
121template <class TBaseSet>
122void ShowBaseSetTextfileWindow(Window *parent, TextfileType file_type, const TBaseSet *baseset, StringID content_type)
123{
124 parent->CloseChildWindowById(WindowClass::Textfile, file_type);
125 new BaseSetTextfileWindow(parent, file_type, baseset->name, *baseset->GetTextfile(file_type), content_type);
126}
127
135template <typename TBaseSet>
136static std::string GetListLabel(const TBaseSet *baseset)
137{
138 if (baseset->GetNumInvalid() == 0) return GetString(STR_JUST_RAW_STRING, baseset->name);
139 return GetString(STR_BASESET_STATUS, baseset->name, baseset->GetNumInvalid());
140}
141
142template <class T>
143DropDownList BuildSetDropDownList(int *selected_index)
144{
145 int n = T::GetNumSets();
146 *selected_index = T::GetIndexOfUsedSet();
147 DropDownList list;
148 for (int i = 0; i < n; i++) {
149 list.push_back(MakeDropDownListStringItem(GetListLabel(T::GetSet(i)), i));
150 }
151 return list;
152}
153
154std::set<int> _refresh_rates = { 30, 60, 75, 90, 100, 120, 144, 240 };
155
161{
162 /* Add the refresh rate as selected in the config. */
163 _refresh_rates.insert(_settings_client.gui.refresh_rate);
164
165 /* Add all the refresh rates of all monitors connected to the machine. */
166 std::vector<int> monitor_rates = VideoDriver::GetInstance()->GetListOfMonitorRefreshRates();
167 std::copy(monitor_rates.begin(), monitor_rates.end(), std::inserter(_refresh_rates, _refresh_rates.end()));
168}
169
170static const int SCALE_NMARKS = (MAX_INTERFACE_SCALE - MIN_INTERFACE_SCALE) / 25 + 1;
171static const int VOLUME_NMARKS = 9;
172
173static std::optional<std::string> ScaleMarkFunc(int, int, int value)
174{
175 /* Label only every 100% mark. */
176 if (value % 100 != 0) return std::string{};
177
178 return GetString(STR_GAME_OPTIONS_GUI_SCALE_MARK, value / 100, 0);
179}
180
181static std::optional<std::string> VolumeMarkFunc(int, int mark, int value)
182{
183 /* Label only every other mark. */
184 if (mark % 2 != 0) return std::string{};
185
186 /* 0-127 does not map nicely to 0-100. Dividing first gives us nice round numbers. */
187 return GetString(STR_GAME_OPTIONS_VOLUME_MARK, value / 31 * 25);
188}
189
200
201static constexpr std::initializer_list<NWidgetPart> _nested_social_plugins_widgets = {
205 NWidget(WWT_TEXT, Colours::Invalid), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_PLATFORM), SetTextStyle(GAME_OPTIONS_LABEL),
207 EndContainer(),
209 NWidget(WWT_TEXT, Colours::Invalid), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE), SetTextStyle(GAME_OPTIONS_LABEL),
211 EndContainer(),
212 EndContainer(),
213 EndContainer(),
214};
215
216static constexpr std::initializer_list<NWidgetPart> _nested_social_plugins_none_widgets = {
218 NWidget(WWT_TEXT, Colours::Invalid), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_GAME_OPTIONS_SOCIAL_PLUGINS_NONE), SetTextStyle(GAME_OPTIONS_LABEL),
219 EndContainer(),
220};
221
222class NWidgetSocialPlugins : public NWidgetVertical {
223public:
224 NWidgetSocialPlugins() : NWidgetVertical({}, WID_GO_SOCIAL_PLUGINS)
225 {
226 this->plugins = SocialIntegration::GetPlugins();
227
228 if (this->plugins.empty()) {
229 auto widget = MakeNWidgets(_nested_social_plugins_none_widgets, nullptr);
230 this->Add(std::move(widget));
231 } else {
232 for (size_t i = 0; i < this->plugins.size(); i++) {
233 auto widget = MakeNWidgets(_nested_social_plugins_widgets, nullptr);
234 this->Add(std::move(widget));
235 }
236 }
237
238 this->SetPIP(0, WidgetDimensions::unscaled.vsep_wide, 0);
239 }
240
241 void SetupSmallestSize(Window *w) override
242 {
243 this->current_index = -1;
245 }
246
253 template <typename T>
254 std::string &GetWidestPlugin(T SocialIntegrationPlugin::*member) const
255 {
256 std::string *longest = &(this->plugins[0]->*member);
257 int longest_length = 0;
258
259 for (auto *plugin : this->plugins) {
260 int length = GetStringBoundingBox(plugin->*member).width;
261 if (length > longest_length) {
262 longest_length = length;
263 longest = &(plugin->*member);
264 }
265 }
266
267 return *longest;
268 }
269
270 std::string GetWidgetString(WidgetID widget, StringID) const
271 {
272 switch (widget) {
274 /* For SetupSmallestSize, use the longest string we have. */
275 if (this->current_index < 0) {
277 }
278
279 if (this->plugins[this->current_index]->name.empty()) {
280 return this->plugins[this->current_index]->basepath;
281 }
282
283 return GetString(STR_GAME_OPTIONS_SOCIAL_PLUGIN_TITLE, this->plugins[this->current_index]->name, this->plugins[this->current_index]->version);
284
286 /* For SetupSmallestSize, use the longest string we have. */
287 if (this->current_index < 0) {
289 }
290
291 return this->plugins[this->current_index]->social_platform;
292
294 static const std::pair<SocialIntegrationPlugin::State, StringID> state_to_string[] = {
295 { SocialIntegrationPlugin::RUNNING, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_RUNNING },
296 { SocialIntegrationPlugin::FAILED, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_FAILED },
297 { SocialIntegrationPlugin::PLATFORM_NOT_RUNNING, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_PLATFORM_NOT_RUNNING },
298 { SocialIntegrationPlugin::UNLOADED, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_UNLOADED },
299 { SocialIntegrationPlugin::DUPLICATE, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_DUPLICATE },
300 { SocialIntegrationPlugin::UNSUPPORTED_API, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_UNSUPPORTED_API },
301 { SocialIntegrationPlugin::INVALID_SIGNATURE, STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_INVALID_SIGNATURE },
302 };
303
304 /* For SetupSmallestSize, use the longest string we have. */
305 if (this->current_index < 0) {
307
308 /* Set the longest plugin when looking for the longest status. */
309 StringID longest = STR_NULL;
310 int longest_length = 0;
311 for (const auto &[state, string] : state_to_string) {
312 int length = GetStringBoundingBox(GetString(string, longest_plugin)).width;
313 if (length > longest_length) {
314 longest_length = length;
315 longest = string;
316 }
317 }
318
319 return GetString(longest, longest_plugin);
320 }
321
322 const auto plugin = this->plugins[this->current_index];
323
324 /* Find the string for the state. */
325 for (const auto &[state, string] : state_to_string) {
326 if (plugin->state == state) {
327 return GetString(string, plugin->social_platform);
328 }
329 }
330
331 /* Default string, in case no state matches. */
332 return GetString(STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE_FAILED, plugin->social_platform);
333 }
334
335 default: NOT_REACHED();
336 }
337 }
338
339 void Draw(const Window *w) override
340 {
341 this->current_index = 0;
342
343 for (auto &wid : this->children) {
344 wid->Draw(w);
345 this->current_index++;
346 }
347 }
348
349private:
350 int current_index = -1;
351 std::vector<SocialIntegrationPlugin *> plugins{};
352};
353
355std::unique_ptr<NWidgetBase> MakeNWidgetSocialPlugins()
356{
357 return std::make_unique<NWidgetSocialPlugins>();
358}
359
360static const StringID _game_settings_restrict_dropdown[] = {
361 STR_CONFIG_SETTING_RESTRICT_BASIC, // RM_BASIC
362 STR_CONFIG_SETTING_RESTRICT_ADVANCED, // RM_ADVANCED
363 STR_CONFIG_SETTING_RESTRICT_ALL, // RM_ALL
364 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT, // RM_CHANGED_AGAINST_DEFAULT
365 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW, // RM_CHANGED_AGAINST_NEW
366};
367static_assert(lengthof(_game_settings_restrict_dropdown) == RM_END);
368
376
382static void ResetAllSettingsConfirmationCallback(Window *w, bool confirmed)
383{
384 if (confirmed) {
387 w->InvalidateData();
388 }
389}
390
391struct GameOptionsWindow : Window {
392 static inline GameSettings *settings_ptr;
393
398 bool closing_dropdown = false;
399
404 int warn_lines = 0;
405
406 Scrollbar *vscroll;
407 Scrollbar *vscroll_description;
408 static constexpr uint NUM_DESCRIPTION_LINES = 5;
409
410 GameSettings *opt = nullptr;
411 bool reload = false;
412 bool gui_scale_changed = false;
413 int gui_scale = 0;
414 static inline int previous_gui_scale = 0;
415 static inline WidgetID active_tab = WID_GO_TAB_GENERAL;
416
417 GameOptionsWindow(WindowDesc &desc) : Window(desc), filter_editbox(50)
418 {
419 this->opt = &GetGameSettings();
420
422
423 this->filter.mode = (RestrictionMode)_settings_client.gui.settings_restriction_mode;
424 this->filter.min_cat = RM_ALL;
425 this->filter.type = ST_ALL;
426 this->filter.type_hides = false;
427 this->settings_ptr = &GetGameSettings();
428
429 GetSettingsTree().FoldAll(); // Close all sub-pages
430
431 this->CreateNestedTree();
432 this->vscroll = this->GetScrollbar(WID_GO_SCROLLBAR);
433 this->vscroll_description = this->GetScrollbar(WID_GO_HELP_TEXT_SCROLL);
434 this->vscroll_description->SetCapacity(NUM_DESCRIPTION_LINES);
436
437 this->querystrings[WID_GO_FILTER] = &this->filter_editbox;
438 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
439
440 this->OnInvalidateData(0);
441
442 this->SetTab(GameOptionsWindow::active_tab);
443
445 }
446
454
455 void Close([[maybe_unused]] int data = 0) override
456 {
457 CloseWindowById(WindowClass::CustomCurrenty, 0);
458 if (this->reload) _switch_mode = SwitchMode::Menu;
459 this->Window::Close();
460 }
461
468 DropDownList BuildDropDownList(WidgetID widget, int *selected_index) const
469 {
470 DropDownList list;
471 switch (widget) {
472 case WID_GO_CURRENCY_DROPDOWN: { // Setup currencies dropdown
473 *selected_index = to_underlying(this->opt->locale.currency);
474 Currencies disabled = _game_mode == GameMode::Menu ? Currencies{} : GetMaskOfAllowedCurrencies().Flip();
475
476 /* Add non-custom currencies; sorted naturally */
477 for (Currency i : EnumRange(Currency::End)) {
478 if (i == Currency::Custom) continue;
479 CurrencySpec &currency = _currency_specs[i];
480 if (currency.code.empty()) {
481 list.push_back(MakeDropDownListStringItem(currency.name, i, disabled.Test(i)));
482 } else {
483 list.push_back(MakeDropDownListStringItem(GetString(STR_GAME_OPTIONS_CURRENCY_CODE, currency.name, currency.code), i, disabled.Test(i)));
484 }
485 }
486 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
487
488 /* Append custom currency at the end */
489 list.push_back(MakeDropDownListDividerItem()); // separator line
490 list.push_back(MakeDropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, Currency::Custom, disabled.Test(Currency::Custom)));
491 break;
492 }
493
494 case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
495 int index = 0;
496 for (auto &minutes : _autosave_dropdown_to_minutes) {
497 index++;
498 if (_settings_client.gui.autosave_interval <= minutes) break;
499 }
500 *selected_index = index - 1;
501
502 const StringID *items = _autosave_dropdown;
503 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
504 list.push_back(MakeDropDownListStringItem(*items, i));
505 }
506 break;
507 }
508
509 case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
510 for (uint i = 0; i < _languages.size(); i++) {
511 bool hide_language = IsReleasedVersion() && !_languages[i].IsReasonablyFinished();
512 if (hide_language) continue;
513 bool hide_percentage = IsReleasedVersion() || _languages[i].missing < _settings_client.gui.missing_strings_threshold;
514 std::string name;
515 if (&_languages[i] == _current_language) {
516 *selected_index = i;
517 name = _languages[i].own_name;
518 } else {
519 /* Especially with sprite-fonts, not all localized
520 * names can be rendered. So instead, we use the
521 * international names for anything but the current
522 * selected language. This avoids showing a few ????
523 * entries in the dropdown list. */
524 name = _languages[i].name;
525 }
526 if (hide_percentage) {
527 list.push_back(MakeDropDownListStringItem(std::move(name), i));
528 } else {
529 int percentage = (LANGUAGE_TOTAL_STRINGS - _languages[i].missing) * 100 / LANGUAGE_TOTAL_STRINGS;
530 list.push_back(MakeDropDownListStringItem(GetString(STR_GAME_OPTIONS_LANGUAGE_PERCENTAGE, std::move(name), percentage), i));
531 }
532 }
533 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
534 break;
535 }
536
537 case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
538 if (_resolutions.empty()) break;
539
540 *selected_index = GetCurrentResolutionIndex();
541 for (uint i = 0; i < _resolutions.size(); i++) {
542 list.push_back(MakeDropDownListStringItem(GetString(STR_GAME_OPTIONS_RESOLUTION_ITEM, _resolutions[i].width, _resolutions[i].height), i));
543 }
544 break;
545
546 case WID_GO_REFRESH_RATE_DROPDOWN: // Setup refresh rate dropdown
547 for (auto it = _refresh_rates.begin(); it != _refresh_rates.end(); it++) {
548 auto i = std::distance(_refresh_rates.begin(), it);
549 if (*it == _settings_client.gui.refresh_rate) *selected_index = i;
550 list.push_back(MakeDropDownListStringItem(GetString(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, *it), i));
551 }
552 break;
553
555 list = BuildSetDropDownList<BaseGraphics>(selected_index);
556 break;
557
559 list = BuildSetDropDownList<BaseSounds>(selected_index);
560 break;
561
563 list = BuildSetDropDownList<BaseMusic>(selected_index);
564 break;
565
567 for (RestrictionMode mode : EnumRange(RM_END)) {
568 /* If we are in adv. settings screen for the new game's settings,
569 * we don't want to allow comparing with new game's settings. */
570 bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame;
571
572 list.push_back(MakeDropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled));
573 }
574 break;
575
577 list.push_back(MakeDropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL));
578 list.push_back(MakeDropDownListStringItem(_game_mode == GameMode::Menu ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME));
579 list.push_back(MakeDropDownListStringItem(_game_mode == GameMode::Menu ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY));
580 list.push_back(MakeDropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT));
581 break;
582 }
583
584 return list;
585 }
586
587 std::string GetToggleString(StringID stringid, WidgetID state_widget) const
588 {
589 return GetString(STR_GAME_OPTIONS_SETTING, stringid, this->IsWidgetLowered(state_widget) ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
590 }
591
592 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
593 {
594 switch (widget) {
596 const CurrencySpec &currency = _currency_specs[this->opt->locale.currency];
597 if (currency.code.empty()) return GetString(currency.name);
598 return GetString(STR_GAME_OPTIONS_CURRENCY_CODE, currency.name, currency.code);
599 }
600
602 int index = 0;
603 for (auto &minutes : _autosave_dropdown_to_minutes) {
604 index++;
605 if (_settings_client.gui.autosave_interval <= minutes) break;
606 }
607 return GetString(_autosave_dropdown[index - 1]);
608 }
609
610 case WID_GO_LANG_DROPDOWN: return _current_language->own_name;
614 case WID_GO_REFRESH_RATE_DROPDOWN: return GetString(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, _settings_client.gui.refresh_rate);
616 auto current_resolution = GetCurrentResolutionIndex();
617
618 if (current_resolution == _resolutions.size()) {
619 return GetString(STR_GAME_OPTIONS_RESOLUTION_OTHER);
620 }
621 return GetString(STR_GAME_OPTIONS_RESOLUTION_ITEM, _resolutions[current_resolution].width, _resolutions[current_resolution].height);
622 }
623
628 assert(plugin != nullptr);
629
630 return plugin->GetWidgetString(widget, stringid);
631 }
632
634 return GetString(_game_settings_restrict_dropdown[this->filter.mode]);
635
637 switch (this->filter.type) {
638 case ST_GAME: return GetString(_game_mode == GameMode::Menu ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME);
639 case ST_COMPANY: return GetString(_game_mode == GameMode::Menu ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME);
640 case ST_CLIENT: return GetString(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT);
641 default: return GetString(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL);
642 }
643 break;
644
646 return GetToggleString(STR_GAME_OPTIONS_PARTICIPATE_SURVEY, WID_GO_SURVEY_PARTICIPATE_BUTTON);
647
649 return GetToggleString(STR_GAME_OPTIONS_GUI_SCALE_AUTO, WID_GO_GUI_SCALE_AUTO);
650
652 return GetToggleString(STR_GAME_OPTIONS_GUI_SCALE_BEVELS, WID_GO_GUI_SCALE_BEVEL_BUTTON);
653
655 return GetToggleString(STR_GAME_OPTIONS_GUI_FONT_SPRITE, WID_GO_GUI_FONT_SPRITE);
656
658 return GetToggleString(STR_GAME_OPTIONS_GUI_FONT_AA, WID_GO_GUI_FONT_AA);
659
661 return GetToggleString(STR_GAME_OPTIONS_FULLSCREEN, WID_GO_FULLSCREEN_BUTTON);
662
664 return GetToggleString(STR_GAME_OPTIONS_VIDEO_ACCELERATION, WID_GO_VIDEO_ACCEL_BUTTON);
665
667 return GetToggleString(STR_GAME_OPTIONS_VIDEO_VSYNC, WID_GO_VIDEO_VSYNC_BUTTON);
668
669 default:
670 return this->Window::GetWidgetString(widget, stringid);
671 }
672 }
673
674 void DrawWidget(const Rect &r, WidgetID widget) const override
675 {
676 switch (widget) {
679 break;
680
683 break;
684
687 break;
688
689 case WID_GO_GUI_SCALE:
690 DrawSliderWidget(r, GAME_OPTIONS_BACKGROUND, GAME_OPTIONS_BUTTON, TextColour::Black, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, SCALE_NMARKS, this->gui_scale, ScaleMarkFunc, 0, GetMaximumScale());
691 break;
692
694 DrawStringMultiLine(r, GetString(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, std::string{VideoDriver::GetInstance()->GetInfoString()}), GAME_OPTIONS_SELECTED);
695 break;
696
699 break;
700
703 break;
704
705 case WID_GO_OPTIONSPANEL: {
707 tr.top += this->warn_lines * BaseSettingEntry::line_height;
708 uint last_row = this->vscroll->GetPosition() + this->vscroll->GetCapacity() - this->warn_lines;
709 int next_row = GetSettingsTree().Draw(settings_ptr, tr.left, tr.right, tr.top,
710 this->vscroll->GetPosition(), last_row, this->last_clicked);
711 if (next_row == 0) DrawString(tr, STR_CONFIG_SETTINGS_NONE);
712 break;
713 }
714
716 if (this->last_clicked != nullptr) {
717 const IntSettingDesc *sd = this->last_clicked->setting;
718
719 Rect tr = r;
720 std::string str;
721 switch (sd->GetType()) {
722 case ST_COMPANY: str = GetString(STR_CONFIG_SETTING_TYPE, _game_mode == GameMode::Menu ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
723 case ST_CLIENT: str = GetString(STR_CONFIG_SETTING_TYPE, STR_CONFIG_SETTING_TYPE_CLIENT); break;
724 case ST_GAME: str = GetString(STR_CONFIG_SETTING_TYPE, _game_mode == GameMode::Menu ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
725 default: NOT_REACHED();
726 }
727 DrawString(tr, str);
729
730 auto [param1, param2] = sd->GetValueParams(sd->GetDefaultValue());
731 DrawString(tr, GetString(STR_CONFIG_SETTING_DEFAULT_VALUE, param1, param2));
732 }
733 break;
734
735 case WID_GO_HELP_TEXT:
736 if (this->last_clicked != nullptr) {
737 const IntSettingDesc *sd = this->last_clicked->setting;
738
739 DrawPixelInfo tmp_dpi;
740 if (FillDrawPixelInfo(&tmp_dpi, r)) {
741 AutoRestoreBackup dpi_backup(_cur_dpi, &tmp_dpi);
742 int scrolls_pos = this->vscroll_description->GetPosition() * GetCharacterHeight(FontSize::Normal);
743 DrawStringMultiLine(0, r.Width() - 1, -scrolls_pos, r.Height() - 1, sd->GetHelp(), TextColour::White);
744 }
745 }
746 break;
747
748 default:
749 break;
750 }
751 }
752
758 {
759 if (this->last_clicked != pe) this->SetDirty();
760 this->last_clicked = pe;
761 UpdateHelpTextSize();
762 }
763
764 void UpdateHelpTextSize()
765 {
767 this->vscroll_description->SetCount(this->last_clicked ? CeilDiv(this->last_clicked->GetMaxHelpHeight(wid->current_x), GetCharacterHeight(FontSize::Normal)) : 0);
768 }
769
770 void SetTab(WidgetID widget)
771 {
773 this->LowerWidget(widget);
774 GameOptionsWindow::active_tab = widget;
775
776 int plane;
777 switch (widget) {
778 case WID_GO_TAB_GENERAL: plane = 0; break;
779 case WID_GO_TAB_GRAPHICS: plane = 1; break;
780 case WID_GO_TAB_SOUND: plane = 2; break;
781 case WID_GO_TAB_SOCIAL: plane = 3; break;
782 case WID_GO_TAB_ADVANCED: plane = 4; break;
783 default: NOT_REACHED();
784 }
785
786 this->GetWidget<NWidgetStacked>(WID_GO_TAB_SELECTION)->SetDisplayedPlane(plane);
788 this->SetDirty();
789 }
790
791 void OnResize() override
792 {
793 this->vscroll->SetCapacityFromWidget(this, WID_GO_OPTIONSPANEL, WidgetDimensions::scaled.framerect.Vertical());
794 UpdateHelpTextSize();
795
796 bool changed = false;
797
799 int y = 0;
800 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
801 std::string str = GetString(STR_JUST_RAW_STRING, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
802 y = std::max(y, GetStringHeight(str, wid->current_x));
803 }
804 changed |= wid->UpdateVerticalSize(y);
805
807 y = 0;
808 for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
809 std::string str = GetString(STR_JUST_RAW_STRING, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
810 y = std::max(y, GetStringHeight(str, wid->current_x));
811 }
812 changed |= wid->UpdateVerticalSize(y);
813
815 y = 0;
816 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
817 std::string str = GetString(STR_JUST_RAW_STRING, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
818 y = std::max(y, GetStringHeight(str, wid->current_x));
819 }
820 changed |= wid->UpdateVerticalSize(y);
821
823 std::string str = GetString(STR_GAME_OPTIONS_VIDEO_DRIVER_INFO, std::string{VideoDriver::GetInstance()->GetInfoString()});
824 y = GetStringHeight(str, wid->current_x);
825 changed |= wid->UpdateVerticalSize(y);
826
827 if (changed) this->ReInit(0, 0, this->flags.Test(WindowFlag::Centred));
828 }
829
830 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
831 {
832 switch (widget) {
835 Dimension d = maxdim(GetStringBoundingBox(STR_GAME_OPTIONS_SFX_VOLUME), GetStringBoundingBox(STR_GAME_OPTIONS_MUSIC_VOLUME));
836 d.width += padding.width;
837 d.height += padding.height;
838 size = maxdim(size, d);
839 break;
840 }
841
850 int selected;
851 size.width = std::max(size.width, GetDropDownListDimension(this->BuildDropDownList(widget, &selected)).width + padding.width);
852 break;
853 }
854
856 fill.height = resize.height = BaseSettingEntry::line_height;
857 resize.width = 1;
858
859 size.height = 8 * resize.height + WidgetDimensions::scaled.framerect.Vertical();
860 break;
861
863 static const StringID setting_types[] = {
864 STR_CONFIG_SETTING_TYPE_CLIENT,
865 STR_CONFIG_SETTING_TYPE_COMPANY_MENU, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME,
866 STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
867 };
868 for (const auto &setting_type : setting_types) {
869 size.width = std::max(size.width, GetStringBoundingBox(GetString(STR_CONFIG_SETTING_TYPE, setting_type)).width + padding.width);
870 }
872 break;
873 }
874
875 case WID_GO_HELP_TEXT:
876 size.height = NUM_DESCRIPTION_LINES * GetCharacterHeight(FontSize::Normal);
877 break;
878
881 size.width = std::max(GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_CATEGORY).width, GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_TYPE).width);
882 break;
883
884 default:
885 break;
886 }
887 }
888
889 void OnPaint() override
890 {
891 if (GameOptionsWindow::active_tab != WID_GO_TAB_ADVANCED) {
892 this->DrawWidgets();
893 return;
894 }
895
896 if (this->closing_dropdown) {
897 this->closing_dropdown = false;
898 assert(this->valuedropdown_entry != nullptr);
899 this->valuedropdown_entry->SetButtons({});
900 this->valuedropdown_entry = nullptr;
901 }
902
903 /* Reserve the correct number of lines for the 'some search results are hidden' notice in the central settings display panel. */
904 const Rect panel = this->GetWidget<NWidgetBase>(WID_GO_OPTIONSPANEL)->GetCurrentRect().Shrink(WidgetDimensions::scaled.frametext);
905 StringID warn_str = STR_CONFIG_SETTING_CATEGORY_HIDES - 1 + this->warn_missing;
906 int new_warn_lines;
907 if (this->warn_missing == WHR_NONE) {
908 new_warn_lines = 0;
909 } else {
910 new_warn_lines = GetStringLineCount(GetString(warn_str, _game_settings_restrict_dropdown[this->filter.min_cat]), panel.Width());
911 }
912 if (this->warn_lines != new_warn_lines) {
913 this->vscroll->SetCount(this->vscroll->GetCount() - this->warn_lines + new_warn_lines);
914 this->warn_lines = new_warn_lines;
915 }
916
917 this->DrawWidgets();
918
919 /* Draw the 'some search results are hidden' notice. */
920 if (this->warn_missing != WHR_NONE) {
922 GetString(warn_str, _game_settings_restrict_dropdown[this->filter.min_cat]),
923 TextColour::Black, {AlignmentH::Centre, AlignmentV::Middle});
924 }
925 }
926
927 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
928 {
930 if (BaseGraphics::GetUsedSet() == nullptr) return;
931
932 ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
933 return;
934 }
936 if (BaseSounds::GetUsedSet() == nullptr) return;
937
938 ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
939 return;
940 }
942 if (BaseMusic::GetUsedSet() == nullptr) return;
943
944 ShowBaseSetTextfileWindow(this, (TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
945 return;
946 }
947 switch (widget) {
950 case WID_GO_TAB_SOUND:
953 SndClickBeep();
954 this->SetTab(widget);
955 break;
956
958 switch (_settings_client.network.participate_survey) {
959 case ParticipateSurvey::Ask:
960 case ParticipateSurvey::No:
961 _settings_client.network.participate_survey = ParticipateSurvey::Yes;
962 break;
963
964 case ParticipateSurvey::Yes:
965 _settings_client.network.participate_survey = ParticipateSurvey::No;
966 break;
967 }
968
969 this->SetWidgetLoweredState(WID_GO_SURVEY_PARTICIPATE_BUTTON, _settings_client.network.participate_survey == ParticipateSurvey::Yes);
972 break;
973
975 OpenBrowser(NETWORK_SURVEY_DETAILS_LINK);
976 break;
977
980 break;
981
982 case WID_GO_FULLSCREEN_BUTTON: // Click fullscreen on/off
983 /* try to toggle full-screen on/off */
984 if (!ToggleFullScreen(!_fullscreen)) {
985 ShowErrorMessage(GetEncodedString(STR_ERROR_FULLSCREEN_FAILED), {}, WarningLevel::Error);
986 }
990 break;
991
994 ShowErrorMessage(GetEncodedString(STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART), {}, WarningLevel::Info);
998#ifndef __APPLE__
1003#endif
1004 break;
1005
1007 if (!_video_hw_accel) break;
1008
1011
1017 break;
1018
1020 _settings_client.gui.scale_bevels = !_settings_client.gui.scale_bevels;
1021
1023 this->SetDirty();
1024
1026 ReInitAllWindows(true);
1027 break;
1028 }
1029
1030#ifdef HAS_TRUETYPE_FONT
1032 _fcsettings.prefer_sprite = !_fcsettings.prefer_sprite;
1033
1034 this->SetWidgetLoweredState(WID_GO_GUI_FONT_SPRITE, _fcsettings.prefer_sprite);
1035 this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
1036 this->SetDirty();
1037
1043 ReInitAllWindows(true);
1044 break;
1045
1046 case WID_GO_GUI_FONT_AA:
1047 _fcsettings.global_aa = !_fcsettings.global_aa;
1048
1049 this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
1051
1053 break;
1054#endif /* HAS_TRUETYPE_FONT */
1055
1056 case WID_GO_GUI_SCALE:
1057 /* Any click on the slider deactivates automatic interface scaling, setting it to the current value before being adjusted. */
1058 if (_gui_scale_cfg == -1) {
1059 _gui_scale_cfg = this->gui_scale;
1063 }
1064
1065 if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, MIN_INTERFACE_SCALE, MAX_INTERFACE_SCALE, IsCtrlPressed() ? 0 : SCALE_NMARKS, this->gui_scale)) {
1066 int max_scale = GetMaximumScale();
1067 if (this->gui_scale > max_scale) this->gui_scale = max_scale;
1068 this->gui_scale_changed = true;
1069 this->SetWidgetDirty(widget);
1070 }
1071
1072 if (click_count > 0) this->mouse_capture_widget = widget;
1073 break;
1074
1076 {
1077 if (_gui_scale_cfg == -1) {
1078 _gui_scale_cfg = this->previous_gui_scale; // Load the previous GUI scale
1080 if (AdjustGUIZoom(false)) ReInitAllWindows(true);
1081 this->gui_scale = _gui_scale;
1082 } else {
1083 this->previous_gui_scale = _gui_scale; // Set the previous GUI scale value as the current one
1084 _gui_scale_cfg = -1;
1086 if (AdjustGUIZoom(false)) ReInitAllWindows(true);
1087 this->gui_scale = _gui_scale;
1088 }
1089 this->SetWidgetDirty(widget);
1091 break;
1092 }
1093
1095 auto *used_set = BaseGraphics::GetUsedSet();
1096 if (used_set == nullptr || !used_set->IsConfigurable()) break;
1097 GRFConfig &extra_cfg = used_set->GetOrCreateExtraConfig();
1098 if (extra_cfg.param.empty()) extra_cfg.SetParameterDefaults();
1099 OpenGRFParameterWindow(true, extra_cfg, _game_mode == GameMode::Menu);
1100 if (_game_mode == GameMode::Menu) this->reload = true;
1101 break;
1102 }
1103
1106 uint8_t &vol = (widget == WID_GO_BASE_MUSIC_VOLUME) ? _settings_client.music.music_vol : _settings_client.music.effect_vol;
1107 if (ClickSliderWidget(this->GetWidget<NWidgetBase>(widget)->GetCurrentRect(), pt, 0, INT8_MAX, 0, vol)) {
1108 if (widget == WID_GO_BASE_MUSIC_VOLUME) {
1110 } else {
1111 SetEffectVolume(vol);
1112 }
1113 this->SetWidgetDirty(widget);
1114 SetWindowClassesDirty(WindowClass::Music);
1115 }
1116
1117 if (click_count > 0) this->mouse_capture_widget = widget;
1118 break;
1119 }
1120
1122 ShowMusicWindow();
1123 break;
1124 }
1125
1127 if (BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->url.empty()) return;
1128 OpenBrowser(BaseGraphics::GetUsedSet()->url);
1129 break;
1130
1132 if (BaseSounds::GetUsedSet() == nullptr || BaseSounds::GetUsedSet()->url.empty()) return;
1133 OpenBrowser(BaseSounds::GetUsedSet()->url);
1134 break;
1135
1137 if (BaseMusic::GetUsedSet() == nullptr || BaseMusic::GetUsedSet()->url.empty()) return;
1138 OpenBrowser(BaseMusic::GetUsedSet()->url);
1139 break;
1140
1143 break;
1144
1147 break;
1148
1151 break;
1152
1156 int selected;
1157 DropDownList list = this->BuildDropDownList(widget, &selected);
1158 if (!list.empty()) {
1159 ShowDropDownList(this, std::move(list), selected, widget);
1160 } else {
1161 if (widget == WID_GO_RESOLUTION_DROPDOWN) ShowErrorMessage(GetEncodedString(STR_ERROR_RESOLUTION_LIST_FAILED), {}, WarningLevel::Error);
1162 }
1163 break;
1164 }
1165
1171 int selected;
1172 DropDownList list = this->BuildDropDownList(widget, &selected);
1173 if (!list.empty()) {
1174 ShowDropDownList(this, std::move(list), selected, widget, 0, DropDownOption::Filterable);
1175 } else {
1176 if (widget == WID_GO_RESOLUTION_DROPDOWN) ShowErrorMessage(GetEncodedString(STR_ERROR_RESOLUTION_LIST_FAILED), {}, WarningLevel::Error);
1177 }
1178 break;
1179 }
1180
1181 case WID_GO_EXPAND_ALL:
1182 this->manually_changed_folding = true;
1184 this->InvalidateData();
1185 break;
1186
1188 this->manually_changed_folding = true;
1190 this->InvalidateData();
1191 break;
1192
1193 case WID_GO_RESET_ALL:
1194 ShowQuery(
1195 GetEncodedString(STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_CAPTION),
1196 GetEncodedString(STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_TEXT),
1197 this,
1199 );
1200 break;
1201
1203 int selected;
1204 DropDownList list = this->BuildDropDownList(widget, &selected);
1205 if (!list.empty()) {
1206 ShowDropDownList(this, std::move(list), this->filter.mode, widget);
1207 }
1208 break;
1209 }
1210
1211 case WID_GO_TYPE_DROPDOWN: {
1212 int selected;
1213 DropDownList list = this->BuildDropDownList(widget, &selected);
1214 if (!list.empty()) {
1215 ShowDropDownList(this, std::move(list), this->filter.type, widget);
1216 }
1217 break;
1218 }
1219
1221 OptionsPanelClick(pt);
1222 break;
1223 }
1224 }
1225
1226 void OptionsPanelClick(Point pt)
1227 {
1228 int32_t btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GO_OPTIONSPANEL, WidgetDimensions::scaled.framerect.top);
1229 if (btn == INT32_MAX || btn < this->warn_lines) return;
1230 btn -= this->warn_lines;
1231
1232 uint cur_row = 0;
1234
1235 if (clicked_entry == nullptr) return; // Clicked below the last setting of the page
1236
1238 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 - wid->pos_x; // Shift x coordinate
1239 if (x < 0) return; // Clicked left of the entry
1240
1241 SettingsPage *clicked_page = dynamic_cast<SettingsPage*>(clicked_entry);
1242 if (clicked_page != nullptr) {
1243 this->SetDisplayedHelpText(nullptr);
1244 clicked_page->folded = !clicked_page->folded; // Flip 'folded'-ness of the sub-page
1245
1246 this->manually_changed_folding = true;
1247
1248 this->InvalidateData();
1249 return;
1250 }
1251
1252 SettingEntry *pe = dynamic_cast<SettingEntry*>(clicked_entry);
1253 assert(pe != nullptr);
1254 const IntSettingDesc *sd = pe->setting;
1255
1256 /* return if action is only active in network, or only settable by server */
1257 if (!sd->IsEditable()) {
1258 this->SetDisplayedHelpText(pe);
1259 return;
1260 }
1261
1262 auto [min_val, max_val] = sd->GetRange();
1263 int32_t value = sd->Read(ResolveObject(settings_ptr, sd));
1264
1265 /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
1266 if (x < SETTING_BUTTON_WIDTH && sd->flags.Test(SettingFlag::GuiDropdown)) {
1267 this->SetDisplayedHelpText(pe);
1268
1269 if (this->valuedropdown_entry == pe) {
1270 /* unclick the dropdown */
1271 this->CloseChildWindows(WindowClass::DropdownMenu);
1272 this->closing_dropdown = false;
1273 this->valuedropdown_entry->SetButtons({});
1274 this->valuedropdown_entry = nullptr;
1275 } else {
1276 if (this->valuedropdown_entry != nullptr) this->valuedropdown_entry->SetButtons({});
1277 this->closing_dropdown = false;
1278
1279 int rel_y = (pt.y - wid->pos_y - WidgetDimensions::scaled.framerect.top) % wid->resize_y;
1280
1281 Rect wi_rect;
1282 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
1283 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
1284 wi_rect.top = pt.y - rel_y + (BaseSettingEntry::line_height - SETTING_BUTTON_HEIGHT) / 2;
1285 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
1286
1287 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
1288 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
1289 this->valuedropdown_entry = pe;
1291
1292 DropDownList list;
1293 for (int32_t i = min_val; i <= static_cast<int32_t>(max_val); i++) {
1294 auto [param1, param2] = sd->GetValueParams(i);
1295 list.push_back(MakeDropDownListStringItem(GetString(STR_JUST_STRING1, param1, param2), i));
1296 }
1297
1298 ShowDropDownListAt(this, std::move(list), value, WID_GO_SETTING_DROPDOWN, wi_rect, Colours::Orange);
1299 }
1300 }
1301 this->SetDirty();
1302 } else if (x < SETTING_BUTTON_WIDTH) {
1303 this->SetDisplayedHelpText(pe);
1304 int32_t oldvalue = value;
1305
1306 if (sd->IsBoolSetting()) {
1307 value ^= 1;
1308 } else {
1309 /* Add a dynamic step-size to the scroller. In a maximum of
1310 * 50-steps you should be able to get from min to max,
1311 * unless specified otherwise in the 'interval' variable
1312 * of the current setting. */
1313 uint32_t step = (sd->interval == 0) ? ((max_val - min_val) / 50) : sd->interval;
1314 if (step == 0) step = 1;
1315
1316 /* don't allow too fast scrolling */
1317 if (this->flags.Test(WindowFlag::Timeout) && this->timeout_timer > 1) {
1319 return;
1320 }
1321
1322 /* Increase or decrease the value and clamp it to extremes */
1323 if (x >= SETTING_BUTTON_WIDTH / 2) {
1324 value += step;
1325 if (min_val < 0) {
1326 assert(static_cast<int32_t>(max_val) >= 0);
1327 if (value > static_cast<int32_t>(max_val)) value = static_cast<int32_t>(max_val);
1328 } else {
1329 if (static_cast<uint32_t>(value) > max_val) value = static_cast<int32_t>(max_val);
1330 }
1331 if (value < min_val) value = min_val; // skip between "disabled" and minimum
1332 } else {
1333 value -= step;
1334 if (value < min_val) value = sd->flags.Test(SettingFlag::GuiZeroIsSpecial) ? 0 : min_val;
1335 }
1336
1337 /* Set up scroller timeout for numeric values */
1338 if (value != oldvalue) {
1339 if (this->clicked_entry != nullptr) { // Release previous buttons if any
1340 this->clicked_entry->SetButtons({});
1341 }
1342 this->clicked_entry = pe;
1344 this->SetTimeout();
1346 }
1347 }
1348
1349 if (value != oldvalue) {
1350 SetSettingValue(sd, value);
1351 this->SetDirty();
1352 }
1353 } else {
1354 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
1355 if (this->last_clicked == pe && !sd->IsBoolSetting() && !sd->flags.Test(SettingFlag::GuiDropdown)) {
1356 int64_t value64 = value;
1357 /* Show the correct currency-translated value */
1358 if (sd->flags.Test(SettingFlag::GuiCurrency)) value64 *= GetCurrency().rate;
1359
1360 CharSetFilter charset_filter = CS_NUMERAL; //default, only numeric input allowed
1361 if (min_val < 0) charset_filter = CS_NUMERAL_SIGNED; // special case, also allow '-' sign for negative input
1362
1363 this->valuewindow_entry = pe;
1364 /* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */
1365 ShowQueryString(GetString(STR_JUST_INT, value64), STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, charset_filter, QueryStringFlag::EnableDefault);
1366 }
1367 this->SetDisplayedHelpText(pe);
1368 }
1369 }
1370
1371 void OnTimeout() override
1372 {
1373 if (this->clicked_entry != nullptr) { // On timeout, release any depressed buttons
1374 this->clicked_entry->SetButtons({});
1375 this->clicked_entry = nullptr;
1376 this->SetDirty();
1377 }
1378 }
1379
1380 void OnQueryTextFinished(std::optional<std::string> str) override
1381 {
1382 /* The user pressed cancel */
1383 if (!str.has_value()) return;
1384
1385 assert(this->valuewindow_entry != nullptr);
1386 const IntSettingDesc *sd = this->valuewindow_entry->setting;
1387
1388 int32_t value;
1389 if (!str->empty()) {
1390 auto llvalue = ParseInteger<int64_t>(*str, 10, true);
1391 if (!llvalue.has_value()) return;
1392
1393 /* Save the correct currency-translated value */
1394 if (sd->flags.Test(SettingFlag::GuiCurrency)) llvalue = *llvalue / GetCurrency().rate;
1395
1396 value = ClampTo<int32_t>(*llvalue);
1397 } else {
1398 value = sd->GetDefaultValue();
1399 }
1400
1401 SetSettingValue(this->valuewindow_entry->setting, value);
1402 this->SetDirty();
1403 }
1404
1405 void OnMouseLoop() override
1406 {
1407 if (IsLeftButtonDown() || !this->gui_scale_changed) return;
1408
1409 this->gui_scale_changed = false;
1410 _gui_scale_cfg = this->gui_scale;
1411
1412 if (AdjustGUIZoom(false)) {
1413 ReInitAllWindows(true);
1415 this->SetDirty();
1416 }
1417 }
1418
1419 void OnDropdownSelect(WidgetID widget, int index, int) override
1420 {
1421 switch (widget) {
1422 case WID_GO_CURRENCY_DROPDOWN: { // Currency
1423 Currency currency = static_cast<Currency>(index);
1424 if (currency == Currency::Custom) ShowCustCurrency();
1425 this->opt->locale.currency = currency;
1426 ReInitAllWindows(false);
1427 break;
1428 }
1429
1430 case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
1431 _settings_client.gui.autosave_interval = _autosave_dropdown_to_minutes[index];
1433 this->SetDirty();
1434 break;
1435
1436 case WID_GO_LANG_DROPDOWN: // Change interface language
1438 CloseWindowByClass(WindowClass::QueryString);
1440 ClearAllCachedNames();
1442 CheckBlitter();
1443 ReInitAllWindows(true);
1444 break;
1445
1446 case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
1447 if ((uint)index < _resolutions.size() && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
1448 this->SetDirty();
1449 }
1450 break;
1451
1453 _settings_client.gui.refresh_rate = *std::next(_refresh_rates.begin(), index);
1454 if (_settings_client.gui.refresh_rate > 60) {
1455 /* Show warning to the user that this refresh rate might not be suitable on
1456 * larger maps with many NewGRFs and vehicles. */
1457 ShowErrorMessage(GetEncodedString(STR_GAME_OPTIONS_REFRESH_RATE_WARNING), {}, WarningLevel::Info);
1458 }
1459 break;
1460 }
1461
1463 if (_game_mode == GameMode::Menu) {
1464 CloseWindowByClass(WindowClass::NewGRFParameters);
1465 auto set = BaseGraphics::GetSet(index);
1467 this->reload = true;
1468 this->InvalidateData();
1469 }
1470 break;
1471
1473 ChangeSoundSet(index);
1474 break;
1475
1477 ChangeMusicSet(index);
1478 break;
1479
1481 this->filter.mode = (RestrictionMode)index;
1482 if (this->filter.mode == RM_CHANGED_AGAINST_DEFAULT ||
1483 this->filter.mode == RM_CHANGED_AGAINST_NEW) {
1484
1485 if (!this->manually_changed_folding) {
1486 /* Expand all when selecting 'changes'. Update the filter state first, in case it becomes less restrictive in some cases. */
1487 GetSettingsTree().UpdateFilterState(this->filter, false);
1489 }
1490 } else {
1491 /* Non-'changes' filter. Save as default. */
1492 _settings_client.gui.settings_restriction_mode = this->filter.mode;
1493 }
1494 this->InvalidateData();
1495 break;
1496
1498 this->filter.type = (SettingType)index;
1499 this->InvalidateData();
1500 break;
1501
1503 /* Deal with drop down boxes on the panel. */
1504 assert(this->valuedropdown_entry != nullptr);
1505 const IntSettingDesc *sd = this->valuedropdown_entry->setting;
1506 assert(sd->flags.Test(SettingFlag::GuiDropdown));
1507
1508 SetSettingValue(sd, index);
1509 this->SetDirty();
1510 break;
1511 }
1512 }
1513
1514 void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close) override
1515 {
1516 if (widget != WID_GO_SETTING_DROPDOWN) {
1517 /* Normally the default implementation of OnDropdownClose() takes care of
1518 * a few things. We want that behaviour here too, but only for
1519 * "normal" dropdown boxes. The special dropdown boxes added for every
1520 * setting that needs one can't have this call. */
1521 Window::OnDropdownClose(pt, widget, index, click_result, instant_close);
1522 } else {
1523 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
1524 * the same dropdown button was clicked again, and then not open the dropdown again.
1525 * So, we only remember that it was closed, and process it on the next OnPaint, which is
1526 * after OnClick. */
1527 assert(this->valuedropdown_entry != nullptr);
1528 this->closing_dropdown = true;
1529 this->SetDirty();
1530 }
1531 }
1532
1538 void OnInvalidateData([[maybe_unused]] int data = 0, [[maybe_unused]] bool gui_scope = true) override
1539 {
1540 if (!gui_scope) return;
1541 this->SetWidgetLoweredState(WID_GO_SURVEY_PARTICIPATE_BUTTON, _settings_client.network.participate_survey == ParticipateSurvey::Yes);
1545
1546#ifndef __APPLE__
1549#endif
1550
1553#ifdef HAS_TRUETYPE_FONT
1554 this->SetWidgetLoweredState(WID_GO_GUI_FONT_SPRITE, _fcsettings.prefer_sprite);
1555 this->SetWidgetLoweredState(WID_GO_GUI_FONT_AA, _fcsettings.global_aa);
1556 this->SetWidgetDisabledState(WID_GO_GUI_FONT_AA, _fcsettings.prefer_sprite);
1557#endif /* HAS_TRUETYPE_FONT */
1558
1560
1562
1566
1571 }
1572
1574
1575 /* Update which settings are to be visible. */
1576 RestrictionMode min_level = (this->filter.mode <= RM_ALL) ? this->filter.mode : RM_BASIC;
1577 this->filter.min_cat = min_level;
1578 this->filter.type_hides = false;
1579 GetSettingsTree().UpdateFilterState(this->filter, false);
1580
1581 if (this->filter.string.IsEmpty()) {
1582 this->warn_missing = WHR_NONE;
1583 } else if (min_level < this->filter.min_cat) {
1584 this->warn_missing = this->filter.type_hides ? WHR_CATEGORY_TYPE : WHR_CATEGORY;
1585 } else {
1586 this->warn_missing = this->filter.type_hides ? WHR_TYPE : WHR_NONE;
1587 }
1588 this->vscroll->SetCount(GetSettingsTree().Length() + this->warn_lines);
1589
1590 if (this->last_clicked != nullptr && !GetSettingsTree().IsVisible(this->last_clicked)) {
1591 this->SetDisplayedHelpText(nullptr);
1592 }
1593
1594 bool all_folded = true;
1595 bool all_unfolded = true;
1596 GetSettingsTree().GetFoldingState(all_folded, all_unfolded);
1597 this->SetWidgetDisabledState(WID_GO_EXPAND_ALL, all_unfolded);
1599 }
1600
1601 void OnEditboxChanged(WidgetID wid) override
1602 {
1603 if (wid == WID_GO_FILTER) {
1604 this->filter.string.SetFilterTerm(this->filter_editbox.text.GetText());
1605 if (!this->filter.string.IsEmpty() && !this->manually_changed_folding) {
1606 /* User never expanded/collapsed single pages and entered a filter term.
1607 * Expand everything, to save weird expand clicks, */
1609 }
1610 this->InvalidateData();
1611 }
1612 }
1613};
1614
1615static constexpr std::initializer_list<NWidgetPart> _nested_game_options_widgets = {
1618 NWidget(WWT_CAPTION, GAME_OPTIONS_BACKGROUND), SetStringTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
1620 EndContainer(),
1623 NWidget(WWT_TEXTBTN, GAME_OPTIONS_BUTTON, WID_GO_TAB_GENERAL), SetMinimalTextLines(2, 0), SetStringTip(STR_GAME_OPTIONS_TAB_GENERAL, STR_GAME_OPTIONS_TAB_GENERAL_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1624 NWidget(WWT_TEXTBTN, GAME_OPTIONS_BUTTON, WID_GO_TAB_GRAPHICS), SetMinimalTextLines(2, 0), SetStringTip(STR_GAME_OPTIONS_TAB_GRAPHICS, STR_GAME_OPTIONS_TAB_GRAPHICS_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1625 NWidget(WWT_TEXTBTN, GAME_OPTIONS_BUTTON, WID_GO_TAB_SOUND), SetMinimalTextLines(2, 0), SetStringTip(STR_GAME_OPTIONS_TAB_SOUND, STR_GAME_OPTIONS_TAB_SOUND_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1626 NWidget(WWT_TEXTBTN, GAME_OPTIONS_BUTTON, WID_GO_TAB_SOCIAL), SetMinimalTextLines(2, 0), SetStringTip(STR_GAME_OPTIONS_TAB_SOCIAL, STR_GAME_OPTIONS_TAB_SOCIAL_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1627 NWidget(WWT_TEXTBTN, GAME_OPTIONS_BUTTON, WID_GO_TAB_ADVANCED), SetMinimalTextLines(2, 0), SetStringTip(STR_GAME_OPTIONS_TAB_ADVANCED, STR_GAME_OPTIONS_TAB_ADVANCED_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1628 EndContainer(),
1629 EndContainer(),
1632 /* General tab */
1636 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_LANG_DROPDOWN), SetToolTip(STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1637 EndContainer(),
1638
1640 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_AUTOSAVE_DROPDOWN), SetToolTip(STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1641 EndContainer(),
1642
1643 NWidget(WWT_FRAME, GAME_OPTIONS_BACKGROUND), SetStringTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME), SetTextStyle(GAME_OPTIONS_FRAME),
1644 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_CURRENCY_DROPDOWN), SetToolTip(STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1645 EndContainer(),
1646
1648 NWidget(WWT_FRAME, GAME_OPTIONS_BACKGROUND), SetStringTip(STR_GAME_OPTIONS_PARTICIPATE_SURVEY_FRAME), SetTextStyle(GAME_OPTIONS_FRAME), SetPIP(0, WidgetDimensions::unscaled.vsep_sparse, 0),
1652 EndContainer(),
1654 NWidget(WWT_TEXTBTN, GAME_OPTIONS_BUTTON, WID_GO_SURVEY_PREVIEW_BUTTON), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_GAME_OPTIONS_PARTICIPATE_SURVEY_PREVIEW, STR_GAME_OPTIONS_PARTICIPATE_SURVEY_PREVIEW_TOOLTIP),
1655 NWidget(WWT_TEXTBTN, GAME_OPTIONS_BUTTON, WID_GO_SURVEY_LINK_BUTTON), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_GAME_OPTIONS_PARTICIPATE_SURVEY_LINK, STR_GAME_OPTIONS_PARTICIPATE_SURVEY_LINK_TOOLTIP),
1656 EndContainer(),
1657 EndContainer(),
1658 EndContainer(),
1659 EndContainer(),
1660 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 1), // Allows this pane to resize
1661 EndContainer(),
1662
1663 /* Graphics tab */
1669 NWidget(WWT_TEXT, Colours::Invalid), SetStringTip(STR_GAME_OPTIONS_GUI_SCALE_FRAME), SetTextStyle(GAME_OPTIONS_LABEL),
1670 NWidget(WWT_EMPTY, Colours::Invalid, WID_GO_GUI_SCALE), SetMinimalTextLines(1, 12 + WidgetDimensions::unscaled.vsep_normal, FontSize::Small), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_GAME_OPTIONS_GUI_SCALE_TOOLTIP),
1671 EndContainer(),
1675 EndContainer(),
1679 EndContainer(),
1680#ifdef HAS_TRUETYPE_FONT
1684 EndContainer(),
1688 EndContainer(),
1689#endif /* HAS_TRUETYPE_FONT */
1690 EndContainer(),
1691 EndContainer(),
1692
1696 NWidget(WWT_TEXT, Colours::Invalid), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_GAME_OPTIONS_RESOLUTION), SetTextStyle(GAME_OPTIONS_LABEL),
1697 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_RESOLUTION_DROPDOWN), SetFill(1, 0), SetToolTip(STR_GAME_OPTIONS_RESOLUTION_TOOLTIP),
1698 EndContainer(),
1700 NWidget(WWT_TEXT, Colours::Invalid), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_GAME_OPTIONS_REFRESH_RATE), SetTextStyle(GAME_OPTIONS_LABEL),
1701 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_REFRESH_RATE_DROPDOWN), SetFill(1, 0), SetToolTip(STR_GAME_OPTIONS_REFRESH_RATE_TOOLTIP),
1702 EndContainer(),
1706 EndContainer(),
1710 EndContainer(),
1711#ifndef __APPLE__
1715 EndContainer(),
1716#endif
1719 EndContainer(),
1720 EndContainer(),
1721 EndContainer(),
1722
1725 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_DROPDOWN), SetToolTip(STR_GAME_OPTIONS_BASE_GRF_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1727 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_CONTENT_DOWNLOAD), SetStringTip(STR_GAME_OPTIONS_ONLINE_CONTENT, STR_GAME_OPTIONS_ONLINE_CONTENT_TOOLTIP),
1728 EndContainer(),
1729 NWidget(WWT_TEXT, Colours::Invalid, WID_GO_BASE_GRF_DESCRIPTION), SetStringTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1732 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1733 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1734 EndContainer(),
1736 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1737 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_GRF_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1738 EndContainer(),
1739 EndContainer(),
1740 EndContainer(),
1741 EndContainer(),
1742 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 1), // Allows this pane to resize
1743 EndContainer(),
1744
1745 /* Sound/Music tab */
1751 NWidget(WWT_EMPTY, Colours::Invalid, WID_GO_BASE_SFX_VOLUME), SetMinimalTextLines(1, 12 + WidgetDimensions::unscaled.vsep_normal, FontSize::Small), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
1752 EndContainer(),
1755 NWidget(WWT_EMPTY, Colours::Invalid, WID_GO_BASE_MUSIC_VOLUME), SetMinimalTextLines(1, 12 + WidgetDimensions::unscaled.vsep_normal, FontSize::Small), SetFill(1, 0), SetResize(1, 0), SetToolTip(STR_MUSIC_TOOLTIP_DRAG_SLIDERS_TO_SET_MUSIC),
1756 EndContainer(),
1757 EndContainer(),
1758
1761 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_DROPDOWN), SetToolTip(STR_GAME_OPTIONS_BASE_SFX_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1762 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_CONTENT_DOWNLOAD), SetStringTip(STR_GAME_OPTIONS_ONLINE_CONTENT, STR_GAME_OPTIONS_ONLINE_CONTENT_TOOLTIP),
1763 EndContainer(),
1764 NWidget(WWT_EMPTY, Colours::Invalid, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalTextLines(1, 0), SetToolTip(STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1767 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1768 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1769 EndContainer(),
1771 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1772 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_SFX_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1773 EndContainer(),
1774 EndContainer(),
1775 EndContainer(),
1776
1779 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_DROPDOWN), SetToolTip(STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1780 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_CONTENT_DOWNLOAD), SetStringTip(STR_GAME_OPTIONS_ONLINE_CONTENT, STR_GAME_OPTIONS_ONLINE_CONTENT_TOOLTIP),
1781 EndContainer(),
1783 NWidget(WWT_EMPTY, Colours::Invalid, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalTextLines(1, 0), SetToolTip(STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1786 EndContainer(),
1787 EndContainer(),
1790 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_OPEN_URL), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_CONTENT_OPEN_URL, STR_CONTENT_OPEN_URL_TOOLTIP),
1791 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TextfileType::Readme), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_README, STR_TEXTFILE_VIEW_README_TOOLTIP),
1792 EndContainer(),
1794 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TextfileType::Changelog), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_TEXTFILE_VIEW_CHANGELOG_TOOLTIP),
1795 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_BASE_MUSIC_TEXTFILE + TextfileType::License), SetFill(1, 0), SetResize(1, 0), SetStringTip(STR_TEXTFILE_VIEW_LICENCE, STR_TEXTFILE_VIEW_LICENCE_TOOLTIP),
1796 EndContainer(),
1797 EndContainer(),
1798 EndContainer(),
1799 EndContainer(),
1800 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 1), // Allows this pane to resize
1801 EndContainer(),
1802
1803 /* Social tab */
1806 NWidget(NWID_SPACER), SetFill(1, 1), SetResize(1, 1), // Allows this pane to resize
1807 EndContainer(),
1808
1809 /* Advanced settings tab */
1814 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_RESTRICT_DROPDOWN), SetToolTip(STR_CONFIG_SETTING_RESTRICT_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
1815 EndContainer(),
1818 NWidget(WWT_DROPDOWN, GAME_OPTIONS_BUTTON, WID_GO_TYPE_DROPDOWN), SetToolTip(STR_CONFIG_SETTING_TYPE_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
1819 EndContainer(),
1821 NWidget(WWT_TEXT, Colours::Invalid), SetFill(0, 1), SetStringTip(STR_CONFIG_SETTING_FILTER_TITLE), SetTextStyle(GAME_OPTIONS_LABEL),
1822 NWidget(WWT_EDITBOX, GAME_OPTIONS_BACKGROUND, WID_GO_FILTER), SetStringTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP), SetFill(1, 0), SetResize(1, 0),
1823 EndContainer(),
1824 EndContainer(),
1825
1828 EndContainer(),
1830 EndContainer(),
1831
1833 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_EXPAND_ALL), SetStringTip(STR_CONFIG_SETTING_EXPAND_ALL), SetFill(1, 0), SetResize(1, 0),
1834 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_COLLAPSE_ALL), SetStringTip(STR_CONFIG_SETTING_COLLAPSE_ALL), SetFill(1, 0), SetResize(1, 0),
1835 NWidget(WWT_PUSHTXTBTN, GAME_OPTIONS_BUTTON, WID_GO_RESET_ALL), SetStringTip(STR_CONFIG_SETTING_RESET_ALL), SetFill(1, 0), SetResize(1, 0),
1836 EndContainer(),
1837
1842 EndContainer(),
1843 EndContainer(),
1844 EndContainer(),
1845
1847 NWidget(NWID_SPACER), SetFill(1, 0), SetResize(1, 0),
1849 EndContainer(),
1850 EndContainer(),
1851};
1852
1855 WindowPosition::Center, "game_options", 0, 0,
1856 WindowClass::GameOptions, WindowClass::None,
1857 {},
1858 _nested_game_options_widgets
1859);
1860
1863{
1864 CloseWindowByClass(WindowClass::GameOptions);
1866}
1867
1877void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
1878{
1879 PixelColour colour = GetColourGradient(button_colour, Shade::Darker);
1880 Dimension dim = NWidgetScrollbar::GetHorizontalDimension();
1881
1882 Rect lr = {x, y, x + (int)dim.width - 1, y + (int)dim.height - 1};
1883 Rect rr = {x + (int)dim.width, y, x + (int)dim.width * 2 - 1, y + (int)dim.height - 1};
1884
1885 DrawFrameRect(lr, button_colour, (state == 1) ? FrameFlag::Lowered : FrameFlags{});
1886 DrawFrameRect(rr, button_colour, (state == 2) ? FrameFlag::Lowered : FrameFlags{});
1889
1890 /* Grey out the buttons that aren't clickable */
1891 bool rtl = _current_text_dir == TD_RTL;
1892 if (rtl ? !clickable_right : !clickable_left) {
1894 }
1895 if (rtl ? !clickable_left : !clickable_right) {
1897 }
1898}
1899
1909void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_up, bool clickable_down)
1910{
1911 PixelColour colour = GetColourGradient(button_colour, Shade::Darker);
1912
1913 Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
1916
1917 DrawFrameRect(ur, button_colour, (state == 1) ? FrameFlag::Lowered : FrameFlags{});
1918 DrawFrameRect(dr, button_colour, (state == 2) ? FrameFlag::Lowered : FrameFlags{});
1921
1922 /* Grey out the buttons that aren't clickable */
1923 if (!clickable_up) GfxFillRect(ur.Shrink(WidgetDimensions::scaled.bevel), colour, FillRectMode::Checker);
1924 if (!clickable_down) GfxFillRect(dr.Shrink(WidgetDimensions::scaled.bevel), colour, FillRectMode::Checker);
1925}
1926
1935void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
1936{
1937 PixelColour colour = GetColourGradient(button_colour, Shade::Darker);
1938
1939 Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
1940
1941 DrawFrameRect(r, button_colour, state ? FrameFlag::Lowered : FrameFlags{});
1943
1944 if (!clickable) {
1946 }
1947}
1948
1958void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
1959{
1960 Rect r = {x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1};
1962 if (!clickable) {
1964 }
1965
1966 Rect button_rect = r.WithWidth(SETTING_BUTTON_WIDTH / 3, state ^ (_current_text_dir == TD_RTL));
1967 DrawFrameRect(button_rect, button_colour, {});
1968 if (!clickable) {
1970 }
1971}
1972
1973struct CustomCurrencyWindow : Window {
1974 WidgetID query_widget{};
1975
1976 CustomCurrencyWindow(WindowDesc &desc) : Window(desc)
1977 {
1978 this->InitNested();
1979
1980 SetButtonState();
1981 }
1982
1983 void SetButtonState()
1984 {
1986 this->SetWidgetDisabledState(WID_CC_RATE_UP, GetCustomCurrency().rate == UINT16_MAX);
1989 }
1990
1991 std::string GetWidgetString(WidgetID widget, StringID stringid) const override
1992 {
1993 switch (widget) {
1994 case WID_CC_RATE: return GetString(STR_CURRENCY_EXCHANGE_RATE, 1, 1);
1995 case WID_CC_SEPARATOR: return GetString(STR_CURRENCY_SEPARATOR, GetCustomCurrency().separator);
1996 case WID_CC_PREFIX: return GetString(STR_CURRENCY_PREFIX, GetCustomCurrency().prefix);
1997 case WID_CC_SUFFIX: return GetString(STR_CURRENCY_SUFFIX, GetCustomCurrency().suffix);
1998 case WID_CC_YEAR:
1999 return GetString((GetCustomCurrency().to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER, GetCustomCurrency().to_euro);
2000
2001 case WID_CC_PREVIEW:
2002 return GetString(STR_CURRENCY_PREVIEW, 10000);
2003
2004 default:
2005 return this->Window::GetWidgetString(widget, stringid);
2006 }
2007 }
2008
2009 void UpdateWidgetSize(WidgetID widget, Dimension &size, [[maybe_unused]] const Dimension &padding, [[maybe_unused]] Dimension &fill, [[maybe_unused]] Dimension &resize) override
2010 {
2011 switch (widget) {
2012 /* Set the appropriate width for the up/down buttons. */
2013 case WID_CC_RATE_DOWN:
2014 case WID_CC_RATE_UP:
2015 case WID_CC_YEAR_DOWN:
2016 case WID_CC_YEAR_UP:
2017 size = maxdim(size, {(uint)SETTING_BUTTON_WIDTH / 2, (uint)SETTING_BUTTON_HEIGHT});
2018 break;
2019
2020 /* Set the appropriate width for the edit buttons. */
2022 case WID_CC_PREFIX_EDIT:
2023 case WID_CC_SUFFIX_EDIT:
2024 size = maxdim(size, {(uint)SETTING_BUTTON_WIDTH, (uint)SETTING_BUTTON_HEIGHT});
2025 break;
2026
2027 /* Make sure the window is wide enough for the widest exchange rate */
2028 case WID_CC_RATE:
2029 size = GetStringBoundingBox(GetString(STR_CURRENCY_EXCHANGE_RATE, 1, INT32_MAX));
2030 break;
2031 }
2032 }
2033
2034 void OnClick([[maybe_unused]] Point pt, WidgetID widget, [[maybe_unused]] int click_count) override
2035 {
2036 int line = 0;
2037 int len = 0;
2038 std::string str;
2040
2041 switch (widget) {
2042 case WID_CC_RATE_DOWN:
2043 if (GetCustomCurrency().rate > 1) GetCustomCurrency().rate--;
2044 if (GetCustomCurrency().rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
2046 break;
2047
2048 case WID_CC_RATE_UP:
2049 if (GetCustomCurrency().rate < UINT16_MAX) GetCustomCurrency().rate++;
2050 if (GetCustomCurrency().rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
2052 break;
2053
2054 case WID_CC_RATE:
2055 str = GetString(STR_JUST_INT, GetCustomCurrency().rate);
2056 len = 5;
2057 line = WID_CC_RATE;
2058 afilter = CS_NUMERAL;
2059 break;
2060
2062 case WID_CC_SEPARATOR:
2064 len = 7;
2065 line = WID_CC_SEPARATOR;
2066 break;
2067
2068 case WID_CC_PREFIX_EDIT:
2069 case WID_CC_PREFIX:
2070 str = GetCustomCurrency().prefix;
2071 len = 15;
2072 line = WID_CC_PREFIX;
2073 break;
2074
2075 case WID_CC_SUFFIX_EDIT:
2076 case WID_CC_SUFFIX:
2077 str = GetCustomCurrency().suffix;
2078 len = 15;
2079 line = WID_CC_SUFFIX;
2080 break;
2081
2082 case WID_CC_YEAR_DOWN:
2086 break;
2087
2088 case WID_CC_YEAR_UP:
2092 break;
2093
2094 case WID_CC_YEAR:
2095 str = GetString(STR_JUST_INT, GetCustomCurrency().to_euro);
2096 len = 7;
2097 line = WID_CC_YEAR;
2098 afilter = CS_NUMERAL;
2099 break;
2100 }
2101
2102 if (len != 0) {
2103 this->query_widget = line;
2104 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, {});
2105 }
2106
2107 this->SetTimeout();
2108 this->SetDirty();
2109 }
2110
2111 void OnQueryTextFinished(std::optional<std::string> str) override
2112 {
2113 if (!str.has_value()) return;
2114
2115 switch (this->query_widget) {
2116 case WID_CC_RATE: {
2117 auto val = ParseInteger(*str, 10, true);
2118 if (!val.has_value()) return;
2119 GetCustomCurrency().rate = Clamp(*val, 1, UINT16_MAX);
2120 break;
2121 }
2122
2123 case WID_CC_SEPARATOR: // Thousands separator
2124 GetCustomCurrency().separator = std::move(*str);
2125 break;
2126
2127 case WID_CC_PREFIX:
2128 GetCustomCurrency().prefix = std::move(*str);
2129 break;
2130
2131 case WID_CC_SUFFIX:
2132 GetCustomCurrency().suffix = std::move(*str);
2133 break;
2134
2135 case WID_CC_YEAR: { // Year to switch to euro
2137 if (!str->empty()) {
2138 auto val = ParseInteger(*str, 10, true);
2139 if (!val.has_value()) return;
2141 }
2142 GetCustomCurrency().to_euro = year;
2143 break;
2144 }
2145 }
2147 SetButtonState();
2148 }
2149
2150 void OnTimeout() override
2151 {
2152 this->SetDirty();
2153 }
2154};
2155
2156static constexpr std::initializer_list<NWidgetPart> _nested_cust_currency_widgets = {
2159 NWidget(WWT_CAPTION, Colours::Grey), SetStringTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2160 EndContainer(),
2168 EndContainer(),
2169 NWidget(WWT_TEXT, Colours::Invalid, WID_CC_RATE), SetToolTip(STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
2170 EndContainer(),
2172 NWidget(WWT_PUSHBTN, Colours::DarkBlue, WID_CC_SEPARATOR_EDIT), SetToolTip(STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
2173 NWidget(WWT_TEXT, Colours::Invalid, WID_CC_SEPARATOR), SetToolTip(STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
2174 EndContainer(),
2176 NWidget(WWT_PUSHBTN, Colours::DarkBlue, WID_CC_PREFIX_EDIT), SetToolTip(STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
2177 NWidget(WWT_TEXT, Colours::Invalid, WID_CC_PREFIX), SetToolTip(STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
2178 EndContainer(),
2180 NWidget(WWT_PUSHBTN, Colours::DarkBlue, WID_CC_SUFFIX_EDIT), SetToolTip(STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
2181 NWidget(WWT_TEXT, Colours::Invalid, WID_CC_SUFFIX), SetToolTip(STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
2182 EndContainer(),
2185 NWidget(WWT_PUSHARROWBTN, Colours::Yellow, WID_CC_YEAR_DOWN), SetArrowWidgetTypeTip(ArrowWidgetType::Decrease, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
2186 NWidget(WWT_PUSHARROWBTN, Colours::Yellow, WID_CC_YEAR_UP), SetArrowWidgetTypeTip(ArrowWidgetType::Increase, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
2187 EndContainer(),
2188 NWidget(WWT_TEXT, Colours::Invalid, WID_CC_YEAR), SetToolTip(STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
2189 EndContainer(),
2190 EndContainer(),
2192 SetToolTip(STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP),
2193 EndContainer(),
2194 EndContainer(),
2195};
2196
2199 WindowPosition::Center, {}, 0, 0,
2200 WindowClass::CustomCurrenty, WindowClass::None,
2201 {},
2202 _nested_cust_currency_widgets
2203);
2204
2206static void ShowCustCurrency()
2207{
2208 CloseWindowById(WindowClass::CustomCurrenty, 0);
2210}
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Class for backupping variables and making sure they are restored later.
Generic functions for replacing base graphics data.
Generic functions for replacing base music data.
Generic functions for replacing base sounds data.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Flip()
Flip all bits.
constexpr Timpl & Reset()
Reset all bits.
static const GraphicsSet * GetUsedSet()
static const GraphicsSet * GetSet(int index)
static bool SetSet(const GraphicsSet *set)
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Iterate a range of enum values.
static void ClearFontCaches(FontSizes fontsizes)
Clear cached information for the specified font caches.
static void LoadFontCaches(FontSizes fontsizes)
(Re)initialize the font cache related things, i.e.
static MusicDriver * GetInstance()
Get the currently active instance of the music driver.
virtual void SetVolume(uint8_t vol)=0
Set the volume, if possible.
Baseclass for nested widgets.
uint current_x
Current horizontal size (after resizing).
int pos_y
Vertical position of top-left corner of the widget in the window.
int pos_x
Horizontal position of top-left corner of the widget in the window.
uint resize_y
Vertical resize step (0 means not resizable).
void Add(std::unique_ptr< NWidgetBase > &&wid)
Append widget wid to container.
Definition widget.cpp:1328
std::vector< std::unique_ptr< NWidgetBase > > children
Child widgets in container.
void SetPIP(uint8_t pip_pre, uint8_t pip_inter, uint8_t pip_post)
Set additional pre/inter/post space for the container.
Definition widget.cpp:1544
Base class for a resizable nested widget.
bool UpdateVerticalSize(uint min_y)
Set absolute (post-scaling) minimal size of the widget.
Definition widget.cpp:1156
void Draw(const Window *w) override
Draw the widgets of the tree.
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
std::string & GetWidestPlugin(T SocialIntegrationPlugin::*member) const
Find of all the plugins the one where the member is the widest (in pixels).
void SetupSmallestSize(Window *w) override
Compute smallest size needed by the widget.
Definition widget.cpp:1760
static constexpr bool IsSurveyPossible()
Check whether a survey is possible.
Scrollbar data structure.
size_type GetCapacity() const
Gets the number of visible elements of the scrollbar.
void SetCount(size_t num)
Sets the number of elements in the list.
void SetCapacity(size_t capacity)
Set the capacity of visible elements.
size_type GetScrolledRowFromWidget(int clickpos, const Window *const w, WidgetID widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition widget.cpp:2474
void SetCapacityFromWidget(Window *w, WidgetID widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition widget.cpp:2548
size_type GetCount() const
Gets the number of elements in the list.
size_type GetPosition() const
Gets the position of the first visible element in the list.
std::string social_platform
Social platform this plugin is for.
std::string name
Name of the plugin.
std::string version
Version of the plugin.
@ PLATFORM_NOT_RUNNING
The plugin failed to initialize because the Social Platform is not running.
@ UNSUPPORTED_API
The plugin does not support the current API version.
@ RUNNING
The plugin is successfully loaded and running.
@ FAILED
The plugin failed to initialize.
@ DUPLICATE
Another plugin of the same Social Platform is already loaded.
@ INVALID_SIGNATURE
The signature of the plugin is invalid.
@ UNLOADED
The plugin is unloaded upon request.
static std::vector< SocialIntegrationPlugin * > GetPlugins()
Get the list of loaded social integration plugins.
static constexpr TimerGame< struct Calendar >::Year MAX_YEAR
StrongType::Typedef< int32_t, struct YearTag< struct Calendar >, StrongType::Compare, StrongType::Integer > Year
virtual std::string_view GetInfoString() const
Get some information about the selected driver/backend to be shown to the user.
virtual void ToggleVsync(bool vsync)
Change the vsync setting.
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
virtual std::vector< int > GetListOfMonitorRefreshRates()
Get a list of refresh rates of each available monitor.
RectPadding framerect
Standard padding inside many panels.
Definition window_gui.h:41
static WidgetDimensions scaled
Widget dimensions scaled for current zoom level.
Definition window_gui.h:30
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:94
Configuration options of the network stuff.
static const std::string NETWORK_SURVEY_DETAILS_LINK
Link with more details & privacy statement of the survey.
Definition config.h:28
Currencies GetMaskOfAllowedCurrencies()
get a mask of the allowed currencies depending on the year
Definition currency.cpp:127
EnumIndexArray< CurrencySpec, Currency, Currency::End > _currency_specs
Array of currencies used by the system.
Definition currency.cpp:79
Functions to handle different currencies.
CurrencySpec & GetCustomCurrency()
Get the custom currency.
const CurrencySpec & GetCurrency()
Get the currently selected currency.
static constexpr TimerGameCalendar::Year MIN_EURO_YEAR
The earliest year custom currencies may switch to the Euro.
Currency
This enum gives the currencies a unique id which must be maintained for savegame compatibility and in...
@ End
Always the last item.
@ Custom
Custom currency.
static constexpr TimerGameCalendar::Year CF_NOEURO
Currency never switches to the Euro (as far as known).
EnumBitSet< Currency, uint64_t, Currency::End > Currencies
Bitmask of Currency.
std::vector< Dimension > _resolutions
List of resolutions.
Definition driver.cpp:28
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, WidgetID button, Rect wi_rect, Colours wi_colour, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:574
std::unique_ptr< DropDownListItem > MakeDropDownListDividerItem()
Creates new DropDownListDividerItem.
Definition dropdown.cpp:36
std::unique_ptr< DropDownListItem > MakeDropDownListStringItem(StringID str, int value, bool masked, bool shaded)
Creates new DropDownListStringItem.
Definition dropdown.cpp:49
Dimension GetDropDownListDimension(const DropDownList &list)
Determine width and height required to fully display a DropDownList.
Definition dropdown.cpp:551
void ShowDropDownList(Window *w, DropDownList &&list, int selected, WidgetID button, uint width, DropDownOptions options, std::string *const persistent_filter_text)
Show a drop down list.
Definition dropdown.cpp:591
Common drop down list components.
Functions related to the drop down widget.
Types related to the drop down widget.
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
@ Filterable
Set if the dropdown is filterable.
#define T
Climate temperate.
Definition engines.h:91
constexpr std::underlying_type_t< enum_type > to_underlying(enum_type e)
Implementation of std::to_underlying (from C++23).
Definition enum_type.hpp:21
Functions related to errors.
@ Info
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition error.h:22
@ Error
Errors (eg. saving/loading failed).
Definition error.h:24
void ShowErrorMessage(EncodedString &&summary_msg, int x, int y, CommandCost &cc)
Display an error message in a window.
@ Baseset
Subdirectory for all base data (base sets, intro game).
Definition fileio_type.h:95
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
Definition fontcache.cpp:88
Functions to read fonts from files and cache them.
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Geometry functions.
@ Centre
Align to the centre.
@ End
Align to the end, LTR/RTL aware.
@ Middle
Align to the middle.
bool DrawStringMultiLineWithClipping(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw a multiline string, possibly over multiple lines, if the region is within the current display cl...
Definition gfx.cpp:867
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition gfx.cpp:711
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition gfx.cpp:966
int GetStringLineCount(std::string_view str, int maxw)
Calculates number of lines of string.
Definition gfx.cpp:735
Dimension GetStringBoundingBox(std::string_view str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition gfx.cpp:894
ControlInputs _input_clicked
Control inputs that have been actioned.
Definition gfx.cpp:35
int _gui_scale_cfg
GUI scale in config.
Definition gfx.cpp:60
int GetMaximumScale()
Get the maximum interface scale.
Definition gfx.cpp:1828
void GfxFillRect(int left, int top, int right, int bottom, const std::variant< PixelColour, PaletteID > &colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition gfx.cpp:111
SwitchMode _switch_mode
The next mainloop command.
Definition gfx.cpp:45
int DrawStringMultiLine(int left, int right, int top, int bottom, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition gfx.cpp:782
int DrawString(int left, int right, int top, std::string_view str, ExtendedTextColour colour, Alignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition gfx.cpp:663
bool FillDrawPixelInfo(DrawPixelInfo *n, int left, int top, int width, int height)
Set up a clipping area for only drawing into a certain area.
Definition gfx.cpp:1567
bool AdjustGUIZoom(bool automatic)
Resolve GUI zoom level and adjust GUI to new zoom, if auto-suggestion is requested.
Definition gfx.cpp:1859
int _gui_scale
GUI scale, 100 is 100%.
Definition gfx.cpp:59
bool IsLeftButtonDown()
Test if the left mouse button is pressed.
Definition gfx_func.h:70
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
Definition gfxinit.cpp:325
bool IsCtrlPressed()
Test if the ctrl key is pressed.
Definition gfx_func.h:82
void DrawSpriteIgnorePadding(SpriteID img, PaletteID pal, const Rect &r, Alignment align)
Draw a sprite within a Rect, ignoring the sprite's padding.
Definition widget.cpp:350
@ Small
Index of the small font in the font tables.
Definition gfx_type.h:250
@ Normal
Index of the normal font in the font tables.
Definition gfx_type.h:249
constexpr FontSizes FONTSIZES_ALL
Mask of all possible font sizes.
Definition gfx_type.h:262
Colours
One of 16 base colours used for companies and windows/widgets.
Definition gfx_type.h:283
@ Mauve
Mauve.
Definition gfx_type.h:295
@ Invalid
Invalid marker.
Definition gfx_type.h:302
@ Yellow
Yellow.
Definition gfx_type.h:288
@ DarkBlue
Dark blue.
Definition gfx_type.h:285
@ Orange
Orange.
Definition gfx_type.h:297
@ Grey
Grey.
Definition gfx_type.h:299
@ Green
Green.
Definition gfx_type.h:291
TextColour
Colour of the strings, see _string_colourmap in table/string_colours.h or docs/ottd-colourtext-palett...
Definition gfx_type.h:315
@ White
White colour.
Definition gfx_type.h:330
@ LightBlue
Light blue colour.
Definition gfx_type.h:331
@ Orange
Orange colour.
Definition gfx_type.h:324
@ Black
Black colour.
Definition gfx_type.h:334
@ Checker
Draw only every second pixel, used for greying-out.
Definition gfx_type.h:393
@ Left
Left mouse button is pressed.
Definition gfx_type.h:444
constexpr NWidgetPart NWidgetFunction(NWidgetFunctionType *func_ptr)
Obtain a nested widget (sub)tree from an external source.
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
constexpr NWidgetPart SetSpriteTip(SpriteID sprite, StringID tip={})
Widget part function for setting the sprite and tooltip.
constexpr NWidgetPart SetResizeWidgetTypeTip(ResizeWidgetType widget_type, StringID tip)
Widget part function for setting the resize widget type and tooltip.
constexpr NWidgetPart SetToolbarMinimalSize(int width)
Widget part function to setting the minimal size for a toolbar button.
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
constexpr NWidgetPart SetScrollbar(WidgetID index)
Attach a scrollbar to a widget.
constexpr NWidgetPart SetPadding(uint8_t top, uint8_t right, uint8_t bottom, uint8_t left)
Widget part function for setting additional space around a widget.
constexpr NWidgetPart SetAlternateColourTip(Colours colour, StringID tip)
Widget part function for setting the alternate colour and tooltip.
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
constexpr NWidgetPart SetMinimalTextLines(uint8_t lines, uint8_t spacing, FontSize size=FontSize::Normal)
Widget part function for setting the minimal text lines.
std::unique_ptr< NWidgetBase > MakeNWidgets(std::span< const NWidgetPart > nwid_parts, std::unique_ptr< NWidgetBase > &&container)
Construct a nested widget tree from an array of parts.
Definition widget.cpp:3431
constexpr NWidgetPart SetToolTip(StringID tip)
Widget part function for setting tooltip and clearing the widget data.
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FontSize::Normal)
Widget part function for setting the text style.
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
constexpr NWidgetPart SetArrowWidgetTypeTip(ArrowWidgetType widget_type, StringID tip={})
Widget part function for setting the arrow widget type and tooltip.
constexpr NWidgetPart SetAlignment(Alignment align)
Widget part function for setting the alignment of text/images.
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
constexpr NWidgetPart SetPIPRatio(uint8_t ratio_pre, uint8_t ratio_inter, uint8_t ratio_post)
Widget part function for setting a pre/inter/post ratio.
void SetDirty() const
Mark entire window as dirty (in need of re-paint).
Definition window.cpp:1013
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition gfx.cpp:1548
GUI functions that shouldn't be here.
Information about languages and their files.
LanguageList _languages
The actual list of language meta data.
Definition strings.cpp:52
const LanguageMetadata * _current_language
The currently loaded language.
Definition strings.cpp:53
bool ReadLanguagePack(const LanguageMetadata *lang)
Read a particular language.
Definition strings.cpp:2050
#define Rect
Macro that prevents name conflicts between included headers.
#define Point
Macro that prevents name conflicts between included headers.
constexpr uint CeilDiv(uint a, uint b)
Computes ceil(a / b) for non-negative a and b.
constexpr T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition math_func.hpp:79
constexpr To ClampTo(From value)
Clamp the given value down to lie within the requested type.
void ShowQuery(EncodedString &&caption, EncodedString &&message, Window *parent, QueryCallbackProc *callback, bool focus)
Show a confirmation window with standard 'yes' and 'no' buttons The window is aligned to the centre o...
void ShowQueryString(std::string_view str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Types related to the misc widgets.
@ WID_TF_CAPTION
The caption of the window.
Definition misc_widget.h:53
Functions to mix sound samples.
Base for all music playback.
void ChangeMusicSet(int index)
Change the configured music set and reset playback.
bool _network_available
is network mode available?
Definition network.cpp:65
Basic functions/variables used all over the place.
Part of the network protocol handling content distribution.
void ShowNetworkContentListWindow(ContentVector *cv=nullptr, ContentType type1=ContentType::End, ContentType type2=ContentType::End)
Show the content list window with a given set of content.
void ShowSurveyResultTextfileWindow(Window *parent)
Show the surver results as a text file.
GUIs related to networking.
Part of the network protocol handling opt-in survey.
@ Length
Vehicle length (trains and road vehicles).
Functions to find and configure NewGRFs.
void ChangeAutosaveFrequency(bool reset)
Reset the interval of the autosave.
Definition openttd.cpp:1300
@ Menu
In the main menu.
Definition openttd.h:19
@ Menu
Switch to game intro menu.
Definition openttd.h:33
PixelColour GetColourGradient(Colours colour, Shade shade)
Get colour gradient palette index.
Definition palette.cpp:393
@ Darker
Darker colour shade.
Base for the GUIs that have an edit box in them.
Declaration of OTTD revision dependent variables.
A number of safeguards to prevent using unsafe methods.
const void * ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd)
Resolve the underlying object where to dynamically load/save a setting to.
SettingsContainer & GetSettingsTree()
Construct settings tree.
Declarations of classes for handling display of individual configuration settings.
RestrictionMode
How the list of advanced settings is filtered.
@ RM_CHANGED_AGAINST_DEFAULT
Show only settings which are different compared to default values.
@ RM_ALL
List all settings regardless of the default/newgame/... values.
@ RM_CHANGED_AGAINST_NEW
Show only settings which are different compared to the user's new game setting values.
@ RM_END
End for iteration.
@ RM_BASIC
Display settings associated to the "basic" list.
@ LeftDepressed
Of a numeric setting entry, the left button is depressed.
@ RightDepressed
Of a numeric setting entry, the right button is depressed.
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition settings.cpp:62
ClientSettings _settings_client
The current settings for this game.
Definition settings.cpp:60
static constexpr TextColour GAME_OPTIONS_LABEL
Colour for label text of game options.
static constexpr Colours GAME_OPTIONS_BACKGROUND
Colour for background of game options.
WarnHiddenResult
Warnings about hidden search results.
@ WHR_CATEGORY_TYPE
Both category and type settings filtered matches away.
@ WHR_CATEGORY
Category setting filtered matches away.
@ WHR_NONE
Nothing was filtering matches away.
@ WHR_TYPE
Type setting filtered matches away.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
static void ResetAllSettingsConfirmationCallback(Window *w, bool confirmed)
Callback function for the reset all settings button.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
void DrawUpDownButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_up, bool clickable_down)
Draw [^][v] buttons.
void ShowBaseSetTextfileWindow(Window *parent, TextfileType file_type, const TBaseSet *baseset, StringID content_type)
Open the BaseSet version of the textfile window.
static WindowDesc _cust_currency_desc(WindowPosition::Center, {}, 0, 0, WindowClass::CustomCurrenty, WindowClass::None, {}, _nested_cust_currency_widgets)
Window definition for the custom currency window.
static const uint32_t _autosave_dropdown_to_minutes[]
Available settings for autosave intervals.
static const int VOLUME_NMARKS
Show 5 values and 4 empty marks.
static std::string GetListLabel(const TBaseSet *baseset)
Get string to use when listing this set in the settings window.
static void AddCustomRefreshRates()
Add the refresh rate from the config and the refresh rates from all the monitors to our list of refre...
static WindowDesc _game_options_desc(WindowPosition::Center, "game_options", 0, 0, WindowClass::GameOptions, WindowClass::None, {}, _nested_game_options_widgets)
Window definition for the game options window.
std::unique_ptr< NWidgetBase > MakeNWidgetSocialPlugins()
Construct nested container widget for managing the list of social plugins.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
static constexpr TextColour GAME_OPTIONS_FRAME
Colour for frame text of game options.
static uint GetCurrentResolutionIndex()
Get index of the current screen resolution.
static constexpr Colours GAME_OPTIONS_BUTTON
Colour for buttons of game options.
static void ShowCustCurrency()
Open custom currency window.
static const int SCALE_NMARKS
Show marks at 25% increments.
static constexpr TextColour GAME_OPTIONS_SELECTED
Colour for selected text of game options.
void ShowGameOptions()
Open the game options window.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Functions and types used internally for the settings configurations.
@ GuiCurrency
The number represents money, so when reading value multiply by exchange rate.
@ GuiZeroIsSpecial
A value of zero is possible and has a custom string (the one after "strval").
@ GuiDropdown
The value represents a limited number of string-options (internally integer) presented as dropdown.
SettingType
Type of settings for filtering.
@ ST_CLIENT
Client setting.
@ ST_ALL
Used in setting filter to match all types.
@ ST_GAME
Game setting.
@ ST_COMPANY
Company setting.
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Types related to the settings widgets.
@ WID_GO_BASE_SFX_OPEN_URL
Open base SFX URL.
@ WID_GO_SETTING_DROPDOWN
Dynamically created dropdown for changing setting value.
@ WID_GO_BASE_MUSIC_DESCRIPTION
Description of selected base music set.
@ WID_GO_BASE_MUSIC_CONTENT_DOWNLOAD
'Get Content' button for base music.
@ WID_GO_RESTRICT_DROPDOWN
The drop down box to restrict the list of settings.
@ WID_GO_RESOLUTION_DROPDOWN
Dropdown for the resolution.
@ WID_GO_COLLAPSE_ALL
Collapse all button.
@ WID_GO_CURRENCY_DROPDOWN
Currency dropdown.
@ WID_GO_BASE_GRF_DESCRIPTION
Description of selected base GRF.
@ WID_GO_BASE_SFX_DESCRIPTION
Description of selected base SFX.
@ WID_GO_GUI_FONT_AA_TEXT
Text for anti-alias toggle.
@ WID_GO_RESET_ALL
Reset all button.
@ WID_GO_GUI_SCALE_BEVEL_BUTTON
Toggle for chunky bevels.
@ WID_GO_GUI_SCALE
GUI Scale slider.
@ WID_GO_BASE_SFX_TEXTFILE
Open base SFX readme, changelog (+1) or license (+2).
@ WID_GO_TAB_ADVANCED
Advanced tab.
@ WID_GO_GUI_FONT_SPRITE
Toggle whether to prefer the sprite font over TTF fonts.
@ WID_GO_GUI_SCALE_AUTO
Autodetect GUI scale button.
@ WID_GO_SOCIAL_PLUGINS
Main widget handling the social plugins.
@ WID_GO_BASE_GRF_CONTENT_DOWNLOAD
'Get Content' button for base GRF.
@ WID_GO_FILTER
Text filter.
@ WID_GO_BASE_GRF_TEXTFILE
Open base GRF readme, changelog (+1) or license (+2).
@ WID_GO_TAB_GENERAL
General tab.
@ WID_GO_VIDEO_VSYNC_TEXT
Text for video vsync toggle.
@ WID_GO_BASE_GRF_DROPDOWN
Use to select a base GRF.
@ WID_GO_BASE_MUSIC_VOLUME
Change music volume.
@ WID_GO_GUI_FONT_SPRITE_TEXT
Text for sprite font toggle.
@ WID_GO_BASE_SFX_VOLUME
Change sound effects volume.
@ WID_GO_BASE_GRF_PARAMETERS
Base GRF parameters.
@ WID_GO_LANG_DROPDOWN
Language dropdown.
@ WID_GO_VIDEO_ACCEL_TEXT
Text for video acceleration toggle.
@ WID_GO_GUI_FONT_AA
Toggle whether to anti-alias fonts.
@ WID_GO_VIDEO_VSYNC_BUTTON
Toggle for video vsync.
@ WID_GO_SURVEY_LINK_BUTTON
Button to open browser to go to the survey website.
@ WID_GO_SURVEY_PARTICIPATE_TEXT
Text for automated survey toggle.
@ WID_GO_OPTIONSPANEL
Panel widget containing the option lists.
@ WID_GO_TAB_SELECTION
Background of the tab selection.
@ WID_GO_SURVEY_PARTICIPATE_BUTTON
Toggle for participating in the automated survey.
@ WID_GO_AUTOSAVE_DROPDOWN
Dropdown to say how often to autosave.
@ WID_GO_TAB_GRAPHICS
Graphics tab.
@ WID_GO_HELP_TEXT_SCROLL
Scrollbar for setting description.
@ WID_GO_SCROLLBAR
Scrollbar.
@ WID_GO_GUI_SCALE_AUTO_TEXT
Text for Autodetect GUI scale.
@ WID_GO_TEXT_MUSIC_VOLUME
Music volume label.
@ WID_GO_GUI_SCALE_BEVEL_TEXT
Text for chunky bevels.
@ WID_GO_BASE_MUSIC_JUKEBOX
Open the jukebox.
@ WID_GO_SOCIAL_PLUGIN_STATE
State of the social plugin.
@ WID_GO_SETTING_PROPERTIES
Information area to display setting type and default value.
@ WID_GO_SURVEY_SEL
Selection to hide survey if no JSON library is compiled in.
@ WID_GO_REFRESH_RATE_DROPDOWN
Dropdown for all available refresh rates.
@ WID_GO_EXPAND_ALL
Expand all button.
@ WID_GO_SOCIAL_PLUGIN_TITLE
Title of the frame of the social plugin.
@ WID_GO_BASE_GRF_OPEN_URL
Open base GRF URL.
@ WID_GO_BASE_MUSIC_TEXTFILE
Open base music readme, changelog (+1) or license (+2).
@ WID_GO_RESTRICT_CATEGORY
Label upfront to the category drop-down box to restrict the list of settings to show.
@ WID_GO_VIDEO_ACCEL_BUTTON
Toggle for video acceleration.
@ WID_GO_TAB_SOCIAL
Social tab.
@ WID_GO_FULLSCREEN_TEXT
Text for toggle fullscreen.
@ WID_GO_HELP_TEXT
Information area to display help text of the selected option.
@ WID_GO_SURVEY_PREVIEW_BUTTON
Button to open a preview window with the survey results.
@ WID_GO_BASE_SFX_CONTENT_DOWNLOAD
'Get Content' button for base SFX.
@ WID_GO_SOCIAL_PLUGIN_PLATFORM
Platform of the social plugin.
@ WID_GO_BASE_MUSIC_DROPDOWN
Use to select a base music set.
@ WID_GO_BASE_MUSIC_OPEN_URL
Open base music URL.
@ WID_GO_TYPE_DROPDOWN
The drop down box to choose client/game/company/all settings.
@ WID_GO_FULLSCREEN_BUTTON
Toggle fullscreen.
@ WID_GO_TAB_SOUND
Sound tab.
@ WID_GO_BASE_SFX_DROPDOWN
Use to select a base SFX.
@ WID_GO_TEXT_SFX_VOLUME
Sound effects volume label.
@ WID_GO_VIDEO_DRIVER_INFO
Label showing details about the current video driver.
@ WID_GO_RESTRICT_TYPE
Label upfront to the type drop-down box to restrict the list of settings to show.
@ WID_CC_YEAR_DOWN
Down button.
@ WID_CC_YEAR
Year of introduction.
@ WID_CC_SUFFIX_EDIT
Suffix edit button.
@ WID_CC_SEPARATOR_EDIT
Separator edit button.
@ WID_CC_RATE_DOWN
Down button.
@ WID_CC_RATE_UP
Up button.
@ WID_CC_PREVIEW
Preview.
@ WID_CC_PREFIX
Current prefix.
@ WID_CC_PREFIX_EDIT
Prefix edit button.
@ WID_CC_SUFFIX
Current suffix.
@ WID_CC_YEAR_UP
Up button.
@ WID_CC_SEPARATOR
Current separator.
@ WID_CC_RATE
Rate of currency.
void DrawSliderWidget(Rect r, Colours wedge_colour, Colours handle_colour, TextColour text_colour, int min_value, int max_value, int nmarks, int value, SliderMarkFunc *mark_func, int soft_min, int soft_max)
Draw a slider widget with knob at given value.
Definition slider.cpp:36
bool ClickSliderWidget(Rect r, Point pt, int min_value, int max_value, int nmarks, int &value)
Handle click on a slider widget to change the value.
Definition slider.cpp:123
Functions related to the horizontal slider widget.
Interface definitions for game to report/respond to social integration.
void SndClickBeep()
Play a beep sound for a click event if enabled in settings.
Definition sound.cpp:252
void ChangeSoundSet(int index)
Change the configured sound set and reset sounds.
Definition sound.cpp:167
Functions related to sound.
static const SpriteID SPR_ARROW_RIGHT
Definition sprites.h:88
static const SpriteID SPR_IMG_MUSIC
Definition sprites.h:1273
static const SpriteID SPR_CIRCLE_FOLDED
(+) icon.
Definition sprites.h:97
static const SpriteID SPR_ARROW_LEFT
Definition sprites.h:87
static const SpriteID SPR_CIRCLE_UNFOLDED
(-) icon.
Definition sprites.h:98
static const SpriteID SPR_ARROW_DOWN
Definition sprites.h:85
static const SpriteID SPR_ARROW_UP
Definition sprites.h:86
Definition of base types and functions in a cross-platform compatible way.
#define lengthof(array)
Return the length of an fixed size array.
Definition stdafx.h:261
Parse strings.
static std::optional< T > ParseInteger(std::string_view arg, int base=10, bool clamp=false)
Change a string into its number representation.
CharSetFilter
Valid filter types for IsValidChar.
Definition string_type.h:24
@ CS_NUMERAL
Only numeric ones.
Definition string_type.h:26
@ CS_NUMERAL_SIGNED
Only numbers and '-' for negative values.
Definition string_type.h:28
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition string_type.h:25
Searching and filtering using a stringterm.
void CheckForMissingGlyphs(FontSizes fontsizes, MissingGlyphSearcher *searcher)
Check whether the currently loaded language pack uses characters that the currently loaded font does ...
Definition strings.cpp:2381
EncodedString GetEncodedString(StringID str)
Encode a string with no parameters into an encoded string.
Definition strings.cpp:89
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
Definition strings.cpp:423
std::string_view GetCurrentLanguageIsoCode()
Get the ISO language code of the currently loaded language.
Definition strings.cpp:2298
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition strings.cpp:55
Functions related to OTTD's strings.
StrongType::Typedef< uint32_t, struct StringIDTag, StrongType::Compare, StrongType::Integer > StringID
Numeric value that represents a string, independent of the selected language.
static constexpr StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames).
@ TD_RTL
Text is written right-to-left by default.
Class to backup a specific variable and restore it upon destruction of this object to prevent stack v...
Window for displaying the textfile of a BaseSet.
const std::string name
Name of the content.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
const StringID content_type
STR_CONTENT_TYPE_xxx for title.
Data structure describing a single setting in a tab.
static Dimension circle_size
Dimension of the circle +/- icon.
static int line_height
Height of a single setting.
uint8_t level
Nesting level of this setting entry.
T y
Y coordinate.
T x
X coordinate.
Specification of a currency.
std::string separator
The thousands separator for this currency.
std::string prefix
Prefix to apply when formatting money in this currency.
TimerGameCalendar::Year to_euro
Year of switching to the Euro. May also be CF_NOEURO or CF_ISEURO.
std::string suffix
Suffix to apply when formatting money in this currency.
std::string code
3 letter untranslated code to identify the currency.
uint16_t rate
The conversion rate compared to the base currency.
StringID name
Translated name of this currency.
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
void OnTimeout() override
Called when this window's timeout has been reached.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
Dimensions (a width and height) of a rectangle in 2D.
value_type height
The height of the rectangle.
value_type width
The width of the rectangle.
Data about how and where to blit pixels.
Definition gfx_type.h:157
Information about GRF, used in the game and (part of it) in savegames.
void SetParameterDefaults()
Set the default value for all parameters as specified by action14.
std::vector< uint32_t > param
GRF parameters.
void OnResize() override
Called after the window got resized.
SettingFilter filter
Filter for the list.
bool closing_dropdown
True, if the dropdown list is currently closing.
void OnTimeout() override
Called when this window's timeout has been reached.
void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close) override
A dropdown window associated to this window has been closed.
SettingEntry * valuewindow_entry
If non-nullptr, pointer to setting for which a value-entering window has been opened.
void OnQueryTextFinished(std::optional< std::string > str) override
The query window opened from this window has closed.
void UpdateWidgetSize(WidgetID widget, Dimension &size, const Dimension &padding, Dimension &fill, Dimension &resize) override
Update size and resize step of a widget in the window.
static int previous_gui_scale
Previous GUI scale.
void OnDropdownSelect(WidgetID widget, int index, int) override
A dropdown option associated to this window has been selected.
SettingEntry * valuedropdown_entry
If non-nullptr, pointer to the value for which a dropdown window is currently opened.
void OnClick(Point pt, WidgetID widget, int click_count) override
A click with the left mouse button has been made on the window.
void OnPaint() override
The window must be repainted.
SettingEntry * clicked_entry
If non-nullptr, pointer to a clicked numeric setting (with a depressed left or right button).
void OnEditboxChanged(WidgetID wid) override
The text in an editbox has been edited.
QueryString filter_editbox
Filter editbox;.
WarnHiddenResult warn_missing
Whether and how to warn about missing search results.
void OnMouseLoop() override
Called for every mouse loop run, which is at least once per (game) tick.
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
void Close(int data=0) override
Hide the window and all its child windows, and mark them for a later deletion.
void SetDisplayedHelpText(SettingEntry *pe)
Set the entry that should have its help text displayed, and mark the window dirty so it gets repainte...
std::string GetWidgetString(WidgetID widget, StringID stringid) const override
Get the raw string for a widget.
int warn_lines
Number of lines used for warning about missing search results.
void DrawWidget(const Rect &r, WidgetID widget) const override
Draw the contents of a nested widget.
bool manually_changed_folding
Whether the user expanded/collapsed something manually.
SettingEntry * last_clicked
If non-nullptr, pointer to the last clicked setting.
DropDownList BuildDropDownList(WidgetID widget, int *selected_index) const
Build the dropdown list for a specific widget.
void OnInit() override
Notification that the nested widget tree gets initialized.
static GameSettings * settings_ptr
Pointer to the game settings being displayed and modified.
All settings together for the game.
LocaleSettings locale
settings related to used currency/unit system in the current game
Base integer type, including boolean, settings.
std::tuple< int32_t, uint32_t > GetRange() const
Get the min/max range for the setting.
Definition settings.cpp:502
int32_t GetDefaultValue() const
Get the default value of the setting.
Definition settings.cpp:493
StringID GetHelp() const
Get the help text of the setting.
Definition settings.cpp:461
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
std::pair< StringParameter, StringParameter > GetValueParams(int32_t value) const
Get parameters for drawing the value of the setting.
Definition settings.cpp:471
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Definition settings.cpp:593
int32_t interval
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dyn...
Currency currency
Currency we currently use.
Colour for pixel/line drawing.
Definition gfx_type.h:307
Data stored about a string that can be modified in the GUI.
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
static const int ACTION_CLEAR
Clear editbox.
Specification of a rectangle with absolute coordinates of all edges.
Rect WithWidth(int width, bool end) const
Copy Rect and set its width.
int Width() const
Get width of Rect.
Rect Shrink(int s) const
Copy and shrink Rect by s pixels.
Rect WithHeight(int height, bool end=false) const
Copy Rect and set its height.
int Height() const
Get height of Rect.
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition settings.cpp:908
SettingFlags flags
Handles how a setting would show up in the GUI (text/currency, etc.).
SettingType GetType() const
Return the type of the setting.
Definition settings.cpp:925
Standard setting.
void SetButtons(SettingEntryFlags new_val)
Set the button-depressed flags (SettingsEntryFlag::LeftDepressed and SettingsEntryFlag::RightDepresse...
uint GetMaxHelpHeight(int maxw) override
Get the biggest height of the help text(s), if the width is at least maxw.
const IntSettingDesc * setting
Setting description of the setting.
Filter for settings list.
SettingType type
Filter based on type.
bool type_hides
Whether the type hides filtered strings.
RestrictionMode mode
Filter based on category.
RestrictionMode min_cat
Minimum category needed to display all filtered strings (RM_BASIC, RM_ADVANCED, or RM_ALL).
StringFilter string
Filter string.
bool UpdateFilterState(SettingFilter &filter, bool force_visible)
Update the filter state.
void GetFoldingState(bool &all_folded, bool &all_unfolded) const
Recursively accumulate the folding state of the tree.
void ResetAll()
Resets all settings to their default values.
void FoldAll()
Recursively close all folds of sub-pages.
void UnFoldAll()
Recursively open all folds of sub-pages.
BaseSettingEntry * FindEntry(uint row, uint *cur_row)
Find the setting entry at row number row_num.
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
Draw a row in the settings panel.
Data structure describing one page of settings in the settings window.
bool folded
Sub-page is folded (not visible except for its title).
bool IsEmpty() const
Check whether any filter words were entered.
void SetFilterTerm(std::string_view str)
Set the term to filter on.
std::string_view GetText() const
Get the current text.
Definition textbuf.cpp:283
TextfileType file_type
Type of textfile to view.
virtual void LoadTextfile(const std::string &textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
High level window description.
Definition window_gui.h:171
Data structure for an opened window.
Definition window_gui.h:272
void ReInit(int rx=0, int ry=0, bool reposition=false)
Re-initialize a window, and optionally change its size.
Definition window.cpp:1025
void CloseChildWindows(WindowClass wc=WindowClass::Invalid) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1122
virtual void Close(int data=0)
Hide the window and all its child windows, and mark them for a later deletion.
Definition window.cpp:1150
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition window.cpp:1855
std::map< WidgetID, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition window_gui.h:319
void DrawWidgets() const
Paint all widgets of a window.
Definition widget.cpp:792
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing).
Definition window.cpp:3317
Window * parent
Parent window.
Definition window_gui.h:327
void SetWidgetDirty(WidgetID widget_index) const
Invalidate a widget, i.e.
Definition window.cpp:565
virtual std::string GetWidgetString(WidgetID widget, StringID stringid) const
Get the raw string for a widget.
Definition window.cpp:513
WidgetID mouse_capture_widget
ID of current mouse capture widget (e.g. dragged scrollbar). INVALID_WIDGET if no widget has mouse ca...
Definition window_gui.h:325
ResizeInfo resize
Resize information.
Definition window_gui.h:313
void DisableWidget(WidgetID widget_index)
Sets a widget to disabled.
Definition window_gui.h:390
void SetWidgetsDisabledState(bool disab_stat, Args... widgets)
Sets the enabled/disabled status of a list of widgets.
Definition window_gui.h:514
void CreateNestedTree()
Perform the first part of the initialization of a nested widget tree.
Definition window.cpp:1845
void CloseChildWindowById(WindowClass wc, WindowNumber number) const
Close all children a window might have in a head-recursive manner.
Definition window.cpp:1137
bool SetFocusedWidget(WidgetID widget_index)
Set focus within this window to the given widget.
Definition window.cpp:494
bool IsWidgetLowered(WidgetID widget_index) const
Gets the lowered state of a widget.
Definition window_gui.h:490
void SetWidgetsLoweredState(bool lowered_stat, Args... widgets)
Sets the lowered/raised status of a list of widgets.
Definition window_gui.h:525
void SetWidgetLoweredState(WidgetID widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition window_gui.h:440
void EnableWidget(WidgetID widget_index)
Sets a widget to Enabled.
Definition window_gui.h:399
virtual void OnDropdownClose(Point pt, WidgetID widget, int index, int click_result, bool instant_close)
A dropdown window associated to this window has been closed.
Definition window.cpp:293
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition window_gui.h:354
Window(WindowDesc &desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition window.cpp:1879
const NWID * GetWidget(WidgetID widnum) const
Get the nested widget with number widnum from the nested widget tree.
void LowerWidget(WidgetID widget_index)
Marks a widget as lowered.
Definition window_gui.h:459
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition window.cpp:1869
WindowFlags flags
Window flags.
Definition window_gui.h:299
const Scrollbar * GetScrollbar(WidgetID widnum) const
Return the Scrollbar to a widget index.
Definition window.cpp:322
void SetWidgetDisabledState(WidgetID widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition window_gui.h:380
int height
Height of the window (number of pixels down in y direction).
Definition window_gui.h:311
int width
width of the window (number of pixels to the right in x direction)
Definition window_gui.h:310
@ BaseSounds
The content consists of base sounds.
@ BaseGraphics
The content consists of base graphics.
@ BaseMusic
The content consists of base music.
Stuff related to the text buffer GUI.
@ EnableDefault
enable the 'Default' button ("\0" is returned)
Definition textbuf_gui.h:20
std::optional< std::string > GetTextfile(TextfileType type, Subdirectory dir, std::string_view filename)
Search a textfile file next to the given content.
GUI functions related to textfiles.
TextfileType
Additional text files accompanying Tar archives.
@ Readme
Content readme.
@ ContentBegin
This marker is used to generate the below three buttons in sequence by various of places in the code.
@ ContentEnd
This marker is used to generate the above three buttons in sequence by various of places in the code.
@ License
Content license.
@ Changelog
Content changelog.
bool _video_vsync
Whether we should use vsync (only if active video driver supports HW acceleration).
bool _video_hw_accel
Whether to consider hardware accelerated video drivers on startup.
Base of all video drivers.
Functions related to (drawing on) viewports.
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition widget.cpp:308
void SetupWidgetDimensions()
Set up pre-scaled versions of Widget Dimensions.
Definition widget.cpp:98
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
@ WWT_PUSHIMGBTN
Normal push-button (no toggle button) with image caption.
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
@ WWT_LABEL
Centered label.
Definition widget_type.h:48
@ NWID_SPACER
Invisible widget that takes some space.
Definition widget_type.h:70
@ WWT_EDITBOX
a textbox for typing
Definition widget_type.h:62
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
@ WWT_TEXTBTN
(Toggle) Button with text
Definition widget_type.h:44
@ WWT_PANEL
Simple depressed panel.
Definition widget_type.h:39
@ WWT_CAPTION
Window caption (window title between closebox and stickybox).
Definition widget_type.h:52
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition widget_type.h:76
@ WWT_BOOLBTN
Standard boolean toggle button.
Definition widget_type.h:46
@ NWID_VERTICAL
Vertical container.
Definition widget_type.h:68
@ WWT_CLOSEBOX
Close box (at top-left of a window).
Definition widget_type.h:60
@ WWT_FRAME
Frame.
Definition widget_type.h:51
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget tree.
Definition widget_type.h:37
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window).
Definition widget_type.h:59
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX).
Definition widget_type.h:56
@ WWT_DROPDOWN
Drop down list.
Definition widget_type.h:61
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49
@ NWID_SELECTION
Stacked widgets, only one visible at a time (eg in a panel with tabs).
Definition widget_type.h:71
@ SZSP_NONE
Display plane with zero size in both directions (none filling and resizing).
@ EqualSize
Containers should keep all their (resizing) children equally large.
@ Decrease
Arrow to the left or in case of RTL to the right.
Definition widget_type.h:20
@ Increase
Arrow to the right or in case of RTL to the left.
Definition widget_type.h:21
@ HideBevel
Bevel of resize box is hidden.
Definition widget_type.h:29
void CloseWindowById(WindowClass cls, WindowNumber number, bool force, int data)
Close a window by its class and window number (if it is open).
Definition window.cpp:1242
void ReInitAllWindows(bool zoom_changed)
Re-initialize all windows.
Definition window.cpp:3494
void CloseWindowByClass(WindowClass cls, int data)
Close all windows of a given class.
Definition window.cpp:1255
void SetWindowClassesDirty(WindowClass cls)
Mark all windows of a particular class as dirty (in need of repainting).
Definition window.cpp:3285
Window functions not directly related to making/drawing windows.
EnumBitSet< FrameFlag, uint8_t > FrameFlags
Bitset of FrameFlag elements.
Definition window_gui.h:31
@ BorderOnly
Draw border only, no background.
Definition window_gui.h:25
@ Lowered
If set the frame is lowered and the background colour brighter (ie. buttons when pressed).
Definition window_gui.h:26
@ Centred
Window is centered and shall stay centered after ReInit.
Definition window_gui.h:233
@ Timeout
Window timeout counter.
Definition window_gui.h:223
@ Center
Center the window.
Definition window_gui.h:146
int WidgetID
Widget ID.
Definition window_type.h:21
@ GameOptions
Game options.
Definition window_type.h:32