diff options
| author | 2020-09-01 18:17:59 -0500 | |
|---|---|---|
| committer | 2020-09-18 16:51:16 -0500 | |
| commit | c5e257017f6ffb888534af1ebbc34fffd7a35a2e (patch) | |
| tree | 59063b1fce2ab10ca9cbf9c3e07869921068a74e /src/input_common/gcadapter/gc_adapter.cpp | |
| parent | Merge pull request #4684 from lioncash/desig4 (diff) | |
| download | yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.tar.gz yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.tar.xz yuzu-c5e257017f6ffb888534af1ebbc34fffd7a35a2e.zip | |
Add automap feature for GC adapter
Diffstat (limited to 'src/input_common/gcadapter/gc_adapter.cpp')
| -rw-r--r-- | src/input_common/gcadapter/gc_adapter.cpp | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/src/input_common/gcadapter/gc_adapter.cpp b/src/input_common/gcadapter/gc_adapter.cpp index c507c9891..89c148aba 100644 --- a/src/input_common/gcadapter/gc_adapter.cpp +++ b/src/input_common/gcadapter/gc_adapter.cpp | |||
| @@ -15,7 +15,9 @@ | |||
| 15 | #endif | 15 | #endif |
| 16 | 16 | ||
| 17 | #include "common/logging/log.h" | 17 | #include "common/logging/log.h" |
| 18 | #include "common/param_package.h" | ||
| 18 | #include "input_common/gcadapter/gc_adapter.h" | 19 | #include "input_common/gcadapter/gc_adapter.h" |
| 20 | #include "input_common/settings.h" | ||
| 19 | 21 | ||
| 20 | namespace GCAdapter { | 22 | namespace GCAdapter { |
| 21 | 23 | ||
| @@ -292,6 +294,92 @@ void Adapter::Reset() { | |||
| 292 | } | 294 | } |
| 293 | } | 295 | } |
| 294 | 296 | ||
| 297 | std::vector<Common::ParamPackage> Adapter::GetInputDevices() const { | ||
| 298 | std::vector<Common::ParamPackage> devices; | ||
| 299 | for (std::size_t port = 0; port < state.size(); ++port) { | ||
| 300 | if (!DeviceConnected(port)) { | ||
| 301 | continue; | ||
| 302 | } | ||
| 303 | std::string name = fmt::format("Gamecube Controller {}", port); | ||
| 304 | devices.emplace_back(Common::ParamPackage{ | ||
| 305 | {"class", "gcpad"}, | ||
| 306 | {"display", std::move(name)}, | ||
| 307 | {"port", std::to_string(port)}, | ||
| 308 | }); | ||
| 309 | } | ||
| 310 | return devices; | ||
| 311 | } | ||
| 312 | |||
| 313 | InputCommon::ButtonMapping Adapter::GetButtonMappingForDevice( | ||
| 314 | const Common::ParamPackage& params) const { | ||
| 315 | // This list is missing ZL/ZR since those are not considered buttons. | ||
| 316 | // We will add those afterwards | ||
| 317 | // This list also excludes any button that can't be really mapped | ||
| 318 | static constexpr std::array<std::pair<Settings::NativeButton::Values, PadButton>, 12> | ||
| 319 | switch_to_gcadapter_button = { | ||
| 320 | std::pair{Settings::NativeButton::A, PadButton::PAD_BUTTON_A}, | ||
| 321 | {Settings::NativeButton::B, PadButton::PAD_BUTTON_B}, | ||
| 322 | {Settings::NativeButton::X, PadButton::PAD_BUTTON_X}, | ||
| 323 | {Settings::NativeButton::Y, PadButton::PAD_BUTTON_Y}, | ||
| 324 | {Settings::NativeButton::Plus, PadButton::PAD_BUTTON_START}, | ||
| 325 | {Settings::NativeButton::DLeft, PadButton::PAD_BUTTON_LEFT}, | ||
| 326 | {Settings::NativeButton::DUp, PadButton::PAD_BUTTON_UP}, | ||
| 327 | {Settings::NativeButton::DRight, PadButton::PAD_BUTTON_RIGHT}, | ||
| 328 | {Settings::NativeButton::DDown, PadButton::PAD_BUTTON_DOWN}, | ||
| 329 | {Settings::NativeButton::SL, PadButton::PAD_TRIGGER_L}, | ||
| 330 | {Settings::NativeButton::SR, PadButton::PAD_TRIGGER_R}, | ||
| 331 | {Settings::NativeButton::R, PadButton::PAD_TRIGGER_Z}, | ||
| 332 | }; | ||
| 333 | if (!params.Has("port")) { | ||
| 334 | return {}; | ||
| 335 | } | ||
| 336 | |||
| 337 | InputCommon::ButtonMapping mapping{}; | ||
| 338 | for (const auto& [switch_button, gcadapter_button] : switch_to_gcadapter_button) { | ||
| 339 | Common::ParamPackage button_params({{"engine", "gcpad"}}); | ||
| 340 | button_params.Set("port", params.Get("port", 0)); | ||
| 341 | button_params.Set("button", static_cast<int>(gcadapter_button)); | ||
| 342 | mapping.insert_or_assign(switch_button, std::move(button_params)); | ||
| 343 | } | ||
| 344 | |||
| 345 | // Add the missing bindings for ZL/ZR | ||
| 346 | static constexpr std::array<std::pair<Settings::NativeButton::Values, PadAxes>, 2> | ||
| 347 | switch_to_gcadapter_axis = { | ||
| 348 | std::pair{Settings::NativeButton::ZL, PadAxes::TriggerLeft}, | ||
| 349 | {Settings::NativeButton::ZR, PadAxes::TriggerRight}, | ||
| 350 | }; | ||
| 351 | for (const auto& [switch_button, gcadapter_axis] : switch_to_gcadapter_axis) { | ||
| 352 | Common::ParamPackage button_params({{"engine", "gcpad"}}); | ||
| 353 | button_params.Set("port", params.Get("port", 0)); | ||
| 354 | button_params.Set("button", static_cast<int>(PadButton::PAD_STICK)); | ||
| 355 | button_params.Set("axis", static_cast<int>(gcadapter_axis)); | ||
| 356 | mapping.insert_or_assign(switch_button, std::move(button_params)); | ||
| 357 | } | ||
| 358 | return mapping; | ||
| 359 | } | ||
| 360 | |||
| 361 | InputCommon::AnalogMapping Adapter::GetAnalogMappingForDevice( | ||
| 362 | const Common::ParamPackage& params) const { | ||
| 363 | if (!params.Has("port")) { | ||
| 364 | return {}; | ||
| 365 | } | ||
| 366 | |||
| 367 | InputCommon::AnalogMapping mapping = {}; | ||
| 368 | Common::ParamPackage left_analog_params; | ||
| 369 | left_analog_params.Set("engine", "gcpad"); | ||
| 370 | left_analog_params.Set("port", params.Get("port", 0)); | ||
| 371 | left_analog_params.Set("axis_x", static_cast<int>(PadAxes::StickX)); | ||
| 372 | left_analog_params.Set("axis_y", static_cast<int>(PadAxes::StickY)); | ||
| 373 | mapping.insert_or_assign(Settings::NativeAnalog::LStick, std::move(left_analog_params)); | ||
| 374 | Common::ParamPackage right_analog_params; | ||
| 375 | right_analog_params.Set("engine", "gcpad"); | ||
| 376 | right_analog_params.Set("port", params.Get("port", 0)); | ||
| 377 | right_analog_params.Set("axis_x", static_cast<int>(PadAxes::SubstickX)); | ||
| 378 | right_analog_params.Set("axis_y", static_cast<int>(PadAxes::SubstickY)); | ||
| 379 | mapping.insert_or_assign(Settings::NativeAnalog::RStick, std::move(right_analog_params)); | ||
| 380 | return mapping; | ||
| 381 | } | ||
| 382 | |||
| 295 | bool Adapter::DeviceConnected(std::size_t port) const { | 383 | bool Adapter::DeviceConnected(std::size_t port) const { |
| 296 | return adapter_controllers_status[port] != ControllerTypes::None; | 384 | return adapter_controllers_status[port] != ControllerTypes::None; |
| 297 | } | 385 | } |