|
@@ -730,12 +730,13 @@ struct BaseSettingEntry {
|
|
|
BaseSettingEntry() : flags(0), level(0) {}
|
|
|
virtual ~BaseSettingEntry() {}
|
|
|
|
|
|
virtual void Init(byte level = 0);
|
|
|
virtual void FoldAll() {}
|
|
|
virtual void UnFoldAll() {}
|
|
|
virtual void ResetAll() = 0;
|
|
|
|
|
|
/**
|
|
|
* Set whether this is the last visible entry of the parent node.
|
|
|
* @param last_field Value to set
|
|
|
*/
|
|
|
void SetLastField(bool last_field) { if (last_field) SETBITS(this->flags, SEF_LAST_FIELD); else CLRBITS(this->flags, SEF_LAST_FIELD); }
|
|
@@ -766,12 +767,13 @@ struct SettingEntry : BaseSettingEntry {
|
|
|
const SettingDesc *setting; ///< Setting description of the setting
|
|
|
uint index; ///< Index of the setting in the settings table
|
|
|
|
|
|
SettingEntry(const char *name);
|
|
|
|
|
|
virtual void Init(byte level = 0);
|
|
|
virtual void ResetAll();
|
|
|
virtual uint Length() const;
|
|
|
virtual uint GetMaxHelpHeight(int maxw);
|
|
|
virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible);
|
|
|
|
|
|
void SetButtons(byte new_val);
|
|
|
|
|
@@ -803,12 +805,13 @@ struct SettingsContainer {
|
|
|
{
|
|
|
this->entries.push_back(item);
|
|
|
return item;
|
|
|
}
|
|
|
|
|
|
void Init(byte level = 0);
|
|
|
void ResetAll();
|
|
|
void FoldAll();
|
|
|
void UnFoldAll();
|
|
|
|
|
|
uint Length() const;
|
|
|
void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
|
|
|
bool IsVisible(const BaseSettingEntry *item) const;
|
|
@@ -825,12 +828,13 @@ struct SettingsPage : BaseSettingEntry,
|
|
|
StringID title; ///< Title of the sub-page
|
|
|
bool folded; ///< Sub-page is folded (not visible except for its title)
|
|
|
|
|
|
SettingsPage(StringID title);
|
|
|
|
|
|
virtual void Init(byte level = 0);
|
|
|
virtual void ResetAll();
|
|
|
virtual void FoldAll();
|
|
|
virtual void UnFoldAll();
|
|
|
|
|
|
virtual uint Length() const;
|
|
|
virtual void GetFoldingState(bool &all_folded, bool &all_unfolded) const;
|
|
|
virtual bool IsVisible(const BaseSettingEntry *item) const;
|
|
@@ -967,12 +971,19 @@ void SettingEntry::Init(byte level)
|
|
|
{
|
|
|
BaseSettingEntry::Init(level);
|
|
|
this->setting = GetSettingFromName(this->name, &this->index);
|
|
|
assert(this->setting != nullptr);
|
|
|
}
|
|
|
|
|
|
/* Sets the given setting entry to its default value */
|
|
|
void SettingEntry::ResetAll()
|
|
|
{
|
|
|
int32 default_value = ReadValue(&this->setting->desc.def, this->setting->save.conv);
|
|
|
SetSettingValue(this->index, default_value);
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* Set the button-depressed flags (#SEF_LEFT_DEPRESSED and #SEF_RIGHT_DEPRESSED) to a specified value
|
|
|
* @param new_val New value for the button flags
|
|
|
* @see SettingEntryFlags
|
|
|
*/
|
|
|
void SettingEntry::SetButtons(byte new_val)
|
|
@@ -1078,13 +1089,12 @@ bool SettingEntry::UpdateFilterState(Set
|
|
|
}
|
|
|
|
|
|
if (!visible) SETBITS(this->flags, SEF_FILTERED);
|
|
|
return visible;
|
|
|
}
|
|
|
|
|
|
|
|
|
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
|
|
|
{
|
|
|
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
|
|
|
if (Company::IsValidID(_local_company) && _game_mode != GM_MENU) {
|
|
|
return GetVariableAddress(&Company::Get(_local_company)->settings, &sd->save);
|
|
|
} else {
|
|
@@ -1169,12 +1179,20 @@ void SettingsContainer::Init(byte level)
|
|
|
{
|
|
|
for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
|
|
|
(*it)->Init(level);
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/** Resets all settings to their default values */
|
|
|
void SettingsContainer::ResetAll()
|
|
|
{
|
|
|
for (auto settings_entry : this->entries) {
|
|
|
settings_entry->ResetAll();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/** Recursively close all folds of sub-pages */
|
|
|
void SettingsContainer::FoldAll()
|
|
|
{
|
|
|
for (EntryVector::iterator it = this->entries.begin(); it != this->entries.end(); ++it) {
|
|
|
(*it)->FoldAll();
|
|
|
}
|
|
@@ -1320,12 +1338,20 @@ SettingsPage::SettingsPage(StringID titl
|
|
|
void SettingsPage::Init(byte level)
|
|
|
{
|
|
|
BaseSettingEntry::Init(level);
|
|
|
SettingsContainer::Init(level + 1);
|
|
|
}
|
|
|
|
|
|
/** Resets all settings to their default values */
|
|
|
void SettingsPage::ResetAll()
|
|
|
{
|
|
|
for (auto settings_entry : this->entries) {
|
|
|
settings_entry->ResetAll();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/** Recursively close all (filtered) folds of sub-pages */
|
|
|
void SettingsPage::FoldAll()
|
|
|
{
|
|
|
if (this->IsFiltered()) return;
|
|
|
this->folded = true;
|
|
|
|
|
@@ -1791,12 +1817,26 @@ enum WarnHiddenResult {
|
|
|
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.
|
|
|
};
|
|
|
|
|
|
/**
|
|
|
* Callback function for the reset all settings button
|
|
|
* @param w Window which is calling this callback
|
|
|
* @param confirmed boolean value, true when yes was clicked, false otherwise
|
|
|
*/
|
|
|
static void ResetAllSettingsConfirmationCallback(Window *w, bool confirmed)
|
|
|
{
|
|
|
if (confirmed) {
|
|
|
GetSettingsTree().ResetAll();
|
|
|
GetSettingsTree().FoldAll();
|
|
|
w->InvalidateData();
|
|
|
}
|
|
|
}
|
|
|
|
|
|
/** Window to edit settings of the game. */
|
|
|
struct GameSettingsWindow : Window {
|
|
|
static const int SETTINGTREE_LEFT_OFFSET = 5; ///< Position of left edge of setting values
|
|
|
static const int SETTINGTREE_RIGHT_OFFSET = 5; ///< Position of right edge of setting values
|
|
|
static const int SETTINGTREE_TOP_OFFSET = 5; ///< Position of top edge of setting values
|
|
|
static const int SETTINGTREE_BOTTOM_OFFSET = 5; ///< Position of bottom edge of setting values
|
|
@@ -2028,12 +2068,21 @@ struct GameSettingsWindow : Window {
|
|
|
case WID_GS_COLLAPSE_ALL:
|
|
|
this->manually_changed_folding = true;
|
|
|
GetSettingsTree().FoldAll();
|
|
|
this->InvalidateData();
|
|
|
break;
|
|
|
|
|
|
case WID_GS_RESET_ALL:
|
|
|
ShowQuery(
|
|
|
STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_CAPTION,
|
|
|
STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_TEXT,
|
|
|
this,
|
|
|
ResetAllSettingsConfirmationCallback
|
|
|
);
|
|
|
break;
|
|
|
|
|
|
case WID_GS_RESTRICT_DROPDOWN: {
|
|
|
DropDownList list = this->BuildDropDownList(widget);
|
|
|
if (!list.empty()) {
|
|
|
ShowDropDownList(this, std::move(list), this->filter.mode, widget);
|
|
|
}
|
|
|
break;
|
|
@@ -2384,12 +2433,13 @@ static const NWidgetPart _nested_setting
|
|
|
NWidget(WWT_EMPTY, INVALID_COLOUR, WID_GS_HELP_TEXT), SetMinimalSize(300, 25), SetFill(1, 1), SetResize(1, 0),
|
|
|
SetPadding(WD_FRAMETEXT_TOP, WD_FRAMETEXT_RIGHT, WD_FRAMETEXT_BOTTOM, WD_FRAMETEXT_LEFT),
|
|
|
EndContainer(),
|
|
|
NWidget(NWID_HORIZONTAL),
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_EXPAND_ALL), SetDataTip(STR_CONFIG_SETTING_EXPAND_ALL, STR_NULL),
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_COLLAPSE_ALL), SetDataTip(STR_CONFIG_SETTING_COLLAPSE_ALL, STR_NULL),
|
|
|
NWidget(WWT_PUSHTXTBTN, COLOUR_MAUVE, WID_GS_RESET_ALL), SetDataTip(STR_CONFIG_SETTING_RESET_ALL, STR_NULL),
|
|
|
NWidget(WWT_PANEL, COLOUR_MAUVE), SetFill(1, 0), SetResize(1, 0),
|
|
|
EndContainer(),
|
|
|
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
|
|
|
EndContainer(),
|
|
|
};
|
|
|
|