Skip to content

Commit bbd05a5

Browse files
emre1702ccw808
authored andcommitted
#9178 - Fix bindKey & unbindKey on commands (2) (#214)
1 parent a24b3ab commit bbd05a5

File tree

4 files changed

+22
-15
lines changed

4 files changed

+22
-15
lines changed

Client/core/CKeyBinds.cpp

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -766,7 +766,7 @@ bool CKeyBinds::CommandExists(const char* szKey, const char* szCommand, bool bCh
766766
}
767767

768768
bool CKeyBinds::SetCommandActive(const char* szKey, const char* szCommand, bool bState, const char* szArguments, const char* szResource, bool bActive,
769-
bool checkHitState)
769+
bool checkHitState, bool bConsiderDefaultKey)
770770
{
771771
NullEmptyStrings(szKey, szCommand, szArguments);
772772

@@ -775,9 +775,11 @@ bool CKeyBinds::SetCommandActive(const char* szKey, const char* szCommand, bool
775775
{
776776
if ((*iter)->GetType() == KEY_BIND_COMMAND)
777777
{
778-
if (!szKey || (stricmp((*iter)->boundKey->szKey, szKey) == 0))
778+
CCommandBind* pBind = static_cast<CCommandBind*>(*iter);
779+
if (!szKey
780+
|| (stricmp(pBind->boundKey->szKey, szKey) == 0)
781+
|| (bConsiderDefaultKey && pBind->bIsReplacingScriptKey && stricmp(pBind->strOriginalScriptKey, szKey) == 0))
779782
{
780-
CCommandBind* pBind = static_cast<CCommandBind*>(*iter);
781783
if (pBind->szResource && (strcmp(pBind->szResource, szResource) == 0))
782784
{
783785
if (!szCommand || (strcmp(pBind->szCommand, szCommand) == 0))
@@ -798,7 +800,7 @@ bool CKeyBinds::SetCommandActive(const char* szKey, const char* szCommand, bool
798800
return false;
799801
}
800802

801-
void CKeyBinds::SetAllCommandsActive(const char* szResource, bool bActive, const char* szCommand, bool bState, const char* szArguments, bool checkHitState)
803+
void CKeyBinds::SetAllCommandsActive(const char* szResource, bool bActive, const char* szCommand, bool bState, const char* szArguments, bool checkHitState, const char* szOnlyWithDefaultKey)
802804
{
803805
NullEmptyStrings(szCommand, szArguments);
804806

@@ -816,7 +818,12 @@ void CKeyBinds::SetAllCommandsActive(const char* szResource, bool bActive, const
816818
{
817819
if (!szArguments || (pBind->szArguments && strcmp(pBind->szArguments, szArguments) == 0))
818820
{
819-
pBind->bActive = bActive;
821+
if (!szOnlyWithDefaultKey
822+
|| (pBind->bIsReplacingScriptKey && stricmp(pBind->strOriginalScriptKey, szOnlyWithDefaultKey) == 0)
823+
|| stricmp(pBind->boundKey->szKey, szOnlyWithDefaultKey) == 0)
824+
{
825+
pBind->bActive = bActive;
826+
}
820827
}
821828
}
822829
}

Client/core/CKeyBinds.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,9 @@ class CKeyBinds : public CKeyBindsInterface
6363
bool CommandExists(const char* szKey, const char* szCommand, bool bCheckState = false, bool bState = true, const char* szArguments = NULL,
6464
const char* szResource = NULL, bool bCheckScriptCreated = false, bool bScriptCreated = false);
6565
bool SetCommandActive(const char* szKey, const char* szCommand, bool bState, const char* szArguments, const char* szResource, bool bActive,
66-
bool checkHitState);
66+
bool checkHitState, bool bConsiderDefaultKey = false);
6767
void SetAllCommandsActive(const char* szResource, bool bActive, const char* szCommand = NULL, bool bState = true, const char* szArguments = NULL,
68-
bool checkHitState = false);
68+
bool checkHitState = false, const char* szOnlyWithDefaultKey = nullptr);
6969
CCommandBind* GetBindFromCommand(const char* szCommand, const char* szArguments = NULL, bool bMatchCase = true, const char* szKey = NULL,
7070
bool bCheckHitState = false, bool bState = NULL);
7171
bool GetBoundCommands(const char* szCommand, std::list<CCommandBind*>& commandsList);

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6433,7 +6433,7 @@ bool CStaticFunctionDefinitions::BindKey(const char* szKey, const char* szHitSta
64336433
{
64346434
bool bHitState = true;
64356435
// Activate all keys for this command
6436-
pKeyBinds->SetAllCommandsActive(szResource, true, szCommandName, bHitState, szArguments, true);
6436+
pKeyBinds->SetAllCommandsActive(szResource, true, szCommandName, bHitState, szArguments, true, szKey);
64376437
// Check if its binded already (dont rebind)
64386438
if (pKeyBinds->CommandExists(szKey, szCommandName, true, bHitState, szArguments, szResource, true, true))
64396439
return true;
@@ -6446,7 +6446,7 @@ bool CStaticFunctionDefinitions::BindKey(const char* szKey, const char* szHitSta
64466446
}
64476447

64486448
bHitState = false;
6449-
pKeyBinds->SetAllCommandsActive(szResource, true, szCommandName, bHitState, szArguments, true);
6449+
pKeyBinds->SetAllCommandsActive(szResource, true, szCommandName, bHitState, szArguments, true, szKey);
64506450
if (pKeyBinds->CommandExists(szKey, szCommandName, true, bHitState, szArguments, szResource, true, true))
64516451
return true;
64526452

@@ -6523,16 +6523,16 @@ bool CStaticFunctionDefinitions::UnbindKey(const char* szKey, const char* szHitS
65236523
}
65246524
}
65256525
if ((!stricmp(szHitState, "down") || !stricmp(szHitState, "both")) &&
6526-
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, NULL, szResource, false, true))
6526+
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, NULL, szResource, false, true, true))
65276527
{
6528-
pKeyBinds->SetAllCommandsActive(szResource, false, szCommandName, bHitState, NULL, true);
6528+
pKeyBinds->SetAllCommandsActive(szResource, false, szCommandName, bHitState, NULL, true, szKey);
65296529
bSuccess = true;
65306530
}
65316531
bHitState = false;
65326532
if ((!stricmp(szHitState, "up") || !stricmp(szHitState, "both")) &&
6533-
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, NULL, szResource, false, true))
6533+
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, NULL, szResource, false, true, true))
65346534
{
6535-
pKeyBinds->SetAllCommandsActive(szResource, false, szCommandName, bHitState, NULL, true);
6535+
pKeyBinds->SetAllCommandsActive(szResource, false, szCommandName, bHitState, NULL, true, szKey);
65366536
bSuccess = true;
65376537
}
65386538
}

Client/sdk/core/CKeyBindsInterface.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -164,9 +164,9 @@ class CKeyBindsInterface
164164
virtual bool CommandExists(const char* szKey, const char* szCommand, bool bCheckState = false, bool bState = true, const char* szArguments = NULL,
165165
const char* szResource = NULL, bool bCheckScriptCreated = false, bool bScriptCreated = false) = 0;
166166
virtual bool SetCommandActive(const char* szKey, const char* szCommand, bool bState, const char* szArguments, const char* szResource, bool bActive,
167-
bool checkHitState) = 0;
167+
bool checkHitState, bool bConsiderDefaultKey = false) = 0;
168168
virtual void SetAllCommandsActive(const char* szResource, bool bActive, const char* szCommand = NULL, bool bState = true, const char* szArguments = NULL,
169-
bool checkHitState = false) = 0;
169+
bool checkHitState = false, const char* szOnlyWithDefaultKey = NULL) = 0;
170170
virtual CCommandBind* GetBindFromCommand(const char* szCommand, const char* szArguments = NULL, bool bMatchCase = true, const char* szKey = NULL,
171171
bool bCheckHitState = false, bool bState = NULL) = 0;
172172
virtual bool GetBoundCommands(const char* szCommand, std::list<CCommandBind*>& commandsList) = 0;

0 commit comments

Comments
 (0)