上传文件至 'source-code/source/plugins/TLAC/Input/DirectInput/GenericUsb'
Allow to custom key combinations and assign it to a key button.
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#include "GenericUsbInput.h"
|
||||
#include "../../../Utilities/Math.h"
|
||||
#include "../../../Utilities/Operations.h"
|
||||
#include "../../../framework.h"
|
||||
#include "../../../FileSystem/ConfigFile.h"
|
||||
#include <stdio.h>
|
||||
@@ -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<std::string> 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;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
#pragma once
|
||||
#include "../Controller.h"
|
||||
#include "../../IInputDevice.h"
|
||||
#include "../../../Input/KeyConfig/Config.h"
|
||||
#include "GuState.h"
|
||||
#include <unordered_map>
|
||||
|
||||
namespace TLAC::Input
|
||||
{
|
||||
@@ -37,6 +39,36 @@ namespace TLAC::Input
|
||||
GuState lastState;
|
||||
GuState currentState;
|
||||
|
||||
std::unordered_map<std::string, std::string> customKeyMapping;
|
||||
|
||||
std::vector<std::string> 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;
|
||||
|
||||
Reference in New Issue
Block a user