Skip to content

Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.

fix(gameclient): escape skips the scene, and the cursor is taken only once it arrives

Olcay Seygan2bac45019c10
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h
index 99c112b7d..d0744d4e6 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/CommandXlat.h
@@ -58,8 +58,9 @@ private:
ICoord2D m_mouseRightDragLift; // the location of a possible mouse drag end
UnsignedInt m_mouseRightDown; // when the mouse down happened
UnsignedInt m_mouseRightUp; // when the mouse up happened
- Coord3D m_mouseRightDragAnchorCamera; // where the camera was at the press
- Coord3D m_mouseRightDragLiftCamera; // where the camera was at the release
+ // No camera term here on purpose: a right click issued while the map is edge-scrolling is
+ // still an order, and weighing the camera's travel turned those into drags and lost them.
+ // The deselect path in SelectionXlat does weigh it, which is where it belongs.
// latched the moment the right button goes down: whether this drag is drawing a formation line.
// Latched rather than asked again, so a selection that changes mid-drag cannot abandon a line
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 4a5829c4c..f46a4d588 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -1399,8 +1399,6 @@ CommandTranslator::CommandTranslator() :
m_mouseRightDragAnchor.y = 0;
m_mouseRightDragLift.x = 0;
m_mouseRightDragLift.y = 0;
- m_mouseRightDragAnchorCamera.zero();
- m_mouseRightDragLiftCamera.zero();
}
//====================================================================================
@@ -3919,7 +3917,6 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
// 2) Time has exceeded the time which we allow for this to be a click.
m_mouseRightDragAnchor = msg->getArgument( 0 )->pixel;
m_mouseRightDown = (UnsignedInt) msg->getArgument( 2 )->integer;
- TheTacticalView->getPosition( &m_mouseRightDragAnchorCamera );
m_formationDragArmed = isFormationDragArmed();
@@ -3956,7 +3953,6 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
// register this event for determining if the click was fast or short enough not to be a drag
m_mouseRightDragLift = msg->getArgument( 0 )->pixel;
m_mouseRightUp = (UnsignedInt) msg->getArgument( 2 )->integer;
- TheTacticalView->getPosition( &m_mouseRightDragLiftCamera );
if( m_formationDragArmed )
{
@@ -4010,7 +4006,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
//didn't have anything selected which is possible via the shortcut bar. Normally, it would get deselected
//via the deselect drawable code.
if( TheMouse->isClick(&m_mouseRightDragAnchor, &m_mouseRightDragLift,
- &m_mouseRightDragAnchorCamera, &m_mouseRightDragLiftCamera,
+ NULL, NULL,
m_mouseRightDown, m_mouseRightUp) )
{
TheInGameUI->placeBuildAvailable( NULL, NULL );
@@ -4045,7 +4041,7 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
// which is gone: a click here commands, a drag draws a formation line, and neither of
// them scrolls.
if (TheMouse->isClick(&m_mouseRightDragAnchor, &m_mouseRightDragLift,
- &m_mouseRightDragAnchorCamera, &m_mouseRightDragLiftCamera,
+ NULL, NULL,
m_mouseRightDown, m_mouseRightUp))
{
Bool isPoint = (msg->getArgument(0)->pixelRegion.height() == 0 && msg->getArgument(0)->pixelRegion.width() == 0);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
index e0b912cbe..fed9aa440 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
@@ -341,9 +341,11 @@ GameMessageDisposition WindowTranslator::translateGameMessage(const GameMessage
returnCode = WIN_INPUT_USED;
}
- if(returnCode != WIN_INPUT_USED
- && (key == KEY_ESC)
- && (BitTest( state, KEY_STATE_UP ))
+ // With input disabled - a scripted camera scene - swallow every key but Escape. This
+ // read the other way round: it ate Escape, the one key meant to get through, and let
+ // everything else past to move the camera out from under the scene.
+ if(returnCode != WIN_INPUT_USED
+ && (key != KEY_ESC)
&& (TheInGameUI && (TheInGameUI->getInputEnabled() == FALSE)) )
{
returnCode = WIN_INPUT_USED;
diff --git a/GeneralsMD/Code/Main/WinMain.cpp b/GeneralsMD/Code/Main/WinMain.cpp
index 44962553a..8a1137117 100644
--- a/GeneralsMD/Code/Main/WinMain.cpp
+++ b/GeneralsMD/Code/Main/WinMain.cpp
@@ -99,7 +99,26 @@ extern void Reset_D3D_Device(bool active);
static Bool gInitializing = false;
static Bool gDoPaint = true;
-static Bool isWinMainActive = false;
+static Bool isWinMainActive = false;
+
+// Whether the cursor is currently clipped to the window. Activating the game by clicking the
+// taskbar leaves the pointer wherever it was, and clipping right then snatched it into the window
+// from across the desktop; the clip waits for the pointer to arrive on its own now.
+static Bool isCursorClippedToWindow = false;
+
+//-------------------------------------------------------------------------------------------------
+/** True when the OS cursor is over our client area right now. */
+//-------------------------------------------------------------------------------------------------
+static Bool isCursorOverWindow( void )
+{
+ POINT cursor;
+ RECT windowRect;
+
+ if( ApplicationHWnd == NULL || !GetCursorPos( &cursor ) || !GetWindowRect( ApplicationHWnd, &windowRect ) )
+ return false;
+
+ return PtInRect( &windowRect, cursor ) != 0;
+}
static HBITMAP gLoadScreenBitmap = NULL;
@@ -518,13 +537,18 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
{
ClipCursor( NULL );
+ isCursorClippedToWindow = false;
if (TheAudio)
TheAudio->loseFocus();
} // end if
else
{
- if( TheMouse )
+ // Only take the cursor if it is already over us. See isCursorOverWindow.
+ if( TheMouse && isCursorOverWindow() )
+ {
TheMouse->setMouseLimits();
+ isCursorClippedToWindow = true;
+ }
if (TheAudio)
TheAudio->regainFocus();
@@ -612,6 +636,13 @@ LRESULT CALLBACK WndProc( HWND hWnd, UINT message,
if( x < rect.left || x > rect.right || y < rect.top || y > rect.bottom )
return 0;
+ // The pointer has walked in of its own accord, so it is fair to hold it now.
+ if( isWinMainActive && !isCursorClippedToWindow && TheMouse )
+ {
+ TheMouse->setMouseLimits();
+ isCursorClippedToWindow = true;
+ }
+
if( TheWin32Mouse )
TheWin32Mouse->addWin32Event( message, wParam, lParam, TheMessageTime );