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.

feat(gameclient): a global production strip above the control bar

Olcay Seygan4b04b2416e82
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index 23a65e553..a2caaefb5 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -471,6 +471,22 @@ public: // ********************************************************************
virtual void draw( void ) = 0; ///< Render the in-game user interface
virtual void postDraw( void ); ///< Logic which needs to occur after the UI renders
+ //
+ // One cameo of the global production strip: which producer it belongs to, which entry of that
+ // producer's queue it is, and where it was drawn this frame.
+ //
+ enum { MAX_PRODUCTION_STRIP = 24 }; ///< as many cameos as the strip will ever draw
+ struct ProductionStripSlot
+ {
+ ObjectID producer; ///< the building this item is queued on
+ Int id; ///< its ProductionID in that building's queue
+ /// (kept as an Int so this header stays clear of GameLogic)
+ ICoord2D pos; ///< top left corner of the cameo on screen
+ };
+
+ /// a click landed on the strip: jump to that producer, or cancel the item when 'cancel' is set
+ Bool handleProductionStripClick( const ICoord2D *mouse, Bool cancel );
+
/// Ingame video playback
virtual void playMovie( const AsciiString& movieName );
virtual void stopMovie( void );
@@ -756,6 +772,7 @@ protected:
void drawHudOverlay( void ); ///< the small elapsed-time / fps plate (ShowHudOverlay)
void drawIncomeRate( void ); ///< income per minute, drawn beside the money window
void updateIncomeEstimate( Player *player ); ///< income per minute, shown beside the money
+ void drawProductionStrip( void ); ///< the global production queue, above the control bar
Bool m_placementRangeRingUp; ///< we put a radius cursor up for a pending structure, so we owe a clear
Real m_placementRingRadius; ///< the radius that ring was built at, so it is not rebuilt every frame
@@ -770,6 +787,14 @@ protected:
UnsignedInt m_hudLastMoneyFrame; ///< logic frame of that sample
Int m_hudIncomePerMin; ///< most recent income estimate, cash per minute
+ //
+ // The global production strip: every unit the local player has queued anywhere, one cameo
+ // each, oldest first, left aligned above the control bar. drawProductionStrip() lays it out
+ // and records where each cameo landed; handleProductionStripClick() reads those back.
+ //
+ ProductionStripSlot m_productionStrip[ MAX_PRODUCTION_STRIP ];
+ Int m_productionStripCount; ///< how many of those slots are live this frame
+
Coord2D m_superweaponPosition;
Real m_superweaponFlashDuration;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/PlaceEventTranslator.h b/GeneralsMD/Code/GameEngine/Include/GameClient/PlaceEventTranslator.h
index a180f8b3c..2a2e357ea 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/PlaceEventTranslator.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/PlaceEventTranslator.h
@@ -37,6 +37,7 @@ class PlaceEventTranslator : public GameMessageTranslator
{
private:
UnsignedInt m_frameOfUpButton;
+ Bool m_stripClickTaken; ///< the down went to the global production strip, so its up belongs there too
public:
PlaceEventTranslator();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index 64f2f4e77..eb5bd2b53 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -1031,6 +1031,7 @@ InGameUI::InGameUI()
m_hudLastMoney = -1;
m_hudLastMoneyFrame = 0;
m_hudIncomePerMin = 0;
+ m_productionStripCount = 0;
m_superweaponPosition.x = 0.7f;
m_superweaponPosition.y = 0.7f;
@@ -3596,6 +3597,7 @@ void InGameUI::postDraw( void )
{
drawHudOverlay();
drawIncomeRate();
+ drawProductionStrip();
// render our display strings for the messages if on
@@ -5399,6 +5401,186 @@ void InGameUI::drawHudOverlay( void )
m_hudDisplayString->draw( x, y, GameMakeColor( 235, 235, 235, 255 ), GameMakeColor( 0, 0, 0, 255 ) );
}
+//-------------------------------------------------------------------------------------------------
+// The global production strip: one cameo per queued unit across every building the local player
+// owns, oldest first, left aligned in a row that grows to the right just above the control bar.
+// The item a building is actually working on wears a radial fill. A click jumps the camera to the
+// building it is queued on; ctrl-click cancels it.
+//-------------------------------------------------------------------------------------------------
+enum
+{
+ PRODUCTION_STRIP_CAMEO = 32, ///< cameo edge in pixels
+ PRODUCTION_STRIP_GAP = 3, ///< space between cameos
+ PRODUCTION_STRIP_LEFT = 8, ///< inset from the left edge of the screen
+ PRODUCTION_STRIP_LIFT = 6 ///< clearance above the control bar
+};
+
+//-------------------------------------------------------------------------------------------------
+/** Player::iterateObjects callback: append every unit this producer has queued. */
+//-------------------------------------------------------------------------------------------------
+struct ProductionStripGather
+{
+ InGameUI::ProductionStripSlot *slot;
+ Int *count;
+};
+
+static void gatherProductionStrip( Object *obj, void *userData )
+{
+ ProductionStripGather *g = (ProductionStripGather *)userData;
+
+ if( obj == NULL || *g->count >= InGameUI::MAX_PRODUCTION_STRIP )
+ return;
+
+ ProductionUpdateInterface *pu = obj->getProductionUpdateInterface();
+ if( pu == NULL )
+ return;
+
+ for( const ProductionEntry *p = pu->firstProduction(); p; p = pu->nextProduction( p ) )
+ {
+ if( p->getProductionType() != PRODUCTION_UNIT )
+ continue;
+
+ //
+ // an entry can stand for several units of the same kind, and each of them is its own
+ // cameo here - the strip counts units, not orders
+ //
+ Int remaining = p->getProductionQuantityRemaining();
+ if( remaining < 1 )
+ remaining = 1;
+
+ while( remaining-- > 0 && *g->count < InGameUI::MAX_PRODUCTION_STRIP )
+ {
+ InGameUI::ProductionStripSlot *slot = &g->slot[ (*g->count)++ ];
+ slot->producer = obj->getID();
+ slot->id = (Int)p->getProductionID();
+ slot->pos.x = 0;
+ slot->pos.y = 0;
+ }
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+void InGameUI::drawProductionStrip( void )
+{
+ m_productionStripCount = 0;
+
+ if( TheGameLogic == NULL || !TheGameLogic->isInGame() || TheGameLogic->isInShellGame() )
+ return;
+
+ Player *player = ThePlayerList ? ThePlayerList->getLocalPlayer() : NULL;
+ if( player == NULL )
+ return;
+
+ ProductionStripGather gather;
+ gather.slot = m_productionStrip;
+ gather.count = &m_productionStripCount;
+ player->iterateObjects( gatherProductionStrip, &gather );
+
+ if( m_productionStripCount == 0 )
+ return;
+
+ //
+ // sit on top of the control bar. If the bar is not up (it is hidden while the game is loading,
+ // and in the observer views) fall back to the bottom of the screen.
+ //
+ Int barTop = TheDisplay->getHeight();
+ static NameKeyType controlBarKey = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ControlBarParent" );
+ GameWindow *bar = TheWindowManager->winGetWindowFromId( NULL, controlBarKey );
+ if( bar && !bar->winIsHidden() )
+ {
+ ICoord2D barPos;
+ bar->winGetScreenPosition( &barPos.x, &barPos.y );
+ barTop = barPos.y;
+ }
+
+ const Int y = barTop - PRODUCTION_STRIP_CAMEO - PRODUCTION_STRIP_LIFT;
+ if( y < 0 )
+ return;
+
+ // one plate behind the whole row, so the cameos read over any terrain
+ const Int rowWidth = m_productionStripCount * PRODUCTION_STRIP_CAMEO +
+ ( m_productionStripCount - 1 ) * PRODUCTION_STRIP_GAP;
+ TheDisplay->drawFillRect( PRODUCTION_STRIP_LEFT - 3, y - 3, rowWidth + 6, PRODUCTION_STRIP_CAMEO + 6,
+ GameMakeColor( 0, 0, 0, 130 ) );
+
+ Int x = PRODUCTION_STRIP_LEFT;
+ for( Int i = 0; i < m_productionStripCount; i++ )
+ {
+ ProductionStripSlot *slot = &m_productionStrip[ i ];
+ slot->pos.x = x;
+ slot->pos.y = y;
+
+ //
+ // re-read the entry rather than caching the template: production runs on the logic clock
+ // and this draws on the render clock, so anything held from the gather can be stale
+ //
+ Object *producer = TheGameLogic->findObjectByID( slot->producer );
+ ProductionUpdateInterface *pu = producer ? producer->getProductionUpdateInterface() : NULL;
+ const ProductionEntry *entry = NULL;
+ if( pu )
+ for( const ProductionEntry *p = pu->firstProduction(); p; p = pu->nextProduction( p ) )
+ if( (Int)p->getProductionID() == slot->id )
+ {
+ entry = p;
+ break;
+ }
+
+ if( entry && entry->getProductionObject() )
+ {
+ const Image *cameo = entry->getProductionObject()->getButtonImage();
+ if( cameo )
+ TheDisplay->drawImage( cameo, x, y, x + PRODUCTION_STRIP_CAMEO, y + PRODUCTION_STRIP_CAMEO );
+
+ // the head of a building's queue is the one being worked on, and only it has progress
+ if( pu->firstProduction() == entry && entry->getPercentComplete() > 0.0f )
+ TheDisplay->drawRectClock( x, y, PRODUCTION_STRIP_CAMEO, PRODUCTION_STRIP_CAMEO,
+ REAL_TO_INT( entry->getPercentComplete() ),
+ GameMakeColor( 0, 0, 0, 100 ) );
+ }
+
+ TheDisplay->drawOpenRect( x, y, PRODUCTION_STRIP_CAMEO, PRODUCTION_STRIP_CAMEO, 1.0f,
+ GameMakeColor( 160, 160, 160, 160 ) );
+
+ x += PRODUCTION_STRIP_CAMEO + PRODUCTION_STRIP_GAP;
+ }
+}
+
+//-------------------------------------------------------------------------------------------------
+Bool InGameUI::handleProductionStripClick( const ICoord2D *mouse, Bool cancel )
+{
+ if( mouse == NULL || m_productionStripCount == 0 )
+ return FALSE;
+
+ for( Int i = 0; i < m_productionStripCount; i++ )
+ {
+ const ProductionStripSlot *slot = &m_productionStrip[ i ];
+
+ if( mouse->x < slot->pos.x || mouse->x >= slot->pos.x + PRODUCTION_STRIP_CAMEO ||
+ mouse->y < slot->pos.y || mouse->y >= slot->pos.y + PRODUCTION_STRIP_CAMEO )
+ continue;
+
+ Object *producer = TheGameLogic->findObjectByID( slot->producer );
+ if( producer == NULL )
+ return TRUE; // the building died under the cursor - the click is still ours
+
+ if( cancel )
+ {
+ // the producer travels with the message: the logic cannot tell whose queue this is otherwise
+ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_CANCEL_UNIT_CREATE );
+ msg->appendIntegerArgument( slot->id );
+ msg->appendObjectIDArgument( slot->producer );
+ }
+ else
+ {
+ TheTacticalView->lookAt( producer->getPosition() );
+ }
+
+ return TRUE;
+ }
+
+ return FALSE;
+}
+
void InGameUI::drawFloatingText( void )
{
FloatingTextData *ftd;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
index b8475e9cc..871986c0d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
@@ -55,7 +55,7 @@
#endif
//-------------------------------------------------------------------------------------------------
-PlaceEventTranslator::PlaceEventTranslator() : m_frameOfUpButton(-1)
+PlaceEventTranslator::PlaceEventTranslator() : m_frameOfUpButton(-1), m_stripClickTaken(FALSE)
{
}
@@ -71,12 +71,32 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess
{
GameMessageDisposition disp = KEEP_MESSAGE;
+ // the up that closes a click the strip took is not a selection either
+ if( m_stripClickTaken && msg->getType() == GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP )
+ {
+ m_stripClickTaken = FALSE;
+ return DESTROY_MESSAGE;
+ }
+
switch(msg->getType())
{
//---------------------------------------------------------------------------------------------
case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN:
{
+ //
+ // The global production strip lies over the world rather than inside a window, so
+ // nothing above us has claimed a click on it. Take it here, before placement and long
+ // before selection turns it into a move order. Ctrl cancels the item, a plain click
+ // takes the camera to the building it is queued on.
+ //
+ if( TheInGameUI->handleProductionStripClick( &msg->getArgument(0)->pixel,
+ TheKeyboard && TheKeyboard->isCtrl() ) )
+ {
+ m_stripClickTaken = TRUE;
+ return DESTROY_MESSAGE;
+ }
+
// if we're in a building placement mode, do the place and send to all players
const ThingTemplate *build = TheInGameUI->getPendingPlaceType();
if( build && TheInGameUI->isPlacementAnchored() == FALSE )