diff options
| author | JMC47 <JMC4789@gmail.com> | 2019-04-13 17:43:29 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2019-04-13 17:43:29 -0400 |
| commit | 1cedbd5b82e8850d3fdabcda49ddec7294bceccb (patch) | |
| tree | 2f9f57e85ced7437ca9aed666ab88a7d6e70a300 /Source/Core/InputCommon/ControllerInterface | |
| parent | a891115ea350528f1735dab54d05edc8b8fe77c6 (diff) | |
| parent | be897b41a746b2c9e427a3411681f1571dea7003 (diff) | |
Merge pull request #7923 from jordan-woyak/full-surface-rename
ControllerInterface: Rename full surface analog inputs.
Diffstat (limited to 'Source/Core/InputCommon/ControllerInterface')
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Device.cpp | 28 | ||||
| -rw-r--r-- | Source/Core/InputCommon/ControllerInterface/Device.h | 9 |
2 files changed, 33 insertions, 4 deletions
diff --git a/Source/Core/InputCommon/ControllerInterface/Device.cpp b/Source/Core/InputCommon/ControllerInterface/Device.cpp index 4cd50fa08e..7624b359d1 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.cpp +++ b/Source/Core/InputCommon/ControllerInterface/Device.cpp @@ -55,7 +55,7 @@ Device::Input* Device::FindInput(const std::string& name) const { for (Input* input : m_inputs) { - if (input->GetName() == name) + if (input->IsMatchingName(name)) return input; } @@ -66,18 +66,42 @@ Device::Output* Device::FindOutput(const std::string& name) const { for (Output* output : m_outputs) { - if (output->GetName() == name) + if (output->IsMatchingName(name)) return output; } return nullptr; } +bool Device::Control::IsMatchingName(const std::string& name) const +{ + return GetName() == name; +} + ControlState Device::FullAnalogSurface::GetState() const { return (1 + std::max(0.0, m_high.GetState()) - std::max(0.0, m_low.GetState())) / 2; } +std::string Device::FullAnalogSurface::GetName() const +{ + // E.g. "Full Axis X+" + return "Full " + m_high.GetName(); +} + +bool Device::FullAnalogSurface::IsMatchingName(const std::string& name) const +{ + if (Control::IsMatchingName(name)) + return true; + + // Old naming scheme was "Axis X-+" which is too visually similar to "Axis X+". + // This has caused countless problems for users with mysterious misconfigurations. + // We match this old name to support old configurations. + const auto old_name = m_low.GetName() + *m_high.GetName().rbegin(); + + return old_name == name; +} + // // DeviceQualifier :: ToString // diff --git a/Source/Core/InputCommon/ControllerInterface/Device.h b/Source/Core/InputCommon/ControllerInterface/Device.h index defbb6cd4a..ac18c18803 100644 --- a/Source/Core/InputCommon/ControllerInterface/Device.h +++ b/Source/Core/InputCommon/ControllerInterface/Device.h @@ -46,6 +46,10 @@ public: virtual ~Control() {} virtual Input* ToInput() { return nullptr; } virtual Output* ToOutput() { return nullptr; } + + // May be overridden to allow multiple valid names. + // Useful for backwards-compatible configurations when names change. + virtual bool IsMatchingName(const std::string& name) const; }; // @@ -114,12 +118,13 @@ protected: void AddInput(Input* const i); void AddOutput(Output* const o); - class FullAnalogSurface : public Input + class FullAnalogSurface final : public Input { public: FullAnalogSurface(Input* low, Input* high) : m_low(*low), m_high(*high) {} ControlState GetState() const override; - std::string GetName() const override { return m_low.GetName() + *m_high.GetName().rbegin(); } + std::string GetName() const override; + bool IsMatchingName(const std::string& name) const override; private: Input& m_low; |
