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
) && BlitterFactoryBase::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.
698 /** Filter for settings list. */
699 struct SettingFilter
{
700 StringFilter string
; ///< Filter string.
701 RestrictionMode mode
; ///< Filter based on category.
702 SettingType type
; ///< Filter based on type.
705 /** Data structure describing a single setting in a tab */
706 struct SettingEntry
{
707 byte flags
; ///< Flags of the setting entry. @see SettingEntryFlags
708 byte level
; ///< Nesting level of this setting entry
710 SettingEntrySetting entry
; ///< Data fields if entry is a setting
711 SettingEntrySubtree sub
; ///< Data fields if entry is a sub-page
712 } d
; ///< Data fields for each kind
714 SettingEntry(const char *nm
);
715 SettingEntry(SettingsPage
*sub
, StringID title
);
717 void Init(byte level
);
720 void SetButtons(byte new_val
);
723 * Set whether this is the last visible entry of the parent node.
724 * @param last_field Value to set
726 void SetLastField(bool last_field
) { if (last_field
) SETBITS(this->flags
, SEF_LAST_FIELD
); else CLRBITS(this->flags
, SEF_LAST_FIELD
); }
729 void GetFoldingState(bool &all_folded
, bool &all_unfolded
) const;
730 bool IsVisible(const SettingEntry
*item
) const;
731 SettingEntry
*FindEntry(uint row
, uint
*cur_row
);
732 uint
GetMaxHelpHeight(int maxw
);
734 bool IsFiltered() const;
735 bool UpdateFilterState(SettingFilter
&filter
, bool force_visible
);
737 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
);
740 * Get the help text of a single setting.
741 * @return The requested help text.
743 inline StringID
GetHelpText()
745 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
746 return this->d
.entry
.setting
->desc
.str_help
;
749 void SetValueDParams(uint first_param
, int32 value
);
752 void DrawSetting(GameSettings
*settings_ptr
, int x
, int y
, int max_x
, int state
, bool highlight
);
753 bool IsVisibleByRestrictionMode(RestrictionMode mode
) const;
756 /** Data structure describing one page of settings in the settings window. */
757 struct SettingsPage
{
758 SettingEntry
*entries
; ///< Array of setting entries of the page.
759 byte num
; ///< Number of entries on the page (statically filled).
761 void Init(byte level
= 0);
766 void GetFoldingState(bool &all_folded
, bool &all_unfolded
) const;
767 bool IsVisible(const SettingEntry
*item
) const;
768 SettingEntry
*FindEntry(uint row
, uint
*cur_row
) const;
769 uint
GetMaxHelpHeight(int maxw
);
771 bool UpdateFilterState(SettingFilter
&filter
, bool force_visible
);
773 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;
777 /* == SettingEntry methods == */
780 * Constructor for a single setting in the 'advanced settings' window
781 * @param nm Name of the setting in the setting table
783 SettingEntry::SettingEntry(const char *nm
)
785 this->flags
= SEF_SETTING_KIND
;
787 this->d
.entry
.name
= nm
;
788 this->d
.entry
.setting
= NULL
;
789 this->d
.entry
.index
= 0;
793 * Constructor for a sub-page in the 'advanced settings' window
794 * @param sub Sub-page
795 * @param title Title of the sub-page
797 SettingEntry::SettingEntry(SettingsPage
*sub
, StringID title
)
799 this->flags
= SEF_SUBTREE_KIND
;
801 this->d
.sub
.page
= sub
;
802 this->d
.sub
.folded
= true;
803 this->d
.sub
.title
= title
;
807 * Initialization of a setting entry
808 * @param level Page nesting level of this entry
810 void SettingEntry::Init(byte level
)
814 switch (this->flags
& SEF_KIND_MASK
) {
815 case SEF_SETTING_KIND
:
816 this->d
.entry
.setting
= GetSettingFromName(this->d
.entry
.name
, &this->d
.entry
.index
);
817 assert(this->d
.entry
.setting
!= NULL
);
819 case SEF_SUBTREE_KIND
:
820 this->d
.sub
.page
->Init(level
+ 1);
822 default: NOT_REACHED();
826 /** Recursively close all (filtered) folds of sub-pages */
827 void SettingEntry::FoldAll()
829 if (this->IsFiltered()) return;
830 switch (this->flags
& SEF_KIND_MASK
) {
831 case SEF_SETTING_KIND
:
834 case SEF_SUBTREE_KIND
:
835 this->d
.sub
.folded
= true;
836 this->d
.sub
.page
->FoldAll();
839 default: NOT_REACHED();
843 /** Recursively open all (filtered) folds of sub-pages */
844 void SettingEntry::UnFoldAll()
846 if (this->IsFiltered()) return;
847 switch (this->flags
& SEF_KIND_MASK
) {
848 case SEF_SETTING_KIND
:
851 case SEF_SUBTREE_KIND
:
852 this->d
.sub
.folded
= false;
853 this->d
.sub
.page
->UnFoldAll();
856 default: NOT_REACHED();
861 * Recursively accumulate the folding state of the (filtered) tree.
862 * @param[in,out] all_folded Set to false, if one entry is not folded.
863 * @param[in,out] all_unfolded Set to false, if one entry is folded.
865 void SettingEntry::GetFoldingState(bool &all_folded
, bool &all_unfolded
) const
867 if (this->IsFiltered()) return;
868 switch (this->flags
& SEF_KIND_MASK
) {
869 case SEF_SETTING_KIND
:
872 case SEF_SUBTREE_KIND
:
873 if (this->d
.sub
.folded
) {
874 all_unfolded
= false;
878 this->d
.sub
.page
->GetFoldingState(all_folded
, all_unfolded
);
881 default: NOT_REACHED();
886 * Check whether an entry is visible and not folded or filtered away.
887 * Note: This does not consider the scrolling range; it might still require scrolling to make the setting really visible.
888 * @param item Entry to search for.
889 * @return true if entry is visible.
891 bool SettingEntry::IsVisible(const SettingEntry
*item
) const
893 if (this->IsFiltered()) return false;
894 if (this == item
) return true;
896 switch (this->flags
& SEF_KIND_MASK
) {
897 case SEF_SETTING_KIND
:
900 case SEF_SUBTREE_KIND
:
901 return !this->d
.sub
.folded
&& this->d
.sub
.page
->IsVisible(item
);
903 default: NOT_REACHED();
908 * Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
909 * @param new_val New value for the button flags
910 * @see SettingEntryFlags
912 void SettingEntry::SetButtons(byte new_val
)
914 assert((new_val
& ~SEF_BUTTONS_MASK
) == 0); // Should not touch any flags outside the buttons
915 this->flags
= (this->flags
& ~SEF_BUTTONS_MASK
) | new_val
;
918 /** Return numbers of rows needed to display the (filtered) entry */
919 uint
SettingEntry::Length() const
921 if (this->IsFiltered()) return 0;
922 switch (this->flags
& SEF_KIND_MASK
) {
923 case SEF_SETTING_KIND
:
925 case SEF_SUBTREE_KIND
:
926 if (this->d
.sub
.folded
) return 1; // Only displaying the title
928 return 1 + this->d
.sub
.page
->Length(); // 1 extra row for the title
929 default: NOT_REACHED();
934 * Find setting entry at row \a row_num
935 * @param row_num Index of entry to return
936 * @param cur_row Current row number
937 * @return The requested setting entry or \c NULL if it not found (folded or filtered)
939 SettingEntry
*SettingEntry::FindEntry(uint row_num
, uint
*cur_row
)
941 if (this->IsFiltered()) return NULL
;
942 if (row_num
== *cur_row
) return this;
944 switch (this->flags
& SEF_KIND_MASK
) {
945 case SEF_SETTING_KIND
:
948 case SEF_SUBTREE_KIND
:
949 (*cur_row
)++; // add one for row containing the title
950 if (this->d
.sub
.folded
) {
954 /* sub-page is visible => search it too */
955 return this->d
.sub
.page
->FindEntry(row_num
, cur_row
);
956 default: NOT_REACHED();
962 * Get the biggest height of the help text(s), if the width is at least \a maxw. Help text gets wrapped if needed.
963 * @param maxw Maximal width of a line help text.
964 * @return Biggest height needed to display any help text of this node (and its descendants).
966 uint
SettingEntry::GetMaxHelpHeight(int maxw
)
968 switch (this->flags
& SEF_KIND_MASK
) {
969 case SEF_SETTING_KIND
: return GetStringHeight(this->GetHelpText(), maxw
);
970 case SEF_SUBTREE_KIND
: return this->d
.sub
.page
->GetMaxHelpHeight(maxw
);
971 default: NOT_REACHED();
976 * Check whether an entry is hidden due to filters
977 * @return true if hidden.
979 bool SettingEntry::IsFiltered() const
981 return (this->flags
& SEF_FILTERED
) != 0;
985 * Checks whether an entry shall be made visible based on the restriction mode.
986 * @param mode The current status of the restriction drop down box.
987 * @return true if the entry shall be visible.
989 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode
) const
991 /* There shall not be any restriction, i.e. all settings shall be visible. */
992 if (mode
== RM_ALL
) return true;
994 GameSettings
*settings_ptr
= &GetGameSettings();
995 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
996 const SettingDesc
*sd
= this->d
.entry
.setting
;
998 if (mode
== RM_BASIC
) return (this->d
.entry
.setting
->desc
.cat
& SC_BASIC_LIST
) != 0;
999 if (mode
== RM_ADVANCED
) return (this->d
.entry
.setting
->desc
.cat
& SC_ADVANCED_LIST
) != 0;
1001 /* Read the current value. */
1002 const void *var
= ResolveVariableAddress(settings_ptr
, sd
);
1003 int64 current_value
= ReadValue(var
, sd
->save
.conv
);
1007 if (mode
== RM_CHANGED_AGAINST_DEFAULT
) {
1008 /* This entry shall only be visible, if the value deviates from its default value. */
1010 /* Read the default value. */
1011 filter_value
= ReadValue(&sd
->desc
.def
, sd
->save
.conv
);
1013 assert(mode
== RM_CHANGED_AGAINST_NEW
);
1014 /* This entry shall only be visible, if the value deviates from
1015 * its value is used when starting a new game. */
1017 /* Make sure we're not comparing the new game settings against itself. */
1018 assert(settings_ptr
!= &_settings_newgame
);
1020 /* Read the new game's value. */
1021 var
= ResolveVariableAddress(&_settings_newgame
, sd
);
1022 filter_value
= ReadValue(var
, sd
->save
.conv
);
1025 return current_value
!= filter_value
;
1029 * Update the filter state.
1030 * @param filter Filter
1031 * @param force_visible Whether to force all items visible, no matter what (due to filter text; not affected by restriction drop down box).
1032 * @return true if item remains visible
1034 bool SettingEntry::UpdateFilterState(SettingFilter
&filter
, bool force_visible
)
1036 CLRBITS(this->flags
, SEF_FILTERED
);
1038 bool visible
= true;
1039 switch (this->flags
& SEF_KIND_MASK
) {
1040 case SEF_SETTING_KIND
: {
1041 const SettingDesc
*sd
= this->d
.entry
.setting
;
1042 if (!force_visible
&& !filter
.string
.IsEmpty()) {
1043 /* Process the search text filter for this item. */
1044 filter
.string
.ResetState();
1046 const SettingDescBase
*sdb
= &sd
->desc
;
1048 SetDParam(0, STR_EMPTY
);
1049 filter
.string
.AddLine(sdb
->str
);
1050 filter
.string
.AddLine(this->GetHelpText());
1052 visible
= filter
.string
.GetState();
1054 if (filter
.type
!= ST_ALL
) visible
= visible
&& sd
->GetType() == filter
.type
;
1055 visible
= visible
&& this->IsVisibleByRestrictionMode(filter
.mode
);
1058 case SEF_SUBTREE_KIND
: {
1059 if (!force_visible
&& !filter
.string
.IsEmpty()) {
1060 filter
.string
.ResetState();
1061 filter
.string
.AddLine(this->d
.sub
.title
);
1062 force_visible
= filter
.string
.GetState();
1064 visible
= this->d
.sub
.page
->UpdateFilterState(filter
, force_visible
);
1067 default: NOT_REACHED();
1070 if (!visible
) SETBITS(this->flags
, SEF_FILTERED
);
1077 * Draw a row in the settings panel.
1079 * See SettingsPage::Draw() for an explanation about how drawing is performed.
1081 * The \a parent_last parameter ensures that the vertical lines at the left are
1082 * only drawn when another entry follows, that it prevents output like
1089 * The left-most vertical line is not wanted. It is prevented by setting the
1090 * appropriate bit in the \a parent_last parameter.
1092 * @param settings_ptr Pointer to current values of all settings
1093 * @param left Left-most position in window/panel to start drawing \a first_row
1094 * @param right Right-most x position to draw strings at.
1095 * @param base_y Upper-most position in window/panel to start drawing \a first_row
1096 * @param first_row First row number to draw
1097 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1098 * @param cur_row Current row number (internal variable)
1099 * @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)
1100 * @param selected Selected entry by the user.
1101 * @return Row number of the next row to draw
1103 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
)
1105 if (this->IsFiltered()) return cur_row
;
1106 if (cur_row
>= max_row
) return cur_row
;
1108 bool rtl
= _current_text_dir
== TD_RTL
;
1109 int offset
= rtl
? -4 : 4;
1110 int level_width
= rtl
? -LEVEL_WIDTH
: LEVEL_WIDTH
;
1112 int x
= rtl
? right
: left
;
1114 if (cur_row
>= first_row
) {
1115 int colour
= _colour_gradient
[COLOUR_ORANGE
][4];
1116 y
= base_y
+ (cur_row
- first_row
) * SETTING_HEIGHT
; // Compute correct y start position
1118 /* Draw vertical for parent nesting levels */
1119 for (uint lvl
= 0; lvl
< this->level
; lvl
++) {
1120 if (!HasBit(parent_last
, lvl
)) GfxDrawLine(x
+ offset
, y
, x
+ offset
, y
+ SETTING_HEIGHT
- 1, colour
);
1123 /* draw own |- prefix */
1124 int halfway_y
= y
+ SETTING_HEIGHT
/ 2;
1125 int bottom_y
= (flags
& SEF_LAST_FIELD
) ? halfway_y
: y
+ SETTING_HEIGHT
- 1;
1126 GfxDrawLine(x
+ offset
, y
, x
+ offset
, bottom_y
, colour
);
1127 /* Small horizontal line from the last vertical line */
1128 GfxDrawLine(x
+ offset
, halfway_y
, x
+ level_width
- offset
, halfway_y
, colour
);
1132 switch (this->flags
& SEF_KIND_MASK
) {
1133 case SEF_SETTING_KIND
:
1134 if (cur_row
>= first_row
) {
1135 this->DrawSetting(settings_ptr
, rtl
? left
: x
, rtl
? x
: right
, y
, this->flags
& SEF_BUTTONS_MASK
,
1140 case SEF_SUBTREE_KIND
:
1141 if (cur_row
>= first_row
) {
1142 DrawSprite((this->d
.sub
.folded
? SPR_CIRCLE_FOLDED
: SPR_CIRCLE_UNFOLDED
), PAL_NONE
, rtl
? x
- 8 : x
, y
+ (SETTING_HEIGHT
- 11) / 2);
1143 DrawString(rtl
? left
: x
+ 12, rtl
? x
- 12 : right
, y
, this->d
.sub
.title
);
1146 if (!this->d
.sub
.folded
) {
1147 if (this->flags
& SEF_LAST_FIELD
) {
1148 assert(this->level
< sizeof(parent_last
));
1149 SetBit(parent_last
, this->level
); // Add own last-field state
1152 cur_row
= this->d
.sub
.page
->Draw(settings_ptr
, left
, right
, base_y
, first_row
, max_row
, selected
, cur_row
, parent_last
);
1155 default: NOT_REACHED();
1160 static const void *ResolveVariableAddress(const GameSettings
*settings_ptr
, const SettingDesc
*sd
)
1162 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
1163 if (Company::IsValidID(_local_company
) && _game_mode
!= GM_MENU
) {
1164 return GetVariableAddress(&sd
->save
, &Company::Get(_local_company
)->settings
);
1166 return GetVariableAddress(&sd
->save
, &_settings_client
.company
);
1169 return GetVariableAddress(&sd
->save
, settings_ptr
);
1174 * Set the DParams for drawing the value of a setting.
1175 * @param first_param First DParam to use
1176 * @param value Setting value to set params for.
1178 void SettingEntry::SetValueDParams(uint first_param
, int32 value
)
1180 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
1181 const SettingDescBase
*sdb
= &this->d
.entry
.setting
->desc
;
1182 if (sdb
->cmd
== SDT_BOOLX
) {
1183 SetDParam(first_param
++, value
!= 0 ? STR_CONFIG_SETTING_ON
: STR_CONFIG_SETTING_OFF
);
1185 if ((sdb
->flags
& SGF_MULTISTRING
) != 0) {
1186 SetDParam(first_param
++, sdb
->str_val
- sdb
->min
+ value
);
1187 } else if ((sdb
->flags
& SGF_DISPLAY_ABS
) != 0) {
1188 SetDParam(first_param
++, sdb
->str_val
+ ((value
>= 0) ? 1 : 0));
1191 SetDParam(first_param
++, sdb
->str_val
+ ((value
== 0 && (sdb
->flags
& SGF_0ISDISABLED
) != 0) ? 1 : 0));
1193 SetDParam(first_param
++, value
);
1198 * Private function to draw setting value (button + text + current value)
1199 * @param settings_ptr Pointer to current values of all settings
1200 * @param left Left-most position in window/panel to start drawing
1201 * @param right Right-most position in window/panel to draw
1202 * @param y Upper-most position in window/panel to start drawing
1203 * @param state State of the left + right arrow buttons to draw for the setting
1204 * @param highlight Highlight entry.
1206 void SettingEntry::DrawSetting(GameSettings
*settings_ptr
, int left
, int right
, int y
, int state
, bool highlight
)
1208 const SettingDesc
*sd
= this->d
.entry
.setting
;
1209 const SettingDescBase
*sdb
= &sd
->desc
;
1210 const void *var
= ResolveVariableAddress(settings_ptr
, sd
);
1212 bool rtl
= _current_text_dir
== TD_RTL
;
1213 uint buttons_left
= rtl
? right
+ 1 - SETTING_BUTTON_WIDTH
: left
;
1214 uint text_left
= left
+ (rtl
? 0 : SETTING_BUTTON_WIDTH
+ 5);
1215 uint text_right
= right
- (rtl
? SETTING_BUTTON_WIDTH
+ 5 : 0);
1216 uint button_y
= y
+ (SETTING_HEIGHT
- SETTING_BUTTON_HEIGHT
) / 2;
1218 /* We do not allow changes of some items when we are a client in a networkgame */
1219 bool editable
= sd
->IsEditable();
1221 SetDParam(0, highlight
? STR_ORANGE_STRING1_WHITE
: STR_ORANGE_STRING1_LTBLUE
);
1222 int32 value
= (int32
)ReadValue(var
, sd
->save
.conv
);
1223 if (sdb
->cmd
== SDT_BOOLX
) {
1224 /* Draw checkbox for boolean-value either on/off */
1225 DrawBoolButton(buttons_left
, button_y
, value
!= 0, editable
);
1226 } else if ((sdb
->flags
& SGF_MULTISTRING
) != 0) {
1227 /* Draw [v] button for settings of an enum-type */
1228 DrawDropDownButton(buttons_left
, button_y
, COLOUR_YELLOW
, state
!= 0, editable
);
1230 /* Draw [<][>] boxes for settings of an integer-type */
1231 DrawArrowButtons(buttons_left
, button_y
, COLOUR_YELLOW
, state
,
1232 editable
&& value
!= (sdb
->flags
& SGF_0ISDISABLED
? 0 : sdb
->min
), editable
&& (uint32
)value
!= sdb
->max
);
1234 this->SetValueDParams(1, value
);
1235 DrawString(text_left
, text_right
, y
, sdb
->str
, highlight
? TC_WHITE
: TC_LIGHT_BLUE
);
1239 /* == SettingsPage methods == */
1242 * Initialization of an entire setting page
1243 * @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
1245 void SettingsPage::Init(byte level
)
1247 for (uint field
= 0; field
< this->num
; field
++) {
1248 this->entries
[field
].Init(level
);
1252 /** Recursively close all folds of sub-pages */
1253 void SettingsPage::FoldAll()
1255 for (uint field
= 0; field
< this->num
; field
++) {
1256 this->entries
[field
].FoldAll();
1260 /** Recursively open all folds of sub-pages */
1261 void SettingsPage::UnFoldAll()
1263 for (uint field
= 0; field
< this->num
; field
++) {
1264 this->entries
[field
].UnFoldAll();
1269 * Recursively accumulate the folding state of the tree.
1270 * @param[in,out] all_folded Set to false, if one entry is not folded.
1271 * @param[in,out] all_unfolded Set to false, if one entry is folded.
1273 void SettingsPage::GetFoldingState(bool &all_folded
, bool &all_unfolded
) const
1275 for (uint field
= 0; field
< this->num
; field
++) {
1276 this->entries
[field
].GetFoldingState(all_folded
, all_unfolded
);
1281 * Update the filter state.
1282 * @param filter Filter
1283 * @param force_visible Whether to force all items visible, no matter what
1284 * @return true if item remains visible
1286 bool SettingsPage::UpdateFilterState(SettingFilter
&filter
, bool force_visible
)
1288 bool visible
= false;
1289 bool first_visible
= true;
1290 for (int field
= this->num
- 1; field
>= 0; field
--) {
1291 visible
|= this->entries
[field
].UpdateFilterState(filter
, force_visible
);
1292 this->entries
[field
].SetLastField(first_visible
);
1293 if (visible
&& first_visible
) first_visible
= false;
1300 * Check whether an entry is visible and not folded or filtered away.
1301 * Note: This does not consider the scrolling range; it might still require scrolling ot make the setting really visible.
1302 * @param item Entry to search for.
1303 * @return true if entry is visible.
1305 bool SettingsPage::IsVisible(const SettingEntry
*item
) const
1307 for (uint field
= 0; field
< this->num
; field
++) {
1308 if (this->entries
[field
].IsVisible(item
)) return true;
1313 /** Return number of rows needed to display the whole page */
1314 uint
SettingsPage::Length() const
1317 for (uint field
= 0; field
< this->num
; field
++) {
1318 length
+= this->entries
[field
].Length();
1324 * Find the setting entry at row number \a row_num
1325 * @param row_num Index of entry to return
1326 * @param cur_row Variable used for keeping track of the current row number. Should point to memory initialized to \c 0 when first called.
1327 * @return The requested setting entry or \c NULL if it does not exist
1329 SettingEntry
*SettingsPage::FindEntry(uint row_num
, uint
*cur_row
) const
1331 SettingEntry
*pe
= NULL
;
1333 for (uint field
= 0; field
< this->num
; field
++) {
1334 pe
= this->entries
[field
].FindEntry(row_num
, cur_row
);
1343 * Get the biggest height of the help texts, if the width is at least \a maxw. Help text gets wrapped if needed.
1344 * @param maxw Maximal width of a line help text.
1345 * @return Biggest height needed to display any help text of this (sub-)tree.
1347 uint
SettingsPage::GetMaxHelpHeight(int maxw
)
1350 for (uint field
= 0; field
< this->num
; field
++) {
1351 biggest
= max(biggest
, this->entries
[field
].GetMaxHelpHeight(maxw
));
1357 * Draw a selected part of the settings page.
1359 * The scrollbar uses rows of the page, while the page data structure is a tree of #SettingsPage and #SettingEntry objects.
1360 * 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.
1361 * Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
1363 * @param settings_ptr Pointer to current values of all settings
1364 * @param left Left-most position in window/panel to start drawing of each setting row
1365 * @param right Right-most position in window/panel to draw at
1366 * @param base_y Upper-most position in window/panel to start drawing of row number \a first_row
1367 * @param first_row Number of first row to draw
1368 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1369 * @param cur_row Current row number (internal variable)
1370 * @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)
1371 * @param selected Selected entry by the user.
1372 * @return Row number of the next row to draw
1374 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
1376 if (cur_row
>= max_row
) return cur_row
;
1378 for (uint i
= 0; i
< this->num
; i
++) {
1379 cur_row
= this->entries
[i
].Draw(settings_ptr
, left
, right
, base_y
, first_row
, max_row
, cur_row
, parent_last
, selected
);
1380 if (cur_row
>= max_row
) {
1388 static SettingEntry _settings_ui_localisation
[] = {
1389 SettingEntry("locale.units_velocity"),
1390 SettingEntry("locale.units_power"),
1391 SettingEntry("locale.units_weight"),
1392 SettingEntry("locale.units_volume"),
1393 SettingEntry("locale.units_force"),
1394 SettingEntry("locale.units_height"),
1396 /** Localisation options sub-page */
1397 static SettingsPage _settings_ui_localisation_page
= {_settings_ui_localisation
, lengthof(_settings_ui_localisation
)};
1399 static SettingEntry _settings_ui_display
[] = {
1400 SettingEntry("gui.date_format_in_default_names"),
1401 SettingEntry("gui.population_in_label"),
1402 SettingEntry("gui.measure_tooltip"),
1403 SettingEntry("gui.loading_indicators"),
1404 SettingEntry("gui.liveries"),
1405 SettingEntry("gui.show_track_reservation"),
1406 SettingEntry("gui.expenses_layout"),
1407 SettingEntry("gui.smallmap_land_colour"),
1408 SettingEntry("gui.zoom_min"),
1409 SettingEntry("gui.zoom_max"),
1410 SettingEntry("gui.graph_line_thickness"),
1412 /** Display options sub-page */
1413 static SettingsPage _settings_ui_display_page
= {_settings_ui_display
, lengthof(_settings_ui_display
)};
1415 static SettingEntry _settings_ui_interaction
[] = {
1416 SettingEntry("gui.window_snap_radius"),
1417 SettingEntry("gui.window_soft_limit"),
1418 SettingEntry("gui.link_terraform_toolbar"),
1419 SettingEntry("gui.prefer_teamchat"),
1420 SettingEntry("gui.auto_scrolling"),
1421 SettingEntry("gui.reverse_scroll"),
1422 SettingEntry("gui.smooth_scroll"),
1423 SettingEntry("gui.left_mouse_btn_scrolling"),
1424 /* While the horizontal scrollwheel scrolling is written as general code, only
1425 * the cocoa (OSX) driver generates input for it.
1426 * Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
1427 SettingEntry("gui.scrollwheel_scrolling"),
1428 SettingEntry("gui.scrollwheel_multiplier"),
1429 SettingEntry("gui.osk_activation"),
1431 /* We might need to emulate a right mouse button on mac */
1432 SettingEntry("gui.right_mouse_btn_emulation"),
1435 /** Interaction sub-page */
1436 static SettingsPage _settings_ui_interaction_page
= {_settings_ui_interaction
, lengthof(_settings_ui_interaction
)};
1438 static SettingEntry _settings_ui_sound
[] = {
1439 SettingEntry("sound.click_beep"),
1440 SettingEntry("sound.confirm"),
1441 SettingEntry("sound.news_ticker"),
1442 SettingEntry("sound.news_full"),
1443 SettingEntry("sound.new_year"),
1444 SettingEntry("sound.disaster"),
1445 SettingEntry("sound.vehicle"),
1446 SettingEntry("sound.ambient"),
1448 /** Sound effects sub-page */
1449 static SettingsPage _settings_ui_sound_page
= {_settings_ui_sound
, lengthof(_settings_ui_sound
)};
1451 static SettingEntry _settings_ui_news
[] = {
1452 SettingEntry("news_display.arrival_player"),
1453 SettingEntry("news_display.arrival_other"),
1454 SettingEntry("news_display.accident"),
1455 SettingEntry("news_display.company_info"),
1456 SettingEntry("news_display.open"),
1457 SettingEntry("news_display.close"),
1458 SettingEntry("news_display.economy"),
1459 SettingEntry("news_display.production_player"),
1460 SettingEntry("news_display.production_other"),
1461 SettingEntry("news_display.production_nobody"),
1462 SettingEntry("news_display.advice"),
1463 SettingEntry("news_display.new_vehicles"),
1464 SettingEntry("news_display.acceptance"),
1465 SettingEntry("news_display.subsidies"),
1466 SettingEntry("news_display.general"),
1467 SettingEntry("gui.coloured_news_year"),
1469 /** News sub-page */
1470 static SettingsPage _settings_ui_news_page
= {_settings_ui_news
, lengthof(_settings_ui_news
)};
1472 static SettingEntry _settings_ui
[] = {
1473 SettingEntry(&_settings_ui_localisation_page
, STR_CONFIG_SETTING_LOCALISATION
),
1474 SettingEntry(&_settings_ui_display_page
, STR_CONFIG_SETTING_DISPLAY_OPTIONS
),
1475 SettingEntry(&_settings_ui_interaction_page
, STR_CONFIG_SETTING_INTERACTION
),
1476 SettingEntry(&_settings_ui_sound_page
, STR_CONFIG_SETTING_SOUND
),
1477 SettingEntry(&_settings_ui_news_page
, STR_CONFIG_SETTING_NEWS
),
1478 SettingEntry("gui.show_finances"),
1479 SettingEntry("gui.errmsg_duration"),
1480 SettingEntry("gui.hover_delay"),
1481 SettingEntry("gui.toolbar_pos"),
1482 SettingEntry("gui.statusbar_pos"),
1483 SettingEntry("gui.newgrf_default_palette"),
1484 SettingEntry("gui.pause_on_newgame"),
1485 SettingEntry("gui.advanced_vehicle_list"),
1486 SettingEntry("gui.timetable_in_ticks"),
1487 SettingEntry("gui.timetable_arrival_departure"),
1488 SettingEntry("gui.quick_goto"),
1489 SettingEntry("gui.default_rail_type"),
1490 SettingEntry("gui.disable_unsuitable_building"),
1491 SettingEntry("gui.persistent_buildingtools"),
1493 /** Interface subpage */
1494 static SettingsPage _settings_ui_page
= {_settings_ui
, lengthof(_settings_ui
)};
1496 static SettingEntry _settings_construction_signals
[] = {
1497 SettingEntry("construction.train_signal_side"),
1498 SettingEntry("gui.enable_signal_gui"),
1499 SettingEntry("gui.drag_signals_fixed_distance"),
1500 SettingEntry("gui.semaphore_build_before"),
1501 SettingEntry("gui.default_signal_type"),
1502 SettingEntry("gui.cycle_signal_types"),
1504 /** Signals subpage */
1505 static SettingsPage _settings_construction_signals_page
= {_settings_construction_signals
, lengthof(_settings_construction_signals
)};
1507 static SettingEntry _settings_construction
[] = {
1508 SettingEntry(&_settings_construction_signals_page
, STR_CONFIG_SETTING_CONSTRUCTION_SIGNALS
),
1509 SettingEntry("construction.build_on_slopes"),
1510 SettingEntry("construction.autoslope"),
1511 SettingEntry("construction.extra_dynamite"),
1512 SettingEntry("construction.max_bridge_length"),
1513 SettingEntry("construction.max_tunnel_length"),
1514 SettingEntry("station.never_expire_airports"),
1515 SettingEntry("construction.freeform_edges"),
1516 SettingEntry("construction.extra_tree_placement"),
1517 SettingEntry("construction.command_pause_level"),
1519 /** Construction sub-page */
1520 static SettingsPage _settings_construction_page
= {_settings_construction
, lengthof(_settings_construction
)};
1522 static SettingEntry _settings_stations_cargo
[] = {
1523 SettingEntry("order.improved_load"),
1524 SettingEntry("order.gradual_loading"),
1525 SettingEntry("order.selectgoods"),
1527 /** Cargo handling sub-page */
1528 static SettingsPage _settings_stations_cargo_page
= {_settings_stations_cargo
, lengthof(_settings_stations_cargo
)};
1530 static SettingEntry _settings_stations
[] = {
1531 SettingEntry(&_settings_stations_cargo_page
, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING
),
1532 SettingEntry("station.adjacent_stations"),
1533 SettingEntry("station.distant_join_stations"),
1534 SettingEntry("station.station_spread"),
1535 SettingEntry("economy.station_noise_level"),
1536 SettingEntry("station.modified_catchment"),
1537 SettingEntry("construction.road_stop_on_town_road"),
1538 SettingEntry("construction.road_stop_on_competitor_road"),
1540 /** Stations sub-page */
1541 static SettingsPage _settings_stations_page
= {_settings_stations
, lengthof(_settings_stations
)};
1543 static SettingEntry _settings_economy_towns
[] = {
1544 SettingEntry("difficulty.town_council_tolerance"),
1545 SettingEntry("economy.bribe"),
1546 SettingEntry("economy.exclusive_rights"),
1547 SettingEntry("economy.fund_roads"),
1548 SettingEntry("economy.fund_buildings"),
1549 SettingEntry("economy.town_layout"),
1550 SettingEntry("economy.allow_town_roads"),
1551 SettingEntry("economy.allow_town_level_crossings"),
1552 SettingEntry("economy.found_town"),
1553 SettingEntry("economy.mod_road_rebuild"),
1554 SettingEntry("economy.town_growth_rate"),
1555 SettingEntry("economy.larger_towns"),
1556 SettingEntry("economy.initial_city_size"),
1558 /** Towns sub-page */
1559 static SettingsPage _settings_economy_towns_page
= {_settings_economy_towns
, lengthof(_settings_economy_towns
)};
1561 static SettingEntry _settings_economy_industries
[] = {
1562 SettingEntry("construction.raw_industry_construction"),
1563 SettingEntry("construction.industry_platform"),
1564 SettingEntry("economy.multiple_industry_per_town"),
1565 SettingEntry("game_creation.oil_refinery_limit"),
1567 /** Industries sub-page */
1568 static SettingsPage _settings_economy_industries_page
= {_settings_economy_industries
, lengthof(_settings_economy_industries
)};
1571 static SettingEntry _settings_economy
[] = {
1572 SettingEntry(&_settings_economy_towns_page
, STR_CONFIG_SETTING_ECONOMY_TOWNS
),
1573 SettingEntry(&_settings_economy_industries_page
, STR_CONFIG_SETTING_ECONOMY_INDUSTRIES
),
1574 SettingEntry("economy.inflation"),
1575 SettingEntry("difficulty.initial_interest"),
1576 SettingEntry("difficulty.max_loan"),
1577 SettingEntry("difficulty.subsidy_multiplier"),
1578 SettingEntry("difficulty.economy"),
1579 SettingEntry("economy.smooth_economy"),
1580 SettingEntry("economy.feeder_payment_share"),
1581 SettingEntry("economy.infrastructure_maintenance"),
1582 SettingEntry("difficulty.vehicle_costs"),
1583 SettingEntry("difficulty.construction_cost"),
1584 SettingEntry("difficulty.disasters"),
1586 /** Economy sub-page */
1587 static SettingsPage _settings_economy_page
= {_settings_economy
, lengthof(_settings_economy
)};
1589 static SettingEntry _settings_linkgraph
[] = {
1590 SettingEntry("linkgraph.recalc_time"),
1591 SettingEntry("linkgraph.recalc_interval"),
1592 SettingEntry("linkgraph.distribution_pax"),
1593 SettingEntry("linkgraph.distribution_mail"),
1594 SettingEntry("linkgraph.distribution_armoured"),
1595 SettingEntry("linkgraph.distribution_default"),
1596 SettingEntry("linkgraph.accuracy"),
1597 SettingEntry("linkgraph.demand_distance"),
1598 SettingEntry("linkgraph.demand_size"),
1599 SettingEntry("linkgraph.short_path_saturation"),
1601 /** Linkgraph sub-page */
1602 static SettingsPage _settings_linkgraph_page
= {_settings_linkgraph
, lengthof(_settings_linkgraph
)};
1604 static SettingEntry _settings_ai_npc
[] = {
1605 SettingEntry("script.settings_profile"),
1606 SettingEntry("script.script_max_opcode_till_suspend"),
1607 SettingEntry("difficulty.competitor_speed"),
1608 SettingEntry("ai.ai_in_multiplayer"),
1609 SettingEntry("ai.ai_disable_veh_train"),
1610 SettingEntry("ai.ai_disable_veh_roadveh"),
1611 SettingEntry("ai.ai_disable_veh_aircraft"),
1612 SettingEntry("ai.ai_disable_veh_ship"),
1614 /** Computer players sub-page */
1615 static SettingsPage _settings_ai_npc_page
= {_settings_ai_npc
, lengthof(_settings_ai_npc
)};
1617 static SettingEntry _settings_ai
[] = {
1618 SettingEntry(&_settings_ai_npc_page
, STR_CONFIG_SETTING_AI_NPC
),
1619 SettingEntry("economy.give_money"),
1620 SettingEntry("economy.allow_shares"),
1623 static SettingsPage _settings_ai_page
= {_settings_ai
, lengthof(_settings_ai
)};
1625 static SettingEntry _settings_vehicles_routing
[] = {
1626 SettingEntry("pf.pathfinder_for_trains"),
1627 SettingEntry("pf.forbid_90_deg"),
1628 SettingEntry("pf.pathfinder_for_roadvehs"),
1629 SettingEntry("pf.roadveh_queue"),
1630 SettingEntry("pf.pathfinder_for_ships"),
1632 /** Autorenew sub-page */
1633 static SettingsPage _settings_vehicles_routing_page
= {_settings_vehicles_routing
, lengthof(_settings_vehicles_routing
)};
1635 static SettingEntry _settings_vehicles_autorenew
[] = {
1636 SettingEntry("company.engine_renew"),
1637 SettingEntry("company.engine_renew_months"),
1638 SettingEntry("company.engine_renew_money"),
1640 /** Autorenew sub-page */
1641 static SettingsPage _settings_vehicles_autorenew_page
= {_settings_vehicles_autorenew
, lengthof(_settings_vehicles_autorenew
)};
1643 static SettingEntry _settings_vehicles_servicing
[] = {
1644 SettingEntry("vehicle.servint_ispercent"),
1645 SettingEntry("vehicle.servint_trains"),
1646 SettingEntry("vehicle.servint_roadveh"),
1647 SettingEntry("vehicle.servint_ships"),
1648 SettingEntry("vehicle.servint_aircraft"),
1649 SettingEntry("difficulty.vehicle_breakdowns"),
1650 SettingEntry("order.no_servicing_if_no_breakdowns"),
1651 SettingEntry("order.serviceathelipad"),
1653 /** Servicing sub-page */
1654 static SettingsPage _settings_vehicles_servicing_page
= {_settings_vehicles_servicing
, lengthof(_settings_vehicles_servicing
)};
1656 static SettingEntry _settings_vehicles_trains
[] = {
1657 SettingEntry("difficulty.line_reverse_mode"),
1658 SettingEntry("pf.reverse_at_signals"),
1659 SettingEntry("vehicle.train_acceleration_model"),
1660 SettingEntry("vehicle.train_slope_steepness"),
1661 SettingEntry("vehicle.max_train_length"),
1662 SettingEntry("vehicle.wagon_speed_limits"),
1663 SettingEntry("vehicle.disable_elrails"),
1664 SettingEntry("vehicle.freight_trains"),
1665 SettingEntry("gui.stop_location"),
1667 /** Trains sub-page */
1668 static SettingsPage _settings_vehicles_trains_page
= {_settings_vehicles_trains
, lengthof(_settings_vehicles_trains
)};
1670 static SettingEntry _settings_vehicles
[] = {
1671 SettingEntry(&_settings_vehicles_routing_page
, STR_CONFIG_SETTING_VEHICLES_ROUTING
),
1672 SettingEntry(&_settings_vehicles_autorenew_page
, STR_CONFIG_SETTING_VEHICLES_AUTORENEW
),
1673 SettingEntry(&_settings_vehicles_servicing_page
, STR_CONFIG_SETTING_VEHICLES_SERVICING
),
1674 SettingEntry(&_settings_vehicles_trains_page
, STR_CONFIG_SETTING_VEHICLES_TRAINS
),
1675 SettingEntry("gui.new_nonstop"),
1676 SettingEntry("gui.order_review_system"),
1677 SettingEntry("gui.vehicle_income_warn"),
1678 SettingEntry("gui.lost_vehicle_warn"),
1679 SettingEntry("vehicle.never_expire_vehicles"),
1680 SettingEntry("vehicle.max_trains"),
1681 SettingEntry("vehicle.max_roadveh"),
1682 SettingEntry("vehicle.max_aircraft"),
1683 SettingEntry("vehicle.max_ships"),
1684 SettingEntry("vehicle.plane_speed"),
1685 SettingEntry("vehicle.plane_crashes"),
1686 SettingEntry("vehicle.dynamic_engines"),
1687 SettingEntry("vehicle.roadveh_acceleration_model"),
1688 SettingEntry("vehicle.roadveh_slope_steepness"),
1689 SettingEntry("vehicle.smoke_amount"),
1691 /** Vehicles sub-page */
1692 static SettingsPage _settings_vehicles_page
= {_settings_vehicles
, lengthof(_settings_vehicles
)};
1694 static SettingEntry _settings_main
[] = {
1695 SettingEntry(&_settings_ui_page
, STR_CONFIG_SETTING_GUI
),
1696 SettingEntry(&_settings_construction_page
, STR_CONFIG_SETTING_CONSTRUCTION
),
1697 SettingEntry(&_settings_vehicles_page
, STR_CONFIG_SETTING_VEHICLES
),
1698 SettingEntry(&_settings_stations_page
, STR_CONFIG_SETTING_STATIONS
),
1699 SettingEntry(&_settings_economy_page
, STR_CONFIG_SETTING_ECONOMY
),
1700 SettingEntry(&_settings_linkgraph_page
, STR_CONFIG_SETTING_LINKGRAPH
),
1701 SettingEntry(&_settings_ai_page
, STR_CONFIG_SETTING_AI
),
1704 /** Main page, holding all advanced settings */
1705 static SettingsPage _settings_main_page
= {_settings_main
, lengthof(_settings_main
)};
1707 static const StringID _game_settings_restrict_dropdown
[] = {
1708 STR_CONFIG_SETTING_RESTRICT_BASIC
, // RM_BASIC
1709 STR_CONFIG_SETTING_RESTRICT_ADVANCED
, // RM_ADVANCED
1710 STR_CONFIG_SETTING_RESTRICT_ALL
, // RM_ALL
1711 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT
, // RM_CHANGED_AGAINST_DEFAULT
1712 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW
, // RM_CHANGED_AGAINST_NEW
1714 assert_compile(lengthof(_game_settings_restrict_dropdown
) == RM_END
);
1716 struct GameSettingsWindow
: Window
{
1717 static const int SETTINGTREE_LEFT_OFFSET
= 5; ///< Position of left edge of setting values
1718 static const int SETTINGTREE_RIGHT_OFFSET
= 5; ///< Position of right edge of setting values
1719 static const int SETTINGTREE_TOP_OFFSET
= 5; ///< Position of top edge of setting values
1720 static const int SETTINGTREE_BOTTOM_OFFSET
= 5; ///< Position of bottom edge of setting values
1722 static GameSettings
*settings_ptr
; ///< Pointer to the game settings being displayed and modified.
1724 SettingEntry
*valuewindow_entry
; ///< If non-NULL, pointer to setting for which a value-entering window has been opened.
1725 SettingEntry
*clicked_entry
; ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button).
1726 SettingEntry
*last_clicked
; ///< If non-NULL, pointer to the last clicked setting.
1727 SettingEntry
*valuedropdown_entry
; ///< If non-NULL, pointer to the value for which a dropdown window is currently opened.
1728 bool closing_dropdown
; ///< True, if the dropdown list is currently closing.
1730 SettingFilter filter
; ///< Filter for the list.
1731 QueryString filter_editbox
; ///< Filter editbox;
1732 bool manually_changed_folding
; ///< Whether the user expanded/collapsed something manually.
1736 GameSettingsWindow(WindowDesc
*desc
) : Window(desc
), filter_editbox(50)
1738 static bool first_time
= true;
1740 filter
.mode
= (RestrictionMode
)_settings_client
.gui
.settings_restriction_mode
;
1741 filter
.type
= ST_ALL
;
1742 settings_ptr
= &GetGameSettings();
1744 /* Build up the dynamic settings-array only once per OpenTTD session */
1746 _settings_main_page
.Init();
1749 _settings_main_page
.FoldAll(); // Close all sub-pages
1752 this->valuewindow_entry
= NULL
; // No setting entry for which a entry window is opened
1753 this->clicked_entry
= NULL
; // No numeric setting buttons are depressed
1754 this->last_clicked
= NULL
;
1755 this->valuedropdown_entry
= NULL
;
1756 this->closing_dropdown
= false;
1757 this->manually_changed_folding
= false;
1759 this->CreateNestedTree();
1760 this->vscroll
= this->GetScrollbar(WID_GS_SCROLLBAR
);
1761 this->FinishInitNested(WN_GAME_OPTIONS_GAME_SETTINGS
);
1763 this->querystrings
[WID_GS_FILTER
] = &this->filter_editbox
;
1764 this->filter_editbox
.cancel_button
= QueryString::ACTION_CLEAR
;
1765 this->SetFocusedWidget(WID_GS_FILTER
);
1767 this->InvalidateData();
1770 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1773 case WID_GS_OPTIONSPANEL
:
1774 resize
->height
= SETTING_HEIGHT
= max(11, FONT_HEIGHT_NORMAL
+ 1);
1777 size
->height
= 5 * resize
->height
+ SETTINGTREE_TOP_OFFSET
+ SETTINGTREE_BOTTOM_OFFSET
;
1780 case WID_GS_HELP_TEXT
: {
1781 static const StringID setting_types
[] = {
1782 STR_CONFIG_SETTING_TYPE_CLIENT
,
1783 STR_CONFIG_SETTING_TYPE_COMPANY_MENU
, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME
,
1784 STR_CONFIG_SETTING_TYPE_GAME_MENU
, STR_CONFIG_SETTING_TYPE_GAME_INGAME
,
1786 for (uint i
= 0; i
< lengthof(setting_types
); i
++) {
1787 SetDParam(0, setting_types
[i
]);
1788 size
->width
= max(size
->width
, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE
).width
);
1790 size
->height
= 2 * FONT_HEIGHT_NORMAL
+ WD_PAR_VSEP_NORMAL
+
1791 max(size
->height
, _settings_main_page
.GetMaxHelpHeight(size
->width
));
1800 virtual void OnPaint()
1802 if (this->closing_dropdown
) {
1803 this->closing_dropdown
= false;
1804 assert(this->valuedropdown_entry
!= NULL
);
1805 this->valuedropdown_entry
->SetButtons(0);
1806 this->valuedropdown_entry
= NULL
;
1808 this->DrawWidgets();
1811 virtual void SetStringParameters(int widget
) const
1814 case WID_GS_RESTRICT_DROPDOWN
:
1815 SetDParam(0, _game_settings_restrict_dropdown
[this->filter
.mode
]);
1818 case WID_GS_TYPE_DROPDOWN
:
1819 switch (this->filter
.type
) {
1820 case ST_GAME
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU
: STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME
); break;
1821 case ST_COMPANY
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU
: STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME
); break;
1822 case ST_CLIENT
: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT
); break;
1823 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL
); break;
1829 DropDownList
*BuildDropDownList(int widget
) const
1831 DropDownList
*list
= NULL
;
1833 case WID_GS_RESTRICT_DROPDOWN
:
1834 list
= new DropDownList();
1836 for (int mode
= 0; mode
!= RM_END
; mode
++) {
1837 /* If we are in adv. settings screen for the new game's settings,
1838 * we don't want to allow comparing with new game's settings. */
1839 bool disabled
= mode
== RM_CHANGED_AGAINST_NEW
&& settings_ptr
== &_settings_newgame
;
1841 *list
->Append() = new DropDownListStringItem(_game_settings_restrict_dropdown
[mode
], mode
, disabled
);
1845 case WID_GS_TYPE_DROPDOWN
:
1846 list
= new DropDownList();
1847 *list
->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL
, ST_ALL
, false);
1848 *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);
1849 *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);
1850 *list
->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT
, ST_CLIENT
, false);
1856 virtual void DrawWidget(const Rect
&r
, int widget
) const
1859 case WID_GS_OPTIONSPANEL
:
1860 _settings_main_page
.Draw(settings_ptr
, r
.left
+ SETTINGTREE_LEFT_OFFSET
, r
.right
- SETTINGTREE_RIGHT_OFFSET
, r
.top
+ SETTINGTREE_TOP_OFFSET
,
1861 this->vscroll
->GetPosition(), this->vscroll
->GetPosition() + this->vscroll
->GetCapacity(), this->last_clicked
);
1864 case WID_GS_HELP_TEXT
:
1865 if (this->last_clicked
!= NULL
) {
1866 const SettingDesc
*sd
= this->last_clicked
->d
.entry
.setting
;
1869 switch (sd
->GetType()) {
1870 case ST_COMPANY
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_COMPANY_MENU
: STR_CONFIG_SETTING_TYPE_COMPANY_INGAME
); break;
1871 case ST_CLIENT
: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT
); break;
1872 case ST_GAME
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_GAME_MENU
: STR_CONFIG_SETTING_TYPE_GAME_INGAME
); break;
1873 default: NOT_REACHED();
1875 DrawString(r
.left
, r
.right
, y
, STR_CONFIG_SETTING_TYPE
);
1876 y
+= FONT_HEIGHT_NORMAL
;
1878 int32 default_value
= ReadValue(&sd
->desc
.def
, sd
->save
.conv
);
1879 this->last_clicked
->SetValueDParams(0, default_value
);
1880 DrawString(r
.left
, r
.right
, y
, STR_CONFIG_SETTING_DEFAULT_VALUE
);
1881 y
+= FONT_HEIGHT_NORMAL
+ WD_PAR_VSEP_NORMAL
;
1883 DrawStringMultiLine(r
.left
, r
.right
, y
, r
.bottom
, this->last_clicked
->GetHelpText(), TC_WHITE
);
1893 * Set the entry that should have its help text displayed, and mark the window dirty so it gets repainted.
1894 * @param pe Setting to display help text of, use \c NULL to stop displaying help of the currently displayed setting.
1896 void SetDisplayedHelpText(SettingEntry
*pe
)
1898 if (this->last_clicked
!= pe
) this->SetDirty();
1899 this->last_clicked
= pe
;
1902 virtual void OnClick(Point pt
, int widget
, int click_count
)
1905 case WID_GS_EXPAND_ALL
:
1906 this->manually_changed_folding
= true;
1907 _settings_main_page
.UnFoldAll();
1908 this->InvalidateData();
1911 case WID_GS_COLLAPSE_ALL
:
1912 this->manually_changed_folding
= true;
1913 _settings_main_page
.FoldAll();
1914 this->InvalidateData();
1917 case WID_GS_RESTRICT_DROPDOWN
: {
1918 DropDownList
*list
= this->BuildDropDownList(widget
);
1920 ShowDropDownList(this, list
, this->filter
.mode
, widget
);
1925 case WID_GS_TYPE_DROPDOWN
: {
1926 DropDownList
*list
= this->BuildDropDownList(widget
);
1928 ShowDropDownList(this, list
, this->filter
.type
, widget
);
1934 if (widget
!= WID_GS_OPTIONSPANEL
) return;
1936 uint btn
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_GS_OPTIONSPANEL
, SETTINGTREE_TOP_OFFSET
);
1937 if (btn
== INT_MAX
) return;
1940 SettingEntry
*pe
= _settings_main_page
.FindEntry(btn
, &cur_row
);
1942 if (pe
== NULL
) return; // Clicked below the last setting of the page
1944 int x
= (_current_text_dir
== TD_RTL
? this->width
- 1 - pt
.x
: pt
.x
) - SETTINGTREE_LEFT_OFFSET
- (pe
->level
+ 1) * LEVEL_WIDTH
; // Shift x coordinate
1945 if (x
< 0) return; // Clicked left of the entry
1947 if ((pe
->flags
& SEF_KIND_MASK
) == SEF_SUBTREE_KIND
) {
1948 this->SetDisplayedHelpText(NULL
);
1949 pe
->d
.sub
.folded
= !pe
->d
.sub
.folded
; // Flip 'folded'-ness of the sub-page
1951 this->manually_changed_folding
= true;
1953 this->InvalidateData();
1957 assert((pe
->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
1958 const SettingDesc
*sd
= pe
->d
.entry
.setting
;
1960 /* return if action is only active in network, or only settable by server */
1961 if (!sd
->IsEditable()) {
1962 this->SetDisplayedHelpText(pe
);
1966 const void *var
= ResolveVariableAddress(settings_ptr
, sd
);
1967 int32 value
= (int32
)ReadValue(var
, sd
->save
.conv
);
1969 /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
1970 if (x
< SETTING_BUTTON_WIDTH
&& (sd
->desc
.flags
& SGF_MULTISTRING
)) {
1971 const SettingDescBase
*sdb
= &sd
->desc
;
1972 this->SetDisplayedHelpText(pe
);
1974 if (this->valuedropdown_entry
== pe
) {
1975 /* unclick the dropdown */
1976 HideDropDownMenu(this);
1977 this->closing_dropdown
= false;
1978 this->valuedropdown_entry
->SetButtons(0);
1979 this->valuedropdown_entry
= NULL
;
1981 if (this->valuedropdown_entry
!= NULL
) this->valuedropdown_entry
->SetButtons(0);
1982 this->closing_dropdown
= false;
1984 const NWidgetBase
*wid
= this->GetWidget
<NWidgetBase
>(WID_GS_OPTIONSPANEL
);
1985 int rel_y
= (pt
.y
- (int)wid
->pos_y
- SETTINGTREE_TOP_OFFSET
) % wid
->resize_y
;
1988 wi_rect
.left
= pt
.x
- (_current_text_dir
== TD_RTL
? SETTING_BUTTON_WIDTH
- 1 - x
: x
);
1989 wi_rect
.right
= wi_rect
.left
+ SETTING_BUTTON_WIDTH
- 1;
1990 wi_rect
.top
= pt
.y
- rel_y
+ (SETTING_HEIGHT
- SETTING_BUTTON_HEIGHT
) / 2;
1991 wi_rect
.bottom
= wi_rect
.top
+ SETTING_BUTTON_HEIGHT
- 1;
1993 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
1994 if (pt
.y
>= wi_rect
.top
&& pt
.y
<= wi_rect
.bottom
) {
1995 this->valuedropdown_entry
= pe
;
1996 this->valuedropdown_entry
->SetButtons(SEF_LEFT_DEPRESSED
);
1998 DropDownList
*list
= new DropDownList();
1999 for (int i
= sdb
->min
; i
<= (int)sdb
->max
; i
++) {
2000 *list
->Append() = new DropDownListStringItem(sdb
->str_val
+ i
- sdb
->min
, i
, false);
2003 ShowDropDownListAt(this, list
, value
, -1, wi_rect
, COLOUR_ORANGE
, true);
2007 } else if (x
< SETTING_BUTTON_WIDTH
) {
2008 this->SetDisplayedHelpText(pe
);
2009 const SettingDescBase
*sdb
= &sd
->desc
;
2010 int32 oldvalue
= value
;
2013 case SDT_BOOLX
: value
^= 1; break;
2016 /* Add a dynamic step-size to the scroller. In a maximum of
2017 * 50-steps you should be able to get from min to max,
2018 * unless specified otherwise in the 'interval' variable
2019 * of the current setting. */
2020 uint32 step
= (sdb
->interval
== 0) ? ((sdb
->max
- sdb
->min
) / 50) : sdb
->interval
;
2021 if (step
== 0) step
= 1;
2023 /* don't allow too fast scrolling */
2024 if ((this->flags
& WF_TIMEOUT
) && this->timeout_timer
> 1) {
2025 _left_button_clicked
= false;
2029 /* Increase or decrease the value and clamp it to extremes */
2030 if (x
>= SETTING_BUTTON_WIDTH
/ 2) {
2033 assert((int32
)sdb
->max
>= 0);
2034 if (value
> (int32
)sdb
->max
) value
= (int32
)sdb
->max
;
2036 if ((uint32
)value
> sdb
->max
) value
= (int32
)sdb
->max
;
2038 if (value
< sdb
->min
) value
= sdb
->min
; // skip between "disabled" and minimum
2041 if (value
< sdb
->min
) value
= (sdb
->flags
& SGF_0ISDISABLED
) ? 0 : sdb
->min
;
2044 /* Set up scroller timeout for numeric values */
2045 if (value
!= oldvalue
) {
2046 if (this->clicked_entry
!= NULL
) { // Release previous buttons if any
2047 this->clicked_entry
->SetButtons(0);
2049 this->clicked_entry
= pe
;
2050 this->clicked_entry
->SetButtons((x
>= SETTING_BUTTON_WIDTH
/ 2) != (_current_text_dir
== TD_RTL
) ? SEF_RIGHT_DEPRESSED
: SEF_LEFT_DEPRESSED
);
2052 _left_button_clicked
= false;
2057 default: NOT_REACHED();
2060 if (value
!= oldvalue
) {
2061 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2062 SetCompanySetting(pe
->d
.entry
.index
, value
);
2064 SetSettingValue(pe
->d
.entry
.index
, value
);
2069 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
2070 if (this->last_clicked
== pe
&& sd
->desc
.cmd
!= SDT_BOOLX
&& !(sd
->desc
.flags
& SGF_MULTISTRING
)) {
2071 /* Show the correct currency-translated value */
2072 if (sd
->desc
.flags
& SGF_CURRENCY
) value
*= _currency
->rate
;
2074 this->valuewindow_entry
= pe
;
2075 SetDParam(0, value
);
2076 ShowQueryString(STR_JUST_INT
, STR_CONFIG_SETTING_QUERY_CAPTION
, 10, this, CS_NUMERAL
, QSF_ENABLE_DEFAULT
);
2078 this->SetDisplayedHelpText(pe
);
2082 virtual void OnTimeout()
2084 if (this->clicked_entry
!= NULL
) { // On timeout, release any depressed buttons
2085 this->clicked_entry
->SetButtons(0);
2086 this->clicked_entry
= NULL
;
2091 virtual void OnQueryTextFinished(char *str
)
2093 /* The user pressed cancel */
2094 if (str
== NULL
) return;
2096 assert(this->valuewindow_entry
!= NULL
);
2097 assert((this->valuewindow_entry
->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
2098 const SettingDesc
*sd
= this->valuewindow_entry
->d
.entry
.setting
;
2101 if (!StrEmpty(str
)) {
2104 /* Save the correct currency-translated value */
2105 if (sd
->desc
.flags
& SGF_CURRENCY
) value
/= _currency
->rate
;
2107 value
= (int32
)(size_t)sd
->desc
.def
;
2110 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2111 SetCompanySetting(this->valuewindow_entry
->d
.entry
.index
, value
);
2113 SetSettingValue(this->valuewindow_entry
->d
.entry
.index
, value
);
2118 virtual void OnDropdownSelect(int widget
, int index
)
2121 case WID_GS_RESTRICT_DROPDOWN
:
2122 this->filter
.mode
= (RestrictionMode
)index
;
2123 if (this->filter
.mode
== RM_CHANGED_AGAINST_DEFAULT
||
2124 this->filter
.mode
== RM_CHANGED_AGAINST_NEW
) {
2126 if (!this->manually_changed_folding
) {
2127 /* Expand all when selecting 'changes'. Update the filter state first, in case it becomes less restrictive in some cases. */
2128 _settings_main_page
.UpdateFilterState(this->filter
, false);
2129 _settings_main_page
.UnFoldAll();
2132 /* Non-'changes' filter. Save as default. */
2133 _settings_client
.gui
.settings_restriction_mode
= this->filter
.mode
;
2135 this->InvalidateData();
2138 case WID_GS_TYPE_DROPDOWN
:
2139 this->filter
.type
= (SettingType
)index
;
2140 this->InvalidateData();
2145 /* Deal with drop down boxes on the panel. */
2146 assert(this->valuedropdown_entry
!= NULL
);
2147 const SettingDesc
*sd
= this->valuedropdown_entry
->d
.entry
.setting
;
2148 assert(sd
->desc
.flags
& SGF_MULTISTRING
);
2150 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2151 SetCompanySetting(this->valuedropdown_entry
->d
.entry
.index
, index
);
2153 SetSettingValue(this->valuedropdown_entry
->d
.entry
.index
, index
);
2162 virtual void OnDropdownClose(Point pt
, int widget
, int index
, bool instant_close
)
2165 /* Normally the default implementation of OnDropdownClose() takes care of
2166 * a few things. We want that behaviour here too, but only for
2167 * "normal" dropdown boxes. The special dropdown boxes added for every
2168 * setting that needs one can't have this call. */
2169 Window::OnDropdownClose(pt
, widget
, index
, instant_close
);
2171 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
2172 * the same dropdown button was clicked again, and then not open the dropdown again.
2173 * So, we only remember that it was closed, and process it on the next OnPaint, which is
2175 assert(this->valuedropdown_entry
!= NULL
);
2176 this->closing_dropdown
= true;
2181 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
2183 if (!gui_scope
) return;
2185 _settings_main_page
.UpdateFilterState(this->filter
, false);
2187 this->vscroll
->SetCount(_settings_main_page
.Length());
2189 if (this->last_clicked
!= NULL
&& !_settings_main_page
.IsVisible(this->last_clicked
)) {
2190 this->SetDisplayedHelpText(NULL
);
2193 bool all_folded
= true;
2194 bool all_unfolded
= true;
2195 _settings_main_page
.GetFoldingState(all_folded
, all_unfolded
);
2196 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL
, all_unfolded
);
2197 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL
, all_folded
);
2200 virtual void OnEditboxChanged(int wid
)
2202 if (wid
== WID_GS_FILTER
) {
2203 this->filter
.string
.SetFilterTerm(this->filter_editbox
.text
.buf
);
2204 if (!this->filter
.string
.IsEmpty() && !this->manually_changed_folding
) {
2205 /* User never expanded/collapsed single pages and entered a filter term.
2206 * Expand everything, to save weird expand clicks, */
2207 _settings_main_page
.UnFoldAll();
2209 this->InvalidateData();
2213 virtual void OnResize()
2215 this->vscroll
->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL
, SETTINGTREE_TOP_OFFSET
+ SETTINGTREE_BOTTOM_OFFSET
);
2219 GameSettings
*GameSettingsWindow::settings_ptr
= NULL
;
2221 static const NWidgetPart _nested_settings_selection_widgets
[] = {
2222 NWidget(NWID_HORIZONTAL
),
2223 NWidget(WWT_CLOSEBOX
, COLOUR_MAUVE
),
2224 NWidget(WWT_CAPTION
, COLOUR_MAUVE
), SetDataTip(STR_CONFIG_SETTING_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2225 NWidget(WWT_DEFSIZEBOX
, COLOUR_MAUVE
),
2227 NWidget(WWT_PANEL
, COLOUR_MAUVE
),
2228 NWidget(NWID_HORIZONTAL
), SetPadding(WD_TEXTPANEL_TOP
, 0, WD_TEXTPANEL_BOTTOM
, 0),
2229 SetPIP(WD_FRAMETEXT_LEFT
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_RIGHT
),
2230 NWidget(WWT_TEXT
, COLOUR_MAUVE
, WID_GS_RESTRICT_LABEL
), SetDataTip(STR_CONFIG_SETTING_RESTRICT_LABEL
, STR_NULL
),
2231 NWidget(NWID_VERTICAL
), SetPIP(0, WD_PAR_VSEP_NORMAL
, 0),
2232 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),
2233 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),
2236 NWidget(NWID_HORIZONTAL
), SetPadding(0, 0, WD_TEXTPANEL_BOTTOM
, 0),
2237 SetPIP(WD_FRAMETEXT_LEFT
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_RIGHT
),
2238 NWidget(WWT_TEXT
, COLOUR_MAUVE
), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE
, STR_NULL
),
2239 NWidget(WWT_EDITBOX
, COLOUR_MAUVE
, WID_GS_FILTER
), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
2240 SetDataTip(STR_LIST_FILTER_OSKTITLE
, STR_LIST_FILTER_TOOLTIP
),
2243 NWidget(NWID_HORIZONTAL
),
2244 NWidget(WWT_PANEL
, COLOUR_MAUVE
, WID_GS_OPTIONSPANEL
), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR
), EndContainer(),
2245 NWidget(NWID_VERTICAL
),
2246 NWidget(NWID_VSCROLLBAR
, COLOUR_MAUVE
, WID_GS_SCROLLBAR
),
2249 NWidget(WWT_PANEL
, COLOUR_MAUVE
), SetMinimalSize(400, 40),
2250 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_GS_HELP_TEXT
), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
2251 SetPadding(WD_FRAMETEXT_TOP
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_BOTTOM
, WD_FRAMETEXT_LEFT
),
2252 NWidget(NWID_HORIZONTAL
),
2253 NWidget(WWT_PANEL
, COLOUR_MAUVE
),
2254 NWidget(NWID_HORIZONTAL
),
2255 NWidget(WWT_PUSHTXTBTN
, COLOUR_MAUVE
, WID_GS_EXPAND_ALL
), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL
, STR_NULL
),
2256 NWidget(WWT_PUSHTXTBTN
, COLOUR_MAUVE
, WID_GS_COLLAPSE_ALL
), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL
, STR_NULL
),
2257 NWidget(NWID_SPACER
, INVALID_COLOUR
), SetFill(1, 1), SetResize(1, 0),
2260 NWidget(WWT_RESIZEBOX
, COLOUR_MAUVE
),
2265 static WindowDesc
_settings_selection_desc(
2266 WDP_CENTER
, "settings", 510, 450,
2267 WC_GAME_OPTIONS
, WC_NONE
,
2269 _nested_settings_selection_widgets
, lengthof(_nested_settings_selection_widgets
)
2272 /** Open advanced settings window. */
2273 void ShowGameSettings()
2275 DeleteWindowByClass(WC_GAME_OPTIONS
);
2276 new GameSettingsWindow(&_settings_selection_desc
);
2281 * Draw [<][>] boxes.
2282 * @param x the x position to draw
2283 * @param y the y position to draw
2284 * @param button_colour the colour of the button
2285 * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked
2286 * @param clickable_left is the left button clickable?
2287 * @param clickable_right is the right button clickable?
2289 void DrawArrowButtons(int x
, int y
, Colours button_colour
, byte state
, bool clickable_left
, bool clickable_right
)
2291 int colour
= _colour_gradient
[button_colour
][2];
2293 DrawFrameRect(x
, y
, x
+ SETTING_BUTTON_WIDTH
/ 2 - 1, y
+ SETTING_BUTTON_HEIGHT
- 1, button_colour
, (state
== 1) ? FR_LOWERED
: FR_NONE
);
2294 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
);
2295 DrawSprite(SPR_ARROW_LEFT
, PAL_NONE
, x
+ WD_IMGBTN_LEFT
, y
+ WD_IMGBTN_TOP
);
2296 DrawSprite(SPR_ARROW_RIGHT
, PAL_NONE
, x
+ WD_IMGBTN_LEFT
+ SETTING_BUTTON_WIDTH
/ 2, y
+ WD_IMGBTN_TOP
);
2298 /* Grey out the buttons that aren't clickable */
2299 bool rtl
= _current_text_dir
== TD_RTL
;
2300 if (rtl
? !clickable_right
: !clickable_left
) {
2301 GfxFillRect(x
+ 1, y
, x
+ SETTING_BUTTON_WIDTH
/ 2 - 1, y
+ SETTING_BUTTON_HEIGHT
- 2, colour
, FILLRECT_CHECKER
);
2303 if (rtl
? !clickable_left
: !clickable_right
) {
2304 GfxFillRect(x
+ SETTING_BUTTON_WIDTH
/ 2 + 1, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 2, colour
, FILLRECT_CHECKER
);
2309 * Draw a dropdown button.
2310 * @param x the x position to draw
2311 * @param y the y position to draw
2312 * @param button_colour the colour of the button
2313 * @param state true = lowered
2314 * @param clickable is the button clickable?
2316 void DrawDropDownButton(int x
, int y
, Colours button_colour
, bool state
, bool clickable
)
2318 static const char *DOWNARROW
= "\xEE\x8A\xAA";
2320 int colour
= _colour_gradient
[button_colour
][2];
2322 DrawFrameRect(x
, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 1, button_colour
, state
? FR_LOWERED
: FR_NONE
);
2323 DrawString(x
+ (state
? 1 : 0), x
+ SETTING_BUTTON_WIDTH
- (state
? 0 : 1), y
+ (state
? 2 : 1), DOWNARROW
, TC_BLACK
, SA_HOR_CENTER
);
2326 GfxFillRect(x
+ 1, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 2, colour
, FILLRECT_CHECKER
);
2331 * Draw a toggle button.
2332 * @param x the x position to draw
2333 * @param y the y position to draw
2334 * @param state true = lowered
2335 * @param clickable is the button clickable?
2337 void DrawBoolButton(int x
, int y
, bool state
, bool clickable
)
2339 static const Colours _bool_ctabs
[2][2] = {{COLOUR_CREAM
, COLOUR_RED
}, {COLOUR_DARK_GREEN
, COLOUR_GREEN
}};
2340 DrawFrameRect(x
, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 1, _bool_ctabs
[state
][clickable
], state
? FR_LOWERED
: FR_NONE
);
2343 struct CustomCurrencyWindow
: Window
{
2346 CustomCurrencyWindow(WindowDesc
*desc
) : Window(desc
)
2353 void SetButtonState()
2355 this->SetWidgetDisabledState(WID_CC_RATE_DOWN
, _custom_currency
.rate
== 1);
2356 this->SetWidgetDisabledState(WID_CC_RATE_UP
, _custom_currency
.rate
== UINT16_MAX
);
2357 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN
, _custom_currency
.to_euro
== CF_NOEURO
);
2358 this->SetWidgetDisabledState(WID_CC_YEAR_UP
, _custom_currency
.to_euro
== MAX_YEAR
);
2361 virtual void SetStringParameters(int widget
) const
2364 case WID_CC_RATE
: SetDParam(0, 1); SetDParam(1, 1); break;
2365 case WID_CC_SEPARATOR
: SetDParamStr(0, _custom_currency
.separator
); break;
2366 case WID_CC_PREFIX
: SetDParamStr(0, _custom_currency
.prefix
); break;
2367 case WID_CC_SUFFIX
: SetDParamStr(0, _custom_currency
.suffix
); break;
2369 SetDParam(0, (_custom_currency
.to_euro
!= CF_NOEURO
) ? STR_CURRENCY_SWITCH_TO_EURO
: STR_CURRENCY_SWITCH_TO_EURO_NEVER
);
2370 SetDParam(1, _custom_currency
.to_euro
);
2373 case WID_CC_PREVIEW
:
2374 SetDParam(0, 10000);
2379 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
2382 /* Set the appropriate width for the edit 'buttons' */
2383 case WID_CC_SEPARATOR_EDIT
:
2384 case WID_CC_PREFIX_EDIT
:
2385 case WID_CC_SUFFIX_EDIT
:
2386 size
->width
= this->GetWidget
<NWidgetBase
>(WID_CC_RATE_DOWN
)->smallest_x
+ this->GetWidget
<NWidgetBase
>(WID_CC_RATE_UP
)->smallest_x
;
2389 /* Make sure the window is wide enough for the widest exchange rate */
2392 SetDParam(1, INT32_MAX
);
2393 *size
= GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE
);
2398 virtual void OnClick(Point pt
, int widget
, int click_count
)
2403 CharSetFilter afilter
= CS_ALPHANUMERAL
;
2406 case WID_CC_RATE_DOWN
:
2407 if (_custom_currency
.rate
> 1) _custom_currency
.rate
--;
2408 if (_custom_currency
.rate
== 1) this->DisableWidget(WID_CC_RATE_DOWN
);
2409 this->EnableWidget(WID_CC_RATE_UP
);
2412 case WID_CC_RATE_UP
:
2413 if (_custom_currency
.rate
< UINT16_MAX
) _custom_currency
.rate
++;
2414 if (_custom_currency
.rate
== UINT16_MAX
) this->DisableWidget(WID_CC_RATE_UP
);
2415 this->EnableWidget(WID_CC_RATE_DOWN
);
2419 SetDParam(0, _custom_currency
.rate
);
2423 afilter
= CS_NUMERAL
;
2426 case WID_CC_SEPARATOR_EDIT
:
2427 case WID_CC_SEPARATOR
:
2428 SetDParamStr(0, _custom_currency
.separator
);
2429 str
= STR_JUST_RAW_STRING
;
2431 line
= WID_CC_SEPARATOR
;
2434 case WID_CC_PREFIX_EDIT
:
2436 SetDParamStr(0, _custom_currency
.prefix
);
2437 str
= STR_JUST_RAW_STRING
;
2439 line
= WID_CC_PREFIX
;
2442 case WID_CC_SUFFIX_EDIT
:
2444 SetDParamStr(0, _custom_currency
.suffix
);
2445 str
= STR_JUST_RAW_STRING
;
2447 line
= WID_CC_SUFFIX
;
2450 case WID_CC_YEAR_DOWN
:
2451 _custom_currency
.to_euro
= (_custom_currency
.to_euro
<= 2000) ? CF_NOEURO
: _custom_currency
.to_euro
- 1;
2452 if (_custom_currency
.to_euro
== CF_NOEURO
) this->DisableWidget(WID_CC_YEAR_DOWN
);
2453 this->EnableWidget(WID_CC_YEAR_UP
);
2456 case WID_CC_YEAR_UP
:
2457 _custom_currency
.to_euro
= Clamp(_custom_currency
.to_euro
+ 1, 2000, MAX_YEAR
);
2458 if (_custom_currency
.to_euro
== MAX_YEAR
) this->DisableWidget(WID_CC_YEAR_UP
);
2459 this->EnableWidget(WID_CC_YEAR_DOWN
);
2463 SetDParam(0, _custom_currency
.to_euro
);
2467 afilter
= CS_NUMERAL
;
2472 this->query_widget
= line
;
2473 ShowQueryString(str
, STR_CURRENCY_CHANGE_PARAMETER
, len
+ 1, this, afilter
, QSF_NONE
);
2480 virtual void OnQueryTextFinished(char *str
)
2482 if (str
== NULL
) return;
2484 switch (this->query_widget
) {
2486 _custom_currency
.rate
= Clamp(atoi(str
), 1, UINT16_MAX
);
2489 case WID_CC_SEPARATOR
: // Thousands separator
2490 strecpy(_custom_currency
.separator
, str
, lastof(_custom_currency
.separator
));
2494 strecpy(_custom_currency
.prefix
, str
, lastof(_custom_currency
.prefix
));
2498 strecpy(_custom_currency
.suffix
, str
, lastof(_custom_currency
.suffix
));
2501 case WID_CC_YEAR
: { // Year to switch to euro
2502 int val
= atoi(str
);
2504 _custom_currency
.to_euro
= (val
< 2000 ? CF_NOEURO
: min(val
, MAX_YEAR
));
2508 MarkWholeScreenDirty();
2512 virtual void OnTimeout()
2518 static const NWidgetPart _nested_cust_currency_widgets
[] = {
2519 NWidget(NWID_HORIZONTAL
),
2520 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
2521 NWidget(WWT_CAPTION
, COLOUR_GREY
), SetDataTip(STR_CURRENCY_WINDOW
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2523 NWidget(WWT_PANEL
, COLOUR_GREY
),
2524 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
), SetPIP(7, 3, 0),
2525 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2526 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_RATE_DOWN
), SetDataTip(AWV_DECREASE
, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP
),
2527 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_RATE_UP
), SetDataTip(AWV_INCREASE
, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP
),
2528 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2529 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_RATE
), SetDataTip(STR_CURRENCY_EXCHANGE_RATE
, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP
), SetFill(1, 0),
2531 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2532 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_SEPARATOR_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP
), SetFill(0, 1),
2533 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2534 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_SEPARATOR
), SetDataTip(STR_CURRENCY_SEPARATOR
, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP
), SetFill(1, 0),
2536 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2537 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_PREFIX_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP
), SetFill(0, 1),
2538 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2539 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_PREFIX
), SetDataTip(STR_CURRENCY_PREFIX
, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP
), SetFill(1, 0),
2541 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2542 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_SUFFIX_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP
), SetFill(0, 1),
2543 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2544 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_SUFFIX
), SetDataTip(STR_CURRENCY_SUFFIX
, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP
), SetFill(1, 0),
2546 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2547 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_YEAR_DOWN
), SetDataTip(AWV_DECREASE
, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
),
2548 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_YEAR_UP
), SetDataTip(AWV_INCREASE
, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
),
2549 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2550 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_YEAR
), SetDataTip(STR_JUST_STRING
, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
), SetFill(1, 0),
2553 NWidget(WWT_LABEL
, COLOUR_BLUE
, WID_CC_PREVIEW
),
2554 SetDataTip(STR_CURRENCY_PREVIEW
, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP
), SetPadding(15, 1, 18, 2),
2558 static WindowDesc
_cust_currency_desc(
2559 WDP_CENTER
, NULL
, 0, 0,
2560 WC_CUSTOM_CURRENCY
, WC_NONE
,
2562 _nested_cust_currency_widgets
, lengthof(_nested_cust_currency_widgets
)
2565 /** Open custom currency window. */
2566 static void ShowCustCurrency()
2568 DeleteWindowById(WC_CUSTOM_CURRENCY
, 0);
2569 new CustomCurrencyWindow(&_cust_currency_desc
);