OpenTTD Source 20250312-master-gcdcc6b491d
settingentry_gui.h
Go to the documentation of this file.
1/*
2 * This file is part of OpenTTD.
3 * 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.
4 * 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.
5 * 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/>.
6 */
7
10#ifndef SETTINGENTRY_GUI_H
11#define SETTINGENTRY_GUI_H
12
13#include "core/enum_type.hpp"
14#include "settings_internal.h"
15#include "stringfilter_type.h"
16
18extern int SETTING_HEIGHT;
19
24enum class SettingEntryFlag : uint8_t {
27 LastField,
28 Filtered,
29};
31
33
44
45
53
57 uint8_t level;
58
59 BaseSettingEntry() : flags(), level(0) {}
60 virtual ~BaseSettingEntry() = default;
61
62 virtual void Init(uint8_t level = 0);
63 virtual void FoldAll() {}
64 virtual void UnFoldAll() {}
65 virtual void ResetAll() = 0;
66
71 void SetLastField(bool last_field) { this->flags.Set(SettingEntryFlag::LastField, last_field); }
72
73 virtual uint Length() const = 0;
74 virtual void GetFoldingState([[maybe_unused]] bool &all_folded, [[maybe_unused]] bool &all_unfolded) const {}
75 virtual bool IsVisible(const BaseSettingEntry *item) const;
76 virtual BaseSettingEntry *FindEntry(uint row, uint *cur_row);
77 virtual uint GetMaxHelpHeight([[maybe_unused]] int maxw) { return 0; }
78
83 bool IsFiltered() const { return this->flags.Test(SettingEntryFlag::Filtered); }
84
85 virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible) = 0;
86
87 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;
88
89protected:
90 virtual void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const = 0;
91};
92
95 const char *name;
97
98 SettingEntry(const char *name);
99
100 void Init(uint8_t level = 0) override;
101 void ResetAll() override;
102 uint Length() const override;
103 uint GetMaxHelpHeight(int maxw) override;
104 bool UpdateFilterState(SettingFilter &filter, bool force_visible) override;
105
106 void SetButtons(SettingEntryFlags new_val);
107
108protected:
109 void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const override;
110
111private:
113};
114
117 typedef std::vector<BaseSettingEntry*> EntryVector;
118 EntryVector entries;
119
120 template <typename T>
121 T *Add(T *item)
122 {
123 this->entries.push_back(item);
124 return item;
125 }
126
127 void Init(uint8_t level = 0);
128 void ResetAll();
129 void FoldAll();
130 void UnFoldAll();
131
132 uint Length() const;
133 void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
134 bool IsVisible(const BaseSettingEntry *item) const;
135 BaseSettingEntry *FindEntry(uint row, uint *cur_row);
136 uint GetMaxHelpHeight(int maxw);
137
138 bool UpdateFilterState(SettingFilter &filter, bool force_visible);
139
140 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;
141};
142
146 bool folded;
147
149
150 void Init(uint8_t level = 0) override;
151 void ResetAll() override;
152 void FoldAll() override;
153 void UnFoldAll() override;
154
155 uint Length() const override;
156 void GetFoldingState(bool &all_folded, bool &all_unfolded) const override;
157 bool IsVisible(const BaseSettingEntry *item) const override;
158 BaseSettingEntry *FindEntry(uint row, uint *cur_row) override;
159 uint GetMaxHelpHeight(int maxw) override { return SettingsContainer::GetMaxHelpHeight(maxw); }
160
161 bool UpdateFilterState(SettingFilter &filter, bool force_visible) override;
162
163 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;
164
165protected:
166 void DrawSetting(GameSettings *settings_ptr, int left, int right, int y, bool highlight) const override;
167};
168
170const void *ResolveObject(const GameSettings *settings_ptr, const IntSettingDesc *sd);
171
172#endif /* SETTINGENTRY_GUI_H */
173
constexpr bool Test(Tvalue_type value) const
Test if the value-th bit is set.
constexpr Timpl & Set()
Set all bits.
Type (helpers) for enums.
#define DECLARE_INCREMENT_DECREMENT_OPERATORS(enum_type)
For some enums it is useful to have pre/post increment/decrement operators.
Definition enum_type.hpp:63
int SETTING_HEIGHT
Height of a single setting in the tree view in pixels.
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_END
End for iteration.
@ RM_BASIC
Display settings associated to the "basic" list.
static constexpr SettingEntryFlags SEF_BUTTONS_MASK
Mask for button flags.
SettingEntryFlag
Flags for SettingEntry.
@ 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.
Dimension _circle_size
Dimension of the circle +/- icon. This is here as not all users are within the class of the settings ...
SettingsContainer & GetSettingsTree()
Construct settings tree.
Functions and types used internally for the settings configurations.
SettingType
Type of settings for filtering.
Searching and filtering using a stringterm.
uint32_t StringID
Numeric value that represents a string, independent of the selected language.
Data structure describing a single setting in a tab.
void SetLastField(bool last_field)
Set whether this is the last visible entry of the parent node.
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.
virtual void Init(uint8_t level=0)
Initialization of a setting entry.
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.
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.
Dimensions (a width and height) of a rectangle in 2D.
All settings together for the game.
Base integer type, including boolean, settings.
Standard setting.
uint Length() const override
Return number of rows needed to display the (filtered) entry.
void SetButtons(SettingEntryFlags new_val)
Set the button-depressed flags (#SettingsEntryFlag::LeftDepressed and #SettingsEntryFlag::RightDepres...
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.
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.
const char * name
Name of the setting.
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.
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.
void UnFoldAll() override
Recursively open all (filtered) folds of sub-pages.
void FoldAll() override
Recursively close all (filtered) folds of sub-pages.
uint Length() const override
Return number of rows needed to display the (filtered) 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 an entire setting page.
void GetFoldingState(bool &all_folded, bool &all_unfolded) const override
Recursively accumulate the folding state of the (filtered) 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)
String filter and state.