From 4c836916b1b9962efb26bd23b146256e19eaa22d Mon Sep 17 00:00:00 2001
From: Delta <46466697+DeltaGW2@users.noreply.github.com>
Date: Mon, 29 Jul 2024 22:19:50 +0200
Subject: [PATCH] input bind housekeeping
---
Nexus.vcxproj | 4 +-
Nexus.vcxproj.filters | 11 ++-
src/GUI/Widgets/Debug/CDebugWindow.cpp | 2 +-
src/GUI/Widgets/Options/COptionsWindow.cpp | 4 +-
src/Inputs/GameBinds/GameBindsHandler.cpp | 72 +++++++++----------
src/Inputs/GameBinds/GameBindsHandler.h | 6 +-
src/Inputs/InputBinds/ActiveInputBind.h | 21 ------
src/Inputs/InputBinds/EInputBindHandlerType.h | 22 ++++++
src/Inputs/InputBinds/EInputBindType.h | 22 ++++++
src/Inputs/InputBinds/FuncDefs.h | 4 +-
src/Inputs/InputBinds/InputBind.cpp | 29 +++++---
src/Inputs/InputBinds/InputBind.h | 47 ++++++++++--
src/Inputs/InputBinds/InputBindHandler.cpp | 40 ++++++-----
src/Inputs/InputBinds/InputBindHandler.h | 23 +++---
src/Inputs/InputBinds/ManagedInputBind.h | 25 +++++++
src/Main.cpp | 2 +-
16 files changed, 225 insertions(+), 109 deletions(-)
delete mode 100644 src/Inputs/InputBinds/ActiveInputBind.h
create mode 100644 src/Inputs/InputBinds/EInputBindHandlerType.h
create mode 100644 src/Inputs/InputBinds/EInputBindType.h
create mode 100644 src/Inputs/InputBinds/ManagedInputBind.h
diff --git a/Nexus.vcxproj b/Nexus.vcxproj
index c53e6f3..a069c19 100644
--- a/Nexus.vcxproj
+++ b/Nexus.vcxproj
@@ -88,6 +88,8 @@
+
+
@@ -139,7 +141,7 @@
-
+
diff --git a/Nexus.vcxproj.filters b/Nexus.vcxproj.filters
index 2f10dfc..90a28f7 100644
--- a/Nexus.vcxproj.filters
+++ b/Nexus.vcxproj.filters
@@ -160,6 +160,9 @@
{f0552fcd-0842-4914-bd35-54f18d11b0cd}
+
+ {5f7a3796-ab71-4979-ace3-8063d007c8b8}
+
@@ -533,7 +536,7 @@
_GLOBAL
-
+
Inputs\InputBinds
@@ -1142,6 +1145,12 @@
GUI\Widgets\QuickAccess
+
+ Inputs\InputBinds\Enums
+
+
+ Inputs\InputBinds\Enums
+
diff --git a/src/GUI/Widgets/Debug/CDebugWindow.cpp b/src/GUI/Widgets/Debug/CDebugWindow.cpp
index 8912dd5..96f0eec 100644
--- a/src/GUI/Widgets/Debug/CDebugWindow.cpp
+++ b/src/GUI/Widgets/Debug/CDebugWindow.cpp
@@ -125,7 +125,7 @@ namespace GUI
{
ImGui::BeginChild("##InputBindsTabScroll", ImVec2(ImGui::GetWindowContentRegionWidth(), 0.0f));
- std::map InputBindRegistry = InputBindApi->GetRegistry();
+ std::map InputBindRegistry = InputBindApi->GetRegistry();
for (auto& [identifier, inputBind] : InputBindRegistry)
{
diff --git a/src/GUI/Widgets/Options/COptionsWindow.cpp b/src/GUI/Widgets/Options/COptionsWindow.cpp
index 7788856..b792e88 100644
--- a/src/GUI/Widgets/Options/COptionsWindow.cpp
+++ b/src/GUI/Widgets/Options/COptionsWindow.cpp
@@ -40,7 +40,7 @@ namespace GUI
struct InputBindPacked
{
std::string KeysText;
- ActiveInputBind Bind;
+ ManagedInputBind Bind;
};
struct KBCat
@@ -306,7 +306,7 @@ namespace GUI
InputBindCategoryMap.clear();
/* copy of all InputBinds */
- std::map InputBindRegistry = InputBindApi->GetRegistry();
+ std::map InputBindRegistry = InputBindApi->GetRegistry();
/* acquire categories */
for (auto& [identifier, inputBind] : InputBindRegistry)
diff --git a/src/Inputs/GameBinds/GameBindsHandler.cpp b/src/Inputs/GameBinds/GameBindsHandler.cpp
index 151ac3c..807d894 100644
--- a/src/Inputs/GameBinds/GameBindsHandler.cpp
+++ b/src/Inputs/GameBinds/GameBindsHandler.cpp
@@ -640,19 +640,19 @@ void CGameBindsApi::OnUEInputBindChanged(void* aData)
/* only process keyboard binds (for now) */
if (kbChange->Bind.DeviceType == 1) { return; }
- InputBind kb{};
+ InputBind ib{};
/* if key was unbound */
if (kbChange->Bind.DeviceType != 0)
{
- kb.Alt = kbChange->Bind.Modifiers & 0b0100;
- kb.Ctrl = kbChange->Bind.Modifiers & 0b0010;
- kb.Shift = kbChange->Bind.Modifiers & 0b0001;
+ ib.Alt = kbChange->Bind.Modifiers & 0b0100;
+ ib.Ctrl = kbChange->Bind.Modifiers & 0b0010;
+ ib.Shift = kbChange->Bind.Modifiers & 0b0001;
- kb.Key = CGameBindsApi::GameBindCodeToScanCode(kbChange->Bind.Code);
+ ib.Code = CGameBindsApi::GameBindCodeToScanCode(kbChange->Bind.Code);
}
- UEInputBindUpdatesTarget->Set(kbChange->Identifier, kb, true);
+ UEInputBindUpdatesTarget->Set(kbChange->Identifier, ib, true);
}
CGameBindsApi::CGameBindsApi(CRawInputApi* aRawInputApi, CLogHandler* aLogger, CEventApi* aEventApi)
@@ -706,67 +706,67 @@ void CGameBindsApi::InvokeAsync(EGameBinds aGameBind, int aDuration)
void CGameBindsApi::Press(EGameBinds aGameBind)
{
- InputBind kb = this->Get(aGameBind);
+ InputBind ib = this->Get(aGameBind);
- if (!kb.IsBound())
+ if (!ib.IsBound())
{
return;
}
KeyLParam key{};
key.RepeatCount = 1;
- key.ScanCode = kb.Key;
- key.ExtendedFlag = (kb.Key & 0xE000) != 0;
+ key.ScanCode = ib.Code;
+ key.ExtendedFlag = (ib.Code & 0xE000) != 0;
key.Reserved = 0;
- key.ContextCode = kb.Alt;
+ key.ContextCode = ib.Alt;
key.PreviousKeyState = 0;
key.TransitionState = 0;
- if (kb.Alt)
+ if (ib.Alt)
{
this->RawInputApi->SendWndProcToGame(0, WM_SYSKEYDOWN, VK_MENU, GetKeyMessageLPARAM(VK_MENU, true, true));
}
- if (kb.Ctrl)
+ if (ib.Ctrl)
{
this->RawInputApi->SendWndProcToGame(0, WM_KEYDOWN, VK_CONTROL, GetKeyMessageLPARAM(VK_CONTROL, true, false));
}
- if (kb.Shift)
+ if (ib.Shift)
{
this->RawInputApi->SendWndProcToGame(0, WM_KEYDOWN, VK_SHIFT, GetKeyMessageLPARAM(VK_SHIFT, true, false));
}
- this->RawInputApi->SendWndProcToGame(0, WM_KEYDOWN, MapVirtualKeyA(kb.Key, MAPVK_VSC_TO_VK), KMFToLParam(key));
+ this->RawInputApi->SendWndProcToGame(0, WM_KEYDOWN, MapVirtualKeyA(ib.Code, MAPVK_VSC_TO_VK), KMFToLParam(key));
}
void CGameBindsApi::Release(EGameBinds aGameBind)
{
- InputBind kb = this->Get(aGameBind);
+ InputBind ib = this->Get(aGameBind);
- if (!kb.IsBound())
+ if (!ib.IsBound())
{
return;
}
KeyLParam key{};
key.RepeatCount = 1;
- key.ScanCode = kb.Key;
- key.ExtendedFlag = (kb.Key & 0xE000) != 0;
+ key.ScanCode = ib.Code;
+ key.ExtendedFlag = (ib.Code & 0xE000) != 0;
key.Reserved = 0;
- key.ContextCode = kb.Alt;
+ key.ContextCode = ib.Alt;
key.PreviousKeyState = 1;
key.TransitionState = 1;
- this->RawInputApi->SendWndProcToGame(0, WM_KEYUP, MapVirtualKeyA(kb.Key, MAPVK_VSC_TO_VK), KMFToLParam(key));
+ this->RawInputApi->SendWndProcToGame(0, WM_KEYUP, MapVirtualKeyA(ib.Code, MAPVK_VSC_TO_VK), KMFToLParam(key));
- if (kb.Alt)
+ if (ib.Alt)
{
this->RawInputApi->SendWndProcToGame(0, WM_SYSKEYUP, VK_MENU, GetKeyMessageLPARAM(VK_MENU, false, true));
}
- if (kb.Ctrl)
+ if (ib.Ctrl)
{
this->RawInputApi->SendWndProcToGame(0, WM_KEYUP, VK_CONTROL, GetKeyMessageLPARAM(VK_CONTROL, false, false));
}
- if (kb.Shift)
+ if (ib.Shift)
{
this->RawInputApi->SendWndProcToGame(0, WM_KEYUP, VK_SHIFT, GetKeyMessageLPARAM(VK_SHIFT, false, false));
}
@@ -853,15 +853,15 @@ void CGameBindsApi::Load()
continue;
}
- InputBind kb{};
- binding["Key"].get_to(kb.Key);
- binding["Alt"].get_to(kb.Alt);
- binding["Ctrl"].get_to(kb.Ctrl);
- binding["Shift"].get_to(kb.Shift);
+ InputBind ib{};
+ binding["Key"].get_to(ib.Code);
+ binding["Alt"].get_to(ib.Alt);
+ binding["Ctrl"].get_to(ib.Ctrl);
+ binding["Shift"].get_to(ib.Shift);
EGameBinds identifier = binding["Identifier"].get();
- this->Registry[identifier] = kb;
+ this->Registry[identifier] = ib;
}
file.close();
@@ -882,18 +882,18 @@ void CGameBindsApi::Save()
for (auto& it : this->Registry)
{
- InputBind kb = it.second;
+ InputBind ib = it.second;
EGameBinds id = it.first;
- if (!kb.IsBound()) { continue; }
+ if (!ib.IsBound()) { continue; }
json binding =
{
{"Identifier", id},
- {"Key", kb.Key},
- {"Alt", kb.Alt},
- {"Ctrl", kb.Ctrl},
- {"Shift", kb.Shift}
+ {"Key", ib.Code},
+ {"Alt", ib.Alt},
+ {"Ctrl", ib.Ctrl},
+ {"Shift", ib.Shift}
};
InputBinds.push_back(binding);
diff --git a/src/Inputs/GameBinds/GameBindsHandler.h b/src/Inputs/GameBinds/GameBindsHandler.h
index b6e1ab5..b0e9c27 100644
--- a/src/Inputs/GameBinds/GameBindsHandler.h
+++ b/src/Inputs/GameBinds/GameBindsHandler.h
@@ -16,11 +16,9 @@
#include "EGameBinds.h"
-#include "Inputs/RawInput/RawInputApi.h"
-#include "Inputs/InputBinds/InputBind.h"
-
#include "Events/EventHandler.h"
-
+#include "Inputs/InputBinds/InputBind.h"
+#include "Inputs/RawInput/RawInputApi.h"
#include "Services/Logging/LogHandler.h"
constexpr const char* CH_GAMEBINDS = "GameBinds";
diff --git a/src/Inputs/InputBinds/ActiveInputBind.h b/src/Inputs/InputBinds/ActiveInputBind.h
deleted file mode 100644
index 8b0ed25..0000000
--- a/src/Inputs/InputBinds/ActiveInputBind.h
+++ /dev/null
@@ -1,21 +0,0 @@
-#ifndef ACTIVEINPUTBIND_H
-#define ACTIVEINPUTBIND_H
-
-#include "InputBind.h"
-#include "FuncDefs.h"
-
-typedef enum class EInputBindHandlerType
-{
- None,
- DownOnly,
- DownAndRelease
-} EIBHType;
-
-struct ActiveInputBind
-{
- InputBind Bind;
- EInputBindHandlerType HandlerType;
- void* Handler;
-};
-
-#endif
diff --git a/src/Inputs/InputBinds/EInputBindHandlerType.h b/src/Inputs/InputBinds/EInputBindHandlerType.h
new file mode 100644
index 0000000..e988482
--- /dev/null
+++ b/src/Inputs/InputBinds/EInputBindHandlerType.h
@@ -0,0 +1,22 @@
+///----------------------------------------------------------------------------------------------------
+/// Copyright (c) Raidcore.GG - All rights reserved.
+///
+/// Name : EInputBindHandlerType.h
+/// Description : EInputBindHandlerType enum definition.
+/// Authors : K. Bieniek
+///----------------------------------------------------------------------------------------------------
+
+#ifndef INPUTBINDHANDLERTYPE_H
+#define INPUTBINDHANDLERTYPE_H
+
+///----------------------------------------------------------------------------------------------------
+/// EInputBindHandlerType Enum
+///----------------------------------------------------------------------------------------------------
+typedef enum class EInputBindHandlerType
+{
+ None,
+ DownOnly,
+ DownAndRelease
+} EIBHType;
+
+#endif
diff --git a/src/Inputs/InputBinds/EInputBindType.h b/src/Inputs/InputBinds/EInputBindType.h
new file mode 100644
index 0000000..3454808
--- /dev/null
+++ b/src/Inputs/InputBinds/EInputBindType.h
@@ -0,0 +1,22 @@
+///----------------------------------------------------------------------------------------------------
+/// Copyright (c) Raidcore.GG - All rights reserved.
+///
+/// Name : EInputBindType.h
+/// Description : EInputBindType enum definition.
+/// Authors : K. Bieniek
+///----------------------------------------------------------------------------------------------------
+
+#ifndef INPUTBINDTYPE_H
+#define INPUTBINDTYPE_H
+
+///----------------------------------------------------------------------------------------------------
+/// EInputBindType Enum
+///----------------------------------------------------------------------------------------------------
+typedef enum class EInputBindType
+{
+ None,
+ Keyboard,
+ Mouse
+} EIBType;
+
+#endif
diff --git a/src/Inputs/InputBinds/FuncDefs.h b/src/Inputs/InputBinds/FuncDefs.h
index 0f59e89..02f7c5b 100644
--- a/src/Inputs/InputBinds/FuncDefs.h
+++ b/src/Inputs/InputBinds/FuncDefs.h
@@ -5,11 +5,11 @@
typedef void (*INPUTBINDS_PROCESS)(const char* aIdentifier);
typedef void (*INPUTBINDS_REGISTERWITHSTRING)(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, const char* aInputBind);
-typedef void (*INPUTBINDS_REGISTERWITHSTRUCT)(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, InputBind aInputBind);
+typedef void (*INPUTBINDS_REGISTERWITHSTRUCT)(const char* aIdentifier, INPUTBINDS_PROCESS aInputBindHandler, LegacyInputBind aInputBind);
typedef void (*INPUTBINDS_PROCESS2)(const char* aIdentifier, bool aIsRelease);
typedef void (*INPUTBINDS_REGISTERWITHSTRING2)(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, const char* aInputBind);
-typedef void (*INPUTBINDS_REGISTERWITHSTRUCT2)(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, InputBind aInputBind);
+typedef void (*INPUTBINDS_REGISTERWITHSTRUCT2)(const char* aIdentifier, INPUTBINDS_PROCESS2 aInputBindHandler, LegacyInputBind aInputBind);
typedef void (*INPUTBINDS_INVOKE)(const char* aIdentifier, bool aIsRelease);
diff --git a/src/Inputs/InputBinds/InputBind.cpp b/src/Inputs/InputBinds/InputBind.cpp
index 63084e5..4add5bb 100644
--- a/src/Inputs/InputBinds/InputBind.cpp
+++ b/src/Inputs/InputBinds/InputBind.cpp
@@ -1,10 +1,22 @@
+///----------------------------------------------------------------------------------------------------
+/// Copyright (c) Raidcore.GG - All rights reserved.
+///
+/// Name : InputBind.cpp
+/// Description : InputBind struct definition.
+/// Authors : K. Bieniek
+///----------------------------------------------------------------------------------------------------
+
#include "InputBind.h"
-#include
-#include
-#include