summaryrefslogtreecommitdiff
path: root/src/settings_internal.h
diff options
context:
space:
mode:
authorrubidium42 <rubidium@openttd.org>2021-05-22 13:39:41 +0200
committerrubidium42 <rubidium42@users.noreply.github.com>2021-05-27 18:49:43 +0200
commitc3cd4a683d34191ff9619ef962060abc1acc5fe3 (patch)
treefab8248d49b6ba84c641df034b979b733d021ec9 /src/settings_internal.h
parentd8125fa46e090f25f3fffbc0202bb971b914a3b4 (diff)
downloadopenttd-c3cd4a683d34191ff9619ef962060abc1acc5fe3.tar.xz
Codechange: make formatting of values into strings a method of SettingDesc
Diffstat (limited to 'src/settings_internal.h')
-rw-r--r--src/settings_internal.h17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/settings_internal.h b/src/settings_internal.h
index 1accc47ed..ee8b59be1 100644
--- a/src/settings_internal.h
+++ b/src/settings_internal.h
@@ -110,6 +110,14 @@ struct SettingDesc {
bool IsEditable(bool do_command = false) const;
SettingType GetType() const;
+
+ /**
+ * Format the value of the setting associated with this object.
+ * @param buf The before of the buffer to format into.
+ * @param last The end of the buffer to format into.
+ * @param object The object the setting is in.
+ */
+ virtual void FormatValue(char *buf, const char *last, const void *object) const = 0;
};
/** Integer type, including boolean, settings. Only these are shown in the settings UI. */
@@ -120,6 +128,8 @@ struct IntSettingDesc : SettingDesc {
SettingDesc(save, name, (void*)(size_t)def, cmd, flags, min, max, interval, many, str, str_help, str_val,
proc, many_cnvt, cat, startup) {}
virtual ~IntSettingDesc() {}
+
+ void FormatValue(char *buf, const char *last, const void *object) const override;
};
/** String settings. */
@@ -128,6 +138,9 @@ struct StringSettingDesc : SettingDesc {
uint32 max_length, OnChange proc) :
SettingDesc(save, name, def, cmd, flags, 0, max_length, 0, nullptr, 0, 0, 0, proc, nullptr, SC_NONE, startup) {}
virtual ~StringSettingDesc() {}
+
+ void FormatValue(char *buf, const char *last, const void *object) const override;
+ const std::string &Read(const void *object) const;
};
/** List/array settings. */
@@ -135,6 +148,8 @@ struct ListSettingDesc : SettingDesc {
ListSettingDesc(SaveLoad save, const char *name, SettingGuiFlag flags, SettingDescType cmd, bool startup, const char *def) :
SettingDesc(save, name, def, cmd, flags, 0, 0, 0, nullptr, 0, 0, 0, proc, nullptr, SC_NONE, startup) {}
virtual ~ListSettingDesc() {}
+
+ void FormatValue(char *buf, const char *last, const void *object) const override;
};
/** Placeholder for settings that have been removed, but might still linger in the savegame. */
@@ -142,6 +157,8 @@ struct NullSettingDesc : SettingDesc {
NullSettingDesc(SaveLoad save) :
SettingDesc(save, "", nullptr, SDT_NULL, SGF_NONE, 0, 0, 0, nullptr, 0, 0, 0, nullptr, nullptr, SC_NONE, false) {}
virtual ~NullSettingDesc() {}
+
+ void FormatValue(char *buf, const char *last, const void *object) const override { NOT_REACHED(); }
};
typedef std::initializer_list<std::unique_ptr<const SettingDesc>> SettingTable;