diff options
| author | Jordan Woyak <jordan.woyak@gmail.com> | 2020-01-18 11:19:32 -0600 |
|---|---|---|
| committer | Jordan Woyak <jordan.woyak@gmail.com> | 2020-02-08 16:03:13 -0600 |
| commit | 0a1634bedf17f7b27a3781d8e5ac6bafb20cd546 (patch) | |
| tree | 1422bbcf3adc3b715f0f0f3bf4630da728342899 /Source/Core/InputCommon/ControllerEmu/Setting | |
| parent | e8152b700f76da97d346b93662ef8492bc93190c (diff) | |
InputCommon: Allow Wii remote extension to be set with an input expression.
Diffstat (limited to 'Source/Core/InputCommon/ControllerEmu/Setting')
| -rw-r--r-- | Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp | 32 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h | 22 |
2 files changed, 41 insertions, 13 deletions
diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp index 3459040824..ab45b64595 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp +++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.cpp @@ -4,6 +4,8 @@ #include "InputCommon/ControllerEmu/Setting/NumericSetting.h" +#include <sstream> + namespace ControllerEmu { NumericSettingBase::NumericSettingBase(const NumericSettingDetails& details) : m_details(details) @@ -26,6 +28,36 @@ const char* NumericSettingBase::GetUIDescription() const } template <> +void NumericSetting<int>::SetExpressionFromValue() +{ + m_value.m_input.SetExpression(ValueToString(GetValue())); +} + +template <> +void NumericSetting<double>::SetExpressionFromValue() +{ + // We must use a dot decimal separator for expression parser. + std::ostringstream ss; + ss.imbue(std::locale::classic()); + ss << GetValue(); + + m_value.m_input.SetExpression(ss.str()); +} + +template <> +void NumericSetting<bool>::SetExpressionFromValue() +{ + // Cast bool to prevent "true"/"false" strings. + m_value.m_input.SetExpression(ValueToString(int(GetValue()))); +} + +template <> +SettingType NumericSetting<int>::GetType() const +{ + return SettingType::Int; +} + +template <> SettingType NumericSetting<double>::GetType() const { return SettingType::Double; diff --git a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h index 6884e7756b..c7298391f4 100644 --- a/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h +++ b/Source/Core/InputCommon/ControllerEmu/Setting/NumericSetting.h @@ -16,6 +16,7 @@ namespace ControllerEmu { enum class SettingType { + Int, Double, Bool, }; @@ -56,6 +57,8 @@ public: virtual InputReference& GetInputReference() = 0; virtual const InputReference& GetInputReference() const = 0; + virtual bool IsSimpleValue() const = 0; + // Convert a literal expression e.g. "7.0" to a regular value. (disables expression parsing) virtual void SimplifyIfPossible() = 0; @@ -76,13 +79,14 @@ template <typename T> class SettingValue; template <typename T> -class NumericSetting : public NumericSettingBase +class NumericSetting final : public NumericSettingBase { public: using ValueType = T; - static_assert(std::is_same<ValueType, double>() || std::is_same<ValueType, bool>(), - "NumericSetting is only implemented for double and bool."); + static_assert(std::is_same<ValueType, int>() || std::is_same<ValueType, double>() || + std::is_same<ValueType, bool>(), + "NumericSetting is only implemented for int, double, and bool."); NumericSetting(SettingValue<ValueType>* value, const NumericSettingDetails& details, ValueType default_value, ValueType min_value, ValueType max_value) @@ -114,7 +118,7 @@ public: section.Set(group_name + m_details.ini_name, m_value.m_input.GetExpression(), ""); } - bool IsSimpleValue() const { return m_value.IsSimpleValue(); } + bool IsSimpleValue() const override { return m_value.IsSimpleValue(); } void SimplifyIfPossible() override { @@ -123,15 +127,7 @@ public: m_value.SetValue(value); } - void SetExpressionFromValue() override - { - if (!IsSimpleValue()) - return; - - // Cast to double to prevent bool -> "true"/"false" strings. - m_value.m_input.SetExpression(ValueToString(static_cast<double>(GetValue()))); - } - + void SetExpressionFromValue() override; InputReference& GetInputReference() override { return m_value.m_input; } const InputReference& GetInputReference() const override { return m_value.m_input; } |
