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): a segmented power bar, forty cells lit to the production
Olcay Seygan9966c6899937
diff --git a/GeneralsMD/Code/Data/Window/Html/ControlBar.html b/GeneralsMD/Code/Data/Window/Html/ControlBar.htmlindex d29ce4a0c..7cc4f3965 100644--- a/GeneralsMD/Code/Data/Window/Html/ControlBar.html+++ b/GeneralsMD/Code/Data/Window/Html/ControlBar.html@@ -19,6 +19,8 @@{{power.fill}} the power bar: production as a percent of the bar, on the bar's own{{power.needle}} logarithmic scale, consumption as the same, and {{power.state}} "green","yellow" or "red"; the watched player's while watching+ data-each="powercells" the same production as 40 cells, each {{lit}} "lit" up to it, standing at+ {{x}} pixels inside the frame's lip and {{w}} wide{{blink}} "lit" for half of every second, for anything that blinks{{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@@ -26,7 +28,8 @@{{left.x}} .y .w .h the box round the radar, so the left panel is only as big as its bezel{{centre.x}} .y .w .h the centre as three blocks stacked flush, with their steel round them{{powerframe.x}} ... already: the command grid's panel, the power bar's frame standing on it,- {{moneyblock.x}} ... and the money's block on the frame; each .shown as above+ {{moneyblock.x}} ... and the money's block on the frame; each .shown as above, and+ {{powerframe.inner}} the height inside the frame and its lip{{right.x}} .y .w .h the box round the portrait and the experience bar. The promotion andminimise buttons are moved to sit over its top right corner{{Name.x}} .y .w .h the rectangle of the bar's window Name, {{Name.shown}} "shown" or "hidden"@@ -88,13 +91,20 @@background-color: #020405; }.groove .lip { position: absolute; left: 0; top: 0; right: 0; bottom: 0; border: 1px solid #000000; }- /* the power bar is the page's: the production fills the frame from the left, in the power bar's- own green, yellow or red, and the consumption is a white needle across it. Full is the whole- frame, lip to lip */- .powerfill { position: absolute; left: 0; top: 0; bottom: 0; background-image: url(PowerBarGreen);- background-size: 100% 100%; background-repeat: no-repeat; }- .powerfill.yellow { background-image: url(PowerBarYellow); }- .powerfill.red { background-image: url(PowerBarRed); }+ /* the power bar is the page's: a row of cells across the frame, lit from the left up to the+ production in the power bar's own green, yellow or red, a black line between every two, and the+ consumption a white needle across them. Full is every cell, lip to lip */+ /* the row's height is the frame's inside, {{powerframe.inner}}, written in: a percentage of a+ height set by top and bottom does not resolve here, and the cells came out with none */+ .cells { position: absolute; left: 1px; top: 1px; right: 1px; }+ /* each cell stands at its own {{x}} and {{w}} in pixels, and the gap is the inner block's margin:+ floated at a percentage the fortieth cell fell onto a second row, and a percentage of an+ absolutely placed box does not resolve here at all */+ .cells .cell { position: absolute; top: 0; }+ .cells .seg { margin-right: 1px; background-color: #0d1512; background-size: 100% 100%; background-repeat: no-repeat; }+ .cells .lit .seg { background-image: url(PowerBarGreen); }+ .cells.yellow .lit .seg { background-image: url(PowerBarYellow); }+ .cells.red .lit .seg { background-image: url(PowerBarRed); }.needle { position: absolute; top: 0; bottom: 0; width: 2px; margin-left: -1px; background-color: #ffffff; }.china .groove { border-color: #a44734; border-bottom-color: #e8a28a; border-right-color: #d98a72; }.gla .groove { border-color: #978a50; border-bottom-color: #ddd29a; border-right-color: #cbbf82; }@@ -136,7 +146,7 @@</div><div class="piece panel solid stack moneyblock {{moneyblock.shown}}" style="left: {{moneyblock.x}}px; top: {{moneyblock.y}}px; width: {{moneyblock.w}}px; height: {{moneyblock.h}}px"><div class="rail"></div></div><div class="piece groove solid stack {{powerframe.shown}}" style="left: {{powerframe.x}}px; top: {{powerframe.y}}px; width: {{powerframe.w}}px; height: {{powerframe.h}}px">- <div class="powerfill {{power.state}}" style="width: {{power.fill}}%"></div>+ <div class="cells {{power.state}}" style="height: {{powerframe.inner}}px"><div class="cell {{lit}}" data-each="powercells" style="left: {{x}}px; width: {{w}}px; height: {{powerframe.inner}}px"><div class="seg" style="height: {{powerframe.inner}}px"></div></div></div><div class="needle" style="left: {{power.needle}}%"></div><div class="lip"></div></div>diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex e7cda8030..a9cb6b944 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -10119,27 +10119,43 @@ static Real powerBarShare( Real power )/** The power bar as the page draws it, filling its frame: {{power.fill}} the production and* {{power.needle}} the consumption, both percent of the frame, and {{power.state}} "green",* "yellow" or "red" by the bar's own rule - red once consumption passes production, yellow within- * m_powerBarYellowRange of it. Watching, it is the watched player's power. */+ * m_powerBarYellowRange of it. Watching, it is the watched player's power. `cells` is the same+ * production as a row of POWER_CELLS cells, each {{lit}} "lit" up to it, for a segmented bar. *///--------------------------------------------------------------------------------------------------static void putPowerBar( HtmlValues &values )+static void putPowerBar( HtmlValues &values, std::vector< HtmlValues > &cells ){- enum { ONE_UNIT_NEEDLE_TENTHS = 15 }; ///< a consumption of 1 is drawn as 1.5: log(1) is 0, and 1 is not nothing+ enum+ {+ ONE_UNIT_NEEDLE_TENTHS = 15, ///< a consumption of 1 is drawn as 1.5: log(1) is 0, and 1 is not nothing+ POWER_CELLS = 40 ///< the bar is drawn as this many cells, lit up to the production+ };Player *player = TheControlBar->isObserverControlBarOn() ? TheControlBar->getObserverLookAtPlayer(): ThePlayerList->getLocalPlayer();const Energy *energy = player ? player->getEnergy() : NULL;- if( energy == NULL )- {- values[ "power.fill" ] = "0";- values[ "power.needle" ] = "0";- return;- }-- const Int production = energy->getProduction();- const Int consumption = energy->getConsumption();+ const Int production = energy ? energy->getProduction() : 0;+ const Int consumption = energy ? energy->getConsumption() : 0;+ const Real fill = powerBarShare( (Real)production );const Real needle = consumption == 1 ? ONE_UNIT_NEEDLE_TENTHS / 10.0f : (Real)consumption;- values[ "power.fill" ] = std::to_string( REAL_TO_INT( powerBarShare( (Real)production ) * PERCENT ) );+ values[ "power.fill" ] = std::to_string( REAL_TO_INT( fill * PERCENT ) );values[ "power.needle" ] = std::to_string( REAL_TO_INT( powerBarShare( needle ) * PERCENT ) );++ // each cell gets its place and width in the page's pixels, cut from the frame's inside so they+ // add up to it exactly: floated at a percentage each the page rounded them up and the fortieth+ // fell onto a second row, and a percentage of an absolutely placed box does not resolve at all+ enum { FRAME_LIP = 1 };+ const Int row = atoi( values[ "powerframe.w" ].c_str() ) - 2 * FRAME_LIP;+ cells.clear();+ const Int lit = REAL_TO_INT( fill * POWER_CELLS );+ for( Int cell = 0; cell < POWER_CELLS && row > 0; cell++ )+ {+ const Int left = cell * row / POWER_CELLS;+ HtmlValues entry;+ entry[ "lit" ] = cell < lit ? "lit" : "";+ entry[ "x" ] = std::to_string( left );+ entry[ "w" ] = std::to_string( ( cell + 1 ) * row / POWER_CELLS - left );+ cells.push_back( entry );+ }if( consumption > production )values[ "power.state" ] = "red";else if( consumption > production - TheGlobalData->m_powerBarYellowRange )@@ -10288,6 +10304,16 @@ static void stackCentre( HtmlValues &values, Bool shown )putPageRect( values, "centre", centre, gridFound && shown );putPageRect( values, "powerframe", frame, powerFound && shown );++ // the page lays boxes out content-box whatever box-sizing says, so the frame's border goes on top+ // of its width and height: hand it the content, and the height inside its lip for the cells, since+ // a percentage of a height set by top and bottom does not resolve in the page either+ enum { FRAME_BORDER = 2, FRAME_LIP = 1 };+ const Int width = atoi( values[ "powerframe.w" ].c_str() ) - 2 * FRAME_BORDER;+ const Int height = atoi( values[ "powerframe.h" ].c_str() ) - 2 * FRAME_BORDER;+ values[ "powerframe.w" ] = std::to_string( width > 0 ? width : 0 );+ values[ "powerframe.h" ] = std::to_string( height > 0 ? height : 0 );+ values[ "powerframe.inner" ] = std::to_string( height > 2 * FRAME_LIP ? height - 2 * FRAME_LIP : 0 );putPageRect( values, "moneyblock", block, moneyFound && shown );}@@ -10337,7 +10363,6 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, Iconst Bool watching = localPlayerWatching();values[ "promotion" ] = !watching && TheControlBar->isGeneralStarFlashing() ? "ready" : "";values[ "watching" ] = watching ? "watching" : "";- putPowerBar( values );values[ "blink" ] = TheGameLogic->getFrame() % LOGICFRAMES_PER_SECOND > LOGICFRAMES_PER_SECOND / 2 ? "lit" : "";for( Int panel = 0; panel < panelCount; panel++ )putPageRect( values, "panel" + std::to_string( panel ), panels[ panel ], shown[ panel ] );@@ -10347,6 +10372,8 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, Iconst Bool leftFound = controlBarUnion( CONTROL_BAR_LEFT, box );putPageRect( values, "left", box, leftFound && panelCount > 0 && shown[ 0 ] );stackCentre( values, panelCount > 1 && shown[ 1 ] );+ HtmlLists lists;+ putPowerBar( values, lists[ "powercells" ] ); // after the stack, whose frame it divides into cellsconst Bool rightFound = controlBarUnion( CONTROL_BAR_RIGHT, box );putPageRect( values, "right", box, rightFound && panelCount > 2 && shown[ 2 ] );@@ -10396,7 +10423,7 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, Iwindow->winHide( TRUE );}- m_controlBarOverlay->setPage( HtmlTemplate_expand( m_controlBarPage, values, HtmlLists(), lookupGameText ) );+ m_controlBarOverlay->setPage( HtmlTemplate_expand( m_controlBarPage, values, lists, lookupGameText ) );m_controlBarOverlay->hover( TheMouse->getMouseStatus()->pos );m_controlBarOverlay->draw();