20#include "table/strings.h"
57 if (row_num == *cur_row)
return this;
91uint
BaseSettingEntry::Draw(
GameSettings *settings_ptr,
int left,
int right,
int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last)
const
94 if (cur_row >= max_row)
return cur_row;
100 int x = rtl ? right : left;
101 if (cur_row >= first_row) {
106 for (uint lvl = 0; lvl < this->
level; lvl++) {
113 GfxDrawLine(x + offset, y, x + offset, bottom_y, colour);
118 this->
DrawSetting(settings_ptr, rtl ? left : x, rtl ? x : right, y,
this == selected);
168 if (mode ==
RM_ALL)
return true;
177 int64_t current_value = sd->
Read(
object);
178 int64_t filter_value;
197 return current_value != filter_value;
271 auto [min_val, max_val] = sd->
GetRange();
275 DrawBoolButton(buttons_left, button_y, COLOUR_YELLOW, COLOUR_MAUVE, value != 0, editable);
296 for (
auto &it : this->
entries) {
304 for (
auto settings_entry : this->
entries) {
305 settings_entry->ResetAll();
312 for (
auto &it : this->
entries) {
320 for (
auto &it : this->
entries) {
332 for (
auto &it : this->
entries) {
333 it->GetFoldingState(all_folded, all_unfolded);
345 bool visible =
false;
346 bool first_visible =
true;
347 for (EntryVector::reverse_iterator it = this->
entries.rbegin(); it != this->entries.rend(); ++it) {
348 visible |= (*it)->UpdateFilterState(filter, force_visible);
349 (*it)->SetLastField(first_visible);
350 if (visible && first_visible) first_visible =
false;
364 for (
const auto &it : this->
entries) {
365 if (it->IsVisible(item))
return true;
377 for (
const auto &it : this->
entries) {
378 length += it->Length();
392 for (
const auto &it : this->
entries) {
409 for (
const auto &it : this->
entries) {
410 biggest = std::max(biggest, it->GetMaxHelpHeight(maxw));
432 for (
const auto &it : this->
entries) {
433 cur_row = it->Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
434 if (cur_row >= max_row)
break;
459 for (
auto settings_entry : this->
entries) {
460 settings_entry->ResetAll();
485 all_unfolded =
false;
509 if (
this == item)
return true;
510 if (this->
folded)
return false;
518 if (this->
folded)
return 1;
532 if (row_num == *cur_row)
return this;
534 if (this->
folded)
return nullptr;
539uint
SettingsPage::Draw(
GameSettings *settings_ptr,
int left,
int right,
int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row, uint parent_last)
const
542 if (cur_row >= max_row)
return cur_row;
544 cur_row =
BaseSettingEntry::Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
548 assert(this->
level < 8 *
sizeof(parent_last));
552 cur_row =
SettingsContainer::Draw(settings_ptr, left, right, y, first_row, max_row, selected, cur_row, parent_last);
573 if (main ==
nullptr) {
586 localisation->
Add(
new SettingEntry(
"gui.date_format_in_default_names"));
654 construction->
Add(
new SettingEntry(
"gui.drag_signals_fixed_distance"));
660 interface->Add(
new SettingEntry(
"gui.prefer_teamchat"));
661 interface->Add(
new SettingEntry(
"gui.advanced_vehicle_list"));
663 interface->Add(
new SettingEntry(
"gui.timetable_arrival_departure"));
664 interface->Add(
new SettingEntry(
"gui.show_newgrf_name"));
665 interface->Add(
new SettingEntry(
"gui.show_cargo_in_vehicle_lists"));
717 accounting->
Add(
new SettingEntry(
"economy.infrastructure_maintenance"));
754 limitations->
Add(
new SettingEntry(
"construction.command_pause_level"));
771 limitations->
Add(
new SettingEntry(
"construction.road_stop_on_town_road"));
772 limitations->
Add(
new SettingEntry(
"construction.road_stop_on_competitor_road"));
773 limitations->
Add(
new SettingEntry(
"construction.crossing_with_competitor"));
775 limitations->
Add(
new SettingEntry(
"order.station_length_loading_penalty"));
784 disasters->
Add(
new SettingEntry(
"order.no_servicing_if_no_breakdowns"));
815 authorities->
Add(
new SettingEntry(
"difficulty.town_council_tolerance"));
842 industries->
Add(
new SettingEntry(
"construction.raw_industry_construction"));
844 industries->
Add(
new SettingEntry(
"economy.multiple_industry_per_town"));
constexpr T SetBit(T &x, const uint8_t y)
Set a bit in a variable.
constexpr bool HasBit(const T x, const uint8_t y)
Checks if a bit in a value is set.
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
Definition of stuff that is very close to a company, like the company struct itself.
CompanyID _local_company
Company controlled by the human player at this client. Can also be COMPANY_SPECTATOR.
Functions related to companies.
int GetCharacterHeight(FontSize size)
Get height of a character for a given font size.
int GetStringHeight(std::string_view str, int maxw, FontSize fontsize)
Calculates height of string (in pixels).
int DrawString(int left, int right, int top, std::string_view str, TextColour colour, StringAlignment align, bool underline, FontSize fontsize)
Draw string, possibly truncated to make it fit in its allocated space.
void DrawSprite(SpriteID img, PaletteID pal, int x, int y, const SubSprite *sub, ZoomLevel zoom)
Draw a sprite, not in a viewport.
@ FS_NORMAL
Index of the normal font in the font tables.
PixelColour GetColourGradient(Colours colour, ColourShade shade)
Get colour gradient palette index.
A number of safeguards to prevent using unsafe methods.
const void * ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd)
Resolve the underlying object where to dynamically load/save a setting to.
SettingsContainer & GetSettingsTree()
Construct settings tree.
Declarations of classes for handling display of individual configuration settings.
const void * ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd)
Resolve the underlying object where to dynamically load/save a setting to.
RestrictionMode
How the list of advanced settings is filtered.
@ RM_CHANGED_AGAINST_DEFAULT
Show only settings which are different compared to default values.
@ RM_ADVANCED
Display settings associated to the "advanced" list.
@ RM_ALL
List all settings regardless of the default/newgame/... values.
@ RM_CHANGED_AGAINST_NEW
Show only settings which are different compared to the user's new game setting values.
@ RM_BASIC
Display settings associated to the "basic" list.
static constexpr SettingEntryFlags SEF_BUTTONS_MASK
Mask for button flags.
@ LeftDepressed
Of a numeric setting entry, the left button is depressed.
@ LastField
This entry is the last one in a (sub-)page.
@ RightDepressed
Of a numeric setting entry, the right button is depressed.
@ Filtered
Entry is hidden by the string filter.
EnumBitSet< SettingEntryFlag, uint8_t > SettingEntryFlags
Bitset of the SettingEntryFlag elements.
bool SetSettingValue(const IntSettingDesc *sd, int32_t value, bool force_newgame)
Top function to save the new value of an element of the Settings struct.
GameSettings _settings_newgame
Game settings for new games (updated from the intro screen).
static const SettingDesc * GetSettingFromName(std::string_view name, const SettingTable &settings)
Given a name of setting, return a setting description from the table.
ClientSettings _settings_client
The current settings for this game.
void DrawArrowButtons(int x, int y, Colours button_colour, uint8_t state, bool clickable_left, bool clickable_right)
Draw [<][>] boxes.
void DrawBoolButton(int x, int y, Colours button_colour, Colours background, bool state, bool clickable)
Draw a toggle button.
void DrawDropDownButton(int x, int y, Colours button_colour, bool state, bool clickable)
Draw a dropdown button.
Functions for setting GUIs.
#define SETTING_BUTTON_WIDTH
Width of setting buttons.
#define SETTING_BUTTON_HEIGHT
Height of setting buttons.
Functions and types used internally for the settings configurations.
@ PerCompany
This setting can be different for each company (saved in company struct).
@ GuiZeroIsSpecial
A value of zero is possible and has a custom string (the one after "strval").
@ GuiDropdown
The value represents a limited number of string-options (internally integer) presented as dropdown.
@ ST_ALL
Used in setting filter to match all types.
@ SC_ADVANCED_LIST
Settings displayed in the list of advanced settings.
@ SC_BASIC_LIST
Settings displayed in the list of basic settings.
GameSettings & GetGameSettings()
Get the settings-object applicable for the current situation: the newgame settings when we're in the ...
This file contains all sprite-related enums and defines.
Definition of base types and functions in a cross-platform compatible way.
Searching and filtering using a stringterm.
std::string GetString(StringID string)
Resolve the given StringID into a std::string with formatting but no parameters.
TextDirection _current_text_dir
Text direction of the currently selected language.
Functions related to OTTD's strings.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
@ TD_RTL
Text is written right-to-left by default.
Data structure describing a single setting in a tab.
bool IsFiltered() const
Check whether an entry is hidden due to filters.
virtual BaseSettingEntry * FindEntry(uint row, uint *cur_row)
Find setting entry at row row_num.
static Dimension circle_size
Dimension of the circle +/- icon.
virtual void Init(uint8_t level=0)
Initialization of a setting entry.
static int line_height
Height of a single setting.
virtual uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row=0, uint parent_last=0) const
Draw a row in the settings panel.
virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const =0
Function to draw setting value (button + text + current value).
SettingEntryFlags flags
Flags of the setting entry.
virtual bool IsVisible(const BaseSettingEntry *item) const
Check whether an entry is visible and not folded or filtered away.
uint8_t level
Nesting level of this setting entry.
All settings together for the game.
Base integer type, including boolean, settings.
std::tuple< int32_t, uint32_t > GetRange() const
Get the min/max range for the setting.
StringID GetTitle() const
Get the title of the setting.
int32_t GetDefaultValue() const
Get the default value of the setting.
StringID GetHelp() const
Get the help text of the setting.
virtual bool IsBoolSetting() const
Check whether this setting is a boolean type setting.
std::pair< StringParameter, StringParameter > GetValueParams(int32_t value) const
Get parameters for drawing the value of the setting.
int32_t Read(const void *object) const
Read the integer from the the actual setting.
Colour for pixel/line drawing.
static Company * Get(auto index)
static bool IsValidID(auto index)
bool IsEditable(bool do_command=false) const
Check whether the setting is editable in the current gamemode.
SettingFlags flags
Handles how a setting would show up in the GUI (text/currency, etc.).
SettingType GetType() const
Return the type of the setting.
const struct IntSettingDesc * AsIntSetting() const
Get the setting description of this setting as an integer setting.
uint Length() const override
Get the number of rows needed to show this entry.
void SetButtons(SettingEntryFlags new_val)
Set the button-depressed flags (SettingsEntryFlag::LeftDepressed and SettingsEntryFlag::RightDepresse...
void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const override
Function to draw setting value (button + text + current value).
bool IsVisibleByRestrictionMode(RestrictionMode mode) const
Checks whether an entry shall be made visible based on the restriction mode.
const std::string_view name
Name of the setting.
uint GetMaxHelpHeight(int maxw) override
Get the biggest height of the help text(s), if the width is at least maxw.
void Init(uint8_t level=0) override
Initialization of a setting entry.
const IntSettingDesc * setting
Setting description of the setting.
bool UpdateFilterState(SettingFilter &filter, bool force_visible) override
Update the filter state.
void ResetAll() override
Resets all settings to their default values.
Filter for settings list.
SettingType type
Filter based on type.
bool type_hides
Whether the type hides filtered strings.
RestrictionMode mode
Filter based on category.
RestrictionMode min_cat
Minimum category needed to display all filtered strings (RM_BASIC, RM_ADVANCED, or RM_ALL).
StringFilter string
Filter string.
Containers for BaseSettingEntry.
bool UpdateFilterState(SettingFilter &filter, bool force_visible)
Update the filter state.
void GetFoldingState(bool &all_folded, bool &all_unfolded) const
Recursively accumulate the folding state of the tree.
uint GetMaxHelpHeight(int maxw)
Get the biggest height of the help texts, if the width is at least maxw.
void ResetAll()
Resets all settings to their default values.
bool IsVisible(const BaseSettingEntry *item) const
Check whether an entry is visible and not folded or filtered away.
void FoldAll()
Recursively close all folds of sub-pages.
void UnFoldAll()
Recursively open all folds of sub-pages.
BaseSettingEntry * FindEntry(uint row, uint *cur_row)
Find the setting entry at row number row_num.
EntryVector entries
Settings on this page.
uint Length() const
Return number of rows needed to display the whole page.
uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row=0, uint parent_last=0) const
Draw a row in the settings panel.
T * Add(T *item)
Add an item to the container.
void Init(uint8_t level=0)
Initialization of an entire setting page.
Data structure describing one page of settings in the settings window.
StringID title
Title of the sub-page.
bool IsVisible(const BaseSettingEntry *item) const override
Check whether an entry is visible and not folded or filtered away.
SettingsPage(StringID title)
Constructor for a sub-page in the 'advanced settings' window.
void UnFoldAll() override
Recursively open all folds of sub-pages.
void FoldAll() override
Recursively close all folds of sub-pages.
uint Length() const override
Get the number of rows needed to show this entry.
BaseSettingEntry * FindEntry(uint row, uint *cur_row) override
Find setting entry at row row_num.
uint Draw(GameSettings *settings_ptr, int left, int right, int y, uint first_row, uint max_row, BaseSettingEntry *selected, uint cur_row=0, uint parent_last=0) const override
Draw a row in the settings panel.
void Init(uint8_t level=0) override
Initialization of a setting entry.
void GetFoldingState(bool &all_folded, bool &all_unfolded) const override
Recursively accumulate the folding state of the tree.
void ResetAll() override
Resets all settings to their default values.
bool folded
Sub-page is folded (not visible except for its title).
bool UpdateFilterState(SettingFilter &filter, bool force_visible) override
Update the filter state.
void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const override
Function to draw setting value (button + text + current value).
bool IsEmpty() const
Check whether any filter words were entered.
void ResetState()
Reset the matching state to process a new item.
bool GetState() const
Get the matching state of the current item.