diff options
author | SamuXarick <43006711+SamuXarick@users.noreply.github.com> | 2020-12-27 14:05:47 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-27 15:05:47 +0100 |
commit | dc5b8020ccd41053f440371ccaa290ca7a2632b9 (patch) | |
tree | f150eeb411e5acd00d0ccf3217de06dbc145896b /src/script | |
parent | b408fe77f792650ef569f9852165759f960fd52f (diff) | |
download | openttd-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.
Diffstat (limited to 'src/script')
-rw-r--r-- | src/script/script_config.cpp | 20 | ||||
-rw-r--r-- | src/script/script_config.hpp | 5 |
2 files changed, 25 insertions, 0 deletions
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(); |