Changeset - r25120:2de578840f52
[Not reviewed]
master
0 3 0
Didac Perez Parera - 3 years ago 2021-04-06 10:47:44
perez.didac@gmail.com
Feature: Button to reset game settings to their default values (#8958)
3 files changed with 55 insertions and 1 deletions:
0 comments (0 inline, 0 general)
src/lang/english.txt
Show inline comments
 
@@ -1135,20 +1135,23 @@ STR_WARNING_NO_SUITABLE_AI              
 

	
 
# Settings tree window
 
STR_CONFIG_SETTING_TREE_CAPTION                                 :{WHITE}Settings
 
STR_CONFIG_SETTING_FILTER_TITLE                                 :{BLACK}Filter string:
 
STR_CONFIG_SETTING_EXPAND_ALL                                   :{BLACK}Expand 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_DEFAULT_VALUE                                :{LTBLUE}Default value: {ORANGE}{STRING1}
 
STR_CONFIG_SETTING_TYPE                                         :{LTBLUE}Setting type: {ORANGE}{STRING}
 
STR_CONFIG_SETTING_TYPE_CLIENT                                  :Client setting (not stored in saves; affects all games)
 
STR_CONFIG_SETTING_TYPE_GAME_MENU                               :Game setting (stored in saves; affects only new games)
 
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_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_TYPE                                :{BLACK}Type:
 
STR_CONFIG_SETTING_RESTRICT_DROPDOWN_HELPTEXT                   :{BLACK}Restricts the list below using predefined filters
 
STR_CONFIG_SETTING_RESTRICT_BASIC                               :Basic (show only important settings)
 
STR_CONFIG_SETTING_RESTRICT_ADVANCED                            :Advanced (show most settings)
src/settings_gui.cpp
Show inline comments
 
@@ -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(),
 
};
 

	
src/widgets/settings_widget.h
Show inline comments
 
@@ -41,12 +41,13 @@ enum GameSettingsWidgets {
 
	WID_GS_FILTER,             ///< Text filter.
 
	WID_GS_OPTIONSPANEL,       ///< Panel widget containing the option lists.
 
	WID_GS_SCROLLBAR,          ///< Scrollbar.
 
	WID_GS_HELP_TEXT,          ///< Information area to display help text of the selected option.
 
	WID_GS_EXPAND_ALL,         ///< Expand 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_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_TYPE_DROPDOWN,      ///< The drop down box to choose client/game/company/all settings
 
};
 

	
0 comments (0 inline, 0 general)