mirror of https://github.com/OpenTTD/OpenTTD
Feature: Button to reset game settings to their default values (#8958)
parent
43c465e8f4
commit
ca783d447a
|
@ -1138,6 +1138,7 @@ STR_CONFIG_SETTING_TREE_CAPTION :{WHITE}Settings
|
||||||
STR_CONFIG_SETTING_FILTER_TITLE :{BLACK}Filter string:
|
STR_CONFIG_SETTING_FILTER_TITLE :{BLACK}Filter string:
|
||||||
STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Expand all
|
STR_CONFIG_SETTING_EXPAND_ALL :{BLACK}Expand all
|
||||||
STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Collapse all
|
STR_CONFIG_SETTING_COLLAPSE_ALL :{BLACK}Collapse all
|
||||||
|
STR_CONFIG_SETTING_RESET_ALL :{BLACK}Reset all values
|
||||||
STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(no explanation available)
|
STR_CONFIG_SETTING_NO_EXPLANATION_AVAILABLE_HELPTEXT :(no explanation available)
|
||||||
STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Default value: {ORANGE}{STRING1}
|
STR_CONFIG_SETTING_DEFAULT_VALUE :{LTBLUE}Default value: {ORANGE}{STRING1}
|
||||||
STR_CONFIG_SETTING_TYPE :{LTBLUE}Setting type: {ORANGE}{STRING}
|
STR_CONFIG_SETTING_TYPE :{LTBLUE}Setting type: {ORANGE}{STRING}
|
||||||
|
@ -1146,6 +1147,8 @@ STR_CONFIG_SETTING_TYPE_GAME_MENU :Game setting (s
|
||||||
STR_CONFIG_SETTING_TYPE_GAME_INGAME :Game setting (stored in save; affects only current game)
|
STR_CONFIG_SETTING_TYPE_GAME_INGAME :Game setting (stored in save; affects only current game)
|
||||||
STR_CONFIG_SETTING_TYPE_COMPANY_MENU :Company setting (stored in saves; affects only new games)
|
STR_CONFIG_SETTING_TYPE_COMPANY_MENU :Company setting (stored in saves; affects only new games)
|
||||||
STR_CONFIG_SETTING_TYPE_COMPANY_INGAME :Company setting (stored in save; affects only current company)
|
STR_CONFIG_SETTING_TYPE_COMPANY_INGAME :Company setting (stored in save; affects only current company)
|
||||||
|
STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_CAPTION :{WHITE}Caution!
|
||||||
|
STR_CONFIG_SETTING_RESET_ALL_CONFIRMATION_DIALOG_TEXT :{WHITE}This action will reset all game settings to their default values.{}Are you sure you want to proceed?
|
||||||
|
|
||||||
STR_CONFIG_SETTING_RESTRICT_CATEGORY :{BLACK}Category:
|
STR_CONFIG_SETTING_RESTRICT_CATEGORY :{BLACK}Category:
|
||||||
STR_CONFIG_SETTING_RESTRICT_TYPE :{BLACK}Type:
|
STR_CONFIG_SETTING_RESTRICT_TYPE :{BLACK}Type:
|
||||||
|
|
|
@ -733,6 +733,7 @@ struct BaseSettingEntry {
|
||||||
virtual void Init(byte level = 0);
|
virtual void Init(byte level = 0);
|
||||||
virtual void FoldAll() {}
|
virtual void FoldAll() {}
|
||||||
virtual void UnFoldAll() {}
|
virtual void UnFoldAll() {}
|
||||||
|
virtual void ResetAll() = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set whether this is the last visible entry of the parent node.
|
* Set whether this is the last visible entry of the parent node.
|
||||||
|
@ -769,6 +770,7 @@ struct SettingEntry : BaseSettingEntry {
|
||||||
SettingEntry(const char *name);
|
SettingEntry(const char *name);
|
||||||
|
|
||||||
virtual void Init(byte level = 0);
|
virtual void Init(byte level = 0);
|
||||||
|
virtual void ResetAll();
|
||||||
virtual uint Length() const;
|
virtual uint Length() const;
|
||||||
virtual uint GetMaxHelpHeight(int maxw);
|
virtual uint GetMaxHelpHeight(int maxw);
|
||||||
virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible);
|
virtual bool UpdateFilterState(SettingFilter &filter, bool force_visible);
|
||||||
|
@ -806,6 +808,7 @@ struct SettingsContainer {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Init(byte level = 0);
|
void Init(byte level = 0);
|
||||||
|
void ResetAll();
|
||||||
void FoldAll();
|
void FoldAll();
|
||||||
void UnFoldAll();
|
void UnFoldAll();
|
||||||
|
|
||||||
|
@ -828,6 +831,7 @@ struct SettingsPage : BaseSettingEntry, SettingsContainer {
|
||||||
SettingsPage(StringID title);
|
SettingsPage(StringID title);
|
||||||
|
|
||||||
virtual void Init(byte level = 0);
|
virtual void Init(byte level = 0);
|
||||||
|
virtual void ResetAll();
|
||||||
virtual void FoldAll();
|
virtual void FoldAll();
|
||||||
virtual void UnFoldAll();
|
virtual void UnFoldAll();
|
||||||
|
|
||||||
|
@ -970,6 +974,13 @@ void SettingEntry::Init(byte level)
|
||||||
assert(this->setting != nullptr);
|
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
|
* 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
|
* @param new_val New value for the button flags
|
||||||
|
@ -1081,7 +1092,6 @@ bool SettingEntry::UpdateFilterState(SettingFilter &filter, bool force_visible)
|
||||||
return visible;
|
return visible;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
|
static const void *ResolveVariableAddress(const GameSettings *settings_ptr, const SettingDesc *sd)
|
||||||
{
|
{
|
||||||
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
|
if ((sd->desc.flags & SGF_PER_COMPANY) != 0) {
|
||||||
|
@ -1172,6 +1182,14 @@ void SettingsContainer::Init(byte 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 */
|
/** Recursively close all folds of sub-pages */
|
||||||
void SettingsContainer::FoldAll()
|
void SettingsContainer::FoldAll()
|
||||||
{
|
{
|
||||||
|
@ -1323,6 +1341,14 @@ void SettingsPage::Init(byte level)
|
||||||
SettingsContainer::Init(level + 1);
|
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 */
|
/** Recursively close all (filtered) folds of sub-pages */
|
||||||
void SettingsPage::FoldAll()
|
void SettingsPage::FoldAll()
|
||||||
{
|
{
|
||||||
|
@ -1794,6 +1820,20 @@ enum WarnHiddenResult {
|
||||||
WHR_CATEGORY_TYPE, ///< Both category and type settings 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. */
|
/** Window to edit settings of the game. */
|
||||||
struct GameSettingsWindow : Window {
|
struct GameSettingsWindow : Window {
|
||||||
static const int SETTINGTREE_LEFT_OFFSET = 5; ///< Position of left edge of setting values
|
static const int SETTINGTREE_LEFT_OFFSET = 5; ///< Position of left edge of setting values
|
||||||
|
@ -2031,6 +2071,15 @@ struct GameSettingsWindow : Window {
|
||||||
this->InvalidateData();
|
this->InvalidateData();
|
||||||
break;
|
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: {
|
case WID_GS_RESTRICT_DROPDOWN: {
|
||||||
DropDownList list = this->BuildDropDownList(widget);
|
DropDownList list = this->BuildDropDownList(widget);
|
||||||
if (!list.empty()) {
|
if (!list.empty()) {
|
||||||
|
@ -2387,6 +2436,7 @@ static const NWidgetPart _nested_settings_selection_widgets[] = {
|
||||||
NWidget(NWID_HORIZONTAL),
|
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_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_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),
|
NWidget(WWT_PANEL, COLOUR_MAUVE), SetFill(1, 0), SetResize(1, 0),
|
||||||
EndContainer(),
|
EndContainer(),
|
||||||
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
|
NWidget(WWT_RESIZEBOX, COLOUR_MAUVE),
|
||||||
|
|
|
@ -44,6 +44,7 @@ enum GameSettingsWidgets {
|
||||||
WID_GS_HELP_TEXT, ///< Information area to display help text of the selected option.
|
WID_GS_HELP_TEXT, ///< Information area to display help text of the selected option.
|
||||||
WID_GS_EXPAND_ALL, ///< Expand all button.
|
WID_GS_EXPAND_ALL, ///< Expand all button.
|
||||||
WID_GS_COLLAPSE_ALL, ///< Collapse all button.
|
WID_GS_COLLAPSE_ALL, ///< Collapse all button.
|
||||||
|
WID_GS_RESET_ALL, ///< Reset all button.
|
||||||
WID_GS_RESTRICT_CATEGORY, ///< Label upfront to the category drop-down box to restrict the list of settings to show
|
WID_GS_RESTRICT_CATEGORY, ///< Label upfront to the category drop-down box to restrict the list of settings to show
|
||||||
WID_GS_RESTRICT_TYPE, ///< Label upfront to the type drop-down box to restrict the list of settings to show
|
WID_GS_RESTRICT_TYPE, ///< Label upfront to the type drop-down box to restrict the list of settings to show
|
||||||
WID_GS_RESTRICT_DROPDOWN, ///< The drop down box to restrict the list of settings
|
WID_GS_RESTRICT_DROPDOWN, ///< The drop down box to restrict the list of settings
|
||||||
|
|
Loading…
Reference in New Issue