From 87f0c20bc0746acb2e5a53a1b65b61cb97d8d707 Mon Sep 17 00:00:00 2001 From: Jonathan G Rennison Date: Mon, 3 Jan 2022 00:01:21 +0000 Subject: [PATCH] Add setting flag to run string setting change callbacks on config load --- src/settings.cpp | 4 ++++ src/settings_internal.h | 1 + 2 files changed, 5 insertions(+) diff --git a/src/settings.cpp b/src/settings.cpp index 564a5b4eb3..cc3c311146 100644 --- a/src/settings.cpp +++ b/src/settings.cpp @@ -662,6 +662,10 @@ void StringSettingDesc::ParseValue(const IniItem *item, void *object) const { std::string str = (item == nullptr) ? this->def : item->value.value_or(""); this->MakeValueValid(str); + if (this->flags & SF_RUN_CALLBACKS_ON_PARSE) { + if (this->pre_check != nullptr && !this->pre_check(str)) str = this->def; + if (this->post_callback != nullptr) this->post_callback(str); + } this->Write(object, str); } diff --git a/src/settings_internal.h b/src/settings_internal.h index 117affd840..ed20bf1e4c 100644 --- a/src/settings_internal.h +++ b/src/settings_internal.h @@ -31,6 +31,7 @@ enum SettingFlag : uint32 { SF_ENUM = 1 << 14, ///< the setting can take one of the values given by an array of struct SettingDescEnumEntry SF_NO_NEWGAME = 1 << 15, ///< the setting does not apply and is not shown in a new game context SF_DEC1SCALE = 1 << 16, ///< also display a float representation of the scale of a decimal1 scale parameter + SF_RUN_CALLBACKS_ON_PARSE = 1 << 17, ///< run callbacks when parsing from config file }; DECLARE_ENUM_AS_BIT_SET(SettingFlag)