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(gameclient): put the peace time clock at the top and count its last ten seconds

Olcay Seygan75e6e274585f
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87966ed17..619adef19 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -433,7 +433,8 @@ found and fixed — EA's own, not port damage.**
- A new lobby setting next to starting cash: three, five, ten or fifteen minutes of truce at the head of the match, or none, which is how the game has always played. LAN and online carry it, only the host can change it, and everyone in the room sees the choice before the game starts.
- While it runs, nobody can attack anybody. Not a rush, not a scout taking a pot shot on the way past, not a shell fired at empty ground in the hope the splash counts.
- The ground around a command centre is not somewhere to wait. Anything of yours standing in an enemy's burns, and goes on burning until it leaves or dies. The truce buys you the time to build, not a free walk up to somebody's front door.
-- The clock counts down in red in the top right corner, above the game clock, for as long as it runs. You are also told when it starts, at a minute, thirty seconds and ten seconds left, and when it is over.
+- The clock sits in red at the top middle of the screen, where you are already looking: the word PEACE over the time left. You are also told when it starts, at a minute, thirty seconds and ten seconds left, and when it is over.
+- The last ten seconds are counted out in front of you, one big number at a time under the word PEACE, each one landing large and fading as the second runs out. The word stays exactly where it was, the plate under it goes, and the time is replaced by a number you cannot miss - all of it at the top of the screen, off the ground you are about to fight over.
- Put a computer player in the room and the truce switches itself off, whatever the host had picked. A computer opponent does not honour a truce - it stands still for five minutes and then plays exactly the game it was going to play - so all peace time buys against one is a handicap for the person who is not a computer. The box greys out and reads off while a bot is in a seat, and remembers the host's choice for when the bot leaves. That is also why the skirmish lobby has no such box: a skirmish is played against computer players.
## The lobby has a settings page
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index fe34b6b18..3475be49e 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -608,7 +608,11 @@ GUI:PeaceTimeOver
END
GUI:PeaceTimeHud
-"PEACE %d:%02d"
+"%d:%02d"
+END
+
+GUI:PeaceTimeHudLabel
+"PEACE"
END
GUI:LobbyTabChat
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index d2ace85c6..d5e22d5b2 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -1005,9 +1005,16 @@ protected:
SuperweaponMap m_superweapons[MAX_PLAYER_COUNT];
enum { HUD_OVERLAY_POINT_SIZE = 9 }; ///< small: this sits over the battlefield, not in a panel
enum { HUD_CLOCK_POINT_SIZE = 7 }; ///< smaller still, and bold: the clock/rate plate is a glance, not a read
- enum { PEACE_TIMER_POINT_SIZE = 12 }; ///< the peace time countdown is the one number you watch, so it is the big one
-
- void drawPeaceTimer( void ); ///< the lobby's peace time, counting down in the top right corner
+ enum { PEACE_TIMER_POINT_SIZE = 24 }; ///< the peace time clock is the one number you watch, so it is read from across the room
+ enum { PEACE_TIMER_LABEL_POINT_SIZE = 12 }; ///< the word over it, which is read once and then only glanced at
+ enum { PEACE_TIMER_TOP_PAD = 16 }; ///< how far its plate hangs below the top edge, an 800x600 number like the strip's
+ enum { PEACE_COUNTDOWN_POINT_SIZE = 96 }; ///< the last ten seconds, written across the middle of the battlefield
+ enum { PEACE_COUNTDOWN_SECONDS = 10 }; ///< how much of the peace time is counted out in the middle of the screen
+ enum { PEACE_COUNTDOWN_SIZE_STEP = 12 }; ///< the popping digit's point sizes are rounded to this, so the font library caches four of them rather than one per frame
+ enum { PEACE_COUNTDOWN_LABEL_SHARE = 4 }; ///< the word over that digit is this fraction of it
+
+ void drawPeaceTimer( void ); ///< the lobby's peace time, counting down at the top of the screen
+ void drawPeaceCountdown( UnsignedInt framesLeft ); ///< the last seconds of it, one big digit in the middle of the screen
void drawHudOverlay( void ); ///< the small elapsed-time / fps plate (ShowHudOverlay)
void drawProductionStrip( void ); ///< the production queue rows above the control bar
///< one run of cells - a column while playing, a player's row while watching - with its left
@@ -1024,7 +1031,9 @@ protected:
Real m_placementRingRadius; ///< the radius that ring was built at, so it is not rebuilt every frame
DisplayString * m_hudDisplayString; ///< the ShowHudOverlay line (fps / clock)
- DisplayString * m_peaceTimeDisplayString; ///< the peace time countdown in the corner
+ DisplayString * m_peaceTimeDisplayString; ///< the peace time clock at the top of the screen
+ DisplayString * m_peaceTimeLabelDisplayString; ///< the word written over that clock
+ DisplayString * m_peaceCountdownDisplayString; ///< the big digit of its last ten seconds
Int m_lastMoneyDisplayed; ///< so the money gadget is only written when the amount changes
UnsignedInt m_hudDrawCount; ///< rendered frames counted by drawHudOverlay itself
UnsignedInt m_hudLastSampleFrame; ///< m_hudDrawCount the fps sample was last refreshed on
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index e9aebfdf5..f9a940fa7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1127,6 +1127,8 @@ InGameUI::InGameUI()
forgetPendingPlacements();
m_hudDisplayString = NULL;
m_peaceTimeDisplayString = NULL;
+ m_peaceTimeLabelDisplayString = NULL;
+ m_peaceCountdownDisplayString = NULL;
m_lastMoneyDisplayed = -1;
m_hudDrawCount = 0;
m_hudLastSampleFrame = 0;
@@ -5851,16 +5853,33 @@ void InGameUI::updateFloatingText( void )
* only behind -displayDebug together with a screenful of engine internals. */
//-------------------------------------------------------------------------------------------------
//-------------------------------------------------------------------------------------------------
-/** The lobby's peace time, counting down in the top right corner: red, bold, and bigger than the
- * clock plate under it, because for as long as it is up it is the only number on the screen that
- * decides what you can do. It is not behind ShowHudOverlay - that switch is for a readout, and
- * this is a rule of the match. Nothing draws once the clock runs out. */
+/** How the last ten seconds of peace time animate, as fractions of one second. */
//-------------------------------------------------------------------------------------------------
-void InGameUI::drawPeaceTimer( void )
+static const Real PEACE_COUNTDOWN_POP_SCALE = 1.35f; ///< the size the digit lands at when the second turns
+static const Real PEACE_COUNTDOWN_POP_TIME = 0.35f; ///< how long it takes to settle back to its own size
+static const Real PEACE_COUNTDOWN_FADE_TIME = 0.30f; ///< how long it fades out for at the end of the second
+
+//-------------------------------------------------------------------------------------------------
+/** The one red the truce is written in, wherever it is written. */
+//-------------------------------------------------------------------------------------------------
+static Color peaceTimeColor( Int alpha )
{
- // the corner is measured fresh every frame, and this is the first thing in it
- m_hudOverlayBottom = 0;
+ return GameMakeColor( 255, 48, 48, alpha );
+}
+//-------------------------------------------------------------------------------------------------
+/** The lobby's peace time at the top of the screen, in the middle of it: the word PEACE in small
+ * letters over the time left, both red and bold on one plate. The top centre is where a player
+ * already looks for the state of the match, and it keeps the corner free for the clock and the
+ * superweapon timers. It is not behind ShowHudOverlay - that switch is for a readout, and this
+ * is a rule of the match.
+ *
+ * The plate goes away for the last ten seconds. Those are counted out across the middle of the
+ * screen instead, and two copies of the same number in two places is one of them asking to be
+ * read and neither getting it. Nothing draws once the truce runs out. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::drawPeaceTimer( void )
+{
if( TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )
return;
@@ -5868,6 +5887,12 @@ void InGameUI::drawPeaceTimer( void )
return;
const UnsignedInt left = TheGameLogic->getPeaceTimeEndFrame() - TheGameLogic->getFrame();
+ if( left <= PEACE_COUNTDOWN_SECONDS * LOGICFRAMES_PER_SECOND )
+ {
+ drawPeaceCountdown( left );
+ return;
+ }
+
const UnsignedInt secs = (left + LOGICFRAMES_PER_SECOND - 1) / LOGICFRAMES_PER_SECOND;
UnicodeString text;
@@ -5882,24 +5907,122 @@ void InGameUI::drawPeaceTimer( void )
}
m_peaceTimeDisplayString->setText( text );
+ // the label is a second string rather than a line of the first: the text renderer has no
+ // concept of a newline and would draw one as a character
+ if( m_peaceTimeLabelDisplayString == NULL )
+ {
+ m_peaceTimeLabelDisplayString = TheDisplayStringManager->newDisplayString();
+ m_peaceTimeLabelDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,
+ TheGlobalLanguageData->adjustFontSize( PEACE_TIMER_LABEL_POINT_SIZE ),
+ TRUE ) );
+ }
+ m_peaceTimeLabelDisplayString->setText( TheGameText->fetch( "GUI:PeaceTimeHudLabel" ) );
+
Int textWidth = 0, textHeight = 0;
m_peaceTimeDisplayString->getSize( &textWidth, &textHeight );
+ Int labelWidth = 0, labelHeight = 0;
+ m_peaceTimeLabelDisplayString->getSize( &labelWidth, &labelHeight );
+
+ // clear of the top edge rather than jammed against it, and the gap grows with the screen the
+ // same way the command bar under it does
const Int pad = 4;
- Int x = TheDisplay->getWidth() - textWidth - pad - 8;
- Int y = 3;
+ const Int plateWidth = (labelWidth > textWidth ? labelWidth : textWidth) + pad*2;
+ const Int plateLeft = (TheDisplay->getWidth() - plateWidth) / 2;
+ const Int top = stripPixels( PEACE_TIMER_TOP_PAD );
- TheDisplay->drawFillRect( x - pad, y - 1, textWidth + pad*2, textHeight + 2,
+ TheDisplay->drawFillRect( plateLeft, top - 1, plateWidth, labelHeight + textHeight + 2,
GameMakeColor( 0, 0, 0, 160 ) );
- m_hudOverlayBottom = y - 1 + textHeight + 2;
+ m_peaceTimeLabelDisplayString->draw( (TheDisplay->getWidth() - labelWidth) / 2, top,
+ peaceTimeColor( 255 ), GameMakeColor( 0, 0, 0, 255 ) );
+
+ m_peaceTimeDisplayString->draw( (TheDisplay->getWidth() - textWidth) / 2, top + labelHeight,
+ peaceTimeColor( 255 ), GameMakeColor( 0, 0, 0, 255 ) );
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The last ten seconds of that peace time, one digit at a time, with the plate at the top of the
+ * screen taken down for them. The word PEACE goes over the digit at a quarter of its size, on
+ * the same line the plate's own word was on, so what happens at ten seconds is the time being
+ * replaced by a number you cannot miss rather than the whole thing moving somewhere else. The
+ * middle of the screen is where the fighting you are about to do is, and a countdown sitting on
+ * your own units is in the way of the thing it counts down to.
+ *
+ * Each second the digit lands at PEACE_COUNTDOWN_POP_SCALE of its size, settles to it over the
+ * first third of the second, then fades out through the last third, so the movement is what
+ * catches the eye rather than the number changing. The word holds still and keeps its colour
+ * through all of it, and the digit grows downwards from under it, so nothing but the number
+ * moves.
+ *
+ * The animation is driven by the logic frame, not the wall clock, because the number it counts
+ * is a logic frame: a paused or slowed game shows a paused countdown instead of one that has
+ * run ahead of the truce it belongs to. */
+//-------------------------------------------------------------------------------------------------
+void InGameUI::drawPeaceCountdown( UnsignedInt framesLeft )
+{
+ const UnsignedInt secondsLeft = (framesLeft + LOGICFRAMES_PER_SECOND - 1) / LOGICFRAMES_PER_SECOND;
+ const UnsignedInt framesLeftOfSecond = framesLeft - (secondsLeft - 1) * LOGICFRAMES_PER_SECOND;
+ const Real secondElapsed = 1.0f - INT_TO_REAL( framesLeftOfSecond ) / INT_TO_REAL( LOGICFRAMES_PER_SECOND );
+
+ Real scale = 1.0f;
+ if( secondElapsed < PEACE_COUNTDOWN_POP_TIME )
+ scale = PEACE_COUNTDOWN_POP_SCALE
+ - (PEACE_COUNTDOWN_POP_SCALE - 1.0f) * (secondElapsed / PEACE_COUNTDOWN_POP_TIME);
+
+ Real opacity = 1.0f;
+ if( secondElapsed > 1.0f - PEACE_COUNTDOWN_FADE_TIME )
+ opacity = (1.0f - secondElapsed) / PEACE_COUNTDOWN_FADE_TIME;
+
+ // rounded to a step so a second's worth of scaling asks the font library for a few sizes, not thirty
+ const Int wantedPointSize = REAL_TO_INT_CEIL( PEACE_COUNTDOWN_POINT_SIZE * scale );
+ const Int pointSize = ((wantedPointSize + PEACE_COUNTDOWN_SIZE_STEP - 1) / PEACE_COUNTDOWN_SIZE_STEP)
+ * PEACE_COUNTDOWN_SIZE_STEP;
+
+ if( m_peaceCountdownDisplayString == NULL )
+ m_peaceCountdownDisplayString = TheDisplayStringManager->newDisplayString();
+
+ m_peaceCountdownDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,
+ TheGlobalLanguageData->adjustFontSize( pointSize ),
+ TRUE ) );
- m_peaceTimeDisplayString->draw( x, y, GameMakeColor( 255, 48, 48, 255 ), GameMakeColor( 0, 0, 0, 255 ) );
+ UnicodeString text;
+ text.format( L"%d", (Int)secondsLeft );
+ m_peaceCountdownDisplayString->setText( text );
+
+ // the same string the plate at the top uses, in its own size: the two are never up together
+ if( m_peaceTimeLabelDisplayString == NULL )
+ m_peaceTimeLabelDisplayString = TheDisplayStringManager->newDisplayString();
+
+ m_peaceTimeLabelDisplayString->setFont( TheFontLibrary->getFont( m_superweaponNormalFont,
+ TheGlobalLanguageData->adjustFontSize( PEACE_COUNTDOWN_POINT_SIZE
+ / PEACE_COUNTDOWN_LABEL_SHARE ),
+ TRUE ) );
+ m_peaceTimeLabelDisplayString->setText( TheGameText->fetch( "GUI:PeaceTimeHudLabel" ) );
+
+ Int textWidth = 0, textHeight = 0;
+ m_peaceCountdownDisplayString->getSize( &textWidth, &textHeight );
+
+ Int labelWidth = 0, labelHeight = 0;
+ m_peaceTimeLabelDisplayString->getSize( &labelWidth, &labelHeight );
+
+ // the same line the plate's word was on, so the word does not move when the plate goes
+ const Int top = stripPixels( PEACE_TIMER_TOP_PAD );
+ const Int alpha = REAL_TO_INT_CEIL( opacity * 255.0f );
+
+ m_peaceTimeLabelDisplayString->draw( (TheDisplay->getWidth() - labelWidth) / 2, top,
+ peaceTimeColor( 255 ), GameMakeColor( 0, 0, 0, 255 ) );
+
+ m_peaceCountdownDisplayString->draw( (TheDisplay->getWidth() - textWidth) / 2, top + labelHeight,
+ peaceTimeColor( alpha ), GameMakeColor( 0, 0, 0, alpha ) );
}
//-------------------------------------------------------------------------------------------------
void InGameUI::drawHudOverlay( void )
{
+ // the corner is measured fresh every frame, and this plate is the first thing in it
+ m_hudOverlayBottom = 0;
+
if( !TheGlobalData->m_showHudOverlay )
return;
@@ -5977,8 +6100,8 @@ void InGameUI::drawHudOverlay( void )
Int textWidth = 0, textHeight = 0;
m_hudDisplayString->getSize( &textWidth, &textHeight );
- // top right, clear of the radar and the superweapon timers - and under the peace time countdown
- // while that is up, because the corner holds one plate above the other.
+ // top right, clear of the radar and the superweapon timers, and first in that corner: the peace
+ // time clock is drawn across the top middle of the screen and takes no room here.
//
// The three gaps are 800x600 numbers put through the command bar's own scale, like everything
// else on this overlay. Held at a flat pixel count the plate crept into the corner as the
@@ -5986,7 +6109,7 @@ void InGameUI::drawHudOverlay( void )
// shot and a 1080-tall one did not overlay however the text was sized.
const Int pad = stripPixels( 2 );
Int x = TheDisplay->getWidth() - textWidth - pad - stripPixels( 4 );
- Int y = (m_hudOverlayBottom > 0) ? m_hudOverlayBottom + stripPixels( 1 ) : stripPixels( 2 );
+ Int y = stripPixels( 2 );
// a plate behind it, so it stays legible over bright terrain
TheDisplay->drawFillRect( x - pad, y - 1, textWidth + pad*2, textHeight + 2,
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
index f8e48bc70..5addbdb05 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/W3DInGameUI.cpp
@@ -476,7 +476,7 @@ void W3DInGameUI::draw( void )
// top of it - a dialog, the menu, the control bar's own art at the top of the screen - covered
// the one reading you want visible exactly when something is going wrong.
//
- // the peace time countdown first: it owns the top of the corner and the clock plate sits under it
+ // the peace time clock across the top middle, and the clock plate in the corner beside it
drawPeaceTimer();
drawHudOverlay();
diff --git a/GeneralsMD/Code/Tools/peacetime_layout.py b/GeneralsMD/Code/Tools/peacetime_layout.py
index b7924ee87..9b240cfb7 100644
--- a/GeneralsMD/Code/Tools/peacetime_layout.py
+++ b/GeneralsMD/Code/Tools/peacetime_layout.py
@@ -55,6 +55,7 @@ STRINGS = [
"GUI:PeaceTimeRemaining",
"GUI:PeaceTimeOver",
"GUI:PeaceTimeHud",
+ "GUI:PeaceTimeHudLabel",
"TOOLTIP:PeaceTime",
]