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(w3ddevice): draw the command bar's frame from a CSS page
Olcay Seygan75d867394273
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 15931e109..ba23fb10a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -486,6 +486,7 @@ found and fixed — EA's own, not port damage.**- When a superweapon comes ready, the left side says so for eight seconds: whose it is, its picture and its name, "ready to fire". The newest is at the bottom, four at most.- Both are an ordinary web page with a stylesheet, in the game's Window folder. Change the colours, the sizes or the order there and the next match you watch draws it that way, and the page opens in a browser too.- A minimised command bar stays minimised. Changing seats, or clicking another player's unit while watching, put the whole bar back up over the battlefield you had just cleared. A new match still opens with the bar up.+- The command bar's frame is drawn new, in the same steel as the boards: three dark panels under a steel rail, the radar and the portrait each set in a bezel with a rivet at every corner, the command buttons in a shallow well, the money on a plaque and the power bar in a groove. Grey for America, red for China, sand for GLA. It slides and minimises with the bar, and like the boards it is a page in the Window folder; take the page away and the old painted bar comes back.## Placing buildingsdiff --git a/GeneralsMD/Code/Data/Window/Html/ControlBar.html b/GeneralsMD/Code/Data/Window/Html/ControlBar.htmlnew file mode 100644index 000000000..979f84ada--- /dev/null+++ b/GeneralsMD/Code/Data/Window/Html/ControlBar.html@@ -0,0 +1,93 @@+<!DOCTYPE html>+<!--+ The command bar's frame, drawn where its three plates used to be. The buttons, the radar, the+ money, the power bar and the portrait are still the bar's own windows and paint over this page;+ the page draws the steel round and under them. Same materials as Window/Html/Spectator.html,+ whose header says what the renderer draws and what it does not.++ The game fills in, every frame (GameClient/HtmlTemplate.h):+ {{side}} "america", "china" or "gla": the side whose bar is on screen+ {{panelN.x}} .y .w .h N 0 to 2, left, centre and right: where the plates would have gone,+ moving with the bar when it slides or minimises; .w and .h are 0 and+ {{panelN.shown}} is "hidden" when a minimised bar has stood it down+ {{Name.x}} .y .w .h the rectangle of the bar's window Name, and {{Name.shown}} "shown" or+ "hidden", for LeftHUD (the radar), RightHUD (the portrait's box),+ CameoWindow (the portrait), CommandWindow, MoneyDisplay, PowerWindow,+ GeneralsExp, ButtonGeneral, ButtonLarge, ButtonOptions, ButtonIdleWorker,+ ButtonPlaceBeacon, PopupCommunicator and WinUAttack+ All in the page's pixels, a pixel of an 800x600 screen. Without this page the plates draw.++ Edit the copy under Run/Window/Html and the next match reads it.+-->+<html>+<head>+<meta charset="utf-8">+<title>Command bar</title>+<style>+ html, body { margin: 0; padding: 0; }+ body { background-color: #3b4a36; }+ .hidden { display: none; }+ .piece { position: absolute; }++ /* a panel: a dark body under a steel rail, lit along the top and left like the other pages */+ .panel { background-color: rgba(10, 16, 20, 0.94); border-top: 1px solid #aab4bf; border-left: 1px solid #8a949f;+ border-right: 1px solid #1a2026; }+ .rail { position: absolute; left: 0; right: 0; top: 0; height: 7px;+ background: linear-gradient(to bottom, #7d8691, #3f4650); border-bottom: 1px solid #0c1114; }+ .china .panel { background-color: rgba(24, 9, 7, 0.94); border-top-color: #d98a72; border-left-color: #b8604b; }+ .china .rail { background: linear-gradient(to bottom, #9a4331, #4c1b13); }+ .gla .panel { background-color: rgba(21, 18, 8, 0.94); border-top-color: #cbbf82; border-left-color: #a99d62; }+ .gla .rail { background: linear-gradient(to bottom, #8f8249, #48401e); }++ /* a bezel: a window set into the panel, four pixels of steel round a black lip */+ .bezel { margin: -5px 0 0 -5px; border: 4px solid #4b535e; border-top-color: #2a3036; border-left-color: #2a3036;+ border-bottom-color: #8a949f; border-right-color: #6f7782; }+ .bezel .lip { position: absolute; left: 0; top: 0; right: 0; bottom: 0; border: 1px solid #000000; }+ .china .bezel { border-color: #6a2a1e; border-top-color: #34120c; border-left-color: #34120c; border-bottom-color: #b8604b; border-right-color: #8e3b2b; }+ .gla .bezel { border-color: #625a31; border-top-color: #302b15; border-left-color: #302b15; border-bottom-color: #a99d62; border-right-color: #867a45; }+ .rivet { position: absolute; width: 3px; height: 3px; background-color: #aab4bf; border-bottom: 1px solid #0c1114; }++ /* the command grid sits in a shallow well */+ .well { margin: -3px 0 0 -3px; border: 2px solid #0c1114; border-bottom-color: #4b535e; border-right-color: #4b535e;+ background-color: rgba(0, 0, 0, 0.35); }++ /* the money's plaque and the power bar's groove */+ .plaque { margin: -2px 0 0 -8px; padding: 0 6px; border: 1px solid #0c1114; border-top-color: #000000; border-bottom-color: #6f7782;+ background-color: #05080a; }+ .groove { margin: -2px 0 0 -2px; border: 1px solid #000000; border-bottom-color: #6f7782; background-color: #020405; }+</style>+</head>+<body>+<div class="{{side}}">++ <!-- the three plates -->+ <div class="piece panel {{panel0.shown}}" style="left: {{panel0.x}}px; top: {{panel0.y}}px; width: {{panel0.w}}px; height: {{panel0.h}}px"><div class="rail"></div></div>+ <div class="piece panel {{panel1.shown}}" style="left: {{panel1.x}}px; top: {{panel1.y}}px; width: {{panel1.w}}px; height: {{panel1.h}}px"><div class="rail"></div></div>+ <div class="piece panel {{panel2.shown}}" style="left: {{panel2.x}}px; top: {{panel2.y}}px; width: {{panel2.w}}px; height: {{panel2.h}}px"><div class="rail"></div></div>++ <!-- the radar, set in a bezel with a rivet at each corner -->+ <div class="piece bezel {{LeftHUD.shown}}" style="left: {{LeftHUD.x}}px; top: {{LeftHUD.y}}px; width: {{LeftHUD.w}}px; height: {{LeftHUD.h}}px">+ <div class="lip"></div>+ <div class="rivet" style="left: -4px; top: -4px"></div>+ <div class="rivet" style="right: -4px; top: -4px"></div>+ <div class="rivet" style="left: -4px; bottom: -4px"></div>+ <div class="rivet" style="right: -4px; bottom: -4px"></div>+ </div>++ <!-- the portrait's box, the same bezel -->+ <div class="piece bezel {{RightHUD.shown}}" style="left: {{RightHUD.x}}px; top: {{RightHUD.y}}px; width: {{RightHUD.w}}px; height: {{RightHUD.h}}px">+ <div class="lip"></div>+ <div class="rivet" style="left: -4px; top: -4px"></div>+ <div class="rivet" style="right: -4px; top: -4px"></div>+ <div class="rivet" style="left: -4px; bottom: -4px"></div>+ <div class="rivet" style="right: -4px; bottom: -4px"></div>+ </div>++ <div class="piece well {{CommandWindow.shown}}" style="left: {{CommandWindow.x}}px; top: {{CommandWindow.y}}px; width: {{CommandWindow.w}}px; height: {{CommandWindow.h}}px"></div>+ <div class="piece plaque {{MoneyDisplay.shown}}" style="left: {{MoneyDisplay.x}}px; top: {{MoneyDisplay.y}}px; width: {{MoneyDisplay.w}}px; height: {{MoneyDisplay.h}}px"></div>+ <div class="piece groove {{PowerWindow.shown}}" style="left: {{PowerWindow.x}}px; top: {{PowerWindow.y}}px; width: {{PowerWindow.w}}px; height: {{PowerWindow.h}}px"></div>+ <div class="piece groove {{GeneralsExp.shown}}" style="left: {{GeneralsExp.x}}px; top: {{GeneralsExp.y}}px; width: {{GeneralsExp.w}}px; height: {{GeneralsExp.h}}px"></div>++</div>+</body>+</html>diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.hindex 7d65bb398..f84505213 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h@@ -401,6 +401,9 @@ public: // ********************************************************************virtual void toggleMessages( void ) { m_messagesOn = 1 - m_messagesOn; } ///< toggle messages on/offvoid toggleScoreboard( void ) { m_scoreboardOpen = !m_scoreboardOpen; } ///< the Tab scoreboard, on or offBool pickSpectatorStat( Int commandSlot ); ///< a command bar key while watching: TRUE when it picked a stat+ /** The command bar's page, Window/Html/ControlBar.html, under the bar's windows: its panels are+ * where the plates would have gone, in screen pixels. FALSE when there is no page to draw. */+ Bool drawControlBarPage( const IRegion2D *panels, const Bool *shown, Int panelCount );void drawScoreboard( void ); ///< that scoreboard, over everythingvirtual Bool isMessagesOn( void ) { return m_messagesOn; } ///< are the display messages onvoid freeMessageResources( void ); ///< free resources for the ui messages@@ -1199,6 +1202,9 @@ protected:HtmlOverlay * m_scoreboardOverlay;Bool m_scoreboardPageLoaded; ///< read once a match, like the spectator's pagestd::string m_scoreboardPage;+ HtmlOverlay * m_controlBarOverlay;+ Bool m_controlBarPageLoaded;+ std::string m_controlBarPage;//// The spectator's page over the battlefield, Window/Html/Spectator.html: the drop-down thatdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 49378ac0e..16a00c4ee 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -1200,6 +1200,8 @@ InGameUI::InGameUI()m_scoreboardOpen = FALSE;m_scoreboardOverlay = NULL;m_scoreboardPageLoaded = FALSE;+ m_controlBarOverlay = NULL;+ m_controlBarPageLoaded = FALSE;for( Int stripSeconds = 0; stripSeconds < STRIP_SECONDS_STRINGS; stripSeconds++ )m_stripSecondsString[ stripSeconds ] = NULL;for( Int stripQuantity = 0; stripQuantity < STRIP_QUANTITY_STRINGS; stripQuantity++ )@@ -1319,6 +1321,8 @@ InGameUI::~InGameUI()m_spectatorOverlay = NULL;delete m_scoreboardOverlay;m_scoreboardOverlay = NULL;+ delete m_controlBarOverlay;+ m_controlBarOverlay = NULL;}//-------------------------------------------------------------------------------------------------@@ -3865,6 +3869,7 @@ void InGameUI::reset( void )m_isQuitMenuVisible = FALSE;m_scoreboardOpen = FALSE;m_scoreboardPageLoaded = FALSE;+ m_controlBarPageLoaded = FALSE;m_spectatorPageLoaded = FALSE;m_spectatorFlipped.clear();m_spectatorPicked.clear();@@ -10077,6 +10082,76 @@ void InGameUI::drawScoreboard( void )m_scoreboardOverlay->draw();}+static const char *const CONTROL_BAR_PAGE = "Window\\Html\\ControlBar.html";++/** The command bar's windows the page is told the place of, by their name in ControlBar.wnd. */+static const char *const CONTROL_BAR_WINDOWS[] =+{+ "LeftHUD", "RightHUD", "CameoWindow", "CommandWindow", "MoneyDisplay", "PowerWindow", "GeneralsExp",+ "ButtonGeneral", "ButtonLarge", "ButtonOptions", "ButtonIdleWorker", "ButtonPlaceBeacon", "PopupCommunicator",+ "WinUAttack"+};++/** `name`.x, .y, .w and .h in the page's pixels, and `name`.shown "shown" or "hidden". */+static void putPageRect( HtmlValues &values, const std::string &name, const IRegion2D &rect, Bool shown )+{+ const Real scale = ControlBarUniformScale();+ values[ name + ".x" ] = std::to_string( REAL_TO_INT( rect.lo.x / scale ) );+ values[ name + ".y" ] = std::to_string( REAL_TO_INT( rect.lo.y / scale ) );+ values[ name + ".w" ] = std::to_string( shown ? REAL_TO_INT( ( rect.hi.x - rect.lo.x ) / scale ) : 0 );+ values[ name + ".h" ] = std::to_string( shown ? REAL_TO_INT( ( rect.hi.y - rect.lo.y ) / scale ) : 0 );+ values[ name + ".shown" ] = shown ? "shown" : "hidden";+}++//-------------------------------------------------------------------------------------------------+/** The command bar's frame, drawn from Window/Html/ControlBar.html in the place of its three plates.+ * The buttons, the radar and the portrait are still the bar's own windows and paint over it; the+ * page only draws what sits round and under them, so it is told where they are: panel0 to panel2+ * are the plates' rectangles, sliding and minimising with the bar, and every name in+ * CONTROL_BAR_WINDOWS is its window's rectangle. All of them in the page's 800x600 pixels. */+//-------------------------------------------------------------------------------------------------+Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, Int panelCount )+{+ if( TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )+ return FALSE;++ if( !m_controlBarPageLoaded )+ {+ m_controlBarPageLoaded = TRUE;+ readHtmlPage( CONTROL_BAR_PAGE, m_controlBarPage );+ }+ if( m_controlBarPage.empty() )+ return FALSE;+ if( m_controlBarOverlay == NULL )+ m_controlBarOverlay = new HtmlOverlay( m_superweaponNormalFont );++ HtmlValues values;+ values[ "side" ] = spectatorSide();+ for( Int panel = 0; panel < panelCount; panel++ )+ putPageRect( values, "panel" + std::to_string( panel ), panels[ panel ], shown[ panel ] );++ for( Int each = 0; each < (Int)ARRAY_SIZE( CONTROL_BAR_WINDOWS ); each++ )+ {+ const std::string name = CONTROL_BAR_WINDOWS[ each ];+ GameWindow *window = TheWindowManager->winGetWindowFromId( NULL, NAMEKEY( ( "ControlBar.wnd:" + name ).c_str() ) );+ IRegion2D rect;+ rect.lo.x = rect.lo.y = rect.hi.x = rect.hi.y = 0;+ if( window )+ {+ Int width = 0, height = 0;+ window->winGetScreenPosition( &rect.lo.x, &rect.lo.y );+ window->winGetSize( &width, &height );+ rect.hi.x = rect.lo.x + width;+ rect.hi.y = rect.lo.y + height;+ }+ putPageRect( values, name, rect, window != NULL && !window->winIsHidden() );+ }++ m_controlBarOverlay->setPage( HtmlTemplate_expand( m_controlBarPage, values, HtmlLists(), lookupGameText ) );+ m_controlBarOverlay->draw();+ return TRUE;+}+//-------------------------------------------------------------------------------------------------/** Lay out and draw one run of cells, its left edge at left and the first cameo's top edge at* bottomY.diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cppindex 8f1f15fe5..9795d99a9 100644--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp@@ -717,8 +717,15 @@ void W3DCommandBarBackgroundDraw( GameWindow *window, WinInstanceData *instDataoffset.y = now.y - TheControlBar->getPanelOrigin()->y;}+ IRegion2D panels[ ControlBar::CB_PANEL_COUNT ];+ Bool shown[ ControlBar::CB_PANEL_COUNT ];+ const Image *images[ ControlBar::CB_PANEL_COUNT ];for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ ){+ shown[ p ] = FALSE;+ images[ p ] = NULL;+ panels[ p ].lo.x = panels[ p ].lo.y = panels[ p ].hi.x = panels[ p ].hi.y = 0;+// a panel the minimised bar has stood down paints nothing at allif( TheControlBar->isPanelHidden( p ) )continue;@@ -736,12 +743,21 @@ void W3DCommandBarBackgroundDraw( GameWindow *window, WinInstanceData *instData// ... and a panel on its way off the bottom takes its painting down with itconst Int slide = TheControlBar->getPanelSlideOffset( p );-- const Image *image = plateImage( plate );- if( image )- TheDisplay->drawImage( image, rect.lo.x + offset.x, rect.lo.y + offset.y + slide,- rect.hi.x + offset.x, rect.hi.y + offset.y + slide );+ panels[ p ].lo.x = rect.lo.x + offset.x;+ panels[ p ].lo.y = rect.lo.y + offset.y + slide;+ panels[ p ].hi.x = rect.hi.x + offset.x;+ panels[ p ].hi.y = rect.hi.y + offset.y + slide;+ shown[ p ] = TRUE;+ images[ p ] = plateImage( plate );}++ // the bar's own page, Window/Html/ControlBar.html, is drawn in the plates' place when it is there+ if( TheInGameUI && TheInGameUI->drawControlBarPage( panels, shown, ControlBar::CB_PANEL_COUNT ) )+ return;++ for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ )+ if( shown[ p ] && images[ p ] )+ TheDisplay->drawImage( images[ p ], panels[ p ].lo.x, panels[ p ].lo.y, panels[ p ].hi.x, panels[ p ].hi.y );}