From 92db73eb8991350b342ee6db47f412a0af90adca Mon Sep 17 00:00:00 2001 From: pierow Date: Thu, 9 May 2024 07:42:19 -0400 Subject: [PATCH] Fix side mouse buttons registering as left click when using the cursor. - also allow mouse3/4/5 binds to be accessible as commander. --- main/source/cl_dll/input.cpp | 40 +++++++++++++++++++++ main/source/cl_dll/inputw32.cpp | 15 ++++++-- main/source/mod/AvHCommanderModeHandler.cpp | 24 +++++++++++-- main/source/mod/AvHPieMenuHandler.cpp | 9 +++++ main/source/mod/AvHScrollHandler.cpp | 24 +++++++++++-- 5 files changed, 105 insertions(+), 7 deletions(-) diff --git a/main/source/cl_dll/input.cpp b/main/source/cl_dll/input.cpp index c5b27b67..b92e036c 100644 --- a/main/source/cl_dll/input.cpp +++ b/main/source/cl_dll/input.cpp @@ -109,6 +109,9 @@ int in_cancel = 0; bool pistolHandlerDown = false; +extern int g_iVisibleMouse; +int g_iVguiSideMouse; + cvar_t *m_pitch; cvar_t *m_yaw; cvar_t *m_forward; @@ -567,6 +570,38 @@ Return 1 to allow engine to process the key, otherwise, act on it as needed int CL_DLLEXPORT HUD_Key_Event( int down, int keynum, const char *pszCurrentBinding ) { // RecClKeyEvent(down, keynum, pszCurrentBinding); + + // 2024 - Check mouse button presses when the cursor is visible to fix issues with VGUI registering mouse4/5 as left click. Previously these were blocked in inputw32. + // Also note that g_iVguiSideMouseRelease is set in inputw32, because for some reason side mouse button releases in VGUI mode don't get sent here. + if (g_iVisibleMouse && (keynum >= K_MOUSE1 && keynum <= K_MOUSE5)) + { + //gEngfuncs.Con_Printf("mouse event keynum:%d down:%d\n", keynum, down); + + switch (keynum) + { + case K_MOUSE1: + case K_MOUSE2: + g_iVguiSideMouse = 0; + return 0; + case K_MOUSE3: + g_iVguiSideMouse = 0; + // Allow mouse3 binds while commanding since commander VGUI currently doesn't use it. + if (!gHUD.GetInTopDownMode()) + { + return 0; + } + break; + case K_MOUSE4: + case K_MOUSE5: + g_iVguiSideMouse = keynum; + + if (!gHUD.GetInTopDownMode()) + { + return 0; + } + break; + } + } // Check to see if the event has any outlawed commands in it. float theBlockScripts = gHUD.GetServerVariableFloat(kvBlockScripts); @@ -1194,6 +1229,11 @@ void CL_DLLEXPORT CL_CreateMove ( float frametime, struct usercmd_s *cmd, int ac theProcessedMove = true; theIsSendingSpecialEvent = true; } + else + { + // Clear the impulse so it doesn't execute once leaving the chair. + in_impulse = 0; + } } if(!theProcessedMove && gHUD.GetAndClearSelectionEvent(theMouseNormPos, theTechEvent)) diff --git a/main/source/cl_dll/inputw32.cpp b/main/source/cl_dll/inputw32.cpp index b741c25f..bcefe952 100644 --- a/main/source/cl_dll/inputw32.cpp +++ b/main/source/cl_dll/inputw32.cpp @@ -35,6 +35,7 @@ // use IN_SetVisibleMouse to set: int g_iVisibleMouse = 0; +int g_iVguiSideMouseRelease = 0; extern cl_enginefunc_t gEngfuncs; @@ -534,8 +535,9 @@ IN_MouseEvent void CL_DLLEXPORT IN_MouseEvent (int mstate) { int i; + g_iVguiSideMouseRelease = 0; - if ( iMouseInUse || g_iVisibleMouse ) + if ( iMouseInUse /*|| g_iVisibleMouse */) // Mouse button processing when the cursor is visible moved to HUD_Key_Event. return; // perform button actions @@ -551,9 +553,16 @@ void CL_DLLEXPORT IN_MouseEvent (int mstate) (mouse_oldbuttonstate & (1<= 3) + { + g_iVguiSideMouseRelease = K_MOUSE1 + i; + } } - } - + } + mouse_oldbuttonstate = mstate; } diff --git a/main/source/mod/AvHCommanderModeHandler.cpp b/main/source/mod/AvHCommanderModeHandler.cpp index 3d2aa3c9..4952eb9e 100644 --- a/main/source/mod/AvHCommanderModeHandler.cpp +++ b/main/source/mod/AvHCommanderModeHandler.cpp @@ -65,6 +65,10 @@ #include "AvHTechImpulsePanel.h" #include "AvHCommandConstants.h" #include "../util/STLUtil.h" +//#include "keydefs.h" + +extern int g_iVguiSideMouse; +extern int g_iVguiSideMouseRelease; AvHCommanderModeHandler::AvHCommanderModeHandler() { @@ -758,7 +762,7 @@ void AvHCommanderModeHandler::mousePressed(MouseCode code, Panel* inPanel) // if the cursor is no longer on the panel. App::getInstance()->setMouseCapture(inPanel); - if(code == MOUSE_LEFT) + if(code == MOUSE_LEFT && !g_iVguiSideMouse) { this->mMouseOneDown = true; @@ -795,6 +799,22 @@ void AvHCommanderModeHandler::mousePressed(MouseCode code, Panel* inPanel) //this->DefaultOrderToLastMousePosition(theHierarchy); } } + //// TO DO: Custom bind cvars for comm side mouse buttons. + //else if (code == MOUSE_MIDDLE) + //{ + // this->mLastTechPressed = ; + // this->mTechNodePressed = true; + //} + //else if (code == vgui::MOUSE_LEFT && g_iVguiSideMouse == K_MOUSE4) + //{ + // this->mLastTechPressed = ; + // this->mTechNodePressed = true; + //} + //else if (code == vgui::MOUSE_LEFT && g_iVguiSideMouse == K_MOUSE5) + //{ + // this->mLastTechPressed = ; + // this->mTechNodePressed = true; + //} } void AvHCommanderModeHandler::mouseDoublePressed(MouseCode code, Panel* inPanel) @@ -856,7 +876,7 @@ void AvHCommanderModeHandler::mouseReleased(MouseCode code, Panel* inPanel) App::getInstance()->setMouseCapture(NULL); - if(code == MOUSE_LEFT) + if(code == MOUSE_LEFT && !g_iVguiSideMouse && !g_iVguiSideMouseRelease) { if (GetIsPointInPanel(inPanel, mLastMouseX, mLastMouseY)) diff --git a/main/source/mod/AvHPieMenuHandler.cpp b/main/source/mod/AvHPieMenuHandler.cpp index 79e05bff..e273f48b 100644 --- a/main/source/mod/AvHPieMenuHandler.cpp +++ b/main/source/mod/AvHPieMenuHandler.cpp @@ -57,6 +57,9 @@ extern int g_weaponselect; extern int in_impulse; bool sTheDebugBool = false; +extern int g_iVguiSideMouse; +//extern int g_iVguiSideMouseRelease; + PieNode* AvHPieMenuHandler::sLastNodeHighlighted = NULL; string AvHPieMenuHandler::sPieMenuName = ""; float AvHPieMenuHandler::sTimeLastNodeHighlighted = 0.0f; @@ -385,6 +388,12 @@ void AvHPieMenuHandler::cursorExited(Panel* panel) void AvHPieMenuHandler::mousePressed(MouseCode code,Panel* panel) { + // Don't register side mouse button clicks. + if (code == vgui::MOUSE_LEFT && g_iVguiSideMouse) + { + return; + } + ClosePieMenu(); //CenterPrint("AvHPieMenuHandler::mousePressed.\n"); } diff --git a/main/source/mod/AvHScrollHandler.cpp b/main/source/mod/AvHScrollHandler.cpp index a9f75f24..11fe3e59 100644 --- a/main/source/mod/AvHScrollHandler.cpp +++ b/main/source/mod/AvHScrollHandler.cpp @@ -6,6 +6,7 @@ #include "AvHScrollPanel.h" #include "AvHActionButtons.h" #include "ui/UIUtil.h" +//#include "keydefs.h" int AvHScrollHandler::sScrollX = 0; int AvHScrollHandler::sScrollY = 0; @@ -20,6 +21,9 @@ bool AvHScrollHandler::sMouseOneDown = false; bool AvHScrollHandler::sMouseTwoDown = false; int AvHScrollHandler::sKeyDown = 0; +extern int g_iVguiSideMouse; +extern int g_iVguiSideMouseRelease; + AvHScrollHandler::AvHScrollHandler() { sKeyDown = 0; @@ -218,7 +222,7 @@ void AvHScrollHandler::keyPressed(KeyCode inKeyCode, Panel* panel) void AvHScrollHandler::mousePressed(MouseCode code, Panel* panel) { // store this - if(code == vgui::MOUSE_LEFT) + if(code == vgui::MOUSE_LEFT && !g_iVguiSideMouse) { sMouseOneDown = true; } @@ -226,12 +230,28 @@ void AvHScrollHandler::mousePressed(MouseCode code, Panel* panel) { sMouseTwoDown = true; } + //// TO DO: Custom bind cvars for comm side mouse buttons. + //else if (code == MOUSE_MIDDLE) + //{ + // this->mLastTechPressed = ; + // this->mTechNodePressed = true; + //} + //else if (code == vgui::MOUSE_LEFT && g_iVguiSideMouse == K_MOUSE4) + //{ + // this->mLastTechPressed = ; + // this->mTechNodePressed = true; + //} + //else if (code == vgui::MOUSE_LEFT && g_iVguiSideMouse == K_MOUSE5) + //{ + // this->mLastTechPressed = ; + // this->mTechNodePressed = true; + //} } void AvHScrollHandler::mouseReleased(MouseCode code, Panel* panel) { // store this - if(code == vgui::MOUSE_LEFT) + if(code == vgui::MOUSE_LEFT && !g_iVguiSideMouse && !g_iVguiSideMouseRelease) { sMouseOneDown = false; }