diff options
author | german77 <juangerman-13@hotmail.com> | 2021-11-21 21:12:01 +0100 |
---|---|---|
committer | Narr the Reg <juangerman-13@hotmail.com> | 2021-11-25 03:30:28 +0100 |
commit | 746c85b56011b87afb57e37b75953435389fc810 (patch) | |
tree | 32d31216be1450b5fbe9897e15829ff9bc1f1e7c /src/input_common | |
parent | input_common: Fix SDL controller with inverted axis (diff) | |
download | yuzu-746c85b56011b87afb57e37b75953435389fc810.tar yuzu-746c85b56011b87afb57e37b75953435389fc810.tar.gz yuzu-746c85b56011b87afb57e37b75953435389fc810.tar.bz2 yuzu-746c85b56011b87afb57e37b75953435389fc810.tar.lz yuzu-746c85b56011b87afb57e37b75953435389fc810.tar.xz yuzu-746c85b56011b87afb57e37b75953435389fc810.tar.zst yuzu-746c85b56011b87afb57e37b75953435389fc810.zip |
Diffstat (limited to 'src/input_common')
-rw-r--r-- | src/input_common/drivers/gc_adapter.cpp | 36 | ||||
-rw-r--r-- | src/input_common/drivers/gc_adapter.h | 4 | ||||
-rw-r--r-- | src/input_common/drivers/mouse.cpp | 9 | ||||
-rw-r--r-- | src/input_common/drivers/mouse.h | 2 | ||||
-rw-r--r-- | src/input_common/drivers/sdl_driver.cpp | 15 | ||||
-rw-r--r-- | src/input_common/drivers/sdl_driver.h | 2 | ||||
-rw-r--r-- | src/input_common/input_engine.h | 5 | ||||
-rw-r--r-- | src/input_common/input_mapping.cpp | 5 | ||||
-rw-r--r-- | src/input_common/main.cpp | 17 | ||||
-rw-r--r-- | src/input_common/main.h | 9 |
10 files changed, 55 insertions, 49 deletions
diff --git a/src/input_common/drivers/gc_adapter.cpp b/src/input_common/drivers/gc_adapter.cpp index a1b9b6d98..8b6574223 100644 --- a/src/input_common/drivers/gc_adapter.cpp +++ b/src/input_common/drivers/gc_adapter.cpp @@ -481,47 +481,47 @@ AnalogMapping GCAdapter::GetAnalogMappingForDevice(const Common::ParamPackage& p return mapping; } -std::string GCAdapter::GetUIButtonName(const Common::ParamPackage& params) const { +Common::Input::ButtonNames GCAdapter::GetUIButtonName(const Common::ParamPackage& params) const { PadButton button = static_cast<PadButton>(params.Get("button", 0)); switch (button) { case PadButton::ButtonLeft: - return "left"; + return Common::Input::ButtonNames::ButtonLeft; case PadButton::ButtonRight: - return "right"; + return Common::Input::ButtonNames::ButtonRight; case PadButton::ButtonDown: - return "down"; + return Common::Input::ButtonNames::ButtonDown; case PadButton::ButtonUp: - return "up"; + return Common::Input::ButtonNames::ButtonUp; case PadButton::TriggerZ: - return "Z"; + return Common::Input::ButtonNames::TriggerZ; case PadButton::TriggerR: - return "R"; + return Common::Input::ButtonNames::TriggerR; case PadButton::TriggerL: - return "L"; + return Common::Input::ButtonNames::TriggerL; case PadButton::ButtonA: - return "A"; + return Common::Input::ButtonNames::ButtonA; case PadButton::ButtonB: - return "B"; + return Common::Input::ButtonNames::ButtonB; case PadButton::ButtonX: - return "X"; + return Common::Input::ButtonNames::ButtonX; case PadButton::ButtonY: - return "Y"; + return Common::Input::ButtonNames::ButtonY; case PadButton::ButtonStart: - return "start"; + return Common::Input::ButtonNames::ButtonStart; default: - return "Unknown GC"; + return Common::Input::ButtonNames::Undefined; } } -std::string GCAdapter::GetUIName(const Common::ParamPackage& params) const { +Common::Input::ButtonNames GCAdapter::GetUIName(const Common::ParamPackage& params) const { if (params.Has("button")) { - return fmt::format("Button {}", GetUIButtonName(params)); + return GetUIButtonName(params); } if (params.Has("axis")) { - return fmt::format("Axis {}", params.Get("axis", 0)); + return Common::Input::ButtonNames::Value; } - return "Bad GC Adapter"; + return Common::Input::ButtonNames::Invalid; } } // namespace InputCommon diff --git a/src/input_common/drivers/gc_adapter.h b/src/input_common/drivers/gc_adapter.h index 3e4747040..8dc51d2e5 100644 --- a/src/input_common/drivers/gc_adapter.h +++ b/src/input_common/drivers/gc_adapter.h @@ -34,7 +34,7 @@ public: std::vector<Common::ParamPackage> GetInputDevices() const override; ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) override; AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; - std::string GetUIName(const Common::ParamPackage& params) const override; + Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; private: enum class PadButton { @@ -112,7 +112,7 @@ private: /// Updates vibration state of all controllers void SendVibrations(); - std::string GetUIButtonName(const Common::ParamPackage& params) const; + Common::Input::ButtonNames GetUIButtonName(const Common::ParamPackage& params) const; std::unique_ptr<LibUSBDeviceHandle> usb_adapter_handle; std::array<GCController, 4> pads; diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp index 9a9a1987d..752118e97 100644 --- a/src/input_common/drivers/mouse.cpp +++ b/src/input_common/drivers/mouse.cpp @@ -171,12 +171,15 @@ AnalogMapping Mouse::GetAnalogMappingForDevice( return mapping; } -std::string Mouse::GetUIName(const Common::ParamPackage& params) const { +Common::Input::ButtonNames Mouse::GetUIName(const Common::ParamPackage& params) const { if (params.Has("button")) { - return fmt::format("Mouse {}", params.Get("button", 0)); + return Common::Input::ButtonNames::Value; + } + if (params.Has("axis")) { + return Common::Input::ButtonNames::Value; } - return "Bad Mouse"; + return Common::Input::ButtonNames::Invalid; } } // namespace InputCommon diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h index 11dd76e14..4a1fd2fd9 100644 --- a/src/input_common/drivers/mouse.h +++ b/src/input_common/drivers/mouse.h @@ -63,7 +63,7 @@ public: std::vector<Common::ParamPackage> GetInputDevices() const override; AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; - std::string GetUIName(const Common::ParamPackage& params) const override; + Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; private: void UpdateThread(std::stop_token stop_token); diff --git a/src/input_common/drivers/sdl_driver.cpp b/src/input_common/drivers/sdl_driver.cpp index d5af6c09b..90128b6cf 100644 --- a/src/input_common/drivers/sdl_driver.cpp +++ b/src/input_common/drivers/sdl_driver.cpp @@ -869,26 +869,25 @@ MotionMapping SDLDriver::GetMotionMappingForDevice(const Common::ParamPackage& p return mapping; } -std::string SDLDriver::GetUIName(const Common::ParamPackage& params) const { +Common::Input::ButtonNames SDLDriver::GetUIName(const Common::ParamPackage& params) const { if (params.Has("button")) { // TODO(German77): Find how to substitue the values for real button names - return fmt::format("Button {}", params.Get("button", 0)); + return Common::Input::ButtonNames::Value; } if (params.Has("hat")) { - return fmt::format("Hat {}", params.Get("direction", "")); + return Common::Input::ButtonNames::Value; } if (params.Has("axis")) { - return fmt::format("Axis {}", params.Get("axis", "")); + return Common::Input::ButtonNames::Value; } if (params.Has("axis_x") && params.Has("axis_y") && params.Has("axis_z")) { - return fmt::format("Axis {},{},{}", params.Get("axis_x", ""), params.Get("axis_y", ""), - params.Get("axis_z", "")); + return Common::Input::ButtonNames::Value; } if (params.Has("motion")) { - return "SDL motion"; + return Common::Input::ButtonNames::Engine; } - return "Bad SDL"; + return Common::Input::ButtonNames::Invalid; } std::string SDLDriver::GetHatButtonName(u8 direction_value) const { diff --git a/src/input_common/drivers/sdl_driver.h b/src/input_common/drivers/sdl_driver.h index 3faaca984..d03ff4b84 100644 --- a/src/input_common/drivers/sdl_driver.h +++ b/src/input_common/drivers/sdl_driver.h @@ -53,7 +53,7 @@ public: ButtonMapping GetButtonMappingForDevice(const Common::ParamPackage& params) override; AnalogMapping GetAnalogMappingForDevice(const Common::ParamPackage& params) override; MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& params) override; - std::string GetUIName(const Common::ParamPackage& params) const override; + Common::Input::ButtonNames GetUIName(const Common::ParamPackage& params) const override; std::string GetHatButtonName(u8 direction_value) const override; u8 GetHatButtonId(const std::string& direction_name) const override; diff --git a/src/input_common/input_engine.h b/src/input_common/input_engine.h index c621686e5..02272b3f8 100644 --- a/src/input_common/input_engine.h +++ b/src/input_common/input_engine.h @@ -161,8 +161,9 @@ public: }; /// Retrieves the name of the given input. - virtual std::string GetUIName([[maybe_unused]] const Common::ParamPackage& params) const { - return GetEngineName(); + virtual Common::Input::ButtonNames GetUIName( + [[maybe_unused]] const Common::ParamPackage& params) const { + return Common::Input::ButtonNames::Engine; }; /// Retrieves the index number of the given hat button direction diff --git a/src/input_common/input_mapping.cpp b/src/input_common/input_mapping.cpp index 0eeeff372..c5218f2cb 100644 --- a/src/input_common/input_mapping.cpp +++ b/src/input_common/input_mapping.cpp @@ -61,6 +61,7 @@ void MappingFactory::RegisterButton(const MappingData& data) { } new_input.Set("port", static_cast<int>(data.pad.port)); new_input.Set("pad", static_cast<int>(data.pad.pad)); + switch (data.type) { case EngineInputType::Button: // Workaround for old compatibility @@ -75,6 +76,10 @@ void MappingFactory::RegisterButton(const MappingData& data) { new_input.Set("direction", data.hat_name); break; case EngineInputType::Analog: + // Ignore mouse axis when mapping buttons + if (data.engine == "mouse") { + return; + } new_input.Set("axis", data.index); new_input.Set("threshold", 0.5f); break; diff --git a/src/input_common/main.cpp b/src/input_common/main.cpp index df36a337c..39e4935dc 100644 --- a/src/input_common/main.cpp +++ b/src/input_common/main.cpp @@ -205,9 +205,9 @@ struct InputSubsystem::Impl { return {}; } - std::string GetButtonName(const Common::ParamPackage& params) const { + Common::Input::ButtonNames GetButtonName(const Common::ParamPackage& params) const { if (!params.Has("engine") || params.Get("engine", "") == "any") { - return "Unknown"; + return Common::Input::ButtonNames::Undefined; } const std::string engine = params.Get("engine", ""); if (engine == mouse->GetEngineName()) { @@ -227,7 +227,7 @@ struct InputSubsystem::Impl { return sdl->GetUIName(params); } #endif - return "Bad engine"; + return Common::Input::ButtonNames::Invalid; } bool IsController(const Common::ParamPackage& params) { @@ -361,15 +361,8 @@ MotionMapping InputSubsystem::GetMotionMappingForDevice(const Common::ParamPacka return impl->GetMotionMappingForDevice(device); } -std::string InputSubsystem::GetButtonName(const Common::ParamPackage& params) const { - const std::string toggle = params.Get("toggle", false) ? "~" : ""; - const std::string inverted = params.Get("inverted", false) ? "!" : ""; - const std::string button_name = impl->GetButtonName(params); - std::string axis_direction = ""; - if (params.Has("axis")) { - axis_direction = params.Get("invert", "+"); - } - return fmt::format("{}{}{}{}", toggle, inverted, button_name, axis_direction); +Common::Input::ButtonNames InputSubsystem::GetButtonName(const Common::ParamPackage& params) const { + return impl->GetButtonName(params); } bool InputSubsystem::IsController(const Common::ParamPackage& params) const { diff --git a/src/input_common/main.h b/src/input_common/main.h index a4a24d076..c6f97f691 100644 --- a/src/input_common/main.h +++ b/src/input_common/main.h @@ -13,6 +13,10 @@ namespace Common { class ParamPackage; } +namespace Common::Input { +enum class ButtonNames; +} + namespace Settings::NativeAnalog { enum Values : int; } @@ -108,8 +112,9 @@ public: /// Retrieves the motion mappings for the given device. [[nodiscard]] MotionMapping GetMotionMappingForDevice(const Common::ParamPackage& device) const; - /// Returns a string contaning the name of the button from the input engine. - [[nodiscard]] std::string GetButtonName(const Common::ParamPackage& params) const; + /// Returns an enum contaning the name to be displayed from the input engine. + [[nodiscard]] Common::Input::ButtonNames GetButtonName( + const Common::ParamPackage& params) const; /// Returns true if device is a controller. [[nodiscard]] bool IsController(const Common::ParamPackage& params) const; |