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.

refactor(gameclient): put EA's control bar art and layout back

Olcay Seygande2e183170c4
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index ac4bd9f11..fa52d612e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -818,24 +818,7 @@ public:
Bool hasAnyShortcutSelection() const;
- //
- // The bar is laid out as three independently anchored panels instead of one stretched strip.
- // layoutPanels() re-places every window in ControlBar.wnd at a single uniform scale and
- // records where the three plates landed; the plates themselves are drawn from getPanelRect().
- //
- enum ControlBarPanel
- {
- CB_PANEL_LEFT = 0, ///< radar, hard against the left edge
- CB_PANEL_CENTER, ///< money, power and the command grid, centred
- CB_PANEL_RIGHT, ///< selection portrait and upgrades, hard against the right edge
-
- CB_PANEL_COUNT
- };
- const IRegion2D *getPanelRect( Int which ) const { return &m_panelRect[ which ]; }
-
protected:
- void layoutPanels( void ); ///< re-anchor the three panels at one uniform scale
-
void updateRadarAttackGlow ( void );
void setDefaultControlBarConfig( void );
@@ -943,8 +926,6 @@ protected:
ICoord2D m_defaultControlBarPosition; ///< Stored the original position of the control bar on the screen
ControlBarStages m_currentControlBarStage;
- IRegion2D m_panelRect[ CB_PANEL_COUNT ]; ///< screen rect of each panel, filled by layoutPanels()
-
Bool m_UIDirty; ///< the context UI must be re-evaluated
CommandButton *m_commandButtons; ///< list of possible commands to have
@@ -1121,13 +1102,5 @@ private:
// EXTERNALS //////////////////////////////////////////////////////////////////////////////////////
extern ControlBar *TheControlBar;
-//
-// The geometry half of ControlBar::layoutPanels, with none of the GameWindow walking: given a
-// screen size it works out the uniform scale the bar is drawn at and where the three panels land.
-// Exposed so it can be checked at resolutions this machine cannot display.
-// outPanel must have room for ControlBar::CB_PANEL_COUNT rectangles.
-//
-void ControlBarComputePanelLayout( Int dispW, Int dispH, IRegion2D *outPanel, Real *outScale );
-
#endif // end __CONTROLBAR_H_
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 91d0e3869..2e01d7622 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -1044,9 +1044,6 @@ ControlBar::ControlBar( void )
m_commandBarBorderColor = GameMakeColor(0,0,0,100);
for( i = 0; i < NUM_CONTEXT_PARENTS; i++ )
m_contextParent[ i ] = NULL;
- // an empty panel is a panel with no plate, which is what the builder tool wants
- for( i = 0; i < CB_PANEL_COUNT; i++ )
- m_panelRect[ i ].lo.x = m_panelRect[ i ].lo.y = m_panelRect[ i ].hi.x = m_panelRect[ i ].hi.y = 0;
for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
{
m_commandWindows[ i ] = NULL;
@@ -1206,244 +1203,6 @@ ControlBar::~ControlBar( void )
} // end ~ControlBar
void ControlBarPopupDescriptionUpdateFunc( WindowLayout *layout, void *param );
-//-------------------------------------------------------------------------------------------------
-// Three-panel control bar layout -----------------------------------------------------------------
-//-------------------------------------------------------------------------------------------------
-//
-// ControlBar.wnd is authored at 800x600 and GameWindowManagerScript stretches every coordinate by
-// the display size over that, separately in x and y. On a 16:9 screen that is a 1.33x horizontal
-// smear: square cameos come out as rectangles and one strip eats the whole bottom of the screen.
-// layoutPanels throws the stretch away. It recovers each window's authored rectangle, then puts it
-// back at ONE uniform scale inside one of three panels - radar hard left, command grid centred,
-// selection hard right. Nothing is distorted and the world shows through the two gaps.
-//
-
-static const Real CONTROL_BAR_DESIGN_W = 800.0f;
-static const Real CONTROL_BAR_DESIGN_H = 600.0f;
-static const Real CONTROL_BAR_DESIGN_TOP = 416.0f; ///< where ControlBarParent starts
-
-/// the authored 800x600 rectangle of each panel
-static const IRegion2D thePanelDesignRect[ ControlBar::CB_PANEL_COUNT ] =
-{
- { { 0, 421 }, { 186, 600 } }, // CB_PANEL_LEFT - radar
- { { 186, 432 }, { 624, 600 } }, // CB_PANEL_CENTER - money, power, command grid
- { { 614, 428 }, { 800, 600 } }, // CB_PANEL_RIGHT - selection portrait and upgrades
-};
-
-/// where each panel is pinned: the fraction of the screen its anchor lands on...
-static const Real thePanelAnchorFraction[ ControlBar::CB_PANEL_COUNT ] = { 0.0f, 0.5f, 1.0f };
-/// ...and which authored x that anchor is, so left pins its left edge and right pins its right
-static const Real thePanelAnchorDesignX[ ControlBar::CB_PANEL_COUNT ] = { 0.0f, 405.0f, 800.0f };
-
-/// how much world has to stay visible between two panels, in screen pixels
-static const Real CONTROL_BAR_MIN_PANEL_GAP = 24.0f;
-
-//-------------------------------------------------------------------------------------------------
-/** Where the three panels land on a dispW x dispH screen, and the uniform scale that puts them
- * there. Split out of layoutPanels because it is the whole of the geometry and none of the
- * GameWindow walking, so it can be checked at any resolution without a display. */
-//-------------------------------------------------------------------------------------------------
-void ControlBarComputePanelLayout( Int dispW, Int dispH, IRegion2D *outPanel, Real *outScale )
-{
- const Real w = (Real)dispW;
- const Real h = (Real)dispH;
-
- //
- // One scale for both axes, so nothing is stretched. Three things bound it:
- //
- // - the width the .wnd was authored against, and
- // - the height, whichever of the two runs out first, and
- // - the room the panels need to sit apart.
- //
- // That last one is not optional. The panels' authored rectangles overlap - they were carved out
- // of one continuous strip, so they add up to 810 of the 800 design units - and the anchors then
- // push the outer two to the screen edges. On a 16:9 screen the height bound is the tight one and
- // there is width to spare, but at 4:3 and squarer the width bound wins and 810 units of panel
- // land in 800 units of screen: no gap at all and overlapping plates at both seams. Solving
- // gap >= CONTROL_BAR_MIN_PANEL_GAP for the scale gives the third bound below; both gaps work out
- // to w/2 - 405*s, so one expression covers them.
- //
- Real s = w / CONTROL_BAR_DESIGN_W;
- const Real byHeight = h / CONTROL_BAR_DESIGN_H;
- const Real byGap = ( w * 0.5f - CONTROL_BAR_MIN_PANEL_GAP ) / 405.0f;
-
- if( byHeight < s )
- s = byHeight;
- if( byGap < s )
- s = byGap;
-
- //
- // Floor throughout, never REAL_TO_INT_CEIL: BaseType.h's fast_float_ceil adds 0.99999994 and
- // truncates, and past about 1024 that sum rounds up to the next whole float - so the "ceiling"
- // of an exact 1080 is 1081, one pixel off the bottom of a 1080p screen. The three edges that
- // have to be exact are pinned below instead, which is what they mean anyway.
- //
- for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ )
- {
- const Real originX = w * thePanelAnchorFraction[ p ] - thePanelAnchorDesignX[ p ] * s;
-
- outPanel[ p ].lo.x = REAL_TO_INT_FLOOR( originX + thePanelDesignRect[ p ].lo.x * s );
- outPanel[ p ].hi.x = REAL_TO_INT_FLOOR( originX + thePanelDesignRect[ p ].hi.x * s );
- outPanel[ p ].lo.y = REAL_TO_INT_FLOOR(
- h - ( CONTROL_BAR_DESIGN_H - thePanelDesignRect[ p ].lo.y ) * s );
- outPanel[ p ].hi.y = dispH; // every panel sits on the bottom edge of the screen
- }
-
- // the outer two are pinned to the screen edges, so say so rather than hoping the float lands
- outPanel[ ControlBar::CB_PANEL_LEFT ].lo.x = 0;
- outPanel[ ControlBar::CB_PANEL_RIGHT ].hi.x = dispW;
-
- *outScale = s;
-
-} // end ControlBarComputePanelLayout
-
-//-------------------------------------------------------------------------------------------------
-/** Which panel a direct child of ControlBarParent belongs to. Everything not named here rides in
- * the middle, which is where the .wnd already puts the money, power and command windows. */
-//-------------------------------------------------------------------------------------------------
-static Int panelForWindowName( const char *shortName )
-{
- static const char *leftNames[] =
- {
- "LeftHUD", "WinUAttack", "BackgroundMarker", "ForegroundMarker", "OnTopDraw",
- // the worker/beacon/comm/options toolbar sits immediately right of the radar in the .wnd
- // (x 192-222, LeftHUD ends at 174) - it reads as part of the left cluster, not the centre
- "ButtonIdleWorker", "ButtonPlaceBeacon", "PopupCommunicator", "ButtonOptions", NULL
- };
- static const char *rightNames[] =
- {
- "RightHUD", "GeneralsExp", "ExpBarForeground", "ButtonGeneral",
- "ButtonSmall", "ButtonMedium", "ButtonLarge", NULL
- };
-
- for( const char **n = leftNames; *n; n++ )
- if( strcmp( shortName, *n ) == 0 )
- return ControlBar::CB_PANEL_LEFT;
-
- for( const char **n = rightNames; *n; n++ )
- if( strcmp( shortName, *n ) == 0 )
- return ControlBar::CB_PANEL_RIGHT;
-
- return ControlBar::CB_PANEL_CENTER;
-}
-
-//-------------------------------------------------------------------------------------------------
-/** Squeeze a window's descendants by the same factors their ancestor was squeezed by, so a subtree
- * keeps its shape. 'shiftX' additionally slides the direct children, which is what a container
- * whose own origin moved needs to keep its contents where they were. */
-//-------------------------------------------------------------------------------------------------
-static void rescaleSubtree( GameWindow *win, Real scaleX, Real scaleY, Int shiftX )
-{
- for( GameWindow *child = win->winGetChild(); child; child = child->winGetNext() )
- {
- ICoord2D pos, size;
- child->winGetPosition( &pos.x, &pos.y );
- child->winGetSize( &size.x, &size.y );
-
- child->winSetPosition( REAL_TO_INT_FLOOR( pos.x * scaleX ) + shiftX,
- REAL_TO_INT_FLOOR( pos.y * scaleY ) );
- child->winSetSize( REAL_TO_INT_CEIL( size.x * scaleX ),
- REAL_TO_INT_CEIL( size.y * scaleY ) );
-
- rescaleSubtree( child, scaleX, scaleY, 0 );
- }
-}
-
-//-------------------------------------------------------------------------------------------------
-/** Re-anchor the control bar as three panels at one uniform scale. */
-//-------------------------------------------------------------------------------------------------
-void ControlBar::layoutPanels( void )
-{
- GameWindow *parent = m_contextParent[ CP_MASTER ];
- if( parent == NULL || TheDisplay == NULL )
- return;
-
- const Real dispW = (Real)TheDisplay->getWidth();
- const Real dispH = (Real)TheDisplay->getHeight();
-
- // what the .wnd loader already multiplied every coordinate by, so we can divide it back out
- const Real loadScaleX = dispW / CONTROL_BAR_DESIGN_W;
- const Real loadScaleY = dispH / CONTROL_BAR_DESIGN_H;
-
- // where each panel lands on screen - the plates are drawn from this
- Real s;
- ControlBarComputePanelLayout( TheDisplay->getWidth(), TheDisplay->getHeight(), m_panelRect, &s );
-
- Int p;
-
- // the children's positions are relative to the frame, so grab where it is before moving it
- ICoord2D barOrigin;
- parent->winGetScreenPosition( &barOrigin.x, &barOrigin.y );
-
- // the frame itself stays full width - it draws nothing and passes input through
- const Int parentTop =
- REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - CONTROL_BAR_DESIGN_TOP ) * s );
- parent->winSetPosition( 0, parentTop );
- parent->winSetSize( TheDisplay->getWidth(), TheDisplay->getHeight() - parentTop );
-
- const Real shrinkX = s / loadScaleX;
- const Real shrinkY = s / loadScaleY;
-
- for( GameWindow *child = parent->winGetChild(); child; child = child->winGetNext() )
- {
- ICoord2D rel, size;
- child->winGetPosition( &rel.x, &rel.y );
- child->winGetSize( &size.x, &size.y );
-
- // recover the authored 800x600 rectangle the loader stretched
- const Real designX = ( barOrigin.x + rel.x ) / loadScaleX;
- const Real designY = ( barOrigin.y + rel.y ) / loadScaleY;
- const Real designW = size.x / loadScaleX;
- const Real designH = size.y / loadScaleY;
-
- AsciiString name = child->winGetInstanceData()->m_decoratedNameString;
- const char *colon = strchr( name.str(), ':' );
- const char *shortName = colon ? colon + 1 : name.str();
-
- p = panelForWindowName( shortName );
- const Real originX = dispW * thePanelAnchorFraction[ p ] - thePanelAnchorDesignX[ p ] * s;
-
- Int newX, newY, newW, newH, shiftChildren = 0;
-
- //
- // The unnamed children are the GameWinBlockInput panes: their only job is to keep clicks on
- // the bar out of the world, so they become exactly their panel. If they kept their authored
- // width the widest of them would still cover the gaps we just opened up.
- //
- if( shortName[ 0 ] == 0 )
- {
- newX = m_panelRect[ p ].lo.x;
- newY = m_panelRect[ p ].lo.y;
- newW = m_panelRect[ p ].width();
- newH = m_panelRect[ p ].height();
- }
- else
- {
- newX = REAL_TO_INT_FLOOR( originX + designX * s );
- newY = REAL_TO_INT_FLOOR( dispH - ( CONTROL_BAR_DESIGN_H - designY ) * s );
- newW = REAL_TO_INT_CEIL( designW * s );
- newH = REAL_TO_INT_CEIL( designH * s );
-
- //
- // CenterBackground is authored full width but blocks input as well as holding the command
- // windows, so left alone it would swallow clicks over the whole bottom of the screen.
- // Pull it in to the centre panel and slide its contents back by as much as it moved.
- //
- if( strcmp( shortName, "CenterBackground" ) == 0 )
- {
- shiftChildren = newX - m_panelRect[ p ].lo.x;
- newX = m_panelRect[ p ].lo.x;
- newW = m_panelRect[ p ].width();
- }
- }
-
- child->winSetPosition( newX, newY - parentTop );
- child->winSetSize( newW, newH );
- rescaleSubtree( child, shrinkX, shrinkY, shiftChildren );
- }
-
-} // end layoutPanels
-
//-------------------------------------------------------------------------------------------------
/** Initialzie the control bar, this is our interface to the context sinsitive GUI */
//-------------------------------------------------------------------------------------------------
@@ -1481,9 +1240,6 @@ void ControlBar::init( void )
id = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ControlBarParent" );
m_contextParent[ CP_MASTER ] = TheWindowManager->winGetWindowFromId( NULL, id );
- // re-anchor the bar as three uniformly scaled panels before anything reads a position off it
- layoutPanels();
-
m_contextParent[ CP_MASTER ]->winGetPosition(&m_defaultControlBarPosition.x, &m_defaultControlBarPosition.y);
m_scienceLayout = TheWindowManager->winCreateLayout("GeneralsExpPoints.wnd");
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp
index bbf91e314..75bbe2401 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/ControlBarCallback.cpp
@@ -511,7 +511,8 @@ void ShowControlBar( Bool immediate )
if (window)
{
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
- TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
+ // full height: the three panels are drawn over the world, they do not crop it (see InGameUI::init)
+ TheTacticalView->setHeight((Int)(TheDisplay->getHeight()));
if (TheControlBar->m_animateWindowManager && !immediate)
{
TheControlBar->m_animateWindowManager->reset();
@@ -591,8 +592,8 @@ void ToggleControlBar( Bool immediate )
if(TheControlBar)
TheControlBar->showSpecialPowerShortcut();
- //now hidden, we're making it visible again so shrink viewport under the window
- TheTacticalView->setHeight((Int)(TheDisplay->getHeight() * 0.80f));
+ // full height: the three panels are drawn over the world, they do not crop it (see InGameUI::init)
+ TheTacticalView->setHeight((Int)(TheDisplay->getHeight()));
window->winHide(!window->winIsHidden());
TheControlBar->switchControlBarStage(CONTROL_BAR_STAGE_DEFAULT);
if (TheControlBar->m_animateWindowManager && !immediate)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index fa951aaf3..304f6c795 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1211,7 +1211,6 @@ void InGameUI::init( void )
// make the tactical display the full screen width for now
TheTacticalView->setWidth( TheDisplay->getWidth());
- // make the tactical display 0.76 of full screen so no drawing under GUI.
TheTacticalView->setHeight( TheDisplay->getHeight() * 0.77f);
}
TheTacticalView->setDefaultView(0.0f, 0.0f, 1.0f);
@@ -5370,13 +5369,8 @@ void InGameUI::drawIncomeRate( void )
Int textHeight = 0;
m_incomeDisplayString->getSize( NULL, &textHeight );
- //
- // Beside the balance, on the same baseline, rather than under it. This used to sit below
- // because the money window ran to the edge of a full width control bar and there was nothing
- // to its right; the centre panel is 624 design units wide against the money window's 439, so
- // the rate now goes where it reads as part of the same number.
- //
- m_incomeDisplayString->draw( pos.x + size.x + 4, pos.y + ( size.y - textHeight ) / 2,
+ // tucked under the balance rather than after it: the money window runs to the bar's edge
+ m_incomeDisplayString->draw( pos.x + 4, pos.y + size.y - 2,
GameMakeColor( 180, 235, 180, 255 ),
GameMakeColor( 0, 0, 0, 255 ) );
}
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp
index 5a41a6b36..03c76ed56 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/GUICallbacks/W3DControlBar.cpp
@@ -633,36 +633,52 @@ void W3DCommandBarTopDraw( GameWindow *window, WinInstanceData *instData )
}
-//
-// The scheme art (ControlBarScheme) is one wide painting of the whole bar, drawn from a single
-// anchor with its own resolution multiplier. Now that the bar is three separately anchored panels
-// there is nowhere for that painting to go, so it is not drawn at all: each panel gets its own
-// plate here instead, sized from the rectangles ControlBar::layoutPanels worked out.
-//
void W3DCommandBarBackgroundDraw( GameWindow *window, WinInstanceData *instData )
{
- if( !TheControlBar || !TheDisplay )
- return;
-
- const Color plate = GameMakeColor( 0, 0, 0, 190 );
- const Color edge = GameMakeColor( 140, 140, 140, 120 );
- for( Int p = 0; p < ControlBar::CB_PANEL_COUNT; p++ )
+ ControlBarSchemeManager *man = TheControlBar->getControlBarSchemeManager();
+ if(!man)
+ return;
+ static NameKeyType winNamekey = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) );
+ GameWindow *win = TheWindowManager->winGetWindowFromId(NULL,winNamekey);
+ static ICoord2D basePos;
+ if(!win)
{
- const IRegion2D *r = TheControlBar->getPanelRect( p );
- if( r->width() <= 0 || r->height() <= 0 )
- continue;
-
- TheDisplay->drawFillRect( r->lo.x, r->lo.y, r->width(), r->height(), plate );
- TheDisplay->drawOpenRect( r->lo.x, r->lo.y, r->width(), r->height(), 1.0f, edge );
+ return;
+ //win = TheWindowManager->winGetWindowFromId(NULL,TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) ));
}
+ TheControlBar->getBackgroundMarkerPos(&basePos.x, &basePos.y);
+ ICoord2D pos, offset;
+ win->winGetScreenPosition(&pos.x,&pos.y);
+ offset.x = pos.x - basePos.x;
+ offset.y = pos.y - basePos.y;
+
+ man->drawBackground(offset);
}
void W3DCommandBarForegroundDraw( GameWindow *window, WinInstanceData *instData )
{
- // nothing sits on top of the plates - see W3DCommandBarBackgroundDraw
+ ControlBarSchemeManager *man = TheControlBar->getControlBarSchemeManager();
+ if(!man)
+ return;
+
+ static NameKeyType winNamekey = TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) );
+ GameWindow *win = TheWindowManager->winGetWindowFromId(NULL,winNamekey);
+ static ICoord2D basePos;
+ if(!win)
+ {
+ return;
+ //win = TheWindowManager->winGetWindowFromId(NULL,TheNameKeyGenerator->nameToKey( AsciiString( "ControlBar.wnd:BackgroundMarker" ) ));
+ }
+ TheControlBar->getForegroundMarkerPos(&basePos.x, &basePos.y);
+ ICoord2D pos, offset;
+ win->winGetScreenPosition(&pos.x,&pos.y);
+ offset.x = pos.x - basePos.x;
+ offset.y = pos.y - basePos.y;
+
+ man->drawForeground(offset);
}