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): clean grid after deselect, money plate fits the income

Olcay Seyganb39eacfdf202
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index f3dc5179b..8865690de 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -1539,6 +1539,7 @@ protected:
Int m_lastMoneyDisplayed; ///< so the money gadget is only written when the amount changes
Int m_lastEarningDisplayed; ///< or the money earned a second beside it
MoneyPlateWidth m_moneyPlate; ///< the money plate's width, following the figure's
+ DisplayString * m_moneyMeasure; ///< the money's text on one line, never wrapped, to measure it by
UnsignedInt m_hudDrawCount; ///< rendered frames counted by drawHudOverlay itself
UnsignedInt m_hudLastSampleFrame; ///< m_hudDrawCount the fps sample was last refreshed on
UnsignedInt m_hudLastSampleMs; ///< wall clock of that sample
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 1646f629c..cb95158e4 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -263,12 +263,15 @@ Bool ControlBar_commandPlaces( const Int *types, const Int *pinned, Int count, I
//-------------------------------------------------------------------------------------------------
Bool ControlBar::getCommandPlaces( Int *places ) const
{
+ // a context without the command group (nothing selected, a building going up, a beacon) hides the
+ // group's parent and leaves the buttons as the last selection set them: those are not on the bar
+ const Bool groupShown = !m_contextParent[ CP_COMMAND ]->winIsHidden();
Int types[ MAX_COMMANDS_PER_SET ];
Int pinned[ MAX_COMMANDS_PER_SET ];
for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )
{
GameWindow *window = m_commandWindows[ slot ];
- const CommandButton *command = ( window && !BitTest( window->winGetStatus(), WIN_STATUS_HIDDEN ) )
+ const CommandButton *command = ( groupShown && window && !BitTest( window->winGetStatus(), WIN_STATUS_HIDDEN ) )
? (const CommandButton *)GadgetButtonGetData( window ) : NULL;
types[ slot ] = command ? command->getCommandType() : GUI_COMMAND_NONE;
pinned[ slot ] = command ? ControlBar_namedCommandPlace( command->getName().str() ) : -1;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 353e5c0d3..fe26f8907 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1189,6 +1189,7 @@ InGameUI::InGameUI()
m_lastMoneyDisplayed = -1;
m_lastEarningDisplayed = 0;
m_moneyPlate = MoneyPlateWidth();
+ m_moneyMeasure = NULL;
m_hudDrawCount = 0;
m_hudLastSampleFrame = 0;
m_hudLastSampleMs = 0;
@@ -11647,10 +11648,19 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, I
putPowerGroove( values, power, centreShown );
putPowerBar( values, lists[ "powercells" ] ); // after the groove, which it divides into cells
// the money's well is as wide as the figure and a margin each side, following it through
- // InGameUI_moneyPlateWidth on the client's clock
+ // InGameUI_moneyPlateWidth on the client's clock. The gadget's own string is wrapped to the
+ // window's width every time it draws, so measured it gave the widest line of a figure already cut
+ // in two, "$ 10000" without its "+25/s", and the plate stayed too narrow to ever unwrap it: the
+ // text is measured on a string of its own that never wraps
GameWindow *moneyWindow = controlBarWindow( "MoneyDisplay" );
- const Int moneyNeeded = ( (TextData *)moneyWindow->winGetUserData() )->text->getWidth()
- + 2 * REAL_TO_INT( MONEY_TEXT_MARGIN * scale );
+ DisplayString *moneyText = ( (TextData *)moneyWindow->winGetUserData() )->text;
+ if( m_moneyMeasure == NULL )
+ m_moneyMeasure = TheDisplayStringManager->newDisplayString();
+ if( m_moneyMeasure->getFont() != moneyText->getFont() )
+ m_moneyMeasure->setFont( moneyText->getFont() );
+ if( m_moneyMeasure->getText().compare( moneyText->getText() ) != 0 )
+ m_moneyMeasure->setText( moneyText->getText() );
+ const Int moneyNeeded = m_moneyMeasure->getWidth() + 2 * REAL_TO_INT( MONEY_TEXT_MARGIN * scale );
putMoney( values, powerBox, InGameUI_moneyPlateWidth( m_moneyPlate, moneyNeeded, nowMs ),
centreShown && !moneyWindow->winIsHidden() );
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index 311f8aad5..d1ece7db4 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -3083,6 +3083,13 @@ TEST(controlbar_command_places_follow_the_owners_drawing)
const Int C = GUI_COMMAND_DOZER_CONSTRUCT;
const Int nothingPinned[ SLOTS ] = { -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1 };
+ /* nothing on the bar, which is what getCommandPlaces hands over for a hidden command group (the
+ last unit deselected or dead) whatever its buttons still hold: no place taken, no page keys */
+ const Int empty[ SLOTS ] = { N, N, N, N, N, N, N, N, N, N, N, N, N, N };
+ CHECK( !ControlBar_commandPlaces( empty, nothingPinned, SLOTS, places ) );
+ for( Int slot = 0; slot < SLOTS; slot++ )
+ CHECK_EQ( places[ slot ], -1 );
+
/* AmericaDozerCommandSet: structures in slots 1 to 9, 11 and 13, disarm mines in 14. The disarm
is pinned to N by its button's name; the eleven structures pack toward the top left in the
owner's order, Q A W Z S E X D R C F */