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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameclient): superweapon alert banner under the top plates
Olcay Seygan4fe9350f8e68
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 554d44231..24c00cf83 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -14,6 +14,8 @@ found and fixed — EA's own, not port damage.**- Your general's powers grow out of the console's right end, a column for each F key with its powers stacked up it, and only the powers you have take any room.- A single unit's name and health stand beside its portrait, and a veteran gets his gold stars there too. A group shows every type it holds in the same box, five to a row.- The match clock hangs from the middle of the top edge with your money in its own box under it. Superweapon countdowns in the top right corner are as big as your general's power buttons. Hold Tab and the scoreboard drops down from it.+- Peace time has its own plate under your money, so the truce clock never pushes the match clock aside. When the last ten seconds start, the countdown hangs straight off that plate.+- A superweapon built, charged or fired anywhere on the map flashes its name in big letters under the clock: "Nuclear Missile launched". Yours are white, an ally's blue, an enemy's red. Each line stays four seconds and fades out. When several land at once they queue and hurry through, two seconds each with one more waiting and one second with a pile behind it, so the last news never sits stale.- Your production queue stands on the console over your selection, five to a row, each row only as long as what is in it. The event feed runs down from the menu key in the top left corner, and the chat sits under it.- HUD Size grows the console from its middle, and on a narrow screen it stops at the size that still fits.diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.strindex fcb2a6f65..f48c14e71 100644--- a/GeneralsMD/Code/Data/Patch.str+++ b/GeneralsMD/Code/Data/Patch.str@@ -1367,6 +1367,19 @@ GUI:HudSuperweaponLaunched"launched"END+// the superweapon banner under the clock: %s is the superweapon's own name, "Nuclear Missile"+GUI:HudAlertBuilt+"%s built"+END++GUI:HudAlertReady+"%s ready"+END++GUI:HudAlertLaunched+"%s launched"+END+// after a general's power's name in the event feed, the moment it is usedGUI:HudPowerUsed"used"diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.strindex 54615da68..9a51ac2f7 100644--- a/GeneralsMD/Code/Data/Turkish/Generals.str+++ b/GeneralsMD/Code/Data/Turkish/Generals.str@@ -15861,6 +15861,18 @@ GUI:HudSuperweaponLaunched"ateşlendi"END+GUI:HudAlertBuilt+"%s tamamlandı"+END++GUI:HudAlertReady+"%s hazır"+END++GUI:HudAlertLaunched+"%s ateşlendi"+END+GUI:HudPowerUsed"kullanıldı"ENDdiff --git a/GeneralsMD/Code/Data/Window/Html/Alert.html b/GeneralsMD/Code/Data/Window/Html/Alert.htmlnew file mode 100644index 000000000..b38deb959--- /dev/null+++ b/GeneralsMD/Code/Data/Window/Html/Alert.html@@ -0,0 +1,46 @@+<!DOCTYPE html>+<!--+ The superweapon banner: words alone, no plate, hanging a little under the top page's plates in the+ middle of the screen while a superweapon is built, charged or fired. Whose it is is the colour,+ nothing else: the player's own neutral, an ally's blue, an enemy's red. The line is written five+ times, four black copies a pixel to each side under the coloured one, so the letters carry their+ own outline and read over snow as well as over a night sky. A page of its own, laid out once per+ banner; it fades through the page's alpha, which the game sets as it draws+ (InGameUI::drawAlertPage).++ The game fills in, in the page's pixels, laid out at ControlBarHudScale() as the bar's page is:+ {{left}} {{top}} the banner's corner: centred on the screen, under the top page's plates+ {{width}} its width; the words are centred in it+ {{whose}} "own", "ally" or "enemy"+ {{text}} "Nuclear Missile launched"++ Edit the copy under Run/Window/Html and the next match reads it.+-->+<html>+<head>+<meta charset="utf-8">+<title>Superweapon banner</title>+<style>+ html, body { margin: 0; padding: 0; }+ body { background-color: #3b4a36; font-size: 8px; color: #dfe5ea; }+ .piece { position: absolute; }++ #alert { height: 24px; }+ .text { position: absolute; left: 0; top: 0; height: 24px; line-height: 24px; font-size: 20px; font-weight: bold;+ text-align: center; white-space: nowrap; }+ .edge { color: #000000; }+ .own .face { color: #f1f4f6; }+ .ally .face { color: #9fd2ff; }+ .enemy .face { color: #ff3030; }+</style>+</head>+<body>+<div id="alert" class="piece {{whose}}" style="left: {{left}}px; top: {{top}}px; width: {{width}}px">+ <div class="text edge" style="width: {{width}}px; margin-left: -1px">{{text}}</div>+ <div class="text edge" style="width: {{width}}px; margin-left: 1px">{{text}}</div>+ <div class="text edge" style="width: {{width}}px; margin-top: -1px">{{text}}</div>+ <div class="text edge" style="width: {{width}}px; margin-top: 1px">{{text}}</div>+ <div class="text face" style="width: {{width}}px">{{text}}</div>+</div>+</body>+</html>diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 2a98f134c..28c660a44 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -1504,6 +1504,8 @@ protected:void drawQueueTray( void ); ///< the playing strip as a row in Window/Html/Queue.html's trayvoid drawNetPage( void ); ///< the network box, Window/Html/Net.html, with the command bar's pagevoid drawReadoutPage( const HtmlValues &values ); ///< the clock and the health, Window/Html/Readout.html, over the bar's page+ void alertSuperweapon( Player *owner, const UnicodeString &name, const char *label ); ///< queue a banner: `name` and what happened to it+ void drawAlertPage( void ); ///< the superweapon banner, Window/Html/Alert.html, under the top pagestd::string scoreboardHtml( void ); ///< Window/Html/Scoreboard.html filled in for this frameconst Image *productionStripTray( void ); ///< the bar's tray, mirrored, kept until the bar changes sidevoid stripTrayMetrics( ICoord2D *tray, ICoord2D *cameo, ICoord2D *hole, Int *step ); ///< that tray's size, its cameo hole, and the column step@@ -1553,6 +1555,14 @@ protected:HtmlOverlay * m_readoutOverlay; ///< Window/Html/Readout.html, the clock and the health over the bar's pageBool m_readoutPageLoaded;std::string m_readoutPage;+ /// one superweapon banner waiting or up: what happened, already lettered, and whose it is+ struct SuperweaponAlert { std::string text; std::string whose; };+ std::vector< SuperweaponAlert > m_alerts; ///< the banner up first, then the ones queued behind it+ UnsignedInt m_alertStartMs; ///< when the first one went up, on the client's clock+ HtmlOverlay * m_alertOverlay; ///< Window/Html/Alert.html, the banner under the top page+ Bool m_alertPageLoaded;+ std::string m_alertPage;+ Int m_alertBottom; ///< the banner's bottom on screen while it is up, else 0: the scoreboard hangs under itHtmlOverlay * m_tooltipOverlay;Bool m_tooltipPageLoaded;std::string m_tooltipPage;diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex ddcf1aa38..bba9bc1c4 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -1239,6 +1239,10 @@ InGameUI::InGameUI()m_netPageLoaded = FALSE;m_readoutOverlay = NULL;m_readoutPageLoaded = FALSE;+ m_alertStartMs = 0;+ m_alertOverlay = NULL;+ m_alertPageLoaded = FALSE;+ m_alertBottom = 0;m_promotionOverlay = NULL;m_promotionFrontOverlay = NULL;for( Int grid = 0; grid < CELL_GRID_COUNT; grid++ )@@ -1387,6 +1391,8 @@ InGameUI::~InGameUI()m_netOverlay = NULL;delete m_readoutOverlay;m_readoutOverlay = NULL;+ delete m_alertOverlay;+ m_alertOverlay = NULL;delete m_promotionOverlay;m_promotionOverlay = NULL;delete m_promotionFrontOverlay;@@ -4101,6 +4107,9 @@ void InGameUI::reset( void )m_controlBarPageLoaded = FALSE;m_netPageLoaded = FALSE;m_readoutPageLoaded = FALSE;+ m_alertPageLoaded = FALSE;+ m_alerts.clear();+ m_alertBottom = 0;m_tooltipPageLoaded = FALSE;m_promotionPageLoaded = FALSE;m_quitMenuPageLoaded = FALSE;@@ -4364,8 +4373,11 @@ void InGameUI::feedSpecialPower( const Object *source, const AsciiString &powerNif( info != NULL ){if( !info->m_hiddenByScript && !info->m_hiddenByScience )+ {feedAct( owner, cameo, WideCharStringToMultiByte( source->getTemplate()->getDisplayName().str() ),"launched", "GUI:HudSuperweaponLaunched" );+ alertSuperweapon( owner, source->getTemplate()->getDisplayName(), "GUI:HudAlertLaunched" );+ }return;}if( power->getRequiredScience() == SCIENCE_INVALID || button == NULL || !feedShows( owner ) )@@ -4389,6 +4401,92 @@ void InGameUI::feedStructure( Object *structure, Bool finished )feedAct( owner, structure->getTemplate()->getButtonImage(),WideCharStringToMultiByte( structure->getTemplate()->getDisplayName().str() ),finished ? "built" : "started", finished ? "GUI:HudStructureBuilt" : "GUI:HudStructureStarted" );+ if( finished && superweapon )+ alertSuperweapon( owner, structure->getTemplate()->getDisplayName(), "GUI:HudAlertBuilt" );+}++//-------------------------------------------------------------------------------------------------+/** A banner for a superweapon built, charged or fired, queued behind any already up: the same three+ * moments EVA calls out to every player, so it tells nobody anything EVA does not. Whose it is+ * is the colour alone, the owner's call: the local player's own neutral, an ally's blue, an enemy's+ * red. A watcher has no side and gets the neutral one. */+//-------------------------------------------------------------------------------------------------+void InGameUI::alertSuperweapon( Player *owner, const UnicodeString &name, const char *label )+{+ const Player *local = ThePlayerList->getLocalPlayer();+ SuperweaponAlert alert;+ UnicodeString text;+ text.format( TheGameText->fetch( label ), name.str() );+ alert.text = WideCharStringToMultiByte( text.str() );+ if( !local->isPlayerActive() || owner == local )+ alert.whose = "own";+ else+ alert.whose = local->getRelationship( owner->getDefaultTeam() ) == ENEMIES ? "enemy" : "ally";+ if( m_alerts.empty() )+ m_alertStartMs = timeGetTime();+ m_alerts.push_back( alert );+}++//-------------------------------------------------------------------------------------------------+/** The banner up now, under the top page and centred on the console, fading out at the end of its+ * time. How long it holds is the owner's rule and goes by what waits behind it: alone, four+ * seconds; with one more, two; with two or more, one. It is asked again every frame, so a banner+ * arriving while one is up can cut the one up short and never draws it out. Timed on the client's+ * wall clock, as the money plate's settle and the superweapon strip's breath are: a picture, not a+ * thing the match counts. Its page is laid out once per banner: the fade is the page's alpha,+ * applied as it draws. */+//-------------------------------------------------------------------------------------------------+static const UnsignedInt ALERT_FADE_MS = 600;+static const char *const ALERT_PAGE = "Window\\Html\\Alert.html";++static UnsignedInt alertHoldMs( size_t waiting )+{+ static const UnsignedInt HOLD_ALONE_MS = 4000, HOLD_ONE_WAITING_MS = 2000, HOLD_MORE_WAITING_MS = 1000;+ return waiting == 0 ? HOLD_ALONE_MS : waiting == 1 ? HOLD_ONE_WAITING_MS : HOLD_MORE_WAITING_MS;+}++void InGameUI::drawAlertPage( void )+{+ enum { ALERT_GAP = 14, ALERT_WIDTH = 360, ALERT_OPAQUE = 255 }; // the gap clear of the plates, the owner's "a bit lower"+ m_alertBottom = 0;+ const UnsignedInt nowMs = timeGetTime();+ while( !m_alerts.empty() && nowMs - m_alertStartMs >= alertHoldMs( m_alerts.size() - 1 ) )+ {+ m_alerts.erase( m_alerts.begin() );+ m_alertStartMs = nowMs;+ }+ if( m_alerts.empty() )+ return;++ if( !m_alertPageLoaded )+ {+ m_alertPageLoaded = TRUE;+ readHtmlPage( ALERT_PAGE, m_alertPage );+ }+ if( m_alertPage.empty() )+ return;+ if( m_alertOverlay == NULL )+ {+ m_alertOverlay = new HtmlOverlay( m_superweaponNormalFont );+ m_alertOverlay->setHud( TRUE );+ }++ const Real scale = ControlBarHudScale();+ const SuperweaponAlert &alert = m_alerts.front();+ HtmlValues values;+ // the console stands with the powers' widest kept free on its right, so its axis with them is the+ // screen's middle, the line the top page's plates hang on too+ values[ "left" ] = std::to_string( REAL_TO_INT_FLOOR( TheDisplay->getWidth() / 2 / scale + 0.5f ) - ALERT_WIDTH / 2 );+ values[ "width" ] = std::to_string( ALERT_WIDTH );+ values[ "top" ] = std::to_string( REAL_TO_INT_FLOOR( m_topBarBottom / scale + 0.5f ) + ALERT_GAP );+ values[ "whose" ] = alert.whose;+ values[ "text" ] = alert.text;+ m_alertOverlay->setPage( HtmlTemplate_expand( m_alertPage, values, HtmlLists(), lookupGameText ) );++ const UnsignedInt left = alertHoldMs( m_alerts.size() - 1 ) - ( nowMs - m_alertStartMs );+ m_alertOverlay->setAlpha( left < ALERT_FADE_MS ? (Int)( ALERT_OPAQUE * left / ALERT_FADE_MS ) : ALERT_OPAQUE );+ m_alertOverlay->draw();+ m_alertBottom = m_alertOverlay->bottomOf( "#alert" );}//-------------------------------------------------------------------------------------------------@@ -7951,6 +8049,8 @@ void InGameUI::postDraw( void )feedAct( owningObject->getControllingPlayer(), superweaponCameo( info->getSpecialPowerTemplate() ),WideCharStringToMultiByte( owningObject->getTemplate()->getDisplayName().str() ),"ready", "GUI:HudSuperweaponReady" );+ alertSuperweapon( owningObject->getControllingPlayer(), owningObject->getTemplate()->getDisplayName(),+ "GUI:HudAlertReady" );SpecialPowerType type = module->getSpecialPowerTemplate()->getSpecialPowerType();@@ -11013,7 +11113,8 @@ std::string InGameUI::scoreboardHtml( void )values[ "side" ] = spectatorSide();values[ "clock" ] = spectatorClock( TheGameLogic->getFrame() );values[ "boardx" ] = std::to_string( REAL_TO_INT_FLOOR( TheDisplay->getWidth() / scale - BOARD_WIDTH ) / 2 );- values[ "boardy" ] = std::to_string( REAL_TO_INT_FLOOR( ( m_controlBarPageShown ? m_topBarBottom : 0 ) / scale ) );+ // under the top page, and under the superweapon banner while one is up+ values[ "boardy" ] = std::to_string( REAL_TO_INT_FLOOR( ( m_controlBarPageShown ? max( m_topBarBottom, m_alertBottom ) : 0 ) / scale ) );return HtmlTemplate_expand( m_scoreboardPage, values, lists, lookupGameText );}@@ -12306,6 +12407,7 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, Im_controlBarPageHovered = m_controlBarOverlay->hover( TheMouse->getMouseStatus()->pos );m_controlBarOverlay->draw();drawReadoutPage( values );+ drawAlertPage();drawNetPage();m_controlBarSolids.clear();