From 9f829971bf90a880c8311cdaadab0b4eb8d3d537 Mon Sep 17 00:00:00 2001 From: zsccat Date: Fri, 5 Jun 2020 01:55:02 +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/DirectInput/GenericUs?= =?UTF-8?q?b'?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Allow to custom key combinations and assign it to a key button. --- .../GenericUsb/GenericUsbInput.cpp | 26 ++++++++++++++- .../DirectInput/GenericUsb/GenericUsbInput.h | 32 +++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp index e2a9b22..8a7983e 100644 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.cpp @@ -1,5 +1,6 @@ #include "GenericUsbInput.h" #include "../../../Utilities/Math.h" +#include "../../../Utilities/Operations.h" #include "../../../framework.h" #include "../../../FileSystem/ConfigFile.h" #include @@ -45,6 +46,8 @@ namespace TLAC::Input FileSystem::ConfigFile configFile(framework::GetModuleDirectory(), GU_CONFIG_FILE_NAME); configFile.OpenRead(); + customKeyMapping = configFile.ConfigMap; + std::string stt = "0x"; std::string vid = configFile.GetStringValue("VID"); std::string pid = configFile.GetStringValue("PID"); @@ -84,7 +87,28 @@ namespace TLAC::Input UpdateInternalGuState(currentState); for (int button = 0; button < GU_BUTTON_MAX; button++) - currentState.Buttons[button] = GetButtonState(currentState, (GuButton)button); + { + bool buttonState = GetButtonState(currentState, (GuButton)button); + currentState.Buttons[button] = buttonState; + + // If custom button is pressed + if (buttonState) + { + // Check whether this button is a custom mapped button + auto customMapping = customKeyMapping.find(buttonNames[button]); + if (customMapping != customKeyMapping.end()) + { + std::vector keys = Utilities::Split(customMapping->second, "+"); + for (std::string key : keys) + { + Utilities::Trim(key); + + auto guButton = KeyConfig::Config::GuMap.find(key.c_str()); + currentState.Buttons[guButton->second] = buttonState; + } + } + } + } return true; } diff --git a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h index 898b7ce..1178342 100644 --- a/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h +++ b/source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb/GenericUsbInput.h @@ -1,7 +1,9 @@ #pragma once #include "../Controller.h" #include "../../IInputDevice.h" +#include "../../../Input/KeyConfig/Config.h" #include "GuState.h" +#include namespace TLAC::Input { @@ -37,6 +39,36 @@ namespace TLAC::Input GuState lastState; GuState currentState; + std::unordered_map customKeyMapping; + + std::vector buttonNames = { "GU_BUTTON1", + "GU_BUTTON2", + "GU_BUTTON3", + "GU_BUTTON4", + "GU_BUTTON5", + "GU_BUTTON6", + "GU_BUTTON7", + "GU_BUTTON8", + "GU_BUTTON9", + "GU_BUTTON10", + "GU_BUTTON11", + "GU_BUTTON12", + "GU_BUTTON13", + "GU_DPAD_UP", + "GU_DPAD_RIGHT", + "GU_DPAD_DOWN", + "GU_DPAD_LEFT", + "GU_L_STICK_UP", + "GU_L_STICK_RIGHT", + "GU_L_STICK_DOWN", + "GU_L_STICK_LEFT", + "GU_R_STICK_UP", + "GU_R_STICK_RIGHT", + "GU_R_STICK_DOWN", + "GU_R_STICK_LEFT", + "GU_BUTTON_MAX" + }; + const float triggerThreshold = 0.5f; const float joystickThreshold = 0.5f; const float dpadThreshold = 0.5f;