OpenTTD Source: src/settings_gui.cpp File Reference

OpenTTD Source 15.0-RC2

Data Structures | Macros | Enumerations | Functions | Variables
settings_gui.cpp File Reference

GUI for settings. More...

`#include "stdafx.h"`
`#include "currency.h"`
`#include "error.h"`
`#include "settings_gui.h"`
`#include "textbuf_gui.h"`
`#include "command_func.h"`
`#include "network/network.h"`
`#include "network/network_content.h"`
`#include "town.h"`
`#include "settings_internal.h"`
`#include "strings_func.h"`
`#include "window_func.h"`
`#include "string_func.h"`
`#include "dropdown_type.h"`
`#include "dropdown_func.h"`
`#include "slider_func.h"`
`#include "highscore.h"`
`#include "base_media_base.h"`
`#include "base_media_graphics.h"`
`#include "base_media_music.h"`
`#include "base_media_sounds.h"`
`#include "company_base.h"`
`#include "company_func.h"`
`#include "viewport_func.h"`
`#include "core/geometry_func.hpp"`
`#include "ai/ai.hpp"`
`#include "blitter/factory.hpp"`
`#include "language.h"`
`#include "textfile_gui.h"`
`#include "stringfilter_type.h"`
`#include "querystring_gui.h"`
`#include "fontcache.h"`
`#include "zoom_func.h"`
`#include "rev.h"`
`#include "video/video_driver.hpp"`
`#include "music/music_driver.hpp"`
`#include "gui.h"`
`#include "mixer.h"`
`#include "newgrf_config.h"`
`#include "network/core/config.h"`
`#include "network/network_gui.h"`
`#include "network/network_survey.h"`
`#include "social_integration.h"`
`#include "sound_func.h"`
`#include "settingentry_gui.h"`
`#include "core/string_consumer.hpp"`
`#include "table/strings.h"`
`#include "dropdown_common_type.h"`
`#include "safeguards.h"`

Go to the source code of this file.

## Data Structures
struct | BaseSetTextfileWindow
| Window for displaying the textfile of a BaseSet. More...
class | NWidgetSocialPlugins
struct | GameOptionsWindow
struct | CustomCurrencyWindow

## Enumerations
enum | WarnHiddenResult { WHR_NONE , WHR_CATEGORY , WHR_TYPE , WHR_CATEGORY_TYPE }
| Warnings about hidden search results. More...

## Functions
static uint | GetCurrentResolutionIndex ()
| Get index of the current screen resolution.
static void | ShowCustCurrency ()
| Open custom currency window.
template<class TBaseSet >
void | ShowBaseSetTextfileWindow (Window *parent, TextfileType file_type, const TBaseSet *baseset, StringID content_type)
| Open the BaseSet version of the textfile window.
template<typename TBaseSet >
static std::string | GetListLabel (const TBaseSet *baseset)
| Get string to use when listing this set in the settings window.
template<class T >
DropDownList | BuildSetDropDownList (int *selected_index)
static void | AddCustomRefreshRates ()
| Add the refresh rate from the config and the refresh rates from all the monitors to our list of refresh rates shown in the GUI.
static std::optional< std::string > | ScaleMarkFunc (int, int, int value)
static std::optional< std::string > | VolumeMarkFunc (int, int mark, int value)
std::unique_ptr< NWidgetBase > | MakeNWidgetSocialPlugins ()
| Construct nested container widget for managing the list of social plugins.
static void | ResetAllSettingsConfirmationCallback (Window *w, bool confirmed)
| Callback function for the reset all settings button.
void | ShowGameOptions ()
| Open the game options window.
void | DrawArrowButtons (int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
| Draw [<][>] boxes.
void | DrawUpDownButtons (int x, int y, Colours button_colour, uint8_t state, bool clickable_up, bool clickable_down)
| Draw [^][v] buttons.
void | DrawDropDownButton (int x, int y, Colours button_colour, bool state, bool clickable)
| Draw a dropdown button.
void | DrawBoolButton (int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
| Draw a toggle button.

## Variables
static const StringID | _autosave_dropdown []
static const uint32_t | _autosave_dropdown_to_minutes []
| Available settings for autosave intervals.
std::set< int > | _refresh_rates = { 30, 60, 75, 90, 100, 120, 144, 240 }
static const int | SCALE_NMARKS = (MAX_INTERFACE_SCALE - MIN_INTERFACE_SCALE) / 25 + 1
static const int | VOLUME_NMARKS = 9
static constexpr Colours | GAME_OPTIONS_BACKGROUND = COLOUR_MAUVE
| Colour for background of game options.
static constexpr Colours | GAME_OPTIONS_BUTTON = COLOUR_YELLOW
| Colour for buttons of game options.
static constexpr TextColour | GAME_OPTIONS_FRAME = TC_ORANGE
| Colour for frame text of game options.
static constexpr TextColour | GAME_OPTIONS_LABEL = TC_LIGHT_BLUE
| Colour for label text of game options.
static constexpr TextColour | GAME_OPTIONS_SELECTED = TC_WHITE
| Colour for selected text of game options.
static constexpr std::initializer_list< NWidgetPart > | _nested_social_plugins_widgets
static constexpr std::initializer_list< NWidgetPart > | _nested_social_plugins_none_widgets
static const StringID | _game_settings_restrict_dropdown []
static constexpr std::initializer_list< NWidgetPart > | _nested_game_options_widgets
static WindowDesc | _game_options_desc (WDP_CENTER, "game_options", 0, 0, WC_GAME_OPTIONS, WC_NONE, {}, _nested_game_options_widgets)
static constexpr std::initializer_list< NWidgetPart > | _nested_cust_currency_widgets
static WindowDesc | _cust_currency_desc (WDP_CENTER, {}, 0, 0, WC_CUSTOM_CURRENCY, WC_NONE, {}, _nested_cust_currency_widgets)

## Detailed Description

GUI for settings.

Definition in file settings_gui.cpp.

## Macro Definition Documentation

## ◆ HAS_TRUETYPE_FONT

#define HAS_TRUETYPE_FONT

Definition at line 66 of file settings_gui.cpp.

## Enumeration Type Documentation

## ◆ WarnHiddenResult

enum WarnHiddenResult

Warnings about hidden search results.

Enumerator
WHR_NONE | Nothing was filtering matches away.
WHR_CATEGORY | Category setting filtered matches away.
WHR_TYPE | Type setting filtered matches away.
WHR_CATEGORY_TYPE | Both category and type settings filtered matches away.

Definition at line 374 of file settings_gui.cpp.

## Function Documentation

## ◆ AddCustomRefreshRates()

static void AddCustomRefreshRates | ( |  | ) |
| static

Add the refresh rate from the config and the refresh rates from all the monitors to our list of refresh rates shown in the GUI.

Definition at line 164 of file settings_gui.cpp.

References _settings_client, VideoDriver::GetInstance(), VideoDriver::GetListOfMonitorRefreshRates(), ClientSettings::gui, and GUISettings::refresh_rate.

## ◆ BuildSetDropDownList()

template<class T >

DropDownList BuildSetDropDownList | ( | int * | selected_index | ) |

Definition at line 147 of file settings_gui.cpp.

## ◆ DrawArrowButtons()

void DrawArrowButtons | ( | int | x,
|  | int | y,
|  | Colours | button_colour,
|  | uint8_t | state,
|  | bool | clickable_left,
|  | bool | clickable_right
| ) |  |

Draw [<][>] boxes.

Parameters

  x | the x position to draw
  y | the y position to draw
  button_colour | the colour of the button
  state | 0 = none clicked, 1 = first clicked, 2 = second clicked
  clickable_left | is the left button clickable?
  clickable_right | is the right button clickable?

Definition at line 1866 of file settings_gui.cpp.

References _current_text_dir, WidgetDimensions::bevel, DrawFrameRect(), FILLRECT_CHECKER, GetColourGradient(), GfxFillRect(), Lowered, SA_CENTER, WidgetDimensions::scaled, Rect::Shrink(), and TD_RTL.

Referenced by IndustryViewWindow::DrawInfo(), SettingEntry::DrawSetting(), SelectCompanyManagerFaceWindow::DrawWidget(), GSConfigWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), and ScriptSettingsWindow::DrawWidget().

## ◆ DrawBoolButton()

void DrawBoolButton | ( | int | x,
|  | int | y,
|  | Colours | button_colour,
|  | Colours | background,
|  | bool | state,
|  | bool | clickable
| ) |  |

Draw a toggle button.

Parameters

  x | the x position to draw
  y | the y position to draw
  button_colour | the colour of the button.
  background | background colour.
  state | true = lowered
  clickable | is the button clickable?

Definition at line 1947 of file settings_gui.cpp.

References _current_text_dir, WidgetDimensions::bevel, BorderOnly, DrawFrameRect(), FILLRECT_CHECKER, GetColourGradient(), GfxFillRect(), Lowered, WidgetDimensions::scaled, SETTING_BUTTON_HEIGHT, SETTING_BUTTON_WIDTH, Rect::Shrink(), TD_RTL, and Rect::WithWidth().

Referenced by NWidgetLeaf::Draw(), SettingEntry::DrawSetting(), SelectCompanyManagerFaceWindow::DrawWidget(), GSConfigWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), and ScriptSettingsWindow::DrawWidget().

## ◆ DrawDropDownButton()

void DrawDropDownButton | ( | int | x,
|  | int | y,
|  | Colours | button_colour,
|  | bool | state,
|  | bool | clickable
| ) |  |

Draw a dropdown button.

Parameters

  x | the x position to draw
  y | the y position to draw
  button_colour | the colour of the button
  state | true = lowered
  clickable | is the button clickable?

Definition at line 1924 of file settings_gui.cpp.

References WidgetDimensions::bevel, DrawFrameRect(), FILLRECT_CHECKER, GetColourGradient(), GfxFillRect(), Lowered, SA_CENTER, WidgetDimensions::scaled, SETTING_BUTTON_HEIGHT, SETTING_BUTTON_WIDTH, and Rect::Shrink().

Referenced by SettingEntry::DrawSetting(), GSConfigWindow::DrawWidget(), NewGRFParametersWindow::DrawWidget(), and ScriptSettingsWindow::DrawWidget().

## ◆ DrawUpDownButtons()

void DrawUpDownButtons | ( | int | x,
|  | int | y,
|  | Colours | button_colour,
|  | uint8_t | state,
|  | bool | clickable_up,
|  | bool | clickable_down
| ) |  |

Draw [^][v] buttons.

Parameters

  x | the x position to draw
  y | the y position to draw
  button_colour | the colour of the button
  state | 0 = none clicked, 1 = first clicked, 2 = second clicked
  clickable_up | is the up button clickable?
  clickable_down | is the down button clickable?

Definition at line 1898 of file settings_gui.cpp.

References _current_text_dir, WidgetDimensions::bevel, DrawFrameRect(), FILLRECT_CHECKER, GetColourGradient(), GfxFillRect(), Lowered, SA_CENTER, WidgetDimensions::scaled, SETTING_BUTTON_HEIGHT, SETTING_BUTTON_WIDTH, Rect::Shrink(), TD_RTL, and Rect::WithWidth().

## ◆ GetCurrentResolutionIndex()

static uint GetCurrentResolutionIndex | ( |  | ) |
| static

Get index of the current screen resolution.

Returns
  Index of the current screen resolution if it is a known resolution, _resolutions.size() otherwise.

Definition at line 91 of file settings_gui.cpp.

References _resolutions.

Referenced by GameOptionsWindow::BuildDropDownList(), and GameOptionsWindow::GetWidgetString().

## ◆ GetListLabel()

template<typename TBaseSet >

static std::string GetListLabel | ( | const TBaseSet * | baseset | ) |
| static

Get string to use when listing this set in the settings window.

If there are no invalid files, then this is just the set name, otherwise a string is formatted including the number of invalid files.

Returns
  the string to display.

Definition at line 140 of file settings_gui.cpp.

References GetString().

Referenced by GameOptionsWindow::GetWidgetString().

## ◆ MakeNWidgetSocialPlugins()

std::unique_ptr< NWidgetBase > MakeNWidgetSocialPlugins | ( |  | ) |

Construct nested container widget for managing the list of social plugins.

Definition at line 359 of file settings_gui.cpp.

## ◆ ResetAllSettingsConfirmationCallback()

static void ResetAllSettingsConfirmationCallback | ( | Window * | w,
|  | bool | confirmed
| ) |  |
| static

Callback function for the reset all settings button.

Parameters

  w | Window which is calling this callback
  confirmed | boolean value, true when yes was clicked, false otherwise

Definition at line 386 of file settings_gui.cpp.

References SettingsContainer::FoldAll(), GetSettingsTree(), Window::InvalidateData(), and SettingsContainer::ResetAll().

Referenced by GameOptionsWindow::OnClick().

## ◆ ScaleMarkFunc()

static std::optional< std::string > ScaleMarkFunc | ( | int | ,
|  | int | ,
|  | int | value
| ) |  |
| static

Definition at line 177 of file settings_gui.cpp.

## ◆ ShowBaseSetTextfileWindow()

template<class TBaseSet >

void ShowBaseSetTextfileWindow | ( | Window * | parent,
|  | TextfileType | file_type,
|  | const TBaseSet * | baseset,
|  | StringID | content_type
| ) |  |

Open the BaseSet version of the textfile window.

Parameters

  file_type | The type of textfile to display.
  baseset | The BaseSet to use.
  content_type | STR_CONTENT_TYPE_xxx for title.

Definition at line 127 of file settings_gui.cpp.

References Window::CloseChildWindowById(), and WC_TEXTFILE.

Referenced by GameOptionsWindow::OnClick().

## ◆ ShowCustCurrency()

static void ShowCustCurrency | ( |  | ) |
| static

Open custom currency window.

Definition at line 2194 of file settings_gui.cpp.

References CloseWindowById(), and WC_CUSTOM_CURRENCY.

Referenced by GameOptionsWindow::OnDropdownSelect().

## ◆ ShowGameOptions()

void ShowGameOptions | ( |  | ) |

Open the game options window.

Definition at line 1851 of file settings_gui.cpp.

References CloseWindowByClass(), and WC_GAME_OPTIONS.

Referenced by MenuClickSettings(), SelectGameWindow::OnClick(), MainToolbarWindow::OnHotkey(), and ScenarioEditorToolbarWindow::OnHotkey().

## ◆ VolumeMarkFunc()

static std::optional< std::string > VolumeMarkFunc | ( | int | ,
|  | int | mark,
|  | int | value
| ) |  |
| static

Definition at line 185 of file settings_gui.cpp.

## Variable Documentation

## ◆ _autosave_dropdown

const StringID _autosave_dropdown[]
| static

Initial value:
= {
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_OFF,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_10_MINUTES,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_30_MINUTES,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_60_MINUTES,
STR_GAME_OPTIONS_AUTOSAVE_DROPDOWN_EVERY_120_MINUTES,
INVALID_STRING_ID,
}
INVALID_STRING_ID
static const StringID INVALID_STRING_ID
Constant representing an invalid string (16bit in case it is used in savegames)
Definition strings_type.h:20

Definition at line 69 of file settings_gui.cpp.

## ◆ _autosave_dropdown_to_minutes

const uint32_t _autosave_dropdown_to_minutes[]
| static

Initial value:
= {
0,
10,
30,
60,
120,
}

Available settings for autosave intervals.

Definition at line 79 of file settings_gui.cpp.

Referenced by GameOptionsWindow::BuildDropDownList(), GameOptionsWindow::GetWidgetString(), and GameOptionsWindow::OnDropdownSelect().

## ◆ _game_settings_restrict_dropdown

const StringID _game_settings_restrict_dropdown[]
| static

Initial value:
= {
STR_CONFIG_SETTING_RESTRICT_BASIC,
STR_CONFIG_SETTING_RESTRICT_ADVANCED,
STR_CONFIG_SETTING_RESTRICT_ALL,
STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_DEFAULT,
STR_CONFIG_SETTING_RESTRICT_CHANGED_AGAINST_NEW,
}

Definition at line 364 of file settings_gui.cpp.

## ◆ _nested_cust_currency_widgets

constexpr std::initializer_list<NWidgetPart> _nested_cust_currency_widgets
| staticconstexpr

Definition at line 2145 of file settings_gui.cpp.

## ◆ _nested_game_options_widgets

constexpr std::initializer_list<NWidgetPart> _nested_game_options_widgets
| staticconstexpr

Definition at line 1605 of file settings_gui.cpp.

## ◆ _nested_social_plugins_none_widgets

constexpr std::initializer_list<NWidgetPart> _nested_social_plugins_none_widgets
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, INVALID_COLOUR), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_GAME_OPTIONS_SOCIAL_PLUGINS_NONE), SetTextStyle(GAME_OPTIONS_LABEL),
EndContainer(),
}
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1219
SetStringTip
constexpr NWidgetPart SetStringTip(StringID string, StringID tip={})
Widget part function for setting the string and tooltip.
Definition widget_type.h:1240
SetTextStyle
constexpr NWidgetPart SetTextStyle(TextColour colour, FontSize size=FS_NORMAL)
Widget part function for setting the text style.
Definition widget_type.h:1198
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1229
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=INVALID_WIDGET)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1424
SetResize
constexpr NWidgetPart SetResize(int16_t dx, int16_t dy)
Widget part function for setting the resize step.
Definition widget_type.h:1145
GAME_OPTIONS_LABEL
static constexpr TextColour GAME_OPTIONS_LABEL
Colour for label text of game options.
Definition settings_gui.cpp:201
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:66
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:49

Definition at line 220 of file settings_gui.cpp.

## ◆ _nested_social_plugins_widgets

constexpr std::initializer_list<NWidgetPart> _nested_social_plugins_widgets
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_FRAME, GAME_OPTIONS_BACKGROUND, WID_GO_SOCIAL_PLUGIN_TITLE), SetTextStyle(GAME_OPTIONS_FRAME),
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
NWidget(WWT_TEXT, INVALID_COLOUR), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_PLATFORM), SetTextStyle(GAME_OPTIONS_LABEL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_GO_SOCIAL_PLUGIN_PLATFORM), SetAlignment(SA_RIGHT),
EndContainer(),
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
NWidget(WWT_TEXT, INVALID_COLOUR), SetResize(1, 0), SetFill(1, 0), SetStringTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE), SetTextStyle(GAME_OPTIONS_LABEL),
NWidget(WWT_TEXT, INVALID_COLOUR, WID_GO_SOCIAL_PLUGIN_STATE), SetAlignment(SA_RIGHT),
EndContainer(),
EndContainer(),
EndContainer(),
}
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:93
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:390
SetPIP
constexpr NWidgetPart SetPIP(uint8_t pre, uint8_t inter, uint8_t post)
Widget part function for setting a pre/inter/post spaces.
Definition widget_type.h:1375
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1208
GAME_OPTIONS_BACKGROUND
static constexpr Colours GAME_OPTIONS_BACKGROUND
Colour for background of game options.
Definition settings_gui.cpp:195
GAME_OPTIONS_FRAME
static constexpr TextColour GAME_OPTIONS_FRAME
Colour for frame text of game options.
Definition settings_gui.cpp:199
WID_GO_SOCIAL_PLUGIN_STATE
@ WID_GO_SOCIAL_PLUGIN_STATE
State of the social plugin.
Definition settings_widget.h:72
WID_GO_SOCIAL_PLUGIN_TITLE
@ WID_GO_SOCIAL_PLUGIN_TITLE
Title of the frame of the social plugin.
Definition settings_widget.h:70
WID_GO_SOCIAL_PLUGIN_PLATFORM
@ WID_GO_SOCIAL_PLUGIN_PLATFORM
Platform of the social plugin.
Definition settings_widget.h:71
WWT_FRAME
@ WWT_FRAME
Frame.
Definition widget_type.h:51

Definition at line 205 of file settings_gui.cpp.

## ◆ _refresh_rates

std::set<int> _refresh_rates = { 30, 60, 75, 90, 100, 120, 144, 240 }

Definition at line 158 of file settings_gui.cpp.

## ◆ GAME_OPTIONS_BACKGROUND

constexpr Colours GAME_OPTIONS_BACKGROUND = COLOUR_MAUVE
| staticconstexpr

Colour for background of game options.

Definition at line 195 of file settings_gui.cpp.

Referenced by GameOptionsWindow::DrawWidget().

## ◆ GAME_OPTIONS_BUTTON

constexpr Colours GAME_OPTIONS_BUTTON = COLOUR_YELLOW
| staticconstexpr

Colour for buttons of game options.

Definition at line 197 of file settings_gui.cpp.

Referenced by GameOptionsWindow::DrawWidget().

## ◆ GAME_OPTIONS_FRAME

constexpr TextColour GAME_OPTIONS_FRAME = TC_ORANGE
| staticconstexpr

Colour for frame text of game options.

Definition at line 199 of file settings_gui.cpp.

## ◆ GAME_OPTIONS_LABEL

constexpr TextColour GAME_OPTIONS_LABEL = TC_LIGHT_BLUE
| staticconstexpr

Colour for label text of game options.

Definition at line 201 of file settings_gui.cpp.

## ◆ GAME_OPTIONS_SELECTED

constexpr TextColour GAME_OPTIONS_SELECTED = TC_WHITE
| staticconstexpr

Colour for selected text of game options.

Definition at line 203 of file settings_gui.cpp.

Referenced by GameOptionsWindow::DrawWidget().

## ◆ SCALE_NMARKS

const int SCALE_NMARKS = (MAX_INTERFACE_SCALE - MIN_INTERFACE_SCALE) / 25 + 1
| static

Definition at line 174 of file settings_gui.cpp.

## ◆ VOLUME_NMARKS

const int VOLUME_NMARKS = 9
| static

Definition at line 175 of file settings_gui.cpp.