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.

feat(gameengine): promotion screen dims the field and closes on an outside click

Olcay Seygan880a9c37d568
diff --git a/CHANGELOG.md b/CHANGELOG.md
index be1ffe8d2..a00aefa2d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -32,7 +32,7 @@ found and fixed — EA's own, not port damage.**
- Point at the attack, hold position or move key and a card says what it does, in English or Turkish. Those three are painted onto the grid rather than given to a unit, so the game had no card for them and showed nothing. The card stands on top of the command bar like every other button's.
- HUD Size grows the console from its middle, and on a narrow screen it stops at the size that still fits.
- The grid under a building you are placing is fainter and its lines thinner, and the red squares where nothing can stand are lighter, so the ground under them shows through. Untick grid placement on the Controls page and the lines go altogether.
-- Your general's promotion screen opens in the middle of the screen, in the Classic interface as well, instead of hanging from the top edge.
+- Your general's promotion screen opens in the middle of the screen, in the Classic interface as well, instead of hanging from the top edge. The battlefield dims behind it, and a click anywhere off the screen closes it without selecting or ordering anything underneath.
## Groups attack-move at their own speed
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/WindowXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/WindowXlat.h
index 68d2dd530..3b6e9c778 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/WindowXlat.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/WindowXlat.h
@@ -38,6 +38,7 @@ class WindowTranslator : public GameMessageTranslator
{
private:
Bool m_rightClickTaken; ///< a GUI right press owns its drag/release even outside the window
+ Bool m_promotionClickTaken; ///< a press that closed the promotion screen owns its drags and release
public:
WindowTranslator();
~WindowTranslator();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 67da7c0c0..bf36e9217 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -2945,6 +2945,17 @@ void ControlBar::shutdownWindows( void )
} // end shutdownWindows
+/** The painted promotion screen's own draw, and the battlefield and bar dimmed under it the way the
+ * Reforged page dims them (Promotion.html, .dim); the page takes the draw over in Reforged. */
+static GameWinDrawFunc theClassicPromotionDraw = NULL;
+
+static void drawClassicPromotionScreen( GameWindow *window, WinInstanceData *instData )
+{
+ enum { DIM_ALPHA = 166 }; ///< rgba(0, 0, 0, 0.65)
+ TheDisplay->drawFillRect( 0, 0, TheDisplay->getWidth(), TheDisplay->getHeight(), GameMakeColor( 0, 0, 0, DIM_ALPHA ) );
+ theClassicPromotionDraw( window, instData );
+}
+
//-------------------------------------------------------------------------------------------------
/** Look up every window the bar drives, and lay the bar out. Re-callable: a resolution change
* rebuilds ControlBar.wnd and then calls this instead of replacing the whole ControlBar. */
@@ -2987,6 +2998,8 @@ void ControlBar::initWindows( void )
id = TheNameKeyGenerator->nameToKey( "GeneralsExpPoints.wnd:GenExpParent" );
m_contextParent[ CP_PURCHASE_SCIENCE ] = TheWindowManager->winGetWindowFromId( NULL, id );//m_scienceLayout->getFirstWindow();
+ theClassicPromotionDraw = m_contextParent[ CP_PURCHASE_SCIENCE ]->winGetDrawFunc();
+ m_contextParent[ CP_PURCHASE_SCIENCE ]->winSetDrawFunc( drawClassicPromotionScreen );
id = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:UnderConstructionWindow" );
m_contextParent[ CP_UNDER_CONSTRUCTION ] = TheWindowManager->winGetWindowFromId( NULL, id );
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
index 9b1becddc..fc0c87d2a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/WindowXlat.cpp
@@ -51,7 +51,9 @@
// USER INCLUDES //////////////////////////////////////////////////////////////
#include "Common/MessageStream.h"
+#include "Common/NameKeyGenerator.h"
#include "Common/Radar.h"
+#include "GameClient/ControlBar.h"
#include "GameClient/GameWindowManager.h"
#include "GameClient/WindowXlat.h"
#include "GameClient/LookAtXlat.h"
@@ -160,7 +162,7 @@ static GameWindowMessage rawMouseToWindowMessage( const GameMessage *msg )
///////////////////////////////////////////////////////////////////////////////
//=============================================================================
-WindowTranslator::WindowTranslator() : m_rightClickTaken(FALSE)
+WindowTranslator::WindowTranslator() : m_rightClickTaken(FALSE), m_promotionClickTaken(FALSE)
{
}
@@ -196,6 +198,50 @@ GameMessageDisposition WindowTranslator::translateGameMessage(const GameMessage
return DESTROY_MESSAGE;
}
+ // The promotion screen is modal. A press anywhere off it closes it and goes no further, to the
+ // battlefield or the bar, and neither do that press's drags and release.
+ switch( msg->getType() )
+ {
+ case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN:
+ case GameMessage::MSG_RAW_MOUSE_LEFT_DOUBLE_CLICK:
+ case GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN:
+ case GameMessage::MSG_RAW_MOUSE_MIDDLE_DOUBLE_CLICK:
+ case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN:
+ case GameMessage::MSG_RAW_MOUSE_RIGHT_DOUBLE_CLICK:
+ {
+ if( TheControlBar == NULL || !TheControlBar->isPurchaseScienceVisible() )
+ break;
+ static const NameKeyType screenID = NAMEKEY( "GeneralsExpPoints.wnd:GenExpParent" );
+ GameWindow *screen = TheWindowManager->winGetWindowFromId( NULL, screenID );
+ ICoord2D origin, size;
+ screen->winGetScreenPosition( &origin.x, &origin.y );
+ screen->winGetSize( &size.x, &size.y );
+ const ICoord2D mousePos = msg->getArgument( 0 )->pixel;
+ if( mousePos.x >= origin.x && mousePos.x < origin.x + size.x && mousePos.y >= origin.y && mousePos.y < origin.y + size.y )
+ break;
+ TheControlBar->hidePurchaseScience();
+ m_promotionClickTaken = TRUE;
+ return DESTROY_MESSAGE;
+ }
+ case GameMessage::MSG_RAW_MOUSE_LEFT_DRAG:
+ case GameMessage::MSG_RAW_MOUSE_MIDDLE_DRAG:
+ case GameMessage::MSG_RAW_MOUSE_RIGHT_DRAG:
+ if( m_promotionClickTaken )
+ return DESTROY_MESSAGE;
+ break;
+ case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP:
+ case GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP:
+ case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP:
+ if( m_promotionClickTaken )
+ {
+ m_promotionClickTaken = FALSE;
+ return DESTROY_MESSAGE;
+ }
+ break;
+ default:
+ break;
+ }
+
// A minimap press already owns its drag and its release, even if keyboard scrolling has locked
// the tactical view's mouse input in the meantime.
const Bool minimapGrab = TheWindowManager && TheRadar &&