OpenTTD Source: src/settings_gui.cpp Source File

OpenTTD Source 1.11.0-RC1

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 <http://www.gnu.org/licenses/>.
6 */
7
10 #include "stdafx.h"
11 #include "currency.h"
12 #include "error.h"
13 #include "settings_gui.h"
14 #include "textbuf_gui.h"
15 #include "command_func.h"
16 #include "network/network.h"
17 #include "town.h"
18 #include "settings_internal.h"
19 #include "strings_func.h"
20 #include "window_func.h"
21 #include "string_func.h"
22 #include "widgets/dropdown_type.h"
23 #include "widgets/dropdown_func.h"
24 #include "highscore.h"
25 #include "base_media_base.h"
26 #include "company_base.h"
27 #include "company_func.h"
28 #include "viewport_func.h"
29 #include "core/geometry_func.hpp"
30 #include "ai/ai.hpp"
31 #include "blitter/factory.hpp"
32 #include "language.h"
33 #include "textfile_gui.h"
34 #include "stringfilter_type.h"
35 #include "querystring_gui.h"
36 #include "fontcache.h"
37 #include "zoom_func.h"
38 #include "video/video_driver.hpp"
39
40 #include <vector>
41 #include <iterator>
42
43 #include "safeguards.h"
44 #include "video/video_driver.hpp"
45
46
47 static const StringID _autosave_dropdown[] = {
48 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
49 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH,
50 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS,
51 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS,
52 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS,
53 INVALID_STRING_ID,
54 };
55
56 static const StringID _gui_zoom_dropdown[] = {
57 STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_AUTO,
58 STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_NORMAL,
59 STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_2X_ZOOM,
60 STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM,
61 INVALID_STRING_ID,
62 };
63
64 static const StringID _font_zoom_dropdown[] = {
65 STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_AUTO,
66 STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_NORMAL,
67 STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_2X_ZOOM,
68 STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_4X_ZOOM,
69 INVALID_STRING_ID,
70 };
71
72 static Dimension _circle_size;
73
74 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd);
75
80 static uint GetCurrentResolutionIndex()
81 {
82 auto it = std::find(_resolutions.begin(), _resolutions.end(), Dimension(_screen.width, _screen.height));
83 return std::distance(_resolutions.begin(), it);
84 }
85
86 static void ShowCustCurrency();
87
88 template <class T>
89 static DropDownList BuildSetDropDownList(int *selected_index, bool allow_selection)
90 {
91 int n = T::GetNumSets();
92 *selected_index = T::GetIndexOfUsedSet();
93
94 DropDownList list;
95 for (int i = 0; i < n; i++) {
96 list.emplace_back(new DropDownListCharStringItem(T::GetSet(i)->name, i, !allow_selection && (*selected_index != i)));
97 }
98
99 return list;
100 }
101
102 DropDownList BuildMusicSetDropDownList(int *selected_index)
103 {
104 return BuildSetDropDownList<BaseMusic>(selected_index, true);
105 }
106
108 template <class TBaseSet>
109 struct BaseSetTextfileWindow : public TextfileWindow {
110 const TBaseSet* baseset;
111 StringID content_type;
112
113 BaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type) : TextfileWindow(file_type), baseset(baseset), content_type(content_type)
114 {
115 const char *textfile = this->baseset->GetTextfile(file_type);
116 this->LoadTextfile(textfile, BASESET_DIR);
117 }
118
119 void SetStringParameters(int widget) const override
120 {
121 if (widget == WID_TF_CAPTION) {
122 SetDParam(0, content_type);
123 SetDParamStr(1, this->baseset->name.c_str());
124 }
125 }
126 };
127
134 template <class TBaseSet>
135 void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet* baseset, StringID content_type)
136 {
137 DeleteWindowById(WC_TEXTFILE, file_type);
138 new BaseSetTextfileWindow<TBaseSet>(file_type, baseset, content_type);
139 }
140
141 std::set<int> _refresh_rates = { 30, 60, 75, 90, 100, 120, 144, 240 };
142
147 static void AddCustomRefreshRates()
148 {
149 /* Add the refresh rate as selected in the config. */
150 _refresh_rates.insert(_settings_client.gui.refresh_rate);
151
152 /* Add all the refresh rates of all monitors connected to the machine. */
153 std::vector<int> monitorRates = VideoDriver::GetInstance()->GetListOfMonitorRefreshRates();
154 std::copy(monitorRates.begin(), monitorRates.end(), std::inserter(_refresh_rates, _refresh_rates.end()));
155 }
156
157 struct GameOptionsWindow : Window {
158 GameSettings *opt;
159 bool reload;
160
161 GameOptionsWindow(WindowDesc *desc) : Window(desc)
162 {
163 this->opt = &GetGameSettings();
164 this->reload = false;
165
166 AddCustomRefreshRates();
167
168 this->InitNested(WN_GAME_OPTIONS_GAME_OPTIONS);
169 this->OnInvalidateData(0);
170 }
171
172 ~GameOptionsWindow()
173 {
174 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
175 DeleteWindowByClass(WC_TEXTFILE);
176 if (this->reload) _switch_mode = SM_MENU;
177 }
178
185 DropDownList BuildDropDownList(int widget, int *selected_index) const
186 {
187 DropDownList list;
188 switch (widget) {
189 case WID_GO_CURRENCY_DROPDOWN: { // Setup currencies dropdown
190 *selected_index = this->opt->locale.currency;
191 StringID *items = BuildCurrencyDropdown();
192 uint64 disabled = _game_mode == GM_MENU ? 0LL : ~GetMaskOfAllowedCurrencies();
193
194 /* Add non-custom currencies; sorted naturally */
195 for (uint i = 0; i < CURRENCY_END; items++, i++) {
196 if (i == CURRENCY_CUSTOM) continue;
197 list.emplace_back(new DropDownListStringItem(*items, i, HasBit(disabled, i)));
198 }
199 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
200
201 /* Append custom currency at the end */
202 list.emplace_back(new DropDownListItem(-1, false)); // separator line
203 list.emplace_back(new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM, CURRENCY_CUSTOM, HasBit(disabled, CURRENCY_CUSTOM)));
204 break;
205 }
206
207 case WID_GO_AUTOSAVE_DROPDOWN: { // Setup autosave dropdown
208 *selected_index = _settings_client.gui.autosave;
209 const StringID *items = _autosave_dropdown;
210 for (uint i = 0; *items != INVALID_STRING_ID; items++, i++) {
211 list.emplace_back(new DropDownListStringItem(*items, i, false));
212 }
213 break;
214 }
215
216 case WID_GO_LANG_DROPDOWN: { // Setup interface language dropdown
217 for (uint i = 0; i < _languages.size(); i++) {
218 auto item = new DropDownListParamStringItem(STR_JUST_RAW_STRING, i, false);
219 if (&_languages[i] == _current_language) {
220 *selected_index = i;
221 item->SetParamStr(0, _languages[i].own_name);
222 } else {
223 /* Especially with sprite-fonts, not all localized
224 * names can be rendered. So instead, we use the
225 * international names for anything but the current
226 * selected language. This avoids showing a few ????
227 * entries in the dropdown list. */
228 item->SetParamStr(0, _languages[i].name);
229 }
230 list.emplace_back(item);
231 }
232 std::sort(list.begin(), list.end(), DropDownListStringItem::NatSortFunc);
233 break;
234 }
235
236 case WID_GO_RESOLUTION_DROPDOWN: // Setup resolution dropdown
237 if (_resolutions.empty()) break;
238
239 *selected_index = GetCurrentResolutionIndex();
240 for (uint i = 0; i < _resolutions.size(); i++) {
241 auto item = new DropDownListParamStringItem(STR_GAME_OPTIONS_RESOLUTION_ITEM, i, false);
242 item->SetParam(0, _resolutions[i].width);
243 item->SetParam(1, _resolutions[i].height);
244 list.emplace_back(item);
245 }
246 break;
247
248 case WID_GO_REFRESH_RATE_DROPDOWN: // Setup refresh rate dropdown
249 for (auto it = _refresh_rates.begin(); it != _refresh_rates.end(); it++) {
250 auto i = std::distance(_refresh_rates.begin(), it);
251 if (*it == _settings_client.gui.refresh_rate) *selected_index = i;
252 auto item = new DropDownListParamStringItem(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, i, false);
253 item->SetParam(0, *it);
254 list.emplace_back(item);
255 }
256 break;
257
258 case WID_GO_GUI_ZOOM_DROPDOWN: {
259 *selected_index = _gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom + 1 : 0;
260 const StringID *items = _gui_zoom_dropdown;
261 for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
262 list.emplace_back(new DropDownListStringItem(*items, i, i != 0 && _settings_client.gui.zoom_min > ZOOM_LVL_OUT_4X - i + 1));
263 }
264 break;
265 }
266
267 case WID_GO_FONT_ZOOM_DROPDOWN: {
268 *selected_index = _font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom + 1 : 0;
269 const StringID *items = _font_zoom_dropdown;
270 for (int i = 0; *items != INVALID_STRING_ID; items++, i++) {
271 list.emplace_back(new DropDownListStringItem(*items, i, false));
272 }
273 break;
274 }
275
276 case WID_GO_BASE_GRF_DROPDOWN:
277 list = BuildSetDropDownList<BaseGraphics>(selected_index, (_game_mode == GM_MENU));
278 break;
279
280 case WID_GO_BASE_SFX_DROPDOWN:
281 list = BuildSetDropDownList<BaseSounds>(selected_index, (_game_mode == GM_MENU));
282 break;
283
284 case WID_GO_BASE_MUSIC_DROPDOWN:
285 list = BuildMusicSetDropDownList(selected_index);
286 break;
287 }
288
289 return list;
290 }
291
292 void SetStringParameters(int widget) const override
293 {
294 switch (widget) {
295 case WID_GO_CURRENCY_DROPDOWN: SetDParam(0, _currency_specs[this->opt->locale.currency].name); break;
296 case WID_GO_AUTOSAVE_DROPDOWN: SetDParam(0, _autosave_dropdown[_settings_client.gui.autosave]); break;
297 case WID_GO_LANG_DROPDOWN: SetDParamStr(0, _current_language->own_name); break;
298 case WID_GO_GUI_ZOOM_DROPDOWN: SetDParam(0, _gui_zoom_dropdown[_gui_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _gui_zoom_cfg + 1 : 0]); break;
299 case WID_GO_FONT_ZOOM_DROPDOWN: SetDParam(0, _font_zoom_dropdown[_font_zoom_cfg != ZOOM_LVL_CFG_AUTO ? ZOOM_LVL_OUT_4X - _font_zoom_cfg + 1 : 0]); break;
300 case WID_GO_BASE_GRF_DROPDOWN: SetDParamStr(0, BaseGraphics::GetUsedSet()->name.c_str()); break;
301 case WID_GO_BASE_GRF_STATUS: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
302 case WID_GO_BASE_SFX_DROPDOWN: SetDParamStr(0, BaseSounds::GetUsedSet()->name.c_str()); break;
303 case WID_GO_BASE_MUSIC_DROPDOWN: SetDParamStr(0, BaseMusic::GetUsedSet()->name.c_str()); break;
304 case WID_GO_BASE_MUSIC_STATUS: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
305 case WID_GO_REFRESH_RATE_DROPDOWN: SetDParam(0, _settings_client.gui.refresh_rate); break;
306 case WID_GO_RESOLUTION_DROPDOWN: {
307 auto current_resolution = GetCurrentResolutionIndex();
308
309 if (current_resolution == _resolutions.size()) {
310 SetDParam(0, STR_GAME_OPTIONS_RESOLUTION_OTHER);
311 } else {
312 SetDParam(0, STR_GAME_OPTIONS_RESOLUTION_ITEM);
313 SetDParam(1, _resolutions[current_resolution].width);
314 SetDParam(2, _resolutions[current_resolution].height);
315 }
316 break;
317 }
318 }
319 }
320
321 void DrawWidget(const Rect &r, int widget) const override
322 {
323 switch (widget) {
324 case WID_GO_BASE_GRF_DESCRIPTION:
325 SetDParamStr(0, BaseGraphics::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
326 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
327 break;
328
329 case WID_GO_BASE_SFX_DESCRIPTION:
330 SetDParamStr(0, BaseSounds::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
331 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
332 break;
333
334 case WID_GO_BASE_MUSIC_DESCRIPTION:
335 SetDParamStr(0, BaseMusic::GetUsedSet()->GetDescription(GetCurrentLanguageIsoCode()));
336 DrawStringMultiLine(r.left, r.right, r.top, UINT16_MAX, STR_BLACK_RAW_STRING);
337 break;
338 }
339 }
340
341 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
342 {
343 switch (widget) {
344 case WID_GO_BASE_GRF_DESCRIPTION:
345 /* Find the biggest description for the default size. */
346 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
347 SetDParamStr(0, BaseGraphics::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
348 size->height = std::max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
349 }
350 break;
351
352 case WID_GO_BASE_GRF_STATUS:
353 /* Find the biggest description for the default size. */
354 for (int i = 0; i < BaseGraphics::GetNumSets(); i++) {
355 uint invalid_files = BaseGraphics::GetSet(i)->GetNumInvalid();
356 if (invalid_files == 0) continue;
357
358 SetDParam(0, invalid_files);
359 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_GRF_STATUS));
360 }
361 break;
362
363 case WID_GO_BASE_SFX_DESCRIPTION:
364 /* Find the biggest description for the default size. */
365 for (int i = 0; i < BaseSounds::GetNumSets(); i++) {
366 SetDParamStr(0, BaseSounds::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
367 size->height = std::max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
368 }
369 break;
370
371 case WID_GO_BASE_MUSIC_DESCRIPTION:
372 /* Find the biggest description for the default size. */
373 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
374 SetDParamStr(0, BaseMusic::GetSet(i)->GetDescription(GetCurrentLanguageIsoCode()));
375 size->height = std::max(size->height, (uint)GetStringHeight(STR_BLACK_RAW_STRING, size->width));
376 }
377 break;
378
379 case WID_GO_BASE_MUSIC_STATUS:
380 /* Find the biggest description for the default size. */
381 for (int i = 0; i < BaseMusic::GetNumSets(); i++) {
382 uint invalid_files = BaseMusic::GetSet(i)->GetNumInvalid();
383 if (invalid_files == 0) continue;
384
385 SetDParam(0, invalid_files);
386 *size = maxdim(*size, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_MUSIC_STATUS));
387 }
388 break;
389
390 default: {
391 int selected;
392 DropDownList list = this->BuildDropDownList(widget, &selected);
393 if (!list.empty()) {
394 /* Find the biggest item for the default size. */
395 for (const auto &ddli : list) {
396 Dimension string_dim;
397 int width = ddli->Width();
398 string_dim.width = width + padding.width;
399 string_dim.height = ddli->Height(width) + padding.height;
400 *size = maxdim(*size, string_dim);
401 }
402 }
403 }
404 }
405 }
406
407 void OnClick(Point pt, int widget, int click_count) override
408 {
409 if (widget >= WID_GO_BASE_GRF_TEXTFILE && widget < WID_GO_BASE_GRF_TEXTFILE + TFT_END) {
410 if (BaseGraphics::GetUsedSet() == nullptr) return;
411
412 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_GRF_TEXTFILE), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS);
413 return;
414 }
415 if (widget >= WID_GO_BASE_SFX_TEXTFILE && widget < WID_GO_BASE_SFX_TEXTFILE + TFT_END) {
416 if (BaseSounds::GetUsedSet() == nullptr) return;
417
418 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_SFX_TEXTFILE), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS);
419 return;
420 }
421 if (widget >= WID_GO_BASE_MUSIC_TEXTFILE && widget < WID_GO_BASE_MUSIC_TEXTFILE + TFT_END) {
422 if (BaseMusic::GetUsedSet() == nullptr) return;
423
424 ShowBaseSetTextfileWindow((TextfileType)(widget - WID_GO_BASE_MUSIC_TEXTFILE), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC);
425 return;
426 }
427 switch (widget) {
428 case WID_GO_FULLSCREEN_BUTTON: // Click fullscreen on/off
429 /* try to toggle full-screen on/off */
430 if (!ToggleFullScreen(!_fullscreen)) {
431 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED, INVALID_STRING_ID, WL_ERROR);
432 }
433 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
434 this->SetDirty();
435 break;
436
437 case WID_GO_VIDEO_ACCEL_BUTTON:
438 _video_hw_accel = !_video_hw_accel;
439 ShowErrorMessage(STR_GAME_OPTIONS_VIDEO_ACCELERATION_RESTART, INVALID_STRING_ID, WL_INFO);
440 this->SetWidgetLoweredState(WID_GO_VIDEO_ACCEL_BUTTON, _video_hw_accel);
441 this->SetDirty();
442 break;
443
444 default: {
445 int selected;
446 DropDownList list = this->BuildDropDownList(widget, &selected);
447 if (!list.empty()) {
448 ShowDropDownList(this, std::move(list), selected, widget);
449 } else {
450 if (widget == WID_GO_RESOLUTION_DROPDOWN) ShowErrorMessage(STR_ERROR_RESOLUTION_LIST_FAILED, INVALID_STRING_ID, WL_ERROR);
451 }
452 break;
453 }
454 }
455 }
456
462 template <class T>
463 void SetMediaSet(int index)
464 {
465 if (_game_mode == GM_MENU) {
466 auto name = T::GetSet(index)->name;
467
468 T::ini_set = name;
469
470 T::SetSet(name);
471 this->reload = true;
472 this->InvalidateData();
473 }
474 }
475
476 void OnDropdownSelect(int widget, int index) override
477 {
478 switch (widget) {
479 case WID_GO_CURRENCY_DROPDOWN: // Currency
480 if (index == CURRENCY_CUSTOM) ShowCustCurrency();
481 this->opt->locale.currency = index;
482 ReInitAllWindows();
483 break;
484
485 case WID_GO_AUTOSAVE_DROPDOWN: // Autosave options
486 _settings_client.gui.autosave = index;
487 this->SetDirty();
488 break;
489
490 case WID_GO_LANG_DROPDOWN: // Change interface language
491 ReadLanguagePack(&_languages[index]);
492 DeleteWindowByClass(WC_QUERY_STRING);
493 CheckForMissingGlyphs();
494 ClearAllCachedNames();
495 UpdateAllVirtCoords();
496 CheckBlitter();
497 ReInitAllWindows();
498 break;
499
500 case WID_GO_RESOLUTION_DROPDOWN: // Change resolution
501 if ((uint)index < _resolutions.size() && ChangeResInGame(_resolutions[index].width, _resolutions[index].height)) {
502 this->SetDirty();
503 }
504 break;
505
506 case WID_GO_REFRESH_RATE_DROPDOWN: {
507 _settings_client.gui.refresh_rate = *std::next(_refresh_rates.begin(), index);
508 if (_settings_client.gui.refresh_rate > 60) {
509 /* Show warning to the user that this refresh rate might not be suitable on
510 * larger maps with many NewGRFs and vehicles. */
511 ShowErrorMessage(STR_GAME_OPTIONS_REFRESH_RATE_WARNING, INVALID_STRING_ID, WL_INFO);
512 }
513 break;
514 }
515
516 case WID_GO_GUI_ZOOM_DROPDOWN: {
517 int8 new_zoom = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
518 if (new_zoom != _gui_zoom_cfg) {
519 GfxClearSpriteCache();
520 _gui_zoom_cfg = new_zoom;
521 UpdateGUIZoom();
522 UpdateCursorSize();
523 UpdateAllVirtCoords();
524 FixTitleGameZoom();
525 ReInitAllWindows();
526 }
527 break;
528 }
529
530 case WID_GO_FONT_ZOOM_DROPDOWN: {
531 int8 new_zoom = index > 0 ? ZOOM_LVL_OUT_4X - index + 1 : ZOOM_LVL_CFG_AUTO;
532 if (new_zoom != _font_zoom_cfg) {
533 GfxClearSpriteCache();
534 _font_zoom_cfg = new_zoom;
535 UpdateGUIZoom();
536 ClearFontCache();
537 LoadStringWidthTable();
538 UpdateAllVirtCoords();
539 }
540 break;
541 }
542
543 case WID_GO_BASE_GRF_DROPDOWN:
544 this->SetMediaSet<BaseGraphics>(index);
545 break;
546
547 case WID_GO_BASE_SFX_DROPDOWN:
548 this->SetMediaSet<BaseSounds>(index);
549 break;
550
551 case WID_GO_BASE_MUSIC_DROPDOWN:
552 ChangeMusicSet(index);
553 break;
554 }
555 }
556
562 void OnInvalidateData(int data = 0, bool gui_scope = true) override
563 {
564 if (!gui_scope) return;
565 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON, _fullscreen);
566 this->SetWidgetLoweredState(WID_GO_VIDEO_ACCEL_BUTTON, _video_hw_accel);
567
568 bool missing_files = BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
569 this->GetWidget<NWidgetCore>(WID_GO_BASE_GRF_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_GRF_STATUS, STR_NULL);
570
571 for (TextfileType tft = TFT_BEGIN; tft < TFT_END; tft++) {
572 this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE + tft, BaseGraphics::GetUsedSet() == nullptr || BaseGraphics::GetUsedSet()->GetTextfile(tft) == nullptr);
573 this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE + tft, BaseSounds::GetUsedSet() == nullptr || BaseSounds::GetUsedSet()->GetTextfile(tft) == nullptr);
574 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE + tft, BaseMusic::GetUsedSet() == nullptr || BaseMusic::GetUsedSet()->GetTextfile(tft) == nullptr);
575 }
576
577 missing_files = BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
578 this->GetWidget<NWidgetCore>(WID_GO_BASE_MUSIC_STATUS)->SetDataTip(missing_files ? STR_EMPTY : STR_GAME_OPTIONS_BASE_MUSIC_STATUS, STR_NULL);
579 }
580 };
581
582 static const NWidgetPart _nested_game_options_widgets[] = {
583 NWidget(NWID_HORIZONTAL),
584 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
585 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
586 EndContainer(),
587 NWidget(WWT_PANEL, COLOUR_GREY, WID_GO_BACKGROUND), SetPIP(6, 6, 10),
588 NWidget(NWID_HORIZONTAL), SetPIP(10, 10, 10),
589 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
590 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME, STR_NULL),
591 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_AUTOSAVE_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_TOOLTIP), SetFill(1, 0),
592 EndContainer(),
593 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GUI_ZOOM_FRAME, STR_NULL),
594 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_GUI_ZOOM_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_TOOLTIP), SetFill(1, 0),
595 EndContainer(),
596 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME, STR_NULL),
597 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_CURRENCY_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_CURRENCY_UNITS_DROPDOWN_TOOLTIP), SetFill(1, 0),
598 EndContainer(),
599 EndContainer(),
600
601 NWidget(NWID_VERTICAL), SetPIP(0, 6, 0),
602 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_LANGUAGE, STR_NULL),
603 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_LANG_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_LANGUAGE_TOOLTIP), SetFill(1, 0),
604 EndContainer(),
605 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_FONT_ZOOM, STR_NULL),
606 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_FONT_ZOOM_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_FONT_ZOOM_DROPDOWN_TOOLTIP), SetFill(1, 0),
607 EndContainer(),
608 EndContainer(),
609 EndContainer(),
610
611 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_GRAPHICS, STR_NULL), SetPadding(0, 10, 0, 10),
612 NWidget(NWID_HORIZONTAL),
613 NWidget(NWID_VERTICAL),
614 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_RESOLUTION, STR_NULL), SetPadding(0, 0, 2, 0),
615 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_REFRESH_RATE, STR_NULL), SetPadding(0, 0, 2, 0),
616 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN, STR_NULL), SetPadding(0, 0, 2, 0),
617 NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_VIDEO_ACCELERATION, STR_NULL),
618 EndContainer(),
619 NWidget(NWID_VERTICAL),
620 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_RESOLUTION_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_BLACK_STRING, STR_GAME_OPTIONS_RESOLUTION_TOOLTIP), SetFill(1, 0), SetPadding(0, 0, 2, 0),
621 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_REFRESH_RATE_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_GAME_OPTIONS_REFRESH_RATE_ITEM, STR_GAME_OPTIONS_REFRESH_RATE_TOOLTIP), SetFill(1, 0), SetPadding(0, 0, 2, 0),
622 NWidget(NWID_HORIZONTAL), SetPadding(0, 0, 2, 0),
623 NWidget(NWID_SPACER), SetMinimalSize(1, 0), SetFill(1, 0),
624 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_FULLSCREEN_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP),
625 EndContainer(),
626 NWidget(NWID_HORIZONTAL),
627 NWidget(NWID_SPACER), SetMinimalSize(1, 0), SetFill(1, 0),
628 NWidget(WWT_TEXTBTN, COLOUR_GREY, WID_GO_VIDEO_ACCEL_BUTTON), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_VIDEO_ACCELERATION_TOOLTIP),
629 EndContainer(),
630 EndContainer(),
631 EndContainer(),
632 EndContainer(),
633
634 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_GRF, STR_NULL), SetPadding(0, 10, 0, 10),
635 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
636 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_GRF_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP),
637 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
638 EndContainer(),
639 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_GRF_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_GRF_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
640 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
641 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
642 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
643 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_GRF_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
644 EndContainer(),
645 EndContainer(),
646
647 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_SFX, STR_NULL), SetPadding(0, 10, 0, 10),
648 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
649 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_SFX_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP),
650 NWidget(NWID_SPACER), SetFill(1, 0),
651 EndContainer(),
652 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_SFX_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_SFX_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
653 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
654 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
655 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
656 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_SFX_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
657 EndContainer(),
658 EndContainer(),
659
660 NWidget(WWT_FRAME, COLOUR_GREY), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC, STR_NULL), SetPadding(0, 10, 0, 10),
661 NWidget(NWID_HORIZONTAL), SetPIP(0, 30, 0),
662 NWidget(WWT_DROPDOWN, COLOUR_GREY, WID_GO_BASE_MUSIC_DROPDOWN), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP),
663 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_STATUS), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY, STR_NULL), SetFill(1, 0),
664 EndContainer(),
665 NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_BASE_MUSIC_DESCRIPTION), SetMinimalSize(330, 0), SetDataTip(STR_EMPTY, STR_GAME_OPTIONS_BASE_MUSIC_DESCRIPTION_TOOLTIP), SetFill(1, 0), SetPadding(6, 0, 6, 0),
666 NWidget(NWID_HORIZONTAL, NC_EQUALSIZE), SetPIP(7, 0, 7),
667 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_README), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_README, STR_NULL),
668 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_CHANGELOG), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_CHANGELOG, STR_NULL),
669 NWidget(WWT_PUSHTXTBTN, COLOUR_GREY, WID_GO_BASE_MUSIC_TEXTFILE + TFT_LICENSE), SetFill(1, 0), SetResize(1, 0), SetDataTip(STR_TEXTFILE_VIEW_LICENCE, STR_NULL),
670 EndContainer(),
671 EndContainer(),
672 EndContainer(),
673 };
674
675 static WindowDesc _game_options_desc(
676 WDP_CENTER, "settings_game", 0, 0,
677 WC_GAME_OPTIONS, WC_NONE,
678 0,
679 _nested_game_options_widgets, lengthof(_nested_game_options_widgets)
680 );
681
683 void ShowGameOptions()
684 {
685 DeleteWindowByClass(WC_GAME_OPTIONS);
686 new GameOptionsWindow(&_game_options_desc);
687 }
688
689 static int SETTING_HEIGHT = 11;
690 static const int LEVEL_WIDTH = 15;
691
696 enum SettingEntryFlags {
697 SEF_LEFT_DEPRESSED = 0x01,
698 SEF_RIGHT_DEPRESSED = 0x02,
699 SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED),
700
701 SEF_LAST_FIELD = 0x04,
702 SEF_FILTERED = 0x08,
703 };
704
706 enum RestrictionMode {
707 RM_BASIC,
708 RM_ADVANCED,
709 RM_ALL,
710 RM_CHANGED_AGAINST_DEFAULT,
711 RM_CHANGED_AGAINST_NEW,
712 RM_END,
713 };
714 DECLARE_POSTFIX_INCREMENT(RestrictionMode)
715
716
717 struct SettingFilter {
718 StringFilter string;
719 RestrictionMode min_cat;
720 bool type_hides;
721 RestrictionMode mode;
722 SettingType type;
723 };
724
726 struct BaseSettingEntry {
727 byte flags;
728 byte level;
729
730 BaseSettingEntry() : flags(0), level(0) {}
731 virtual ~BaseSettingEntry() {}
732
733 virtual void Init(byte level = 0);
734 virtual void FoldAll() {}
735 virtual void UnFoldAll() {}
736
741 void SetLastField(bool last_field) { if (last_field) SETBITS(this->flags, SEF_LAST_FIELD); else CLRBITS(this->flags, SEF_LAST_FIELD); }
742
743 virtual uint Length() const = 0;
744 virtual void GetFoldingState(bool &all_folded, bool &all_unfolded) const {}
745 virtual bool IsVisible(const BaseSettingEntry *item) const;
746 virtual BaseSettingEntry *FindEntry(uint row, uint *cur_row);
747 virtual uint GetMaxHelpHeight(int maxw) { return 0; }
748
753 bool IsFiltered() const { return (this->flags & SEF_FILTERED) != 0; }
754
755 virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible) = 0;
756
757 virtual uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
758
759 protected:
760 virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const = 0;
761 };
762
764 struct SettingEntry : BaseSettingEntry {
765 const char *name;
766 const SettingDesc *setting;
767 uint index;
768
769 SettingEntry(const char *name);
770
771 virtual void Init(byte level = 0);
772 virtual uint Length() const;
773 virtual uint GetMaxHelpHeight(int maxw);
774 virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible);
775
776 void SetButtons(byte new_val);
777
782 inline StringID GetHelpText() const
783 {
784 return this->setting->desc.str_help;
785 }
786
787 void SetValueDParams(uint first_param, int32 value) const;
788
789 protected:
790 virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const;
791
792 private:
793 bool IsVisibleByRestrictionMode(RestrictionMode mode) const;
794 };
795
797 struct SettingsContainer {
798 typedef std::vector<BaseSettingEntry*> EntryVector;
799 EntryVector entries;
800
801 template<typename T>
802 T *Add(T *item)
803 {
804 this->entries.push_back(item);
805 return item;
806 }
807
808 void Init(byte level = 0);
809 void FoldAll();
810 void UnFoldAll();
811
812 uint Length() const;
813 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
814 bool IsVisible(const BaseSettingEntry *item) const;
815 BaseSettingEntry *FindEntry(uint row, uint *cur_row);
816 uint GetMaxHelpHeight(int maxw);
817
818 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
819
820 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;
821 };
822
824 struct SettingsPage : BaseSettingEntry, SettingsContainer {
825 StringID title;
826 bool folded;
827
828 SettingsPage(StringID title);
829
830 virtual void Init(byte level = 0);
831 virtual void FoldAll();
832 virtual void UnFoldAll();
833
834 virtual uint Length() const;
835 virtual void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
836 virtual bool IsVisible(const BaseSettingEntry *item) const;
837 virtual BaseSettingEntry *FindEntry(uint row, uint *cur_row);
838 virtual uint GetMaxHelpHeight(int maxw) { return SettingsContainer::GetMaxHelpHeight(maxw); }
839
840 virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible);
841
842 virtual uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row = 0, uint parent_last = 0) const;
843
844 protected:
845 virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const;
846 };
847
848 /* == BaseSettingEntry methods == */
849
854 void BaseSettingEntry::Init(byte level)
855 {
856 this->level = level;
857 }
858
865 bool BaseSettingEntry::IsVisible(const BaseSettingEntry *item) const
866 {
867 if (this->IsFiltered()) return false;
868 if (this == item) return true;
869 return false;
870 }
871
878 BaseSettingEntry *BaseSettingEntry::FindEntry(uint row_num, uint *cur_row)
879 {
880 if (this->IsFiltered()) return nullptr;
881 if (row_num == *cur_row) return this;
882 (*cur_row)++;
883 return nullptr;
884 }
885
915 uint BaseSettingEntry::Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last) const
916 {
917 if (this->IsFiltered()) return cur_row;
918 if (cur_row >= max_row) return cur_row;
919
920 bool rtl = _current_text_dir == TD_RTL;
921 int offset = rtl ? -4 : 4;
922 int level_width = rtl ? -LEVEL_WIDTH : LEVEL_WIDTH;
923
924 int x = rtl ? right : left;
925 if (cur_row >= first_row) {
926 int colour = _colour_gradient[COLOUR_ORANGE][4];
927 y += (cur_row - first_row) * SETTING_HEIGHT; // Compute correct y start position
928
929 /* Draw vertical for parent nesting levels */
930 for (uint lvl = 0; lvl < this->level; lvl++) {
931 if (!HasBit(parent_last, lvl)) GfxDrawLine(x + offset, y, x + offset, y + SETTING_HEIGHT - 1, colour);
932 x += level_width;
933 }
934 /* draw own |- prefix */
935 int halfway_y = y + SETTING_HEIGHT / 2;
936 int bottom_y = (flags & SEF_LAST_FIELD) ? halfway_y : y + SETTING_HEIGHT - 1;
937 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
938 /* Small horizontal line from the last vertical line */
939 GfxDrawLine(x + offset, halfway_y, x + level_width - offset, halfway_y, colour);
940 x += level_width;
941
942 this->DrawSetting(settings_ptr, rtl ? left : x, rtl ? x : right, y, this == selected);
943 }
944 cur_row++;
945
946 return cur_row;
947 }
948
949 /* == SettingEntry methods == */
950
955 SettingEntry::SettingEntry(const char *name)
956 {
957 this->name = name;
958 this->setting = nullptr;
959 this->index = 0;
960 }
961
966 void SettingEntry::Init(byte level)
967 {
968 BaseSettingEntry::Init(level);
969 this->setting = GetSettingFromName(this->name, &this->index);
970 assert(this->setting != nullptr);
971 }
972
978 void SettingEntry::SetButtons(byte new_val)
979 {
980 assert((new_val & ~SEF_BUTTONS_MASK) == 0); // Should not touch any flags outside the buttons
981 this->flags = (this->flags & ~SEF_BUTTONS_MASK) | new_val;
982 }
983
985 uint SettingEntry::Length() const
986 {
987 return this->IsFiltered() ? 0 : 1;
988 }
989
995 uint SettingEntry::GetMaxHelpHeight(int maxw)
996 {
997 return GetStringHeight(this->GetHelpText(), maxw);
998 }
999
1005 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode) const
1006 {
1007 /* There shall not be any restriction, i.e. all settings shall be visible. */
1008 if (mode == RM_ALL) return true;
1009
1010 GameSettings *settings_ptr = &GetGameSettings();
1011 const SettingDesc *sd = this->setting;
1012
1013 if (mode == RM_BASIC) return (this->setting->desc.cat & SC_BASIC_LIST) != 0;
1014 if (mode == RM_ADVANCED) return (this->setting->desc.cat & SC_ADVANCED_LIST) != 0;
1015
1016 /* Read the current value. */
1017 const void *var = ResolveVariableAddress(settings_ptr, sd);
1018 int64 current_value = ReadValue(var, sd->save.conv);
1019
1020 int64 filter_value;
1021
1022 if (mode == RM_CHANGED_AGAINST_DEFAULT) {
1023 /* This entry shall only be visible, if the value deviates from its default value. */
1024
1025 /* Read the default value. */
1026 filter_value = ReadValue(&sd->desc.def, sd->save.conv);
1027 } else {
1028 assert(mode == RM_CHANGED_AGAINST_NEW);
1029 /* This entry shall only be visible, if the value deviates from
1030 * its value is used when starting a new game. */
1031
1032 /* Make sure we're not comparing the new game settings against itself. */
1033 assert(settings_ptr != &_settings_newgame);
1034
1035 /* Read the new game's value. */
1036 var = ResolveVariableAddress(&_settings_newgame, sd);
1037 filter_value = ReadValue(var, sd->save.conv);
1038 }
1039
1040 return current_value != filter_value;
1041 }
1042
1049 bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
1050 {
1051 CLRBITS(this->flags, SEF_FILTERED);
1052
1053 bool visible = true;
1054
1055 const SettingDesc *sd = this->setting;
1056 if (!force_visible && !filter.string.IsEmpty()) {
1057 /* Process the search text filter for this item. */
1058 filter.string.ResetState();
1059
1060 const SettingDescBase *sdb = &sd->desc;
1061
1062 SetDParam(0, STR_EMPTY);
1063 filter.string.AddLine(sdb->str);
1064 filter.string.AddLine(this->GetHelpText());
1065
1066 visible = filter.string.GetState();
1067 }
1068
1069 if (visible) {
1070 if (filter.type != ST_ALL && sd->GetType() != filter.type) {
1071 filter.type_hides = true;
1072 visible = false;
1073 }
1074 if (!this->IsVisibleByRestrictionMode(filter.mode)) {
1075 while (filter.min_cat < RM_ALL && (filter.min_cat == filter.mode || !this->IsVisibleByRestrictionMode(filter.min_cat))) filter.min_cat++;
1076 visible = false;
1077 }
1078 }
1079
1080 if (!visible) SETBITS(this->flags, SEF_FILTERED);
1081 return visible;
1082 }
1083
1084
1085 static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
1086 {
1087 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
1088 if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
1089 return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
1090 } else {
1091 return GetVariableAddress(&_settings_client.company, &sd->save);
1092 }
1093 } else {
1094 return GetVariableAddress(settings_ptr, &sd->save);
1095 }
1096 }
1097
1103 void SettingEntry::SetValueDParams(uint first_param, int32 value) const
1104 {
1105 const SettingDescBase *sdb = &this->setting->desc;
1106 if (sdb->cmd == SDT_BOOLX) {
1107 SetDParam(first_param++, value != 0 ? STR_CONFIG_SETTING_ON : STR_CONFIG_SETTING_OFF);
1108 } else {
1109 if ((sdb->flags & SGF_MULTISTRING) != 0) {
1110 SetDParam(first_param++, sdb->str_val - sdb->min + value);
1111 } else if ((sdb->flags & SGF_DISPLAY_ABS) != 0) {
1112 SetDParam(first_param++, sdb->str_val + ((value >= 0) ? 1 : 0));
1113 value = abs(value);
1114 } else {
1115 SetDParam(first_param++, sdb->str_val + ((value == 0 && (sdb->flags & SGF_0ISDISABLED) != 0) ? 1 : 0));
1116 }
1117 SetDParam(first_param++, value);
1118 }
1119 }
1120
1129 void SettingEntry::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const
1130 {
1131 const SettingDesc *sd = this->setting;
1132 const SettingDescBase *sdb = &sd->desc;
1133 const void *var = ResolveVariableAddress(settings_ptr, sd);
1134 int state = this->flags & SEF_BUTTONS_MASK;
1135
1136 bool rtl = _current_text_dir == TD_RTL;
1137 uint buttons_left = rtl ? right + 1 - SETTING_BUTTON_WIDTH : left;
1138 uint text_left = left + (rtl ? 0 : SETTING_BUTTON_WIDTH + 5);
1139 uint text_right = right - (rtl ? SETTING_BUTTON_WIDTH + 5 : 0);
1140 uint button_y = y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
1141
1142 /* We do not allow changes of some items when we are a client in a networkgame */
1143 bool editable = sd->IsEditable();
1144
1145 SetDParam(0, highlight ? STR_ORANGE_STRING1_WHITE : STR_ORANGE_STRING1_LTBLUE);
1146 int32 value = (int32)ReadValue(var, sd->save.conv);
1147 if (sdb->cmd == SDT_BOOLX) {
1148 /* Draw checkbox for boolean-value either on/off */
1149 DrawBoolButton(buttons_left, button_y, value != 0, editable);
1150 } else if ((sdb->flags & SGF_MULTISTRING) != 0) {
1151 /* Draw [v] button for settings of an enum-type */
1152 DrawDropDownButton(buttons_left, button_y, COLOUR_YELLOW, state != 0, editable);
1153 } else {
1154 /* Draw [<][>] boxes for settings of an integer-type */
1155 DrawArrowButtons(buttons_left, button_y, COLOUR_YELLOW, state,
1156 editable && value != (sdb->flags & SGF_0ISDISABLED ? 0 : sdb->min), editable && (uint32)value != sdb->max);
1157 }
1158 this->SetValueDParams(1, value);
1159 DrawString(text_left, text_right, y + (SETTING_HEIGHT - FONT_HEIGHT_NORMAL) / 2, sdb->str, highlight ? TC_WHITE : TC_LIGHT_BLUE);
1160 }
1161
1162 /* == SettingsContainer methods == */
1163
1168 void SettingsContainer::Init(byte level)
1169 {
1170 for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1171 (*it)->Init(level);
1172 }
1173 }
1174
1176 void SettingsContainer::FoldAll()
1177 {
1178 for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1179 (*it)->FoldAll();
1180 }
1181 }
1182
1184 void SettingsContainer::UnFoldAll()
1185 {
1186 for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1187 (*it)->UnFoldAll();
1188 }
1189 }
1190
1196 void SettingsContainer::GetFoldingState(bool &all_folded, bool &all_unfolded) const
1197 {
1198 for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1199 (*it)->GetFoldingState(all_folded, all_unfolded);
1200 }
1201 }
1202
1209 bool SettingsContainer::UpdateFilterState(SettingFilter &filter, bool force_visible)
1210 {
1211 bool visible = false;
1212 bool first_visible = true;
1213 for (EntryVector::reverse_iterator it = this->entries.rbegin(); it != this->entries.rend(); ++it) {
1214 visible |= (*it)->UpdateFilterState(filter, force_visible);
1215 (*it)->SetLastField(first_visible);
1216 if (visible && first_visible) first_visible = false;
1217 }
1218 return visible;
1219 }
1220
1221
1228 bool SettingsContainer::IsVisible(const BaseSettingEntry *item) const
1229 {
1230 for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1231 if ((*it)->IsVisible(item)) return true;
1232 }
1233 return false;
1234 }
1235
1237 uint SettingsContainer::Length() const
1238 {
1239 uint length = 0;
1240 for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1241 length += (*it)->Length();
1242 }
1243 return length;
1244 }
1245
1252 BaseSettingEntry *SettingsContainer::FindEntry(uint row_num, uint *cur_row)
1253 {
1254 BaseSettingEntry *pe = nullptr;
1255 for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1256 pe = (*it)->FindEntry(row_num, cur_row);
1257 if (pe != nullptr) {
1258 break;
1259 }
1260 }
1261 return pe;
1262 }
1263
1269 uint SettingsContainer::GetMaxHelpHeight(int maxw)
1270 {
1271 uint biggest = 0;
1272 for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1273 biggest = std::max(biggest, (*it)->GetMaxHelpHeight(maxw));
1274 }
1275 return biggest;
1276 }
1277
1278
1293 uint SettingsContainer::Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last) const
1294 {
1295 for (EntryVector::const_iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
1296 cur_row = (*it)->Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
1297 if (cur_row >= max_row) {
1298 break;
1299 }
1300 }
1301 return cur_row;
1302 }
1303
1304 /* == SettingsPage methods == */
1305
1310 SettingsPage::SettingsPage(StringID title)
1311 {
1312 this->title = title;
1313 this->folded = true;
1314 }
1315
1320 void SettingsPage::Init(byte level)
1321 {
1322 BaseSettingEntry::Init(level);
1323 SettingsContainer::Init(level + 1);
1324 }
1325
1327 void SettingsPage::FoldAll()
1328 {
1329 if (this->IsFiltered()) return;
1330 this->folded = true;
1331
1332 SettingsContainer::FoldAll();
1333 }
1334
1336 void SettingsPage::UnFoldAll()
1337 {
1338 if (this->IsFiltered()) return;
1339 this->folded = false;
1340
1341 SettingsContainer::UnFoldAll();
1342 }
1343
1349 void SettingsPage::GetFoldingState(bool &all_folded, bool &all_unfolded) const
1350 {
1351 if (this->IsFiltered()) return;
1352
1353 if (this->folded) {
1354 all_unfolded = false;
1355 } else {
1356 all_folded = false;
1357 }
1358
1359 SettingsContainer::GetFoldingState(all_folded, all_unfolded);
1360 }
1361
1368 bool SettingsPage::UpdateFilterState(SettingFilter &filter, bool force_visible)
1369 {
1370 if (!force_visible && !filter.string.IsEmpty()) {
1371 filter.string.ResetState();
1372 filter.string.AddLine(this->title);
1373 force_visible = filter.string.GetState();
1374 }
1375
1376 bool visible = SettingsContainer::UpdateFilterState(filter, force_visible);
1377 if (visible) {
1378 CLRBITS(this->flags, SEF_FILTERED);
1379 } else {
1380 SETBITS(this->flags, SEF_FILTERED);
1381 }
1382 return visible;
1383 }
1384
1391 bool SettingsPage::IsVisible(const BaseSettingEntry *item) const
1392 {
1393 if (this->IsFiltered()) return false;
1394 if (this == item) return true;
1395 if (this->folded) return false;
1396
1397 return SettingsContainer::IsVisible(item);
1398 }
1399
1401 uint SettingsPage::Length() const
1402 {
1403 if (this->IsFiltered()) return 0;
1404 if (this->folded) return 1; // Only displaying the title
1405
1406 return 1 + SettingsContainer::Length();
1407 }
1408
1415 BaseSettingEntry *SettingsPage::FindEntry(uint row_num, uint *cur_row)
1416 {
1417 if (this->IsFiltered()) return nullptr;
1418 if (row_num == *cur_row) return this;
1419 (*cur_row)++;
1420 if (this->folded) return nullptr;
1421
1422 return SettingsContainer::FindEntry(row_num, cur_row);
1423 }
1424
1439 uint SettingsPage::Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last) const
1440 {
1441 if (this->IsFiltered()) return cur_row;
1442 if (cur_row >= max_row) return cur_row;
1443
1444 cur_row = BaseSettingEntry::Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
1445
1446 if (!this->folded) {
1447 if (this->flags & SEF_LAST_FIELD) {
1448 assert(this->level < 8 * sizeof(parent_last));
1449 SetBit(parent_last, this->level); // Add own last-field state
1450 }
1451
1452 cur_row = SettingsContainer::Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
1453 }
1454
1455 return cur_row;
1456 }
1457
1466 void SettingsPage::DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const
1467 {
1468 bool rtl = _current_text_dir == TD_RTL;
1469 DrawSprite((this->folded ? SPR_CIRCLE_FOLDED : SPR_CIRCLE_UNFOLDED), PAL_NONE, rtl ? right - _circle_size.width : left, y + (SETTING_HEIGHT - _circle_size.height) / 2);
1470 DrawString(rtl ? left : left + _circle_size.width + 2, rtl ? right - _circle_size.width - 2 : right, y + (SETTING_HEIGHT - FONT_HEIGHT_NORMAL) / 2, this->title);
1471 }
1472
1474 static SettingsContainer &GetSettingsTree()
1475 {
1476 static SettingsContainer *main = nullptr;
1477
1478 if (main == nullptr)
1479 {
1480 /* Build up the dynamic settings-array only once per OpenTTD session */
1481 main = new SettingsContainer();
1482
1483 SettingsPage *localisation = main->Add(new SettingsPage(STR_CONFIG_SETTING_LOCALISATION));
1484 {
1485 localisation->Add(new SettingEntry("locale.units_velocity"));
1486 localisation->Add(new SettingEntry("locale.units_power"));
1487 localisation->Add(new SettingEntry("locale.units_weight"));
1488 localisation->Add(new SettingEntry("locale.units_volume"));
1489 localisation->Add(new SettingEntry("locale.units_force"));
1490 localisation->Add(new SettingEntry("locale.units_height"));
1491 localisation->Add(new SettingEntry("gui.date_format_in_default_names"));
1492 }
1493
1494 SettingsPage *graphics = main->Add(new SettingsPage(STR_CONFIG_SETTING_GRAPHICS));
1495 {
1496 graphics->Add(new SettingEntry("gui.zoom_min"));
1497 graphics->Add(new SettingEntry("gui.zoom_max"));
1498 graphics->Add(new SettingEntry("gui.sprite_zoom_min"));
1499 graphics->Add(new SettingEntry("gui.smallmap_land_colour"));
1500 graphics->Add(new SettingEntry("gui.graph_line_thickness"));
1501 }
1502
1503 SettingsPage *sound = main->Add(new SettingsPage(STR_CONFIG_SETTING_SOUND));
1504 {
1505 sound->Add(new SettingEntry("sound.click_beep"));
1506 sound->Add(new SettingEntry("sound.confirm"));
1507 sound->Add(new SettingEntry("sound.news_ticker"));
1508 sound->Add(new SettingEntry("sound.news_full"));
1509 sound->Add(new SettingEntry("sound.new_year"));
1510 sound->Add(new SettingEntry("sound.disaster"));
1511 sound->Add(new SettingEntry("sound.vehicle"));
1512 sound->Add(new SettingEntry("sound.ambient"));
1513 }
1514
1515 SettingsPage *interface = main->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE));
1516 {
1517 SettingsPage *general = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_GENERAL));
1518 {
1519 general->Add(new SettingEntry("gui.osk_activation"));
1520 general->Add(new SettingEntry("gui.hover_delay_ms"));
1521 general->Add(new SettingEntry("gui.errmsg_duration"));
1522 general->Add(new SettingEntry("gui.window_snap_radius"));
1523 general->Add(new SettingEntry("gui.window_soft_limit"));
1524 general->Add(new SettingEntry("gui.right_mouse_wnd_close"));
1525 }
1526
1527 SettingsPage *viewports = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_VIEWPORTS));
1528 {
1529 viewports->Add(new SettingEntry("gui.auto_scrolling"));
1530 viewports->Add(new SettingEntry("gui.scroll_mode"));
1531 viewports->Add(new SettingEntry("gui.smooth_scroll"));
1532 /* While the horizontal scrollwheel scrolling is written as general code, only
1533 * the cocoa (OSX) driver generates input for it.
1534 * Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
1535 viewports->Add(new SettingEntry("gui.scrollwheel_scrolling"));
1536 viewports->Add(new SettingEntry("gui.scrollwheel_multiplier"));
1537 #ifdef __APPLE__
1538 /* We might need to emulate a right mouse button on mac */
1539 viewports->Add(new SettingEntry("gui.right_mouse_btn_emulation"));
1540 #endif
1541 viewports->Add(new SettingEntry("gui.population_in_label"));
1542 viewports->Add(new SettingEntry("gui.liveries"));
1543 viewports->Add(new SettingEntry("construction.train_signal_side"));
1544 viewports->Add(new SettingEntry("gui.measure_tooltip"));
1545 viewports->Add(new SettingEntry("gui.loading_indicators"));
1546 viewports->Add(new SettingEntry("gui.show_track_reservation"));
1547 }
1548
1549 SettingsPage *construction = interface->Add(new SettingsPage(STR_CONFIG_SETTING_INTERFACE_CONSTRUCTION));
1550 {
1551 construction->Add(new SettingEntry("gui.link_terraform_toolbar"));
1552 construction->Add(new SettingEntry("gui.enable_signal_gui"));
1553 construction->Add(new SettingEntry("gui.persistent_buildingtools"));
1554 construction->Add(new SettingEntry("gui.quick_goto"));
1555 construction->Add(new SettingEntry("gui.default_rail_type"));
1556 }
1557
1558 interface->Add(new SettingEntry("gui.fast_forward_speed_limit"));
1559 interface->Add(new SettingEntry("gui.autosave"));
1560 interface->Add(new SettingEntry("gui.toolbar_pos"));
1561 interface->Add(new SettingEntry("gui.statusbar_pos"));
1562 interface->Add(new SettingEntry("gui.prefer_teamchat"));
1563 interface->Add(new SettingEntry("gui.advanced_vehicle_list"));
1564 interface->Add(new SettingEntry("gui.timetable_in_ticks"));
1565 interface->Add(new SettingEntry("gui.timetable_arrival_departure"));
1566 interface->Add(new SettingEntry("gui.expenses_layout"));
1567 interface->Add(new SettingEntry("gui.show_newgrf_name"));
1568 }
1569
1570 SettingsPage *advisors = main->Add(new SettingsPage(STR_CONFIG_SETTING_ADVISORS));
1571 {
1572 advisors->Add(new SettingEntry("gui.coloured_news_year"));
1573 advisors->Add(new SettingEntry("news_display.general"));
1574 advisors->Add(new SettingEntry("news_display.new_vehicles"));
1575 advisors->Add(new SettingEntry("news_display.accident"));
1576 advisors->Add(new SettingEntry("news_display.company_info"));
1577 advisors->Add(new SettingEntry("news_display.acceptance"));
1578 advisors->Add(new SettingEntry("news_display.arrival_player"));
1579 advisors->Add(new SettingEntry("news_display.arrival_other"));
1580 advisors->Add(new SettingEntry("news_display.advice"));
1581 advisors->Add(new SettingEntry("gui.order_review_system"));
1582 advisors->Add(new SettingEntry("gui.vehicle_income_warn"));
1583 advisors->Add(new SettingEntry("gui.lost_vehicle_warn"));
1584 advisors->Add(new SettingEntry("gui.show_finances"));
1585 advisors->Add(new SettingEntry("news_display.economy"));
1586 advisors->Add(new SettingEntry("news_display.subsidies"));
1587 advisors->Add(new SettingEntry("news_display.open"));
1588 advisors->Add(new SettingEntry("news_display.close"));
1589 advisors->Add(new SettingEntry("news_display.production_player"));
1590 advisors->Add(new SettingEntry("news_display.production_other"));
1591 advisors->Add(new SettingEntry("news_display.production_nobody"));
1592 }
1593
1594 SettingsPage *company = main->Add(new SettingsPage(STR_CONFIG_SETTING_COMPANY));
1595 {
1596 company->Add(new SettingEntry("gui.semaphore_build_before"));
1597 company->Add(new SettingEntry("gui.default_signal_type"));
1598 company->Add(new SettingEntry("gui.cycle_signal_types"));
1599 company->Add(new SettingEntry("gui.drag_signals_fixed_distance"));
1600 company->Add(new SettingEntry("gui.auto_remove_signals"));
1601 company->Add(new SettingEntry("gui.new_nonstop"));
1602 company->Add(new SettingEntry("gui.stop_location"));
1603 company->Add(new SettingEntry("gui.starting_colour"));
1604 company->Add(new SettingEntry("company.engine_renew"));
1605 company->Add(new SettingEntry("company.engine_renew_months"));
1606 company->Add(new SettingEntry("company.engine_renew_money"));
1607 company->Add(new SettingEntry("vehicle.servint_ispercent"));
1608 company->Add(new SettingEntry("vehicle.servint_trains"));
1609 company->Add(new SettingEntry("vehicle.servint_roadveh"));
1610 company->Add(new SettingEntry("vehicle.servint_ships"));
1611 company->Add(new SettingEntry("vehicle.servint_aircraft"));
1612 }
1613
1614 SettingsPage *accounting = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCOUNTING));
1615 {
1616 accounting->Add(new SettingEntry("economy.inflation"));
1617 accounting->Add(new SettingEntry("difficulty.initial_interest"));
1618 accounting->Add(new SettingEntry("difficulty.max_loan"));
1619 accounting->Add(new SettingEntry("difficulty.subsidy_multiplier"));
1620 accounting->Add(new SettingEntry("economy.feeder_payment_share"));
1621 accounting->Add(new SettingEntry("economy.infrastructure_maintenance"));
1622 accounting->Add(new SettingEntry("difficulty.vehicle_costs"));
1623 accounting->Add(new SettingEntry("difficulty.construction_cost"));
1624 }
1625
1626 SettingsPage *vehicles = main->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES));
1627 {
1628 SettingsPage *physics = vehicles->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES_PHYSICS));
1629 {
1630 physics->Add(new SettingEntry("vehicle.train_acceleration_model"));
1631 physics->Add(new SettingEntry("vehicle.train_slope_steepness"));
1632 physics->Add(new SettingEntry("vehicle.wagon_speed_limits"));
1633 physics->Add(new SettingEntry("vehicle.freight_trains"));
1634 physics->Add(new SettingEntry("vehicle.roadveh_acceleration_model"));
1635 physics->Add(new SettingEntry("vehicle.roadveh_slope_steepness"));
1636 physics->Add(new SettingEntry("vehicle.smoke_amount"));
1637 physics->Add(new SettingEntry("vehicle.plane_speed"));
1638 }
1639
1640 SettingsPage *routing = vehicles->Add(new SettingsPage(STR_CONFIG_SETTING_VEHICLES_ROUTING));
1641 {
1642 routing->Add(new SettingEntry("pf.pathfinder_for_trains"));
1643 routing->Add(new SettingEntry("difficulty.line_reverse_mode"));
1644 routing->Add(new SettingEntry("pf.reverse_at_signals"));
1645 routing->Add(new SettingEntry("pf.forbid_90_deg"));
1646 routing->Add(new SettingEntry("pf.pathfinder_for_roadvehs"));
1647 routing->Add(new SettingEntry("pf.pathfinder_for_ships"));
1648 }
1649
1650 vehicles->Add(new SettingEntry("order.no_servicing_if_no_breakdowns"));
1651 vehicles->Add(new SettingEntry("order.serviceathelipad"));
1652 }
1653
1654 SettingsPage *limitations = main->Add(new SettingsPage(STR_CONFIG_SETTING_LIMITATIONS));
1655 {
1656 limitations->Add(new SettingEntry("construction.command_pause_level"));
1657 limitations->Add(new SettingEntry("construction.autoslope"));
1658 limitations->Add(new SettingEntry("construction.extra_dynamite"));
1659 limitations->Add(new SettingEntry("construction.max_heightlevel"));
1660 limitations->Add(new SettingEntry("construction.max_bridge_length"));
1661 limitations->Add(new SettingEntry("construction.max_bridge_height"));
1662 limitations->Add(new SettingEntry("construction.max_tunnel_length"));
1663 limitations->Add(new SettingEntry("station.never_expire_airports"));
1664 limitations->Add(new SettingEntry("vehicle.never_expire_vehicles"));
1665 limitations->Add(new SettingEntry("vehicle.max_trains"));
1666 limitations->Add(new SettingEntry("vehicle.max_roadveh"));
1667 limitations->Add(new SettingEntry("vehicle.max_aircraft"));
1668 limitations->Add(new SettingEntry("vehicle.max_ships"));
1669 limitations->Add(new SettingEntry("vehicle.max_train_length"));
1670 limitations->Add(new SettingEntry("station.station_spread"));
1671 limitations->Add(new SettingEntry("station.distant_join_stations"));
1672 limitations->Add(new SettingEntry("construction.road_stop_on_town_road"));
1673 limitations->Add(new SettingEntry("construction.road_stop_on_competitor_road"));
1674 limitations->Add(new SettingEntry("vehicle.disable_elrails"));
1675 }
1676
1677 SettingsPage *disasters = main->Add(new SettingsPage(STR_CONFIG_SETTING_ACCIDENTS));
1678 {
1679 disasters->Add(new SettingEntry("difficulty.disasters"));
1680 disasters->Add(new SettingEntry("difficulty.economy"));
1681 disasters->Add(new SettingEntry("difficulty.vehicle_breakdowns"));
1682 disasters->Add(new SettingEntry("vehicle.plane_crashes"));
1683 }
1684
1685 SettingsPage *genworld = main->Add(new SettingsPage(STR_CONFIG_SETTING_GENWORLD));
1686 {
1687 genworld->Add(new SettingEntry("game_creation.landscape"));
1688 genworld->Add(new SettingEntry("game_creation.land_generator"));
1689 genworld->Add(new SettingEntry("difficulty.terrain_type"));
1690 genworld->Add(new SettingEntry("game_creation.tgen_smoothness"));
1691 genworld->Add(new SettingEntry("game_creation.variety"));
1692 genworld->Add(new SettingEntry("game_creation.snow_line_height"));
1693 genworld->Add(new SettingEntry("game_creation.amount_of_rivers"));
1694 genworld->Add(new SettingEntry("game_creation.tree_placer"));
1695 genworld->Add(new SettingEntry("vehicle.road_side"));
1696 genworld->Add(new SettingEntry("economy.larger_towns"));
1697 genworld->Add(new SettingEntry("economy.initial_city_size"));
1698 genworld->Add(new SettingEntry("economy.town_layout"));
1699 genworld->Add(new SettingEntry("difficulty.industry_density"));
1700 genworld->Add(new SettingEntry("gui.pause_on_newgame"));
1701 genworld->Add(new SettingEntry("game_creation.ending_year"));
1702 }
1703
1704 SettingsPage *environment = main->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT));
1705 {
1706 SettingsPage *authorities = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_AUTHORITIES));
1707 {
1708 authorities->Add(new SettingEntry("difficulty.town_council_tolerance"));
1709 authorities->Add(new SettingEntry("economy.bribe"));
1710 authorities->Add(new SettingEntry("economy.exclusive_rights"));
1711 authorities->Add(new SettingEntry("economy.fund_roads"));
1712 authorities->Add(new SettingEntry("economy.fund_buildings"));
1713 authorities->Add(new SettingEntry("economy.station_noise_level"));
1714 }
1715
1716 SettingsPage *towns = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_TOWNS));
1717 {
1718 towns->Add(new SettingEntry("economy.town_growth_rate"));
1719 towns->Add(new SettingEntry("economy.allow_town_roads"));
1720 towns->Add(new SettingEntry("economy.allow_town_level_crossings"));
1721 towns->Add(new SettingEntry("economy.found_town"));
1722 towns->Add(new SettingEntry("economy.town_cargogen_mode"));
1723 }
1724
1725 SettingsPage *industries = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_INDUSTRIES));
1726 {
1727 industries->Add(new SettingEntry("construction.raw_industry_construction"));
1728 industries->Add(new SettingEntry("construction.industry_platform"));
1729 industries->Add(new SettingEntry("economy.multiple_industry_per_town"));
1730 industries->Add(new SettingEntry("game_creation.oil_refinery_limit"));
1731 industries->Add(new SettingEntry("economy.type"));
1732 industries->Add(new SettingEntry("station.serve_neutral_industries"));
1733 }
1734
1735 SettingsPage *cdist = environment->Add(new SettingsPage(STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST));
1736 {
1737 cdist->Add(new SettingEntry("linkgraph.recalc_time"));
1738 cdist->Add(new SettingEntry("linkgraph.recalc_interval"));
1739 cdist->Add(new SettingEntry("linkgraph.distribution_pax"));
1740 cdist->Add(new SettingEntry("linkgraph.distribution_mail"));
1741 cdist->Add(new SettingEntry("linkgraph.distribution_armoured"));
1742 cdist->Add(new SettingEntry("linkgraph.distribution_default"));
1743 cdist->Add(new SettingEntry("linkgraph.accuracy"));
1744 cdist->Add(new SettingEntry("linkgraph.demand_distance"));
1745 cdist->Add(new SettingEntry("linkgraph.demand_size"));
1746 cdist->Add(new SettingEntry("linkgraph.short_path_saturation"));
1747 }
1748
1749 environment->Add(new SettingEntry("station.modified_catchment"));
1750 environment->Add(new SettingEntry("construction.extra_tree_placement"));
1751 }
1752
1753 SettingsPage *ai = main->Add(new SettingsPage(STR_CONFIG_SETTING_AI));
1754 {
1755 SettingsPage *npc = ai->Add(new SettingsPage(STR_CONFIG_SETTING_AI_NPC));
1756 {
1757 npc->Add(new SettingEntry("script.settings_profile"));
1758 npc->Add(new SettingEntry("script.script_max_opcode_till_suspend"));
1759 npc->Add(new SettingEntry("script.script_max_memory_megabytes"));
1760 npc->Add(new SettingEntry("difficulty.competitor_speed"));
1761 npc->Add(new SettingEntry("ai.ai_in_multiplayer"));
1762 npc->Add(new SettingEntry("ai.ai_disable_veh_train"));
1763 npc->Add(new SettingEntry("ai.ai_disable_veh_roadveh"));
1764 npc->Add(new SettingEntry("ai.ai_disable_veh_aircraft"));
1765 npc->Add(new SettingEntry("ai.ai_disable_veh_ship"));
1766 }
1767
1768 ai->Add(new SettingEntry("economy.give_money"));
1769 ai->Add(new SettingEntry("economy.allow_shares"));
1770 ai->Add(new SettingEntry("economy.min_years_for_shares"));
1771 }
1772
1773 main->Init();
1774 }
1775 return *main;
1776 }
1777
1778 static const StringID _game_settings_restrict_dropdown[] = {
1779 STR_CONFIG_SETTING_RESTRICT_BASIC, // RM_BASIC
1780 STR_CONFIG_SETTING_RESTRICT_ADVANCED, // RM_ADVANCED
1781 STR_CONFIG_SETTING_RESTRICT_ALL, // RM_ALL
1782 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT, // RM_CHANGED_AGAINST_DEFAULT
1783 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW, // RM_CHANGED_AGAINST_NEW
1784 };
1785 static_assert(lengthof(_game_settings_restrict_dropdown) == RM_END);
1786
1788 enum WarnHiddenResult {
1789 WHR_NONE,
1790 WHR_CATEGORY,
1791 WHR_TYPE,
1792 WHR_CATEGORY_TYPE,
1793 };
1794
1796 struct GameSettingsWindow : Window {
1797 static const int SETTINGTREE_LEFT_OFFSET = 5;
1798 static const int SETTINGTREE_RIGHT_OFFSET = 5;
1799 static const int SETTINGTREE_TOP_OFFSET = 5;
1800 static const int SETTINGTREE_BOTTOM_OFFSET = 5;
1801
1802 static GameSettings *settings_ptr;
1803
1804 SettingEntry *valuewindow_entry;
1805 SettingEntry *clicked_entry;
1806 SettingEntry *last_clicked;
1807 SettingEntry *valuedropdown_entry;
1808 bool closing_dropdown;
1809
1810 SettingFilter filter;
1811 QueryString filter_editbox;
1812 bool manually_changed_folding;
1813 WarnHiddenResult warn_missing;
1814 int warn_lines;
1815
1816 Scrollbar *vscroll;
1817
1818 GameSettingsWindow(WindowDesc *desc) : Window(desc), filter_editbox(50)
1819 {
1820 this->warn_missing = WHR_NONE;
1821 this->warn_lines = 0;
1822 this->filter.mode = (RestrictionMode)_settings_client.gui.settings_restriction_mode;
1823 this->filter.min_cat = RM_ALL;
1824 this->filter.type = ST_ALL;
1825 this->filter.type_hides = false;
1826 this->settings_ptr = &GetGameSettings();
1827
1828 _circle_size = maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED), GetSpriteSize(SPR_CIRCLE_UNFOLDED));
1829 GetSettingsTree().FoldAll(); // Close all sub-pages
1830
1831 this->valuewindow_entry = nullptr; // No setting entry for which a entry window is opened
1832 this->clicked_entry = nullptr; // No numeric setting buttons are depressed
1833 this->last_clicked = nullptr;
1834 this->valuedropdown_entry = nullptr;
1835 this->closing_dropdown = false;
1836 this->manually_changed_folding = false;
1837
1838 this->CreateNestedTree();
1839 this->vscroll = this->GetScrollbar(WID_GS_SCROLLBAR);
1840 this->FinishInitNested(WN_GAME_OPTIONS_GAME_SETTINGS);
1841
1842 this->querystrings[WID_GS_FILTER] = &this->filter_editbox;
1843 this->filter_editbox.cancel_button = QueryString::ACTION_CLEAR;
1844 this->SetFocusedWidget(WID_GS_FILTER);
1845
1846 this->InvalidateData();
1847 }
1848
1849 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
1850 {
1851 switch (widget) {
1852 case WID_GS_OPTIONSPANEL:
1853 resize->height = SETTING_HEIGHT = std::max({(int)_circle_size.height, SETTING_BUTTON_HEIGHT, FONT_HEIGHT_NORMAL}) + 1;
1854 resize->width = 1;
1855
1856 size->height = 5 * resize->height + SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET;
1857 break;
1858
1859 case WID_GS_HELP_TEXT: {
1860 static const StringID setting_types[] = {
1861 STR_CONFIG_SETTING_TYPE_CLIENT,
1862 STR_CONFIG_SETTING_TYPE_COMPANY_MENU, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME,
1863 STR_CONFIG_SETTING_TYPE_GAME_MENU, STR_CONFIG_SETTING_TYPE_GAME_INGAME,
1864 };
1865 for (uint i = 0; i < lengthof(setting_types); i++) {
1866 SetDParam(0, setting_types[i]);
1867 size->width = std::max(size->width, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE).width);
1868 }
1869 size->height = 2 * FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL +
1870 std::max(size->height, GetSettingsTree().GetMaxHelpHeight(size->width));
1871 break;
1872 }
1873
1874 case WID_GS_RESTRICT_CATEGORY:
1875 case WID_GS_RESTRICT_TYPE:
1876 size->width = std::max(GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_CATEGORY).width, GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_TYPE).width);
1877 break;
1878
1879 default:
1880 break;
1881 }
1882 }
1883
1884 void OnPaint() override
1885 {
1886 if (this->closing_dropdown) {
1887 this->closing_dropdown = false;
1888 assert(this->valuedropdown_entry != nullptr);
1889 this->valuedropdown_entry->SetButtons(0);
1890 this->valuedropdown_entry = nullptr;
1891 }
1892
1893 /* Reserve the correct number of lines for the 'some search results are hidden' notice in the central settings display panel. */
1894 const NWidgetBase *panel = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
1895 StringID warn_str = STR_CONFIG_SETTING_CATEGORY_HIDES - 1 + this->warn_missing;
1896 int new_warn_lines;
1897 if (this->warn_missing == WHR_NONE) {
1898 new_warn_lines = 0;
1899 } else {
1900 SetDParam(0, _game_settings_restrict_dropdown[this->filter.min_cat]);
1901 new_warn_lines = GetStringLineCount(warn_str, panel->current_x);
1902 }
1903 if (this->warn_lines != new_warn_lines) {
1904 this->vscroll->SetCount(this->vscroll->GetCount() - this->warn_lines + new_warn_lines);
1905 this->warn_lines = new_warn_lines;
1906 }
1907
1908 this->DrawWidgets();
1909
1910 /* Draw the 'some search results are hidden' notice. */
1911 if (this->warn_missing != WHR_NONE) {
1912 const int left = panel->pos_x;
1913 const int right = left + panel->current_x - 1;
1914 const int top = panel->pos_y + WD_FRAMETEXT_TOP + (SETTING_HEIGHT - FONT_HEIGHT_NORMAL) * this->warn_lines / 2;
1915 SetDParam(0, _game_settings_restrict_dropdown[this->filter.min_cat]);
1916 if (this->warn_lines == 1) {
1917 /* If the warning fits at one line, center it. */
1918 DrawString(left + WD_FRAMETEXT_LEFT, right - WD_FRAMETEXT_RIGHT, top, warn_str, TC_FROMSTRING, SA_HOR_CENTER);
1919 } else {
1920 DrawStringMultiLine(left + WD_FRAMERECT_LEFT, right - WD_FRAMERECT_RIGHT, top, INT32_MAX, warn_str, TC_FROMSTRING, SA_HOR_CENTER);
1921 }
1922 }
1923 }
1924
1925 void SetStringParameters(int widget) const override
1926 {
1927 switch (widget) {
1928 case WID_GS_RESTRICT_DROPDOWN:
1929 SetDParam(0, _game_settings_restrict_dropdown[this->filter.mode]);
1930 break;
1931
1932 case WID_GS_TYPE_DROPDOWN:
1933 switch (this->filter.type) {
1934 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME); break;
1935 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME); break;
1936 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT); break;
1937 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL); break;
1938 }
1939 break;
1940 }
1941 }
1942
1943 DropDownList BuildDropDownList(int widget) const
1944 {
1945 DropDownList list;
1946 switch (widget) {
1947 case WID_GS_RESTRICT_DROPDOWN:
1948 for (int mode = 0; mode != RM_END; mode++) {
1949 /* If we are in adv. settings screen for the new game's settings,
1950 * we don't want to allow comparing with new game's settings. */
1951 bool disabled = mode == RM_CHANGED_AGAINST_NEW && settings_ptr == &_settings_newgame;
1952
1953 list.emplace_back(new DropDownListStringItem(_game_settings_restrict_dropdown[mode], mode, disabled));
1954 }
1955 break;
1956
1957 case WID_GS_TYPE_DROPDOWN:
1958 list.emplace_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL, ST_ALL, false));
1959 list.emplace_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME, ST_GAME, false));
1960 list.emplace_back(new DropDownListStringItem(_game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME, ST_COMPANY, false));
1961 list.emplace_back(new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT, ST_CLIENT, false));
1962 break;
1963 }
1964 return list;
1965 }
1966
1967 void DrawWidget(const Rect &r, int widget) const override
1968 {
1969 switch (widget) {
1970 case WID_GS_OPTIONSPANEL: {
1971 int top_pos = r.top + SETTINGTREE_TOP_OFFSET + 1 + this->warn_lines * SETTING_HEIGHT;
1972 uint last_row = this->vscroll->GetPosition() + this->vscroll->GetCapacity() - this->warn_lines;
1973 int next_row = GetSettingsTree().Draw(settings_ptr, r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, top_pos,
1974 this->vscroll->GetPosition(), last_row, this->last_clicked);
1975 if (next_row == 0) DrawString(r.left + SETTINGTREE_LEFT_OFFSET, r.right - SETTINGTREE_RIGHT_OFFSET, top_pos, STR_CONFIG_SETTINGS_NONE);
1976 break;
1977 }
1978
1979 case WID_GS_HELP_TEXT:
1980 if (this->last_clicked != nullptr) {
1981 const SettingDesc *sd = this->last_clicked->setting;
1982
1983 int y = r.top;
1984 switch (sd->GetType()) {
1985 case ST_COMPANY: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_COMPANY_MENU : STR_CONFIG_SETTING_TYPE_COMPANY_INGAME); break;
1986 case ST_CLIENT: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT); break;
1987 case ST_GAME: SetDParam(0, _game_mode == GM_MENU ? STR_CONFIG_SETTING_TYPE_GAME_MENU : STR_CONFIG_SETTING_TYPE_GAME_INGAME); break;
1988 default: NOT_REACHED();
1989 }
1990 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_TYPE);
1991 y += FONT_HEIGHT_NORMAL;
1992
1993 int32 default_value = ReadValue(&sd->desc.def, sd->save.conv);
1994 this->last_clicked->SetValueDParams(0, default_value);
1995 DrawString(r.left, r.right, y, STR_CONFIG_SETTING_DEFAULT_VALUE);
1996 y += FONT_HEIGHT_NORMAL + WD_PAR_VSEP_NORMAL;
1997
1998 DrawStringMultiLine(r.left, r.right, y, r.bottom, this->last_clicked->GetHelpText(), TC_WHITE);
1999 }
2000 break;
2001
2002 default:
2003 break;
2004 }
2005 }
2006
2011 void SetDisplayedHelpText(SettingEntry *pe)
2012 {
2013 if (this->last_clicked != pe) this->SetDirty();
2014 this->last_clicked = pe;
2015 }
2016
2017 void OnClick(Point pt, int widget, int click_count) override
2018 {
2019 switch (widget) {
2020 case WID_GS_EXPAND_ALL:
2021 this->manually_changed_folding = true;
2022 GetSettingsTree().UnFoldAll();
2023 this->InvalidateData();
2024 break;
2025
2026 case WID_GS_COLLAPSE_ALL:
2027 this->manually_changed_folding = true;
2028 GetSettingsTree().FoldAll();
2029 this->InvalidateData();
2030 break;
2031
2032 case WID_GS_RESTRICT_DROPDOWN: {
2033 DropDownList list = this->BuildDropDownList(widget);
2034 if (!list.empty()) {
2035 ShowDropDownList(this, std::move(list), this->filter.mode, widget);
2036 }
2037 break;
2038 }
2039
2040 case WID_GS_TYPE_DROPDOWN: {
2041 DropDownList list = this->BuildDropDownList(widget);
2042 if (!list.empty()) {
2043 ShowDropDownList(this, std::move(list), this->filter.type, widget);
2044 }
2045 break;
2046 }
2047 }
2048
2049 if (widget != WID_GS_OPTIONSPANEL) return;
2050
2051 uint btn = this->vscroll->GetScrolledRowFromWidget(pt.y, this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET);
2052 if (btn == INT_MAX || (int)btn < this->warn_lines) return;
2053 btn -= this->warn_lines;
2054
2055 uint cur_row = 0;
2056 BaseSettingEntry *clicked_entry = GetSettingsTree().FindEntry(btn, &cur_row);
2057
2058 if (clicked_entry == nullptr) return; // Clicked below the last setting of the page
2059
2060 int x = (_current_text_dir == TD_RTL ? this->width - 1 - pt.x : pt.x) - SETTINGTREE_LEFT_OFFSET - (clicked_entry->level + 1) * LEVEL_WIDTH; // Shift x coordinate
2061 if (x < 0) return; // Clicked left of the entry
2062
2063 SettingsPage *clicked_page = dynamic_cast<SettingsPage*>(clicked_entry);
2064 if (clicked_page != nullptr) {
2065 this->SetDisplayedHelpText(nullptr);
2066 clicked_page->folded = !clicked_page->folded; // Flip 'folded'-ness of the sub-page
2067
2068 this->manually_changed_folding = true;
2069
2070 this->InvalidateData();
2071 return;
2072 }
2073
2074 SettingEntry *pe = dynamic_cast<SettingEntry*>(clicked_entry);
2075 assert(pe != nullptr);
2076 const SettingDesc *sd = pe->setting;
2077
2078 /* return if action is only active in network, or only settable by server */
2079 if (!sd->IsEditable()) {
2080 this->SetDisplayedHelpText(pe);
2081 return;
2082 }
2083
2084 const void *var = ResolveVariableAddress(settings_ptr, sd);
2085 int32 value = (int32)ReadValue(var, sd->save.conv);
2086
2087 /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
2088 if (x < SETTING_BUTTON_WIDTH && (sd->desc.flags & SGF_MULTISTRING)) {
2089 const SettingDescBase *sdb = &sd->desc;
2090 this->SetDisplayedHelpText(pe);
2091
2092 if (this->valuedropdown_entry == pe) {
2093 /* unclick the dropdown */
2094 HideDropDownMenu(this);
2095 this->closing_dropdown = false;
2096 this->valuedropdown_entry->SetButtons(0);
2097 this->valuedropdown_entry = nullptr;
2098 } else {
2099 if (this->valuedropdown_entry != nullptr) this->valuedropdown_entry->SetButtons(0);
2100 this->closing_dropdown = false;
2101
2102 const NWidgetBase *wid = this->GetWidget<NWidgetBase>(WID_GS_OPTIONSPANEL);
2103 int rel_y = (pt.y - (int)wid->pos_y - SETTINGTREE_TOP_OFFSET) % wid->resize_y;
2104
2105 Rect wi_rect;
2106 wi_rect.left = pt.x - (_current_text_dir == TD_RTL ? SETTING_BUTTON_WIDTH - 1 - x : x);
2107 wi_rect.right = wi_rect.left + SETTING_BUTTON_WIDTH - 1;
2108 wi_rect.top = pt.y - rel_y + (SETTING_HEIGHT - SETTING_BUTTON_HEIGHT) / 2;
2109 wi_rect.bottom = wi_rect.top + SETTING_BUTTON_HEIGHT - 1;
2110
2111 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
2112 if (pt.y >= wi_rect.top && pt.y <= wi_rect.bottom) {
2113 this->valuedropdown_entry = pe;
2114 this->valuedropdown_entry->SetButtons(SEF_LEFT_DEPRESSED);
2115
2116 DropDownList list;
2117 for (int i = sdb->min; i <= (int)sdb->max; i++) {
2118 list.emplace_back(new DropDownListStringItem(sdb->str_val + i - sdb->min, i, false));
2119 }
2120
2121 ShowDropDownListAt(this, std::move(list), value, -1, wi_rect, COLOUR_ORANGE, true);
2122 }
2123 }
2124 this->SetDirty();
2125 } else if (x < SETTING_BUTTON_WIDTH) {
2126 this->SetDisplayedHelpText(pe);
2127 const SettingDescBase *sdb = &sd->desc;
2128 int32 oldvalue = value;
2129
2130 switch (sdb->cmd) {
2131 case SDT_BOOLX: value ^= 1; break;
2132 case SDT_ONEOFMANY:
2133 case SDT_NUMX: {
2134 /* Add a dynamic step-size to the scroller. In a maximum of
2135 * 50-steps you should be able to get from min to max,
2136 * unless specified otherwise in the 'interval' variable
2137 * of the current setting. */
2138 uint32 step = (sdb->interval == 0) ? ((sdb->max - sdb->min) / 50) : sdb->interval;
2139 if (step == 0) step = 1;
2140
2141 /* don't allow too fast scrolling */
2142 if ((this->flags & WF_TIMEOUT) && this->timeout_timer > 1) {
2143 _left_button_clicked = false;
2144 return;
2145 }
2146
2147 /* Increase or decrease the value and clamp it to extremes */
2148 if (x >= SETTING_BUTTON_WIDTH / 2) {
2149 value += step;
2150 if (sdb->min < 0) {
2151 assert((int32)sdb->max >= 0);
2152 if (value > (int32)sdb->max) value = (int32)sdb->max;
2153 } else {
2154 if ((uint32)value > sdb->max) value = (int32)sdb->max;
2155 }
2156 if (value < sdb->min) value = sdb->min; // skip between "disabled" and minimum
2157 } else {
2158 value -= step;
2159 if (value < sdb->min) value = (sdb->flags & SGF_0ISDISABLED) ? 0 : sdb->min;
2160 }
2161
2162 /* Set up scroller timeout for numeric values */
2163 if (value != oldvalue) {
2164 if (this->clicked_entry != nullptr) { // Release previous buttons if any
2165 this->clicked_entry->SetButtons(0);
2166 }
2167 this->clicked_entry = pe;
2168 this->clicked_entry->SetButtons((x >= SETTING_BUTTON_WIDTH / 2) != (_current_text_dir == TD_RTL) ? SEF_RIGHT_DEPRESSED : SEF_LEFT_DEPRESSED);
2169 this->SetTimeout();
2170 _left_button_clicked = false;
2171 }
2172 break;
2173 }
2174
2175 default: NOT_REACHED();
2176 }
2177
2178 if (value != oldvalue) {
2179 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2180 SetCompanySetting(pe->index, value);
2181 } else {
2182 SetSettingValue(pe->index, value);
2183 }
2184 this->SetDirty();
2185 }
2186 } else {
2187 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
2188 if (this->last_clicked == pe && sd->desc.cmd != SDT_BOOLX && !(sd->desc.flags & SGF_MULTISTRING)) {
2189 int64 value64 = value;
2190 /* Show the correct currency-translated value */
2191 if (sd->desc.flags & SGF_CURRENCY) value64 *= _currency->rate;
2192
2193 this->valuewindow_entry = pe;
2194 SetDParam(0, value64);
2195 /* Limit string length to 14 so that MAX_INT32 * max currency rate doesn't exceed MAX_INT64. */
2196 ShowQueryString(STR_JUST_INT, STR_CONFIG_SETTING_QUERY_CAPTION, 15, this, CS_NUMERAL, QSF_ENABLE_DEFAULT);
2197 }
2198 this->SetDisplayedHelpText(pe);
2199 }
2200 }
2201
2202 void OnTimeout() override
2203 {
2204 if (this->clicked_entry != nullptr) { // On timeout, release any depressed buttons
2205 this->clicked_entry->SetButtons(0);
2206 this->clicked_entry = nullptr;
2207 this->SetDirty();
2208 }
2209 }
2210
2211 void OnQueryTextFinished(char *str) override
2212 {
2213 /* The user pressed cancel */
2214 if (str == nullptr) return;
2215
2216 assert(this->valuewindow_entry != nullptr);
2217 const SettingDesc *sd = this->valuewindow_entry->setting;
2218
2219 int32 value;
2220 if (!StrEmpty(str)) {
2221 long long llvalue = atoll(str);
2222
2223 /* Save the correct currency-translated value */
2224 if (sd->desc.flags & SGF_CURRENCY) llvalue /= _currency->rate;
2225
2226 value = (int32)ClampToI32(llvalue);
2227 } else {
2228 value = (int32)(size_t)sd->desc.def;
2229 }
2230
2231 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2232 SetCompanySetting(this->valuewindow_entry->index, value);
2233 } else {
2234 SetSettingValue(this->valuewindow_entry->index, value);
2235 }
2236 this->SetDirty();
2237 }
2238
2239 void OnDropdownSelect(int widget, int index) override
2240 {
2241 switch (widget) {
2242 case WID_GS_RESTRICT_DROPDOWN:
2243 this->filter.mode = (RestrictionMode)index;
2244 if (this->filter.mode == RM_CHANGED_AGAINST_DEFAULT ||
2245 this->filter.mode == RM_CHANGED_AGAINST_NEW) {
2246
2247 if (!this->manually_changed_folding) {
2248 /* Expand all when selecting 'changes'. Update the filter state first, in case it becomes less restrictive in some cases. */
2249 GetSettingsTree().UpdateFilterState(this->filter, false);
2250 GetSettingsTree().UnFoldAll();
2251 }
2252 } else {
2253 /* Non-'changes' filter. Save as default. */
2254 _settings_client.gui.settings_restriction_mode = this->filter.mode;
2255 }
2256 this->InvalidateData();
2257 break;
2258
2259 case WID_GS_TYPE_DROPDOWN:
2260 this->filter.type = (SettingType)index;
2261 this->InvalidateData();
2262 break;
2263
2264 default:
2265 if (widget < 0) {
2266 /* Deal with drop down boxes on the panel. */
2267 assert(this->valuedropdown_entry != nullptr);
2268 const SettingDesc *sd = this->valuedropdown_entry->setting;
2269 assert(sd->desc.flags & SGF_MULTISTRING);
2270
2271 if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
2272 SetCompanySetting(this->valuedropdown_entry->index, index);
2273 } else {
2274 SetSettingValue(this->valuedropdown_entry->index, index);
2275 }
2276
2277 this->SetDirty();
2278 }
2279 break;
2280 }
2281 }
2282
2283 void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
2284 {
2285 if (widget >= 0) {
2286 /* Normally the default implementation of OnDropdownClose() takes care of
2287 * a few things. We want that behaviour here too, but only for
2288 * "normal" dropdown boxes. The special dropdown boxes added for every
2289 * setting that needs one can't have this call. */
2290 Window::OnDropdownClose(pt, widget, index, instant_close);
2291 } else {
2292 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
2293 * the same dropdown button was clicked again, and then not open the dropdown again.
2294 * So, we only remember that it was closed, and process it on the next OnPaint, which is
2295 * after OnClick. */
2296 assert(this->valuedropdown_entry != nullptr);
2297 this->closing_dropdown = true;
2298 this->SetDirty();
2299 }
2300 }
2301
2302 void OnInvalidateData(int data = 0, bool gui_scope = true) override
2303 {
2304 if (!gui_scope) return;
2305
2306 /* Update which settings are to be visible. */
2307 RestrictionMode min_level = (this->filter.mode <= RM_ALL) ? this->filter.mode : RM_BASIC;
2308 this->filter.min_cat = min_level;
2309 this->filter.type_hides = false;
2310 GetSettingsTree().UpdateFilterState(this->filter, false);
2311
2312 if (this->filter.string.IsEmpty()) {
2313 this->warn_missing = WHR_NONE;
2314 } else if (min_level < this->filter.min_cat) {
2315 this->warn_missing = this->filter.type_hides ? WHR_CATEGORY_TYPE : WHR_CATEGORY;
2316 } else {
2317 this->warn_missing = this->filter.type_hides ? WHR_TYPE : WHR_NONE;
2318 }
2319 this->vscroll->SetCount(GetSettingsTree().Length() + this->warn_lines);
2320
2321 if (this->last_clicked != nullptr && !GetSettingsTree().IsVisible(this->last_clicked)) {
2322 this->SetDisplayedHelpText(nullptr);
2323 }
2324
2325 bool all_folded = true;
2326 bool all_unfolded = true;
2327 GetSettingsTree().GetFoldingState(all_folded, all_unfolded);
2328 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL, all_unfolded);
2329 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL, all_folded);
2330 }
2331
2332 void OnEditboxChanged(int wid) override
2333 {
2334 if (wid == WID_GS_FILTER) {
2335 this->filter.string.SetFilterTerm(this->filter_editbox.text.buf);
2336 if (!this->filter.string.IsEmpty() && !this->manually_changed_folding) {
2337 /* User never expanded/collapsed single pages and entered a filter term.
2338 * Expand everything, to save weird expand clicks, */
2339 GetSettingsTree().UnFoldAll();
2340 }
2341 this->InvalidateData();
2342 }
2343 }
2344
2345 void OnResize() override
2346 {
2347 this->vscroll->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL, SETTINGTREE_TOP_OFFSET + SETTINGTREE_BOTTOM_OFFSET);
2348 }
2349 };
2350
2351 GameSettings *GameSettingsWindow::settings_ptr = nullptr;
2352
2353 static const NWidgetPart _nested_settings_selection_widgets[] = {
2354 NWidget(NWID_HORIZONTAL),
2355 NWidget(WWT_CLOSEBOX, COLOUR_MAUVE),
2356 NWidget(WWT_CAPTION, COLOUR_MAUVE), SetDataTip(STR_CONFIG_SETTING_TREE_CAPTION, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2357 NWidget(WWT_DEFSIZEBOX, COLOUR_MAUVE),
2358 EndContainer(),
2359 NWidget(WWT_PANEL, COLOUR_MAUVE),
2360 NWidget(NWID_VERTICAL), SetPIP(0, WD_PAR_VSEP_NORMAL, 0), SetPadding(WD_TEXTPANEL_TOP, 0, WD_TEXTPANEL_BOTTOM, 0),
2361 NWidget(NWID_HORIZONTAL), SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
2362 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_GS_RESTRICT_CATEGORY), SetDataTip(STR_CONFIG_SETTING_RESTRICT_CATEGORY, STR_NULL),
2363 NWidget(WWT_DROPDOWN, COLOUR_MAUVE, WID_GS_RESTRICT_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_BLACK_STRING, STR_CONFIG_SETTING_RESTRICT_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
2364 EndContainer(),
2365 NWidget(NWID_HORIZONTAL), SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
2366 NWidget(WWT_TEXT, COLOUR_MAUVE, WID_GS_RESTRICT_TYPE), SetDataTip(STR_CONFIG_SETTING_RESTRICT_TYPE, STR_NULL),
2367 NWidget(WWT_DROPDOWN, COLOUR_MAUVE, WID_GS_TYPE_DROPDOWN), SetMinimalSize(100, 12), SetDataTip(STR_BLACK_STRING, STR_CONFIG_SETTING_TYPE_DROPDOWN_HELPTEXT), SetFill(1, 0), SetResize(1, 0),
2368 EndContainer(),
2369 EndContainer(),
2370 NWidget(NWID_HORIZONTAL), SetPadding(0, 0, WD_TEXTPANEL_BOTTOM, 0),
2371 SetPIP(WD_FRAMETEXT_LEFT, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_RIGHT),
2372 NWidget(WWT_TEXT, COLOUR_MAUVE), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE, STR_NULL),
2373 NWidget(WWT_EDITBOX, COLOUR_MAUVE, WID_GS_FILTER), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
2374 SetDataTip(STR_LIST_FILTER_OSKTITLE, STR_LIST_FILTER_TOOLTIP),
2375 EndContainer(),
2376 EndContainer(),
2377 NWidget(NWID_HORIZONTAL),
2378 NWidget(WWT_PANEL, COLOUR_MAUVE, WID_GS_OPTIONSPANEL), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR), EndContainer(),
2379 NWidget(NWID_VSCROLLBAR, COLOUR_MAUVE, WID_GS_SCROLLBAR),
2380 EndContainer(),
2381 NWidget(WWT_PANEL, COLOUR_MAUVE), SetMinimalSize(400, 40),
2382 NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GS_HELP_TEXT), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
2383 SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT),
2384 EndContainer(),
2385 NWidget(NWID_HORIZONTAL),
2386 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_EXPAND_ALL), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL, STR_NULL),
2387 NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_COLLAPSE_ALL), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL, STR_NULL),
2388 NWidget(WWT_PANEL, COLOUR_MAUVE), SetFill(1, 0), SetResize(1, 0),
2389 EndContainer(),
2390 NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
2391 EndContainer(),
2392 };
2393
2394 static WindowDesc _settings_selection_desc(
2395 WDP_CENTER, "settings", 510, 450,
2396 WC_GAME_OPTIONS, WC_NONE,
2397 0,
2398 _nested_settings_selection_widgets, lengthof(_nested_settings_selection_widgets)
2399 );
2400
2402 void ShowGameSettings()
2403 {
2404 DeleteWindowByClass(WC_GAME_OPTIONS);
2405 new GameSettingsWindow(&_settings_selection_desc);
2406 }
2407
2408
2418 void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
2419 {
2420 int colour = _colour_gradient[button_colour][2];
2421 Dimension dim = NWidgetScrollbar::GetHorizontalDimension();
2422
2423 DrawFrameRect(x, y, x + dim.width - 1, y + dim.height - 1, button_colour, (state == 1) ? FR_LOWERED : FR_NONE);
2424 DrawFrameRect(x + dim.width, y, x + dim.width + dim.width - 1, y + dim.height - 1, button_colour, (state == 2) ? FR_LOWERED : FR_NONE);
2425 DrawSprite(SPR_ARROW_LEFT, PAL_NONE, x + WD_IMGBTN_LEFT, y + WD_IMGBTN_TOP);
2426 DrawSprite(SPR_ARROW_RIGHT, PAL_NONE, x + WD_IMGBTN_LEFT + dim.width, y + WD_IMGBTN_TOP);
2427
2428 /* Grey out the buttons that aren't clickable */
2429 bool rtl = _current_text_dir == TD_RTL;
2430 if (rtl ? !clickable_right : !clickable_left) {
2431 GfxFillRect(x + 1, y, x + dim.width - 1, y + dim.height - 2, colour, FILLRECT_CHECKER);
2432 }
2433 if (rtl ? !clickable_left : !clickable_right) {
2434 GfxFillRect(x + dim.width + 1, y, x + dim.width + dim.width - 1, y + dim.height - 2, colour, FILLRECT_CHECKER);
2435 }
2436 }
2437
2446 void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
2447 {
2448 int colour = _colour_gradient[button_colour][2];
2449
2450 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, button_colour, state ? FR_LOWERED : FR_NONE);
2451 DrawSprite(SPR_ARROW_DOWN, PAL_NONE, x + (SETTING_BUTTON_WIDTH - NWidgetScrollbar::GetVerticalDimension().width) / 2 + state, y + 2 + state);
2452
2453 if (!clickable) {
2454 GfxFillRect(x + 1, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 2, colour, FILLRECT_CHECKER);
2455 }
2456 }
2457
2465 void DrawBoolButton(int x, int y, bool state, bool clickable)
2466 {
2467 static const Colours _bool_ctabs[2][2] = {{COLOUR_CREAM, COLOUR_RED}, {COLOUR_DARK_GREEN, COLOUR_GREEN}};
2468 DrawFrameRect(x, y, x + SETTING_BUTTON_WIDTH - 1, y + SETTING_BUTTON_HEIGHT - 1, _bool_ctabs[state][clickable], state ? FR_LOWERED : FR_NONE);
2469 }
2470
2471 struct CustomCurrencyWindow : Window {
2472 int query_widget;
2473
2474 CustomCurrencyWindow(WindowDesc *desc) : Window(desc)
2475 {
2476 this->InitNested();
2477
2478 SetButtonState();
2479 }
2480
2481 void SetButtonState()
2482 {
2483 this->SetWidgetDisabledState(WID_CC_RATE_DOWN, _custom_currency.rate == 1);
2484 this->SetWidgetDisabledState(WID_CC_RATE_UP, _custom_currency.rate == UINT16_MAX);
2485 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN, _custom_currency.to_euro == CF_NOEURO);
2486 this->SetWidgetDisabledState(WID_CC_YEAR_UP, _custom_currency.to_euro == MAX_YEAR);
2487 }
2488
2489 void SetStringParameters(int widget) const override
2490 {
2491 switch (widget) {
2492 case WID_CC_RATE: SetDParam(0, 1); SetDParam(1, 1); break;
2493 case WID_CC_SEPARATOR: SetDParamStr(0, _custom_currency.separator); break;
2494 case WID_CC_PREFIX: SetDParamStr(0, _custom_currency.prefix); break;
2495 case WID_CC_SUFFIX: SetDParamStr(0, _custom_currency.suffix); break;
2496 case WID_CC_YEAR:
2497 SetDParam(0, (_custom_currency.to_euro != CF_NOEURO) ? STR_CURRENCY_SWITCH_TO_EURO : STR_CURRENCY_SWITCH_TO_EURO_NEVER);
2498 SetDParam(1, _custom_currency.to_euro);
2499 break;
2500
2501 case WID_CC_PREVIEW:
2502 SetDParam(0, 10000);
2503 break;
2504 }
2505 }
2506
2507 void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
2508 {
2509 switch (widget) {
2510 /* Set the appropriate width for the edit 'buttons' */
2511 case WID_CC_SEPARATOR_EDIT:
2512 case WID_CC_PREFIX_EDIT:
2513 case WID_CC_SUFFIX_EDIT:
2514 size->width = this->GetWidget<NWidgetBase>(WID_CC_RATE_DOWN)->smallest_x + this->GetWidget<NWidgetBase>(WID_CC_RATE_UP)->smallest_x;
2515 break;
2516
2517 /* Make sure the window is wide enough for the widest exchange rate */
2518 case WID_CC_RATE:
2519 SetDParam(0, 1);
2520 SetDParam(1, INT32_MAX);
2521 *size = GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE);
2522 break;
2523 }
2524 }
2525
2526 void OnClick(Point pt, int widget, int click_count) override
2527 {
2528 int line = 0;
2529 int len = 0;
2530 StringID str = 0;
2531 CharSetFilter afilter = CS_ALPHANUMERAL;
2532
2533 switch (widget) {
2534 case WID_CC_RATE_DOWN:
2535 if (_custom_currency.rate > 1) _custom_currency.rate--;
2536 if (_custom_currency.rate == 1) this->DisableWidget(WID_CC_RATE_DOWN);
2537 this->EnableWidget(WID_CC_RATE_UP);
2538 break;
2539
2540 case WID_CC_RATE_UP:
2541 if (_custom_currency.rate < UINT16_MAX) _custom_currency.rate++;
2542 if (_custom_currency.rate == UINT16_MAX) this->DisableWidget(WID_CC_RATE_UP);
2543 this->EnableWidget(WID_CC_RATE_DOWN);
2544 break;
2545
2546 case WID_CC_RATE:
2547 SetDParam(0, _custom_currency.rate);
2548 str = STR_JUST_INT;
2549 len = 5;
2550 line = WID_CC_RATE;
2551 afilter = CS_NUMERAL;
2552 break;
2553
2554 case WID_CC_SEPARATOR_EDIT:
2555 case WID_CC_SEPARATOR:
2556 SetDParamStr(0, _custom_currency.separator);
2557 str = STR_JUST_RAW_STRING;
2558 len = 1;
2559 line = WID_CC_SEPARATOR;
2560 break;
2561
2562 case WID_CC_PREFIX_EDIT:
2563 case WID_CC_PREFIX:
2564 SetDParamStr(0, _custom_currency.prefix);
2565 str = STR_JUST_RAW_STRING;
2566 len = 12;
2567 line = WID_CC_PREFIX;
2568 break;
2569
2570 case WID_CC_SUFFIX_EDIT:
2571 case WID_CC_SUFFIX:
2572 SetDParamStr(0, _custom_currency.suffix);
2573 str = STR_JUST_RAW_STRING;
2574 len = 12;
2575 line = WID_CC_SUFFIX;
2576 break;
2577
2578 case WID_CC_YEAR_DOWN:
2579 _custom_currency.to_euro = (_custom_currency.to_euro <= 2000) ? CF_NOEURO : _custom_currency.to_euro - 1;
2580 if (_custom_currency.to_euro == CF_NOEURO) this->DisableWidget(WID_CC_YEAR_DOWN);
2581 this->EnableWidget(WID_CC_YEAR_UP);
2582 break;
2583
2584 case WID_CC_YEAR_UP:
2585 _custom_currency.to_euro = Clamp(_custom_currency.to_euro + 1, 2000, MAX_YEAR);
2586 if (_custom_currency.to_euro == MAX_YEAR) this->DisableWidget(WID_CC_YEAR_UP);
2587 this->EnableWidget(WID_CC_YEAR_DOWN);
2588 break;
2589
2590 case WID_CC_YEAR:
2591 SetDParam(0, _custom_currency.to_euro);
2592 str = STR_JUST_INT;
2593 len = 7;
2594 line = WID_CC_YEAR;
2595 afilter = CS_NUMERAL;
2596 break;
2597 }
2598
2599 if (len != 0) {
2600 this->query_widget = line;
2601 ShowQueryString(str, STR_CURRENCY_CHANGE_PARAMETER, len + 1, this, afilter, QSF_NONE);
2602 }
2603
2604 this->SetTimeout();
2605 this->SetDirty();
2606 }
2607
2608 void OnQueryTextFinished(char *str) override
2609 {
2610 if (str == nullptr) return;
2611
2612 switch (this->query_widget) {
2613 case WID_CC_RATE:
2614 _custom_currency.rate = Clamp(atoi(str), 1, UINT16_MAX);
2615 break;
2616
2617 case WID_CC_SEPARATOR: // Thousands separator
2618 strecpy(_custom_currency.separator, str, lastof(_custom_currency.separator));
2619 break;
2620
2621 case WID_CC_PREFIX:
2622 strecpy(_custom_currency.prefix, str, lastof(_custom_currency.prefix));
2623 break;
2624
2625 case WID_CC_SUFFIX:
2626 strecpy(_custom_currency.suffix, str, lastof(_custom_currency.suffix));
2627 break;
2628
2629 case WID_CC_YEAR: { // Year to switch to euro
2630 int val = atoi(str);
2631
2632 _custom_currency.to_euro = (val < 2000 ? CF_NOEURO : std::min(val, MAX_YEAR));
2633 break;
2634 }
2635 }
2636 MarkWholeScreenDirty();
2637 SetButtonState();
2638 }
2639
2640 void OnTimeout() override
2641 {
2642 this->SetDirty();
2643 }
2644 };
2645
2646 static const NWidgetPart _nested_cust_currency_widgets[] = {
2647 NWidget(NWID_HORIZONTAL),
2648 NWidget(WWT_CLOSEBOX, COLOUR_GREY),
2649 NWidget(WWT_CAPTION, COLOUR_GREY), SetDataTip(STR_CURRENCY_WINDOW, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS),
2650 EndContainer(),
2651 NWidget(WWT_PANEL, COLOUR_GREY),
2652 NWidget(NWID_VERTICAL, NC_EQUALSIZE), SetPIP(7, 3, 0),
2653 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2654 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP),
2655 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_RATE_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP),
2656 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2657 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_RATE), SetDataTip(STR_CURRENCY_EXCHANGE_RATE, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP), SetFill(1, 0),
2658 EndContainer(),
2659 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2660 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SEPARATOR_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(0, 1),
2661 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2662 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SEPARATOR), SetDataTip(STR_CURRENCY_SEPARATOR, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP), SetFill(1, 0),
2663 EndContainer(),
2664 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2665 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_PREFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(0, 1),
2666 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2667 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_PREFIX), SetDataTip(STR_CURRENCY_PREFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP), SetFill(1, 0),
2668 EndContainer(),
2669 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2670 NWidget(WWT_PUSHBTN, COLOUR_DARK_BLUE, WID_CC_SUFFIX_EDIT), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(0, 1),
2671 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2672 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_SUFFIX), SetDataTip(STR_CURRENCY_SUFFIX, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP), SetFill(1, 0),
2673 EndContainer(),
2674 NWidget(NWID_HORIZONTAL), SetPIP(10, 0, 5),
2675 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_DOWN), SetDataTip(AWV_DECREASE, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
2676 NWidget(WWT_PUSHARROWBTN, COLOUR_YELLOW, WID_CC_YEAR_UP), SetDataTip(AWV_INCREASE, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP),
2677 NWidget(NWID_SPACER), SetMinimalSize(5, 0),
2678 NWidget(WWT_TEXT, COLOUR_BLUE, WID_CC_YEAR), SetDataTip(STR_JUST_STRING, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP), SetFill(1, 0),
2679 EndContainer(),
2680 EndContainer(),
2681 NWidget(WWT_LABEL, COLOUR_BLUE, WID_CC_PREVIEW),
2682 SetDataTip(STR_CURRENCY_PREVIEW, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP), SetPadding(15, 1, 18, 2),
2683 EndContainer(),
2684 };
2685
2686 static WindowDesc _cust_currency_desc(
2687 WDP_CENTER, nullptr, 0, 0,
2688 WC_CUSTOM_CURRENCY, WC_NONE,
2689 0,
2690 _nested_cust_currency_widgets, lengthof(_nested_cust_currency_widgets)
2691 );
2692
2694 static void ShowCustCurrency()
2695 {
2696 DeleteWindowById(WC_CUSTOM_CURRENCY, 0);
2697 new CustomCurrencyWindow(&_cust_currency_desc);
2698 }
WID_GO_REFRESH_RATE_DROPDOWN
@ WID_GO_REFRESH_RATE_DROPDOWN
Dropdown for all available refresh rates.
Definition: settings_widget.h:36
LoadStringWidthTable
void LoadStringWidthTable(bool monospace)
Initialize _stringwidth_table cache.
Definition: gfx.cpp:1276
SettingEntry::Length
virtual uint Length() const
Return number of rows needed to display the (filtered) entry.
Definition: settings_gui.cpp:985
WC_CUSTOM_CURRENCY
@ WC_CUSTOM_CURRENCY
Custom currency; Window numbers:
Definition: window_type.h:612
SEF_RIGHT_DEPRESSED
@ SEF_RIGHT_DEPRESSED
Of a numeric setting entry, the right button is depressed.
Definition: settings_gui.cpp:698
WID_GO_FULLSCREEN_BUTTON
@ WID_GO_FULLSCREEN_BUTTON
Toggle fullscreen.
Definition: settings_widget.h:21
Window::SetTimeout
void SetTimeout()
Set the timeout flag of the window and initiate the timer.
Definition: window_gui.h:366
SettingEntry::UpdateFilterState
virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible)
Update the filter state.
Definition: settings_gui.cpp:1049
CustomCurrencyWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: settings_gui.cpp:2640
CF_NOEURO
static const int CF_NOEURO
Currency never switches to the Euro (as far as known).
Definition: currency.h:17
ClampToI32
static int32 ClampToI32(const int64 a)
Reduce a signed 64-bit int to a signed 32-bit one.
Definition: math_func.hpp:141
factory.hpp
GUISettings::refresh_rate
uint16 refresh_rate
How often we refresh the screen (time between draw-ticks).
Definition: settings_type.h:160
ReInitAllWindows
void ReInitAllWindows()
Re-initialize all windows.
Definition: window.cpp:3456
WID_GO_FONT_ZOOM_DROPDOWN
@ WID_GO_FONT_ZOOM_DROPDOWN
Dropdown for the font zoom level.
Definition: settings_widget.h:34
TextfileWindow::LoadTextfile
virtual void LoadTextfile(const char *textfile, Subdirectory dir)
Loads the textfile text from file and setup lines.
Definition: textfile_gui.cpp:317
Pool::PoolItem<&_company_pool >::Get
static Titem * Get(size_t index)
Returns Titem with given index.
Definition: pool_type.hpp:329
WID_GO_AUTOSAVE_DROPDOWN
@ WID_GO_AUTOSAVE_DROPDOWN
Dropdown to say how often to autosave.
Definition: settings_widget.h:18
SEF_LEFT_DEPRESSED
@ SEF_LEFT_DEPRESSED
Of a numeric setting entry, the left button is depressed.
Definition: settings_gui.cpp:697
Window::timeout_timer
uint8 timeout_timer
Timer value of the WF_TIMEOUT for flags.
Definition: window_gui.h:314
querystring_gui.h
DropDownListParamStringItem
String list item with parameters.
Definition: dropdown_type.h:56
SetScrollbar
static NWidgetPart SetScrollbar(int index)
Attach a scrollbar to a widget.
Definition: widget_type.h:1094
GetCurrentLanguageIsoCode
const char * GetCurrentLanguageIsoCode()
Get the ISO language code of the currently loaded language.
Definition: strings.cpp:1978
SEF_BUTTONS_MASK
@ SEF_BUTTONS_MASK
Bit-mask for button flags.
Definition: settings_gui.cpp:699
Dimension
Dimensions (a width and height) of a rectangle in 2D.
Definition: geometry_type.hpp:27
Scrollbar::GetCapacity
uint16 GetCapacity() const
Gets the number of visible elements of the scrollbar.
Definition: widget_type.h:621
WID_GS_OPTIONSPANEL
@ WID_GS_OPTIONSPANEL
Panel widget containing the option lists.
Definition: settings_widget.h:42
command_func.h
BaseSetTextfileWindow::baseset
const TBaseSet * baseset
View the textfile of this BaseSet.
Definition: settings_gui.cpp:110
WID_GS_COLLAPSE_ALL
@ WID_GS_COLLAPSE_ALL
Collapse all button.
Definition: settings_widget.h:46
WID_GS_HELP_TEXT
@ WID_GS_HELP_TEXT
Information area to display help text of the selected option.
Definition: settings_widget.h:44
SetPadding
static NWidgetPart SetPadding(uint8 top, uint8 right, uint8 bottom, uint8 left)
Widget part function for setting additional space around a widget.
Definition: widget_type.h:1045
Window::GetScrollbar
const Scrollbar * GetScrollbar(uint widnum) const
Return the Scrollbar to a widget index.
Definition: window.cpp:309
BaseSetTextfileWindow::content_type
StringID content_type
STR_CONTENT_TYPE_xxx for title.
Definition: settings_gui.cpp:111
dropdown_func.h
WID_GO_BASE_GRF_STATUS
@ WID_GO_BASE_GRF_STATUS
Info about missing files etc.
Definition: settings_widget.h:24
GameSettingsWindow
Window to edit settings of the game.
Definition: settings_gui.cpp:1796
StringFilter::IsEmpty
bool IsEmpty() const
Check whether any filter words were entered.
Definition: stringfilter_type.h:59
SettingDescBase::cat
SettingCategory cat
assigned categories of the setting
Definition: settings_internal.h:105
CustomCurrencyWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: settings_gui.cpp:2526
SettingsPage::DrawSetting
virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const
Function to draw setting value (button + text + current value)
Definition: settings_gui.cpp:1466
company_base.h
WID_CC_SEPARATOR_EDIT
@ WID_CC_SEPARATOR_EDIT
Separator edit button.
Definition: settings_widget.h:58
GameSettingsWindow::settings_ptr
static GameSettings * settings_ptr
Pointer to the game settings being displayed and modified.
Definition: settings_gui.cpp:1802
StringFilter::SetFilterTerm
void SetFilterTerm(const char *str)
Set the term to filter on.
Definition: stringfilter.cpp:27
WID_GO_BASE_SFX_TEXTFILE
@ WID_GO_BASE_SFX_TEXTFILE
Open base SFX readme, changelog (+1) or license (+2).
Definition: settings_widget.h:28
SettingDescBase::str_val
StringID str_val
(Translated) first string describing the value.
Definition: settings_internal.h:102
SettingFilter::type
SettingType type
Filter based on type.
Definition: settings_gui.cpp:722
WWT_CAPTION
@ WWT_CAPTION
Window caption (window title between closebox and stickybox)
Definition: widget_type.h:59
SGF_PER_COMPANY
@ SGF_PER_COMPANY
this setting can be different for each company (saved in company struct)
Definition: settings_internal.h:48
BASESET_DIR
@ BASESET_DIR
Subdirectory for all base data (base sets, intro game)
Definition: fileio_type.h:116
currency.h
Scrollbar::GetScrolledRowFromWidget
int GetScrolledRowFromWidget(int clickpos, const Window *const w, int widget, int padding=0, int line_height=-1) const
Compute the row of a scrolled widget that a user clicked in.
Definition: widget.cpp:1966
ST_GAME
@ ST_GAME
Game setting.
Definition: settings_internal.h:80
WID_GO_GUI_ZOOM_DROPDOWN
@ WID_GO_GUI_ZOOM_DROPDOWN
Dropdown for the GUI zoom level.
Definition: settings_widget.h:22
WWT_LABEL
@ WWT_LABEL
Centered label.
Definition: widget_type.h:55
SettingDesc::save
SaveLoad save
Internal structure (going to savegame, parts to config)
Definition: settings_internal.h:111
DropDownList
std::vector< std::unique_ptr< const DropDownListItem > > DropDownList
A drop down list is a collection of drop down list items.
Definition: dropdown_type.h:100
WID_CC_YEAR
@ WID_CC_YEAR
Year of introduction.
Definition: settings_widget.h:66
SettingDesc::GetType
SettingType GetType() const
Return the type of the setting.
Definition: settings.cpp:836
SettingsPage::Init
virtual void Init(byte level=0)
Initialization of an entire setting page.
Definition: settings_gui.cpp:1320
WWT_DEFSIZEBOX
@ WWT_DEFSIZEBOX
Default window size box (at top-right of a window, between WWT_SHADEBOX and WWT_STICKYBOX)
Definition: widget_type.h:63
Window::CreateNestedTree
void CreateNestedTree(bool fill_nested=true)
Perform the first part of the initialization of a nested widget tree.
Definition: window.cpp:1832
SettingsPage::Length
virtual uint Length() const
Return number of rows needed to display the (filtered) entry.
Definition: settings_gui.cpp:1401
SettingDesc::IsEditable
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
Definition: settings.cpp:821
WID_GO_BASE_GRF_DESCRIPTION
@ WID_GO_BASE_GRF_DESCRIPTION
Description of selected base GRF.
Definition: settings_widget.h:26
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition: widget_type.h:73
GameSettingsWindow::OnDropdownClose
void OnDropdownClose(Point pt, int widget, int index, bool instant_close) override
A dropdown window associated to this window has been closed.
Definition: settings_gui.cpp:2283
DropDownListCharStringItem
List item containing a C char string.
Definition: dropdown_type.h:70
SettingsContainer::GetMaxHelpHeight
uint GetMaxHelpHeight(int maxw)
Get the biggest height of the help texts, if the width is at least maxw.
Definition: settings_gui.cpp:1269
SDT_BOOLX
@ SDT_BOOLX
a boolean number
Definition: settings_internal.h:25
GameSettingsWindow::filter_editbox
QueryString filter_editbox
Filter editbox;.
Definition: settings_gui.cpp:1811
ST_CLIENT
@ ST_CLIENT
Client setting.
Definition: settings_internal.h:82
maxdim
Dimension maxdim(const Dimension &d1, const Dimension &d2)
Compute bounding box of both dimensions.
Definition: geometry_func.cpp:22
BaseSettingEntry::SetLastField
void SetLastField(bool last_field)
Set whether this is the last visible entry of the parent node.
Definition: settings_gui.cpp:741
WID_CC_RATE
@ WID_CC_RATE
Rate of currency.
Definition: settings_widget.h:57
HasBit
static bool HasBit(const T x, const uint8 y)
Checks if a bit in a value is set.
Definition: bitmath_func.hpp:103
BaseSetTextfileWindow
Window for displaying the textfile of a BaseSet.
Definition: settings_gui.cpp:109
Scrollbar::SetCount
void SetCount(int num)
Sets the number of elements in the list.
Definition: widget_type.h:669
FILLRECT_CHECKER
@ FILLRECT_CHECKER
Draw only every second pixel, used for greying-out.
Definition: gfx_type.h:288
SettingFilter::string
StringFilter string
Filter string.
Definition: settings_gui.cpp:718
_font_zoom_cfg
int8 _font_zoom_cfg
Font zoom level in config.
Definition: gfx.cpp:63
SettingEntry::Init
virtual void Init(byte level=0)
Initialization of a setting entry.
Definition: settings_gui.cpp:966
GameOptionsWindow
Definition: settings_gui.cpp:157
SettingEntry::setting
const SettingDesc * setting
Setting description of the setting.
Definition: settings_gui.cpp:766
SetResize
static NWidgetPart SetResize(int16 dx, int16 dy)
Widget part function for setting the resize step.
Definition: widget_type.h:929
zoom_func.h
ST_COMPANY
@ ST_COMPANY
Company setting.
Definition: settings_internal.h:81
WD_FRAMETEXT_TOP
@ WD_FRAMETEXT_TOP
Top offset of the text of the frame.
Definition: window_gui.h:72
WID_GS_EXPAND_ALL
@ WID_GS_EXPAND_ALL
Expand all button.
Definition: settings_widget.h:45
SGF_DISPLAY_ABS
@ SGF_DISPLAY_ABS
display absolute value of the setting
Definition: settings_internal.h:41
base_media_base.h
DropDownListItem
Base list item class from which others are derived.
Definition: dropdown_type.h:22
SettingsContainer::entries
EntryVector entries
Settings on this page.
Definition: settings_gui.cpp:799
_settings_client
ClientSettings _settings_client
The current settings for this game.
Definition: settings.cpp:79
GameSettingsWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: settings_gui.cpp:1849
DrawString
int DrawString(int left, int right, int top, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
Definition: gfx.cpp:640
GameSettingsWindow::last_clicked
SettingEntry * last_clicked
If non-nullptr, pointer to the last clicked setting.
Definition: settings_gui.cpp:1806
GUISettings::autosave
byte autosave
how often should we do autosaves?
Definition: settings_type.h:121
WWT_EMPTY
@ WWT_EMPTY
Empty widget, place holder to reserve space in widget array.
Definition: widget_type.h:46
DeleteWindowByClass
void DeleteWindowByClass(WindowClass cls)
Delete all windows of a given class.
Definition: window.cpp:1178
town.h
WWT_PUSHARROWBTN
@ WWT_PUSHARROWBTN
Normal push-button (no toggle button) with arrow caption.
Definition: widget_type.h:104
WID_GS_FILTER
@ WID_GS_FILTER
Text filter.
Definition: settings_widget.h:41
StringFilter::AddLine
void AddLine(const char *str)
Pass another text line from the current item to the filter.
Definition: stringfilter.cpp:104
GameSettingsWindow::SETTINGTREE_TOP_OFFSET
static const int SETTINGTREE_TOP_OFFSET
Position of top edge of setting values.
Definition: settings_gui.cpp:1799
Window::OnDropdownClose
virtual void OnDropdownClose(Point pt, int widget, int index, bool instant_close)
A dropdown window associated to this window has been closed.
Definition: window.cpp:282
FR_LOWERED
@ FR_LOWERED
If set the frame is lowered and the background colour brighter (ie. buttons when pressed)
Definition: window_gui.h:29
settings_internal.h
SDT_NUMX
@ SDT_NUMX
any number-type
Definition: settings_internal.h:24
WID_CC_PREFIX
@ WID_CC_PREFIX
Current prefix.
Definition: settings_widget.h:61
SEF_FILTERED
@ SEF_FILTERED
Entry is hidden by the string filter.
Definition: settings_gui.cpp:702
WID_GO_BASE_MUSIC_DROPDOWN
@ WID_GO_BASE_MUSIC_DROPDOWN
Use to select a base music set.
Definition: settings_widget.h:30
GameSettingsWindow::SETTINGTREE_LEFT_OFFSET
static const int SETTINGTREE_LEFT_OFFSET
Position of left edge of setting values.
Definition: settings_gui.cpp:1797
SaveLoad::conv
VarType conv
type of the variable to be saved, int
Definition: saveload.h:518
_gui_zoom
ZoomLevel _gui_zoom
GUI Zoom level.
Definition: gfx.cpp:59
SA_HOR_CENTER
@ SA_HOR_CENTER
Horizontally center the text.
Definition: gfx_func.h:97
SettingEntry::IsVisibleByRestrictionMode
bool IsVisibleByRestrictionMode(RestrictionMode mode) const
Checks whether an entry shall be made visible based on the restriction mode.
Definition: settings_gui.cpp:1005
SettingsPage::SettingsPage
SettingsPage(StringID title)
Constructor for a sub-page in the 'advanced settings' window.
Definition: settings_gui.cpp:1310
BaseSettingEntry::Init
virtual void Init(byte level=0)
Initialization of a setting entry.
Definition: settings_gui.cpp:854
Scrollbar
Scrollbar data structure.
Definition: widget_type.h:588
SettingsPage
Data structure describing one page of settings in the settings window.
Definition: settings_gui.cpp:824
WD_FRAMETEXT_LEFT
@ WD_FRAMETEXT_LEFT
Left offset of the text of the frame.
Definition: window_gui.h:70
TextfileWindow::file_type
TextfileType file_type
Type of textfile to view.
Definition: textfile_gui.h:22
TFT_CHANGELOG
@ TFT_CHANGELOG
NewGRF changelog.
Definition: textfile_type.h:18
SettingDescBase::str
StringID str
(translated) string with descriptive text; gui and console
Definition: settings_internal.h:100
SettingsContainer::UpdateFilterState
bool UpdateFilterState(SettingFilter &filter, bool force_visible)
Update the filter state.
Definition: settings_gui.cpp:1209
_colour_gradient
byte _colour_gradient[COLOUR_END][8]
All 16 colour gradients 8 colours per gradient from darkest (0) to lightest (7)
Definition: gfx.cpp:52
Window::Window
Window(WindowDesc *desc)
Empty constructor, initialization has been moved to InitNested() called from the constructor of the d...
Definition: window.cpp:1871
SetDParam
static void SetDParam(uint n, uint64 v)
Set a string parameter v at index n in the global string parameter array.
Definition: strings_func.h:199
CustomCurrencyWindow
Definition: settings_gui.cpp:2471
NWidgetPart
Partial widget specification to allow NWidgets to be written nested.
Definition: widget_type.h:909
textfile_gui.h
SetDataTip
static NWidgetPart SetDataTip(uint32 data, StringID tip)
Widget part function for setting the data and tooltip.
Definition: widget_type.h:1013
QueryString
Data stored about a string that can be modified in the GUI.
Definition: querystring_gui.h:20
SettingDescBase::min
int32 min
minimum values
Definition: settings_internal.h:96
SETBITS
#define SETBITS(x, y)
Sets several bits in a variable.
Definition: bitmath_func.hpp:136
GameSettingsWindow::OnTimeout
void OnTimeout() override
Called when this window's timeout has been reached.
Definition: settings_gui.cpp:2202
GetStringBoundingBox
Dimension GetStringBoundingBox(const char *str, FontSize start_fontsize)
Return the string dimension in pixels.
Definition: gfx.cpp:842
GetStringLineCount
int GetStringLineCount(StringID str, int maxw)
Calculates number of lines of string.
Definition: gfx.cpp:714
textbuf_gui.h
Textbuf::buf
char *const buf
buffer in which text is saved
Definition: textbuf_type.h:32
Window::querystrings
SmallMap< int, QueryString * > querystrings
QueryString associated to WWT_EDITBOX widgets.
Definition: window_gui.h:328
ShowErrorMessage
void ShowErrorMessage(StringID summary_msg, StringID detailed_msg, WarningLevel wl, int x=0, int y=0, const GRFFile *textref_stack_grffile=nullptr, uint textref_stack_size=0, const uint32 *textref_stack=nullptr)
Display an error message in a window.
Definition: error_gui.cpp:372
DrawStringMultiLine
int DrawStringMultiLine(int left, int right, int top, int bottom, const char *str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly over multiple lines.
Definition: gfx.cpp:763
GameOptionsWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: settings_gui.cpp:292
SettingEntry::GetMaxHelpHeight
virtual uint GetMaxHelpHeight(int maxw)
Get the biggest height of the help text(s), if the width is at least maxw.
Definition: settings_gui.cpp:995
BuildCurrencyDropdown
StringID * BuildCurrencyDropdown()
Build a list of currency names StringIDs to use in a dropdown list.
Definition: currency.cpp:169
ai.hpp
WID_CC_SEPARATOR
@ WID_CC_SEPARATOR
Current separator.
Definition: settings_widget.h:59
UpdateCursorSize
void UpdateCursorSize()
Update cursor dimension.
Definition: gfx.cpp:1666
GetGameSettings
static GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
Definition: settings_type.h:601
WN_GAME_OPTIONS_GAME_OPTIONS
@ WN_GAME_OPTIONS_GAME_OPTIONS
Game options.
Definition: window_type.h:18
WindowDesc
High level window description.
Definition: window_gui.h:166
GameSettingsWindow::warn_missing
WarnHiddenResult warn_missing
Whether and how to warn about missing search results.
Definition: settings_gui.cpp:1813
BaseSettingEntry::level
byte level
Nesting level of this setting entry.
Definition: settings_gui.cpp:728
SettingType
SettingType
Type of settings for filtering.
Definition: settings_internal.h:79
DECLARE_POSTFIX_INCREMENT
#define DECLARE_POSTFIX_INCREMENT(enum_type)
Some enums need to have allowed incrementing (i.e.
Definition: enum_type.hpp:14
SettingDescBase::cmd
SettingDescType cmd
various flags for the variable
Definition: settings_internal.h:94
SettingsPage::title
StringID title
Title of the sub-page.
Definition: settings_gui.cpp:825
SettingFilter::min_cat
RestrictionMode min_cat
Minimum category needed to display all filtered strings (RM_BASIC, RM_ADVANCED, or RM_ALL).
Definition: settings_gui.cpp:719
NC_EQUALSIZE
@ NC_EQUALSIZE
Value of the NCB_EQUALSIZE flag.
Definition: widget_type.h:428
WC_QUERY_STRING
@ WC_QUERY_STRING
Query string window; Window numbers:
Definition: window_type.h:116
GameOptionsWindow::BuildDropDownList
DropDownList BuildDropDownList(int widget, int *selected_index) const
Build the dropdown list for a specific widget.
Definition: settings_gui.cpp:185
DrawDropDownButton
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Definition: settings_gui.cpp:2446
WWT_PUSHBTN
@ WWT_PUSHBTN
Normal push-button (no toggle button) with custom drawing.
Definition: widget_type.h:101
Window::resize
ResizeInfo resize
Resize information.
Definition: window_gui.h:322
WID_GS_RESTRICT_CATEGORY
@ WID_GS_RESTRICT_CATEGORY
Label upfront to the category drop-down box to restrict the list of settings to show.
Definition: settings_widget.h:47
SettingDescBase
Properties of config file settings.
Definition: settings_internal.h:91
GameSettingsWindow::warn_lines
int warn_lines
Number of lines used for warning about missing search results.
Definition: settings_gui.cpp:1814
VideoDriver::GetListOfMonitorRefreshRates
virtual std::vector< int > GetListOfMonitorRefreshRates()
Get a list of refresh rates of each available monitor.
Definition: video_driver.hpp:156
Scrollbar::GetCount
uint16 GetCount() const
Gets the number of elements in the list.
Definition: widget_type.h:612
SETTING_HEIGHT
static int SETTING_HEIGHT
Height of a single setting in the tree view in pixels.
Definition: settings_gui.cpp:689
Window::EnableWidget
void EnableWidget(byte widget_index)
Sets a widget to Enabled.
Definition: window_gui.h:411
RestrictionMode
RestrictionMode
How the list of advanced settings is filtered.
Definition: settings_gui.cpp:706
Window::InitNested
void InitNested(WindowNumber number=0)
Perform complete initialization of the Window with nested widgets, to allow use.
Definition: window.cpp:1861
WWT_EDITBOX
@ WWT_EDITBOX
a textbox for typing
Definition: widget_type.h:69
GameSettingsWindow::valuewindow_entry
SettingEntry * valuewindow_entry
If non-nullptr, pointer to setting for which a value-entering window has been opened.
Definition: settings_gui.cpp:1804
SettingDescBase::max
uint32 max
maximum values
Definition: settings_internal.h:97
GfxClearSpriteCache
void GfxClearSpriteCache()
Remove all encoded sprites from the sprite cache without discarding sprite location information.
Definition: spritecache.cpp:974
SettingEntry::DrawSetting
virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const
Function to draw setting value (button + text + current value)
Definition: settings_gui.cpp:1129
WHR_TYPE
@ WHR_TYPE
Type setting filtered matches away.
Definition: settings_gui.cpp:1791
Window::height
int height
Height of the window (number of pixels down in y direction)
Definition: window_gui.h:320
WID_CC_SUFFIX_EDIT
@ WID_CC_SUFFIX_EDIT
Suffix edit button.
Definition: settings_widget.h:62
WID_GO_BASE_MUSIC_DESCRIPTION
@ WID_GO_BASE_MUSIC_DESCRIPTION
Description of selected base music set.
Definition: settings_widget.h:33
CustomCurrencyWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: settings_gui.cpp:2608
GameSettingsWindow::SETTINGTREE_BOTTOM_OFFSET
static const int SETTINGTREE_BOTTOM_OFFSET
Position of bottom edge of setting values.
Definition: settings_gui.cpp:1800
Window::SetDirty
void SetDirty() const
Mark entire window as dirty (in need of re-paint)
Definition: window.cpp:984
highscore.h
WD_FRAMERECT_LEFT
@ WD_FRAMERECT_LEFT
Offset at left to draw the frame rectangular area.
Definition: window_gui.h:60
GameSettingsWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: settings_gui.cpp:2239
BaseSettingEntry
Data structure describing a single setting in a tab.
Definition: settings_gui.cpp:726
GameSettingsWindow::OnQueryTextFinished
void OnQueryTextFinished(char *str) override
The query window opened from this window has closed.
Definition: settings_gui.cpp:2211
WD_PAR_VSEP_NORMAL
@ WD_PAR_VSEP_NORMAL
Normal amount of vertical space between two paragraphs of text.
Definition: window_gui.h:137
WD_FRAMERECT_RIGHT
@ WD_FRAMERECT_RIGHT
Offset at right to draw the frame rectangular area.
Definition: window_gui.h:61
WWT_PUSHTXTBTN
@ WWT_PUSHTXTBTN
Normal push-button (no toggle button) with text caption.
Definition: widget_type.h:102
NWidgetBase
Baseclass for nested widgets.
Definition: widget_type.h:124
WD_FRAMETEXT_BOTTOM
@ WD_FRAMETEXT_BOTTOM
Bottom offset of the text of the frame.
Definition: window_gui.h:73
SDT_ONEOFMANY
@ SDT_ONEOFMANY
bitmasked number where only ONE bit may be set
Definition: settings_internal.h:26
ShowDropDownList
void ShowDropDownList(Window *w, DropDownList &&list, int selected, int button, uint width, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:453
GameOptionsWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: settings_gui.cpp:321
RM_END
@ RM_END
End for iteration.
Definition: settings_gui.cpp:712
SettingFilter::mode
RestrictionMode mode
Filter based on category.
Definition: settings_gui.cpp:721
dropdown_type.h
SettingEntry::name
const char * name
Name of the setting.
Definition: settings_gui.cpp:765
Window::SetWidgetDisabledState
void SetWidgetDisabledState(byte widget_index, bool disab_stat)
Sets the enabled/disabled status of a widget.
Definition: window_gui.h:392
WL_INFO
@ WL_INFO
Used for DoCommand-like (and some non-fatal AI GUI) errors/information.
Definition: error.h:22
SettingsPage::FoldAll
virtual void FoldAll()
Recursively close all (filtered) folds of sub-pages.
Definition: settings_gui.cpp:1327
_local_company
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Definition: company_cmd.cpp:46
_current_language
const LanguageMetadata * _current_language
The currently loaded language.
Definition: strings.cpp:46
SettingDescBase::def
const void * def
default value given when none is present
Definition: settings_internal.h:93
SEF_LAST_FIELD
@ SEF_LAST_FIELD
This entry is the last one in a (sub-)page.
Definition: settings_gui.cpp:701
DropDownListStringItem
Common string list item.
Definition: dropdown_type.h:39
safeguards.h
ShowQueryString
void ShowQueryString(StringID str, StringID caption, uint maxsize, Window *parent, CharSetFilter afilter, QueryStringFlags flags)
Show a query popup window with a textbox in it.
Definition: misc_gui.cpp:1131
RM_ALL
@ RM_ALL
List all settings regardless of the default/newgame/... values.
Definition: settings_gui.cpp:709
SettingDescBase::interval
int32 interval
the interval to use between settings in the 'settings' window. If interval is '0' the interval is dyn...
Definition: settings_internal.h:98
Window::left
int left
x position of left edge of the window
Definition: window_gui.h:317
Window::flags
WindowFlags flags
Window flags.
Definition: window_gui.h:310
_resolutions
std::vector< Dimension > _resolutions
List of resolutions.
Definition: driver.cpp:24
WF_TIMEOUT
@ WF_TIMEOUT
Window timeout counter.
Definition: window_gui.h:232
SetCompanySetting
void SetCompanySetting(uint index, int32 value)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:2018
StrEmpty
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
Definition: string_func.h:60
settings
fluid_settings_t * settings
FluidSynth settings handle.
Definition: fluidsynth.cpp:21
GameSettings
All settings together for the game.
Definition: settings_type.h:558
GetSettingFromName
const SettingDesc * GetSettingFromName(const char *name, uint *i)
Given a name of setting, return a setting description of it.
Definition: settings.cpp:2106
SettingsPage::folded
bool folded
Sub-page is folded (not visible except for its title)
Definition: settings_gui.cpp:826
DrawSprite
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
Definition: gfx.cpp:978
WID_GO_BASE_GRF_DROPDOWN
@ WID_GO_BASE_GRF_DROPDOWN
Use to select a base GRF.
Definition: settings_widget.h:23
WID_CC_YEAR_UP
@ WID_CC_YEAR_UP
Up button.
Definition: settings_widget.h:65
GameSettingsWindow::valuedropdown_entry
SettingEntry * valuedropdown_entry
If non-nullptr, pointer to the value for which a dropdown window is currently opened.
Definition: settings_gui.cpp:1807
SettingsContainer::Init
void Init(byte level=0)
Initialization of an entire setting page.
Definition: settings_gui.cpp:1168
Point
Coordinates of a point in 2D.
Definition: geometry_type.hpp:21
error.h
CheckBlitter
void CheckBlitter()
Check whether we still use the right blitter, or use another (better) one.
Definition: gfxinit.cpp:320
RM_BASIC
@ RM_BASIC
Display settings associated to the "basic" list.
Definition: settings_gui.cpp:707
WWT_FRAME
@ WWT_FRAME
Frame.
Definition: widget_type.h:58
language.h
AddCustomRefreshRates
static void AddCustomRefreshRates()
Add the refresh rate from the config and the refresh rates from all the monitors to our list of refre...
Definition: settings_gui.cpp:147
WID_CC_YEAR_DOWN
@ WID_CC_YEAR_DOWN
Down button.
Definition: settings_widget.h:64
WHR_CATEGORY
@ WHR_CATEGORY
Category setting filtered matches away.
Definition: settings_gui.cpp:1790
SettingsPage::FindEntry
virtual BaseSettingEntry * FindEntry(uint row, uint *cur_row)
Find setting entry at row row_num.
Definition: settings_gui.cpp:1415
BaseSetTextfileWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: settings_gui.cpp:119
SETTING_BUTTON_WIDTH
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
Definition: settings_gui.h:17
CustomCurrencyWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: settings_gui.cpp:2489
WD_FRAMETEXT_RIGHT
@ WD_FRAMETEXT_RIGHT
Right offset of the text of the frame.
Definition: window_gui.h:71
Window::SetFocusedWidget
bool SetFocusedWidget(int widget_index)
Set focus within this window to the given widget.
Definition: window.cpp:495
stdafx.h
DrawArrowButtons
void DrawArrowButtons(int x, int y, Colours button_colour, byte state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
Definition: settings_gui.cpp:2418
WID_GO_LANG_DROPDOWN
@ WID_GO_LANG_DROPDOWN
Language dropdown.
Definition: settings_widget.h:19
SettingFilter::type_hides
bool type_hides
Whether the type hides filtered strings.
Definition: settings_gui.cpp:720
GfxFillRect
void GfxFillRect(int left, int top, int right, int bottom, int colour, FillRectMode mode)
Applies a certain FillRectMode-operation to a rectangle [left, right] x [top, bottom] on the screen.
Definition: gfx.cpp:114
ShowCustCurrency
static void ShowCustCurrency()
Open custom currency window.
Definition: settings_gui.cpp:2694
WID_CC_RATE_DOWN
@ WID_CC_RATE_DOWN
Down button.
Definition: settings_widget.h:55
TFT_README
@ TFT_README
NewGRF readme.
Definition: textfile_type.h:17
LanguagePackHeader::own_name
char own_name[32]
the localized name of this language
Definition: language.h:30
SettingsContainer::Draw
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.
Definition: settings_gui.cpp:1293
WarnHiddenResult
WarnHiddenResult
Warnings about hidden search results.
Definition: settings_gui.cpp:1788
Window::InvalidateData
void InvalidateData(int data=0, bool gui_scope=true)
Mark this window's data as invalid (in need of re-computing)
Definition: window.cpp:3261
VideoDriver::GetInstance
static VideoDriver * GetInstance()
Get the currently active instance of the video driver.
Definition: video_driver.hpp:187
CS_ALPHANUMERAL
@ CS_ALPHANUMERAL
Both numeric and alphabetic and spaces and stuff.
Definition: string_type.h:27
viewport_func.h
WC_NONE
@ WC_NONE
No window, redirects to WC_MAIN_WINDOW.
Definition: window_type.h:38
WHR_CATEGORY_TYPE
@ WHR_CATEGORY_TYPE
Both category and type settings filtered matches away.
Definition: settings_gui.cpp:1792
SettingEntry::index
uint index
Index of the setting in the settings table.
Definition: settings_gui.cpp:767
NWID_VERTICAL
@ NWID_VERTICAL
Vertical container.
Definition: widget_type.h:75
ShowBaseSetTextfileWindow
void ShowBaseSetTextfileWindow(TextfileType file_type, const TBaseSet *baseset, StringID content_type)
Open the BaseSet version of the textfile window.
Definition: settings_gui.cpp:135
BaseSet::GetNumMissing
int GetNumMissing() const
Get the number of missing files.
Definition: base_media_base.h:88
SettingDescBase::flags
SettingGuiFlag flags
handles how a setting would show up in the GUI (text/currency, etc.)
Definition: settings_internal.h:95
WID_CC_RATE_UP
@ WID_CC_RATE_UP
Up button.
Definition: settings_widget.h:56
GetStringHeight
int GetStringHeight(const char *str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
Definition: gfx.cpp:689
GetSpriteSize
Dimension GetSpriteSize(SpriteID sprid, Point *offset, ZoomLevel zoom)
Get the size of a sprite.
Definition: gfx.cpp:913
WWT_CLOSEBOX
@ WWT_CLOSEBOX
Close box (at top-left of a window)
Definition: widget_type.h:67
WWT_RESIZEBOX
@ WWT_RESIZEBOX
Resize box (normally at bottom-right of a window)
Definition: widget_type.h:66
GUISettings::zoom_min
ZoomLevel zoom_min
minimum zoom out level
Definition: settings_type.h:118
GameSettingsWindow::SetStringParameters
void SetStringParameters(int widget) const override
Initialize string parameters for a widget.
Definition: settings_gui.cpp:1925
WID_GO_BACKGROUND
@ WID_GO_BACKGROUND
Background of the window.
Definition: settings_widget.h:15
_gui_zoom_cfg
int8 _gui_zoom_cfg
GUI zoom level in config.
Definition: gfx.cpp:62
BaseMedia< GraphicsSet >::GetNumSets
static int GetNumSets()
Count the number of available graphics sets.
Definition: base_media_func.h:311
string_func.h
SettingEntry::SetButtons
void SetButtons(byte new_val)
Set the button-depressed flags (SEF_LEFT_DEPRESSED and SEF_RIGHT_DEPRESSED) to a specified value.
Definition: settings_gui.cpp:978
TFT_LICENSE
@ TFT_LICENSE
NewGRF license.
Definition: textfile_type.h:19
_switch_mode
SwitchMode _switch_mode
The next mainloop command.
Definition: gfx.cpp:46
_font_zoom
ZoomLevel _font_zoom
Font Zoom level.
Definition: gfx.cpp:60
GameSettingsWindow::OnResize
void OnResize() override
Called after the window got resized.
Definition: settings_gui.cpp:2345
StringID
uint32 StringID
Numeric value that represents a string, independent of the selected language.
Definition: strings_type.h:16
WID_GS_SCROLLBAR
@ WID_GS_SCROLLBAR
Scrollbar.
Definition: settings_widget.h:43
WID_CC_PREFIX_EDIT
@ WID_CC_PREFIX_EDIT
Prefix edit button.
Definition: settings_widget.h:60
QueryString::cancel_button
int cancel_button
Widget button of parent window to simulate when pressing CANCEL in OSK.
Definition: querystring_gui.h:28
SGF_MULTISTRING
@ SGF_MULTISTRING
the value represents a limited number of string-options (internally integer)
Definition: settings_internal.h:42
SGF_0ISDISABLED
@ SGF_0ISDISABLED
a value of zero means the feature is disabled
Definition: settings_internal.h:40
WC_GAME_OPTIONS
@ WC_GAME_OPTIONS
Game options window; Window numbers:
Definition: window_type.h:606
CURRENCY_END
@ CURRENCY_END
always the last item
Definition: currency.h:68
EndContainer
static NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition: widget_type.h:998
Clamp
static T Clamp(const T a, const T min, const T max)
Clamp a value between an interval.
Definition: math_func.hpp:77
WID_GO_RESOLUTION_DROPDOWN
@ WID_GO_RESOLUTION_DROPDOWN
Dropdown for the resolution.
Definition: settings_widget.h:20
strings_func.h
NWID_VSCROLLBAR
@ NWID_VSCROLLBAR
Vertical scrollbar.
Definition: widget_type.h:82
DeleteWindowById
void DeleteWindowById(WindowClass cls, WindowNumber number, bool force)
Delete a window by its class and window number (if it is open).
Definition: window.cpp:1165
main
int CDECL main(int argc, char *argv[])
And the main program (what else?)
Definition: settingsgen.cpp:455
GetTextfile
const char * GetTextfile(TextfileType type, Subdirectory dir, const char *filename)
Search a textfile file next to the given content.
Definition: textfile_gui.cpp:385
NWidgetBase::pos_x
int pos_x
Horizontal position of top-left corner of the widget in the window.
Definition: widget_type.h:175
LocaleSettings::currency
byte currency
currency we currently use
Definition: settings_type.h:217
WID_GO_BASE_SFX_DROPDOWN
@ WID_GO_BASE_SFX_DROPDOWN
Use to select a base SFX.
Definition: settings_widget.h:27
GRFConfig::name
GRFTextWrapper name
NOSAVE: GRF name (Action 0x08)
Definition: newgrf_config.h:160
WID_GO_BASE_MUSIC_TEXTFILE
@ WID_GO_BASE_MUSIC_TEXTFILE
Open base music readme, changelog (+1) or license (+2).
Definition: settings_widget.h:32
BaseSettingEntry::FindEntry
virtual BaseSettingEntry * FindEntry(uint row, uint *cur_row)
Find setting entry at row row_num.
Definition: settings_gui.cpp:878
HideDropDownMenu
int HideDropDownMenu(Window *pw)
Delete the drop-down menu from window pw.
Definition: dropdown.cpp:512
SettingsContainer::UnFoldAll
void UnFoldAll()
Recursively open all folds of sub-pages.
Definition: settings_gui.cpp:1184
SettingDesc
Definition: settings_internal.h:109
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition: widget_type.h:56
SettingsContainer::IsVisible
bool IsVisible(const BaseSettingEntry *item) const
Check whether an entry is visible and not folded or filtered away.
Definition: settings_gui.cpp:1228
SettingsPage::GetFoldingState
virtual void GetFoldingState(bool &all_folded, bool &all_unfolded) const
Recursively accumulate the folding state of the (filtered) tree.
Definition: settings_gui.cpp:1349
SettingsContainer::Length
uint Length() const
Return number of rows needed to display the whole page.
Definition: settings_gui.cpp:1237
WID_GS_RESTRICT_TYPE
@ WID_GS_RESTRICT_TYPE
Label upfront to the type drop-down box to restrict the list of settings to show.
Definition: settings_widget.h:48
FONT_HEIGHT_NORMAL
#define FONT_HEIGHT_NORMAL
Height of characters in the normal (FS_NORMAL) font.
Definition: gfx_func.h:179
video_driver.hpp
NWidget
static NWidgetPart NWidget(WidgetType tp, Colours col, int16 idx=-1)
Widget part function for starting a new 'real' widget.
Definition: widget_type.h:1113
GameSettingsWindow::DrawWidget
void DrawWidget(const Rect &r, int widget) const override
Draw the contents of a nested widget.
Definition: settings_gui.cpp:1967
RM_CHANGED_AGAINST_DEFAULT
@ RM_CHANGED_AGAINST_DEFAULT
Show only settings which are different compared to default values.
Definition: settings_gui.cpp:710
SC_BASIC_LIST
@ SC_BASIC_LIST
Settings displayed in the list of basic settings.
Definition: settings_internal.h:64
geometry_func.hpp
SGF_CURRENCY
@ SGF_CURRENCY
the number represents money, so when reading value multiply by exchange rate
Definition: settings_internal.h:44
SetMinimalSize
static NWidgetPart SetMinimalSize(int16 x, int16 y)
Widget part function for setting the minimal size.
Definition: widget_type.h:946
GameSettingsWindow::OnPaint
void OnPaint() override
The window must be repainted.
Definition: settings_gui.cpp:1884
UpdateAllVirtCoords
void UpdateAllVirtCoords()
Update the viewport coordinates of all signs.
Definition: afterload.cpp:217
StringFilter::ResetState
void ResetState()
Reset the matching state to process a new item.
Definition: stringfilter.cpp:88
WWT_PANEL
@ WWT_PANEL
Simple depressed panel.
Definition: widget_type.h:48
SettingsPage::UpdateFilterState
virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible)
Update the filter state.
Definition: settings_gui.cpp:1368
_video_hw_accel
bool _video_hw_accel
Whether to consider hardware accelerated video drivers.
Definition: video_driver.cpp:23
NWidgetBase::resize_y
uint resize_y
Vertical resize step (0 means not resizable).
Definition: widget_type.h:165
SettingsContainer::FindEntry
BaseSettingEntry * FindEntry(uint row, uint *cur_row)
Find the setting entry at row number row_num.
Definition: settings_gui.cpp:1252
Scrollbar::GetPosition
uint16 GetPosition() const
Gets the position of the first visible element in the list.
Definition: widget_type.h:630
CustomCurrencyWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: settings_gui.cpp:2507
StringFilter::GetState
bool GetState() const
Get the matching state of the current item.
Definition: stringfilter_type.h:69
WD_IMGBTN_TOP
@ WD_IMGBTN_TOP
Top offset of image in the button.
Definition: window_gui.h:40
WID_GO_BASE_MUSIC_STATUS
@ WID_GO_BASE_MUSIC_STATUS
Info about corrupted files etc.
Definition: settings_widget.h:31
SettingDesc::desc
SettingDescBase desc
Settings structure (going to configuration file)
Definition: settings_internal.h:110
Window::FinishInitNested
void FinishInitNested(WindowNumber window_number=0)
Perform the second part of the initialization of a nested widget tree.
Definition: window.cpp:1848
WID_GS_RESTRICT_DROPDOWN
@ WID_GS_RESTRICT_DROPDOWN
The drop down box to restrict the list of settings.
Definition: settings_widget.h:49
NWID_SPACER
@ NWID_SPACER
Invisible widget that takes some space.
Definition: widget_type.h:77
GameSettingsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: settings_gui.cpp:2302
company_func.h
WL_ERROR
@ WL_ERROR
Errors (eg. saving/loading failed)
Definition: error.h:24
SM_MENU
@ SM_MENU
Switch to game intro menu.
Definition: openttd.h:31
GetCurrentResolutionIndex
static uint GetCurrentResolutionIndex()
Get index of the current screen resolution.
Definition: settings_gui.cpp:80
QueryString::ACTION_CLEAR
static const int ACTION_CLEAR
Clear editbox.
Definition: querystring_gui.h:24
SettingsPage::Draw
virtual uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row=0, uint parent_last=0) const
Draw a row in the settings panel.
Definition: settings_gui.cpp:1439
Window::top
int top
y position of top edge of the window
Definition: window_gui.h:318
abs
static T abs(const T a)
Returns the absolute value of (scalar) variable.
Definition: math_func.hpp:21
WID_GO_BASE_GRF_TEXTFILE
@ WID_GO_BASE_GRF_TEXTFILE
Open base GRF readme, changelog (+1) or license (+2).
Definition: settings_widget.h:25
LEVEL_WIDTH
static const int LEVEL_WIDTH
Indenting width of a sub-page in pixels.
Definition: settings_gui.cpp:690
GameOptionsWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: settings_gui.cpp:407
SettingEntry::SetValueDParams
void SetValueDParams(uint first_param, int32 value) const
Set the DParams for drawing the value of a setting.
Definition: settings_gui.cpp:1103
DrawFrameRect
void DrawFrameRect(int left, int top, int right, int bottom, Colours colour, FrameFlags flags)
Draw frame rectangle.
Definition: widget.cpp:175
network.h
SettingsPage::IsVisible
virtual bool IsVisible(const BaseSettingEntry *item) const
Check whether an entry is visible and not folded or filtered away.
Definition: settings_gui.cpp:1391
SettingsContainer::FoldAll
void FoldAll()
Recursively close all folds of sub-pages.
Definition: settings_gui.cpp:1176
ShowDropDownListAt
void ShowDropDownListAt(Window *w, DropDownList &&list, int selected, int button, Rect wi_rect, Colours wi_colour, bool auto_width, bool instant_close)
Show a drop down list.
Definition: dropdown.cpp:366
GUISettings::settings_restriction_mode
uint8 settings_restriction_mode
selected restriction mode in adv. settings GUI.
Definition: settings_type.h:178
window_func.h
CheckForMissingGlyphs
void CheckForMissingGlyphs(bool base_font, MissingGlyphSearcher *searcher)
Check whether the currently loaded language pack uses characters that the currently loaded font does ...
Definition: strings.cpp:2085
GameSettingsWindow::filter
SettingFilter filter
Filter for the list.
Definition: settings_gui.cpp:1810
SetBit
static T SetBit(T &x, const uint8 y)
Set a bit in a variable.
Definition: bitmath_func.hpp:121
BaseMedia< GraphicsSet >::GetSet
static const GraphicsSet * GetSet(int index)
Get the name of the graphics set at the specified index.
Definition: base_media_func.h:342
lengthof
#define lengthof(x)
Return the length of an fixed size array.
Definition: stdafx.h:367
Window::width
int width
width of the window (number of pixels to the right in x direction)
Definition: window_gui.h:319
stringfilter_type.h
Scrollbar::SetCapacityFromWidget
void SetCapacityFromWidget(Window *w, int widget, int padding=0)
Set capacity of visible elements from the size and resize properties of a widget.
Definition: widget.cpp:1980
MarkWholeScreenDirty
void MarkWholeScreenDirty()
This function mark the whole screen as dirty.
Definition: gfx.cpp:1597
GameSettings::locale
LocaleSettings locale
settings related to used currency/unit system in the current game
Definition: settings_type.h:572
SetPIP
static NWidgetPart SetPIP(uint8 pre, uint8 inter, uint8 post)
Widget part function for setting a pre/inter/post spaces.
Definition: widget_type.h:1075
NWidgetBase::pos_y
int pos_y
Vertical position of top-left corner of the widget in the window.
Definition: widget_type.h:176
BaseSettingEntry::IsVisible
virtual bool IsVisible(const BaseSettingEntry *item) const
Check whether an entry is visible and not folded or filtered away.
Definition: settings_gui.cpp:865
SettingEntry::SettingEntry
SettingEntry(const char *name)
Constructor for a single setting in the 'advanced settings' window.
Definition: settings_gui.cpp:955
WID_GO_VIDEO_ACCEL_BUTTON
@ WID_GO_VIDEO_ACCEL_BUTTON
Toggle for video acceleration.
Definition: settings_widget.h:35
GameSettingsWindow::SETTINGTREE_RIGHT_OFFSET
static const int SETTINGTREE_RIGHT_OFFSET
Position of right edge of setting values.
Definition: settings_gui.cpp:1798
SettingFilter
Filter for settings list.
Definition: settings_gui.cpp:717
fontcache.h
RM_CHANGED_AGAINST_NEW
@ RM_CHANGED_AGAINST_NEW
Show only settings which are different compared to the user's new game setting values.
Definition: settings_gui.cpp:711
SetFill
static NWidgetPart SetFill(uint fill_x, uint fill_y)
Widget part function for setting filling.
Definition: widget_type.h:982
TextfileWindow
Window for displaying a textfile.
Definition: textfile_gui.h:21
WID_CC_PREVIEW
@ WID_CC_PREVIEW
Preview.
Definition: settings_widget.h:67
GameOptionsWindow::OnInvalidateData
void OnInvalidateData(int data=0, bool gui_scope=true) override
Some data on this window has become invalid.
Definition: settings_gui.cpp:562
GetSettingsTree
static SettingsContainer & GetSettingsTree()
Construct settings tree.
Definition: settings_gui.cpp:1474
ST_ALL
@ ST_ALL
Used in setting filter to match all types.
Definition: settings_internal.h:84
ReadValue
int64 ReadValue(const void *ptr, VarType conv)
Return a signed-long version of the value of a setting.
Definition: saveload.cpp:749
ClientSettings::company
CompanySettings company
default values for per-company settings
Definition: settings_type.h:579
SettingsContainer
Containers for BaseSettingEntry.
Definition: settings_gui.cpp:797
GameSettingsWindow::closing_dropdown
bool closing_dropdown
True, if the dropdown list is currently closing.
Definition: settings_gui.cpp:1808
BaseSettingEntry::flags
byte flags
Flags of the setting entry.
Definition: settings_gui.cpp:727
Window
Data structure for an opened window.
Definition: window_gui.h:276
TextfileType
TextfileType
Additional text files accompanying Tar archives.
Definition: textfile_type.h:14
SetSettingValue
bool SetSettingValue(uint index, int32 value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
Definition: settings.cpp:1974
WID_GO_BASE_SFX_DESCRIPTION
@ WID_GO_BASE_SFX_DESCRIPTION
Description of selected base SFX.
Definition: settings_widget.h:29
SC_ADVANCED_LIST
@ SC_ADVANCED_LIST
Settings displayed in the list of advanced settings.
Definition: settings_internal.h:65
SettingEntry
Standard setting.
Definition: settings_gui.cpp:764
Pool::PoolItem<&_company_pool >::IsValidID
static bool IsValidID(size_t index)
Tests whether given index can be used to get valid (non-nullptr) Titem.
Definition: pool_type.hpp:318
BaseMedia< GraphicsSet >::GetUsedSet
static const GraphicsSet * GetUsedSet()
Return the used set.
Definition: base_media_func.h:357
Window::DrawWidgets
void DrawWidgets() const
Paint all widgets of a window.
Definition: widget.cpp:602
ZOOM_LVL_OUT_4X
@ ZOOM_LVL_OUT_4X
Zoomed 4 times out.
Definition: zoom_type.h:26
ShowGameSettings
void ShowGameSettings()
Open advanced settings window.
Definition: settings_gui.cpp:2402
DrawBoolButton
void DrawBoolButton(int x, int y, bool state, bool clickable)
Draw a toggle button.
Definition: settings_gui.cpp:2465
settings_gui.h
WD_IMGBTN_LEFT
@ WD_IMGBTN_LEFT
Left offset of the image in the button.
Definition: window_gui.h:38
strecpy
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
Definition: string.cpp:112
WID_TF_CAPTION
@ WID_TF_CAPTION
The caption of the window.
Definition: misc_widget.h:51
SettingEntry::GetHelpText
StringID GetHelpText() const
Get the help text of a single setting.
Definition: settings_gui.cpp:782
WID_GO_CURRENCY_DROPDOWN
@ WID_GO_CURRENCY_DROPDOWN
Currency dropdown.
Definition: settings_widget.h:16
_languages
LanguageList _languages
The actual list of language meta data.
Definition: strings.cpp:45
GetMaskOfAllowedCurrencies
uint64 GetMaskOfAllowedCurrencies()
get a mask of the allowed currencies depending on the year
Definition: currency.cpp:122
BaseSet::GetNumInvalid
int GetNumInvalid() const
Get the number of invalid files.
Definition: base_media_base.h:98
Rect
Specification of a rectangle with absolute coordinates of all edges.
Definition: geometry_type.hpp:47
GameSettingsWindow::manually_changed_folding
bool manually_changed_folding
Whether the user expanded/collapsed something manually.
Definition: settings_gui.cpp:1812
BaseSettingEntry::Draw
virtual uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row=0, uint parent_last=0) const
Draw a row in the settings panel.
Definition: settings_gui.cpp:915
GameSettingsWindow::SetDisplayedHelpText
void SetDisplayedHelpText(SettingEntry *pe)
Set the entry that should have its help text displayed, and mark the window dirty so it gets repainte...
Definition: settings_gui.cpp:2011
AWV_INCREASE
@ AWV_INCREASE
Arrow to the right or in case of RTL to the left.
Definition: widget_type.h:36
QSF_ENABLE_DEFAULT
@ QSF_ENABLE_DEFAULT
enable the 'Default' button ("\0" is returned)
Definition: textbuf_gui.h:21
Window::DisableWidget
void DisableWidget(byte widget_index)
Sets a widget to disabled.
Definition: window_gui.h:402
CLRBITS
#define CLRBITS(x, y)
Clears several bits in a variable.
Definition: bitmath_func.hpp:166
NWidgetBase::current_x
uint current_x
Current horizontal size (after resizing).
Definition: widget_type.h:172
GetVariableAddress
static void * GetVariableAddress(const void *object, const SaveLoad *sld)
Get the address of the variable.
Definition: saveload.h:887
WC_TEXTFILE
@ WC_TEXTFILE
textfile; Window numbers:
Definition: window_type.h:180
lastof
#define lastof(x)
Get the last element of an fixed size array.
Definition: stdafx.h:383
WHR_NONE
@ WHR_NONE
Nothing was filtering matches away.
Definition: settings_gui.cpp:1789
UpdateGUIZoom
void UpdateGUIZoom()
Resolve GUI zoom level, if auto-suggestion is requested.
Definition: gfx.cpp:1870
SettingsContainer::GetFoldingState
void GetFoldingState(bool &all_folded, bool &all_unfolded) const
Recursively accumulate the folding state of the tree.
Definition: settings_gui.cpp:1196
WDP_CENTER
@ WDP_CENTER
Center the window.
Definition: window_gui.h:155
ChangeMusicSet
void ChangeMusicSet(int index)
Change the configured music set and reset playback.
Definition: music_gui.cpp:431
Window::SetWidgetLoweredState
void SetWidgetLoweredState(byte widget_index, bool lowered_stat)
Sets the lowered/raised status of a widget.
Definition: window_gui.h:453
SETTING_BUTTON_HEIGHT
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Definition: settings_gui.h:19
GameSettingsWindow::clicked_entry
SettingEntry * clicked_entry
If non-nullptr, pointer to a clicked numeric setting (with a depressed left or right button).
Definition: settings_gui.cpp:1805
ReadLanguagePack
bool ReadLanguagePack(const LanguageMetadata *lang)
Read a particular language.
Definition: strings.cpp:1712
GameOptionsWindow::OnDropdownSelect
void OnDropdownSelect(int widget, int index) override
A dropdown option associated to this window has been selected.
Definition: settings_gui.cpp:476
_left_button_clicked
bool _left_button_clicked
Is left mouse button clicked?
Definition: gfx.cpp:39
TD_RTL
@ TD_RTL
Text is written right-to-left by default.
Definition: strings_type.h:24
_current_text_dir
TextDirection _current_text_dir
Text direction of the currently selected language.
Definition: strings.cpp:48
GameSettingsWindow::OnEditboxChanged
void OnEditboxChanged(int wid) override
The text in an editbox has been edited.
Definition: settings_gui.cpp:2332
_circle_size
static Dimension _circle_size
Dimension of the circle +/- icon. This is here as not all users are within the class of the settings ...
Definition: settings_gui.cpp:72
CS_NUMERAL
@ CS_NUMERAL
Only numeric ones.
Definition: string_type.h:28
SettingsPage::UnFoldAll
virtual void UnFoldAll()
Recursively open all (filtered) folds of sub-pages.
Definition: settings_gui.cpp:1336
CharSetFilter
CharSetFilter
Valid filter types for IsValidChar.
Definition: string_type.h:26
_currency_specs
CurrencySpec _currency_specs[CURRENCY_END]
Array of currencies used by the system.
Definition: currency.cpp:74
GameSettingsWindow::OnClick
void OnClick(Point pt, int widget, int click_count) override
A click with the left mouse button has been made on the window.
Definition: settings_gui.cpp:2017
WD_TEXTPANEL_BOTTOM
@ WD_TEXTPANEL_BOTTOM
Offset at bottom to draw below the text.
Definition: window_gui.h:67
StringFilter
String filter and state.
Definition: stringfilter_type.h:31
GameOptionsWindow::SetMediaSet
void SetMediaSet(int index)
Set the base media set.
Definition: settings_gui.cpp:463
SettingDescBase::str_help
StringID str_help
(Translated) string with help text; gui only.
Definition: settings_internal.h:101
SetDParamStr
void SetDParamStr(uint n, const char *str)
This function is used to "bind" a C string to a OpenTTD dparam slot.
Definition: strings.cpp:286
CURRENCY_CUSTOM
@ CURRENCY_CUSTOM
Custom currency.
Definition: currency.h:57
_settings_newgame
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
Definition: settings.cpp:81
WWT_TEXTBTN
@ WWT_TEXTBTN
(Toggle) Button with text
Definition: widget_type.h:53
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition: strings_type.h:17
ClientSettings::gui
GUISettings gui
settings related to the GUI
Definition: settings_type.h:577
WID_GS_TYPE_DROPDOWN
@ WID_GS_TYPE_DROPDOWN
The drop down box to choose client/game/company/all settings.
Definition: settings_widget.h:50
GameOptionsWindow::UpdateWidgetSize
void UpdateWidgetSize(int widget, Dimension *size, const Dimension &padding, Dimension *fill, Dimension *resize) override
Update size and resize step of a widget in the window.
Definition: settings_gui.cpp:341
AWV_DECREASE
@ AWV_DECREASE
Arrow to the left or in case of RTL to the right.
Definition: widget_type.h:35
WWT_DROPDOWN
@ WWT_DROPDOWN
Drop down list.
Definition: widget_type.h:68
WD_TEXTPANEL_TOP
@ WD_TEXTPANEL_TOP
Offset at top to draw above the text.
Definition: window_gui.h:66
WID_CC_SUFFIX
@ WID_CC_SUFFIX
Current suffix.
Definition: settings_widget.h:63
BaseSettingEntry::IsFiltered
bool IsFiltered() const
Check whether an entry is hidden due to filters.
Definition: settings_gui.cpp:753
MAX_YEAR
static const Year MAX_YEAR
MAX_YEAR, nicely rounded value of the number of years that can be encoded in a single 32 bits date,...
Definition: date_type.h:94
RM_ADVANCED
@ RM_ADVANCED
Display settings associated to the "advanced" list.
Definition: settings_gui.cpp:708
WN_GAME_OPTIONS_GAME_SETTINGS
@ WN_GAME_OPTIONS_GAME_SETTINGS
Game settings.
Definition: window_type.h:19
ShowGameOptions
void ShowGameOptions()
Open the game options window.
Definition: settings_gui.cpp:683
SettingEntryFlags
SettingEntryFlags
Flags for SettingEntry.
Definition: settings_gui.cpp:696
DropDownListStringItem::NatSortFunc
static bool NatSortFunc(std::unique_ptr< const DropDownListItem > const &first, std::unique_ptr< const DropDownListItem > const &second)
Natural sorting comparator function for DropDownList::sort().
Definition: dropdown.cpp:52