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): the page draws the power bar, so full fills its frame
Olcay Seyganb9144a79c11c
diff --git a/GeneralsMD/Code/Data/Window/Html/ControlBar.html b/GeneralsMD/Code/Data/Window/Html/ControlBar.htmlindex 3e7d26f86..d29ce4a0c 100644--- a/GeneralsMD/Code/Data/Window/Html/ControlBar.html+++ b/GeneralsMD/Code/Data/Window/Html/ControlBar.html@@ -16,6 +16,9 @@{{side}} "america", "china" or "gla": the side whose bar is on screen{{promotion}} "ready" while the general has a promotion to spend{{watching}} "watching" while the local player is an observer or out of the match+ {{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{{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@@ -84,6 +87,15 @@.groove { margin: -3px 0 0 -3px; border: 2px solid #7d8691; border-bottom-color: #c3ccd3; border-right-color: #aab4bf;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); }+ .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; }@@ -123,7 +135,11 @@<div class="alert {{WinUAttack.state}}">{{text:GUI:BarUnderAttack}}</div></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="lip"></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="needle" style="left: {{power.needle}}%"></div>+ <div class="lip"></div>+ </div><div class="piece panel solid stack centre {{centre.shown}}" style="left: {{centre.x}}px; top: {{centre.y}}px; width: {{centre.w}}px; height: {{centre.h}}px"><div class="rail"></div><div class="worker button {{ButtonIdleWorker.state}}" data-click="press:ButtonIdleWorker"><div class="cap">{{text:GUI:BarIdleWorker}}</div></div>diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 8c5511b66..e7cda8030 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -10102,9 +10102,52 @@ static const char *const CONTROL_BAR_WINDOWS[] =* clicks; only their pictures are the page's. */static const char *const CONTROL_BAR_CUSTOM[] ={- "ButtonGeneral", "ButtonLarge", "ButtonPlaceBeacon", "WinUAttack"+ "ButtonGeneral", "ButtonLarge", "ButtonPlaceBeacon", "WinUAttack", "PowerWindow"};+/** How far along its scale a power figure reaches, 0 to 1: the power bar's own logarithmic scale,+ * TheGlobalData's base and intervals, the one W3DPowerDraw measured with. */+static Real powerBarShare( Real power )+{+ if( power <= 1.0f || TheGlobalData->m_powerBarBase <= 1 || TheGlobalData->m_powerBarIntervals <= 0.0f )+ return 0.0f;+ const Real share = logf( power ) / logf( (Real)TheGlobalData->m_powerBarBase ) / TheGlobalData->m_powerBarIntervals;+ return share > 1.0f ? 1.0f : share;+}++//-------------------------------------------------------------------------------------------------+/** 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. */+//-------------------------------------------------------------------------------------------------+static void putPowerBar( HtmlValues &values )+{+ enum { ONE_UNIT_NEEDLE_TENTHS = 15 }; ///< a consumption of 1 is drawn as 1.5: log(1) is 0, and 1 is not nothing++ 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 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.needle" ] = std::to_string( REAL_TO_INT( powerBarShare( needle ) * PERCENT ) );+ if( consumption > production )+ values[ "power.state" ] = "red";+ else if( consumption > production - TheGlobalData->m_powerBarYellowRange )+ values[ "power.state" ] = "yellow";+ else+ values[ "power.state" ] = "green";+}+/** The bar's windows the page stands down altogether. The menu and idle worker buttons are the* page's own, pressed through data-click="press:Name" because they sit where the bar's frame takes* no clicks; the chat button is gone, and Enter still opens the chat. */@@ -10294,6 +10337,7 @@ 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 ] );