Skip to content

Commit c5c6b3c

Browse files
emre1702ccw808
authored andcommitted
#9178 - Fix bindKey & unbindKey on commands (#201)
1 parent c707b75 commit c5c6b3c

File tree

2 files changed

+35
-41
lines changed

2 files changed

+35
-41
lines changed

Client/core/CKeyBinds.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,7 @@ bool CKeyBinds::SetCommandActive(const char* szKey, const char* szCommand, bool
770770
{
771771
NullEmptyStrings(szKey, szCommand, szArguments);
772772

773+
bool bReturn = false;
773774
list<CKeyBind*>::const_iterator iter = m_pList->begin();
774775
for (; iter != m_pList->end(); iter++)
775776
{
@@ -784,18 +785,25 @@ bool CKeyBinds::SetCommandActive(const char* szKey, const char* szCommand, bool
784785
{
785786
if (!checkHitState || (pBind->bHitState == bState))
786787
{
787-
if (!szArguments || (pBind->szArguments && strcmp(pBind->szArguments, szArguments) == 0))
788+
if ((!szArguments && (!bActive || !pBind->szArguments))
789+
|| (szArguments && pBind->szArguments && strcmp(pBind->szArguments, szArguments) == 0))
788790
{
791+
bool bOldActive = pBind->bActive;
789792
pBind->bActive = bActive;
790-
return true;
793+
if (szArguments)
794+
{
795+
return true;
796+
}
797+
else
798+
bReturn = (bReturn || bOldActive != bActive);
791799
}
792800
}
793801
}
794802
}
795803
}
796804
}
797805
}
798-
return false;
806+
return bReturn;
799807
}
800808

801809
void CKeyBinds::SetAllCommandsActive(const char* szResource, bool bActive, const char* szCommand, bool bState, const char* szArguments, bool checkHitState)

Client/mods/deathmatch/logic/CStaticFunctionDefinitions.cpp

Lines changed: 24 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -6408,6 +6408,24 @@ bool CStaticFunctionDefinitions::BindKey(const char* szKey, const char* szHitSta
64086408
return bSuccess;
64096409
}
64106410

6411+
static inline void BindKeyAtHitState(CKeyBindsInterface* pKeyBinds, const char* szKey, const char* szCommandName, const char* szArguments, const char* szResource, const bool bHitState, bool& bSuccess)
6412+
{
6413+
// Check if its binded already (dont rebind)
6414+
if (!pKeyBinds->CommandExists(szKey, szCommandName, true, bHitState, szArguments, szResource, true, true))
6415+
{
6416+
if (pKeyBinds->AddCommand(szKey, szCommandName, szArguments, bHitState, szResource, true))
6417+
{
6418+
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, szArguments, szResource, true, true);
6419+
bSuccess = true;
6420+
}
6421+
}
6422+
else
6423+
{
6424+
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, szArguments, szResource, true, true);
6425+
bSuccess = true;
6426+
}
6427+
}
6428+
64116429
bool CStaticFunctionDefinitions::BindKey(const char* szKey, const char* szHitState, const char* szCommandName, const char* szArguments, const char* szResource)
64126430
{
64136431
assert(szKey);
@@ -6419,30 +6437,13 @@ bool CStaticFunctionDefinitions::BindKey(const char* szKey, const char* szHitSta
64196437
bool bKey = pKeyBinds->IsKey(szKey);
64206438
if (bKey)
64216439
{
6422-
bool bHitState = true;
6423-
// Activate all keys for this command
6424-
pKeyBinds->SetAllCommandsActive(szResource, true, szCommandName, bHitState, szArguments, true);
6425-
// Check if its binded already (dont rebind)
6426-
if (pKeyBinds->CommandExists(szKey, szCommandName, true, bHitState, szArguments, szResource, true, true))
6427-
return true;
6428-
6429-
if ((!stricmp(szHitState, "down") || !stricmp(szHitState, "both")) &&
6430-
pKeyBinds->AddCommand(szKey, szCommandName, szArguments, bHitState, szResource, true))
6440+
if (!stricmp(szHitState, "down") || !stricmp(szHitState, "both"))
64316441
{
6432-
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, szArguments, szResource, true, true);
6433-
bSuccess = true;
6442+
BindKeyAtHitState(pKeyBinds, szKey, szCommandName, szArguments, szResource, true, bSuccess);
64346443
}
6435-
6436-
bHitState = false;
6437-
pKeyBinds->SetAllCommandsActive(szResource, true, szCommandName, bHitState, szArguments, true);
6438-
if (pKeyBinds->CommandExists(szKey, szCommandName, true, bHitState, szArguments, szResource, true, true))
6439-
return true;
6440-
6441-
if ((!stricmp(szHitState, "up") || !stricmp(szHitState, "both")) &&
6442-
pKeyBinds->AddCommand(szKey, szCommandName, szArguments, bHitState, szResource, true))
6444+
if (!stricmp(szHitState, "up") || !stricmp(szHitState, "both"))
64436445
{
6444-
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, szArguments, szResource, true, true);
6445-
bSuccess = true;
6446+
BindKeyAtHitState(pKeyBinds, szKey, szCommandName, szArguments, szResource, false, bSuccess);
64466447
}
64476448
}
64486449
return bSuccess;
@@ -6498,29 +6499,14 @@ bool CStaticFunctionDefinitions::UnbindKey(const char* szKey, const char* szHitS
64986499
bool bKey = pKeyBinds->IsKey(szKey);
64996500
if (bKey)
65006501
{
6501-
bool bCheckHitState = false, bHitState = true;
6502-
if (szHitState)
6503-
{
6504-
if (stricmp(szHitState, "down") == 0)
6505-
{
6506-
bCheckHitState = true, bHitState = true;
6507-
}
6508-
else if (stricmp(szHitState, "up") == 0)
6509-
{
6510-
bCheckHitState = true, bHitState = false;
6511-
}
6512-
}
65136502
if ((!stricmp(szHitState, "down") || !stricmp(szHitState, "both")) &&
6514-
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, NULL, szResource, false, true))
6503+
pKeyBinds->SetCommandActive(szKey, szCommandName, true, NULL, szResource, false, true))
65156504
{
6516-
pKeyBinds->SetAllCommandsActive(szResource, false, szCommandName, bHitState, NULL, true);
65176505
bSuccess = true;
65186506
}
6519-
bHitState = false;
65206507
if ((!stricmp(szHitState, "up") || !stricmp(szHitState, "both")) &&
6521-
pKeyBinds->SetCommandActive(szKey, szCommandName, bHitState, NULL, szResource, false, true))
6508+
pKeyBinds->SetCommandActive(szKey, szCommandName, false, NULL, szResource, false, true))
65226509
{
6523-
pKeyBinds->SetAllCommandsActive(szResource, false, szCommandName, bHitState, NULL, true);
65246510
bSuccess = true;
65256511
}
65266512
}

0 commit comments

Comments
 (0)