OpenTTD Source: src/settings_gui.cpp File Reference

OpenTTD Source 15.0-beta1

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 "dropdown_common_type.h"`
`#include "slider_func.h"`
`#include "highscore.h"`
`#include "base_media_base.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 "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 | SettingFilter
| Filter for settings list. More...
struct | BaseSettingEntry
| Data structure describing a single setting in a tab. More...
struct | SettingEntry
| Standard setting. More...
struct | SettingsContainer
| Containers for BaseSettingEntry. More...
struct | SettingsPage
| Data structure describing one page of settings in the settings window. More...
struct | GameSettingsWindow
| Window to edit settings of the game. More...
struct | CustomCurrencyWindow

## Enumerations
enum | SettingEntryFlags { SEF_LEFT_DEPRESSED = 0x01 , SEF_RIGHT_DEPRESSED = 0x02 , SEF_BUTTONS_MASK = (SEF_LEFT_DEPRESSED | SEF_RIGHT_DEPRESSED) , SEF_LAST_FIELD = 0x04 , SEF_FILTERED = 0x08 }
| Flags for SettingEntry. More...
enum | RestrictionMode { RM_BASIC , RM_ADVANCED , RM_ALL , RM_CHANGED_AGAINST_DEFAULT , RM_CHANGED_AGAINST_NEW , RM_END }
| How the list of advanced settings is filtered. More...
enum | WarnHiddenResult { WHR_NONE , WHR_CATEGORY , WHR_TYPE , WHR_CATEGORY_TYPE }
| Warnings about hidden search results. More...

## Functions
static const void * | ResolveObject (const GameSettings *settings_ptr, const IntSettingDesc *sd)
static uint | GetCurrentResolutionIndex ()
| Get index of the current screen resolution.
static void | ShowCustCurrency ()
| Open custom currency window.
template<class TBaseSet >
void | ShowBaseSetTextfileWindow (TextfileType file_type, const TBaseSet *baseset, StringID content_type)
| Open the BaseSet version of the textfile 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 StringID | ScaleMarkFunc (int, int, int value)
static StringID | VolumeMarkFunc (int, int mark, int value)
std::unique_ptr< NWidgetBase > | MakeNWidgetSocialPlugins ()
| Construct nested container widget for managing the list of social plugins.
void | ShowGameOptions ()
| Open the game options window.
static SettingsContainer & | GetSettingsTree ()
| Construct settings tree.
static void | ResetAllSettingsConfirmationCallback (Window *w, bool confirmed)
| Callback function for the reset all settings button.
void | ShowGameSettings ()
| Open advanced settings window.
void | DrawArrowButtons (int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
| Draw [<][>] boxes.
void | DrawDropDownButton (int x, int y, Colours button_colour, bool state, bool clickable)
| Draw a dropdown button.
void | DrawBoolButton (int x, int y, 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.
static Dimension | _circle_size
| Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.
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 NWidgetPart | _nested_social_plugins_widgets []
static constexpr NWidgetPart | _nested_social_plugins_none_widgets []
static constexpr NWidgetPart | _nested_game_options_widgets []
static WindowDesc | _game_options_desc (WDP_CENTER, nullptr, 0, 0, WC_GAME_OPTIONS, WC_NONE, 0, _nested_game_options_widgets)
static int | SETTING_HEIGHT = 11
| Height of a single setting in the tree view in pixels.
static const StringID | _game_settings_restrict_dropdown []
static constexpr NWidgetPart | _nested_settings_selection_widgets []
static WindowDesc | _settings_selection_desc (WDP_CENTER, "settings", 510, 450, WC_GAME_OPTIONS, WC_NONE, 0, _nested_settings_selection_widgets)
static constexpr NWidgetPart | _nested_cust_currency_widgets []
static WindowDesc | _cust_currency_desc (WDP_CENTER, nullptr, 0, 0, WC_CUSTOM_CURRENCY, WC_NONE, 0, _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 58 of file settings_gui.cpp.

## Enumeration Type Documentation

## ◆ RestrictionMode

enum RestrictionMode

How the list of advanced settings is filtered.

Enumerator
RM_BASIC | Display settings associated to the "basic" list.
RM_ADVANCED | Display settings associated to the "advanced" list.
RM_ALL | List all settings regardless of the default/newgame/... values.
RM_CHANGED_AGAINST_DEFAULT | Show only settings which are different compared to default values.
RM_CHANGED_AGAINST_NEW | Show only settings which are different compared to the user's new game setting values.
RM_END | End for iteration.

Definition at line 1222 of file settings_gui.cpp.

## ◆ SettingEntryFlags

enum SettingEntryFlags

Flags for SettingEntry.

Note
  The SEF_BUTTONS_MASK matches expectations of the formal parameter 'state' of DrawArrowButtons

Enumerator
SEF_LEFT_DEPRESSED | Of a numeric setting entry, the left button is depressed.
SEF_RIGHT_DEPRESSED | Of a numeric setting entry, the right button is depressed.
SEF_BUTTONS_MASK | Bit-mask for button flags.
SEF_LAST_FIELD | This entry is the last one in a (sub-)page.
SEF_FILTERED | Entry is hidden by the string filter.

Definition at line 1212 of file settings_gui.cpp.

## ◆ 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 2300 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 146 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 129 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 2927 of file settings_gui.cpp.

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

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

## ◆ DrawBoolButton()

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

Draw a toggle button.

Parameters

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

Definition at line 2979 of file settings_gui.cpp.

References DrawFrameRect(), FR_LOWERED, SETTING_BUTTON_HEIGHT, and SETTING_BUTTON_WIDTH.

Referenced by SettingEntry::DrawSetting(), CheatWindow::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 2958 of file settings_gui.cpp.

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

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

## ◆ 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 87 of file settings_gui.cpp.

References _resolutions.

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

## ◆ GetSettingsTree()

static SettingsContainer & GetSettingsTree | ( |  | ) |
| static

Construct settings tree.

Definition at line 1964 of file settings_gui.cpp.

Referenced by GameSettingsWindow::DrawWidget(), GameSettingsWindow::OnClick(), GameSettingsWindow::OnDropdownSelect(), GameSettingsWindow::OnEditboxChanged(), GameSettingsWindow::OnInvalidateData(), ResetAllSettingsConfirmationCallback(), and GameSettingsWindow::UpdateWidgetSize().

## ◆ MakeNWidgetSocialPlugins()

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

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

Definition at line 352 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 2312 of file settings_gui.cpp.

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

Referenced by GameSettingsWindow::OnClick().

## ◆ ResolveObject()

static const void * ResolveObject | ( | const GameSettings * | settings_ptr,
|  | const IntSettingDesc * | sd
| ) |  |
| static

Definition at line 1590 of file settings_gui.cpp.

## ◆ ScaleMarkFunc()

static StringID ScaleMarkFunc | ( | int | ,
|  | int | ,
|  | int | value
| ) |  |
| static

Definition at line 159 of file settings_gui.cpp.

## ◆ ShowBaseSetTextfileWindow()

template<class TBaseSet >

void ShowBaseSetTextfileWindow | ( | 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 122 of file settings_gui.cpp.

References CloseWindowById(), and WC_TEXTFILE.

Referenced by GameOptionsWindow::OnClick().

## ◆ ShowCustCurrency()

static void ShowCustCurrency | ( |  | ) |
| static

Open custom currency window.

Definition at line 3219 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 1200 of file settings_gui.cpp.

References CloseWindowByClass(), and WC_GAME_OPTIONS.

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

## ◆ ShowGameSettings()

void ShowGameSettings | ( |  | ) |

Open advanced settings window.

Definition at line 2911 of file settings_gui.cpp.

References CloseWindowByClass(), and WC_GAME_OPTIONS.

Referenced by MenuClickSettings(), and SelectGameWindow::OnClick().

## ◆ VolumeMarkFunc()

static StringID VolumeMarkFunc | ( | int | ,
|  | int | mark,
|  | int | value
| ) |  |
| static

Definition at line 169 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:17

Definition at line 61 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 71 of file settings_gui.cpp.

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

## ◆ _circle_size

Dimension _circle_size
| static

Dimension of the circle +/- icon. This is here as not all users are within the class of the settings window.

Definition at line 79 of file settings_gui.cpp.

Referenced by BaseSettingEntry::Draw(), SettingsPage::DrawSetting(), and GameSettingsWindow::UpdateWidgetSize().

## ◆ _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 2290 of file settings_gui.cpp.

## ◆ _nested_cust_currency_widgets

constexpr NWidgetPart _nested_cust_currency_widgets[]
| staticconstexpr

Definition at line 3170 of file settings_gui.cpp.

## ◆ _nested_game_options_widgets

constexpr NWidgetPart _nested_game_options_widgets[]
| staticconstexpr

Definition at line 1010 of file settings_gui.cpp.

## ◆ _nested_settings_selection_widgets

constexpr NWidgetPart _nested_settings_selection_widgets[]
| staticconstexpr

Definition at line 2863 of file settings_gui.cpp.

## ◆ _nested_social_plugins_none_widgets

constexpr NWidgetPart _nested_social_plugins_none_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGINS_NONE, STR_NULL),
EndContainer(),
}
SetFill
constexpr NWidgetPart SetFill(uint16_t fill_x, uint16_t fill_y)
Widget part function for setting filling.
Definition widget_type.h:1181
SetDataTip
constexpr NWidgetPart SetDataTip(uint32_t data, StringID tip)
Widget part function for setting the data and tooltip.
Definition widget_type.h:1202
SetMinimalSize
constexpr NWidgetPart SetMinimalSize(int16_t x, int16_t y)
Widget part function for setting the minimal size.
Definition widget_type.h:1137
NWidget
constexpr NWidgetPart NWidget(WidgetType tp, Colours col, WidgetID idx=-1)
Widget part function for starting a new 'real' widget.
Definition widget_type.h:1320
EndContainer
constexpr NWidgetPart EndContainer()
Widget part function for denoting the end of a container (horizontal, vertical, WWT_FRAME,...
Definition widget_type.h:1191
NWID_HORIZONTAL
@ NWID_HORIZONTAL
Horizontal container.
Definition widget_type.h:75
WWT_TEXT
@ WWT_TEXT
Pure simple text.
Definition widget_type.h:58

Definition at line 193 of file settings_gui.cpp.

## ◆ _nested_social_plugins_widgets

constexpr NWidgetPart _nested_social_plugins_widgets[]
| staticconstexpr

Initial value:
= {
NWidget(NWID_HORIZONTAL),
NWidget(WWT_FRAME, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_TITLE), SetDataTip(STR_JUST_STRING2, STR_NULL),
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_PLATFORM, STR_NULL),
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_PLATFORM), SetMinimalSize(100, 12), SetDataTip(STR_JUST_RAW_STRING, STR_NULL), SetAlignment(SA_RIGHT),
EndContainer(),
NWidget(NWID_HORIZONTAL), SetPIP(0, WidgetDimensions::unscaled.hsep_normal, 0),
NWidget(WWT_TEXT, COLOUR_GREY), SetMinimalSize(0, 12), SetFill(1, 0), SetDataTip(STR_GAME_OPTIONS_SOCIAL_PLUGIN_STATE, STR_NULL),
NWidget(WWT_TEXT, COLOUR_GREY, WID_GO_SOCIAL_PLUGIN_STATE), SetMinimalSize(100, 12), SetDataTip(STR_JUST_STRING1, STR_NULL), SetAlignment(SA_RIGHT),
EndContainer(),
EndContainer(),
EndContainer(),
}
WidgetDimensions::unscaled
static const WidgetDimensions unscaled
Unscaled widget dimensions.
Definition window_gui.h:96
SA_RIGHT
@ SA_RIGHT
Right align the text (must be a single bit).
Definition gfx_type.h:345
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:1271
SetAlignment
constexpr NWidgetPart SetAlignment(StringAlignment align)
Widget part function for setting the alignment of text/images.
Definition widget_type.h:1170
WID_GO_SOCIAL_PLUGIN_STATE
@ WID_GO_SOCIAL_PLUGIN_STATE
State of the social plugin.
Definition settings_widget.h:63
WID_GO_SOCIAL_PLUGIN_TITLE
@ WID_GO_SOCIAL_PLUGIN_TITLE
Title of the frame of the social plugin.
Definition settings_widget.h:61
WID_GO_SOCIAL_PLUGIN_PLATFORM
@ WID_GO_SOCIAL_PLUGIN_PLATFORM
Platform of the social plugin.
Definition settings_widget.h:62
WWT_FRAME
@ WWT_FRAME
Frame.
Definition widget_type.h:60

Definition at line 178 of file settings_gui.cpp.

## ◆ _refresh_rates

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

Definition at line 140 of file settings_gui.cpp.

## ◆ SCALE_NMARKS

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

Definition at line 156 of file settings_gui.cpp.

## ◆ SETTING_HEIGHT

int SETTING_HEIGHT = 11
| static

Height of a single setting in the tree view in pixels.

Definition at line 1206 of file settings_gui.cpp.

Referenced by BaseSettingEntry::Draw(), SettingEntry::DrawSetting(), SettingsPage::DrawSetting(), GameSettingsWindow::DrawWidget(), GameSettingsWindow::OnClick(), and GameSettingsWindow::UpdateWidgetSize().

## ◆ VOLUME_NMARKS

const int VOLUME_NMARKS = 9
| static

Definition at line 157 of file settings_gui.cpp.