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 "townnamegen.h"
23 #include "newgrf_townname.h"
24 #include "strings_func.h"
25 #include "window_func.h"
27 #include "widgets/dropdown_type.h"
28 #include "widgets/dropdown_func.h"
29 #include "highscore.h"
30 #include "base_media_base.h"
31 #include "company_base.h"
32 #include "company_func.h"
33 #include "viewport_func.h"
34 #include "core/geometry_func.hpp"
36 #include "blitter/blitter.h"
39 #include "stringfilter_type.h"
40 #include "querystring_gui.h"
41 #include "spritecache.h"
44 static const StringID _driveside_dropdown
[] = {
45 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT
,
46 STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_RIGHT
,
50 static const StringID _autosave_dropdown
[] = {
51 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF
,
52 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_1_MONTH
,
53 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_3_MONTHS
,
54 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_6_MONTHS
,
55 STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_12_MONTHS
,
59 static const StringID _gui_zoom_dropdown
[] = {
60 STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_NORMAL
,
61 STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_2X_ZOOM
,
62 STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_4X_ZOOM
,
66 static StringID
*_grf_names
= NULL
; ///< Pointer to town names defined by NewGRFs.
67 static int _nb_grf_names
= 0; ///< Number of town names defined by NewGRFs.
69 static Dimension _circle_size
; ///< Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.
71 /** Read the variable encoded in a setting description. */
72 static int64
ReadVariable (const GameSettings
*settings_ptr
, const SettingDesc
*sd
)
75 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) == 0) {
76 object
= settings_ptr
;
77 } else if (Company::IsValidID(_local_company
) && _game_mode
!= GM_MENU
) {
78 object
= &Company::Get(_local_company
)->settings
;
80 object
= &_settings_client
.company
;
83 const void *ptr
= sd
->save
.get_variable_address (object
);
84 return ReadValue (ptr
, sd
->save
.conv
);
87 /** Allocate memory for the NewGRF town names. */
88 void InitGRFTownGeneratorNames()
91 _grf_names
= GetGRFTownNameList();
93 for (StringID
*s
= _grf_names
; *s
!= INVALID_STRING_ID
; s
++) _nb_grf_names
++;
98 * @param town_name Number of the wanted town name.
99 * @return Name of the town as string ID.
101 static inline StringID
TownName(int town_name
)
103 if (town_name
< (int)N_ORIG_TOWN_NAME_GEN
) return STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH
+ town_name
;
104 town_name
-= N_ORIG_TOWN_NAME_GEN
;
105 if (town_name
< _nb_grf_names
) return _grf_names
[town_name
];
106 return STR_UNDEFINED
;
110 * Get index of the current screen resolution.
111 * @return Index of the current screen resolution if it is a known resolution, #_num_resolutions otherwise.
113 static int GetCurRes()
117 for (i
= 0; i
!= _num_resolutions
; i
++) {
118 if ((int)_resolutions
[i
].width
== _screen_width
&&
119 (int)_resolutions
[i
].height
== _screen_height
) {
126 static void ShowCustCurrency();
129 static DropDownList
*BuiltSetDropDownList(int *selected_index
)
131 int n
= T::GetNumSets();
132 *selected_index
= T::GetIndexOfUsedSet();
134 DropDownList
*list
= new DropDownList();
135 for (int i
= 0; i
< n
; i
++) {
136 *list
->Append() = new DropDownListCharStringItem(T::GetSet(i
)->get_name(), i
, (_game_mode
== GM_MENU
) ? false : (*selected_index
!= i
));
142 /** Window for displaying the textfile of a BaseSet. */
143 template <class TBaseSet
>
144 struct BaseSetTextfileWindow
: public TextfileWindow
{
145 const TBaseSet
* baseset
; ///< View the textfile of this BaseSet.
146 StringID content_type
; ///< STR_CONTENT_TYPE_xxx for title.
148 BaseSetTextfileWindow (TextfileType file_type
, const TBaseSet
* baseset
, StringID content_type
)
149 : TextfileWindow (baseset
->GetTextfile (file_type
)),
150 baseset(baseset
), content_type(content_type
)
152 this->CheckForMissingGlyphs();
155 /* virtual */ void SetStringParameters(int widget
) const
157 if (widget
== WID_TF_CAPTION
) {
158 SetDParam(0, content_type
);
159 SetDParamStr(1, this->baseset
->get_name());
165 * Open the BaseSet version of the textfile window.
166 * @param file_type The type of textfile to display.
167 * @param baseset The BaseSet to use.
168 * @param content_type STR_CONTENT_TYPE_xxx for title.
170 template <class TBaseSet
>
171 void ShowBaseSetTextfileWindow(TextfileType file_type
, const TBaseSet
* baseset
, StringID content_type
)
173 DeleteWindowByClass(WC_TEXTFILE
);
174 new BaseSetTextfileWindow
<TBaseSet
>(file_type
, baseset
, content_type
);
177 struct GameOptionsWindow
: Window
{
181 GameOptionsWindow (const WindowDesc
*desc
) :
182 Window (desc
), opt (&GetGameSettings()), reload (false)
184 this->InitNested(WN_GAME_OPTIONS_GAME_OPTIONS
);
185 this->OnInvalidateData(0);
188 void OnDelete (void) FINAL_OVERRIDE
190 DeleteWindowById(WC_CUSTOM_CURRENCY
, 0);
191 if (this->reload
) _switch_mode
= SM_MENU
;
195 * Build the dropdown list for a specific widget.
196 * @param widget Widget to build list for
197 * @param selected_index Currently selected item
198 * @return the built dropdown list, or NULL if the widget has no dropdown menu.
200 DropDownList
*BuildDropDownList(int widget
, int *selected_index
) const
202 DropDownList
*list
= NULL
;
204 case WID_GO_CURRENCY_DROPDOWN
: { // Setup currencies dropdown
205 list
= new DropDownList();
206 *selected_index
= this->opt
->locale
.currency
;
207 StringID
*items
= BuildCurrencyDropdown();
208 uint64 disabled
= _game_mode
== GM_MENU
? 0LL : ~GetMaskOfAllowedCurrencies();
210 /* Add non-custom currencies; sorted naturally */
211 for (uint i
= 0; i
< CURRENCY_END
; items
++, i
++) {
212 if (i
== CURRENCY_CUSTOM
) continue;
213 *list
->Append() = new DropDownListStringItem(*items
, i
, HasBit(disabled
, i
));
215 list
->Sort (DropDownListStringItem::NatSortFunc
);
217 /* Append custom currency at the end */
218 *list
->Append() = new DropDownListItem(-1, false); // separator line
219 *list
->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_CURRENCY_CUSTOM
, CURRENCY_CUSTOM
, HasBit(disabled
, CURRENCY_CUSTOM
));
223 case WID_GO_ROADSIDE_DROPDOWN
: { // Setup road-side dropdown
224 list
= new DropDownList();
225 *selected_index
= this->opt
->vehicle
.road_side
;
226 const StringID
*items
= _driveside_dropdown
;
229 /* You can only change the drive side if you are in the menu or ingame with
230 * no vehicles present. In a networking game only the server can change it */
231 extern bool RoadVehiclesAreBuilt();
232 if ((_game_mode
!= GM_MENU
&& RoadVehiclesAreBuilt()) || (_networking
&& !_network_server
)) {
233 disabled
= ~(1 << this->opt
->vehicle
.road_side
); // disable the other value
236 for (uint i
= 0; *items
!= INVALID_STRING_ID
; items
++, i
++) {
237 *list
->Append() = new DropDownListStringItem(*items
, i
, HasBit(disabled
, i
));
242 case WID_GO_TOWNNAME_DROPDOWN
: { // Setup townname dropdown
243 list
= new DropDownList();
244 *selected_index
= this->opt
->game_creation
.town_name
;
246 int enabled_item
= (_game_mode
== GM_MENU
|| Town::GetNumItems() == 0) ? -1 : *selected_index
;
248 /* Add and sort newgrf townnames generators */
249 for (int i
= 0; i
< _nb_grf_names
; i
++) {
250 int result
= N_ORIG_TOWN_NAME_GEN
+ i
;
251 *list
->Append() = new DropDownListStringItem (_grf_names
[i
], result
, enabled_item
!= result
&& enabled_item
>= 0);
253 list
->Sort (DropDownListStringItem::NatSortFunc
);
255 int newgrf_size
= list
->Length();
256 /* Insert newgrf_names at the top of the list */
257 if (newgrf_size
> 0) {
258 *list
->Append() = new DropDownListItem(-1, false); // separator line
262 /* Add and sort original townnames generators */
263 for (uint i
= 0; i
< N_ORIG_TOWN_NAME_GEN
; i
++) {
264 *list
->Append() = new DropDownListStringItem(STR_GAME_OPTIONS_TOWN_NAME_ORIGINAL_ENGLISH
+ i
, i
, enabled_item
!= (int)i
&& enabled_item
>= 0);
266 list
->Sort (DropDownListStringItem::NatSortFunc
, newgrf_size
);
270 case WID_GO_AUTOSAVE_DROPDOWN
: { // Setup autosave dropdown
271 list
= new DropDownList();
272 *selected_index
= _settings_client
.gui
.autosave
;
273 const StringID
*items
= _autosave_dropdown
;
274 for (uint i
= 0; *items
!= INVALID_STRING_ID
; items
++, i
++) {
275 *list
->Append() = new DropDownListStringItem(*items
, i
, false);
280 case WID_GO_LANG_DROPDOWN
: { // Setup interface language dropdown
281 list
= new DropDownList();
282 for (uint i
= 0; i
< _languages
.Length(); i
++) {
283 if (&_languages
[i
] == _current_language
) *selected_index
= i
;
284 *list
->Append() = new DropDownListStringItem(SPECSTR_LANGUAGE_START
+ i
, i
, false);
286 list
->Sort (DropDownListStringItem::NatSortFunc
);
290 case WID_GO_RESOLUTION_DROPDOWN
: // Setup resolution dropdown
291 if (_num_resolutions
== 0) break;
293 list
= new DropDownList();
294 *selected_index
= GetCurRes();
295 for (int i
= 0; i
< _num_resolutions
; i
++) {
296 *list
->Append() = new DropDownListStringItem(SPECSTR_RESOLUTION_START
+ i
, i
, false);
300 case WID_GO_GUI_ZOOM_DROPDOWN
: {
301 list
= new DropDownList();
302 *selected_index
= ZOOM_LVL_OUT_4X
- _gui_zoom
;
303 const StringID
*items
= _gui_zoom_dropdown
;
304 for (int i
= 0; *items
!= INVALID_STRING_ID
; items
++, i
++) {
305 *list
->Append() = new DropDownListStringItem(*items
, i
, _settings_client
.gui
.zoom_min
> ZOOM_LVL_OUT_4X
- i
);
310 case WID_GO_SCREENSHOT_DROPDOWN
: // Setup screenshot format dropdown
311 list
= new DropDownList();
312 *selected_index
= _cur_screenshot_format
;
313 for (uint i
= 0; i
< _num_screenshot_formats
; i
++) {
314 if (!GetScreenshotFormatSupports_32bpp(i
) && Blitter::get()->screen_depth
== 32) continue;
315 *list
->Append() = new DropDownListStringItem(SPECSTR_SCREENSHOT_START
+ i
, i
, false);
319 case WID_GO_BASE_GRF_DROPDOWN
:
320 list
= BuiltSetDropDownList
<BaseGraphics
>(selected_index
);
323 case WID_GO_BASE_SFX_DROPDOWN
:
324 list
= BuiltSetDropDownList
<BaseSounds
>(selected_index
);
327 case WID_GO_BASE_MUSIC_DROPDOWN
:
328 list
= BuiltSetDropDownList
<BaseMusic
>(selected_index
);
338 virtual void SetStringParameters(int widget
) const
341 case WID_GO_CURRENCY_DROPDOWN
: SetDParam(0, _currency_specs
[this->opt
->locale
.currency
].name
); break;
342 case WID_GO_ROADSIDE_DROPDOWN
: SetDParam(0, STR_GAME_OPTIONS_ROAD_VEHICLES_DROPDOWN_LEFT
+ this->opt
->vehicle
.road_side
); break;
343 case WID_GO_TOWNNAME_DROPDOWN
: SetDParam(0, TownName(this->opt
->game_creation
.town_name
)); break;
344 case WID_GO_AUTOSAVE_DROPDOWN
: SetDParam(0, _autosave_dropdown
[_settings_client
.gui
.autosave
]); break;
345 case WID_GO_LANG_DROPDOWN
: SetDParamStr(0, _current_language
->own_name
); break;
346 case WID_GO_RESOLUTION_DROPDOWN
: SetDParam(0, GetCurRes() == _num_resolutions
? STR_GAME_OPTIONS_RESOLUTION_OTHER
: SPECSTR_RESOLUTION_START
+ GetCurRes()); break;
347 case WID_GO_GUI_ZOOM_DROPDOWN
: SetDParam(0, _gui_zoom_dropdown
[ZOOM_LVL_OUT_4X
- _gui_zoom
]); break;
348 case WID_GO_SCREENSHOT_DROPDOWN
: SetDParam(0, SPECSTR_SCREENSHOT_START
+ _cur_screenshot_format
); break;
349 case WID_GO_BASE_GRF_DROPDOWN
: SetDParamStr(0, BaseGraphics::GetUsedSet()->get_name()); break;
350 case WID_GO_BASE_GRF_STATUS
: SetDParam(0, BaseGraphics::GetUsedSet()->GetNumInvalid()); break;
351 case WID_GO_BASE_SFX_DROPDOWN
: SetDParamStr(0, BaseSounds::GetUsedSet()->get_name()); break;
352 case WID_GO_BASE_MUSIC_DROPDOWN
: SetDParamStr(0, BaseMusic::GetUsedSet()->get_name()); break;
353 case WID_GO_BASE_MUSIC_STATUS
: SetDParam(0, BaseMusic::GetUsedSet()->GetNumInvalid()); break;
357 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
359 const BaseSetDesc
*set
;
362 case WID_GO_BASE_GRF_DESCRIPTION
:
363 set
= BaseGraphics::GetUsedSet();
366 case WID_GO_BASE_SFX_DESCRIPTION
:
367 set
= BaseSounds::GetUsedSet();
370 case WID_GO_BASE_MUSIC_DESCRIPTION
:
371 set
= BaseMusic::GetUsedSet();
377 SetDParamStr (0, set
->get_desc (GetCurrentLanguageIsoCode()));
378 DrawStringMultiLine (dpi
, r
.left
, r
.right
, r
.top
, UINT16_MAX
, STR_BLACK_RAW_STRING
);
382 static void UpdateSetDescWidgetSize (Dimension
*size
)
384 /* Find the biggest description for the default size. */
385 for (int i
= 0; i
< T::GetNumSets(); i
++) {
386 SetDParamStr (0, T::GetSet(i
)->get_desc (GetCurrentLanguageIsoCode()));
387 size
->height
= max (size
->height
, GetStringHeight (STR_BLACK_RAW_STRING
, size
->width
));
391 template <class T
, StringID str
>
392 static void UpdateSetStatusWidgetSize (Dimension
*size
)
394 /* Find the biggest description for the default size. */
395 for (int i
= 0; i
< T::GetNumSets(); i
++) {
396 uint invalid_files
= T::GetSet(i
)->GetNumInvalid();
397 if (invalid_files
== 0) continue;
399 SetDParam (0, invalid_files
);
400 *size
= maxdim (*size
, GetStringBoundingBox (str
));
404 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
407 case WID_GO_BASE_GRF_DESCRIPTION
:
408 UpdateSetDescWidgetSize
<BaseGraphics
> (size
);
411 case WID_GO_BASE_GRF_STATUS
:
412 UpdateSetStatusWidgetSize
<BaseGraphics
, STR_GAME_OPTIONS_BASE_GRF_STATUS
> (size
);
415 case WID_GO_BASE_SFX_DESCRIPTION
:
416 UpdateSetDescWidgetSize
<BaseSounds
> (size
);
419 case WID_GO_BASE_MUSIC_DESCRIPTION
:
420 UpdateSetDescWidgetSize
<BaseMusic
> (size
);
423 case WID_GO_BASE_MUSIC_STATUS
:
424 UpdateSetStatusWidgetSize
<BaseMusic
, STR_GAME_OPTIONS_BASE_MUSIC_STATUS
> (size
);
429 DropDownList
*list
= this->BuildDropDownList(widget
, &selected
);
431 /* Find the biggest item for the default size. */
432 for (const DropDownListItem
* const *it
= list
->Begin(); it
!= list
->End(); it
++) {
433 Dimension string_dim
;
434 int width
= (*it
)->Width();
435 string_dim
.width
= width
+ padding
.width
;
436 string_dim
.height
= (*it
)->Height(width
) + padding
.height
;
437 *size
= maxdim(*size
, string_dim
);
445 virtual void OnClick(Point pt
, int widget
, int click_count
)
447 if (widget
>= WID_GO_BASE_GRF_TEXTFILE
&& widget
< WID_GO_BASE_GRF_TEXTFILE
+ TFT_END
) {
448 if (BaseGraphics::GetUsedSet() == NULL
) return;
450 ShowBaseSetTextfileWindow((TextfileType
)(widget
- WID_GO_BASE_GRF_TEXTFILE
), BaseGraphics::GetUsedSet(), STR_CONTENT_TYPE_BASE_GRAPHICS
);
453 if (widget
>= WID_GO_BASE_SFX_TEXTFILE
&& widget
< WID_GO_BASE_SFX_TEXTFILE
+ TFT_END
) {
454 if (BaseSounds::GetUsedSet() == NULL
) return;
456 ShowBaseSetTextfileWindow((TextfileType
)(widget
- WID_GO_BASE_SFX_TEXTFILE
), BaseSounds::GetUsedSet(), STR_CONTENT_TYPE_BASE_SOUNDS
);
459 if (widget
>= WID_GO_BASE_MUSIC_TEXTFILE
&& widget
< WID_GO_BASE_MUSIC_TEXTFILE
+ TFT_END
) {
460 if (BaseMusic::GetUsedSet() == NULL
) return;
462 ShowBaseSetTextfileWindow((TextfileType
)(widget
- WID_GO_BASE_MUSIC_TEXTFILE
), BaseMusic::GetUsedSet(), STR_CONTENT_TYPE_BASE_MUSIC
);
466 case WID_GO_FULLSCREEN_BUTTON
: // Click fullscreen on/off
467 /* try to toggle full-screen on/off */
468 if (!ToggleFullScreen(!_fullscreen
)) {
469 ShowErrorMessage(STR_ERROR_FULLSCREEN_FAILED
, INVALID_STRING_ID
, WL_ERROR
);
471 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON
, _fullscreen
);
477 DropDownList
*list
= this->BuildDropDownList(widget
, &selected
);
479 ShowDropDownList(this, list
, selected
, widget
);
481 if (widget
== WID_GO_RESOLUTION_DROPDOWN
) ShowErrorMessage(STR_ERROR_RESOLUTION_LIST_FAILED
, INVALID_STRING_ID
, WL_ERROR
);
489 * Set the base media set.
490 * @param index the index of the media set
491 * @tparam T class of media set
494 void SetMediaSet(int index
)
496 if (_game_mode
== GM_MENU
) {
497 const char *name
= T::GetSet(index
)->get_name();
500 T::ini_set
= xstrdup(name
);
504 this->InvalidateData();
508 virtual void OnDropdownSelect(int widget
, int index
)
511 case WID_GO_CURRENCY_DROPDOWN
: // Currency
512 if (index
== CURRENCY_CUSTOM
) ShowCustCurrency();
513 this->opt
->locale
.currency
= index
;
517 case WID_GO_ROADSIDE_DROPDOWN
: // Road side
518 if (this->opt
->vehicle
.road_side
!= index
) { // only change if setting changed
520 if (GetSettingFromName("vehicle.road_side", &i
) == NULL
) NOT_REACHED();
521 SetSettingValue(i
, index
);
522 MarkWholeScreenDirty();
526 case WID_GO_TOWNNAME_DROPDOWN
: // Town names
527 if (_game_mode
== GM_MENU
|| Town::GetNumItems() == 0) {
528 this->opt
->game_creation
.town_name
= index
;
529 SetWindowDirty(WC_GAME_OPTIONS
, WN_GAME_OPTIONS_GAME_OPTIONS
);
533 case WID_GO_AUTOSAVE_DROPDOWN
: // Autosave options
534 _settings_client
.gui
.autosave
= index
;
538 case WID_GO_LANG_DROPDOWN
: // Change interface language
539 ReadLanguagePack(&_languages
[index
]);
540 DeleteWindowByClass(WC_QUERY_STRING
);
541 CheckForMissingGlyphs();
542 UpdateAllVirtCoords();
546 case WID_GO_RESOLUTION_DROPDOWN
: // Change resolution
547 if (index
< _num_resolutions
&& ChangeResInGame(_resolutions
[index
].width
, _resolutions
[index
].height
)) {
552 case WID_GO_GUI_ZOOM_DROPDOWN
:
553 GfxClearSpriteCache();
554 _gui_zoom
= (ZoomLevel
)(ZOOM_LVL_OUT_4X
- index
);
556 LoadStringWidthTable();
557 UpdateAllVirtCoords();
560 case WID_GO_SCREENSHOT_DROPDOWN
: // Change screenshot format
561 SetScreenshotFormat(index
);
565 case WID_GO_BASE_GRF_DROPDOWN
:
566 this->SetMediaSet
<BaseGraphics
>(index
);
569 case WID_GO_BASE_SFX_DROPDOWN
:
570 this->SetMediaSet
<BaseSounds
>(index
);
573 case WID_GO_BASE_MUSIC_DROPDOWN
:
574 this->SetMediaSet
<BaseMusic
>(index
);
579 template <class T
, class S
, GameOptionsWidgets W
>
580 void SetBaseSetWidgetsDisabledState (void)
582 const S
*set
= T::GetUsedSet();
583 for (TextfileType tft
= TFT_BEGIN
; tft
< TFT_END
; tft
++) {
584 this->SetWidgetDisabledState (W
+ tft
,
585 set
== NULL
|| !set
->GetTextfile(tft
).valid());
590 * Some data on this window has become invalid.
591 * @param data Information about the changed data. @see GameOptionsInvalidationData
592 * @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.
594 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
596 if (!gui_scope
) return;
597 this->SetWidgetLoweredState(WID_GO_FULLSCREEN_BUTTON
, _fullscreen
);
599 bool missing_files
= BaseGraphics::GetUsedSet()->GetNumMissing() == 0;
600 this->GetWidget
<NWidgetCore
>(WID_GO_BASE_GRF_STATUS
)->SetDataTip(missing_files
? STR_EMPTY
: STR_GAME_OPTIONS_BASE_GRF_STATUS
, STR_NULL
);
602 this->SetBaseSetWidgetsDisabledState
<BaseGraphics
, GraphicsSet
, WID_GO_BASE_GRF_TEXTFILE
> ();
603 this->SetBaseSetWidgetsDisabledState
<BaseSounds
, SoundsSet
, WID_GO_BASE_SFX_TEXTFILE
> ();
604 this->SetBaseSetWidgetsDisabledState
<BaseMusic
, MusicSet
, WID_GO_BASE_MUSIC_TEXTFILE
> ();
606 missing_files
= BaseMusic::GetUsedSet()->GetNumInvalid() == 0;
607 this->GetWidget
<NWidgetCore
>(WID_GO_BASE_MUSIC_STATUS
)->SetDataTip(missing_files
? STR_EMPTY
: STR_GAME_OPTIONS_BASE_MUSIC_STATUS
, STR_NULL
);
611 static const NWidgetPart _nested_game_options_widgets
[] = {
612 NWidget(NWID_HORIZONTAL
),
613 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
614 NWidget(WWT_CAPTION
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
616 NWidget(WWT_PANEL
, COLOUR_GREY
, WID_GO_BACKGROUND
), SetPIP(6, 6, 10),
617 NWidget(NWID_HORIZONTAL
), SetPIP(10, 10, 10),
618 NWidget(NWID_VERTICAL
), SetPIP(0, 6, 0),
619 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_CURRENCY_UNITS_FRAME
, STR_NULL
),
620 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),
622 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_ROAD_VEHICLES_FRAME
, STR_NULL
),
623 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),
625 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_AUTOSAVE_FRAME
, STR_NULL
),
626 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),
628 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_RESOLUTION
, STR_NULL
),
629 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),
630 NWidget(NWID_HORIZONTAL
),
631 NWidget(WWT_TEXT
, COLOUR_GREY
), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_FULLSCREEN
, STR_NULL
),
632 NWidget(WWT_TEXTBTN
, COLOUR_GREY
, WID_GO_FULLSCREEN_BUTTON
), SetMinimalSize(21, 9), SetDataTip(STR_EMPTY
, STR_GAME_OPTIONS_FULLSCREEN_TOOLTIP
),
635 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_GUI_ZOOM_FRAME
, STR_NULL
),
636 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_GUI_ZOOM_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_STRING
, STR_GAME_OPTIONS_GUI_ZOOM_DROPDOWN_TOOLTIP
), SetFill(1, 0),
640 NWidget(NWID_VERTICAL
), SetPIP(0, 6, 0),
641 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_TOWN_NAMES_FRAME
, STR_NULL
),
642 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),
644 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_LANGUAGE
, STR_NULL
),
645 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),
647 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_SCREENSHOT_FORMAT
, STR_NULL
),
648 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),
650 NWidget(NWID_SPACER
), SetMinimalSize(0, 0), SetFill(0, 1),
654 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_BASE_GRF
, STR_NULL
), SetPadding(0, 10, 0, 10),
655 NWidget(NWID_HORIZONTAL
), SetPIP(0, 30, 0),
656 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_BASE_GRF_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING
, STR_GAME_OPTIONS_BASE_GRF_TOOLTIP
),
657 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_GO_BASE_GRF_STATUS
), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY
, STR_NULL
), SetFill(1, 0),
659 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),
660 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(7, 0, 7),
661 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
),
662 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
),
663 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
),
667 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_BASE_SFX
, STR_NULL
), SetPadding(0, 10, 0, 10),
668 NWidget(NWID_HORIZONTAL
), SetPIP(0, 30, 0),
669 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_BASE_SFX_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING
, STR_GAME_OPTIONS_BASE_SFX_TOOLTIP
),
670 NWidget(NWID_SPACER
), SetFill(1, 0),
672 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),
673 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(7, 0, 7),
674 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
),
675 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
),
676 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
),
680 NWidget(WWT_FRAME
, COLOUR_GREY
), SetDataTip(STR_GAME_OPTIONS_BASE_MUSIC
, STR_NULL
), SetPadding(0, 10, 0, 10),
681 NWidget(NWID_HORIZONTAL
), SetPIP(0, 30, 0),
682 NWidget(WWT_DROPDOWN
, COLOUR_GREY
, WID_GO_BASE_MUSIC_DROPDOWN
), SetMinimalSize(150, 12), SetDataTip(STR_BLACK_RAW_STRING
, STR_GAME_OPTIONS_BASE_MUSIC_TOOLTIP
),
683 NWidget(WWT_TEXT
, COLOUR_GREY
, WID_GO_BASE_MUSIC_STATUS
), SetMinimalSize(150, 12), SetDataTip(STR_EMPTY
, STR_NULL
), SetFill(1, 0),
685 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),
686 NWidget(NWID_HORIZONTAL
, NC_EQUALSIZE
), SetPIP(7, 0, 7),
687 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
),
688 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
),
689 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
),
695 static WindowDesc::Prefs
_game_options_prefs ("settings_game");
697 static const WindowDesc
_game_options_desc(
699 WC_GAME_OPTIONS
, WC_NONE
,
701 _nested_game_options_widgets
, lengthof(_nested_game_options_widgets
),
705 /** Open the game options window. */
706 void ShowGameOptions()
708 DeleteWindowByClass(WC_GAME_OPTIONS
);
709 new GameOptionsWindow(&_game_options_desc
);
712 static int SETTING_HEIGHT
= 11; ///< Height of a single setting in the tree view in pixels
713 static const int LEVEL_WIDTH
= 15; ///< Indenting width of a sub-page in pixels
716 * Flags for #SettingEntry
717 * @note The #SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of #DrawArrowButtons
719 enum SettingEntryFlags
{
720 SEF_LEFT_DEPRESSED
= 0x01, ///< Of a numeric setting entry, the left button is depressed
721 SEF_RIGHT_DEPRESSED
= 0x02, ///< Of a numeric setting entry, the right button is depressed
722 SEF_BUTTONS_MASK
= (SEF_LEFT_DEPRESSED
| SEF_RIGHT_DEPRESSED
), ///< Bit-mask for button flags
724 SEF_LAST_FIELD
= 0x04, ///< This entry is the last one in a (sub-)page
725 SEF_FILTERED
= 0x08, ///< Entry is hidden by the string filter
728 SEF_SETTING_KIND
= 0x10, ///< Entry kind: Entry is a setting
729 SEF_SUBTREE_KIND
= 0x20, ///< Entry kind: Entry is a sub-tree
730 SEF_KIND_MASK
= (SEF_SETTING_KIND
| SEF_SUBTREE_KIND
), ///< Bit-mask for fetching entry kind
733 struct SettingsPage
; // Forward declaration
735 /** Data fields for a sub-page (#SEF_SUBTREE_KIND kind)*/
736 struct SettingEntrySubtree
{
737 SettingsPage
*page
; ///< Pointer to the sub-page
738 bool folded
; ///< Sub-page is folded (not visible except for its title)
739 StringID title
; ///< Title of the sub-page
742 /** Data fields for a single setting (#SEF_SETTING_KIND kind) */
743 struct SettingEntrySetting
{
744 const char *name
; ///< Name of the setting
745 const SettingDesc
*setting
; ///< Setting description of the setting
746 uint index
; ///< Index of the setting in the settings table
749 /** How the list of advanced settings is filtered. */
750 enum RestrictionMode
{
751 RM_BASIC
, ///< Display settings associated to the "basic" list.
752 RM_ADVANCED
, ///< Display settings associated to the "advanced" list.
753 RM_ALL
, ///< List all settings regardless of the default/newgame/... values.
754 RM_CHANGED_AGAINST_DEFAULT
, ///< Show only settings which are different compared to default values.
755 RM_CHANGED_AGAINST_NEW
, ///< Show only settings which are different compared to the user's new game setting values.
756 RM_END
, ///< End for iteration.
758 DECLARE_POSTFIX_INCREMENT(RestrictionMode
)
760 /** Filter for settings list. */
761 struct SettingFilter
{
762 StringFilter string
; ///< Filter string.
763 RestrictionMode min_cat
; ///< Minimum category needed to display all filtered strings (#RM_BASIC, #RM_ADVANCED, or #RM_ALL).
764 bool type_hides
; ///< Whether the type hides filtered strings.
765 RestrictionMode mode
; ///< Filter based on category.
766 SettingType type
; ///< Filter based on type.
769 /** Data structure describing a single setting in a tab */
770 struct SettingEntry
{
771 byte flags
; ///< Flags of the setting entry. @see SettingEntryFlags
772 byte level
; ///< Nesting level of this setting entry
774 SettingEntrySetting entry
; ///< Data fields if entry is a setting
775 SettingEntrySubtree sub
; ///< Data fields if entry is a sub-page
776 } d
; ///< Data fields for each kind
778 SettingEntry(const char *nm
);
779 SettingEntry(SettingsPage
*sub
, StringID title
);
781 void Init(byte level
);
784 void SetButtons(byte new_val
);
787 * Set whether this is the last visible entry of the parent node.
788 * @param last_field Value to set
790 void SetLastField(bool last_field
) { if (last_field
) SETBITS(this->flags
, SEF_LAST_FIELD
); else CLRBITS(this->flags
, SEF_LAST_FIELD
); }
793 void GetFoldingState(bool &all_folded
, bool &all_unfolded
) const;
794 bool IsVisible(const SettingEntry
*item
) const;
795 SettingEntry
*FindEntry(uint row
, uint
*cur_row
);
796 uint
GetMaxHelpHeight(int maxw
);
798 bool IsFiltered() const;
799 bool UpdateFilterState(SettingFilter
&filter
, bool force_visible
);
801 uint
Draw (GameSettings
*settings_ptr
, BlitArea
*dpi
, int base_x
,
802 int base_y
, int max_x
, uint first_row
, uint max_row
,
803 uint cur_row
, uint parent_last
, SettingEntry
*selected
);
806 * Get the help text of a single setting.
807 * @return The requested help text.
809 inline StringID
GetHelpText()
811 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
812 return this->d
.entry
.setting
->desc
.str_help
;
815 void SetValueDParams(uint first_param
, int32 value
);
818 void DrawSetting (GameSettings
*settings_ptr
, BlitArea
*dpi
,
819 int x
, int y
, int max_x
, int state
, bool highlight
);
821 bool IsVisibleByRestrictionMode(RestrictionMode mode
) const;
824 /** Data structure describing one page of settings in the settings window. */
825 struct SettingsPage
{
826 SettingEntry
*entries
; ///< Array of setting entries of the page.
827 byte num
; ///< Number of entries on the page (statically filled).
829 void Init(byte level
= 0);
834 void GetFoldingState(bool &all_folded
, bool &all_unfolded
) const;
835 bool IsVisible(const SettingEntry
*item
) const;
836 SettingEntry
*FindEntry(uint row
, uint
*cur_row
) const;
837 uint
GetMaxHelpHeight(int maxw
);
839 bool UpdateFilterState(SettingFilter
&filter
, bool force_visible
);
841 uint
Draw (GameSettings
*settings_ptr
, BlitArea
*dpi
, int base_x
,
842 int base_y
, int max_x
, uint first_row
, uint max_row
,
843 SettingEntry
*selected
, uint cur_row
= 0, uint parent_last
= 0) const;
847 /* == SettingEntry methods == */
850 * Constructor for a single setting in the 'advanced settings' window
851 * @param nm Name of the setting in the setting table
853 SettingEntry::SettingEntry(const char *nm
)
855 this->flags
= SEF_SETTING_KIND
;
857 this->d
.entry
.name
= nm
;
858 this->d
.entry
.setting
= NULL
;
859 this->d
.entry
.index
= 0;
863 * Constructor for a sub-page in the 'advanced settings' window
864 * @param sub Sub-page
865 * @param title Title of the sub-page
867 SettingEntry::SettingEntry(SettingsPage
*sub
, StringID title
)
869 this->flags
= SEF_SUBTREE_KIND
;
871 this->d
.sub
.page
= sub
;
872 this->d
.sub
.folded
= true;
873 this->d
.sub
.title
= title
;
877 * Initialization of a setting entry
878 * @param level Page nesting level of this entry
880 void SettingEntry::Init(byte level
)
884 switch (this->flags
& SEF_KIND_MASK
) {
885 case SEF_SETTING_KIND
:
886 this->d
.entry
.setting
= GetSettingFromName(this->d
.entry
.name
, &this->d
.entry
.index
);
887 assert(this->d
.entry
.setting
!= NULL
);
889 case SEF_SUBTREE_KIND
:
890 this->d
.sub
.page
->Init(level
+ 1);
892 default: NOT_REACHED();
896 /** Recursively close all (filtered) folds of sub-pages */
897 void SettingEntry::FoldAll()
899 if (this->IsFiltered()) return;
900 switch (this->flags
& SEF_KIND_MASK
) {
901 case SEF_SETTING_KIND
:
904 case SEF_SUBTREE_KIND
:
905 this->d
.sub
.folded
= true;
906 this->d
.sub
.page
->FoldAll();
909 default: NOT_REACHED();
913 /** Recursively open all (filtered) folds of sub-pages */
914 void SettingEntry::UnFoldAll()
916 if (this->IsFiltered()) return;
917 switch (this->flags
& SEF_KIND_MASK
) {
918 case SEF_SETTING_KIND
:
921 case SEF_SUBTREE_KIND
:
922 this->d
.sub
.folded
= false;
923 this->d
.sub
.page
->UnFoldAll();
926 default: NOT_REACHED();
931 * Recursively accumulate the folding state of the (filtered) tree.
932 * @param[in,out] all_folded Set to false, if one entry is not folded.
933 * @param[in,out] all_unfolded Set to false, if one entry is folded.
935 void SettingEntry::GetFoldingState(bool &all_folded
, bool &all_unfolded
) const
937 if (this->IsFiltered()) return;
938 switch (this->flags
& SEF_KIND_MASK
) {
939 case SEF_SETTING_KIND
:
942 case SEF_SUBTREE_KIND
:
943 if (this->d
.sub
.folded
) {
944 all_unfolded
= false;
948 this->d
.sub
.page
->GetFoldingState(all_folded
, all_unfolded
);
951 default: NOT_REACHED();
956 * Check whether an entry is visible and not folded or filtered away.
957 * Note: This does not consider the scrolling range; it might still require scrolling to make the setting really visible.
958 * @param item Entry to search for.
959 * @return true if entry is visible.
961 bool SettingEntry::IsVisible(const SettingEntry
*item
) const
963 if (this->IsFiltered()) return false;
964 if (this == item
) return true;
966 switch (this->flags
& SEF_KIND_MASK
) {
967 case SEF_SETTING_KIND
:
970 case SEF_SUBTREE_KIND
:
971 return !this->d
.sub
.folded
&& this->d
.sub
.page
->IsVisible(item
);
973 default: NOT_REACHED();
978 * Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
979 * @param new_val New value for the button flags
980 * @see SettingEntryFlags
982 void SettingEntry::SetButtons(byte new_val
)
984 assert((new_val
& ~SEF_BUTTONS_MASK
) == 0); // Should not touch any flags outside the buttons
985 this->flags
= (this->flags
& ~SEF_BUTTONS_MASK
) | new_val
;
988 /** Return numbers of rows needed to display the (filtered) entry */
989 uint
SettingEntry::Length() const
991 if (this->IsFiltered()) return 0;
992 switch (this->flags
& SEF_KIND_MASK
) {
993 case SEF_SETTING_KIND
:
995 case SEF_SUBTREE_KIND
:
996 if (this->d
.sub
.folded
) return 1; // Only displaying the title
998 return 1 + this->d
.sub
.page
->Length(); // 1 extra row for the title
999 default: NOT_REACHED();
1004 * Find setting entry at row \a row_num
1005 * @param row_num Index of entry to return
1006 * @param cur_row Current row number
1007 * @return The requested setting entry or \c NULL if it not found (folded or filtered)
1009 SettingEntry
*SettingEntry::FindEntry(uint row_num
, uint
*cur_row
)
1011 if (this->IsFiltered()) return NULL
;
1012 if (row_num
== *cur_row
) return this;
1014 switch (this->flags
& SEF_KIND_MASK
) {
1015 case SEF_SETTING_KIND
:
1018 case SEF_SUBTREE_KIND
:
1019 (*cur_row
)++; // add one for row containing the title
1020 if (this->d
.sub
.folded
) {
1024 /* sub-page is visible => search it too */
1025 return this->d
.sub
.page
->FindEntry(row_num
, cur_row
);
1026 default: NOT_REACHED();
1032 * Get the biggest height of the help text(s), if the width is at least \a maxw. Help text gets wrapped if needed.
1033 * @param maxw Maximal width of a line help text.
1034 * @return Biggest height needed to display any help text of this node (and its descendants).
1036 uint
SettingEntry::GetMaxHelpHeight(int maxw
)
1038 switch (this->flags
& SEF_KIND_MASK
) {
1039 case SEF_SETTING_KIND
: return GetStringHeight(this->GetHelpText(), maxw
);
1040 case SEF_SUBTREE_KIND
: return this->d
.sub
.page
->GetMaxHelpHeight(maxw
);
1041 default: NOT_REACHED();
1046 * Check whether an entry is hidden due to filters
1047 * @return true if hidden.
1049 bool SettingEntry::IsFiltered() const
1051 return (this->flags
& SEF_FILTERED
) != 0;
1055 * Checks whether an entry shall be made visible based on the restriction mode.
1056 * @param mode The current status of the restriction drop down box.
1057 * @return true if the entry shall be visible.
1059 bool SettingEntry::IsVisibleByRestrictionMode(RestrictionMode mode
) const
1061 /* There shall not be any restriction, i.e. all settings shall be visible. */
1062 if (mode
== RM_ALL
) return true;
1064 GameSettings
*settings_ptr
= &GetGameSettings();
1065 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
1066 const SettingDesc
*sd
= this->d
.entry
.setting
;
1068 if (mode
== RM_BASIC
) return (this->d
.entry
.setting
->desc
.cat
& SC_BASIC_LIST
) != 0;
1069 if (mode
== RM_ADVANCED
) return (this->d
.entry
.setting
->desc
.cat
& SC_ADVANCED_LIST
) != 0;
1071 /* Read the current value. */
1072 int64 current_value
= ReadVariable (settings_ptr
, sd
);
1076 if (mode
== RM_CHANGED_AGAINST_DEFAULT
) {
1077 /* This entry shall only be visible, if the value deviates from its default value. */
1079 /* Read the default value. */
1080 filter_value
= ReadValue(&sd
->desc
.def
, sd
->save
.conv
);
1082 assert(mode
== RM_CHANGED_AGAINST_NEW
);
1083 /* This entry shall only be visible, if the value deviates from
1084 * its value is used when starting a new game. */
1086 /* Make sure we're not comparing the new game settings against itself. */
1087 assert(settings_ptr
!= &_settings_newgame
);
1089 /* Read the new game's value. */
1090 filter_value
= ReadVariable (&_settings_newgame
, sd
);
1093 return current_value
!= filter_value
;
1097 * Update the filter state.
1098 * @param filter Filter
1099 * @param force_visible Whether to force all items visible, no matter what (due to filter text; not affected by restriction drop down box).
1100 * @return true if item remains visible
1102 bool SettingEntry::UpdateFilterState(SettingFilter
&filter
, bool force_visible
)
1104 CLRBITS(this->flags
, SEF_FILTERED
);
1106 bool visible
= true;
1107 switch (this->flags
& SEF_KIND_MASK
) {
1108 case SEF_SETTING_KIND
: {
1109 const SettingDesc
*sd
= this->d
.entry
.setting
;
1110 if (!force_visible
&& !filter
.string
.IsEmpty()) {
1111 /* Process the search text filter for this item. */
1112 filter
.string
.ResetState();
1114 const SettingDescBase
*sdb
= &sd
->desc
;
1116 SetDParam(0, STR_EMPTY
);
1117 filter
.string
.AddLine(sdb
->str
);
1118 filter
.string
.AddLine(this->GetHelpText());
1120 visible
= filter
.string
.GetState();
1123 if (filter
.type
!= ST_ALL
&& sd
->GetType() != filter
.type
) {
1124 filter
.type_hides
= true;
1127 if (!this->IsVisibleByRestrictionMode(filter
.mode
)) {
1128 while (filter
.min_cat
< RM_ALL
&& (filter
.min_cat
== filter
.mode
|| !this->IsVisibleByRestrictionMode(filter
.min_cat
))) filter
.min_cat
++;
1134 case SEF_SUBTREE_KIND
: {
1135 if (!force_visible
&& !filter
.string
.IsEmpty()) {
1136 filter
.string
.ResetState();
1137 filter
.string
.AddLine(this->d
.sub
.title
);
1138 force_visible
= filter
.string
.GetState();
1140 visible
= this->d
.sub
.page
->UpdateFilterState(filter
, force_visible
);
1143 default: NOT_REACHED();
1146 if (!visible
) SETBITS(this->flags
, SEF_FILTERED
);
1153 * Draw a row in the settings panel.
1155 * See SettingsPage::Draw() for an explanation about how drawing is performed.
1157 * The \a parent_last parameter ensures that the vertical lines at the left are
1158 * only drawn when another entry follows, that it prevents output like
1165 * The left-most vertical line is not wanted. It is prevented by setting the
1166 * appropriate bit in the \a parent_last parameter.
1168 * @param settings_ptr Pointer to current values of all settings
1169 * @param dpi Area to draw on
1170 * @param left Left-most position in window/panel to start drawing \a first_row
1171 * @param right Right-most x position to draw strings at.
1172 * @param base_y Upper-most position in window/panel to start drawing \a first_row
1173 * @param first_row First row number to draw
1174 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1175 * @param cur_row Current row number (internal variable)
1176 * @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)
1177 * @param selected Selected entry by the user.
1178 * @return Row number of the next row to draw
1180 uint
SettingEntry::Draw (GameSettings
*settings_ptr
, BlitArea
*dpi
,
1181 int left
, int right
, int base_y
, uint first_row
, uint max_row
,
1182 uint cur_row
, uint parent_last
, SettingEntry
*selected
)
1184 if (this->IsFiltered()) return cur_row
;
1185 if (cur_row
>= max_row
) return cur_row
;
1187 bool rtl
= _current_text_dir
== TD_RTL
;
1188 int offset
= rtl
? -4 : 4;
1189 int level_width
= rtl
? -LEVEL_WIDTH
: LEVEL_WIDTH
;
1191 int x
= rtl
? right
: left
;
1193 if (cur_row
>= first_row
) {
1194 int colour
= _colour_gradient
[COLOUR_ORANGE
][4];
1195 y
= base_y
+ (cur_row
- first_row
) * SETTING_HEIGHT
; // Compute correct y start position
1197 /* Draw vertical for parent nesting levels */
1198 for (uint lvl
= 0; lvl
< this->level
; lvl
++) {
1199 if (!HasBit(parent_last
, lvl
)) GfxDrawLine (dpi
, x
+ offset
, y
, x
+ offset
, y
+ SETTING_HEIGHT
- 1, colour
);
1202 /* draw own |- prefix */
1203 int halfway_y
= y
+ SETTING_HEIGHT
/ 2;
1204 int bottom_y
= (flags
& SEF_LAST_FIELD
) ? halfway_y
: y
+ SETTING_HEIGHT
- 1;
1205 GfxDrawLine (dpi
, x
+ offset
, y
, x
+ offset
, bottom_y
, colour
);
1206 /* Small horizontal line from the last vertical line */
1207 GfxDrawLine (dpi
, x
+ offset
, halfway_y
, x
+ level_width
- offset
, halfway_y
, colour
);
1211 switch (this->flags
& SEF_KIND_MASK
) {
1212 case SEF_SETTING_KIND
:
1213 if (cur_row
>= first_row
) {
1214 this->DrawSetting (settings_ptr
, dpi
, rtl
? left
: x
, rtl
? x
: right
, y
, this->flags
& SEF_BUTTONS_MASK
,
1219 case SEF_SUBTREE_KIND
:
1220 if (cur_row
>= first_row
) {
1221 DrawSprite (dpi
, (this->d
.sub
.folded
? SPR_CIRCLE_FOLDED
: SPR_CIRCLE_UNFOLDED
), PAL_NONE
, rtl
? x
- _circle_size
.width
: x
, y
+ (SETTING_HEIGHT
- _circle_size
.height
) / 2);
1222 DrawString (dpi
, rtl
? left
: x
+ _circle_size
.width
+ 2, rtl
? x
- _circle_size
.width
- 2 : right
, y
+ (SETTING_HEIGHT
- FONT_HEIGHT_NORMAL
) / 2, this->d
.sub
.title
);
1225 if (!this->d
.sub
.folded
) {
1226 if (this->flags
& SEF_LAST_FIELD
) {
1227 assert(this->level
< sizeof(parent_last
));
1228 SetBit(parent_last
, this->level
); // Add own last-field state
1231 cur_row
= this->d
.sub
.page
->Draw (settings_ptr
, dpi
, left
, right
, base_y
, first_row
, max_row
, selected
, cur_row
, parent_last
);
1234 default: NOT_REACHED();
1240 * Set the DParams for drawing the value of a setting.
1241 * @param first_param First DParam to use
1242 * @param value Setting value to set params for.
1244 void SettingEntry::SetValueDParams(uint first_param
, int32 value
)
1246 assert((this->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
1247 const SettingDescBase
*sdb
= &this->d
.entry
.setting
->desc
;
1248 if (sdb
->cmd
== SDT_BOOLX
) {
1249 SetDParam(first_param
++, value
!= 0 ? STR_CONFIG_SETTING_ON
: STR_CONFIG_SETTING_OFF
);
1251 if ((sdb
->flags
& SGF_MULTISTRING
) != 0) {
1252 SetDParam(first_param
++, sdb
->str_val
- sdb
->min
+ value
);
1253 } else if ((sdb
->flags
& SGF_DISPLAY_ABS
) != 0) {
1254 SetDParam(first_param
++, sdb
->str_val
+ ((value
>= 0) ? 1 : 0));
1257 SetDParam(first_param
++, sdb
->str_val
+ ((value
== 0 && (sdb
->flags
& SGF_0ISDISABLED
) != 0) ? 1 : 0));
1259 SetDParam(first_param
++, value
);
1264 * Private function to draw setting value (button + text + current value)
1265 * @param settings_ptr Pointer to current values of all settings
1266 * @param dpi Area to draw on
1267 * @param left Left-most position in window/panel to start drawing
1268 * @param right Right-most position in window/panel to draw
1269 * @param y Upper-most position in window/panel to start drawing
1270 * @param state State of the left + right arrow buttons to draw for the setting
1271 * @param highlight Highlight entry.
1273 void SettingEntry::DrawSetting (GameSettings
*settings_ptr
, BlitArea
*dpi
,
1274 int left
, int right
, int y
, int state
, bool highlight
)
1276 const SettingDesc
*sd
= this->d
.entry
.setting
;
1277 const SettingDescBase
*sdb
= &sd
->desc
;
1278 int32 value
= ReadVariable (settings_ptr
, sd
);
1280 bool rtl
= _current_text_dir
== TD_RTL
;
1281 uint buttons_left
= rtl
? right
+ 1 - SETTING_BUTTON_WIDTH
: left
;
1282 uint text_left
= left
+ (rtl
? 0 : SETTING_BUTTON_WIDTH
+ 5);
1283 uint text_right
= right
- (rtl
? SETTING_BUTTON_WIDTH
+ 5 : 0);
1284 uint button_y
= y
+ (SETTING_HEIGHT
- SETTING_BUTTON_HEIGHT
) / 2;
1286 /* We do not allow changes of some items when we are a client in a networkgame */
1287 bool editable
= sd
->IsEditable();
1289 SetDParam(0, highlight
? STR_ORANGE_STRING1_WHITE
: STR_ORANGE_STRING1_LTBLUE
);
1290 if (sdb
->cmd
== SDT_BOOLX
) {
1291 /* Draw checkbox for boolean-value either on/off */
1292 DrawBoolButton (dpi
, buttons_left
, button_y
, value
!= 0, editable
);
1293 } else if ((sdb
->flags
& SGF_MULTISTRING
) != 0) {
1294 /* Draw [v] button for settings of an enum-type */
1295 DrawDropDownButton (dpi
, buttons_left
, button_y
, COLOUR_YELLOW
, state
!= 0, editable
);
1297 /* Draw [<][>] boxes for settings of an integer-type */
1298 DrawArrowButtons (dpi
, buttons_left
, button_y
, COLOUR_YELLOW
, state
,
1299 editable
&& value
!= (sdb
->flags
& SGF_0ISDISABLED
? 0 : sdb
->min
), editable
&& (uint32
)value
!= sdb
->max
);
1301 this->SetValueDParams(1, value
);
1302 DrawString (dpi
, text_left
, text_right
, y
+ (SETTING_HEIGHT
- FONT_HEIGHT_NORMAL
) / 2, sdb
->str
, highlight
? TC_WHITE
: TC_LIGHT_BLUE
);
1306 /* == SettingsPage methods == */
1309 * Initialization of an entire setting page
1310 * @param level Nesting level of this page (internal variable, do not provide a value for it when calling)
1312 void SettingsPage::Init(byte level
)
1314 for (uint field
= 0; field
< this->num
; field
++) {
1315 this->entries
[field
].Init(level
);
1319 /** Recursively close all folds of sub-pages */
1320 void SettingsPage::FoldAll()
1322 for (uint field
= 0; field
< this->num
; field
++) {
1323 this->entries
[field
].FoldAll();
1327 /** Recursively open all folds of sub-pages */
1328 void SettingsPage::UnFoldAll()
1330 for (uint field
= 0; field
< this->num
; field
++) {
1331 this->entries
[field
].UnFoldAll();
1336 * Recursively accumulate the folding state of the tree.
1337 * @param[in,out] all_folded Set to false, if one entry is not folded.
1338 * @param[in,out] all_unfolded Set to false, if one entry is folded.
1340 void SettingsPage::GetFoldingState(bool &all_folded
, bool &all_unfolded
) const
1342 for (uint field
= 0; field
< this->num
; field
++) {
1343 this->entries
[field
].GetFoldingState(all_folded
, all_unfolded
);
1348 * Update the filter state.
1349 * @param filter Filter
1350 * @param force_visible Whether to force all items visible, no matter what
1351 * @return true if item remains visible
1353 bool SettingsPage::UpdateFilterState(SettingFilter
&filter
, bool force_visible
)
1355 bool visible
= false;
1356 bool first_visible
= true;
1357 for (int field
= this->num
- 1; field
>= 0; field
--) {
1358 visible
|= this->entries
[field
].UpdateFilterState(filter
, force_visible
);
1359 this->entries
[field
].SetLastField(first_visible
);
1360 if (visible
&& first_visible
) first_visible
= false;
1367 * Check whether an entry is visible and not folded or filtered away.
1368 * Note: This does not consider the scrolling range; it might still require scrolling ot make the setting really visible.
1369 * @param item Entry to search for.
1370 * @return true if entry is visible.
1372 bool SettingsPage::IsVisible(const SettingEntry
*item
) const
1374 for (uint field
= 0; field
< this->num
; field
++) {
1375 if (this->entries
[field
].IsVisible(item
)) return true;
1380 /** Return number of rows needed to display the whole page */
1381 uint
SettingsPage::Length() const
1384 for (uint field
= 0; field
< this->num
; field
++) {
1385 length
+= this->entries
[field
].Length();
1391 * Find the setting entry at row number \a row_num
1392 * @param row_num Index of entry to return
1393 * @param cur_row Variable used for keeping track of the current row number. Should point to memory initialized to \c 0 when first called.
1394 * @return The requested setting entry or \c NULL if it does not exist
1396 SettingEntry
*SettingsPage::FindEntry(uint row_num
, uint
*cur_row
) const
1398 SettingEntry
*pe
= NULL
;
1400 for (uint field
= 0; field
< this->num
; field
++) {
1401 pe
= this->entries
[field
].FindEntry(row_num
, cur_row
);
1410 * Get the biggest height of the help texts, if the width is at least \a maxw. Help text gets wrapped if needed.
1411 * @param maxw Maximal width of a line help text.
1412 * @return Biggest height needed to display any help text of this (sub-)tree.
1414 uint
SettingsPage::GetMaxHelpHeight(int maxw
)
1417 for (uint field
= 0; field
< this->num
; field
++) {
1418 biggest
= max(biggest
, this->entries
[field
].GetMaxHelpHeight(maxw
));
1424 * Draw a selected part of the settings page.
1426 * The scrollbar uses rows of the page, while the page data structure is a tree of #SettingsPage and #SettingEntry objects.
1427 * 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.
1428 * Then it enables drawing rows while traversing until \a max_row is reached, at which point drawing is terminated.
1430 * @param settings_ptr Pointer to current values of all settings
1431 * @param dpi Area to raw on
1432 * @param left Left-most position in window/panel to start drawing of each setting row
1433 * @param right Right-most position in window/panel to draw at
1434 * @param base_y Upper-most position in window/panel to start drawing of row number \a first_row
1435 * @param first_row Number of first row to draw
1436 * @param max_row Row-number to stop drawing (the row-number of the row below the last row to draw)
1437 * @param cur_row Current row number (internal variable)
1438 * @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)
1439 * @param selected Selected entry by the user.
1440 * @return Row number of the next row to draw
1442 uint
SettingsPage::Draw (GameSettings
*settings_ptr
, BlitArea
*dpi
,
1443 int left
, int right
, int base_y
, uint first_row
, uint max_row
,
1444 SettingEntry
*selected
, uint cur_row
, uint parent_last
) const
1446 if (cur_row
>= max_row
) return cur_row
;
1448 for (uint i
= 0; i
< this->num
; i
++) {
1449 cur_row
= this->entries
[i
].Draw (settings_ptr
, dpi
, left
, right
, base_y
, first_row
, max_row
, cur_row
, parent_last
, selected
);
1450 if (cur_row
>= max_row
) {
1458 static SettingEntry _settings_localisation
[] = {
1459 SettingEntry("locale.units_velocity"),
1460 SettingEntry("locale.units_power"),
1461 SettingEntry("locale.units_weight"),
1462 SettingEntry("locale.units_volume"),
1463 SettingEntry("locale.units_force"),
1464 SettingEntry("locale.units_height"),
1465 SettingEntry("gui.date_format_in_default_names"),
1467 /** Localisation options sub-page */
1468 static SettingsPage _settings_localisation_page
= {_settings_localisation
, lengthof(_settings_localisation
)};
1470 static SettingEntry _settings_graphics
[] = {
1471 SettingEntry("gui.zoom_min"),
1472 SettingEntry("gui.zoom_max"),
1473 SettingEntry("gui.smallmap_land_colour"),
1474 SettingEntry("gui.graph_line_thickness"),
1476 /** Graphics options sub-page */
1477 static SettingsPage _settings_graphics_page
= {_settings_graphics
, lengthof(_settings_graphics
)};
1479 static SettingEntry _settings_sound
[] = {
1480 SettingEntry("sound.click_beep"),
1481 SettingEntry("sound.confirm"),
1482 SettingEntry("sound.news_ticker"),
1483 SettingEntry("sound.news_full"),
1484 SettingEntry("sound.new_year"),
1485 SettingEntry("sound.disaster"),
1486 SettingEntry("sound.vehicle"),
1487 SettingEntry("sound.ambient"),
1489 /** Sound effects sub-page */
1490 static SettingsPage _settings_sound_page
= {_settings_sound
, lengthof(_settings_sound
)};
1492 static SettingEntry _settings_interface_general
[] = {
1493 SettingEntry("gui.osk_activation"),
1494 SettingEntry("gui.hover_delay_ms"),
1495 SettingEntry("gui.errmsg_duration"),
1496 SettingEntry("gui.window_snap_radius"),
1497 SettingEntry("gui.window_soft_limit"),
1498 SettingEntry("gui.right_mouse_wnd_close"),
1500 /** Interface/General sub-page */
1501 static SettingsPage _settings_interface_general_page
= {_settings_interface_general
, lengthof(_settings_interface_general
)};
1503 static SettingEntry _settings_interface_viewports
[] = {
1504 SettingEntry("gui.auto_scrolling"),
1505 SettingEntry("gui.reverse_scroll"),
1506 SettingEntry("gui.smooth_scroll"),
1507 SettingEntry("gui.left_mouse_btn_scrolling"),
1508 /* While the horizontal scrollwheel scrolling is written as general code, only
1509 * the cocoa (OSX) driver generates input for it.
1510 * Since it's also able to completely disable the scrollwheel will we display it on all platforms anyway */
1511 SettingEntry("gui.scrollwheel_scrolling"),
1512 SettingEntry("gui.scrollwheel_multiplier"),
1514 /* We might need to emulate a right mouse button on mac */
1515 SettingEntry("gui.right_mouse_btn_emulation"),
1517 SettingEntry("gui.population_in_label"),
1518 SettingEntry("gui.liveries"),
1519 SettingEntry("construction.train_signal_side"),
1520 SettingEntry("gui.measure_tooltip"),
1521 SettingEntry("gui.loading_indicators"),
1522 SettingEntry("gui.show_track_reservation"),
1524 /** Interface/Viewports sub-page */
1525 static SettingsPage _settings_interface_viewports_page
= {_settings_interface_viewports
, lengthof(_settings_interface_viewports
)};
1527 static SettingEntry _settings_interface_construction
[] = {
1528 SettingEntry("gui.link_terraform_toolbar"),
1529 SettingEntry("gui.enable_signal_gui"),
1530 SettingEntry("gui.persistent_buildingtools"),
1531 SettingEntry("gui.quick_goto"),
1532 SettingEntry("gui.default_rail_type"),
1533 SettingEntry("gui.disable_unsuitable_building"),
1535 /** Interface/Construction sub-page */
1536 static SettingsPage _settings_interface_construction_page
= {_settings_interface_construction
, lengthof(_settings_interface_construction
)};
1538 static SettingEntry _settings_interface
[] = {
1539 SettingEntry(&_settings_interface_general_page
, STR_CONFIG_SETTING_INTERFACE_GENERAL
),
1540 SettingEntry(&_settings_interface_viewports_page
, STR_CONFIG_SETTING_INTERFACE_VIEWPORTS
),
1541 SettingEntry(&_settings_interface_construction_page
, STR_CONFIG_SETTING_INTERFACE_CONSTRUCTION
),
1542 SettingEntry("gui.autosave"),
1543 SettingEntry("gui.toolbar_pos"),
1544 SettingEntry("gui.statusbar_pos"),
1545 SettingEntry("gui.prefer_teamchat"),
1546 SettingEntry("gui.advanced_vehicle_list"),
1547 SettingEntry("gui.timetable_in_ticks"),
1548 SettingEntry("gui.timetable_arrival_departure"),
1549 SettingEntry("gui.expenses_layout"),
1552 /** Interface subpage */
1553 static SettingsPage _settings_interface_page
= {_settings_interface
, lengthof(_settings_interface
)};
1555 static SettingEntry _settings_advisors
[] = {
1556 SettingEntry("gui.coloured_news_year"),
1557 SettingEntry("news_display.general"),
1558 SettingEntry("news_display.new_vehicles"),
1559 SettingEntry("news_display.accident"),
1560 SettingEntry("news_display.company_info"),
1561 SettingEntry("news_display.acceptance"),
1562 SettingEntry("news_display.arrival_player"),
1563 SettingEntry("news_display.arrival_other"),
1564 SettingEntry("news_display.advice"),
1565 SettingEntry("gui.order_review_system"),
1566 SettingEntry("gui.vehicle_income_warn"),
1567 SettingEntry("gui.lost_vehicle_warn"),
1568 SettingEntry("gui.show_finances"),
1569 SettingEntry("news_display.economy"),
1570 SettingEntry("news_display.subsidies"),
1571 SettingEntry("news_display.open"),
1572 SettingEntry("news_display.close"),
1573 SettingEntry("news_display.production_player"),
1574 SettingEntry("news_display.production_other"),
1575 SettingEntry("news_display.production_nobody"),
1577 /** Interface/News sub-page */
1578 static SettingsPage _settings_advisors_page
= {_settings_advisors
, lengthof(_settings_advisors
)};
1580 static SettingEntry _settings_company
[] = {
1581 SettingEntry("gui.semaphore_build_before"),
1582 SettingEntry("gui.default_signal_type"),
1583 SettingEntry("gui.cycle_signal_types"),
1584 SettingEntry("gui.drag_signals_fixed_distance"),
1585 SettingEntry("gui.new_nonstop"),
1586 SettingEntry("gui.stop_location"),
1587 SettingEntry("company.servicing_if_no_breakdowns"),
1588 SettingEntry("company.engine_renew"),
1589 SettingEntry("company.engine_renew_months"),
1590 SettingEntry("company.engine_renew_money"),
1591 SettingEntry("vehicle.servint_ispercent"),
1592 SettingEntry("vehicle.servint_trains"),
1593 SettingEntry("vehicle.servint_roadveh"),
1594 SettingEntry("vehicle.servint_ships"),
1595 SettingEntry("vehicle.servint_aircraft"),
1598 /** Company subpage */
1599 static SettingsPage _settings_company_page
= {_settings_company
, lengthof(_settings_company
)};
1601 static SettingEntry _settings_accounting
[] = {
1602 SettingEntry("economy.inflation"),
1603 SettingEntry("difficulty.initial_interest"),
1604 SettingEntry("difficulty.max_loan"),
1605 SettingEntry("difficulty.subsidy_multiplier"),
1606 SettingEntry("economy.feeder_payment_share"),
1607 SettingEntry("economy.infrastructure_maintenance"),
1608 SettingEntry("difficulty.vehicle_costs"),
1609 SettingEntry("difficulty.construction_cost"),
1611 /** Accounting sub-page */
1612 static SettingsPage _settings_accounting_page
= {_settings_accounting
, lengthof(_settings_accounting
)};
1614 static SettingEntry _settings_vehicles_physics
[] = {
1615 SettingEntry("vehicle.train_acceleration_model"),
1616 SettingEntry("vehicle.train_slope_steepness"),
1617 SettingEntry("vehicle.wagon_speed_limits"),
1618 SettingEntry("vehicle.freight_trains"),
1619 SettingEntry("vehicle.roadveh_acceleration_model"),
1620 SettingEntry("vehicle.roadveh_slope_steepness"),
1621 SettingEntry("vehicle.smoke_amount"),
1622 SettingEntry("vehicle.plane_speed"),
1624 /** Vehicles/Physics sub-page */
1625 static SettingsPage _settings_vehicles_physics_page
= {_settings_vehicles_physics
, lengthof(_settings_vehicles_physics
)};
1627 static SettingEntry _settings_vehicles_routing
[] = {
1628 SettingEntry("difficulty.line_reverse_mode"),
1629 SettingEntry("pf.reverse_at_signals"),
1630 SettingEntry("pf.forbid_90_deg"),
1631 SettingEntry("pf.roadveh_queue"),
1632 SettingEntry("pf.pathfinder_for_ships"),
1634 /** Vehicles/Routing sub-page */
1635 static SettingsPage _settings_vehicles_routing_page
= {_settings_vehicles_routing
, lengthof(_settings_vehicles_routing
)};
1637 static SettingEntry _settings_vehicles
[] = {
1638 SettingEntry(&_settings_vehicles_physics_page
, STR_CONFIG_SETTING_VEHICLES_PHYSICS
),
1639 SettingEntry(&_settings_vehicles_routing_page
, STR_CONFIG_SETTING_VEHICLES_ROUTING
),
1640 SettingEntry("order.serviceathelipad"),
1641 SettingEntry("vehicle.never_expire_vehicles"),
1642 SettingEntry("vehicle.max_trains"),
1643 SettingEntry("vehicle.max_roadveh"),
1644 SettingEntry("vehicle.max_aircraft"),
1645 SettingEntry("vehicle.max_ships"),
1646 SettingEntry("vehicle.max_train_length"),
1648 /** Vehicles sub-page */
1649 static SettingsPage _settings_vehicles_page
= {_settings_vehicles
, lengthof(_settings_vehicles
)};
1651 static SettingEntry _settings_construction
[] = {
1652 SettingEntry("construction.command_pause_level"),
1653 SettingEntry("construction.build_on_slopes"),
1654 SettingEntry("construction.autoslope"),
1655 SettingEntry("construction.extra_dynamite"),
1656 SettingEntry("construction.max_heightlevel"),
1657 SettingEntry("construction.max_bridge_height"),
1658 SettingEntry("construction.max_bridge_length"),
1659 SettingEntry("construction.max_tunnel_length"),
1660 SettingEntry("construction.freeform_edges"),
1662 /** Construction sub-page */
1663 static SettingsPage _settings_construction_page
= {_settings_construction
, lengthof(_settings_construction
)};
1665 static SettingEntry _settings_stations_cargo
[] = {
1666 SettingEntry("order.improved_load"),
1667 SettingEntry("order.gradual_loading"),
1668 SettingEntry("order.selectgoods"),
1670 /** Cargo handling sub-page */
1671 static SettingsPage _settings_stations_cargo_page
= {_settings_stations_cargo
, lengthof(_settings_stations_cargo
)};
1673 static SettingEntry _settings_stations
[] = {
1674 SettingEntry(&_settings_stations_cargo_page
, STR_CONFIG_SETTING_STATIONS_CARGOHANDLING
),
1675 SettingEntry("station.adjacent_stations"),
1676 SettingEntry("station.distant_join_stations"),
1677 SettingEntry("station.station_spread"),
1678 SettingEntry("construction.road_stop_on_town_road"),
1679 SettingEntry("construction.road_stop_on_competitor_road"),
1680 SettingEntry("station.never_expire_airports"),
1681 SettingEntry("vehicle.disable_elrails"),
1683 /** Limitations sub-page */
1684 static SettingsPage _settings_stations_page
= {_settings_stations
, lengthof(_settings_stations
)};
1686 static SettingEntry _settings_disasters
[] = {
1687 SettingEntry("difficulty.disasters"),
1688 SettingEntry("difficulty.economy"),
1689 SettingEntry("difficulty.vehicle_breakdowns"),
1690 SettingEntry("vehicle.plane_crashes"),
1692 /** Disasters sub-page */
1693 static SettingsPage _settings_disasters_page
= {_settings_disasters
, lengthof(_settings_disasters
)};
1695 static SettingEntry _settings_genworld
[] = {
1696 SettingEntry("game_creation.landscape"),
1697 SettingEntry("game_creation.land_generator"),
1698 SettingEntry("difficulty.terrain_type"),
1699 SettingEntry("game_creation.tgen_smoothness"),
1700 SettingEntry("game_creation.variety"),
1701 SettingEntry("game_creation.snow_line_height"),
1702 SettingEntry("game_creation.amount_of_rivers"),
1703 SettingEntry("game_creation.tree_placer"),
1704 SettingEntry("vehicle.road_side"),
1705 SettingEntry("economy.larger_towns"),
1706 SettingEntry("economy.initial_city_size"),
1707 SettingEntry("economy.town_layout"),
1708 SettingEntry("difficulty.industry_density"),
1709 SettingEntry("gui.pause_on_newgame"),
1712 /** Genworld subpage */
1713 static SettingsPage _settings_genworld_page
= {_settings_genworld
, lengthof(_settings_genworld
)};
1715 static SettingEntry _settings_environment_authorities
[] = {
1716 SettingEntry("difficulty.town_council_tolerance"),
1717 SettingEntry("economy.bribe"),
1718 SettingEntry("economy.exclusive_rights"),
1719 SettingEntry("economy.fund_roads"),
1720 SettingEntry("economy.fund_buildings"),
1721 SettingEntry("economy.station_noise_level"),
1723 /** Environment/Authorities sub-page */
1724 static SettingsPage _settings_environment_authorities_page
= {_settings_environment_authorities
, lengthof(_settings_environment_authorities
)};
1726 static SettingEntry _settings_environment_towns
[] = {
1727 SettingEntry("economy.town_growth_rate"),
1728 SettingEntry("economy.allow_town_roads"),
1729 SettingEntry("economy.allow_town_level_crossings"),
1730 SettingEntry("economy.mod_road_rebuild"),
1731 SettingEntry("economy.found_town"),
1733 /** Environment/Towns sub-page */
1734 static SettingsPage _settings_environment_towns_page
= {_settings_environment_towns
, lengthof(_settings_environment_towns
)};
1736 static SettingEntry _settings_environment_industries
[] = {
1737 SettingEntry("construction.raw_industry_construction"),
1738 SettingEntry("construction.industry_platform"),
1739 SettingEntry("economy.multiple_industry_per_town"),
1740 SettingEntry("game_creation.oil_refinery_limit"),
1741 SettingEntry("economy.smooth_economy"),
1743 /** Environment/Industries subpage */
1744 static SettingsPage _settings_environment_industries_page
= {_settings_environment_industries
, lengthof(_settings_environment_industries
)};
1746 static SettingEntry _settings_environment_cdist
[] = {
1747 SettingEntry("linkgraph.recalc_time"),
1748 SettingEntry("linkgraph.recalc_interval"),
1749 SettingEntry("linkgraph.distribution_pax"),
1750 SettingEntry("linkgraph.distribution_mail"),
1751 SettingEntry("linkgraph.distribution_armoured"),
1752 SettingEntry("linkgraph.distribution_default"),
1753 SettingEntry("linkgraph.accuracy"),
1754 SettingEntry("linkgraph.demand_distance"),
1755 SettingEntry("linkgraph.demand_size"),
1756 SettingEntry("linkgraph.short_path_saturation"),
1758 /** Environment/Cargo Distribution sub-page */
1759 static SettingsPage _settings_environment_cdist_page
= {_settings_environment_cdist
, lengthof(_settings_environment_cdist
)};
1761 static SettingEntry _settings_environment
[] = {
1762 SettingEntry(&_settings_environment_authorities_page
, STR_CONFIG_SETTING_ENVIRONMENT_AUTHORITIES
),
1763 SettingEntry(&_settings_environment_towns_page
, STR_CONFIG_SETTING_ENVIRONMENT_TOWNS
),
1764 SettingEntry(&_settings_environment_industries_page
, STR_CONFIG_SETTING_ENVIRONMENT_INDUSTRIES
),
1765 SettingEntry(&_settings_environment_cdist_page
, STR_CONFIG_SETTING_ENVIRONMENT_CARGODIST
),
1766 SettingEntry("station.modified_catchment"),
1767 SettingEntry("construction.extra_tree_placement"),
1769 /** Environment sub-page */
1770 static SettingsPage _settings_environment_page
= {_settings_environment
, lengthof(_settings_environment
)};
1772 static SettingEntry _settings_ai_npc
[] = {
1773 SettingEntry("script.settings_profile"),
1774 SettingEntry("script.script_max_opcode_till_suspend"),
1775 SettingEntry("difficulty.competitor_speed"),
1776 SettingEntry("ai.ai_in_multiplayer"),
1777 SettingEntry("ai.ai_disable_veh_train"),
1778 SettingEntry("ai.ai_disable_veh_roadveh"),
1779 SettingEntry("ai.ai_disable_veh_aircraft"),
1780 SettingEntry("ai.ai_disable_veh_ship"),
1782 /** Computer players sub-page */
1783 static SettingsPage _settings_ai_npc_page
= {_settings_ai_npc
, lengthof(_settings_ai_npc
)};
1785 static SettingEntry _settings_ai
[] = {
1786 SettingEntry(&_settings_ai_npc_page
, STR_CONFIG_SETTING_AI_NPC
),
1787 SettingEntry("economy.give_money"),
1788 SettingEntry("economy.allow_shares"),
1791 static SettingsPage _settings_ai_page
= {_settings_ai
, lengthof(_settings_ai
)};
1793 static SettingEntry _settings_main
[] = {
1794 SettingEntry(&_settings_localisation_page
, STR_CONFIG_SETTING_LOCALISATION
),
1795 SettingEntry(&_settings_graphics_page
, STR_CONFIG_SETTING_GRAPHICS
),
1796 SettingEntry(&_settings_sound_page
, STR_CONFIG_SETTING_SOUND
),
1797 SettingEntry(&_settings_interface_page
, STR_CONFIG_SETTING_INTERFACE
),
1798 SettingEntry(&_settings_advisors_page
, STR_CONFIG_SETTING_ADVISORS
),
1799 SettingEntry(&_settings_company_page
, STR_CONFIG_SETTING_COMPANY
),
1800 SettingEntry(&_settings_accounting_page
, STR_CONFIG_SETTING_ACCOUNTING
),
1801 SettingEntry(&_settings_vehicles_page
, STR_CONFIG_SETTING_VEHICLES
),
1802 SettingEntry(&_settings_construction_page
, STR_CONFIG_SETTING_INTERFACE_CONSTRUCTION
),
1803 SettingEntry(&_settings_stations_page
, STR_CONFIG_SETTING_STATIONS
),
1804 SettingEntry(&_settings_disasters_page
, STR_CONFIG_SETTING_ACCIDENTS
),
1805 SettingEntry(&_settings_genworld_page
, STR_CONFIG_SETTING_GENWORLD
),
1806 SettingEntry(&_settings_environment_page
, STR_CONFIG_SETTING_ENVIRONMENT
),
1807 SettingEntry(&_settings_ai_page
, STR_CONFIG_SETTING_AI
),
1810 /** Main page, holding all advanced settings */
1811 static SettingsPage _settings_main_page
= {_settings_main
, lengthof(_settings_main
)};
1813 static const StringID _game_settings_restrict_dropdown
[] = {
1814 STR_CONFIG_SETTING_RESTRICT_BASIC
, // RM_BASIC
1815 STR_CONFIG_SETTING_RESTRICT_ADVANCED
, // RM_ADVANCED
1816 STR_CONFIG_SETTING_RESTRICT_ALL
, // RM_ALL
1817 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT
, // RM_CHANGED_AGAINST_DEFAULT
1818 STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW
, // RM_CHANGED_AGAINST_NEW
1820 assert_compile(lengthof(_game_settings_restrict_dropdown
) == RM_END
);
1822 /** Warnings about hidden search results. */
1823 enum WarnHiddenResult
{
1824 WHR_NONE
, ///< Nothing was filtering matches away.
1825 WHR_CATEGORY
, ///< Category setting filtered matches away.
1826 WHR_TYPE
, ///< Type setting filtered matches away.
1827 WHR_CATEGORY_TYPE
, ///< Both category and type settings filtered matches away.
1830 /** Window to edit settings of the game. */
1831 struct GameSettingsWindow
: Window
{
1832 static const int SETTINGTREE_LEFT_OFFSET
= 5; ///< Position of left edge of setting values
1833 static const int SETTINGTREE_RIGHT_OFFSET
= 5; ///< Position of right edge of setting values
1834 static const int SETTINGTREE_TOP_OFFSET
= 5; ///< Position of top edge of setting values
1835 static const int SETTINGTREE_BOTTOM_OFFSET
= 5; ///< Position of bottom edge of setting values
1837 static GameSettings
*settings_ptr
; ///< Pointer to the game settings being displayed and modified.
1839 SettingEntry
*valuewindow_entry
; ///< If non-NULL, pointer to setting for which a value-entering window has been opened.
1840 SettingEntry
*clicked_entry
; ///< If non-NULL, pointer to a clicked numeric setting (with a depressed left or right button).
1841 SettingEntry
*last_clicked
; ///< If non-NULL, pointer to the last clicked setting.
1842 SettingEntry
*valuedropdown_entry
; ///< If non-NULL, pointer to the value for which a dropdown window is currently opened.
1843 bool closing_dropdown
; ///< True, if the dropdown list is currently closing.
1845 SettingFilter filter
; ///< Filter for the list.
1846 QueryStringN
<50> filter_editbox
; ///< Filter editbox;
1847 bool manually_changed_folding
; ///< Whether the user expanded/collapsed something manually.
1848 WarnHiddenResult warn_missing
; ///< Whether and how to warn about missing search results.
1849 int warn_lines
; ///< Number of lines used for warning about missing search results.
1853 GameSettingsWindow (const WindowDesc
*desc
) : Window (desc
),
1854 valuewindow_entry (NULL
), clicked_entry (NULL
),
1855 last_clicked (NULL
), valuedropdown_entry (NULL
),
1856 closing_dropdown (false), filter(), filter_editbox(),
1857 manually_changed_folding (false), warn_missing (WHR_NONE
),
1858 warn_lines (0), vscroll (NULL
)
1860 static bool first_time
= true;
1862 this->warn_missing
= WHR_NONE
;
1863 this->warn_lines
= 0;
1864 this->filter
.mode
= (RestrictionMode
)_settings_client
.gui
.settings_restriction_mode
;
1865 this->filter
.min_cat
= RM_ALL
;
1866 this->filter
.type
= ST_ALL
;
1867 this->filter
.type_hides
= false;
1868 this->settings_ptr
= &GetGameSettings();
1870 _circle_size
= maxdim(GetSpriteSize(SPR_CIRCLE_FOLDED
), GetSpriteSize(SPR_CIRCLE_UNFOLDED
));
1871 /* Build up the dynamic settings-array only once per OpenTTD session */
1873 _settings_main_page
.Init();
1876 _settings_main_page
.FoldAll(); // Close all sub-pages
1879 this->valuewindow_entry
= NULL
; // No setting entry for which a entry window is opened
1880 this->clicked_entry
= NULL
; // No numeric setting buttons are depressed
1881 this->last_clicked
= NULL
;
1882 this->valuedropdown_entry
= NULL
;
1883 this->closing_dropdown
= false;
1884 this->manually_changed_folding
= false;
1886 this->CreateNestedTree();
1887 this->vscroll
= this->GetScrollbar(WID_GS_SCROLLBAR
);
1888 this->InitNested(WN_GAME_OPTIONS_GAME_SETTINGS
);
1890 this->querystrings
[WID_GS_FILTER
] = &this->filter_editbox
;
1891 this->filter_editbox
.cancel_button
= QueryString::ACTION_CLEAR
;
1892 this->SetFocusedWidget(WID_GS_FILTER
);
1894 this->InvalidateData();
1897 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
1900 case WID_GS_OPTIONSPANEL
:
1901 resize
->height
= SETTING_HEIGHT
= max(max
<int>(_circle_size
.height
, SETTING_BUTTON_HEIGHT
), FONT_HEIGHT_NORMAL
) + 1;
1904 size
->height
= 5 * resize
->height
+ SETTINGTREE_TOP_OFFSET
+ SETTINGTREE_BOTTOM_OFFSET
;
1907 case WID_GS_HELP_TEXT
: {
1908 static const StringID setting_types
[] = {
1909 STR_CONFIG_SETTING_TYPE_CLIENT
,
1910 STR_CONFIG_SETTING_TYPE_COMPANY_MENU
, STR_CONFIG_SETTING_TYPE_COMPANY_INGAME
,
1911 STR_CONFIG_SETTING_TYPE_GAME_MENU
, STR_CONFIG_SETTING_TYPE_GAME_INGAME
,
1913 for (uint i
= 0; i
< lengthof(setting_types
); i
++) {
1914 SetDParam(0, setting_types
[i
]);
1915 size
->width
= max(size
->width
, GetStringBoundingBox(STR_CONFIG_SETTING_TYPE
).width
);
1917 size
->height
= 2 * FONT_HEIGHT_NORMAL
+ WD_PAR_VSEP_NORMAL
+
1918 max(size
->height
, _settings_main_page
.GetMaxHelpHeight(size
->width
));
1922 case WID_GS_RESTRICT_CATEGORY
:
1923 case WID_GS_RESTRICT_TYPE
:
1924 size
->width
= max(GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_CATEGORY
).width
, GetStringBoundingBox(STR_CONFIG_SETTING_RESTRICT_TYPE
).width
);
1932 void OnPaint (BlitArea
*dpi
) OVERRIDE
1934 if (this->closing_dropdown
) {
1935 this->closing_dropdown
= false;
1936 assert(this->valuedropdown_entry
!= NULL
);
1937 this->valuedropdown_entry
->SetButtons(0);
1938 this->valuedropdown_entry
= NULL
;
1941 /* Reserve the correct number of lines for the 'some search results are hidden' notice in the central settings display panel. */
1942 const NWidgetBase
*panel
= this->GetWidget
<NWidgetBase
>(WID_GS_OPTIONSPANEL
);
1943 StringID warn_str
= STR_CONFIG_SETTING_CATEGORY_HIDES
- 1 + this->warn_missing
;
1945 if (this->warn_missing
== WHR_NONE
) {
1948 SetDParam(0, _game_settings_restrict_dropdown
[this->filter
.min_cat
]);
1949 new_warn_lines
= GetStringLineCount(warn_str
, panel
->current_x
);
1951 if (this->warn_lines
!= new_warn_lines
) {
1952 this->vscroll
->SetCount(this->vscroll
->GetCount() - this->warn_lines
+ new_warn_lines
);
1953 this->warn_lines
= new_warn_lines
;
1956 this->DrawWidgets (dpi
);
1958 /* Draw the 'some search results are hidden' notice. */
1959 if (this->warn_missing
!= WHR_NONE
) {
1960 const int left
= panel
->pos_x
;
1961 const int right
= left
+ panel
->current_x
- 1;
1962 const int top
= panel
->pos_y
+ WD_FRAMETEXT_TOP
+ (SETTING_HEIGHT
- FONT_HEIGHT_NORMAL
) * this->warn_lines
/ 2;
1963 SetDParam(0, _game_settings_restrict_dropdown
[this->filter
.min_cat
]);
1964 if (this->warn_lines
== 1) {
1965 /* If the warning fits at one line, center it. */
1966 DrawString (dpi
, left
+ WD_FRAMETEXT_LEFT
, right
- WD_FRAMETEXT_RIGHT
, top
, warn_str
, TC_FROMSTRING
, SA_HOR_CENTER
);
1968 DrawStringMultiLine (dpi
, left
+ WD_FRAMERECT_LEFT
, right
- WD_FRAMERECT_RIGHT
, top
, INT32_MAX
, warn_str
, TC_FROMSTRING
, SA_HOR_CENTER
);
1973 virtual void SetStringParameters(int widget
) const
1976 case WID_GS_RESTRICT_DROPDOWN
:
1977 SetDParam(0, _game_settings_restrict_dropdown
[this->filter
.mode
]);
1980 case WID_GS_TYPE_DROPDOWN
:
1981 switch (this->filter
.type
) {
1982 case ST_GAME
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_MENU
: STR_CONFIG_SETTING_TYPE_DROPDOWN_GAME_INGAME
); break;
1983 case ST_COMPANY
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_MENU
: STR_CONFIG_SETTING_TYPE_DROPDOWN_COMPANY_INGAME
); break;
1984 case ST_CLIENT
: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT
); break;
1985 default: SetDParam(0, STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL
); break;
1991 DropDownList
*BuildDropDownList(int widget
) const
1993 DropDownList
*list
= NULL
;
1995 case WID_GS_RESTRICT_DROPDOWN
:
1996 list
= new DropDownList();
1998 for (int mode
= 0; mode
!= RM_END
; mode
++) {
1999 /* If we are in adv. settings screen for the new game's settings,
2000 * we don't want to allow comparing with new game's settings. */
2001 bool disabled
= mode
== RM_CHANGED_AGAINST_NEW
&& settings_ptr
== &_settings_newgame
;
2003 *list
->Append() = new DropDownListStringItem(_game_settings_restrict_dropdown
[mode
], mode
, disabled
);
2007 case WID_GS_TYPE_DROPDOWN
:
2008 list
= new DropDownList();
2009 *list
->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_ALL
, ST_ALL
, false);
2010 *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);
2011 *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);
2012 *list
->Append() = new DropDownListStringItem(STR_CONFIG_SETTING_TYPE_DROPDOWN_CLIENT
, ST_CLIENT
, false);
2018 void DrawWidget (BlitArea
*dpi
, const Rect
&r
, int widget
) const OVERRIDE
2021 case WID_GS_OPTIONSPANEL
: {
2022 int top_pos
= r
.top
+ SETTINGTREE_TOP_OFFSET
+ 1 + this->warn_lines
* SETTING_HEIGHT
;
2023 uint last_row
= this->vscroll
->GetPosition() + this->vscroll
->GetCapacity() - this->warn_lines
;
2024 int next_row
= _settings_main_page
.Draw (settings_ptr
, dpi
, r
.left
+ SETTINGTREE_LEFT_OFFSET
, r
.right
- SETTINGTREE_RIGHT_OFFSET
, top_pos
,
2025 this->vscroll
->GetPosition(), last_row
, this->last_clicked
);
2026 if (next_row
== 0) DrawString (dpi
, r
.left
+ SETTINGTREE_LEFT_OFFSET
, r
.right
- SETTINGTREE_RIGHT_OFFSET
, top_pos
, STR_CONFIG_SETTINGS_NONE
);
2030 case WID_GS_HELP_TEXT
:
2031 if (this->last_clicked
!= NULL
) {
2032 const SettingDesc
*sd
= this->last_clicked
->d
.entry
.setting
;
2035 switch (sd
->GetType()) {
2036 case ST_COMPANY
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_COMPANY_MENU
: STR_CONFIG_SETTING_TYPE_COMPANY_INGAME
); break;
2037 case ST_CLIENT
: SetDParam(0, STR_CONFIG_SETTING_TYPE_CLIENT
); break;
2038 case ST_GAME
: SetDParam(0, _game_mode
== GM_MENU
? STR_CONFIG_SETTING_TYPE_GAME_MENU
: STR_CONFIG_SETTING_TYPE_GAME_INGAME
); break;
2039 default: NOT_REACHED();
2041 DrawString (dpi
, r
.left
, r
.right
, y
, STR_CONFIG_SETTING_TYPE
);
2042 y
+= FONT_HEIGHT_NORMAL
;
2044 int32 default_value
= ReadValue(&sd
->desc
.def
, sd
->save
.conv
);
2045 this->last_clicked
->SetValueDParams(0, default_value
);
2046 DrawString (dpi
, r
.left
, r
.right
, y
, STR_CONFIG_SETTING_DEFAULT_VALUE
);
2047 y
+= FONT_HEIGHT_NORMAL
+ WD_PAR_VSEP_NORMAL
;
2049 DrawStringMultiLine (dpi
, r
.left
, r
.right
, y
, r
.bottom
, this->last_clicked
->GetHelpText(), TC_WHITE
);
2059 * Set the entry that should have its help text displayed, and mark the window dirty so it gets repainted.
2060 * @param pe Setting to display help text of, use \c NULL to stop displaying help of the currently displayed setting.
2062 void SetDisplayedHelpText(SettingEntry
*pe
)
2064 if (this->last_clicked
!= pe
) this->SetDirty();
2065 this->last_clicked
= pe
;
2068 virtual void OnClick(Point pt
, int widget
, int click_count
)
2071 case WID_GS_EXPAND_ALL
:
2072 this->manually_changed_folding
= true;
2073 _settings_main_page
.UnFoldAll();
2074 this->InvalidateData();
2077 case WID_GS_COLLAPSE_ALL
:
2078 this->manually_changed_folding
= true;
2079 _settings_main_page
.FoldAll();
2080 this->InvalidateData();
2083 case WID_GS_RESTRICT_DROPDOWN
: {
2084 DropDownList
*list
= this->BuildDropDownList(widget
);
2086 ShowDropDownList(this, list
, this->filter
.mode
, widget
);
2091 case WID_GS_TYPE_DROPDOWN
: {
2092 DropDownList
*list
= this->BuildDropDownList(widget
);
2094 ShowDropDownList(this, list
, this->filter
.type
, widget
);
2100 if (widget
!= WID_GS_OPTIONSPANEL
) return;
2102 uint btn
= this->vscroll
->GetScrolledRowFromWidget(pt
.y
, this, WID_GS_OPTIONSPANEL
, SETTINGTREE_TOP_OFFSET
);
2103 if (btn
== INT_MAX
|| (int)btn
< this->warn_lines
) return;
2104 btn
-= this->warn_lines
;
2107 SettingEntry
*pe
= _settings_main_page
.FindEntry(btn
, &cur_row
);
2109 if (pe
== NULL
) return; // Clicked below the last setting of the page
2111 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
2112 if (x
< 0) return; // Clicked left of the entry
2114 if ((pe
->flags
& SEF_KIND_MASK
) == SEF_SUBTREE_KIND
) {
2115 this->SetDisplayedHelpText(NULL
);
2116 pe
->d
.sub
.folded
= !pe
->d
.sub
.folded
; // Flip 'folded'-ness of the sub-page
2118 this->manually_changed_folding
= true;
2120 this->InvalidateData();
2124 assert((pe
->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
2125 const SettingDesc
*sd
= pe
->d
.entry
.setting
;
2127 /* return if action is only active in network, or only settable by server */
2128 if (!sd
->IsEditable()) {
2129 this->SetDisplayedHelpText(pe
);
2133 int32 value
= ReadVariable (settings_ptr
, sd
);
2135 /* clicked on the icon on the left side. Either scroller, bool on/off or dropdown */
2136 if (x
< SETTING_BUTTON_WIDTH
&& (sd
->desc
.flags
& SGF_MULTISTRING
)) {
2137 const SettingDescBase
*sdb
= &sd
->desc
;
2138 this->SetDisplayedHelpText(pe
);
2140 if (this->valuedropdown_entry
== pe
) {
2141 /* unclick the dropdown */
2142 HideDropDownMenu(this);
2143 this->closing_dropdown
= false;
2144 this->valuedropdown_entry
->SetButtons(0);
2145 this->valuedropdown_entry
= NULL
;
2147 if (this->valuedropdown_entry
!= NULL
) this->valuedropdown_entry
->SetButtons(0);
2148 this->closing_dropdown
= false;
2150 const NWidgetBase
*wid
= this->GetWidget
<NWidgetBase
>(WID_GS_OPTIONSPANEL
);
2151 int rel_y
= (pt
.y
- (int)wid
->pos_y
- SETTINGTREE_TOP_OFFSET
) % wid
->resize_y
;
2154 wi_rect
.left
= pt
.x
- (_current_text_dir
== TD_RTL
? SETTING_BUTTON_WIDTH
- 1 - x
: x
);
2155 wi_rect
.right
= wi_rect
.left
+ SETTING_BUTTON_WIDTH
- 1;
2156 wi_rect
.top
= pt
.y
- rel_y
+ (SETTING_HEIGHT
- SETTING_BUTTON_HEIGHT
) / 2;
2157 wi_rect
.bottom
= wi_rect
.top
+ SETTING_BUTTON_HEIGHT
- 1;
2159 /* For dropdowns we also have to check the y position thoroughly, the mouse may not above the just opening dropdown */
2160 if (pt
.y
>= wi_rect
.top
&& pt
.y
<= wi_rect
.bottom
) {
2161 this->valuedropdown_entry
= pe
;
2162 this->valuedropdown_entry
->SetButtons(SEF_LEFT_DEPRESSED
);
2164 DropDownList
*list
= new DropDownList();
2165 for (int i
= sdb
->min
; i
<= (int)sdb
->max
; i
++) {
2166 *list
->Append() = new DropDownListStringItem(sdb
->str_val
+ i
- sdb
->min
, i
, false);
2169 ShowDropDownListAt(this, list
, value
, -1, wi_rect
, COLOUR_ORANGE
, true);
2173 } else if (x
< SETTING_BUTTON_WIDTH
) {
2174 this->SetDisplayedHelpText(pe
);
2175 const SettingDescBase
*sdb
= &sd
->desc
;
2176 int32 oldvalue
= value
;
2179 case SDT_BOOLX
: value
^= 1; break;
2182 /* Add a dynamic step-size to the scroller. In a maximum of
2183 * 50-steps you should be able to get from min to max,
2184 * unless specified otherwise in the 'interval' variable
2185 * of the current setting. */
2186 uint32 step
= (sdb
->interval
== 0) ? ((sdb
->max
- sdb
->min
) / 50) : sdb
->interval
;
2187 if (step
== 0) step
= 1;
2189 /* don't allow too fast scrolling */
2190 if ((this->flags
& WF_TIMEOUT
) && this->timeout_timer
> 1) {
2191 _left_button_clicked
= false;
2195 /* Increase or decrease the value and clamp it to extremes */
2196 if (x
>= SETTING_BUTTON_WIDTH
/ 2) {
2199 assert((int32
)sdb
->max
>= 0);
2200 if (value
> (int32
)sdb
->max
) value
= (int32
)sdb
->max
;
2202 if ((uint32
)value
> sdb
->max
) value
= (int32
)sdb
->max
;
2204 if (value
< sdb
->min
) value
= sdb
->min
; // skip between "disabled" and minimum
2207 if (value
< sdb
->min
) value
= (sdb
->flags
& SGF_0ISDISABLED
) ? 0 : sdb
->min
;
2210 /* Set up scroller timeout for numeric values */
2211 if (value
!= oldvalue
) {
2212 if (this->clicked_entry
!= NULL
) { // Release previous buttons if any
2213 this->clicked_entry
->SetButtons(0);
2215 this->clicked_entry
= pe
;
2216 this->clicked_entry
->SetButtons((x
>= SETTING_BUTTON_WIDTH
/ 2) != (_current_text_dir
== TD_RTL
) ? SEF_RIGHT_DEPRESSED
: SEF_LEFT_DEPRESSED
);
2218 _left_button_clicked
= false;
2223 default: NOT_REACHED();
2226 if (value
!= oldvalue
) {
2227 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2228 SetCompanySetting(pe
->d
.entry
.index
, value
);
2230 SetSettingValue(pe
->d
.entry
.index
, value
);
2235 /* Only open editbox if clicked for the second time, and only for types where it is sensible for. */
2236 if (this->last_clicked
== pe
&& sd
->desc
.cmd
!= SDT_BOOLX
&& !(sd
->desc
.flags
& SGF_MULTISTRING
)) {
2237 /* Show the correct currency-translated value */
2238 if (sd
->desc
.flags
& SGF_CURRENCY
) value
*= _currency
->rate
;
2240 this->valuewindow_entry
= pe
;
2241 SetDParam(0, value
);
2242 ShowQueryString(STR_JUST_INT
, STR_CONFIG_SETTING_QUERY_CAPTION
, 10, this, CS_NUMERAL
, QSF_ENABLE_DEFAULT
);
2244 this->SetDisplayedHelpText(pe
);
2248 virtual void OnTimeout()
2250 if (this->clicked_entry
!= NULL
) { // On timeout, release any depressed buttons
2251 this->clicked_entry
->SetButtons(0);
2252 this->clicked_entry
= NULL
;
2257 virtual void OnQueryTextFinished(char *str
)
2259 /* The user pressed cancel */
2260 if (str
== NULL
) return;
2262 assert(this->valuewindow_entry
!= NULL
);
2263 assert((this->valuewindow_entry
->flags
& SEF_KIND_MASK
) == SEF_SETTING_KIND
);
2264 const SettingDesc
*sd
= this->valuewindow_entry
->d
.entry
.setting
;
2267 if (!StrEmpty(str
)) {
2270 /* Save the correct currency-translated value */
2271 if (sd
->desc
.flags
& SGF_CURRENCY
) value
/= _currency
->rate
;
2273 value
= (int32
)(size_t)sd
->desc
.def
;
2276 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2277 SetCompanySetting(this->valuewindow_entry
->d
.entry
.index
, value
);
2279 SetSettingValue(this->valuewindow_entry
->d
.entry
.index
, value
);
2284 virtual void OnDropdownSelect(int widget
, int index
)
2287 case WID_GS_RESTRICT_DROPDOWN
:
2288 this->filter
.mode
= (RestrictionMode
)index
;
2289 if (this->filter
.mode
== RM_CHANGED_AGAINST_DEFAULT
||
2290 this->filter
.mode
== RM_CHANGED_AGAINST_NEW
) {
2292 if (!this->manually_changed_folding
) {
2293 /* Expand all when selecting 'changes'. Update the filter state first, in case it becomes less restrictive in some cases. */
2294 _settings_main_page
.UpdateFilterState(this->filter
, false);
2295 _settings_main_page
.UnFoldAll();
2298 /* Non-'changes' filter. Save as default. */
2299 _settings_client
.gui
.settings_restriction_mode
= this->filter
.mode
;
2301 this->InvalidateData();
2304 case WID_GS_TYPE_DROPDOWN
:
2305 this->filter
.type
= (SettingType
)index
;
2306 this->InvalidateData();
2311 /* Deal with drop down boxes on the panel. */
2312 assert(this->valuedropdown_entry
!= NULL
);
2313 const SettingDesc
*sd
= this->valuedropdown_entry
->d
.entry
.setting
;
2314 assert(sd
->desc
.flags
& SGF_MULTISTRING
);
2316 if ((sd
->desc
.flags
& SGF_PER_COMPANY
) != 0) {
2317 SetCompanySetting(this->valuedropdown_entry
->d
.entry
.index
, index
);
2319 SetSettingValue(this->valuedropdown_entry
->d
.entry
.index
, index
);
2328 virtual void OnDropdownClose(Point pt
, int widget
, int index
, bool instant_close
)
2331 /* Normally the default implementation of OnDropdownClose() takes care of
2332 * a few things. We want that behaviour here too, but only for
2333 * "normal" dropdown boxes. The special dropdown boxes added for every
2334 * setting that needs one can't have this call. */
2335 Window::OnDropdownClose(pt
, widget
, index
, instant_close
);
2337 /* We cannot raise the dropdown button just yet. OnClick needs some hint, whether
2338 * the same dropdown button was clicked again, and then not open the dropdown again.
2339 * So, we only remember that it was closed, and process it on the next OnPaint, which is
2341 assert(this->valuedropdown_entry
!= NULL
);
2342 this->closing_dropdown
= true;
2347 virtual void OnInvalidateData(int data
= 0, bool gui_scope
= true)
2349 if (!gui_scope
) return;
2351 /* Update which settings are to be visible. */
2352 RestrictionMode min_level
= (this->filter
.mode
<= RM_ALL
) ? this->filter
.mode
: RM_BASIC
;
2353 this->filter
.min_cat
= min_level
;
2354 this->filter
.type_hides
= false;
2355 _settings_main_page
.UpdateFilterState(this->filter
, false);
2357 if (this->filter
.string
.IsEmpty()) {
2358 this->warn_missing
= WHR_NONE
;
2359 } else if (min_level
< this->filter
.min_cat
) {
2360 this->warn_missing
= this->filter
.type_hides
? WHR_CATEGORY_TYPE
: WHR_CATEGORY
;
2362 this->warn_missing
= this->filter
.type_hides
? WHR_TYPE
: WHR_NONE
;
2364 this->vscroll
->SetCount(_settings_main_page
.Length() + this->warn_lines
);
2366 if (this->last_clicked
!= NULL
&& !_settings_main_page
.IsVisible(this->last_clicked
)) {
2367 this->SetDisplayedHelpText(NULL
);
2370 bool all_folded
= true;
2371 bool all_unfolded
= true;
2372 _settings_main_page
.GetFoldingState(all_folded
, all_unfolded
);
2373 this->SetWidgetDisabledState(WID_GS_EXPAND_ALL
, all_unfolded
);
2374 this->SetWidgetDisabledState(WID_GS_COLLAPSE_ALL
, all_folded
);
2377 virtual void OnEditboxChanged(int wid
)
2379 if (wid
== WID_GS_FILTER
) {
2380 this->filter
.string
.SetFilterTerm(this->filter_editbox
.GetText());
2381 if (!this->filter
.string
.IsEmpty() && !this->manually_changed_folding
) {
2382 /* User never expanded/collapsed single pages and entered a filter term.
2383 * Expand everything, to save weird expand clicks, */
2384 _settings_main_page
.UnFoldAll();
2386 this->InvalidateData();
2390 virtual void OnResize()
2392 this->vscroll
->SetCapacityFromWidget(this, WID_GS_OPTIONSPANEL
, SETTINGTREE_TOP_OFFSET
+ SETTINGTREE_BOTTOM_OFFSET
);
2396 GameSettings
*GameSettingsWindow::settings_ptr
= NULL
;
2398 static const NWidgetPart _nested_settings_selection_widgets
[] = {
2399 NWidget(NWID_HORIZONTAL
),
2400 NWidget(WWT_CLOSEBOX
, COLOUR_MAUVE
),
2401 NWidget(WWT_CAPTION
, COLOUR_MAUVE
), SetDataTip(STR_CONFIG_SETTING_TREE_CAPTION
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2402 NWidget(WWT_DEFSIZEBOX
, COLOUR_MAUVE
),
2404 NWidget(WWT_PANEL
, COLOUR_MAUVE
),
2405 NWidget(NWID_VERTICAL
), SetPIP(0, WD_PAR_VSEP_NORMAL
, 0), SetPadding(WD_TEXTPANEL_TOP
, 0, WD_TEXTPANEL_BOTTOM
, 0),
2406 NWidget(NWID_HORIZONTAL
), SetPIP(WD_FRAMETEXT_LEFT
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_RIGHT
),
2407 NWidget(WWT_TEXT
, COLOUR_MAUVE
, WID_GS_RESTRICT_CATEGORY
), SetDataTip(STR_CONFIG_SETTING_RESTRICT_CATEGORY
, STR_NULL
),
2408 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),
2410 NWidget(NWID_HORIZONTAL
), SetPIP(WD_FRAMETEXT_LEFT
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_RIGHT
),
2411 NWidget(WWT_TEXT
, COLOUR_MAUVE
, WID_GS_RESTRICT_TYPE
), SetDataTip(STR_CONFIG_SETTING_RESTRICT_TYPE
, STR_NULL
),
2412 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),
2415 NWidget(NWID_HORIZONTAL
), SetPadding(0, 0, WD_TEXTPANEL_BOTTOM
, 0),
2416 SetPIP(WD_FRAMETEXT_LEFT
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_RIGHT
),
2417 NWidget(WWT_TEXT
, COLOUR_MAUVE
), SetFill(0, 1), SetDataTip(STR_CONFIG_SETTING_FILTER_TITLE
, STR_NULL
),
2418 NWidget(WWT_EDITBOX
, COLOUR_MAUVE
, WID_GS_FILTER
), SetFill(1, 0), SetMinimalSize(50, 12), SetResize(1, 0),
2419 SetDataTip(STR_LIST_FILTER_OSKTITLE
, STR_LIST_FILTER_TOOLTIP
),
2422 NWidget(NWID_HORIZONTAL
),
2423 NWidget(WWT_PANEL
, COLOUR_MAUVE
, WID_GS_OPTIONSPANEL
), SetMinimalSize(400, 174), SetScrollbar(WID_GS_SCROLLBAR
), EndContainer(),
2424 NWidget(NWID_VSCROLLBAR
, COLOUR_MAUVE
, WID_GS_SCROLLBAR
),
2426 NWidget(WWT_PANEL
, COLOUR_MAUVE
), SetMinimalSize(400, 40),
2427 NWidget(WWT_EMPTY
, INVALID_COLOUR
, WID_GS_HELP_TEXT
), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
2428 SetPadding(WD_FRAMETEXT_TOP
, WD_FRAMETEXT_RIGHT
, WD_FRAMETEXT_BOTTOM
, WD_FRAMETEXT_LEFT
),
2430 NWidget(NWID_HORIZONTAL
),
2431 NWidget(WWT_PUSHTXTBTN
, COLOUR_MAUVE
, WID_GS_EXPAND_ALL
), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL
, STR_NULL
),
2432 NWidget(WWT_PUSHTXTBTN
, COLOUR_MAUVE
, WID_GS_COLLAPSE_ALL
), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL
, STR_NULL
),
2433 NWidget(WWT_PANEL
, COLOUR_MAUVE
), SetFill(1, 0), SetResize(1, 0),
2435 NWidget(WWT_RESIZEBOX
, COLOUR_MAUVE
),
2439 static WindowDesc::Prefs
_settings_selection_prefs ("settings");
2441 static const WindowDesc
_settings_selection_desc(
2442 WDP_CENTER
, 510, 450,
2443 WC_GAME_OPTIONS
, WC_NONE
,
2445 _nested_settings_selection_widgets
, lengthof(_nested_settings_selection_widgets
),
2446 &_settings_selection_prefs
2449 /** Open advanced settings window. */
2450 void ShowGameSettings()
2452 DeleteWindowByClass(WC_GAME_OPTIONS
);
2453 new GameSettingsWindow(&_settings_selection_desc
);
2458 * Draw [<][>] boxes.
2459 * @param dpi the area to draw on
2460 * @param x the x position to draw
2461 * @param y the y position to draw
2462 * @param button_colour the colour of the button
2463 * @param state 0 = none clicked, 1 = first clicked, 2 = second clicked
2464 * @param clickable_left is the left button clickable?
2465 * @param clickable_right is the right button clickable?
2467 void DrawArrowButtons (BlitArea
*dpi
, int x
, int y
, Colours button_colour
,
2468 byte state
, bool clickable_left
, bool clickable_right
)
2470 int colour
= _colour_gradient
[button_colour
][2];
2471 Dimension dim
= NWidgetScrollbar::GetHorizontalDimension();
2473 DrawFrameRect (dpi
, x
, y
, x
+ dim
.width
- 1, y
+ dim
.height
- 1, button_colour
, (state
== 1) ? FR_LOWERED
: FR_NONE
);
2474 DrawFrameRect (dpi
, x
+ dim
.width
, y
, x
+ dim
.width
+ dim
.width
- 1, y
+ dim
.height
- 1, button_colour
, (state
== 2) ? FR_LOWERED
: FR_NONE
);
2475 DrawSprite (dpi
, SPR_ARROW_LEFT
, PAL_NONE
, x
+ WD_IMGBTN_LEFT
, y
+ WD_IMGBTN_TOP
);
2476 DrawSprite (dpi
, SPR_ARROW_RIGHT
, PAL_NONE
, x
+ WD_IMGBTN_LEFT
+ dim
.width
, y
+ WD_IMGBTN_TOP
);
2478 /* Grey out the buttons that aren't clickable */
2479 bool rtl
= _current_text_dir
== TD_RTL
;
2480 if (rtl
? !clickable_right
: !clickable_left
) {
2481 GfxFillRect (dpi
, x
+ 1, y
, x
+ dim
.width
- 1, y
+ dim
.height
- 2, colour
, FILLRECT_CHECKER
);
2483 if (rtl
? !clickable_left
: !clickable_right
) {
2484 GfxFillRect (dpi
, x
+ dim
.width
+ 1, y
, x
+ dim
.width
+ dim
.width
- 1, y
+ dim
.height
- 2, colour
, FILLRECT_CHECKER
);
2489 * Draw a dropdown button.
2490 * @param dpi the area to draw on
2491 * @param x the x position to draw
2492 * @param y the y position to draw
2493 * @param button_colour the colour of the button
2494 * @param state true = lowered
2495 * @param clickable is the button clickable?
2497 void DrawDropDownButton (BlitArea
*dpi
, int x
, int y
, Colours button_colour
,
2498 bool state
, bool clickable
)
2500 int colour
= _colour_gradient
[button_colour
][2];
2502 DrawFrameRect (dpi
, x
, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 1, button_colour
, state
? FR_LOWERED
: FR_NONE
);
2503 DrawSprite (dpi
, SPR_ARROW_DOWN
, PAL_NONE
, x
+ (SETTING_BUTTON_WIDTH
- NWidgetScrollbar::GetVerticalDimension().width
) / 2 + state
, y
+ 2 + state
);
2506 GfxFillRect (dpi
, x
+ 1, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 2, colour
, FILLRECT_CHECKER
);
2511 * Draw a toggle button.
2512 * @param dpi the area to draw on
2513 * @param x the x position to draw
2514 * @param y the y position to draw
2515 * @param state true = lowered
2516 * @param clickable is the button clickable?
2518 void DrawBoolButton (BlitArea
*dpi
, int x
, int y
, bool state
, bool clickable
)
2520 static const Colours _bool_ctabs
[2][2] = {{COLOUR_CREAM
, COLOUR_RED
}, {COLOUR_DARK_GREEN
, COLOUR_GREEN
}};
2521 DrawFrameRect (dpi
, x
, y
, x
+ SETTING_BUTTON_WIDTH
- 1, y
+ SETTING_BUTTON_HEIGHT
- 1, _bool_ctabs
[state
][clickable
], state
? FR_LOWERED
: FR_NONE
);
2524 struct CustomCurrencyWindow
: Window
{
2527 CustomCurrencyWindow (const WindowDesc
*desc
) :
2528 Window (desc
), query_widget (0)
2535 void SetButtonState()
2537 this->SetWidgetDisabledState(WID_CC_RATE_DOWN
, _custom_currency
.rate
== 1);
2538 this->SetWidgetDisabledState(WID_CC_RATE_UP
, _custom_currency
.rate
== UINT16_MAX
);
2539 this->SetWidgetDisabledState(WID_CC_YEAR_DOWN
, _custom_currency
.to_euro
== CF_NOEURO
);
2540 this->SetWidgetDisabledState(WID_CC_YEAR_UP
, _custom_currency
.to_euro
== MAX_YEAR
);
2543 virtual void SetStringParameters(int widget
) const
2546 case WID_CC_RATE
: SetDParam(0, 1); SetDParam(1, 1); break;
2547 case WID_CC_SEPARATOR
: SetDParamStr(0, _custom_currency
.separator
); break;
2548 case WID_CC_PREFIX
: SetDParamStr(0, _custom_currency
.prefix
); break;
2549 case WID_CC_SUFFIX
: SetDParamStr(0, _custom_currency
.suffix
); break;
2551 SetDParam(0, (_custom_currency
.to_euro
!= CF_NOEURO
) ? STR_CURRENCY_SWITCH_TO_EURO
: STR_CURRENCY_SWITCH_TO_EURO_NEVER
);
2552 SetDParam(1, _custom_currency
.to_euro
);
2555 case WID_CC_PREVIEW
:
2556 SetDParam(0, 10000);
2561 virtual void UpdateWidgetSize(int widget
, Dimension
*size
, const Dimension
&padding
, Dimension
*fill
, Dimension
*resize
)
2564 /* Set the appropriate width for the edit 'buttons' */
2565 case WID_CC_SEPARATOR_EDIT
:
2566 case WID_CC_PREFIX_EDIT
:
2567 case WID_CC_SUFFIX_EDIT
:
2568 size
->width
= this->GetWidget
<NWidgetBase
>(WID_CC_RATE_DOWN
)->smallest_x
+ this->GetWidget
<NWidgetBase
>(WID_CC_RATE_UP
)->smallest_x
;
2571 /* Make sure the window is wide enough for the widest exchange rate */
2574 SetDParam(1, INT32_MAX
);
2575 *size
= GetStringBoundingBox(STR_CURRENCY_EXCHANGE_RATE
);
2580 virtual void OnClick(Point pt
, int widget
, int click_count
)
2585 CharSetFilter afilter
= CS_ALPHANUMERAL
;
2586 QueryStringFlags flags
= QSF_NONE
;
2589 case WID_CC_RATE_DOWN
:
2590 if (_custom_currency
.rate
> 1) _custom_currency
.rate
--;
2591 if (_custom_currency
.rate
== 1) this->DisableWidget(WID_CC_RATE_DOWN
);
2592 this->EnableWidget(WID_CC_RATE_UP
);
2595 case WID_CC_RATE_UP
:
2596 if (_custom_currency
.rate
< UINT16_MAX
) _custom_currency
.rate
++;
2597 if (_custom_currency
.rate
== UINT16_MAX
) this->DisableWidget(WID_CC_RATE_UP
);
2598 this->EnableWidget(WID_CC_RATE_DOWN
);
2602 SetDParam(0, _custom_currency
.rate
);
2606 afilter
= CS_NUMERAL
;
2609 case WID_CC_SEPARATOR_EDIT
:
2610 case WID_CC_SEPARATOR
:
2611 SetDParamStr(0, _custom_currency
.separator
);
2612 str
= STR_JUST_RAW_STRING
;
2614 line
= WID_CC_SEPARATOR
;
2615 flags
= QSF_LEN_IN_CHARS
;
2618 case WID_CC_PREFIX_EDIT
:
2620 SetDParamStr(0, _custom_currency
.prefix
);
2621 str
= STR_JUST_RAW_STRING
;
2623 line
= WID_CC_PREFIX
;
2626 case WID_CC_SUFFIX_EDIT
:
2628 SetDParamStr(0, _custom_currency
.suffix
);
2629 str
= STR_JUST_RAW_STRING
;
2631 line
= WID_CC_SUFFIX
;
2634 case WID_CC_YEAR_DOWN
:
2635 _custom_currency
.to_euro
= (_custom_currency
.to_euro
<= 2000) ? CF_NOEURO
: _custom_currency
.to_euro
- 1;
2636 if (_custom_currency
.to_euro
== CF_NOEURO
) this->DisableWidget(WID_CC_YEAR_DOWN
);
2637 this->EnableWidget(WID_CC_YEAR_UP
);
2640 case WID_CC_YEAR_UP
:
2641 _custom_currency
.to_euro
= Clamp(_custom_currency
.to_euro
+ 1, 2000, MAX_YEAR
);
2642 if (_custom_currency
.to_euro
== MAX_YEAR
) this->DisableWidget(WID_CC_YEAR_UP
);
2643 this->EnableWidget(WID_CC_YEAR_DOWN
);
2647 SetDParam(0, _custom_currency
.to_euro
);
2651 afilter
= CS_NUMERAL
;
2656 this->query_widget
= line
;
2657 ShowQueryString(str
, STR_CURRENCY_CHANGE_PARAMETER
, len
+ 1, this, afilter
, flags
);
2664 virtual void OnQueryTextFinished(char *str
)
2666 if (str
== NULL
) return;
2668 switch (this->query_widget
) {
2670 _custom_currency
.rate
= Clamp(atoi(str
), 1, UINT16_MAX
);
2673 case WID_CC_SEPARATOR
: // Thousands separator
2674 bstrcpy (_custom_currency
.separator
, str
);
2678 bstrcpy (_custom_currency
.prefix
, str
);
2682 bstrcpy (_custom_currency
.suffix
, str
);
2685 case WID_CC_YEAR
: { // Year to switch to euro
2686 int val
= atoi(str
);
2688 _custom_currency
.to_euro
= (val
< 2000 ? CF_NOEURO
: min(val
, MAX_YEAR
));
2692 MarkWholeScreenDirty();
2696 virtual void OnTimeout()
2702 static const NWidgetPart _nested_cust_currency_widgets
[] = {
2703 NWidget(NWID_HORIZONTAL
),
2704 NWidget(WWT_CLOSEBOX
, COLOUR_GREY
),
2705 NWidget(WWT_CAPTION
, COLOUR_GREY
), SetDataTip(STR_CURRENCY_WINDOW
, STR_TOOLTIP_WINDOW_TITLE_DRAG_THIS
),
2707 NWidget(WWT_PANEL
, COLOUR_GREY
),
2708 NWidget(NWID_VERTICAL
, NC_EQUALSIZE
), SetPIP(7, 3, 0),
2709 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2710 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_RATE_DOWN
), SetDataTip(AWV_DECREASE
, STR_CURRENCY_DECREASE_EXCHANGE_RATE_TOOLTIP
),
2711 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_RATE_UP
), SetDataTip(AWV_INCREASE
, STR_CURRENCY_INCREASE_EXCHANGE_RATE_TOOLTIP
),
2712 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2713 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_RATE
), SetDataTip(STR_CURRENCY_EXCHANGE_RATE
, STR_CURRENCY_SET_EXCHANGE_RATE_TOOLTIP
), SetFill(1, 0),
2715 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2716 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_SEPARATOR_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP
), SetFill(0, 1),
2717 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2718 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_SEPARATOR
), SetDataTip(STR_CURRENCY_SEPARATOR
, STR_CURRENCY_SET_CUSTOM_CURRENCY_SEPARATOR_TOOLTIP
), SetFill(1, 0),
2720 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2721 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_PREFIX_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP
), SetFill(0, 1),
2722 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2723 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_PREFIX
), SetDataTip(STR_CURRENCY_PREFIX
, STR_CURRENCY_SET_CUSTOM_CURRENCY_PREFIX_TOOLTIP
), SetFill(1, 0),
2725 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2726 NWidget(WWT_PUSHBTN
, COLOUR_DARK_BLUE
, WID_CC_SUFFIX_EDIT
), SetDataTip(0x0, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP
), SetFill(0, 1),
2727 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2728 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_SUFFIX
), SetDataTip(STR_CURRENCY_SUFFIX
, STR_CURRENCY_SET_CUSTOM_CURRENCY_SUFFIX_TOOLTIP
), SetFill(1, 0),
2730 NWidget(NWID_HORIZONTAL
), SetPIP(10, 0, 5),
2731 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_YEAR_DOWN
), SetDataTip(AWV_DECREASE
, STR_CURRENCY_DECREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
),
2732 NWidget(WWT_PUSHARROWBTN
, COLOUR_YELLOW
, WID_CC_YEAR_UP
), SetDataTip(AWV_INCREASE
, STR_CURRENCY_INCREASE_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
),
2733 NWidget(NWID_SPACER
), SetMinimalSize(5, 0),
2734 NWidget(WWT_TEXT
, COLOUR_BLUE
, WID_CC_YEAR
), SetDataTip(STR_JUST_STRING
, STR_CURRENCY_SET_CUSTOM_CURRENCY_TO_EURO_TOOLTIP
), SetFill(1, 0),
2737 NWidget(WWT_LABEL
, COLOUR_BLUE
, WID_CC_PREVIEW
),
2738 SetDataTip(STR_CURRENCY_PREVIEW
, STR_CURRENCY_CUSTOM_CURRENCY_PREVIEW_TOOLTIP
), SetPadding(15, 1, 18, 2),
2742 static const WindowDesc
_cust_currency_desc(
2744 WC_CUSTOM_CURRENCY
, WC_NONE
,
2746 _nested_cust_currency_widgets
, lengthof(_nested_cust_currency_widgets
)
2749 /** Open custom currency window. */
2750 static void ShowCustCurrency()
2752 DeleteWindowById(WC_CUSTOM_CURRENCY
, 0);
2753 new CustomCurrencyWindow(&_cust_currency_desc
);