summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSamuXarick <43006711+SamuXarick@users.noreply.github.com>2020-12-27 14:05:47 +0000
committerGitHub <noreply@github.com>2020-12-27 15:05:47 +0100
commitdc5b8020ccd41053f440371ccaa290ca7a2632b9 (patch)
treef150eeb411e5acd00d0ccf3217de06dbc145896b
parentb408fe77f792650ef569f9852165759f960fd52f (diff)
downloadopenttd-dc5b8020ccd41053f440371ccaa290ca7a2632b9.tar.xz
Fix #6452: Reset only editable and visible settings from GUI (#7890)
Also enables the Reset button while in-game for AI configs.
-rw-r--r--src/ai/ai_gui.cpp8
-rw-r--r--src/script/script_config.cpp20
-rw-r--r--src/script/script_config.hpp5
3 files changed, 27 insertions, 6 deletions
diff --git a/src/ai/ai_gui.cpp b/src/ai/ai_gui.cpp
index f1ee03fc1..9e16ec3ec 100644
--- a/src/ai/ai_gui.cpp
+++ b/src/ai/ai_gui.cpp
@@ -315,8 +315,6 @@ struct AISettingsWindow : public Window {
this->vscroll = this->GetScrollbar(WID_AIS_SCROLLBAR);
this->FinishInitNested(slot); // Initializes 'this->line_height' as side effect.
- this->SetWidgetDisabledState(WID_AIS_RESET, _game_mode != GM_MENU && Company::IsValidID(this->slot));
-
this->RebuildVisibleSettings();
}
@@ -524,10 +522,8 @@ struct AISettingsWindow : public Window {
break;
case WID_AIS_RESET:
- if (_game_mode == GM_MENU || !Company::IsValidID(this->slot)) {
- this->ai_config->ResetSettings();
- this->SetDirty();
- }
+ this->ai_config->ResetEditableSettings(_game_mode == GM_MENU || ((this->slot != OWNER_DEITY) && !Company::IsValidID(this->slot)));
+ this->SetDirty();
break;
}
}
diff --git a/src/script/script_config.cpp b/src/script/script_config.cpp
index 8de141e66..9bb953c4c 100644
--- a/src/script/script_config.cpp
+++ b/src/script/script_config.cpp
@@ -127,6 +127,26 @@ void ScriptConfig::ResetSettings()
this->settings.clear();
}
+void ScriptConfig::ResetEditableSettings(bool yet_to_start)
+{
+ if (this->info == nullptr) return ResetSettings();
+
+ for (SettingValueList::iterator it = this->settings.begin(); it != this->settings.end();) {
+ const ScriptConfigItem *config_item = this->info->GetConfigItem(it->first);
+ assert(config_item != nullptr);
+
+ bool editable = yet_to_start || (config_item->flags & SCRIPTCONFIG_INGAME) != 0;
+ bool visible = _settings_client.gui.ai_developer_tools || (config_item->flags & SCRIPTCONFIG_DEVELOPER) == 0;
+
+ if (editable && visible) {
+ free(it->first);
+ it = this->settings.erase(it);
+ } else {
+ it++;
+ }
+ }
+}
+
void ScriptConfig::AddRandomDeviation()
{
for (const auto &item : *this->GetConfigList()) {
diff --git a/src/script/script_config.hpp b/src/script/script_config.hpp
index 31004caba..be231fcdc 100644
--- a/src/script/script_config.hpp
+++ b/src/script/script_config.hpp
@@ -135,6 +135,11 @@ public:
void ResetSettings();
/**
+ * Reset only editable and visible settings to their default value.
+ */
+ void ResetEditableSettings(bool yet_to_start);
+
+ /**
* Randomize all settings the Script requested to be randomized.
*/
virtual void AddRandomDeviation();