From 566d992f763352f88503d98e2595b5560dd7833d Mon Sep 17 00:00:00 2001 From: Satori Date: Sat, 2 Oct 2021 15:34:04 +0100 Subject: [PATCH] [App/Settings] Add support for range input and adjust number settings impl --- assets/settings.xml | 24 +++- assets/settings_schema.xsd | 148 ++++++++++------------ src/xenia/app/settings/settings.h | 52 +++++++- src/xenia/app/settings/settings_loader.cc | 42 +++++- 4 files changed, 173 insertions(+), 93 deletions(-) diff --git a/assets/settings.xml b/assets/settings.xml index 6383c399c..7ac826d4e 100644 --- a/assets/settings.xml +++ b/assets/settings.xml @@ -1,4 +1,5 @@ + @@ -79,6 +80,11 @@ Enable Discord Rich Presence in Xenia discord + + Discord Rich Presence 2 + Enable Discord Rich Presence in Xenia + discord + Show game Icon in Taskbar Show the currently loaded game's icon in the Taskbar @@ -136,12 +142,28 @@ log_file + + + Test int32 + A test int slider + test_int + int32 + 0 + 100 + + - + + + Resolution scale + Renders the game at native resolution or higher resolutions. Very GPU intensive. May cause issues in some games. + + + diff --git a/assets/settings_schema.xsd b/assets/settings_schema.xsd index bf41dba1d..1986b8368 100644 --- a/assets/settings_schema.xsd +++ b/assets/settings_schema.xsd @@ -1,90 +1,70 @@ - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + \ No newline at end of file diff --git a/src/xenia/app/settings/settings.h b/src/xenia/app/settings/settings.h index 0c066f1de..9294f1b1a 100644 --- a/src/xenia/app/settings/settings.h +++ b/src/xenia/app/settings/settings.h @@ -115,9 +115,8 @@ inline int number_value_to_int(NumberValue v) { template class NumberSettingsItem : public ISettingsItem { - public: - struct ValueVisitor { - ValueVisitor(NumberSettingsItem* item) : item(item) {} + struct ValueUpdater { + ValueUpdater(NumberSettingsItem* item) : item(item) {} bool operator()(int8_t value) { return update(ValueType::Int8, value); } bool operator()(int16_t value) { return update(ValueType::Int16, value); } @@ -144,6 +143,7 @@ class NumberSettingsItem : public ISettingsItem { NumberSettingsItem* item; }; + public: NumberSettingsItem(ValueType value_type, const std::string& title, const std::string& description, IConfigVar* cvar = nullptr) : ISettingsItem(settings_type, title, description), @@ -154,8 +154,44 @@ class NumberSettingsItem : public ISettingsItem { IConfigVar* cvar() const { return cvar_; } + NumberValue current_value() const { + switch (value_type()) { + case ValueType::Int8: { + return *cvar()->as()->current_value(); + } + case ValueType::Int16: { + return *cvar()->as()->current_value(); + } + case ValueType::Int32: { + return *cvar()->as()->current_value(); + } + case ValueType::Int64: { + return *cvar()->as()->current_value(); + } + case ValueType::UInt8: { + return *cvar()->as()->current_value(); + } + case ValueType::UInt16: { + return *cvar()->as()->current_value(); + } + case ValueType::UInt32: { + return *cvar()->as()->current_value(); + } + case ValueType::UInt64: { + return *cvar()->as()->current_value(); + } + case ValueType::Double: { + return *cvar()->as()->current_value(); + } + default: { + assert_always("Invalid number type provided"); + return 0; + } + } + } + virtual bool UpdateValue(NumberValue value) { - auto res = std::visit(ValueVisitor(this), value); + auto res = std::visit(ValueUpdater(this), value); if (!res) { XELOGE("Could not update value for {0}. Incorrect value type provided", cvar_->name()); @@ -172,9 +208,8 @@ class NumberSettingsItem : public ISettingsItem { class RangeInputSettingsItem : public NumberSettingsItem { public: RangeInputSettingsItem(ValueType value_type, std::string title, - NumberValue min, NumberValue max, - std::string description = "", - IConfigVar* cvar = nullptr) + std::string description, NumberValue min, + NumberValue max, IConfigVar* cvar = nullptr) : NumberSettingsItem(value_type, title, description, cvar), min_(min), max_(max) {} @@ -205,6 +240,7 @@ class IMultiChoiceSettingsItem : public ISettingsItem { virtual bool UpdateIndex(int index) = 0; virtual std::vector option_names() const = 0; virtual int current_index() const = 0; + virtual IConfigVar* cvar() const = 0; }; template @@ -273,6 +309,8 @@ class MultiChoiceSettingsItem : public IMultiChoiceSettingsItem { return names; } + IConfigVar* cvar() const override { return cvar_; } + private: ConfigVar* cvar_; std::vector