4 * This file is part of OpenTTD.
5 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
6 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
7 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
10 /** @file settings_gui.cpp GUI for settings. */
15 #include "settings_gui.h"
16 #include "textbuf_gui.h"
17 #include "command_func.h"
18 #include "screenshot.h"
19 #include "network/network.h"
21 #include "settings_internal.h"
22 #include "newgrf_townname.h"
23 #include "strings_func.h"
24 #include "window_func.h"
25 #include "string_func.h"
26 #include "widgets/dropdown_type.h"
27 #include "widgets/dropdown_func.h"
28 #include "highscore.h"
29 #include "base_media_base.h"
30 #include "company_base.h"
31 #include "company_func.h"
32 #include "viewport_func.h"
33 #include "core/geometry_func.hpp"
35 #include "blitter/factory.hpp"
37 #include "textfile_gui.h"
38 #include "stringfilter_type.h"
39 #include "querystring_gui.h"
42 static const StringID _driveside_dropdown
[] = {
43 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT
,
44 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT
,
48 static const StringID _autosave_dropdown
[] = {
49 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF
,
50 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH
,
51 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS
,
52 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS
,
53 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS
,
57 int _nb_orig_names
= SPECSTR_TOWNNAME_LAST
- SPECSTR_TOWNNAME_START
+ 1; ///< Number of original town names.
58 static StringID
*_grf_names
= NULL
; ///< Pointer to town names defined by NewGRFs.
59 static int _nb_grf_names
= 0; ///< Number of town names defined by NewGRFs.
61 static const void *ResolveVariableAddress(const GameSettings
*settings_ptr
, const SettingDesc
*sd
);
63 /** Allocate memory for the NewGRF town names. */
64 void InitGRFTownGeneratorNames()
67 _grf_names
= GetGRFTownNameList();
69 for (StringID
*s
= _grf_names
; *s
!= INVALID_STRING_ID
; s
++) _nb_grf_names
++;
74 * @param town_name Number of the wanted town name.
75 * @return Name of the town as string ID.
77 static inline StringID
TownName(int town_name
)
79 if (town_name
< _nb_orig_names
) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH
+ town_name
;
80 town_name
-= _nb_orig_names
;
81 if (town_name
< _nb_grf_names
) return _grf_names
[town_name
];
86 * Get index of the current screen resolution.
87 * @return Index of the current screen resolution if it is a known resolution, #_num_resolutions otherwise.
89 static int GetCurRes()
93 for (i
= 0; i
!= _num_resolutions
; i
++) {
94 if ((int)_resolutions
[i
].width
== _screen
.width
&&
95 (int)_resolutions
[i
].height
== _screen
.height
) {
102 static void ShowCustCurrency();
105 static DropDownList
*BuiltSetDropDownList(int *selected_index
)
107 int n
= T::GetNumSets();
108 *selected_index
= T::GetIndexOfUsedSet();
110 DropDownList
*list
= new DropDownList();
111 for (int i
= 0; i
< n
; i
++) {
112 *list
->Append() = new DropDownListCharStringItem(T::GetSet(i
)->name
, i
, (_game_mode
== GM_MENU
) ? false : (*selected_index
!= i
));
118 /** Window for displaying the textfile of a BaseSet. */
119 template <class TBaseSet
>
120 struct BaseSetTextfileWindow
: public TextfileWindow
{
121 const TBaseSet
* baseset
; ///< View the textfile of this BaseSet.
122 StringID content_type
; ///< STR_CONTENT_TYPE_xxx for title.
124 BaseSetTextfileWindow(TextfileType file_type
, const TBaseSet
* baseset
, StringID content_type
) : TextfileWindow(file_type
), baseset(baseset
), content_type(content_type
)
126 const char *textfile
= this->baseset
->GetTextfile(file_type
);
127 this->LoadTextfile(textfile
, BASESET_DIR
);
130 /* virtual */ void SetStringParameters(int widget
) const
132 if (widget
== WID_TF_CAPTION
) {
133 SetDParam(0, content_type
);
134 SetDParamStr(1, this->baseset
->name
);
140 * Open the BaseSet version of the textfile window.
141 * @param file_type The type of textfile to display.
142 * @param baseset The BaseSet to use.
143 * @param content_type STR_CONTENT_TYPE_xxx for title.
145 template <class TBaseSet
>
146 void ShowBaseSetTextfileWindow(TextfileType file_type
, const TBaseSet
* baseset
, StringID content_type
)
148 DeleteWindowByClass(WC_TEXTFILE
);
149 new BaseSetTextfileWindow
<TBaseSet
>(file_type
, baseset
, content_type
);
152 struct GameOptionsWindow
: Window
{
156 GameOptionsWindow(WindowDesc
*desc
) : Window(desc
)
158 this->opt
= &GetGameSettings();
159 this->reload
= false;
161 this->InitNested(WN_GAME_OPTIONS_GAME_OPTIONS
);
162 this->OnInvalidateData(0);
167 DeleteWindowById(WC_CUSTOM_CURRENCY
, 0);
168 if (this->reload
) _switch_mode
= SM_MENU
;
172 * Build the dropdown list for a specific widget.
173 * @param widget Widget to build list for
174 * @param selected_index Currently selected item
175 * @return the built dropdown list, or NULL if the widget has no dropdown menu.
177 DropDownList
*BuildDropDownList(int widget
, int *selected_index
) const
179 DropDownList
*list
= NULL
;
181 case WID_GO_CURRENCY_DROPDOWN
: { // Setup currencies dropdown
182 list
= new DropDownList();
183 *selected_index
= this->opt
->locale
.currency
;
184 StringID
*items
= BuildCurrencyDropdown();
185 uint64 disabled
= _game_mode
== GM_MENU
? 0LL : ~GetMaskOfAllowedCurrencies();
187 /* Add non-custom currencies; sorted naturally */
188 for (uint i
= 0; i
< CURRENCY_END
; items
++, i
++) {
189 if (i
== CURRENCY_CUSTOM
) continue;
190 *list
->Append() = new DropDownListStringItem(*items
, i
, HasBit(disabled
, i
));
192 QSortT(list
->Begin(), list
->Length(), DropDownListStringItem::NatSortFunc
);
194 /* Append custom currency at the end */
195 *list
->Append() = new DropDownListItem(-1, false); // separator line
196 *list
->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM
, CURRENCY_CUSTOM
, HasBit(disabled
, CURRENCY_CUSTOM
));
200 case WID_GO_ROADSIDE_DROPDOWN
: { // Setup road-side dropdown
201 list
= new DropDownList();
202 *selected_index
= this->opt
->vehicle
.road_side
;
203 const StringID
*items
= _driveside_dropdown
;
206 /* You can only change the drive side if you are in the menu or ingame with
207 * no vehicles present. In a networking game only the server can change it */
208 extern bool RoadVehiclesAreBuilt();
209 if ((_game_mode
!= GM_MENU
&& RoadVehiclesAreBuilt()) || (_networking
&& !_network_server
)) {
210 disabled
= ~(1 << this->opt
->vehicle
.road_side
); // disable the other value
213 for (uint i
= 0; *items
!= INVALID_STRING_ID
; items
++, i
++) {
214 *list
->Append() = new DropDownListStringItem(*items
, i
, HasBit(disabled
, i
));
219 case WID_GO_TOWNNAME_DROPDOWN
: { // Setup townname dropdown
220 list
= new DropDownList();
221 *selected_index
= this->opt
->game_creation
.town_name
;
223 int enabled_item
= (_game_mode
== GM_MENU
|| Town::GetNumItems() == 0) ? -1 : *selected_index
;
225 /* Add and sort newgrf townnames generators */
226 for (int i
= 0; i
< _nb_grf_names
; i
++) {
227 int result
= _nb_orig_names
+ i
;
228 *list
->Append() = new DropDownListStringItem(_grf_names
[i
], result
, enabled_item
!= result
&& enabled_item
>= 0);
230 QSortT(list
->Begin(), list
->Length(), DropDownListStringItem::NatSortFunc
);
232 int newgrf_size
= list
->Length();
233 /* Insert newgrf_names at the top of the list */
234 if (newgrf_size
> 0) {
235 *list
->Append() = new DropDownListItem(-1, false); // separator line
239 /* Add and sort original townnames generators */
240 for (int i
= 0; i
< _nb_orig_names
; i
++) {
241 *list
->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH
+ i
, i
, enabled_item
!= i
&& enabled_item
>= 0);
243 QSortT(list
->Begin() + newgrf_size
, list
->Length() - newgrf_size
, DropDownListStringItem::NatSortFunc
);
247 case WID_GO_AUTOSAVE_DROPDOWN
: { // Setup autosave dropdown
248 list
= new DropDownList();
249 *selected_index
= _settings_client
.gui
.autosave
;
250 const StringID
*items
= _autosave_dropdown
;
251 for (uint i
= 0; *items
!= INVALID_STRING_ID
; items
++, i
++) {
252 *list
->Append() = new DropDownListStringItem(*items
, i
, false);
257 case WID_GO_LANG_DROPDOWN
: { // Setup interface language dropdown
258 list
= new DropDownList();
259 for (uint i
= 0; i
< _languages
.Length(); i
++) {
260 if (&_languages
[i
] == _current_language
) *selected_index
= i
;
261 *list
->Append() = new DropDownListStringItem(SPECSTR_LANGUAGE_START
+ i
, i
, false);
263 QSortT(list
->Begin(), list
->Length(), DropDownListStringItem::NatSortFunc
);
267 case WID_GO_RESOLUTION_DROPDOWN
: // Setup resolution dropdown
268 list
= new DropDownList();
269 *selected_index
= GetCurRes();
270 for (int i
= 0; i
< _num_resolutions
; i
++) {
271 *list
->Append() = new DropDownListStringItem(SPECSTR_RESOLUTION_START
+ i
, i
, false);
275 case WID_GO_SCREENSHOT_DROPDOWN
: // Setup screenshot format dropdown
276 list
= new DropDownList();
277 *selected_index
= _cur_screenshot_format
;
278 for (uint i
= 0; i
< _num_screenshot_formats
; i
++) {
279 if (!GetScreenshotFormatSupports_32bpp(i
) && BlitterFactory::GetCurrentBlitter()->GetScreenDepth() == 32) continue;
280 *list
->Append() = new DropDownListStringItem(SPECSTR_SCREENSHOT_START
+ i
, i
, false);
284 case WID_GO_BASE_GRF_DROPDOWN
:
285 list
= BuiltSetDropDownList
<BaseGraphics
>(selected_index
);
288 case WID_GO_BASE_SFX_DROPDOWN
:
289 list
= BuiltSetDropDownList
<BaseSounds
>(selected_index
);
292 case WID_GO_BASE_MUSIC_DROPDOWN
:
293 list
= BuiltSetDropDownList
<BaseMusic
>(selected_index
);
303 virtual void SetStringParameters(int widget
) const
306 case WID_GO_CURRENCY_DROPDOWN
: SetDParam(0, _currency_specs
[this->opt
->locale
.currency
].name
); break;
307 case WID_GO_ROADSIDE_DROPDOWN
: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT
+ this->opt
->vehicle
.road_side
); break;
308 case WID_GO_TOWNNAME_DROPDOWN
: SetDParam(0, TownName(this->opt
->game_creation
.town_name
)); break;
309 case WID_GO_AUTOSAVE_DROPDOWN
: SetDParam(0, _autosave_dropdown
[_settings_client
.gui
.autosave
]); break;
310 case WID_GO_LANG_DROPDOWN
: SetDParamStr(0, _current_language
->own_name
); break;
311 case WID_GO_RESOLUTION_DROPDOWN
: SetDParam(0, GetCurRes() == _num_resolutions
? STR_GAME_OPTIONS_RESOLUTION_OTHER
: SPECSTR_RESOLUTION_START
+ GetCurRes()); break;
312 case WID_GO_SCREENSHOT_DROPDOWN
: SetDParam(0, SPECSTR_SCREENSHOT_START
+ _cur_screenshot_format
); break;
313 case WID_GO_BASE_GRF_DROPDOWN
: SetDParamStr(0, BaseGraphics::GetUsedSet()->name
); break;
314 case WID_GO_BASE_GRF_STATUS
: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
315 case WID_GO_BASE_SFX_DROPDOWN
: SetDParamStr(0, BaseSounds::GetUsedSet()->name
); break;
316 case WID_GO_BASE_MUSIC_DROPDOWN
: SetDParamStr(0, BaseMusic::GetUsedSet()->name
); break;
317 case WID_GO_BASE_MUSIC_STATUS
: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
321 virtual void DrawWidget(const Rect
&r
, int widget
) const
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
);
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
);
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
);
341 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
344 case WID_GO_BASE_GRF_DESCRIPTION
:
345 /* Find the biggest description for the default size. */
346 for (int i
= 0; i
< BaseGraphics::GetNumSets(); i
++) {
347 SetDParamStr(0, BaseGraphics::GetSet(i
)->GetDescription(GetCurrentLanguageIsoCode()));
348 size
->height
= max(size
->height
, (uint
)GetStringHeight(STR_BLACK_RAW_STRING
, size
->width
));
352 case WID_GO_BASE_GRF_STATUS
:
353 /* Find the biggest description for the default size. */
354 for (int i
= 0; i
< BaseGraphics::GetNumSets(); i
++) {
355 uint invalid_files
= BaseGraphics::GetSet(i
)->GetNumInvalid();
356 if (invalid_files
== 0) continue;
358 SetDParam(0, invalid_files
);
359 *size
= maxdim(*size
, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_GRF_STATUS
));
363 case WID_GO_BASE_SFX_DESCRIPTION
:
364 /* Find the biggest description for the default size. */
365 for (int i
= 0; i
< BaseSounds::GetNumSets(); i
++) {
366 SetDParamStr(0, BaseSounds::GetSet(i
)->GetDescription(GetCurrentLanguageIsoCode()));
367 size
->height
= max(size
->height
, (uint
)GetStringHeight(STR_BLACK_RAW_STRING
, size
->width
));
371 case WID_GO_BASE_MUSIC_DESCRIPTION
:
372 /* Find the biggest description for the default size. */
373 for (int i
= 0; i
< BaseMusic::GetNumSets(); i
++) {
374 SetDParamStr(0, BaseMusic::GetSet(i
)->GetDescription(GetCurrentLanguageIsoCode()));
375 size
->height
= max(size
->height
, (uint
)GetStringHeight(STR_BLACK_RAW_STRING
, size
->width
));
379 case WID_GO_BASE_MUSIC_STATUS
:
380 /* Find the biggest description for the default size. */
381 for (int i
= 0; i
< BaseMusic::GetNumSets(); i
++) {
382 uint invalid_files
= BaseMusic::GetSet(i
)->GetNumInvalid();
383 if (invalid_files
== 0) continue;
385 SetDParam(0, invalid_files
);
386 *size
= maxdim(*size
, GetStringBoundingBox(STR_GAME_OPTIONS_BASE_MUSIC_STATUS
));
392 DropDownList
*list
= this->BuildDropDownList(widget
, &selected
);
394 /* Find the biggest item for the default size. */
395 for (const DropDownListItem
* const *it
= list
->Begin(); it
!= list
->End(); it
++) {
396 Dimension string_dim
;
397 int width
= (*it
)->Width();
398 string_dim
.width
= width
+ padding
.width
;
399 string_dim
.height
= (*it
)->Height(width
) + padding
.height
;
400 *size
= maxdim(*size
, string_dim
);
408 virtual void OnClick(Point pt
, int widget
, int click_count
)
410 if (widget
>= WID_GO_BASE_GRF_TEXTFILE
&& widget
< WID_GO_BASE_GRF_TEXTFILE
+ TFT_END
) {
411 if (BaseGraphics::GetUsedSet() == NULL
) return;
413 ShowBaseSetTextfileWindow((TextfileType
)(widget
- WID_GO_BASE_GRF_TEXTFILE
), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS
);
416 if (widget
>= WID_GO_BASE_SFX_TEXTFILE
&& widget
< WID_GO_BASE_SFX_TEXTFILE
+ TFT_END
) {
417 if (BaseSounds::GetUsedSet() == NULL
) return;
419 ShowBaseSetTextfileWindow((TextfileType
)(widget
- WID_GO_BASE_SFX_TEXTFILE
), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS
);
422 if (widget
>= WID_GO_BASE_MUSIC_TEXTFILE
&& widget
< WID_GO_BASE_MUSIC_TEXTFILE
+ TFT_END
) {
423 if (BaseMusic::GetUsedSet() == NULL
) return;
425 ShowBaseSetTextfileWindow((TextfileType
)(widget
- WID_GO_BASE_MUSIC_TEXTFILE
), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC
);
429 case WID_GO_FULLSCREEN_BUTTON
: // Click fullscreen on/off
430 /* try to toggle full-screen on/off */
431 if (!ToggleFullScreen(!_fullscreen
)) {
432 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED
, INVALID_STRING_ID
, WL_ERROR
);
434 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON
, _fullscreen
);
440 DropDownList
*list
= this->BuildDropDownList(widget
, &selected
);
442 ShowDropDownList(this, list
, selected
, widget
);
450 * Set the base media set.
451 * @param index the index of the media set
452 * @tparam T class of media set
455 void SetMediaSet(int index
)
457 if (_game_mode
== GM_MENU
) {
458 const char *name
= T::GetSet(index
)->name
;
461 T::ini_set
= strdup(name
);
465 this->InvalidateData();
469 virtual void OnDropdownSelect(int widget
, int index
)
472 case WID_GO_CURRENCY_DROPDOWN
: // Currency
473 if (index
== CURRENCY_CUSTOM
) ShowCustCurrency();
474 this->opt
->locale
.currency
= index
;
478 case WID_GO_ROADSIDE_DROPDOWN
: // Road side
479 if (this->opt
->vehicle
.road_side
!= index
) { // only change if setting changed
481 if (GetSettingFromName("vehicle.road_side", &i
) == NULL
) NOT_REACHED();
482 SetSettingValue(i
, index
);
483 MarkWholeScreenDirty();
487 case WID_GO_TOWNNAME_DROPDOWN
: // Town names
488 if (_game_mode
== GM_MENU
|| Town::GetNumItems() == 0) {
489 this->opt
->game_creation
.town_name
= index
;
490 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_OPTIONS
);
494 case WID_GO_AUTOSAVE_DROPDOWN
: // Autosave options
495 _settings_client
.gui
.autosave
= index
;
499 case WID_GO_LANG_DROPDOWN
: // Change interface language
500 ReadLanguagePack(&_languages
[index
]);
501 DeleteWindowByClass(WC_QUERY_STRING
);
502 CheckForMissingGlyphs();
503 UpdateAllVirtCoords();
507 case WID_GO_RESOLUTION_DROPDOWN
: // Change resolution
508 if (index
< _num_resolutions
&& ChangeResInGame(_resolutions
[index
].width
, _resolutions
[index
].height
)) {
513 case WID_GO_SCREENSHOT_DROPDOWN
: // Change screenshot format
514 SetScreenshotFormat(index
);
518 case WID_GO_BASE_GRF_DROPDOWN
:
519 this->SetMediaSet
<BaseGraphics
>(index
);
522 case WID_GO_BASE_SFX_DROPDOWN
:
523 this->SetMediaSet
<BaseSounds
>(index
);
526 case WID_GO_BASE_MUSIC_DROPDOWN
:
527 this->SetMediaSet
<BaseMusic
>(index
);
533 * Some data on this window has become invalid.
534 * @param data Information about the changed data. @see GameOptionsInvalidationData
535 * @param gui_scope Whether the call is done from GUI scope. You may not do everything when not in GUI scope. See #InvalidateWindowData() for details.
537 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
539 if (!gui_scope
) return;
540 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON
, _fullscreen
);
542 bool missing_files
= BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
543 this->GetWidget
<NWidgetCore
>(WID_GO_BASE_GRF_STATUS
)->SetDataTip(missing_files
? STR_EMPTY
: STR_GAME_OPTIONS_BASE_GRF_STATUS
, STR_NULL
);
545 for (TextfileType tft
= TFT_BEGIN
; tft
< TFT_END
; tft
++) {
546 this->SetWidgetDisabledState(WID_GO_BASE_GRF_TEXTFILE
+ tft
, BaseGraphics::GetUsedSet() == NULL
|| BaseGraphics::GetUsedSet()->GetTextfile(tft
) == NULL
);
547 this->SetWidgetDisabledState(WID_GO_BASE_SFX_TEXTFILE
+ tft
, BaseSounds::GetUsedSet() == NULL
|| BaseSounds::GetUsedSet()->GetTextfile(tft
) == NULL
);
548 this->SetWidgetDisabledState(WID_GO_BASE_MUSIC_TEXTFILE
+ tft
, BaseMusic::GetUsedSet() == NULL
|| BaseMusic::GetUsedSet()->GetTextfile(tft
) == NULL
);
551 missing_files
= BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
552 this->GetWidget
<NWidgetCore
>(WID_GO_BASE_MUSIC_STATUS
)->SetDataTip(missing_files
? STR_EMPTY
: STR_GAME_OPTIONS_BASE_MUSIC_STATUS
, STR_NULL
);
556 static const NWidgetPart _nested_game_options_widgets
[] = {
557 NWidget(NWID_HORIZONTAL
),
558 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
559 NWidget(WWT_CAPTION
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
561 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_GO_BACKGROUND
), SetPIP(6, 6, 10),
562 NWidget(NWID_HORIZONTAL
), SetPIP(10, 10, 10),
563 NWidget(NWID_VERTICAL
), SetPIP(0, 6, 0),
564 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME
, STR_NULL
),
565 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),
567 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME
, STR_NULL
),
568 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_ROADSIDE_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING
, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_TOOLTIP
), SetFill(1, 0),
570 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME
, STR_NULL
),
571 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),
573 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_RESOLUTION
, STR_NULL
),
574 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_RESOLUTION_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING
, STR_GAME_OPTIONS_RESOLUTION_TOOLTIP
), SetFill(1, 0), SetPadding(0, 0, 3, 0),
575 NWidget(NWID_HORIZONTAL
),
576 NWidget(WWT_TEXT
, COLOUR_GREY
), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN
, STR_NULL
),
577 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_GO_FULLSCREEN_BUTTON
), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY
, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP
),
582 NWidget(NWID_VERTICAL
), SetPIP(0, 6, 0),
583 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME
, STR_NULL
),
584 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_TOWNNAME_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING
, STR_GAME_OPTIONS_TOWN_NAMES_DROPDOWN_TOOLTIP
), SetFill(1, 0),
586 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_LANGUAGE
, STR_NULL
),
587 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),
589 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_SCREENSHOT_FORMAT
, STR_NULL
),
590 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_SCREENSHOT_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING
, STR_GAME_OPTIONS_SCREENSHOT_FORMAT_TOOLTIP
), SetFill(1, 0),
592 NWidget(NWID_SPACER
), SetMinimalSize(0, 0), SetFill(0, 1),
596 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_BASE_GRF
, STR_NULL
), SetPadding(0, 10, 0, 10),
597 NWidget(NWID_HORIZONTAL
), SetPIP(0, 30, 0),
598 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_BASE_GRF_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING
, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP
),
599 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_GO_BASE_GRF_STATUS
), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY
, STR_NULL
), SetFill(1, 0),
601 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),
602 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(7, 0, 7),
603 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
),
604 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
),
605 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
),
609 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_BASE_SFX
, STR_NULL
), SetPadding(0, 10, 0, 10),
610 NWidget(NWID_HORIZONTAL
), SetPIP(0, 30, 0),
611 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_BASE_SFX_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING
, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP
),
612 NWidget(NWID_SPACER
), SetFill(1, 0),
614 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),
615 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(7, 0, 7),
616 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
),
617 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
),
618 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
),
622 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC
, STR_NULL
), SetPadding(0, 10, 0, 10),
623 NWidget(NWID_HORIZONTAL
), SetPIP(0, 30, 0),
624 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_BASE_MUSIC_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING
, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP
),
625 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_GO_BASE_MUSIC_STATUS
), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY
, STR_NULL
), SetFill(1, 0),
627 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),
628 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(7, 0, 7),
629 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
),
630 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
),
631 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
),
637 static WindowDesc
_game_options_desc(
638 WDP_CENTER
, "settings_game", 0, 0,
639 WC_GAME_OPTIONS
, WC_NONE
,
641 _nested_game_options_widgets
, lengthof(_nested_game_options_widgets
)
644 /** Open the game options window. */
645 void ShowGameOptions()
647 DeleteWindowByClass(WC_GAME_OPTIONS
);
648 new GameOptionsWindow(&_game_options_desc
);
651 static int SETTING_HEIGHT
= 11; ///< Height of a single setting in the tree view in pixels
652 static const int LEVEL_WIDTH
= 15; ///< Indenting width of a sub-page in pixels
655 * Flags for #SettingEntry
656 * @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
658 enum SettingEntryFlags
{
659 SEF_LEFT_DEPRESSED
= 0x01, ///< Of a numeric setting entry, the left button is depressed
660 SEF_RIGHT_DEPRESSED
= 0x02, ///< Of a numeric setting entry, the right button is depressed
661 SEF_BUTTONS_MASK
= (SEF_LEFT_DEPRESSED
| SEF_RIGHT_DEPRESSED
), ///< Bit-mask for button flags
663 SEF_LAST_FIELD
= 0x04, ///< This entry is the last one in a (sub-)page
664 SEF_FILTERED
= 0x08, ///< Entry is hidden by the string filter
667 SEF_SETTING_KIND
= 0x10, ///< Entry kind: Entry is a setting
668 SEF_SUBTREE_KIND
= 0x20, ///< Entry kind: Entry is a sub-tree
669 SEF_KIND_MASK
= (SEF_SETTING_KIND
| SEF_SUBTREE_KIND
), ///< Bit-mask for fetching entry kind
672 struct SettingsPage
; // Forward declaration
674 /** Data fields for a sub-page (#SEF_SUBTREE_KIND kind)*/
675 struct SettingEntrySubtree
{
676 SettingsPage
*page
; ///< Pointer to the sub-page
677 bool folded
; ///< Sub-page is folded (not visible except for its title)
678 StringID title
; ///< Title of the sub-page
681 /** Data fields for a single setting (#SEF_SETTING_KIND kind) */
682 struct SettingEntrySetting
{
683 const char *name
; ///< Name of the setting
684 const SettingDesc
*setting
; ///< Setting description of the setting
685 uint index
; ///< Index of the setting in the settings table
688 /** How the list of advanced settings is filtered. */
689 enum RestrictionMode
{
690 RM_BASIC
, ///< Display settings associated to the "basic" list.
691 RM_ADVANCED
, ///< Display settings associated to the "advanced" list.
692 RM_ALL
, ///< List all settings regardless of the default/newgame/... values.
693 RM_CHANGED_AGAINST_DEFAULT
, ///< Show only settings which are different compared to default values.
694 RM_CHANGED_AGAINST_NEW
, ///< Show only settings which are different compared to the user's new game setting values.
695 RM_END
, ///< End for iteration.
697 DECLARE_POSTFIX_INCREMENT(RestrictionMode
)
699 /** Filter for settings list. */
700 struct SettingFilter
{
701 StringFilter string
; ///< Filter string.
702 RestrictionMode min_cat
; ///< Minimum category needed to display all filtered strings (#RM_BASIC, #RM_ADVANCED, or #RM_ALL).
703 bool type_hides
; ///< Whether the type hides filtered strings.
704 RestrictionMode mode
; ///< Filter based on category.
705 SettingType type
; ///< Filter based on type.
708 /** Data structure describing a single setting in a tab */
709 struct SettingEntry
{
710 byte flags
; ///< Flags of the setting entry. @see SettingEntryFlags
711 byte level
; ///< Nesting level of this setting entry
713 SettingEntrySetting entry
; ///< Data fields if entry is a setting
714 SettingEntrySubtree sub
; ///< Data fields if entry is a sub-page
715 } d
; ///< Data fields for each kind
717 SettingEntry(const char *nm
);
718 SettingEntry(SettingsPage
*sub
, StringID title
);
720 void Init(byte level
);
723 void SetButtons(byte new_val
);
726 * Set whether this is the last visible entry of the parent node.
727 * @param last_field Value to set
729 void SetLastField(bool last_field
) { if (last_field
) SETBITS(this->flags
, SEF_LAST_FIELD
); else CLRBITS(this->flags
, SEF_LAST_FIELD
); }
732 void GetFoldingState(bool &all_folded
, bool &all_unfolded
) const;
733 bool IsVisible(const SettingEntry
*item
) const;
734 SettingEntry
*FindEntry(uint row
, uint
*cur_row
);
735 uint
GetMaxHelpHeight(int maxw
);
737 bool IsFiltered() const;
738 bool UpdateFilterState(SettingFilter
&filter
, bool force_visible
);
740 uint
Draw(GameSettings
*settings_ptr
, int base_x
, int base_y
, int max_x
, uint first_row
, uint max_row
, uint cur_row
, uint parent_last
, SettingEntry
*selected
);
743 * Get the help text of a single setting.
744 * @return The requested help text.
746 inline StringID
GetHelpText()
748 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
749 return this->d
.entry
.setting
->desc
.str_help
;
752 void SetValueDParams(uint first_param
, int32 value
);
755 void DrawSetting(GameSettings
*settings_ptr
, int x
, int y
, int max_x
, int state
, bool highlight
);
756 bool IsVisibleByRestrictionMode(RestrictionMode mode
) const;
759 /** Data structure describing one page of settings in the settings window. */
760 struct SettingsPage
{
761 SettingEntry
*entries
; ///< Array of setting entries of the page.
762 byte num
; ///< Number of entries on the page (statically filled).
764 void Init(byte level
= 0);
769 void GetFoldingState(bool &all_folded
, bool &all_unfolded
) const;
770 bool IsVisible(const SettingEntry
*item
) const;
771 SettingEntry
*FindEntry(uint row
, uint
*cur_row
) const;
772 uint
GetMaxHelpHeight(int maxw
);
774 bool UpdateFilterState(SettingFilter
&filter
, bool force_visible
);
776 uint
Draw(GameSettings
*settings_ptr
, int base_x
, int base_y
, int max_x
, uint first_row
, uint max_row
, SettingEntry
*selected
, uint cur_row
= 0, uint parent_last
= 0) const;
780 /* == SettingEntry methods == */
783 * Constructor for a single setting in the 'advanced settings' window
784 * @param nm Name of the setting in the setting table
786 SettingEntry::SettingEntry(const char *nm
)
788 this->flags
= SEF_SETTING_KIND
;
790 this->d
.entry
.name
= nm
;
791 this->d
.entry
.setting
= NULL
;
792 this->d
.entry
.index
= 0;
796 * Constructor for a sub-page in the 'advanced settings' window
797 * @param sub Sub-page
798 * @param title Title of the sub-page
800 SettingEntry::SettingEntry(SettingsPage
*sub
, StringID title
)
802 this->flags
= SEF_SUBTREE_KIND
;
804 this->d
.sub
.page
= sub
;
805 this->d
.sub
.folded
= true;
806 this->d
.sub
.title
= title
;
810 * Initialization of a setting entry
811 * @param level Page nesting level of this entry
813 void SettingEntry::Init(byte level
)
817 switch (this->flags
& SEF_KIND_MASK
) {
818 case SEF_SETTING_KIND
:
819 this->d
.entry
.setting
= GetSettingFromName(this->d
.entry
.name
, &this->d
.entry
.index
);
820 assert(this->d
.entry
.setting
!= NULL
);
822 case SEF_SUBTREE_KIND
:
823 this->d
.sub
.page
->Init(level
+ 1);
825 default: NOT_REACHED();
829 /** Recursively close all (filtered) folds of sub-pages */
830 void SettingEntry::FoldAll()
832 if (this->IsFiltered()) return;
833 switch (this->flags
& SEF_KIND_MASK
) {
834 case SEF_SETTING_KIND
:
837 case SEF_SUBTREE_KIND
:
838 this->d
.sub
.folded
= true;
839 this->d
.sub
.page
->FoldAll();
842 default: NOT_REACHED();
846 /** Recursively open all (filtered) folds of sub-pages */
847 void SettingEntry::UnFoldAll()
849 if (this->IsFiltered()) return;
850 switch (this->flags
& SEF_KIND_MASK
) {
851 case SEF_SETTING_KIND
:
854 case SEF_SUBTREE_KIND
:
855 this->d
.sub
.folded
= false;
856 this->d
.sub
.page
->UnFoldAll();
859 default: NOT_REACHED();
864 * Recursively accumulate the folding state of the (filtered) tree.
865 * @param[in,out] all_folded Set to false, if one entry is not folded.
866 * @param[in,out] all_unfolded Set to false, if one entry is folded.
868 void SettingEntry::GetFoldingState(bool &all_folded
, bool &all_unfolded
) const
870 if (this->IsFiltered()) return;
871 switch (this->flags
& SEF_KIND_MASK
) {
872 case SEF_SETTING_KIND
:
875 case SEF_SUBTREE_KIND
:
876 if (this->d
.sub
.folded
) {
877 all_unfolded
= false;
881 this->d
.sub
.page
->GetFoldingState(all_folded
, all_unfolded
);
884 default: NOT_REACHED();
889 * Check whether an entry is visible and not folded or filtered away.
890 * Note: This does not consider the scrolling range; it might still require scrolling to make the setting really visible.
891 * @param item Entry to search for.
892 * @return true if entry is visible.
894 bool SettingEntry::IsVisible(const SettingEntry
*item
) const
896 if (this->IsFiltered()) return false;
897 if (this == item
) return true;
899 switch (this->flags
& SEF_KIND_MASK
) {
900 case SEF_SETTING_KIND
:
903 case SEF_SUBTREE_KIND
:
904 return !this->d
.sub
.folded
&& this->d
.sub
.page
->IsVisible(item
);
906 default: NOT_REACHED();
911 * Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
912 * @param new_val New value for the button flags
913 * @see SettingEntryFlags
915 void SettingEntry::SetButtons(byte new_val
)
917 assert((new_val
& ~SEF_BUTTONS_MASK
) == 0); // Should not touch any flags outside the buttons
918 this->flags
= (this->flags
& ~SEF_BUTTONS_MASK
) | new_val
;
921 /** Return numbers of rows needed to display the (filtered) entry */
922 uint
SettingEntry::Length() const
924 if (this->IsFiltered()) return 0;
925 switch (this->flags
& SEF_KIND_MASK
) {
926 case SEF_SETTING_KIND
:
928 case SEF_SUBTREE_KIND
:
929 if (this->d
.sub
.folded
) return 1; // Only displaying the title
931 return 1 + this->d
.sub
.page
->Length(); // 1 extra row for the title
932 default: NOT_REACHED();
937 * Find setting entry at row \a row_num
938 * @param row_num Index of entry to return
939 * @param cur_row Current row number
940 * @return The requested setting entry or \c NULL if it not found (folded or filtered)
942 SettingEntry
*SettingEntry::FindEntry(uint row_num
, uint
*cur_row
)
944 if (this->IsFiltered()) return NULL
;
945 if (row_num
== *cur_row
) return this;
947 switch (this->flags
& SEF_KIND_MASK
) {
948 case SEF_SETTING_KIND
:
951 case SEF_SUBTREE_KIND
:
952 (*cur_row
)++; // add one for row containing the title
953 if (this->d
.sub
.folded
) {
957 /* sub-page is visible => search it too */
958 return this->d
.sub
.page
->FindEntry(row_num
, cur_row
);
959 default: NOT_REACHED();
965 * Get the biggest height of the help text(s), if the width is at least \a maxw. Help text gets wrapped if needed.
966 * @param maxw Maximal width of a line help text.
967 * @return Biggest height needed to display any help text of this node (and its descendants).
969 uint
SettingEntry::GetMaxHelpHeight(int maxw
)
971 switch (this->flags
& SEF_KIND_MASK
) {
972 case SEF_SETTING_KIND
: return GetStringHeight(this->GetHelpText(), maxw
);
973 case SEF_SUBTREE_KIND
: return this->d
.sub
.page
->GetMaxHelpHeight(maxw
);
974 default: NOT_REACHED();
979 * Check whether an entry is hidden due to filters
980 * @return true if hidden.
982 bool SettingEntry::IsFiltered() const
984 return (this->flags
& SEF_FILTERED
) != 0;
988 * Checks whether an entry shall be made visible based on the restriction mode.
989 * @param mode The current status of the restriction drop down box.
990 * @return true if the entry shall be visible.
992 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode
) const
994 /* There shall not be any restriction, i.e. all settings shall be visible. */
995 if (mode
== RM_ALL
) return true;
997 GameSettings
*settings_ptr
= &GetGameSettings();
998 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
999 const SettingDesc
*sd
= this->d
.entry
.setting
;
1001 if (mode
== RM_BASIC
) return (this->d
.entry
.setting
->desc
.cat
& SC_BASIC_LIST
) != 0;
1002 if (mode
== RM_ADVANCED
) return (this->d
.entry
.setting
->desc
.cat
& SC_ADVANCED_LIST
) != 0;
1004 /* Read the current value. */
1005 const void *var
= ResolveVariableAddress(settings_ptr
, sd
);
1006 int64 current_value
= ReadValue(var
, sd
->save
.conv
);
1010 if (mode
== RM_CHANGED_AGAINST_DEFAULT
) {
1011 /* This entry shall only be visible, if the value deviates from its default value. */
1013 /* Read the default value. */
1014 filter_value
= ReadValue(&sd
->desc
.def
, sd
->save
.conv
);
1016 assert(mode
== RM_CHANGED_AGAINST_NEW
);
1017 /* This entry shall only be visible, if the value deviates from
1018 * its value is used when starting a new game. */
1020 /* Make sure we're not comparing the new game settings against itself. */
1021 assert(settings_ptr
!= &_settings_newgame
);
1023 /* Read the new game's value. */
1024 var
= ResolveVariableAddress(&_settings_newgame
, sd
);
1025 filter_value
= ReadValue(var
, sd
->save
.conv
);
1028 return current_value
!= filter_value
;
1032 * Update the filter state.
1033 * @param filter Filter
1034 * @param force_visible Whether to force all items visible, no matter what (due to filter text; not affected by restriction drop down box).
1035 * @return true if item remains visible
1037 bool SettingEntry::UpdateFilterState(SettingFilter
&filter
, bool force_visible
)
1039 CLRBITS(this->flags
, SEF_FILTERED
);
1041 bool visible
= true;
1042 switch (this->flags
& SEF_KIND_MASK
) {
1043 case SEF_SETTING_KIND
: {
1044 const SettingDesc
*sd
= this->d
.entry
.setting
;
1045 if (!force_visible
&& !filter
.string
.IsEmpty()) {
1046 /* Process the search text filter for this item. */
1047 filter
.string
.ResetState();
1049 const SettingDescBase
*sdb
= &sd
->desc
;
1051 SetDParam(0, STR_EMPTY
);
1052 filter
.string
.AddLine(sdb
->str
);
1053 filter
.string
.AddLine(this->GetHelpText());
1055 visible
= filter
.string
.GetState();
1058 if (filter
.type
!= ST_ALL
&& sd
->GetType() != filter
.type
) {
1059 filter
.type_hides
= true;
1062 if (!this->IsVisibleByRestrictionMode(filter
.mode
)) {
1063 while (filter
.min_cat
< RM_ALL
&& (filter
.min_cat
== filter
.mode
|| !this->IsVisibleByRestrictionMode(filter
.min_cat
))) filter
.min_cat
++;
1069 case SEF_SUBTREE_KIND
: {
1070 if (!force_visible
&& !filter
.string
.IsEmpty()) {
1071 filter
.string
.ResetState();
1072 filter
.string
.AddLine(this->d
.sub
.title
);
1073 force_visible
= filter
.string
.GetState();
1075 visible
= this->d
.sub
.page
->UpdateFilterState(filter
, force_visible
);
1078 default: NOT_REACHED();
1081 if (!visible
) SETBITS(this->flags
, SEF_FILTERED
);
1088 * Draw a row in the settings panel.
1090 * See SettingsPage::Draw() for an explanation about how drawing is performed.
1092 * The \a parent_last parameter ensures that the vertical lines at the left are
1093 * only drawn when another entry follows, that it prevents output like
1100 * The left-most vertical line is not wanted. It is prevented by setting the
1101 * appropriate bit in the \a parent_last parameter.
1103 * @param settings_ptr Pointer to current values of all settings
1104 * @param left Left-most position in window/panel to start drawing \a first_row
1105 * @param right Right-most x position to draw strings at.
1106 * @param base_y Upper-most position in window/panel to start drawing \a first_row
1107 * @param first_row First row number to draw
1108 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1109 * @param cur_row Current row number (internal variable)
1110 * @param parent_last Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
1111 * @param selected Selected entry by the user.
1112 * @return Row number of the next row to draw
1114 uint
SettingEntry::Draw(GameSettings
*settings_ptr
, int left
, int right
, int base_y
, uint first_row
, uint max_row
, uint cur_row
, uint parent_last
, SettingEntry
*selected
)
1116 if (this->IsFiltered()) return cur_row
;
1117 if (cur_row
>= max_row
) return cur_row
;
1119 bool rtl
= _current_text_dir
== TD_RTL
;
1120 int offset
= rtl
? -4 : 4;
1121 int level_width
= rtl
? -LEVEL_WIDTH
: LEVEL_WIDTH
;
1123 int x
= rtl
? right
: left
;
1125 if (cur_row
>= first_row
) {
1126 int colour
= _colour_gradient
[COLOUR_ORANGE
][4];
1127 y
= base_y
+ (cur_row
- first_row
) * SETTING_HEIGHT
; // Compute correct y start position
1129 /* Draw vertical for parent nesting levels */
1130 for (uint lvl
= 0; lvl
< this->level
; lvl
++) {
1131 if (!HasBit(parent_last
, lvl
)) GfxDrawLine(x
+ offset
, y
, x
+ offset
, y
+ SETTING_HEIGHT
- 1, colour
);
1134 /* draw own |- prefix */
1135 int halfway_y
= y
+ SETTING_HEIGHT
/ 2;
1136 int bottom_y
= (flags
& SEF_LAST_FIELD
) ? halfway_y
: y
+ SETTING_HEIGHT
- 1;
1137 GfxDrawLine(x
+ offset
, y
, x
+ offset
, bottom_y
, colour
);
1138 /* Small horizontal line from the last vertical line */
1139 GfxDrawLine(x
+ offset
, halfway_y
, x
+ level_width
- offset
, halfway_y
, colour
);
1143 switch (this->flags
& SEF_KIND_MASK
) {
1144 case SEF_SETTING_KIND
:
1145 if (cur_row
>= first_row
) {
1146 this->DrawSetting(settings_ptr
, rtl
? left
: x
, rtl
? x
: right
, y
, this->flags
& SEF_BUTTONS_MASK
,
1151 case SEF_SUBTREE_KIND
:
1152 if (cur_row
>= first_row
) {
1153 DrawSprite((this->d
.sub
.folded
? SPR_CIRCLE_FOLDED
: SPR_CIRCLE_UNFOLDED
), PAL_NONE
, rtl
? x
- 8 : x
, y
+ (SETTING_HEIGHT
- 11) / 2);
1154 DrawString(rtl
? left
: x
+ 12, rtl
? x
- 12 : right
, y
, this->d
.sub
.title
);
1157 if (!this->d
.sub
.folded
) {
1158 if (this->flags
& SEF_LAST_FIELD
) {
1159 assert(this->level
< sizeof(parent_last
));
1160 SetBit(parent_last
, this->level
); // Add own last-field state
1163 cur_row
= this->d
.sub
.page
->Draw(settings_ptr
, left
, right
, base_y
, first_row
, max_row
, selected
, cur_row
, parent_last
);
1166 default: NOT_REACHED();
1171 static const void *ResolveVariableAddress(const GameSettings
*settings_ptr
, const SettingDesc
*sd
)
1173 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
1174 if (Company::IsValidID(_local_company
) && _game_mode
!= GM_MENU
) {
1175 return GetVariableAddress(&sd
->save
, &Company::Get(_local_company
)->settings
);
1177 return GetVariableAddress(&sd
->save
, &_settings_client
.company
);
1180 return GetVariableAddress(&sd
->save
, settings_ptr
);
1185 * Set the DParams for drawing the value of a setting.
1186 * @param first_param First DParam to use
1187 * @param value Setting value to set params for.
1189 void SettingEntry::SetValueDParams(uint first_param
, int32 value
)
1191 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
1192 const SettingDescBase
*sdb
= &this->d
.entry
.setting
->desc
;
1193 if (sdb
->cmd
== SDT_BOOLX
) {
1194 SetDParam(first_param
++, value
!= 0 ? STR_CONFIG_SETTING_ON
: STR_CONFIG_SETTING_OFF
);
1196 if ((sdb
->flags
& SGF_MULTISTRING
) != 0) {
1197 SetDParam(first_param
++, sdb
->str_val
- sdb
->min
+ value
);
1198 } else if ((sdb
->flags
& SGF_DISPLAY_ABS
) != 0) {
1199 SetDParam(first_param
++, sdb
->str_val
+ ((value
>= 0) ? 1 : 0));
1202 SetDParam(first_param
++, sdb
->str_val
+ ((value
== 0 && (sdb
->flags
& SGF_0ISDISABLED
) != 0) ? 1 : 0));
1204 SetDParam(first_param
++, value
);
1209 * Private function to draw setting value (button + text + current value)
1210 * @param settings_ptr Pointer to current values of all settings
1211 * @param left Left-most position in window/panel to start drawing
1212 * @param right Right-most position in window/panel to draw
1213 * @param y Upper-most position in window/panel to start drawing
1214 * @param state State of the left + right arrow buttons to draw for the setting
1215 * @param highlight Highlight entry.
1217 void SettingEntry::DrawSetting(GameSettings
*settings_ptr
, int left
, int right
, int y
, int state
, bool highlight
)
1219 const SettingDesc
*sd
= this->d
.entry
.setting
;
1220 const SettingDescBase
*sdb
= &sd
->desc
;
1221 const void *var
= ResolveVariableAddress(settings_ptr
, sd
);
1223 bool rtl
= _current_text_dir
== TD_RTL
;
1224 uint buttons_left
= rtl
? right
+ 1 - SETTING_BUTTON_WIDTH
: left
;
1225 uint text_left
= left
+ (rtl
? 0 : SETTING_BUTTON_WIDTH
+ 5);
1226 uint text_right
= right
- (rtl
? SETTING_BUTTON_WIDTH
+ 5 : 0);
1227 uint button_y
= y
+ (SETTING_HEIGHT
- SETTING_BUTTON_HEIGHT
) / 2;
1229 /* We do not allow changes of some items when we are a client in a networkgame */
1230 bool editable
= sd
->IsEditable();
1232 SetDParam(0, highlight
? STR_ORANGE_STRING1_WHITE
: STR_ORANGE_STRING1_LTBLUE
);
1233 int32 value
= (int32
)ReadValue(var
, sd
->save
.conv
);
1234 if (sdb
->cmd
== SDT_BOOLX
) {
1235 /* Draw checkbox for boolean-value either on/off */
1236 DrawBoolButton(buttons_left
, button_y
, value
!= 0, editable
);
1237 } else if ((sdb
->flags
& SGF_MULTISTRING
) != 0) {
1238 /* Draw [v] button for settings of an enum-type */
1239 DrawDropDownButton(buttons_left
, button_y
, COLOUR_YELLOW
, state
!= 0, editable
);
1241 /* Draw [<][>] boxes for settings of an integer-type */
1242 DrawArrowButtons(buttons_left
, button_y
, COLOUR_YELLOW
, state
,
1243 editable
&& value
!= (sdb
->flags
& SGF_0ISDISABLED
? 0 : sdb
->min
), editable
&& (uint32
)value
!= sdb
->max
);
1245 this->SetValueDParams(1, value
);
1246 DrawString(text_left
, text_right
, y
, sdb
->str
, highlight
? TC_WHITE
: TC_LIGHT_BLUE
);
1250 /* == SettingsPage methods == */
1253 * Initialization of an entire setting page
1254 * @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
1256 void SettingsPage::Init(byte level
)
1258 for (uint field
= 0; field
< this->num
; field
++) {
1259 this->entries
[field
].Init(level
);
1263 /** Recursively close all folds of sub-pages */
1264 void SettingsPage::FoldAll()
1266 for (uint field
= 0; field
< this->num
; field
++) {
1267 this->entries
[field
].FoldAll();
1271 /** Recursively open all folds of sub-pages */
1272 void SettingsPage::UnFoldAll()
1274 for (uint field
= 0; field
< this->num
; field
++) {
1275 this->entries
[field
].UnFoldAll();
1280 * Recursively accumulate the folding state of the tree.
1281 * @param[in,out] all_folded Set to false, if one entry is not folded.
1282 * @param[in,out] all_unfolded Set to false, if one entry is folded.
1284 void SettingsPage::GetFoldingState(bool &all_folded
, bool &all_unfolded
) const
1286 for (uint field
= 0; field
< this->num
; field
++) {
1287 this->entries
[field
].GetFoldingState(all_folded
, all_unfolded
);
1292 * Update the filter state.
1293 * @param filter Filter
1294 * @param force_visible Whether to force all items visible, no matter what
1295 * @return true if item remains visible
1297 bool SettingsPage::UpdateFilterState(SettingFilter
&filter
, bool force_visible
)
1299 bool visible
= false;
1300 bool first_visible
= true;
1301 for (int field
= this->num
- 1; field
>= 0; field
--) {
1302 visible
|= this->entries
[field
].UpdateFilterState(filter
, force_visible
);
1303 this->entries
[field
].SetLastField(first_visible
);
1304 if (visible
&& first_visible
) first_visible
= false;
1311 * Check whether an entry is visible and not folded or filtered away.
1312 * Note: This does not consider the scrolling range; it might still require scrolling ot make the setting really visible.
1313 * @param item Entry to search for.
1314 * @return true if entry is visible.
1316 bool SettingsPage::IsVisible(const SettingEntry
*item
) const
1318 for (uint field
= 0; field
< this->num
; field
++) {
1319 if (this->entries
[field
].IsVisible(item
)) return true;
1324 /** Return number of rows needed to display the whole page */
1325 uint
SettingsPage::Length() const
1328 for (uint field
= 0; field
< this->num
; field
++) {
1329 length
+= this->entries
[field
].Length();
1335 * Find the setting entry at row number \a row_num
1336 * @param row_num Index of entry to return
1337 * @param cur_row Variable used for keeping track of the current row number. Should point to memory initialized to \c 0 when first called.
1338 * @return The requested setting entry or \c NULL if it does not exist
1340 SettingEntry
*SettingsPage::FindEntry(uint row_num
, uint
*cur_row
) const
1342 SettingEntry
*pe
= NULL
;
1344 for (uint field
= 0; field
< this->num
; field
++) {
1345 pe
= this->entries
[field
].FindEntry(row_num
, cur_row
);
1354 * Get the biggest height of the help texts, if the width is at least \a maxw. Help text gets wrapped if needed.
1355 * @param maxw Maximal width of a line help text.
1356 * @return Biggest height needed to display any help text of this (sub-)tree.
1358 uint
SettingsPage::GetMaxHelpHeight(int maxw
)
1361 for (uint field
= 0; field
< this->num
; field
++) {
1362 biggest
= max(biggest
, this->entries
[field
].GetMaxHelpHeight(maxw
));
1368 * Draw a selected part of the settings page.
1370 * The scrollbar uses rows of the page, while the page data structure is a tree of #SettingsPage and #SettingEntry objects.
1371 * As a result, the drawing routing traverses the tree from top to bottom, counting rows in \a cur_row until it reaches \a first_row.
1372 * Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
1374 * @param settings_ptr Pointer to current values of all settings
1375 * @param left Left-most position in window/panel to start drawing of each setting row
1376 * @param right Right-most position in window/panel to draw at
1377 * @param base_y Upper-most position in window/panel to start drawing of row number \a first_row
1378 * @param first_row Number of first row to draw
1379 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1380 * @param cur_row Current row number (internal variable)
1381 * @param parent_last Last-field booleans of parent page level (page level \e i sets bit \e i to 1 if it is its last field)
1382 * @param selected Selected entry by the user.
1383 * @return Row number of the next row to draw
1385 uint
SettingsPage::Draw(GameSettings
*settings_ptr
, int left
, int right
, int base_y
, uint first_row
, uint max_row
, SettingEntry
*selected
, uint cur_row
, uint parent_last
) const
1387 if (cur_row
>= max_row
) return cur_row
;
1389 for (uint i
= 0; i
< this->num
; i
++) {
1390 cur_row
= this->entries
[i
].Draw(settings_ptr
, left
, right
, base_y
, first_row
, max_row
, cur_row
, parent_last
, selected
);
1391 if (cur_row
>= max_row
) {
1399 static SettingEntry _settings_ui_localisation
[] = {
1400 SettingEntry("locale.units_velocity"),
1401 SettingEntry("locale.units_power"),
1402 SettingEntry("locale.units_weight"),
1403 SettingEntry("locale.units_volume"),
1404 SettingEntry("locale.units_force"),
1405 SettingEntry("locale.units_height"),
1407 /** Localisation options sub-page */
1408 static SettingsPage _settings_ui_localisation_page
= {_settings_ui_localisation
, lengthof(_settings_ui_localisation
)};
1410 static SettingEntry _settings_ui_display
[] = {
1411 SettingEntry("gui.date_format_in_default_names"),
1412 SettingEntry("gui.population_in_label"),
1413 SettingEntry("gui.measure_tooltip"),
1414 SettingEntry("gui.loading_indicators"),
1415 SettingEntry("gui.liveries"),
1416 SettingEntry("gui.show_track_reservation"),
1417 SettingEntry("gui.expenses_layout"),
1418 SettingEntry("gui.smallmap_land_colour"),
1419 SettingEntry("gui.zoom_min"),
1420 SettingEntry("gui.zoom_max"),
1421 SettingEntry("gui.graph_line_thickness"),
1423 /** Display options sub-page */
1424 static SettingsPage _settings_ui_display_page
= {_settings_ui_display
, lengthof(_settings_ui_display
)};
1426 static SettingEntry _settings_ui_interaction
[] = {
1427 SettingEntry("gui.window_snap_radius"),
1428 SettingEntry("gui.window_soft_limit"),
1429 SettingEntry("gui.link_terraform_toolbar"),
1430 SettingEntry("gui.prefer_teamchat"),
1431 SettingEntry("gui.auto_scrolling"),
1432 SettingEntry("gui.reverse_scroll"),
1433 SettingEntry("gui.smooth_scroll"),
1434 SettingEntry("gui.left_mouse_btn_scrolling"),
1435 /* While the horizontal scrollwheel scrolling is written as general code, only
1436 * the cocoa (OSX) driver generates input for it.
1437 * Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
1438 SettingEntry("gui.scrollwheel_scrolling"),
1439 SettingEntry("gui.scrollwheel_multiplier"),
1440 SettingEntry("gui.osk_activation"),
1442 /* We might need to emulate a right mouse button on mac */
1443 SettingEntry("gui.right_mouse_btn_emulation"),
1446 /** Interaction sub-page */
1447 static SettingsPage _settings_ui_interaction_page
= {_settings_ui_interaction
, lengthof(_settings_ui_interaction
)};
1449 static SettingEntry _settings_ui_sound
[] = {
1450 SettingEntry("sound.click_beep"),
1451 SettingEntry("sound.confirm"),
1452 SettingEntry("sound.news_ticker"),
1453 SettingEntry("sound.news_full"),
1454 SettingEntry("sound.new_year"),
1455 SettingEntry("sound.disaster"),
1456 SettingEntry("sound.vehicle"),
1457 SettingEntry("sound.ambient"),
1459 /** Sound effects sub-page */
1460 static SettingsPage _settings_ui_sound_page
= {_settings_ui_sound
, lengthof(_settings_ui_sound
)};
1462 static SettingEntry _settings_ui_news
[] = {
1463 SettingEntry("news_display.arrival_player"),
1464 SettingEntry("news_display.arrival_other"),
1465 SettingEntry("news_display.accident"),
1466 SettingEntry("news_display.company_info"),
1467 SettingEntry("news_display.open"),
1468 SettingEntry("news_display.close"),
1469 SettingEntry("news_display.economy"),
1470 SettingEntry("news_display.production_player"),
1471 SettingEntry("news_display.production_other"),
1472 SettingEntry("news_display.production_nobody"),
1473 SettingEntry("news_display.advice"),
1474 SettingEntry("news_display.new_vehicles"),
1475 SettingEntry("news_display.acceptance"),
1476 SettingEntry("news_display.subsidies"),
1477 SettingEntry("news_display.general"),
1478 SettingEntry("gui.coloured_news_year"),
1480 /** News sub-page */
1481 static SettingsPage _settings_ui_news_page
= {_settings_ui_news
, lengthof(_settings_ui_news
)};
1483 static SettingEntry _settings_ui
[] = {
1484 SettingEntry(&_settings_ui_localisation_page
, STR_CONFIG_SETTING_LOCALISATION
),
1485 SettingEntry(&_settings_ui_display_page
, STR_CONFIG_SETTING_DISPLAY_OPTIONS
),
1486 SettingEntry(&_settings_ui_interaction_page
, STR_CONFIG_SETTING_INTERACTION
),
1487 SettingEntry(&_settings_ui_sound_page
, STR_CONFIG_SETTING_SOUND
),
1488 SettingEntry(&_settings_ui_news_page
, STR_CONFIG_SETTING_NEWS
),
1489 SettingEntry("gui.show_finances"),
1490 SettingEntry("gui.errmsg_duration"),
1491 SettingEntry("gui.hover_delay"),
1492 SettingEntry("gui.toolbar_pos"),
1493 SettingEntry("gui.statusbar_pos"),
1494 SettingEntry("gui.newgrf_default_palette"),
1495 SettingEntry("gui.pause_on_newgame"),
1496 SettingEntry("gui.advanced_vehicle_list"),
1497 SettingEntry("gui.timetable_in_ticks"),
1498 SettingEntry("gui.timetable_arrival_departure"),
1499 SettingEntry("gui.quick_goto"),
1500 SettingEntry("gui.default_rail_type"),
1501 SettingEntry("gui.disable_unsuitable_building"),
1502 SettingEntry("gui.persistent_buildingtools"),
1504 /** Interface subpage */
1505 static SettingsPage _settings_ui_page
= {_settings_ui
, lengthof(_settings_ui
)};
1507 static SettingEntry _settings_construction_signals
[] = {
1508 SettingEntry("construction.train_signal_side"),
1509 SettingEntry("gui.enable_signal_gui"),
1510 SettingEntry("gui.drag_signals_fixed_distance"),
1511 SettingEntry("gui.semaphore_build_before"),
1512 SettingEntry("gui.default_signal_type"),
1513 SettingEntry("gui.cycle_signal_types"),
1515 /** Signals subpage */
1516 static SettingsPage _settings_construction_signals_page
= {_settings_construction_signals
, lengthof(_settings_construction_signals
)};
1518 static SettingEntry _settings_construction
[] = {
1519 SettingEntry(&_settings_construction_signals_page
, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS
),
1520 SettingEntry("construction.build_on_slopes"),
1521 SettingEntry("construction.autoslope"),
1522 SettingEntry("construction.extra_dynamite"),
1523 SettingEntry("construction.max_bridge_length"),
1524 SettingEntry("construction.max_tunnel_length"),
1525 SettingEntry("station.never_expire_airports"),
1526 SettingEntry("construction.freeform_edges"),
1527 SettingEntry("construction.extra_tree_placement"),
1528 SettingEntry("construction.command_pause_level"),
1530 /** Construction sub-page */
1531 static SettingsPage _settings_construction_page
= {_settings_construction
, lengthof(_settings_construction
)};
1533 static SettingEntry _settings_stations_cargo
[] = {
1534 SettingEntry("order.improved_load"),
1535 SettingEntry("order.gradual_loading"),
1536 SettingEntry("order.selectgoods"),
1538 /** Cargo handling sub-page */
1539 static SettingsPage _settings_stations_cargo_page
= {_settings_stations_cargo
, lengthof(_settings_stations_cargo
)};
1541 static SettingEntry _settings_stations
[] = {
1542 SettingEntry(&_settings_stations_cargo_page
, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING
),
1543 SettingEntry("station.adjacent_stations"),
1544 SettingEntry("station.distant_join_stations"),
1545 SettingEntry("station.station_spread"),
1546 SettingEntry("economy.station_noise_level"),
1547 SettingEntry("station.modified_catchment"),
1548 SettingEntry("construction.road_stop_on_town_road"),
1549 SettingEntry("construction.road_stop_on_competitor_road"),
1551 /** Stations sub-page */
1552 static SettingsPage _settings_stations_page
= {_settings_stations
, lengthof(_settings_stations
)};
1554 static SettingEntry _settings_economy_towns
[] = {
1555 SettingEntry("difficulty.town_council_tolerance"),
1556 SettingEntry("economy.bribe"),
1557 SettingEntry("economy.exclusive_rights"),
1558 SettingEntry("economy.fund_roads"),
1559 SettingEntry("economy.fund_buildings"),
1560 SettingEntry("economy.town_layout"),
1561 SettingEntry("economy.allow_town_roads"),
1562 SettingEntry("economy.allow_town_level_crossings"),
1563 SettingEntry("economy.found_town"),
1564 SettingEntry("economy.mod_road_rebuild"),
1565 SettingEntry("economy.town_growth_rate"),
1566 SettingEntry("economy.larger_towns"),
1567 SettingEntry("economy.initial_city_size"),
1569 /** Towns sub-page */
1570 static SettingsPage _settings_economy_towns_page
= {_settings_economy_towns
, lengthof(_settings_economy_towns
)};
1572 static SettingEntry _settings_economy_industries
[] = {
1573 SettingEntry("construction.raw_industry_construction"),
1574 SettingEntry("construction.industry_platform"),
1575 SettingEntry("economy.multiple_industry_per_town"),
1576 SettingEntry("game_creation.oil_refinery_limit"),
1578 /** Industries sub-page */
1579 static SettingsPage _settings_economy_industries_page
= {_settings_economy_industries
, lengthof(_settings_economy_industries
)};
1582 static SettingEntry _settings_economy
[] = {
1583 SettingEntry(&_settings_economy_towns_page
, STR_CONFIG_SETTING_ECONOMY_TOWNS
),
1584 SettingEntry(&_settings_economy_industries_page
, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES
),
1585 SettingEntry("economy.inflation"),
1586 SettingEntry("difficulty.initial_interest"),
1587 SettingEntry("difficulty.max_loan"),
1588 SettingEntry("difficulty.subsidy_multiplier"),
1589 SettingEntry("difficulty.economy"),
1590 SettingEntry("economy.smooth_economy"),
1591 SettingEntry("economy.feeder_payment_share"),
1592 SettingEntry("economy.infrastructure_maintenance"),
1593 SettingEntry("difficulty.vehicle_costs"),
1594 SettingEntry("difficulty.construction_cost"),
1595 SettingEntry("difficulty.disasters"),
1597 /** Economy sub-page */
1598 static SettingsPage _settings_economy_page
= {_settings_economy
, lengthof(_settings_economy
)};
1600 static SettingEntry _settings_linkgraph
[] = {
1601 SettingEntry("linkgraph.recalc_time"),
1602 SettingEntry("linkgraph.recalc_interval"),
1603 SettingEntry("linkgraph.distribution_pax"),
1604 SettingEntry("linkgraph.distribution_mail"),
1605 SettingEntry("linkgraph.distribution_armoured"),
1606 SettingEntry("linkgraph.distribution_default"),
1607 SettingEntry("linkgraph.accuracy"),
1608 SettingEntry("linkgraph.demand_distance"),
1609 SettingEntry("linkgraph.demand_size"),
1610 SettingEntry("linkgraph.short_path_saturation"),
1612 /** Linkgraph sub-page */
1613 static SettingsPage _settings_linkgraph_page
= {_settings_linkgraph
, lengthof(_settings_linkgraph
)};
1615 static SettingEntry _settings_ai_npc
[] = {
1616 SettingEntry("script.settings_profile"),
1617 SettingEntry("script.script_max_opcode_till_suspend"),
1618 SettingEntry("difficulty.competitor_speed"),
1619 SettingEntry("ai.ai_in_multiplayer"),
1620 SettingEntry("ai.ai_disable_veh_train"),
1621 SettingEntry("ai.ai_disable_veh_roadveh"),
1622 SettingEntry("ai.ai_disable_veh_aircraft"),
1623 SettingEntry("ai.ai_disable_veh_ship"),
1625 /** Computer players sub-page */
1626 static SettingsPage _settings_ai_npc_page
= {_settings_ai_npc
, lengthof(_settings_ai_npc
)};
1628 static SettingEntry _settings_ai
[] = {
1629 SettingEntry(&_settings_ai_npc_page
, STR_CONFIG_SETTING_AI_NPC
),
1630 SettingEntry("economy.give_money"),
1631 SettingEntry("economy.allow_shares"),
1634 static SettingsPage _settings_ai_page
= {_settings_ai
, lengthof(_settings_ai
)};
1636 static SettingEntry _settings_vehicles_routing
[] = {
1637 SettingEntry("pf.forbid_90_deg"),
1638 SettingEntry("pf.roadveh_queue"),
1639 SettingEntry("pf.pathfinder_for_ships"),
1641 /** Autorenew sub-page */
1642 static SettingsPage _settings_vehicles_routing_page
= {_settings_vehicles_routing
, lengthof(_settings_vehicles_routing
)};
1644 static SettingEntry _settings_vehicles_autorenew
[] = {
1645 SettingEntry("company.engine_renew"),
1646 SettingEntry("company.engine_renew_months"),
1647 SettingEntry("company.engine_renew_money"),
1649 /** Autorenew sub-page */
1650 static SettingsPage _settings_vehicles_autorenew_page
= {_settings_vehicles_autorenew
, lengthof(_settings_vehicles_autorenew
)};
1652 static SettingEntry _settings_vehicles_servicing
[] = {
1653 SettingEntry("vehicle.servint_ispercent"),
1654 SettingEntry("vehicle.servint_trains"),
1655 SettingEntry("vehicle.servint_roadveh"),
1656 SettingEntry("vehicle.servint_ships"),
1657 SettingEntry("vehicle.servint_aircraft"),
1658 SettingEntry("difficulty.vehicle_breakdowns"),
1659 SettingEntry("order.no_servicing_if_no_breakdowns"),
1660 SettingEntry("order.serviceathelipad"),
1662 /** Servicing sub-page */
1663 static SettingsPage _settings_vehicles_servicing_page
= {_settings_vehicles_servicing
, lengthof(_settings_vehicles_servicing
)};
1665 static SettingEntry _settings_vehicles_trains
[] = {
1666 SettingEntry("difficulty.line_reverse_mode"),
1667 SettingEntry("pf.reverse_at_signals"),
1668 SettingEntry("vehicle.train_acceleration_model"),
1669 SettingEntry("vehicle.train_slope_steepness"),
1670 SettingEntry("vehicle.max_train_length"),
1671 SettingEntry("vehicle.wagon_speed_limits"),
1672 SettingEntry("vehicle.disable_elrails"),
1673 SettingEntry("vehicle.freight_trains"),
1674 SettingEntry("gui.stop_location"),
1676 /** Trains sub-page */
1677 static SettingsPage _settings_vehicles_trains_page
= {_settings_vehicles_trains
, lengthof(_settings_vehicles_trains
)};
1679 static SettingEntry _settings_vehicles
[] = {
1680 SettingEntry(&_settings_vehicles_routing_page
, STR_CONFIG_SETTING_VEHICLES_ROUTING
),
1681 SettingEntry(&_settings_vehicles_autorenew_page
, STR_CONFIG_SETTING_VEHICLES_AUTORENEW
),
1682 SettingEntry(&_settings_vehicles_servicing_page
, STR_CONFIG_SETTING_VEHICLES_SERVICING
),
1683 SettingEntry(&_settings_vehicles_trains_page
, STR_CONFIG_SETTING_VEHICLES_TRAINS
),
1684 SettingEntry("gui.new_nonstop"),
1685 SettingEntry("gui.order_review_system"),
1686 SettingEntry("gui.vehicle_income_warn"),
1687 SettingEntry("gui.lost_vehicle_warn"),
1688 SettingEntry("vehicle.never_expire_vehicles"),
1689 SettingEntry("vehicle.max_trains"),
1690 SettingEntry("vehicle.max_roadveh"),
1691 SettingEntry("vehicle.max_aircraft"),
1692 SettingEntry("vehicle.max_ships"),
1693 SettingEntry("vehicle.plane_speed"),
1694 SettingEntry("vehicle.plane_crashes"),
1695 SettingEntry("vehicle.dynamic_engines"),
1696 SettingEntry("vehicle.roadveh_acceleration_model"),
1697 SettingEntry("vehicle.roadveh_slope_steepness"),
1698 SettingEntry("vehicle.smoke_amount"),
1700 /** Vehicles sub-page */
1701 static SettingsPage _settings_vehicles_page
= {_settings_vehicles
, lengthof(_settings_vehicles
)};
1703 static SettingEntry _settings_main
[] = {
1704 SettingEntry(&_settings_ui_page
, STR_CONFIG_SETTING_GUI
),
1705 SettingEntry(&_settings_construction_page
, STR_CONFIG_SETTING_CONSTRUCTION
),
1706 SettingEntry(&_settings_vehicles_page
, STR_CONFIG_SETTING_VEHICLES
),
1707 SettingEntry(&_settings_stations_page
, STR_CONFIG_SETTING_STATIONS
),
1708 SettingEntry(&_settings_economy_page
, STR_CONFIG_SETTING_ECONOMY
),
1709 SettingEntry(&_settings_linkgraph_page
, STR_CONFIG_SETTING_LINKGRAPH
),
1710 SettingEntry(&_settings_ai_page
, STR_CONFIG_SETTING_AI
),
1713 /** Main page, holding all advanced settings */
1714 static SettingsPage _settings_main_page
= {_settings_main
, lengthof(_settings_main
)};
1716 static const StringID _game_settings_restrict_dropdown
[] = {
1717 STR_CONFIG_SETTING_RESTRICT_BASIC
, // RM_BASIC
1718 STR_CONFIG_SETTING_RESTRICT_ADVANCED
, // RM_ADVANCED
1719 STR_CONFIG_SETTING_RESTRICT_ALL
, // RM_ALL
1720 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT
, // RM_CHANGED_AGAINST_DEFAULT
1721 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW
, // RM_CHANGED_AGAINST_NEW
1723 assert_compile(lengthof(_game_settings_restrict_dropdown
) == RM_END
);
1725 /** Warnings about hidden search results. */
1726 enum WarnHiddenResult
{
1727 WHR_NONE
, ///< Nothing was filtering matches away.
1728 WHR_CATEGORY
, ///< Category setting filtered matches away.
1729 WHR_TYPE
, ///< Type setting filtered matches away.
1730 WHR_CATEGORY_TYPE
, ///< Both category and type settings filtered matches away.
1733 /** Window to edit settings of the game. */
1734 struct GameSettingsWindow
: Window
{
1735 static const int SETTINGTREE_LEFT_OFFSET
= 5; ///< Position of left edge of setting values
1736 static const int SETTINGTREE_RIGHT_OFFSET
= 5; ///< Position of right edge of setting values
1737 static const int SETTINGTREE_TOP_OFFSET
= 5; ///< Position of top edge of setting values
1738 static const int SETTINGTREE_BOTTOM_OFFSET
= 5; ///< Position of bottom edge of setting values
1740 static GameSettings
*settings_ptr
; ///< Pointer to the game settings being displayed and modified.
1742 SettingEntry
*valuewindow_entry
; ///< If non-NULL, pointer to setting for which a value-entering window has been opened.
1743 SettingEntry
*clicked_entry
; ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button).
1744 SettingEntry
*last_clicked
; ///< If non-NULL, pointer to the last clicked setting.
1745 SettingEntry
*valuedropdown_entry
; ///< If non-NULL, pointer to the value for which a dropdown window is currently opened.
1746 bool closing_dropdown
; ///< True, if the dropdown list is currently closing.
1748 SettingFilter filter
; ///< Filter for the list.
1749 QueryString filter_editbox
; ///< Filter editbox;
1750 bool manually_changed_folding
; ///< Whether the user expanded/collapsed something manually.
1751 WarnHiddenResult warn_missing
; ///< Whether and how to warn about missing search results.
1752 int warn_lines
; ///< Number of lines used for warning about missing search results.
1756 GameSettingsWindow(WindowDesc
*desc
) : Window(desc
), filter_editbox(50)
1758 static bool first_time
= true;
1760 this->warn_missing
= WHR_NONE
;
1761 this->warn_lines
= 0;
1762 this->filter
.mode
= (RestrictionMode
)_settings_client
.gui
.settings_restriction_mode
;
1763 this->filter
.min_cat
= RM_ALL
;
1764 this->filter
.type
= ST_ALL
;
1765 this->filter
.type_hides
= false;
1766 this->settings_ptr
= &GetGameSettings();
1768 /* Build up the dynamic settings-array only once per OpenTTD session */
1770 _settings_main_page
.Init();
1773 _settings_main_page
.FoldAll(); // Close all sub-pages
1776 this->valuewindow_entry
= NULL
; // No setting entry for which a entry window is opened
1777 this->clicked_entry
= NULL
; // No numeric setting buttons are depressed
1778 this->last_clicked
= NULL
;
1779 this->valuedropdown_entry
= NULL
;
1780 this->closing_dropdown
= false;
1781 this->manually_changed_folding
= false;
1783 this->CreateNestedTree();
1784 this->vscroll
= this->GetScrollbar(WID_GS_SCROLLBAR
);
1785 this->FinishInitNested(WN_GAME_OPTIONS_GAME_SETTINGS
);
1787 this->querystrings
[WID_GS_FILTER
] = &this->filter_editbox
;
1788 this->filter_editbox
.cancel_button
= QueryString::ACTION_CLEAR
;
1789 this->SetFocusedWidget(WID_GS_FILTER
);
1791 this->InvalidateData();
1794 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1797 case WID_GS_OPTIONSPANEL
:
1798 resize
->height
= SETTING_HEIGHT
= max(11, FONT_HEIGHT_NORMAL
+ 1);
1801 size
->height
= 5 * resize
->height
+ SETTINGTREE_TOP_OFFSET
+ SETTINGTREE_BOTTOM_OFFSET
;
1804 case WID_GS_HELP_TEXT
: {
1805 static const StringID setting_types
[] = {
1806 STR_CONFIG_SETTING_TYPE_CLIENT
,
1807 STR_CONFIG_SETTING_TYPE_COMPANY_MENU
, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME
,
1808 STR_CONFIG_SETTING_TYPE_GAME_MENU
, STR_CONFIG_SETTING_TYPE_GAME_INGAME
,
1810 for (uint i
= 0; i
< lengthof(setting_types
); i
++) {
1811 SetDParam(0, setting_types
[i
]);
1812 size
->width
= max(size
->width
, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE
).width
);
1814 size
->height
= 2 * FONT_HEIGHT_NORMAL
+ WD_PAR_VSEP_NORMAL
+
1815 max(size
->height
, _settings_main_page
.GetMaxHelpHeight(size
->width
));
1819 case WID_GS_RESTRICT_CATEGORY
:
1820 case WID_GS_RESTRICT_TYPE
:
1821 size
->width
= max(GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_CATEGORY
).width
, GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_TYPE
).width
);
1829 virtual void OnPaint()
1831 if (this->closing_dropdown
) {
1832 this->closing_dropdown
= false;
1833 assert(this->valuedropdown_entry
!= NULL
);
1834 this->valuedropdown_entry
->SetButtons(0);
1835 this->valuedropdown_entry
= NULL
;
1838 /* Reserve the correct number of lines for the 'some search results are hidden' notice in the central settings display panel. */
1839 const NWidgetBase
*panel
= this->GetWidget
<NWidgetBase
>(WID_GS_OPTIONSPANEL
);
1840 StringID warn_str
= STR_CONFIG_SETTING_CATEGORY_HIDES
- 1 + this->warn_missing
;
1842 if (this->warn_missing
== WHR_NONE
) {
1845 SetDParam(0, _game_settings_restrict_dropdown
[this->filter
.min_cat
]);
1846 new_warn_lines
= GetStringLineCount(warn_str
, panel
->current_x
);
1848 if (this->warn_lines
!= new_warn_lines
) {
1849 this->vscroll
->SetCount(this->vscroll
->GetCount() - this->warn_lines
+ new_warn_lines
);
1850 this->warn_lines
= new_warn_lines
;
1853 this->DrawWidgets();
1855 /* Draw the 'some search results are hidden' notice. */
1856 if (this->warn_missing
!= WHR_NONE
) {
1857 const int left
= panel
->pos_x
;
1858 const int right
= left
+ panel
->current_x
- 1;
1859 const int top
= panel
->pos_y
;
1860 SetDParam(0, _game_settings_restrict_dropdown
[this->filter
.min_cat
]);
1861 if (this->warn_lines
== 1) {
1862 /* If the warning fits at one line, center it. */
1863 DrawString(left
+ WD_FRAMETEXT_LEFT
, right
- WD_FRAMETEXT_RIGHT
, top
+ WD_FRAMETEXT_TOP
, warn_str
, TC_FROMSTRING
, SA_HOR_CENTER
);
1865 DrawStringMultiLine(left
+ WD_FRAMERECT_LEFT
, right
- WD_FRAMERECT_RIGHT
, top
+ WD_FRAMERECT_TOP
, INT32_MAX
, warn_str
);
1870 virtual void SetStringParameters(int widget
) const
1873 case WID_GS_RESTRICT_DROPDOWN
:
1874 SetDParam(0, _game_settings_restrict_dropdown
[this->filter
.mode
]);
1877 case WID_GS_TYPE_DROPDOWN
:
1878 switch (this->filter
.type
) {
1879 case ST_GAME
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU
: STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME
); break;
1880 case ST_COMPANY
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU
: STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME
); break;
1881 case ST_CLIENT
: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT
); break;
1882 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL
); break;
1888 DropDownList
*BuildDropDownList(int widget
) const
1890 DropDownList
*list
= NULL
;
1892 case WID_GS_RESTRICT_DROPDOWN
:
1893 list
= new DropDownList();
1895 for (int mode
= 0; mode
!= RM_END
; mode
++) {
1896 /* If we are in adv. settings screen for the new game's settings,
1897 * we don't want to allow comparing with new game's settings. */
1898 bool disabled
= mode
== RM_CHANGED_AGAINST_NEW
&& settings_ptr
== &_settings_newgame
;
1900 *list
->Append() = new DropDownListStringItem(_game_settings_restrict_dropdown
[mode
], mode
, disabled
);
1904 case WID_GS_TYPE_DROPDOWN
:
1905 list
= new DropDownList();
1906 *list
->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL
, ST_ALL
, false);
1907 *list
->Append() = new DropDownListStringItem(_game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU
: STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME
, ST_GAME
, false);
1908 *list
->Append() = new DropDownListStringItem(_game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU
: STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME
, ST_COMPANY
, false);
1909 *list
->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT
, ST_CLIENT
, false);
1915 virtual void DrawWidget(const Rect
&r
, int widget
) const
1918 case WID_GS_OPTIONSPANEL
: {
1919 int top_pos
= r
.top
+ SETTINGTREE_TOP_OFFSET
+ 1 + this->warn_lines
* FONT_HEIGHT_NORMAL
;
1920 uint last_row
= this->vscroll
->GetPosition() + this->vscroll
->GetCapacity() - this->warn_lines
;
1921 int next_row
= _settings_main_page
.Draw(settings_ptr
, r
.left
+ SETTINGTREE_LEFT_OFFSET
, r
.right
- SETTINGTREE_RIGHT_OFFSET
, top_pos
,
1922 this->vscroll
->GetPosition(), last_row
, this->last_clicked
);
1923 if (next_row
== 0) DrawString(r
.left
+ SETTINGTREE_LEFT_OFFSET
, r
.right
- SETTINGTREE_RIGHT_OFFSET
, top_pos
, STR_CONFIG_SETTINGS_NONE
);
1927 case WID_GS_HELP_TEXT
:
1928 if (this->last_clicked
!= NULL
) {
1929 const SettingDesc
*sd
= this->last_clicked
->d
.entry
.setting
;
1932 switch (sd
->GetType()) {
1933 case ST_COMPANY
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_COMPANY_MENU
: STR_CONFIG_SETTING_TYPE_COMPANY_INGAME
); break;
1934 case ST_CLIENT
: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT
); break;
1935 case ST_GAME
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_GAME_MENU
: STR_CONFIG_SETTING_TYPE_GAME_INGAME
); break;
1936 default: NOT_REACHED();
1938 DrawString(r
.left
, r
.right
, y
, STR_CONFIG_SETTING_TYPE
);
1939 y
+= FONT_HEIGHT_NORMAL
;
1941 int32 default_value
= ReadValue(&sd
->desc
.def
, sd
->save
.conv
);
1942 this->last_clicked
->SetValueDParams(0, default_value
);
1943 DrawString(r
.left
, r
.right
, y
, STR_CONFIG_SETTING_DEFAULT_VALUE
);
1944 y
+= FONT_HEIGHT_NORMAL
+ WD_PAR_VSEP_NORMAL
;
1946 DrawStringMultiLine(r
.left
, r
.right
, y
, r
.bottom
, this->last_clicked
->GetHelpText(), TC_WHITE
);
1956 * Set the entry that should have its help text displayed, and mark the window dirty so it gets repainted.
1957 * @param pe Setting to display help text of, use \c NULL to stop displaying help of the currently displayed setting.
1959 void SetDisplayedHelpText(SettingEntry
*pe
)
1961 if (this->last_clicked
!= pe
) this->SetDirty();
1962 this->last_clicked
= pe
;
1965 virtual void OnClick(Point pt
, int widget
, int click_count
)
1968 case WID_GS_EXPAND_ALL
:
1969 this->manually_changed_folding
= true;
1970 _settings_main_page
.UnFoldAll();
1971 this->InvalidateData();
1974 case WID_GS_COLLAPSE_ALL
:
1975 this->manually_changed_folding
= true;
1976 _settings_main_page
.FoldAll();
1977 this->InvalidateData();
1980 case WID_GS_RESTRICT_DROPDOWN
: {
1981 DropDownList
*list
= this->BuildDropDownList(widget
);
1983 ShowDropDownList(this, list
, this->filter
.mode
, widget
);
1988 case WID_GS_TYPE_DROPDOWN
: {
1989 DropDownList
*list
= this->BuildDropDownList(widget
);
1991 ShowDropDownList(this, list
, this->filter
.type
, widget
);
1997 if (widget
!= WID_GS_OPTIONSPANEL
) return;
1999 uint btn
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_GS_OPTIONSPANEL
, SETTINGTREE_TOP_OFFSET
);
2000 if (btn
== INT_MAX
|| (int)btn
< this->warn_lines
) return;
2001 btn
-= this->warn_lines
;
2004 SettingEntry
*pe
= _settings_main_page
.FindEntry(btn
, &cur_row
);
2006 if (pe
== NULL
) return; // Clicked below the last setting of the page
2008 int x
= (_current_text_dir
== TD_RTL
? this->width
- 1 - pt
.x
: pt
.x
) - SETTINGTREE_LEFT_OFFSET
- (pe
->level
+ 1) * LEVEL_WIDTH
; // Shift x coordinate
2009 if (x
< 0) return; // Clicked left of the entry
2011 if ((pe
->flags
& SEF_KIND_MASK
) == SEF_SUBTREE_KIND
) {
2012 this->SetDisplayedHelpText(NULL
);
2013 pe
->d
.sub
.folded
= !pe
->d
.sub
.folded
; // Flip 'folded'-ness of the sub-page
2015 this->manually_changed_folding
= true;
2017 this->InvalidateData();
2021 assert((pe
->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
2022 const SettingDesc
*sd
= pe
->d
.entry
.setting
;
2024 /* return if action is only active in network, or only settable by server */
2025 if (!sd
->IsEditable()) {
2026 this->SetDisplayedHelpText(pe
);
2030 const void *var
= ResolveVariableAddress(settings_ptr
, sd
);
2031 int32 value
= (int32
)ReadValue(var
, sd
->save
.conv
);
2033 /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
2034 if (x
< SETTING_BUTTON_WIDTH
&& (sd
->desc
.flags
& SGF_MULTISTRING
)) {
2035 const SettingDescBase
*sdb
= &sd
->desc
;
2036 this->SetDisplayedHelpText(pe
);
2038 if (this->valuedropdown_entry
== pe
) {
2039 /* unclick the dropdown */
2040 HideDropDownMenu(this);
2041 this->closing_dropdown
= false;
2042 this->valuedropdown_entry
->SetButtons(0);
2043 this->valuedropdown_entry
= NULL
;
2045 if (this->valuedropdown_entry
!= NULL
) this->valuedropdown_entry
->SetButtons(0);
2046 this->closing_dropdown
= false;
2048 const NWidgetBase
*wid
= this->GetWidget
<NWidgetBase
>(WID_GS_OPTIONSPANEL
);
2049 int rel_y
= (pt
.y
- (int)wid
->pos_y
- SETTINGTREE_TOP_OFFSET
) % wid
->resize_y
;
2052 wi_rect
.left
= pt
.x
- (_current_text_dir
== TD_RTL
? SETTING_BUTTON_WIDTH
- 1 - x
: x
);
2053 wi_rect
.right
= wi_rect
.left
+ SETTING_BUTTON_WIDTH
- 1;
2054 wi_rect
.top
= pt
.y
- rel_y
+ (SETTING_HEIGHT
- SETTING_BUTTON_HEIGHT
) / 2;
2055 wi_rect
.bottom
= wi_rect
.top
+ SETTING_BUTTON_HEIGHT
- 1;
2057 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
2058 if (pt
.y
>= wi_rect
.top
&& pt
.y
<= wi_rect
.bottom
) {
2059 this->valuedropdown_entry
= pe
;
2060 this->valuedropdown_entry
->SetButtons(SEF_LEFT_DEPRESSED
);
2062 DropDownList
*list
= new DropDownList();
2063 for (int i
= sdb
->min
; i
<= (int)sdb
->max
; i
++) {
2064 *list
->Append() = new DropDownListStringItem(sdb
->str_val
+ i
- sdb
->min
, i
, false);
2067 ShowDropDownListAt(this, list
, value
, -1, wi_rect
, COLOUR_ORANGE
, true);
2071 } else if (x
< SETTING_BUTTON_WIDTH
) {
2072 this->SetDisplayedHelpText(pe
);
2073 const SettingDescBase
*sdb
= &sd
->desc
;
2074 int32 oldvalue
= value
;
2077 case SDT_BOOLX
: value
^= 1; break;
2080 /* Add a dynamic step-size to the scroller. In a maximum of
2081 * 50-steps you should be able to get from min to max,
2082 * unless specified otherwise in the 'interval' variable
2083 * of the current setting. */
2084 uint32 step
= (sdb
->interval
== 0) ? ((sdb
->max
- sdb
->min
) / 50) : sdb
->interval
;
2085 if (step
== 0) step
= 1;
2087 /* don't allow too fast scrolling */
2088 if ((this->flags
& WF_TIMEOUT
) && this->timeout_timer
> 1) {
2089 _left_button_clicked
= false;
2093 /* Increase or decrease the value and clamp it to extremes */
2094 if (x
>= SETTING_BUTTON_WIDTH
/ 2) {
2097 assert((int32
)sdb
->max
>= 0);
2098 if (value
> (int32
)sdb
->max
) value
= (int32
)sdb
->max
;
2100 if ((uint32
)value
> sdb
->max
) value
= (int32
)sdb
->max
;
2102 if (value
< sdb
->min
) value
= sdb
->min
; // skip between "disabled" and minimum
2105 if (value
< sdb
->min
) value
= (sdb
->flags
& SGF_0ISDISABLED
) ? 0 : sdb
->min
;
2108 /* Set up scroller timeout for numeric values */
2109 if (value
!= oldvalue
) {
2110 if (this->clicked_entry
!= NULL
) { // Release previous buttons if any
2111 this->clicked_entry
->SetButtons(0);
2113 this->clicked_entry
= pe
;
2114 this->clicked_entry
->SetButtons((x
>= SETTING_BUTTON_WIDTH
/ 2) != (_current_text_dir
== TD_RTL
) ? SEF_RIGHT_DEPRESSED
: SEF_LEFT_DEPRESSED
);
2116 _left_button_clicked
= false;
2121 default: NOT_REACHED();
2124 if (value
!= oldvalue
) {
2125 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2126 SetCompanySetting(pe
->d
.entry
.index
, value
);
2128 SetSettingValue(pe
->d
.entry
.index
, value
);
2133 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
2134 if (this->last_clicked
== pe
&& sd
->desc
.cmd
!= SDT_BOOLX
&& !(sd
->desc
.flags
& SGF_MULTISTRING
)) {
2135 /* Show the correct currency-translated value */
2136 if (sd
->desc
.flags
& SGF_CURRENCY
) value
*= _currency
->rate
;
2138 this->valuewindow_entry
= pe
;
2139 SetDParam(0, value
);
2140 ShowQueryString(STR_JUST_INT
, STR_CONFIG_SETTING_QUERY_CAPTION
, 10, this, CS_NUMERAL
, QSF_ENABLE_DEFAULT
);
2142 this->SetDisplayedHelpText(pe
);
2146 virtual void OnTimeout()
2148 if (this->clicked_entry
!= NULL
) { // On timeout, release any depressed buttons
2149 this->clicked_entry
->SetButtons(0);
2150 this->clicked_entry
= NULL
;
2155 virtual void OnQueryTextFinished(char *str
)
2157 /* The user pressed cancel */
2158 if (str
== NULL
) return;
2160 assert(this->valuewindow_entry
!= NULL
);
2161 assert((this->valuewindow_entry
->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
2162 const SettingDesc
*sd
= this->valuewindow_entry
->d
.entry
.setting
;
2165 if (!StrEmpty(str
)) {
2168 /* Save the correct currency-translated value */
2169 if (sd
->desc
.flags
& SGF_CURRENCY
) value
/= _currency
->rate
;
2171 value
= (int32
)(size_t)sd
->desc
.def
;
2174 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2175 SetCompanySetting(this->valuewindow_entry
->d
.entry
.index
, value
);
2177 SetSettingValue(this->valuewindow_entry
->d
.entry
.index
, value
);
2182 virtual void OnDropdownSelect(int widget
, int index
)
2185 case WID_GS_RESTRICT_DROPDOWN
:
2186 this->filter
.mode
= (RestrictionMode
)index
;
2187 if (this->filter
.mode
== RM_CHANGED_AGAINST_DEFAULT
||
2188 this->filter
.mode
== RM_CHANGED_AGAINST_NEW
) {
2190 if (!this->manually_changed_folding
) {
2191 /* Expand all when selecting 'changes'. Update the filter state first, in case it becomes less restrictive in some cases. */
2192 _settings_main_page
.UpdateFilterState(this->filter
, false);
2193 _settings_main_page
.UnFoldAll();
2196 /* Non-'changes' filter. Save as default. */
2197 _settings_client
.gui
.settings_restriction_mode
= this->filter
.mode
;
2199 this->InvalidateData();
2202 case WID_GS_TYPE_DROPDOWN
:
2203 this->filter
.type
= (SettingType
)index
;
2204 this->InvalidateData();
2209 /* Deal with drop down boxes on the panel. */
2210 assert(this->valuedropdown_entry
!= NULL
);
2211 const SettingDesc
*sd
= this->valuedropdown_entry
->d
.entry
.setting
;
2212 assert(sd
->desc
.flags
& SGF_MULTISTRING
);
2214 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2215 SetCompanySetting(this->valuedropdown_entry
->d
.entry
.index
, index
);
2217 SetSettingValue(this->valuedropdown_entry
->d
.entry
.index
, index
);
2226 virtual void OnDropdownClose(Point pt
, int widget
, int index
, bool instant_close
)
2229 /* Normally the default implementation of OnDropdownClose() takes care of
2230 * a few things. We want that behaviour here too, but only for
2231 * "normal" dropdown boxes. The special dropdown boxes added for every
2232 * setting that needs one can't have this call. */
2233 Window::OnDropdownClose(pt
, widget
, index
, instant_close
);
2235 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
2236 * the same dropdown button was clicked again, and then not open the dropdown again.
2237 * So, we only remember that it was closed, and process it on the next OnPaint, which is
2239 assert(this->valuedropdown_entry
!= NULL
);
2240 this->closing_dropdown
= true;
2245 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
2247 if (!gui_scope
) return;
2249 /* Update which settings are to be visible. */
2250 RestrictionMode min_level
= (this->filter
.mode
<= RM_ALL
) ? this->filter
.mode
: RM_BASIC
;
2251 this->filter
.min_cat
= min_level
;
2252 this->filter
.type_hides
= false;
2253 _settings_main_page
.UpdateFilterState(this->filter
, false);
2255 if (this->filter
.string
.IsEmpty()) {
2256 this->warn_missing
= WHR_NONE
;
2257 } else if (min_level
< this->filter
.min_cat
) {
2258 this->warn_missing
= this->filter
.type_hides
? WHR_CATEGORY_TYPE
: WHR_CATEGORY
;
2260 this->warn_missing
= this->filter
.type_hides
? WHR_TYPE
: WHR_NONE
;
2262 this->vscroll
->SetCount(_settings_main_page
.Length() + this->warn_lines
);
2264 if (this->last_clicked
!= NULL
&& !_settings_main_page
.IsVisible(this->last_clicked
)) {
2265 this->SetDisplayedHelpText(NULL
);
2268 bool all_folded
= true;
2269 bool all_unfolded
= true;
2270 _settings_main_page
.GetFoldingState(all_folded
, all_unfolded
);
2271 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL
, all_unfolded
);
2272 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL
, all_folded
);
2275 virtual void OnEditboxChanged(int wid
)
2277 if (wid
== WID_GS_FILTER
) {
2278 this->filter
.string
.SetFilterTerm(this->filter_editbox
.text
.buf
);
2279 if (!this->filter
.string
.IsEmpty() && !this->manually_changed_folding
) {
2280 /* User never expanded/collapsed single pages and entered a filter term.
2281 * Expand everything, to save weird expand clicks, */
2282 _settings_main_page
.UnFoldAll();
2284 this->InvalidateData();
2288 virtual void OnResize()
2290 this->vscroll
->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL
, SETTINGTREE_TOP_OFFSET
+ SETTINGTREE_BOTTOM_OFFSET
);
2294 GameSettings
*GameSettingsWindow::settings_ptr
= NULL
;
2296 static const NWidgetPart _nested_settings_selection_widgets
[] = {
2297 NWidget(NWID_HORIZONTAL
),
2298 NWidget(WWT_CLOSEBOX
, COLOUR_MAUVE
),
2299 NWidget(WWT_CAPTION
, COLOUR_MAUVE
), SetDataTip(STR_CONFIG_SETTING_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2300 NWidget(WWT_DEFSIZEBOX
, COLOUR_MAUVE
),
2302 NWidget(WWT_PANEL
, COLOUR_MAUVE
),
2303 NWidget(NWID_VERTICAL
), SetPIP(0, WD_PAR_VSEP_NORMAL
, 0), SetPadding(WD_TEXTPANEL_TOP
, 0, WD_TEXTPANEL_BOTTOM
, 0),
2304 NWidget(NWID_HORIZONTAL
), SetPIP(WD_FRAMETEXT_LEFT
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_RIGHT
),
2305 NWidget(WWT_TEXT
, COLOUR_MAUVE
, WID_GS_RESTRICT_CATEGORY
), SetDataTip(STR_CONFIG_SETTING_RESTRICT_CATEGORY
, STR_NULL
),
2306 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),
2308 NWidget(NWID_HORIZONTAL
), SetPIP(WD_FRAMETEXT_LEFT
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_RIGHT
),
2309 NWidget(WWT_TEXT
, COLOUR_MAUVE
, WID_GS_RESTRICT_TYPE
), SetDataTip(STR_CONFIG_SETTING_RESTRICT_TYPE
, STR_NULL
),
2310 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),
2313 NWidget(NWID_HORIZONTAL
), SetPadding(0, 0, WD_TEXTPANEL_BOTTOM
, 0),
2314 SetPIP(WD_FRAMETEXT_LEFT
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_RIGHT
),
2315 NWidget(WWT_TEXT
, COLOUR_MAUVE
), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE
, STR_NULL
),
2316 NWidget(WWT_EDITBOX
, COLOUR_MAUVE
, WID_GS_FILTER
), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
2317 SetDataTip(STR_LIST_FILTER_OSKTITLE
, STR_LIST_FILTER_TOOLTIP
),
2320 NWidget(NWID_HORIZONTAL
),
2321 NWidget(WWT_PANEL
, COLOUR_MAUVE
, WID_GS_OPTIONSPANEL
), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR
), EndContainer(),
2322 NWidget(NWID_VERTICAL
),
2323 NWidget(NWID_VSCROLLBAR
, COLOUR_MAUVE
, WID_GS_SCROLLBAR
),
2326 NWidget(WWT_PANEL
, COLOUR_MAUVE
), SetMinimalSize(400, 40),
2327 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_GS_HELP_TEXT
), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
2328 SetPadding(WD_FRAMETEXT_TOP
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_BOTTOM
, WD_FRAMETEXT_LEFT
),
2329 NWidget(NWID_HORIZONTAL
),
2330 NWidget(WWT_PANEL
, COLOUR_MAUVE
),
2331 NWidget(NWID_HORIZONTAL
),
2332 NWidget(WWT_PUSHTXTBTN
, COLOUR_MAUVE
, WID_GS_EXPAND_ALL
), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL
, STR_NULL
),
2333 NWidget(WWT_PUSHTXTBTN
, COLOUR_MAUVE
, WID_GS_COLLAPSE_ALL
), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL
, STR_NULL
),
2334 NWidget(NWID_SPACER
, INVALID_COLOUR
), SetFill(1, 1), SetResize(1, 0),
2337 NWidget(WWT_RESIZEBOX
, COLOUR_MAUVE
),
2342 static WindowDesc
_settings_selection_desc(
2343 WDP_CENTER
, "settings", 510, 450,
2344 WC_GAME_OPTIONS
, WC_NONE
,
2346 _nested_settings_selection_widgets
, lengthof(_nested_settings_selection_widgets
)
2349 /** Open advanced settings window. */
2350 void ShowGameSettings()
2352 DeleteWindowByClass(WC_GAME_OPTIONS
);
2353 new GameSettingsWindow(&_settings_selection_desc
);
2358 * Draw [<][>] boxes.
2359 * @param x the x position to draw
2360 * @param y the y position to draw
2361 * @param button_colour the colour of the button
2362 * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked
2363 * @param clickable_left is the left button clickable?
2364 * @param clickable_right is the right button clickable?
2366 void DrawArrowButtons(int x
, int y
, Colours button_colour
, byte state
, bool clickable_left
, bool clickable_right
)
2368 int colour
= _colour_gradient
[button_colour
][2];
2370 DrawFrameRect(x
, y
, x
+ SETTING_BUTTON_WIDTH
/ 2 - 1, y
+ SETTING_BUTTON_HEIGHT
- 1, button_colour
, (state
== 1) ? FR_LOWERED
: FR_NONE
);
2371 DrawFrameRect(x
+ SETTING_BUTTON_WIDTH
/ 2, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 1, button_colour
, (state
== 2) ? FR_LOWERED
: FR_NONE
);
2372 DrawSprite(SPR_ARROW_LEFT
, PAL_NONE
, x
+ WD_IMGBTN_LEFT
, y
+ WD_IMGBTN_TOP
);
2373 DrawSprite(SPR_ARROW_RIGHT
, PAL_NONE
, x
+ WD_IMGBTN_LEFT
+ SETTING_BUTTON_WIDTH
/ 2, y
+ WD_IMGBTN_TOP
);
2375 /* Grey out the buttons that aren't clickable */
2376 bool rtl
= _current_text_dir
== TD_RTL
;
2377 if (rtl
? !clickable_right
: !clickable_left
) {
2378 GfxFillRect(x
+ 1, y
, x
+ SETTING_BUTTON_WIDTH
/ 2 - 1, y
+ SETTING_BUTTON_HEIGHT
- 2, colour
, FILLRECT_CHECKER
);
2380 if (rtl
? !clickable_left
: !clickable_right
) {
2381 GfxFillRect(x
+ SETTING_BUTTON_WIDTH
/ 2 + 1, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 2, colour
, FILLRECT_CHECKER
);
2386 * Draw a dropdown button.
2387 * @param x the x position to draw
2388 * @param y the y position to draw
2389 * @param button_colour the colour of the button
2390 * @param state true = lowered
2391 * @param clickable is the button clickable?
2393 void DrawDropDownButton(int x
, int y
, Colours button_colour
, bool state
, bool clickable
)
2395 static const char *DOWNARROW
= "\xEE\x8A\xAA";
2397 int colour
= _colour_gradient
[button_colour
][2];
2399 DrawFrameRect(x
, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 1, button_colour
, state
? FR_LOWERED
: FR_NONE
);
2400 DrawString(x
+ (state
? 1 : 0), x
+ SETTING_BUTTON_WIDTH
- (state
? 0 : 1), y
+ (state
? 2 : 1), DOWNARROW
, TC_BLACK
, SA_HOR_CENTER
);
2403 GfxFillRect(x
+ 1, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 2, colour
, FILLRECT_CHECKER
);
2408 * Draw a toggle button.
2409 * @param x the x position to draw
2410 * @param y the y position to draw
2411 * @param state true = lowered
2412 * @param clickable is the button clickable?
2414 void DrawBoolButton(int x
, int y
, bool state
, bool clickable
)
2416 static const Colours _bool_ctabs
[2][2] = {{COLOUR_CREAM
, COLOUR_RED
}, {COLOUR_DARK_GREEN
, COLOUR_GREEN
}};
2417 DrawFrameRect(x
, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 1, _bool_ctabs
[state
][clickable
], state
? FR_LOWERED
: FR_NONE
);
2420 struct CustomCurrencyWindow
: Window
{
2423 CustomCurrencyWindow(WindowDesc
*desc
) : Window(desc
)
2430 void SetButtonState()
2432 this->SetWidgetDisabledState(WID_CC_RATE_DOWN
, _custom_currency
.rate
== 1);
2433 this->SetWidgetDisabledState(WID_CC_RATE_UP
, _custom_currency
.rate
== UINT16_MAX
);
2434 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN
, _custom_currency
.to_euro
== CF_NOEURO
);
2435 this->SetWidgetDisabledState(WID_CC_YEAR_UP
, _custom_currency
.to_euro
== MAX_YEAR
);
2438 virtual void SetStringParameters(int widget
) const
2441 case WID_CC_RATE
: SetDParam(0, 1); SetDParam(1, 1); break;
2442 case WID_CC_SEPARATOR
: SetDParamStr(0, _custom_currency
.separator
); break;
2443 case WID_CC_PREFIX
: SetDParamStr(0, _custom_currency
.prefix
); break;
2444 case WID_CC_SUFFIX
: SetDParamStr(0, _custom_currency
.suffix
); break;
2446 SetDParam(0, (_custom_currency
.to_euro
!= CF_NOEURO
) ? STR_CURRENCY_SWITCH_TO_EURO
: STR_CURRENCY_SWITCH_TO_EURO_NEVER
);
2447 SetDParam(1, _custom_currency
.to_euro
);
2450 case WID_CC_PREVIEW
:
2451 SetDParam(0, 10000);
2456 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
2459 /* Set the appropriate width for the edit 'buttons' */
2460 case WID_CC_SEPARATOR_EDIT
:
2461 case WID_CC_PREFIX_EDIT
:
2462 case WID_CC_SUFFIX_EDIT
:
2463 size
->width
= this->GetWidget
<NWidgetBase
>(WID_CC_RATE_DOWN
)->smallest_x
+ this->GetWidget
<NWidgetBase
>(WID_CC_RATE_UP
)->smallest_x
;
2466 /* Make sure the window is wide enough for the widest exchange rate */
2469 SetDParam(1, INT32_MAX
);
2470 *size
= GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE
);
2475 virtual void OnClick(Point pt
, int widget
, int click_count
)
2480 CharSetFilter afilter
= CS_ALPHANUMERAL
;
2483 case WID_CC_RATE_DOWN
:
2484 if (_custom_currency
.rate
> 1) _custom_currency
.rate
--;
2485 if (_custom_currency
.rate
== 1) this->DisableWidget(WID_CC_RATE_DOWN
);
2486 this->EnableWidget(WID_CC_RATE_UP
);
2489 case WID_CC_RATE_UP
:
2490 if (_custom_currency
.rate
< UINT16_MAX
) _custom_currency
.rate
++;
2491 if (_custom_currency
.rate
== UINT16_MAX
) this->DisableWidget(WID_CC_RATE_UP
);
2492 this->EnableWidget(WID_CC_RATE_DOWN
);
2496 SetDParam(0, _custom_currency
.rate
);
2500 afilter
= CS_NUMERAL
;
2503 case WID_CC_SEPARATOR_EDIT
:
2504 case WID_CC_SEPARATOR
:
2505 SetDParamStr(0, _custom_currency
.separator
);
2506 str
= STR_JUST_RAW_STRING
;
2508 line
= WID_CC_SEPARATOR
;
2511 case WID_CC_PREFIX_EDIT
:
2513 SetDParamStr(0, _custom_currency
.prefix
);
2514 str
= STR_JUST_RAW_STRING
;
2516 line
= WID_CC_PREFIX
;
2519 case WID_CC_SUFFIX_EDIT
:
2521 SetDParamStr(0, _custom_currency
.suffix
);
2522 str
= STR_JUST_RAW_STRING
;
2524 line
= WID_CC_SUFFIX
;
2527 case WID_CC_YEAR_DOWN
:
2528 _custom_currency
.to_euro
= (_custom_currency
.to_euro
<= 2000) ? CF_NOEURO
: _custom_currency
.to_euro
- 1;
2529 if (_custom_currency
.to_euro
== CF_NOEURO
) this->DisableWidget(WID_CC_YEAR_DOWN
);
2530 this->EnableWidget(WID_CC_YEAR_UP
);
2533 case WID_CC_YEAR_UP
:
2534 _custom_currency
.to_euro
= Clamp(_custom_currency
.to_euro
+ 1, 2000, MAX_YEAR
);
2535 if (_custom_currency
.to_euro
== MAX_YEAR
) this->DisableWidget(WID_CC_YEAR_UP
);
2536 this->EnableWidget(WID_CC_YEAR_DOWN
);
2540 SetDParam(0, _custom_currency
.to_euro
);
2544 afilter
= CS_NUMERAL
;
2549 this->query_widget
= line
;
2550 ShowQueryString(str
, STR_CURRENCY_CHANGE_PARAMETER
, len
+ 1, this, afilter
, QSF_NONE
);
2557 virtual void OnQueryTextFinished(char *str
)
2559 if (str
== NULL
) return;
2561 switch (this->query_widget
) {
2563 _custom_currency
.rate
= Clamp(atoi(str
), 1, UINT16_MAX
);
2566 case WID_CC_SEPARATOR
: // Thousands separator
2567 strecpy(_custom_currency
.separator
, str
, lastof(_custom_currency
.separator
));
2571 strecpy(_custom_currency
.prefix
, str
, lastof(_custom_currency
.prefix
));
2575 strecpy(_custom_currency
.suffix
, str
, lastof(_custom_currency
.suffix
));
2578 case WID_CC_YEAR
: { // Year to switch to euro
2579 int val
= atoi(str
);
2581 _custom_currency
.to_euro
= (val
< 2000 ? CF_NOEURO
: min(val
, MAX_YEAR
));
2585 MarkWholeScreenDirty();
2589 virtual void OnTimeout()
2595 static const NWidgetPart _nested_cust_currency_widgets
[] = {
2596 NWidget(NWID_HORIZONTAL
),
2597 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
2598 NWidget(WWT_CAPTION
, COLOUR_GREY
), SetDataTip(STR_CURRENCY_WINDOW
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2600 NWidget(WWT_PANEL
, COLOUR_GREY
),
2601 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
), SetPIP(7, 3, 0),
2602 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2603 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_RATE_DOWN
), SetDataTip(AWV_DECREASE
, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP
),
2604 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_RATE_UP
), SetDataTip(AWV_INCREASE
, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP
),
2605 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2606 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_RATE
), SetDataTip(STR_CURRENCY_EXCHANGE_RATE
, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP
), SetFill(1, 0),
2608 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2609 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_SEPARATOR_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP
), SetFill(0, 1),
2610 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2611 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_SEPARATOR
), SetDataTip(STR_CURRENCY_SEPARATOR
, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP
), SetFill(1, 0),
2613 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2614 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_PREFIX_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP
), SetFill(0, 1),
2615 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2616 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_PREFIX
), SetDataTip(STR_CURRENCY_PREFIX
, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP
), SetFill(1, 0),
2618 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2619 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_SUFFIX_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP
), SetFill(0, 1),
2620 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2621 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_SUFFIX
), SetDataTip(STR_CURRENCY_SUFFIX
, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP
), SetFill(1, 0),
2623 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2624 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_YEAR_DOWN
), SetDataTip(AWV_DECREASE
, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
),
2625 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_YEAR_UP
), SetDataTip(AWV_INCREASE
, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
),
2626 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2627 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_YEAR
), SetDataTip(STR_JUST_STRING
, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
), SetFill(1, 0),
2630 NWidget(WWT_LABEL
, COLOUR_BLUE
, WID_CC_PREVIEW
),
2631 SetDataTip(STR_CURRENCY_PREVIEW
, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP
), SetPadding(15, 1, 18, 2),
2635 static WindowDesc
_cust_currency_desc(
2636 WDP_CENTER
, NULL
, 0, 0,
2637 WC_CUSTOM_CURRENCY
, WC_NONE
,
2639 _nested_cust_currency_widgets
, lengthof(_nested_cust_currency_widgets
)
2642 /** Open custom currency window. */
2643 static void ShowCustCurrency()
2645 DeleteWindowById(WC_CUSTOM_CURRENCY
, 0);
2646 new CustomCurrencyWindow(&_cust_currency_desc
);