Skip to content

Commit

Permalink
input bind housekeeping
Browse files Browse the repository at this point in the history
  • Loading branch information
DeltaGW2 committed Jul 29, 2024
1 parent 5595ec8 commit 4c83691
Show file tree
Hide file tree
Showing 16 changed files with 225 additions and 109 deletions.
4 changes: 3 additions & 1 deletion Nexus.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@
<ClInclude Include="src\Inputs\GameBinds\EGameBinds.h" />
<ClInclude Include="src\Inputs\GameBinds\FuncDefs.h" />
<ClInclude Include="src\Inputs\GameBinds\GameBindsHandler.h" />
<ClInclude Include="src\Inputs\InputBinds\EInputBindHandlerType.h" />
<ClInclude Include="src\Inputs\InputBinds\EInputBindType.h" />
<ClInclude Include="src\Loader\AddonVersion.h" />
<ClInclude Include="src\Services\API\ApiClient.h" />
<ClInclude Include="src\Services\API\APIController.h" />
Expand Down Expand Up @@ -139,7 +141,7 @@
<ClInclude Include="src\thirdparty\imgui\imstb_rectpack.h" />
<ClInclude Include="src\thirdparty\imgui\imstb_textedit.h" />
<ClInclude Include="src\thirdparty\imgui\imstb_truetype.h" />
<ClInclude Include="src\Inputs\InputBinds\ActiveInputBind.h" />
<ClInclude Include="src\Inputs\InputBinds\ManagedInputBind.h" />
<ClInclude Include="src\Inputs\InputBinds\FuncDefs.h" />
<ClInclude Include="src\Inputs\InputBinds\InputBind.h" />
<ClInclude Include="src\Inputs\InputBinds\InputBindHandler.h" />
Expand Down
11 changes: 10 additions & 1 deletion Nexus.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,9 @@
<Filter Include="Inputs\InputBinds">
<UniqueIdentifier>{f0552fcd-0842-4914-bd35-54f18d11b0cd}</UniqueIdentifier>
</Filter>
<Filter Include="Inputs\InputBinds\Enums">
<UniqueIdentifier>{5f7a3796-ab71-4979-ace3-8063d007c8b8}</UniqueIdentifier>
</Filter>
</ItemGroup>
<ItemGroup>
<ClCompile Include="src\Main.cpp">
Expand Down Expand Up @@ -533,7 +536,7 @@
<ClInclude Include="src\Consts.h">
<Filter>_GLOBAL</Filter>
</ClInclude>
<ClInclude Include="src\Inputs\InputBinds\ActiveInputBind.h">
<ClInclude Include="src\Inputs\InputBinds\ManagedInputBind.h">
<Filter>Inputs\InputBinds</Filter>
</ClInclude>
<ClInclude Include="src\GUI\Widgets\Addons\AddonItem.h">
Expand Down Expand Up @@ -1142,6 +1145,12 @@
<ClInclude Include="src\GUI\Widgets\QuickAccess\EQAVisibility.h">
<Filter>GUI\Widgets\QuickAccess</Filter>
</ClInclude>
<ClInclude Include="src\Inputs\InputBinds\EInputBindHandlerType.h">
<Filter>Inputs\InputBinds\Enums</Filter>
</ClInclude>
<ClInclude Include="src\Inputs\InputBinds\EInputBindType.h">
<Filter>Inputs\InputBinds\Enums</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ResourceCompile Include="src\Nexus.rc">
Expand Down
2 changes: 1 addition & 1 deletion src/GUI/Widgets/Debug/CDebugWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ namespace GUI
{
ImGui::BeginChild("##InputBindsTabScroll", ImVec2(ImGui::GetWindowContentRegionWidth(), 0.0f));

std::map<std::string, ActiveInputBind> InputBindRegistry = InputBindApi->GetRegistry();
std::map<std::string, ManagedInputBind> InputBindRegistry = InputBindApi->GetRegistry();

for (auto& [identifier, inputBind] : InputBindRegistry)
{
Expand Down
4 changes: 2 additions & 2 deletions src/GUI/Widgets/Options/COptionsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace GUI
struct InputBindPacked
{
std::string KeysText;
ActiveInputBind Bind;
ManagedInputBind Bind;
};

struct KBCat
Expand Down Expand Up @@ -306,7 +306,7 @@ namespace GUI
InputBindCategoryMap.clear();

/* copy of all InputBinds */
std::map<std::string, ActiveInputBind> InputBindRegistry = InputBindApi->GetRegistry();
std::map<std::string, ManagedInputBind> InputBindRegistry = InputBindApi->GetRegistry();

/* acquire categories */
for (auto& [identifier, inputBind] : InputBindRegistry)
Expand Down
72 changes: 36 additions & 36 deletions src/Inputs/GameBinds/GameBindsHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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<EGameBinds>();

this->Registry[identifier] = kb;
this->Registry[identifier] = ib;
}

file.close();
Expand All @@ -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);
Expand Down
6 changes: 2 additions & 4 deletions src/Inputs/GameBinds/GameBindsHandler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
21 changes: 0 additions & 21 deletions src/Inputs/InputBinds/ActiveInputBind.h

This file was deleted.

22 changes: 22 additions & 0 deletions src/Inputs/InputBinds/EInputBindHandlerType.h
Original file line number Diff line number Diff line change
@@ -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
22 changes: 22 additions & 0 deletions src/Inputs/InputBinds/EInputBindType.h
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions src/Inputs/InputBinds/FuncDefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
29 changes: 21 additions & 8 deletions src/Inputs/InputBinds/InputBind.cpp
Original file line number Diff line number Diff line change
@@ -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 <Windows.h>
#include <algorithm>
#include <map>
InputBind::InputBind(LegacyInputBind aLegacyInputBind)
{
Alt = aLegacyInputBind.Alt;
Ctrl = aLegacyInputBind.Ctrl;
Shift = aLegacyInputBind.Shift;

#include "InputBindHandler.h"
Type = EInputBindType::Keyboard;
Code = aLegacyInputBind.Key;
}

bool InputBind::IsBound()
{
Expand All @@ -13,13 +25,14 @@ bool InputBind::IsBound()

bool operator==(const InputBind& lhs, const InputBind& rhs)
{
return lhs.Key == rhs.Key &&
lhs.Alt == rhs.Alt &&
return lhs.Alt == rhs.Alt &&
lhs.Ctrl == rhs.Ctrl &&
lhs.Shift == rhs.Shift;
lhs.Shift == rhs.Shift &&
lhs.Type == rhs.Type &&
lhs.Code == rhs.Code;
}

bool operator!=(const InputBind& lhs, const InputBind& rhs)
{
return !(lhs == rhs);
}
}
Loading

0 comments on commit 4c83691

Please sign in to comment.