Skip to content

Commit b074f38

Browse files
committed
Fix #4499: Controls toggling with showCursor being globally unlocked
1 parent 3d1ff37 commit b074f38

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

Client/mods/deathmatch/logic/CResource.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ using namespace std;
2121
extern CClientGame* g_pClientGame;
2222

2323
int CResource::m_iShowingCursor = 0;
24+
int CResource::m_iToggleControls = 0;
2425

2526
CResource::CResource(unsigned short usNetID, const char* szResourceName, CClientEntity* pResourceEntity, CClientEntity* pResourceDynamicEntity,
2627
const CMtaVersion& strMinServerReq, const CMtaVersion& strMinClientReq, bool bEnableOOP)
@@ -31,6 +32,7 @@ CResource::CResource(unsigned short usNetID, const char* szResourceName, CClient
3132
m_bStarting = true;
3233
m_bStopping = false;
3334
m_bShowingCursor = false;
35+
m_bToggleControls = false;
3436
m_usRemainingNoClientCacheScripts = 0;
3537
m_bLoadAfterReceivingNoClientCacheScripts = false;
3638
m_strMinServerReq = strMinServerReq;
@@ -486,8 +488,19 @@ void CResource::ShowCursor(bool bShow, bool bToggleControls)
486488
m_bShowingCursor = bShow;
487489
}
488490

491+
bool bWantsToggle = m_bShowingCursor && bToggleControls;
492+
if (bWantsToggle != m_bToggleControls)
493+
{
494+
if (bWantsToggle)
495+
m_iToggleControls += 1;
496+
else
497+
m_iToggleControls -= 1;
498+
499+
m_bToggleControls = bWantsToggle;
500+
}
501+
489502
// Always update cursor and controls state regardless of cursor visibility change
490-
g_pCore->ForceCursorVisible(m_iShowingCursor > 0, bToggleControls);
503+
g_pCore->ForceCursorVisible(m_iShowingCursor > 0, m_iToggleControls > 0);
491504
g_pClientGame->SetCursorEventsEnabled(m_iShowingCursor > 0);
492505
}
493506

Client/mods/deathmatch/logic/CResource.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,8 @@ class CResource
142142
// To control cursor show/hide
143143
static int m_iShowingCursor;
144144
bool m_bShowingCursor;
145+
static int m_iToggleControls;
146+
bool m_bToggleControls;
145147

146148
SString m_strResourceDirectoryPath; // stores the path to /mods/deathmatch/resources/resource_name
147149
SString m_strResourcePrivateDirectoryPath; // stores the path to /mods/deathmatch/priv/server-id/resource_name

0 commit comments

Comments
 (0)