From 35520472ed1783f15042642b33c179923611b42e Mon Sep 17 00:00:00 2001 From: zsccat Date: Thu, 4 Jun 2020 12:53:48 +0000 Subject: [PATCH] =?UTF-8?q?=E4=B8=8A=E4=BC=A0=E6=96=87=E4=BB=B6=E8=87=B3?= =?UTF-8?q?=20'source-code/source/plugins/TLAC/Input/KeyConfig'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow to load key config for generic usb game controller. --- .../plugins/TLAC/Input/KeyConfig/Config.cpp | 49 ++++++++++++++++++- .../plugins/TLAC/Input/KeyConfig/Config.h | 3 ++ 2 files changed, 51 insertions(+), 1 deletion(-) diff --git a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp index a045fe2..0009a6d 100644 --- a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp +++ b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.cpp @@ -2,6 +2,7 @@ #include "windows.h" #include "../Bindings/KeyboardBinding.h" #include "../Bindings/Ds4Binding.h" +#include "../Bindings/GuBinding.h" #include "../../Utilities/Operations.h" #include "../Bindings/XinputBinding.h" #include "../../Constants.h" @@ -218,6 +219,43 @@ namespace TLAC::Input::KeyConfig { "Ds4_R_Stick_Left", DS4_R_STICK_LEFT }, }; + GuButtonMap Config::GuMap = + { + // Face Buttons + { "GU_BUTTON1", GU_BUTTON1 }, + { "GU_BUTTON2", GU_BUTTON2 }, + { "GU_BUTTON3", GU_BUTTON3 }, + { "GU_BUTTON4", GU_BUTTON4 }, + { "GU_BUTTON5", GU_BUTTON5 }, + { "GU_BUTTON6", GU_BUTTON6 }, + { "GU_BUTTON7", GU_BUTTON7 }, + { "GU_BUTTON8", GU_BUTTON8 }, + { "GU_BUTTON9", GU_BUTTON9 }, + { "GU_BUTTON10", GU_BUTTON10 }, + { "GU_BUTTON11", GU_BUTTON11 }, + { "GU_BUTTON12", GU_BUTTON12 }, + { "GU_BUTTON13", GU_BUTTON13 }, + + // D-Pad Directions + { "GU_DPAD_UP", GU_DPAD_UP }, + { "GU_DPAD_RIGHT", GU_DPAD_RIGHT }, + { "GU_DPAD_DOWN", GU_DPAD_DOWN }, + { "GU_DPAD_LEFT", GU_DPAD_LEFT }, + + // Left Joystick + { "GU_L_STICK_UP", GU_L_STICK_UP }, + { "GU_L_STICK_RIGHT", GU_L_STICK_RIGHT }, + { "GU_L_STICK_DOWN", GU_L_STICK_DOWN }, + { "GU_L_STICK_LEFT", GU_L_STICK_LEFT }, + + // Right Joystick + { "GU_R_STICK_UP", GU_R_STICK_UP }, + { "GU_R_STICK_RIGHT", GU_R_STICK_RIGHT }, + { "GU_R_STICK_DOWN", GU_R_STICK_DOWN }, + { "GU_R_STICK_LEFT", GU_R_STICK_LEFT }, + + }; + void Config::BindConfigKeys(std::unordered_map &configMap, const char *configKeyName, Binding &bindObj, std::vector defaultKeys) { std::vector keys; @@ -271,7 +309,16 @@ namespace TLAC::Input::KeyConfig } else { - printf("[TLAC] Config::BindConfigKeys(): Unable to parse key: '%s'\n", key.c_str()); + auto guButton = Config::GuMap.find(key.c_str()); + + if (guButton != Config::GuMap.end()) + { + bindObj.AddBinding(new GuBinding(guButton->second)); + } + else + { + printf("[TLAC] Config::BindConfigKeys(): Unable to parse key: '%s'\n", key.c_str()); + } } } } diff --git a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h index 194cd13..2a19842 100644 --- a/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h +++ b/source-code/source/plugins/TLAC/Input/KeyConfig/Config.h @@ -5,11 +5,13 @@ #include "KeyStringHash.h" #include "../Bindings/Binding.h" #include "../DirectInput/Ds4/Ds4Button.h" +#include "../DirectInput/GenericUsb/GuButton.h" namespace TLAC::Input::KeyConfig { typedef std::unordered_map KeycodeMap; typedef std::unordered_map Ds4ButtonMap; + typedef std::unordered_map GuButtonMap; class Config { @@ -17,6 +19,7 @@ namespace TLAC::Input::KeyConfig static KeycodeMap Keymap; static Ds4ButtonMap Ds4Map; static KeycodeMap XinputMap; + static GuButtonMap GuMap; static void BindConfigKeys(std::unordered_map &configMap, const char *configKeyName, Binding &bindObj, std::vector defaultKeys); };