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): rework the command bar around the grid keys and multi-selection

Olcay Seygan73b788255422
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
index 68aff94d5..a737d5fb7 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
@@ -239,6 +239,14 @@ public:
MSG_META_COMMAND_SLOT12, ///< press command bar slot 12
MSG_META_COMMAND_SLOT13, ///< press command bar slot 13
MSG_META_COMMAND_SLOT14, ///< press command bar slot 14
+ MSG_META_SHORTCUT_SLOT01, ///< press general's power shortcut bar slot 01 (F1)
+ MSG_META_SHORTCUT_SLOT02, ///< press general's power shortcut bar slot 02
+ MSG_META_SHORTCUT_SLOT03, ///< press general's power shortcut bar slot 03
+ MSG_META_SHORTCUT_SLOT04, ///< press general's power shortcut bar slot 04
+ MSG_META_SHORTCUT_SLOT05, ///< press general's power shortcut bar slot 05
+ MSG_META_SHORTCUT_SLOT06, ///< press general's power shortcut bar slot 06
+ MSG_META_SHORTCUT_SLOT07, ///< press general's power shortcut bar slot 07
+ MSG_META_SHORTCUT_SLOT08, ///< press general's power shortcut bar slot 08
MSG_META_VIEW_COMMAND_CENTER, ///< center view on command center
MSG_META_VIEW_LAST_RADAR_EVENT, ///< center view on last radar event
MSG_META_SELECT_HERO, ///< selects player's hero character, if exists...
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index 7922299d9..933395350 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -409,6 +409,7 @@ private:
//-------------------------------------------------------------------------------------------------
enum { MAX_COMMANDS_PER_SET = 18 }; // user interface max is 14 (but internally it's 18 for script only buttons!)
enum { MAX_RIGHT_HUD_UPGRADE_CAMEOS = 5};
+enum { MAX_MULTI_SELECT_GROUPS = 36 }; ///< unit types a multi-selection tells apart (6x6 grid, Tab focus)
enum {
MAX_PURCHASE_SCIENCE_RANK_1 = 4,
MAX_PURCHASE_SCIENCE_RANK_3 = 15,
@@ -691,14 +692,33 @@ public:
a mouse click would. This is what the COMMAND_SLOTnn grid keys are wired to. */
void pressCommandButton( Int index );
+ /** press the index'th visible general's power shortcut button, exactly as a mouse click
+ would. This is what the SHORTCUT_SLOTnn keys (F1..F8) are wired to. */
+ void pressSpecialPowerShortcut( Int index );
+
/** A builder with more structures than BUILD_PAGE_ONE_SIZE does not show them all at once.
- The command bar opens on two menu buttons instead - the first grid keys, Q and W - and
- each one opens its own page of structures, so a structure is two keystrokes away (Q-Q,
- Q-W, ... W-Q, ...) instead of competing for the fourteen slots. Page one holds the
- first BUILD_PAGE_ONE_SIZE structures of the command set, page two holds the rest. */
- enum { BUILD_PAGE_ROOT = -1, BUILD_PAGE_COUNT = 2, BUILD_PAGE_ONE_SIZE = 4 };
+ The command bar opens on two menu buttons instead - Q and W - and each one opens its
+ own page of structures, so a structure is two keystrokes away (Q-Q, Q-A, ... W-Q, ...)
+ instead of competing for the fourteen slots. Page one holds the first
+ BUILD_PAGE_ONE_SIZE structures of the command set (the ones that sit on Q W E / A S D
+ without paging), page two holds the rest (the R T Y / F G H region). */
+ enum { BUILD_PAGE_ROOT = -1, BUILD_PAGE_COUNT = 2, BUILD_PAGE_ONE_SIZE = 6 };
void setBuildPage( Int page );
+ /** with multiple units selected the right HUD shows the unit types; Tab (+1) and
+ Shift-Tab (-1) walk the focus between them */
+ void cycleMultiSelectFocus( Int direction );
+
+ /** a builder's structures are reached by a two-key chord: the Q cell (slot 0) arms the
+ structures in columns 1-4 (slots 0..7), the W cell (slot 2) the ones in columns 5-7
+ (slots 8..), then the next grid key picks the cell within the group by its own position */
+ enum { CHORD_SLOT_Q = 0, CHORD_SLOT_W = 2, CHORD_GROUP_SIZE = 8 };
+
+ /** a raw key while a chord is armed: one of the fixed second keys (Q A W S E D R F)
+ resolves the chord and returns TRUE (the key is eaten), anything else drops it */
+ Bool handleChordKey( Int mappableKey );
+ Bool isChordArmed( void ) const { return m_chordGroup >= 0; }
+
/// is the drawable the currently selected drawable for the context sensitive UI?
Bool isDrivingContextUI( Drawable *draw ) const { return draw == m_currentSelectedDrawable; }
@@ -841,6 +861,7 @@ protected:
void resetCommonCommandData( void ); /// reset shared command data
void resetContainData( void ); /// reset container data we use to tie controls to objects IDs for containment
void resetBuildQueueData( void ); /// reset the build queue data we use to die queue entires to control
+ void resetBuildQueueButtons( void ); /// attach the queue button windows and wipe them to empty
// the following methods are for populating the context GUI controls for a particular context
static void populateButtonProc( Object *obj, void *userData );
@@ -849,6 +870,11 @@ protected:
void buildCommandLayout( Object *obj, const CommandSet *commandSet, const CommandButton **slot );
void makeBuildPageButtons( void );
void populateMultiSelect( void );
+ void populateMultiSelectUnitList( void );
+ void setMultiSelectFocus( Int index );
+ void updateMultiSelectStrip( void );
+ void layoutMultiSelectTiles( Int count ); ///< make sure count cells exist, laid out n x n over the right HUD
+ void cancelLastQueuedUnit( const ThingTemplate *thing ); ///< right-click on a build button
void populateBuildQueue( Object *producer );
void populateStructureInventory( Object *building );
void populateBeacon( Object *beacon );
@@ -941,6 +967,9 @@ protected:
CommandButton *m_buildPageBackButton; ///< takes a page back to the menu buttons
Int m_buildPage; ///< BUILD_PAGE_ROOT, or the page being shown
ObjectID m_buildPageObjectID; ///< builder the page belongs to; a new one starts at the menu
+ Int m_chordGroup; ///< -1, or the structure group (0 = Q, 1 = W) armed by the first chord key
+ DrawableID m_standInBuilderID; ///< with nothing selected, the builder whose command bar is shown (INVALID_DRAWABLE_ID otherwise)
+ Drawable *findStandInBuilder( Bool freeOnly ); ///< the local player's free builder (or, unless freeOnly, any builder) to stand in for an empty selection
// removed from multiplayer branch
//GameWindow *m_commandMarkers[ MAX_COMMANDS_PER_SET ]; ///< When we don't have a command, they want to show an image
@@ -974,6 +1003,15 @@ protected:
};
QueueEntry m_queueData[ MAX_BUILD_QUEUE_BUTTONS ]; ///< what the build queue represents
+ // a multi-selection grouped by unit type: one cameo cell per type, with its count, in an
+ // n x n grid over the right HUD (n = ceil(sqrt(types))); Tab walks the focus over the types
+ std::vector<GameWindow *> m_multiSelectTiles; ///< grid cells, created in code on demand over the right HUD
+ const ThingTemplate *m_multiSelectGroupTemplate[ MAX_MULTI_SELECT_GROUPS ]; ///< one entry per selected unit type
+ Int m_multiSelectGroupSize[ MAX_MULTI_SELECT_GROUPS ]; ///< how many of that type are selected
+ DrawableID m_multiSelectGroupFirst[ MAX_MULTI_SELECT_GROUPS ]; ///< a member of the group, the context representative
+ Int m_multiSelectGroupCount; ///< number of type groups
+ Int m_multiSelectFocus; ///< the group Tab currently focuses
+
//cameo flash
Bool m_flash; ///< tells update whether or not to check for flash
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
index 3e2a79219..9ed931730 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/Gadget.h
@@ -431,6 +431,7 @@ typedef struct _PushButtonData
Color colorClock; ///< The color to display the clock at
Bool drawBorder; ///< We only want to draw the border if we want to
Color colorBorder; ///< The color for the border around the button
+ Int drawCount; ///< when > 0, a small number badge drawn in the bottom right corner
void *userData; ///< random additional data we can set
const Image *overlayImage; ///< An overlay image (like a veterancy symbol)
AsciiString altSound; ///< use an alternitive sound if one is set
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h b/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
index b525ea438..e30e3f70b 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/GadgetPushButton.h
@@ -81,6 +81,7 @@ void GadgetButtonDrawClock( GameWindow *g, Int percent, Color color ); //Darkens
void GadgetButtonDrawInverseClock( GameWindow *g, Int percent, Color color ); //Darkens the remaining portion.
void GadgetButtonDrawOverlayImage( GameWindow *g, const Image *image );
void GadgetButtonSetBorder( GameWindow *g, Color color, Bool drawBorder = TRUE );
+void GadgetButtonSetCount( GameWindow *g, Int count );
void GadgetButtonSetData(GameWindow *g, void *data);
void *GadgetButtonGetData(GameWindow *g);
void GadgetButtonSetAltSound( GameWindow *g, AsciiString altSound );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
index 0fdbcef2b..e41d96c60 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
@@ -347,6 +347,14 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)
CHECK_IF(MSG_META_COMMAND_SLOT12)
CHECK_IF(MSG_META_COMMAND_SLOT13)
CHECK_IF(MSG_META_COMMAND_SLOT14)
+ CHECK_IF(MSG_META_SHORTCUT_SLOT01)
+ CHECK_IF(MSG_META_SHORTCUT_SLOT02)
+ CHECK_IF(MSG_META_SHORTCUT_SLOT03)
+ CHECK_IF(MSG_META_SHORTCUT_SLOT04)
+ CHECK_IF(MSG_META_SHORTCUT_SLOT05)
+ CHECK_IF(MSG_META_SHORTCUT_SLOT06)
+ CHECK_IF(MSG_META_SHORTCUT_SLOT07)
+ CHECK_IF(MSG_META_SHORTCUT_SLOT08)
CHECK_IF(MSG_META_VIEW_COMMAND_CENTER)
CHECK_IF(MSG_META_VIEW_LAST_RADAR_EVENT)
CHECK_IF(MSG_META_SELECT_HERO)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
index 241e9f018..83ac7e976 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/Drawable.cpp
@@ -3999,7 +3999,11 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)
Int totalFrames = pe->getProductionType() == PRODUCTION_UNIT
? pe->getProductionObject()->calcTimeToBuild( player )
: pe->getProductionUpgrade()->calcTimeToBuild( player );
- Int secondsLeft = REAL_TO_INT_CEIL( totalFrames * (1.0f - pct * 0.01f) / LOGICFRAMES_PER_SECOND );
+ // real seconds: the logic runs at the game-speed rate, not at a fixed 30 frames a second
+ Int logicFps = TheGameEngine ? TheGameEngine->getFramesPerSecondLimit() : 0;
+ if( logicFps <= 0 )
+ logicFps = LOGICFRAMES_PER_SECOND;
+ Int secondsLeft = REAL_TO_INT_CEIL( totalFrames * (1.0f - pct * 0.01f) / logicFps );
// everything behind the head of the queue has not started yet, so each costs its full
// build time (an entry builds its whole quantity at once, so quantity does not scale it)
@@ -4022,7 +4026,7 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)
UnicodeString text;
if( queuedFrames > 0 )
text.format( L"%ds (%ds)", secondsLeft,
- secondsLeft + REAL_TO_INT_CEIL( INT_TO_REAL( queuedFrames ) / LOGICFRAMES_PER_SECOND ) );
+ secondsLeft + REAL_TO_INT_CEIL( INT_TO_REAL( queuedFrames ) / logicFps ) );
else
text.format( L"%ds", secondsLeft );
if( prodTimeString->getText().compare( text ) != 0 )
@@ -4031,6 +4035,25 @@ void Drawable::drawHealthBar(const IRegion2D* healthBarRegion)
prodTimeString->getSize( &textW, &textH );
prodTimeString->draw( healthBarRegion->lo.x, prodY - textH,
GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 255 ) );
+
+ // how many entries the queue holds, right-aligned on the bar (one is not worth saying)
+ if( pu->getProductionCount() > 1 )
+ {
+ static DisplayString *prodCountString = NULL;
+ if( prodCountString == NULL )
+ {
+ prodCountString = TheDisplayStringManager->newDisplayString();
+ prodCountString->setFont( prodTimeString->getFont() );
+ }
+ UnicodeString countText;
+ countText.format( L"x%d", pu->getProductionCount() );
+ if( prodCountString->getText().compare( countText ) != 0 )
+ prodCountString->setText( countText );
+ Int countW, countH;
+ prodCountString->getSize( &countW, &countH );
+ prodCountString->draw( healthBarRegion->hi.x - countW, prodY - countH,
+ GameMakeColor( 255, 255, 255, 255 ), GameMakeColor( 0, 0, 0, 255 ) );
+ }
}
} // end if
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index cb60a9e47..045a93bf4 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -53,6 +53,11 @@
#include "GameLogic/GameLogic.h"
#include "GameLogic/Object.h"
+#include "GameLogic/Module/AIUpdate.h"
+#include "GameLogic/Module/DozerAIUpdate.h"
+#include "GameLogic/Module/SupplyTruckAIUpdate.h"
+
+static Bool builderIsFree( AIUpdateInterface *ai, DozerAIInterface *dozer ); // defined with findStandInBuilder
#include "GameLogic/Module/ProductionUpdate.h"
#include "GameLogic/Module/OCLUpdate.h"
#include "GameLogic/Module/ContainModule.h"
@@ -147,6 +152,43 @@ void ControlBar::pressCommandButton( Int index )
if( index < 0 || index >= MAX_COMMANDS_PER_SET )
return;
+ //
+ // a builder's structures are reached by a two-key chord so the whole set can stay on
+ // screen: Q arms the structures in columns 1-4 (slots 0-7), W the ones in columns 5-7
+ // (slots 8-13), and the next grid key picks the cell inside that group by its own
+ // position - Q-Q, Q-A, ... W-Q (= T's cell), W-A (= G's cell) ...
+ //
+ Bool hasStructures = FALSE;
+ for( Int i = 0; i < MAX_COMMANDS_PER_SET && !hasStructures; i++ )
+ {
+ GameWindow *w = m_commandWindows[ i ];
+ if( w == NULL || BitTest( w->winGetStatus(), WIN_STATUS_HIDDEN ) )
+ continue;
+ const CommandButton *c = (const CommandButton *)GadgetButtonGetData( w );
+ hasStructures = ( c && c->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT );
+ }
+ if( hasStructures )
+ {
+ if( m_chordGroup < 0 )
+ {
+ if( index == CHORD_SLOT_Q || index == CHORD_SLOT_W )
+ {
+ m_chordGroup = ( index == CHORD_SLOT_Q ) ? 0 : 1;
+ return;
+ }
+ }
+ else
+ {
+ Int group = m_chordGroup;
+ m_chordGroup = -1;
+ if( index >= CHORD_GROUP_SIZE )
+ return; // the second key must be one of the first group's cells (Q W E R A S D F)
+ index += group * CHORD_GROUP_SIZE;
+ if( index >= MAX_COMMANDS_PER_SET )
+ return;
+ }
+ }
+
GameWindow *win = m_commandWindows[ index ];
if( win == NULL || BitTest( win->winGetStatus(), WIN_STATUS_HIDDEN ) )
return;
@@ -169,6 +211,36 @@ void ControlBar::pressCommandButton( Int index )
} // end pressCommandButton
+//-------------------------------------------------------------------------------------------------
+/** The second key of a structure chord is a fixed physical cell - Q A W S E D R F for local
+ slots 0..7 (column-major, like the command bar) - whatever the grid rows are bound to, so
+ A/S stay free for attack move and stop outside a chord. MetaEventTranslator hands the
+ raw key here while a chord is armed. */
+//-------------------------------------------------------------------------------------------------
+static const MappableKeyType s_chordKeys[ ControlBar::CHORD_GROUP_SIZE ] =
+ { MK_Q, MK_A, MK_W, MK_S, MK_E, MK_D, MK_R, MK_F };
+static const WideChar s_chordKeyLabels[ ControlBar::CHORD_GROUP_SIZE + 1 ] = L"QAWSEDRF";
+
+Bool ControlBar::handleChordKey( Int mappableKey )
+{
+ if( m_chordGroup < 0 )
+ return FALSE;
+
+ for( Int i = 0; i < CHORD_GROUP_SIZE; i++ )
+ {
+ if( s_chordKeys[ i ] == mappableKey )
+ {
+ pressCommandButton( i ); // resolves the chord: i + group * CHORD_GROUP_SIZE
+ return TRUE;
+ }
+ }
+
+ // any other key is not ours; a grid key of another cell drops the chord in
+ // pressCommandButton, a context change drops it in switchToContext
+ return FALSE;
+
+} // end handleChordKey
+
//-------------------------------------------------------------------------------------------------
/** Build the menu and back buttons a paged builder shows. They carry no thing template and no
text label of their own - the page they open is told by the cameo of its first structure, and
@@ -1007,6 +1079,16 @@ ControlBar::ControlBar( void )
for( i = 0; i < BUILD_PAGE_COUNT; i++ )
m_buildPageButton[ i ] = NULL;
m_buildPageBackButton = NULL;
+ m_chordGroup = -1;
+ m_standInBuilderID = INVALID_DRAWABLE_ID;
+ for( i = 0; i < MAX_MULTI_SELECT_GROUPS; i++ )
+ {
+ m_multiSelectGroupTemplate[ i ] = NULL;
+ m_multiSelectGroupSize[ i ] = 0;
+ m_multiSelectGroupFirst[ i ] = INVALID_DRAWABLE_ID;
+ }
+ m_multiSelectGroupCount = 0;
+ m_multiSelectFocus = 0;
m_buildPage = BUILD_PAGE_ROOT;
m_buildPageObjectID = INVALID_ID;
m_rallyPointDrawableID = INVALID_DRAWABLE_ID;
@@ -1259,11 +1341,15 @@ void ControlBar::init( void )
{
windowName.format( "ControlBar.wnd:UnitUpgrade%d", i+1 );
id = TheNameKeyGenerator->nameToKey( windowName.str() );
- m_rightHUDUpgradeCameos[ i ] =
+ m_rightHUDUpgradeCameos[ i ] =
TheWindowManager->winGetWindowFromId( m_rightHUDWindow, id );
m_rightHUDUpgradeCameos[ i ]->winSetStatus( WIN_STATUS_USE_OVERLAY_STATES );
}
+ // the multi-select unit grid cells over the right HUD are created on demand by
+ // layoutMultiSelectTiles; the windows die with the rest of the layout
+ m_multiSelectTiles.clear();
+
// m_transitionHandler = NEW GameWindowTransitionsHandler;
// m_transitionHandler->load();
// m_transitionHandler->init();
@@ -1579,6 +1665,38 @@ void ControlBar::update( void )
if(!m_contextParent[ CP_PURCHASE_SCIENCE ]->winIsHidden())
updateContextPurchaseScience();
+ //
+ // a stand-in builder is not selected, so no deselect event tells us when it dies or when a
+ // real selection arrives; re-evaluate ourselves before anything touches its drawable
+ //
+ if( m_standInBuilderID != INVALID_DRAWABLE_ID )
+ {
+ Drawable *standIn = TheGameClient->findDrawableByID( m_standInBuilderID );
+ Object *standInObj = standIn ? standIn->getObject() : NULL;
+ if( TheInGameUI->getSelectCount() > 0 || standInObj == NULL || standInObj->isEffectivelyDead() )
+ {
+ m_standInBuilderID = INVALID_DRAWABLE_ID;
+ m_currentSelectedDrawable = NULL;
+ markUIDirty();
+ }
+ else
+ {
+ // the stand-in went to work - a builder with a job greys its structure buttons out -
+ // so hand the bar to a free builder if there is one
+ AIUpdateInterface *ai = standInObj->getAI();
+ DozerAIInterface *dozer = ai ? ai->getDozerAIInterface() : NULL;
+ if( dozer && !builderIsFree( ai, dozer ) )
+ {
+ Drawable *freeBuilder = findStandInBuilder( TRUE );
+ if( freeBuilder && freeBuilder != standIn )
+ {
+ m_standInBuilderID = INVALID_DRAWABLE_ID;
+ markUIDirty();
+ }
+ }
+ }
+ }
+
//
// first, if the UI is dirty repopulate the UI with what the user should see for all the
// selected drawables
@@ -1809,10 +1927,23 @@ void ControlBar::evaluateContextUI( void )
// erase any current state of the GUI by switching out to the empty context
switchToContext( CB_CONTEXT_NONE, NULL );
+ m_standInBuilderID = INVALID_DRAWABLE_ID;
- // sanity, nothing selected
+ //
+ // nothing selected: one of the player's builders stands in and its command bar shows, so
+ // a structure can be placed without selecting a dozer first - the logic then sends the
+ // idle builder nearest the site (MSG_DOZER_CONSTRUCT)
+ //
if( TheInGameUI->getSelectCount() == 0 )
+ {
+ Drawable *builder = findStandInBuilder( FALSE );
+ if( builder )
+ {
+ switchToContext( CB_CONTEXT_COMMAND, builder );
+ m_standInBuilderID = builder->getID();
+ }
return;
+ }
// get the list of drawable IDs from the in game UI
const DrawableList *selectedDrawables = TheInGameUI->getAllSelectedDrawables();
@@ -2176,15 +2307,139 @@ CommandSet *ControlBar::newCommandSetOverride( CommandSet *setToOverride )
//-------------------------------------------------------------------------------------------------
/** Process a button click for the context sensitive GUI */
//-------------------------------------------------------------------------------------------------
-CBCommandStatus ControlBar::processContextSensitiveButtonClick( GameWindow *button,
+CBCommandStatus ControlBar::processContextSensitiveButtonClick( GameWindow *button,
GadgetGameMessage gadgetMessage )
{
+ // right-click on a unit build button takes the last one of that unit back out of the
+ // queue (the build queue panel no longer sits in the right HUD to click on)
+ if( gadgetMessage == GBM_SELECTED_RIGHT )
+ {
+ const CommandButton *command = (const CommandButton *)GadgetButtonGetData( button );
+ if( command && command->getCommandType() == GUI_COMMAND_UNIT_BUILD )
+ {
+ cancelLastQueuedUnit( command->getThingTemplate() );
+ return CBC_COMMAND_USED;
+ }
+ }
+
// call command processing method
return processCommandUI( button, gadgetMessage );
} // end processContextSensitiveButtonClick
+//-------------------------------------------------------------------------------------------------
+/** Cancel the last queued production of 'thing' on the representative producer */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::cancelLastQueuedUnit( const ThingTemplate *thing )
+{
+ Object *producer = m_currentSelectedDrawable ? m_currentSelectedDrawable->getObject() : NULL;
+ ProductionUpdateInterface *pu = producer ? producer->getProductionUpdateInterface() : NULL;
+ if( pu == NULL || thing == NULL )
+ return;
+ if( producer->getControllingPlayer() != ThePlayerList->getLocalPlayer() )
+ return;
+
+ ProductionID last = PRODUCTIONID_INVALID;
+ for( const ProductionEntry *p = pu->firstProduction(); p; p = pu->nextProduction( p ) )
+ if( p->getProductionType() == PRODUCTION_UNIT && p->getProductionObject() == thing )
+ last = p->getProductionID();
+ if( last == PRODUCTIONID_INVALID )
+ return;
+
+ // the producer travels with the message: in a multi-selection the logic cannot tell
+ // which selected object the queue belongs to otherwise
+ GameMessage *msg = TheMessageStream->appendMessage( GameMessage::MSG_CANCEL_UNIT_CREATE );
+ msg->appendIntegerArgument( last );
+ msg->appendObjectIDArgument( producer->getID() );
+
+} // end cancelLastQueuedUnit
+
+//-------------------------------------------------------------------------------------------------
+/** The local player's builder that stands in for an empty selection: an idle one if there is
+ * one, else any live one. (Player::iterateObjects callback + driver.) */
+//-------------------------------------------------------------------------------------------------
+struct StandInBuilderSearch
+{
+ Object *idle;
+ Object *any;
+};
+
+/** a builder is free for a job when it has no build/repair task and is not hauling supplies -
+ walking somewhere on a plain move order does not make it busy */
+static Bool builderIsFree( AIUpdateInterface *ai, DozerAIInterface *dozer )
+{
+ if( dozer->isAnyTaskPending() )
+ return FALSE;
+ const SupplyTruckAIInterface *supply = ai->getSupplyTruckAIInterface();
+ if( supply && supply->isCurrentlyFerryingSupplies() )
+ return FALSE;
+ return TRUE;
+}
+
+static void findStandInBuilderProc( Object *obj, void *userData )
+{
+ StandInBuilderSearch *s = (StandInBuilderSearch *)userData;
+ if( obj == NULL || obj->isEffectivelyDead() || obj->getDrawable() == NULL )
+ return;
+ if( obj->testStatus( OBJECT_STATUS_UNDER_CONSTRUCTION ) || obj->testStatus( OBJECT_STATUS_SOLD ) )
+ return;
+ AIUpdateInterface *ai = obj->getAI();
+ DozerAIInterface *dozer = ai ? ai->getDozerAIInterface() : NULL;
+ if( dozer == NULL )
+ return;
+ if( s->any == NULL )
+ s->any = obj;
+ if( s->idle == NULL && builderIsFree( ai, dozer ) )
+ s->idle = obj;
+}
+
+Drawable *ControlBar::findStandInBuilder( Bool freeOnly )
+{
+ Player *player = ThePlayerList ? ThePlayerList->getLocalPlayer() : NULL;
+ if( player == NULL )
+ return NULL;
+
+ StandInBuilderSearch s;
+ s.idle = NULL;
+ s.any = NULL;
+ player->iterateObjects( findStandInBuilderProc, &s );
+
+ Object *pick = s.idle ? s.idle : ( freeOnly ? NULL : s.any );
+ return pick ? pick->getDrawable() : NULL;
+
+} // end findStandInBuilder
+
+//-------------------------------------------------------------------------------------------------
+/** Press the index'th general's power shortcut button, as a mouse click would */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::pressSpecialPowerShortcut( Int index )
+{
+ if( index < 0 || index >= m_currentlyUsedSpecialPowersButtons || m_specialPowerShortcutParent == NULL )
+ return;
+
+ GameWindow *win = m_specialPowerShortcutButtons[ index ];
+ if( win == NULL || win->winIsHidden() || m_specialPowerShortcutParent->winIsHidden() )
+ return;
+
+ if( BitTest( win->winGetStatus(), WIN_STATUS_ENABLED ) )
+ {
+ // the bar's parent runs ControlBarSystem, the same callback a real click reaches
+ TheWindowManager->winSendSystemMsg( m_specialPowerShortcutParent, GBM_SELECTED,
+ (WindowMsgData)win, win->winGetWindowId() );
+ AudioEventRTS buttonClick( "GUIGenShortcutClick" );
+ if( TheAudio )
+ TheAudio->addAudioEvent( &buttonClick );
+ }
+ else
+ {
+ AudioEventRTS disabledClick( "GUIClickDisabled" );
+ if( TheAudio )
+ TheAudio->addAudioEvent( &disabledClick );
+ }
+
+} // end pressSpecialPowerShortcut
+
//-------------------------------------------------------------------------------------------------
/** Process a button click for the context sensitive GUI */
//-------------------------------------------------------------------------------------------------
@@ -2222,6 +2477,9 @@ void ControlBar::switchToContext( ControlBarContext context, Drawable *draw )
// save a pointer for the currently selected drawable
m_currentSelectedDrawable = draw;
+ // a half-typed structure chord does not survive a context change
+ m_chordGroup = -1;
+
if (IsInGameChatActive() == FALSE && TheGameLogic && !TheGameLogic->isInShellGame()) {
TheWindowManager->winSetFocus( NULL );
}
@@ -2298,27 +2556,9 @@ void ControlBar::switchToContext( ControlBarContext context, Drawable *draw )
// fill the specific UI info
populateCommand( draw->getObject() );
- //
- // for objects that are able to create units, we show a build queue if we actually
- // actually have something in production, otherwise we show the selection portrait
- //
+ // the selection portrait; the build queue panel never takes the right HUD over
if( obj )
- {
- ProductionUpdateInterface *pu = obj->getProductionUpdateInterface();
-
- if( pu && pu->firstProduction() != NULL )
- {
-
- m_contextParent[ CP_BUILD_QUEUE ]->winHide( FALSE );
- populateBuildQueue( obj );
- setPortraitByObject( NULL );
- } // end if
- else
- {
- setPortraitByObject( obj );
- }
-
- } // end if
+ setPortraitByObject( obj );
break;
@@ -2513,35 +2753,49 @@ void ControlBar::setCommandBarBorder( GameWindow *button, CommandButtonMappedBor
slot has no unmodified binding. Read live out of the meta map so rebinding the key in
Options > Keyboard re-labels the button. */
//-------------------------------------------------------------------------------------------------
-static UnicodeString getGridHotKeyLabel( Int slot )
+static UnicodeString getMetaKeyLabel( GameMessage::Type wanted )
{
UnicodeString label;
if( TheMetaMap == NULL || TheKeyboard == NULL )
return label;
- GameMessage::Type wanted = (GameMessage::Type)(GameMessage::MSG_META_COMMAND_SLOT01 + slot);
for( const MetaMapRec *rec = TheMetaMap->getFirstMetaMapRec(); rec; rec = rec->m_next )
{
- // only a plain, unmodified key makes a readable one character label
+ // only a plain, unmodified key makes a readable short label
if( rec->m_meta != wanted || rec->m_modState != 0 )
continue;
- WideChar c = TheKeyboard->getPrintableKey( (UnsignedByte)rec->m_key, 0 );
- if( c )
+ // function keys have no printable character; name them
+ if( rec->m_key >= MK_F1 && rec->m_key <= MK_F10 )
+ label.format( L"F%d", rec->m_key - MK_F1 + 1 );
+ else if( rec->m_key == MK_F11 )
+ label.set( L"F11" );
+ else if( rec->m_key == MK_F12 )
+ label.set( L"F12" );
+ else
{
- if( c >= L'a' && c <= L'z' )
- c -= (L'a' - L'A');
+ WideChar c = TheKeyboard->getPrintableKey( (UnsignedByte)rec->m_key, 0 );
+ if( c )
+ {
+ if( c >= L'a' && c <= L'z' )
+ c -= (L'a' - L'A');
- WideChar text[ 2 ] = { c, 0 };
- label.set( text );
+ WideChar text[ 2 ] = { c, 0 };
+ label.set( text );
+ }
}
break;
}
return label;
-} // end getGridHotKeyLabel
+} // end getMetaKeyLabel
+
+static UnicodeString getGridHotKeyLabel( Int slot )
+{
+ return getMetaKeyLabel( (GameMessage::Type)(GameMessage::MSG_META_COMMAND_SLOT01 + slot) );
+}
//-------------------------------------------------------------------------------------------------
void ControlBar::setControlCommand( GameWindow *button, const CommandButton *commandButton )
@@ -2615,7 +2869,10 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *com
// save the command in the user data of the window
GadgetButtonSetData(button, (void*)commandButton);
//button->winSetUserData( commandButton );
-
+
+ // a recycled button must not keep the previous occupant's count badge
+ GadgetButtonSetCount( button, 0 );
+
setCommandBarBorder(button, commandButton->getCommandButtonMappedBorderType());
// The '&' letter buried in each localized button label and the grid keys are two rival
@@ -2639,6 +2896,18 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *com
continue;
UnicodeString label = getGridHotKeyLabel( slot );
+
+ // structures are reached by a chord: Q or W picks the group (columns 1-4 or 5-7),
+ // then the cell's fixed second key (Q A W S E D R F) - paint both letters, "QW", "WA", ...
+ if( commandButton->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT && !label.isEmpty() )
+ {
+ Int base = ( slot < CHORD_GROUP_SIZE ) ? 0 : CHORD_GROUP_SIZE;
+ UnicodeString chord = getGridHotKeyLabel( base == 0 ? CHORD_SLOT_Q : CHORD_SLOT_W );
+ WideChar second[ 2 ] = { s_chordKeyLabels[ slot - base ], 0 };
+ chord.concat( second );
+ label = chord;
+ }
+
if( label.isEmpty() )
button->winClearStatus( WIN_STATUS_SHORTCUT_BUTTON );
else
@@ -2740,6 +3009,14 @@ void ControlBar::setPortraitByImage( const Image *image )
void ControlBar::setPortraitByObject( Object *obj )
{
+ // the multi-select unit grid lives over this same HUD; a plain portrait means it must
+ // go, and so must the selection-count badge a one-type selection put on the portrait.
+ // updateMultiSelectStrip re-applies its own look right after calling in here.
+ for( size_t tile = 0; tile < m_multiSelectTiles.size(); tile++ )
+ if( m_multiSelectTiles[ tile ] )
+ m_multiSelectTiles[ tile ]->winHide( TRUE );
+ GadgetButtonSetCount( m_rightHUDCameoWindow, 0 );
+
if( obj )
{
if( obj->isKindOf( KINDOF_SHOW_PORTRAIT_WHEN_CONTROLLED ) && !obj->isLocallyControlled() )
@@ -3420,6 +3697,18 @@ void ControlBar::initSpecialPowershortcutBar( Player *player)
// Oh god... this is a total hack for shortcut buttons to handle rendering text top left corner...
m_specialPowerShortcutButtons[ i ]->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );
+ // the F-key label should read like the command bar's grid letters, not the big yellow
+ // font the shortcut layout ships with: borrow a command button's font and text colors
+ GameWindow *model = m_commandWindows[ 0 ];
+ if( model )
+ {
+ GameWindow *b = m_specialPowerShortcutButtons[ i ];
+ b->winSetFont( model->winGetFont() );
+ b->winSetEnabledTextColors( model->winGetEnabledTextColor(), model->winGetEnabledTextBorderColor() );
+ b->winSetDisabledTextColors( model->winGetDisabledTextColor(), model->winGetDisabledTextBorderColor() );
+ b->winSetHiliteTextColors( model->winGetHiliteTextColor(), model->winGetHiliteTextBorderColor() );
+ }
+
windowName.format( parentName, i+1 );
id = TheNameKeyGenerator->nameToKey( windowName.str() );
m_specialPowerShortcutButtonParents[ i ] =
@@ -3828,39 +4117,26 @@ void ControlBar::drawSpecialPowerShortcutMultiplierText()
if( command == NULL )
continue;
- //draw superweapon ready multipliers
- for( int i = 0; i < MAX_SPECIAL_POWER_SHORTCUTS; i++ )
- {
- if( !m_shortcutDisplayStrings[ i ] )
- {
- //m_shortcutDisplayStrings[ i ] = TheDisplayStringManager->newDisplayString();
- //m_shortcutDisplayStrings[ i ]->setFont( TheFontLibrary->getFont( "Arial", 16, false ) );
- }
-
- const SpecialPowerTemplate *spTemplate = command->getSpecialPowerTemplate();
- Int numReady = 0;
- if( spTemplate )
- {
- numReady = ThePlayerList->getLocalPlayer()->countReadyShortcutSpecialPowersOfType( spTemplate->getSpecialPowerType() );
- }
- if( numReady > 1 ) // Lorenzen changed... Displaying a "1" is superfluous
- {
- UnicodeString unibuffer;
- unibuffer.format( L"%d", numReady );
-
- GadgetButtonSetText( win, unibuffer );
+ // the button's text: the key that presses it (SHORTCUT_SLOTnn, F1..), then how many
+ // of its superweapons are ready - a "1" is superfluous (Lorenzen)
+ UnicodeString text;
+ if( i < 8 )
+ text = getMetaKeyLabel( (GameMessage::Type)(GameMessage::MSG_META_SHORTCUT_SLOT01 + i) );
- //m_shortcutDisplayStrings[ i ]->setText( unibuffer );
- //TheControlBar->m_shortcutDisplayStrings[ i ]->draw( 600, i * 40 + 40, GameMakeColor(255,255,255,255), GameMakeColor(0,0,0,0), 0, 0 );
- }
- else
- {
- UnicodeString unibuffer;
- GadgetButtonSetText( win, unibuffer );
- //TheDisplayStringManager->freeDisplayString( m_shortcutDisplayStrings[ i ] );
- //m_shortcutDisplayStrings[ i ] = NULL;
- }
+ const SpecialPowerTemplate *spTemplate = command->getSpecialPowerTemplate();
+ Int numReady = 0;
+ if( spTemplate )
+ numReady = ThePlayerList->getLocalPlayer()->countReadyShortcutSpecialPowersOfType( spTemplate->getSpecialPowerType() );
+ if( numReady > 1 )
+ {
+ UnicodeString count;
+ count.format( L"%d", numReady );
+ if( !text.isEmpty() )
+ text.concat( L" " );
+ text.concat( count );
}
+
+ GadgetButtonSetText( win, text );
}
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
index ccc2dec7e..e714f8ad1 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp
@@ -70,7 +70,7 @@
// PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
static GameWindow *commandWindows[ MAX_COMMANDS_PER_SET ];
Bool commandWindowsInitialized = FALSE;
-static Color BuildClockColor = GameMakeColor(0,0,0,100);
+static Color BuildClockColor = GameMakeColor(0,0,0,120); ///< translucent black radial fill drawn over the cameo as production progresses
// STATIC DATA STORAGE ////////////////////////////////////////////////////////////////////////////
ControlBar::ContainEntry ControlBar::m_containData[ MAX_COMMANDS_PER_SET ];
@@ -267,109 +267,18 @@ void ControlBar::doTransportInventoryUI( Object *transport, const CommandSet *co
} // end doTransportInventoryUI
//-------------------------------------------------------------------------------------------------
-/** The command bar is two rows of seven, and the grid keys run along the top row first:
- slot 0 is Q, slot 2 is W, slot 4 is E and so on to slot 12 for U, then the bottom row
- from slot 1 for Z through slot 13 for M. A build page lays its structures out along
- that order so the first four of them are Q, W, E and R. Slot 1 (Z) is left out - it is
- where the back button sits. */
-//-------------------------------------------------------------------------------------------------
-static const Int s_buildPageSlots[] = { 0, 2, 4, 6, 8, 10, 12, 3, 5, 7, 9, 11, 13 };
-static const Int s_buildPageSlotCount = sizeof( s_buildPageSlots ) / sizeof( s_buildPageSlots[ 0 ] );
-static const Int s_buildPageBackSlot = 1;
-
-//-------------------------------------------------------------------------------------------------
-/** Which command button belongs in each of the command bar's slots for this object. Normally
- that is just the command set, slot for slot. A builder with more structures than one page
- holds instead gets its structures replaced by the two page menu buttons, or - once a page is
- open - by that page's structures plus a button back to the menu. Commands that are not
- structures keep the slot the data gave them on every page. */
+/** Which command button belongs in each of the command bar's slots for this object: the
+ command set, slot for slot. No paging - every structure shows at once and the ones the
+ player cannot afford or has no prerequisite for just grey out through the availability
+ pass. (The BUILD_PAGE machinery is dormant, kept in case pages come back.) */
//-------------------------------------------------------------------------------------------------
void ControlBar::buildCommandLayout( Object *obj, const CommandSet *commandSet,
const CommandButton **slot )
{
- Int i;
-
- for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
+ for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
slot[ i ] = commandSet->getCommandButton( i );
- //
- // the pages are worked with the grid keys, so without them a page would be a menu the
- // keyboard cannot reach. Leave the command set alone.
- //
- if( TheGlobalData->m_useGridHotKeys == FALSE || m_buildPageButton[ 0 ] == NULL )
- {
- m_buildPage = BUILD_PAGE_ROOT;
- return;
- }
-
- // a different builder starts at the menu rather than wherever the last one was left
- if( obj->getID() != m_buildPageObjectID )
- {
- m_buildPageObjectID = obj->getID();
- m_buildPage = BUILD_PAGE_ROOT;
- }
-
- // the structures, in command set order
- const CommandButton *structure[ MAX_COMMANDS_PER_SET ];
- Int structureCount = 0;
- for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
- if( slot[ i ] != NULL && slot[ i ]->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT )
- structure[ structureCount++ ] = slot[ i ];
-
- // a set that already fits on one page has nothing to gain from a menu in front of it
- if( structureCount <= BUILD_PAGE_ONE_SIZE )
- {
- m_buildPage = BUILD_PAGE_ROOT;
- return;
- }
-
- // page two is whatever page one did not take
- Int pageFirst[ BUILD_PAGE_COUNT ], pageLast[ BUILD_PAGE_COUNT ];
- pageFirst[ 0 ] = 0;
- pageLast[ 0 ] = BUILD_PAGE_ONE_SIZE;
- pageFirst[ 1 ] = BUILD_PAGE_ONE_SIZE;
- pageLast[ 1 ] = structureCount;
-
- // the structures give their slots up; everything else in the set stays where it is
- for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
- if( slot[ i ] != NULL && slot[ i ]->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT )
- slot[ i ] = NULL;
-
- // what the page puts on the bar, in the order the grid keys run
- const CommandButton *paged[ MAX_COMMANDS_PER_SET ];
- Int pagedCount = 0;
- if( m_buildPage == BUILD_PAGE_ROOT )
- {
- for( Int page = 0; page < BUILD_PAGE_COUNT; page++ )
- {
- // the menu button wears the cameo of the first structure behind it
- m_buildPageButton[ page ]->setButtonImage( structure[ pageFirst[ page ] ]->getButtonImage() );
- paged[ pagedCount++ ] = m_buildPageButton[ page ];
- }
- }
- else
- {
- if( TheMappedImageCollection != NULL && m_buildPageBackButton->getButtonImage() == NULL )
- m_buildPageBackButton->setButtonImage( TheMappedImageCollection->findImageByName( AsciiString( "SSStop" ) ) );
- if( slot[ s_buildPageBackSlot ] == NULL )
- slot[ s_buildPageBackSlot ] = m_buildPageBackButton;
-
- for( i = pageFirst[ m_buildPage ]; i < pageLast[ m_buildPage ]; i++ )
- paged[ pagedCount++ ] = structure[ i ];
- }
-
- // drop them into the free slots, keeping the grid key order
- Int next = 0;
- for( i = 0; i < s_buildPageSlotCount && next < pagedCount; i++ )
- {
- Int where = s_buildPageSlots[ i ];
- if( slot[ where ] != NULL )
- continue;
- slot[ where ] = paged[ next++ ];
- }
-
- DEBUG_ASSERTCRASH( next == pagedCount, ("buildCommandLayout: command set '%s' left %d structures with no slot to sit in\n",
- commandSet->getName().str(), pagedCount - next) );
+ m_buildPage = BUILD_PAGE_ROOT;
} // end buildCommandLayout
@@ -663,13 +572,12 @@ void ControlBar::resetBuildQueueData( void )
} // end resetBuildQueue
//-------------------------------------------------------------------------------------------------
+/** attach the ButtonQueueNN windows to m_queueData and wipe every button back to its empty,
+ * disabled state. Shared by the production build queue and the multi-select unit list,
+ * which reuse the same windows. */
//-------------------------------------------------------------------------------------------------
-void ControlBar::populateBuildQueue( Object *producer )
+void ControlBar::resetBuildQueueButtons( void )
{
-/// @todo srj -- remove hard-coding here, please
- static const CommandButton *cancelUnitCommand = findCommandButton( "Command_CancelUnitCreate" );
-/// @todo srj -- remove hard-coding here, please
- static const CommandButton *cancelUpgradeCommand = findCommandButton( "Command_CancelUpgradeCreate" );
static NameKeyType buildQueueIDs[ MAX_BUILD_QUEUE_BUTTONS ];
static Bool idsInitialized = FALSE;
Int i;
@@ -684,7 +592,7 @@ void ControlBar::populateBuildQueue( Object *producer )
for( i = 0; i < MAX_BUILD_QUEUE_BUTTONS; i++ )
{
-
+
buttonName.format( "ControlBar.wnd:ButtonQueue%02d", i + 1 );
buildQueueIDs[ i ] = TheNameKeyGenerator->nameToKey( buttonName );
@@ -715,8 +623,26 @@ void ControlBar::populateBuildQueue( Object *producer )
//Clear any potential veterancy rank, or else we'll see it when it's empty!
GadgetButtonDrawOverlayImage( m_queueData[ i ].control, NULL );
+ //Clear any multi-select focus border left behind
+ GadgetButtonSetBorder( m_queueData[ i ].control, GAME_COLOR_UNDEFINED, FALSE );
+ GadgetButtonSetCount( m_queueData[ i ].control, 0 );
+
} // end for i
+} // end resetBuildQueueButtons
+
+//-------------------------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
+void ControlBar::populateBuildQueue( Object *producer )
+{
+/// @todo srj -- remove hard-coding here, please
+ static const CommandButton *cancelUnitCommand = findCommandButton( "Command_CancelUnitCreate" );
+/// @todo srj -- remove hard-coding here, please
+ static const CommandButton *cancelUpgradeCommand = findCommandButton( "Command_CancelUpgradeCreate" );
+
+ // attach and wipe the queue buttons
+ resetBuildQueueButtons();
+
// step through each object being built and set the image data for the buttons
ProductionUpdateInterface *pu = producer->getProductionUpdateInterface();
if( pu == NULL )
@@ -801,6 +727,13 @@ void ControlBar::populateBuildQueue( Object *producer )
} // end for
+ //
+ // the panel has MAX_BUILD_QUEUE_BUTTONS windows but the queue can run to 100; when it
+ // overflows, the last cell wears the whole queue's length as its badge
+ //
+ if( pu->getProductionCount() > MAX_BUILD_QUEUE_BUTTONS )
+ GadgetButtonSetCount( m_queueData[ MAX_BUILD_QUEUE_BUTTONS - 1 ].control, pu->getProductionCount() );
+
//
// save the count of things being produced in the build queue, when it changes we will
// repopulate the queue to visually show the change
@@ -841,85 +774,15 @@ void ControlBar::updateContextCommand( void )
ProductionUpdateInterface *pu = obj ? obj->getProductionUpdateInterface() : NULL;
//
- // when we have a production update, we show the build queue when there is actually
- // something in the queue, otherwise we show the selection portrait for the object ... so if
- // the queue is visible we need to check to see if we should hide it and show the portrait,
- // and if the queue is hidden, we need to check and see if it should become shown
+ // the right HUD always belongs to the selection, so the build queue panel is never shown
+ // over it: a unit build button carries its own queue (radial progress, count badge,
+ // right-click cancels the last one) and the producer's world bar shows the rest
//
- if( m_contextParent[ CP_BUILD_QUEUE ]->winIsHidden() == TRUE )
- {
-
- if( pu && pu->firstProduction() != NULL )
- {
-
- // don't show the portrait image
- setPortraitByObject( NULL );
-
- // show the build queue
- m_contextParent[ CP_BUILD_QUEUE ]->winHide( FALSE );
- populateBuildQueue( obj );
-
- } // end if
-
- } // end if
- else
- {
-
- if( pu && pu->firstProduction() == NULL )
- {
-
- // hide the build queue
- m_contextParent[ CP_BUILD_QUEUE ]->winHide( TRUE );
-
- // show the portrait image
- setPortraitByObject( obj );
-
- } // end if
-
- } // end else
-
- // update a visible production queue
if( m_contextParent[ CP_BUILD_QUEUE ]->winIsHidden() == FALSE )
{
-
- // when the build queue is enabled, the selected portrait cannot be shown
- setPortraitByObject( NULL );
-
- //
- // when showing a production queue, when the production count changes of the producer
- // object (the thing we have selected for the control bar) we will repopulate the
- // windows to visually show the new production linup
- //
- if( pu )
- {
-
- // update the whole queue as necessary
- if( pu->getProductionCount() != m_displayedQueueCount )
- populateBuildQueue( obj );
-
- //
- // update the build percentage on the first thing (the thing that's being built)
- // in the queue
- //
- const ProductionEntry *produce = pu->firstProduction();
- if( produce )
- {
- static NameKeyType winID = TheNameKeyGenerator->nameToKey( "ControlBar.wnd:ButtonQueue01" );
- GameWindow *win = TheWindowManager->winGetWindowFromId( m_contextParent[ CP_BUILD_QUEUE ], winID );
-
- DEBUG_ASSERTCRASH( win, ("updateContextCommand: Unable to find first build queue button\n") );
- // UnicodeString text;
- //
- // text.format( L"%.0f%%", produce->getPercentComplete() );
- // GadgetButtonSetText( win, text );
-
- GadgetButtonDrawInverseClock(win,produce->getPercentComplete(), m_buildUpClockColor);
-
- } // end if
-
- } // end if
-
- } // end if
+ m_contextParent[ CP_BUILD_QUEUE ]->winHide( TRUE );
+ setPortraitByObject( obj );
+ }
// evaluate each command on whether or not it should be enabled
for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
@@ -945,6 +808,34 @@ void ControlBar::updateContextCommand( void )
if( command == NULL )
continue;
+ //
+ // a unit build button wears its own queue: a radial fill over the cameo while its unit
+ // is the one being built, and a corner badge with how many of it are queued
+ //
+ if( command->getCommandType() == GUI_COMMAND_UNIT_BUILD && pu )
+ {
+ Int queued = 0;
+ for( const ProductionEntry *p = pu->firstProduction(); p; p = pu->nextProduction( p ) )
+ if( p->getProductionType() == PRODUCTION_UNIT &&
+ p->getProductionObject() == command->getThingTemplate() )
+ queued++;
+ GadgetButtonSetCount( win, queued );
+
+ const ProductionEntry *first = pu->firstProduction();
+ if( first && first->getProductionType() == PRODUCTION_UNIT &&
+ first->getProductionObject() == command->getThingTemplate() )
+ GadgetButtonDrawClock( win, first->getPercentComplete(), BuildClockColor );
+ }
+
+ // a structure outside the armed chord group greys out until the chord resolves
+ if( m_chordGroup >= 0 && command->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT &&
+ ( i < CHORD_GROUP_SIZE ) != ( m_chordGroup == 0 ) )
+ {
+ setCommandBarBorder( win, command->getCommandButtonMappedBorderType() );
+ win->winEnable( FALSE );
+ continue;
+ }
+
// LORENZEN COMMENTED THIS OUT 8/11
// Reason: ExitCameos can be greyed out when the container object gets subdued
@@ -985,7 +876,17 @@ void ControlBar::updateContextCommand( void )
win->winEnable( TRUE );
break;
}
-
+
+ // while a chord is armed, the structures of its group that can be built right now wear
+ // a green border - those are what the next key picks; otherwise the command's own border
+ if( command->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT )
+ {
+ if( m_chordGroup >= 0 && BitTest( win->winGetStatus(), WIN_STATUS_ENABLED ) )
+ GadgetButtonSetBorder( win, GameMakeColor( 60, 255, 60, 255 ), TRUE );
+ else
+ setCommandBarBorder( win, command->getCommandButtonMappedBorderType() );
+ }
+
//Determine by the production type of this button, whether or not the created object
//will have a veterancy rank
if( command->getCommandType() != GUI_COMMAND_EXIT_CONTAINER )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
index 0520bef8b..ba4d1a0ac 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp
@@ -193,16 +193,22 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,
}
//
- // get the object that is driving the context sensitive UI if we're not in a multi
- // select context
+ // get the object that is driving the context sensitive UI. In the multi-select context
+ // that is the focused type's representative - except for unit builds, whose handler
+ // spreads the batch across every selected factory when obj is left NULL
//
Object *obj = NULL;
- if( m_currContext != CB_CONTEXT_MULTI_SELECT &&
- commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE &&
- commandButton->getCommandType() != GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT &&
+ if( commandButton->getCommandType() != GUI_COMMAND_PURCHASE_SCIENCE &&
+ commandButton->getCommandType() != GUI_COMMAND_SPECIAL_POWER_FROM_SHORTCUT &&
commandButton->getCommandType() != GUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT &&
commandButton->getCommandType() != GUI_COMMAND_SELECT_ALL_UNITS_OF_TYPE )
- obj = m_currentSelectedDrawable->getObject();
+ {
+ if( m_currContext != CB_CONTEXT_MULTI_SELECT )
+ obj = m_currentSelectedDrawable->getObject();
+ else if( commandButton->getCommandType() != GUI_COMMAND_UNIT_BUILD &&
+ m_currentSelectedDrawable != NULL )
+ obj = m_currentSelectedDrawable->getObject();
+ }
//@todo Kris -- Special case code so convoy trucks can detonate nuke trucks -- if other things need this,
//rethink it.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp
index 3bae57445..db894c4d3 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarMultiSelect.cpp
@@ -37,6 +37,7 @@
#include "GameClient/GameClient.h"
#include "GameClient/GadgetPushButton.h"
#include "GameClient/GameWindow.h"
+#include "GameClient/GameWindowManager.h"
#include "GameClient/InGameUI.h"
#include "GameLogic/Object.h"
@@ -214,223 +215,241 @@ void ControlBar::addCommonCommands( Drawable *draw, Bool firstDrawable )
//-------------------------------------------------------------------------------------------------
void ControlBar::populateMultiSelect( void )
{
- Drawable *draw;
- Bool firstDrawable = TRUE;
- Bool portraitSet = FALSE;
- const Image *portrait = NULL;
- Object *portraitObj = NULL;
-
- // first reset the common command data
- resetCommonCommandData();
-
- // by default, hide all the controls in the command section
- for( Int i = 0; i < MAX_COMMANDS_PER_SET; i++ )
- {
- if (m_commandWindows[ i ])
- {
- m_commandWindows[ i ]->winHide( TRUE );
- }
- }
// sanity
DEBUG_ASSERTCRASH( TheInGameUI->getSelectCount() > 1,
("populateMultiSelect: Can't populate multiselect context cause there are only '%d' things selected\n",
TheInGameUI->getSelectCount()) );
- // get the list of drawable IDs from the in game UI
- const DrawableList *selectedDrawables = TheInGameUI->getAllSelectedDrawables();
-
- // sanity
- DEBUG_ASSERTCRASH( selectedDrawables->empty() == FALSE, ("populateMultiSelect: Drawable list is empty\n") );
+ //
+ // group the selection by unit type for the right HUD, then let the focused type drive
+ // the whole context: its portrait, its command set (build pages included) and the strip
+ // of type cameos. Tab/Shift-Tab move the focus.
+ //
+ populateMultiSelectUnitList();
- // loop through all the selected drawables
- for( DrawableListCIt it = selectedDrawables->begin();
- it != selectedDrawables->end(); ++it )
- {
-
- // get the drawable
- draw = *it;
+} // end populateMultiSelect
-
- if (draw->getObject()->isKindOf(KINDOF_IGNORED_IN_GUI)) // ignore these guys
- continue;
+//-------------------------------------------------------------------------------------------------
+/** Show what a multi-selection holds in the right HUD: one cameo per selected unit type on the
+ * small strip windows, each with a count badge. Tab/Shift-Tab move the focus between the
+ * types; the focused type gets the portrait window and its cameo is the lit one. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::populateMultiSelectUnitList( void )
+{
+ // remember what was focused - a repopulate (a unit died, a build page turned) should not
+ // yank the player onto another type
+ const ThingTemplate *focusedTemplate = NULL;
+ if( m_multiSelectFocus >= 0 && m_multiSelectFocus < m_multiSelectGroupCount )
+ focusedTemplate = m_multiSelectGroupTemplate[ m_multiSelectFocus ];
- //
- // add command for this drawable, note that we also sanity check to make sure the
- // drawable has an object as all interesting drawables that we can select should
- // actually have an object underneath it so that we can do interesting things with
- // it ... otherwise we should have never selected it.
- // NOTE that we're not considering objects that are currently in the process of
- // being sold as those objects can't be issued anymore commands
- //
- if( draw && draw->getObject() &&
- !draw->getObject()->getStatusBits().test( OBJECT_STATUS_SOLD ) )
- {
+ m_multiSelectGroupCount = 0;
- // add the common commands of this drawable to the common command set
- addCommonCommands( draw, firstDrawable );
+ const DrawableList *selectedDrawables = TheInGameUI->getAllSelectedDrawables();
+ for( DrawableListCIt it = selectedDrawables->begin(); it != selectedDrawables->end(); ++it )
+ {
+ Drawable *draw = *it;
+ Object *obj = draw ? draw->getObject() : NULL;
- // not adding the first drawble anymore
- firstDrawable = FALSE;
+ // same filter the command population uses
+ if( obj == NULL || obj->isKindOf( KINDOF_IGNORED_IN_GUI ) ||
+ obj->getStatusBits().test( OBJECT_STATUS_SOLD ) )
+ continue;
- //
- // keep track of the portrait images, if all units selected have the same portrait
- // we will display it in the right HUD, otherwise we won't
- //
- if( portraitSet == FALSE )
- {
-
- portrait = draw->getTemplate()->getSelectedPortraitImage();
- portraitObj = draw->getObject();
- portraitSet = TRUE;
+ // find this unit's type group, or open a new one
+ const ThingTemplate *thing = draw->getTemplate();
+ Int g;
+ for( g = 0; g < m_multiSelectGroupCount; g++ )
+ if( m_multiSelectGroupTemplate[ g ] == thing )
+ break;
+ if( g == m_multiSelectGroupCount )
+ {
+ // ponytail: MAX_MULTI_SELECT_GROUPS unit types; a selection with more than that
+ // drops the tail types from the display
+ if( m_multiSelectGroupCount >= MAX_MULTI_SELECT_GROUPS )
+ continue;
+ m_multiSelectGroupTemplate[ g ] = thing;
+ m_multiSelectGroupSize[ g ] = 0;
+ m_multiSelectGroupFirst[ g ] = draw->getID();
+ m_multiSelectGroupCount++;
+ }
+ m_multiSelectGroupSize[ g ]++;
- } // end if
- else if( draw->getTemplate()->getSelectedPortraitImage() != portrait )
- portrait = NULL;
+ } // end for, selected drawables
- } // end if
+ // one cell per type, laid out n x n over the right HUD
+ layoutMultiSelectTiles( m_multiSelectGroupCount );
- } // end for, drawble id iterator
+ // stay on the type that was focused if it is still selected
+ Int focus = 0;
+ for( Int g = 0; g < m_multiSelectGroupCount; g++ )
+ if( m_multiSelectGroupTemplate[ g ] == focusedTemplate )
+ focus = g;
- // set the portrait image
- setPortraitByObject( portraitObj );
+ m_multiSelectFocus = focus;
+ setMultiSelectFocus( focus );
-} // end populateMultiSelect
+} // end populateMultiSelectUnitList
//-------------------------------------------------------------------------------------------------
-/** Update logic for the multi select context sensitive GUI */
+/** Focus one type group of the multi-selection: its portrait and count go to the portrait
+ * window, and the strip below shows every group's cameo with the focused one lit */
//-------------------------------------------------------------------------------------------------
-void ControlBar::updateContextMultiSelect( void )
+void ControlBar::setMultiSelectFocus( Int index )
{
- Drawable *draw;
- Object *obj;
- const CommandButton *command;
- GameWindow *win;
- Int objectsThatCanDoCommand[ MAX_COMMANDS_PER_SET ];
- Int i;
- // zero the array that counts how many objects can do each command
- memset( objectsThatCanDoCommand, 0, sizeof( objectsThatCanDoCommand ) );
+ if( m_multiSelectGroupCount == 0 )
+ return;
- // santiy
- DEBUG_ASSERTCRASH( TheInGameUI->getSelectCount() > 1,
- ("updateContextMultiSelect: TheInGameUI only has '%d' things selected\n",
- TheInGameUI->getSelectCount()) );
+ // wrap in both directions
+ m_multiSelectFocus = ( index % m_multiSelectGroupCount + m_multiSelectGroupCount )
+ % m_multiSelectGroupCount;
- // get the list of drawable IDs from the in game UI
- const DrawableList *selectedDrawables = TheInGameUI->getAllSelectedDrawables();
+ Drawable *draw = TheGameClient->findDrawableByID( m_multiSelectGroupFirst[ m_multiSelectFocus ] );
+ Object *obj = draw ? draw->getObject() : NULL;
+ if( obj == NULL )
+ return; // the next selection change repopulates the groups
- // sanity
- DEBUG_ASSERTCRASH( selectedDrawables->empty() == FALSE, ("populateMultiSelect: Drawable list is empty\n") );
+ //
+ // the focused type's representative drives the whole context: the command area shows its
+ // command set (a builder's structure pages included), and updateContextMultiSelect keeps
+ // judging those buttons through the single-selection update
+ //
+ m_currentSelectedDrawable = draw;
+ populateCommand( obj );
- // loop through all the selected drawable IDs
- for( DrawableListCIt it = selectedDrawables->begin();
- it != selectedDrawables->end(); ++it )
- {
-
- // get the drawable from the ID
- draw = *it;
+ // the previous representative's production queue does not belong to this one; the update
+ // re-shows the panel if the new representative is producing
+ m_contextParent[ CP_BUILD_QUEUE ]->winHide( TRUE );
- if (draw->getObject()->isKindOf(KINDOF_IGNORED_IN_GUI)) // ignore these guys
- continue;
+ // ... and the 3x3 type grid in the right HUD
+ updateMultiSelectStrip();
+} // end setMultiSelectFocus
- // get the object
- obj = draw->getObject();
+//-------------------------------------------------------------------------------------------------
+/** Keep the 3x3 unit-type grid of a multi-selection alive. Called every frame: the
+ * single-selection update trades the portrait back and forth with the build queue panel
+ * and setPortraitByObject hides the grid cells, so the multi-select look has to be
+ * re-applied after them. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::updateMultiSelectStrip( void )
+{
- // sanity
- if( obj == NULL )
- continue;
+ if( m_currContext != CB_CONTEXT_MULTI_SELECT || m_multiSelectGroupCount == 0 )
+ return;
- // for each of the visible command windows make sure the object can execute the command
- for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
- {
+ //
+ // a selection of one unit type reads like a single selection: its portrait, upgrade
+ // cameos and all, with how many are selected written on the portrait
+ //
+ if( m_multiSelectGroupCount == 1 )
+ {
+ Drawable *draw = TheGameClient->findDrawableByID( m_multiSelectGroupFirst[ 0 ] );
+ Object *obj = draw ? draw->getObject() : NULL;
+ setPortraitByObject( obj ); // also hides the grid cells
+ if( obj )
+ GadgetButtonSetCount( m_rightHUDCameoWindow, m_multiSelectGroupSize[ 0 ] );
+ return;
+ }
- // get the control window
- win = m_commandWindows[ i ];
+ // the grid replaces the portrait while a mixed multi-selection is up
+ setPortraitByObject( NULL );
- // our implementation doesn't necessarily make use of the max possible command buttons
- if (!win) continue;
+ // one cell per selected type with its count; the focused type is the lit one, the rest
+ // wear the darkened overlay state
+ for( size_t i = 0; i < m_multiSelectTiles.size(); i++ )
+ {
+ GameWindow *win = m_multiSelectTiles[ i ];
+ if( win == NULL )
+ continue;
- // don't consider hidden windows
- if( win->winIsHidden() == TRUE )
- continue;
+ if( (Int)i < m_multiSelectGroupCount )
+ {
+ win->winHide( FALSE );
+ win->winSetEnabledImage( 0, m_multiSelectGroupTemplate[ i ]->getButtonImage() );
+ win->winEnable( (Int)i == m_multiSelectFocus );
+ GadgetButtonSetCount( win, m_multiSelectGroupSize[ i ] );
+ }
+ else
+ win->winHide( TRUE );
+ }
- // get the command
- command = (const CommandButton *)GadgetButtonGetData(win);
- if( command == NULL )
- continue;
+} // end updateMultiSelectStrip
- // can we do the command
- CommandAvailability availability = getCommandAvailability( command, obj, win );
+//-------------------------------------------------------------------------------------------------
+/** Make sure 'count' grid cells exist and lay them out n x n over the right HUD, n the
+ * smallest square that holds them: one type fills the HUD, 2-4 get 2x2, 5-9 get 3x3, and
+ * so on. Cells are plain windows created in code (ControlBar.wnd has none to spare) that
+ * borrow the push button image draw, so cameos, count badges and the darkened disabled
+ * state work. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::layoutMultiSelectTiles( Int count )
+{
+ if( m_rightHUDWindow == NULL || count <= 0 )
+ return;
- win->winClearStatus( WIN_STATUS_NOT_READY );
- win->winClearStatus( WIN_STATUS_ALWAYS_COLOR );
+ Int n = 1;
+ while( n * n < count )
+ n++;
- // enable/disable the window control
- switch( availability )
- {
- case COMMAND_HIDDEN:
- win->winHide( TRUE );
- break;
- case COMMAND_RESTRICTED:
- win->winEnable( FALSE );
- break;
- case COMMAND_NOT_READY:
- win->winEnable( FALSE );
- win->winSetStatus( WIN_STATUS_NOT_READY );
- break;
- case COMMAND_CANT_AFFORD:
- win->winEnable( FALSE );
- win->winSetStatus( WIN_STATUS_ALWAYS_COLOR );
- break;
- default:
- win->winEnable( TRUE );
- break;
- }
+ ICoord2D hudSize;
+ m_rightHUDWindow->winGetSize( &hudSize.x, &hudSize.y );
+ Int cellW = hudSize.x / n;
+ Int cellH = hudSize.y / n;
- //If button is a CHECK_LIKE, then update it's status now.
- if( BitTest( command->getOptions(), CHECK_LIKE ) )
- {
- GadgetCheckLikeButtonSetVisualCheck( win, availability == COMMAND_ACTIVE );
- }
+ for( Int i = 0; i < count; i++ )
+ {
+ if( (Int)m_multiSelectTiles.size() <= i )
+ {
+ GameWindow *tile = TheWindowManager->winCreate( m_rightHUDWindow,
+ WIN_STATUS_ENABLED | WIN_STATUS_USE_OVERLAY_STATES | WIN_STATUS_HIDDEN,
+ 0, 0, cellW, cellH, GameWinDefaultSystem );
+ if( tile )
+ tile->winSetDrawFunc( TheWindowManager->getPushButtonImageDrawFunc() );
+ m_multiSelectTiles.push_back( tile );
+ }
- if( availability == COMMAND_AVAILABLE || availability == COMMAND_ACTIVE )
- objectsThatCanDoCommand[ i ]++;
+ GameWindow *tile = m_multiSelectTiles[ i ];
+ if( tile == NULL )
+ continue;
+ Int col = i % n;
+ Int row = i / n;
+ tile->winSetPosition( col * cellW + 1, row * cellH + 1 );
+ tile->winSetSize( cellW - 2, cellH - 2 );
+ }
- } // end for i
+} // end layoutMultiSelectTiles
- } // end for, selected drawables
+//-------------------------------------------------------------------------------------------------
+/** Tab (+1) / Shift-Tab (-1): walk the focus through the multi-selected units */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::cycleMultiSelectFocus( Int direction )
+{
- //
- // for each command, if any objects can do the command we enable the window, otherwise
- // we disable it
- //
- for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )
- {
- // our implementation doesn't necessarily make use of the max possible command buttons
- if (! m_commandWindows[ i ]) continue;
+ if( m_currContext != CB_CONTEXT_MULTI_SELECT )
+ return;
- // don't consider hidden commands
- if( m_commandWindows[ i ]->winIsHidden() == TRUE )
- continue;
+ setMultiSelectFocus( m_multiSelectFocus + direction );
- // don't consider slots that don't have commands
- if( m_commonCommands[ i ] == NULL )
- continue;
-
- // check the count of objects that can do the command and enable/disable the control,
- if( objectsThatCanDoCommand[ i ] > 0 )
- m_commandWindows[ i ]->winEnable( TRUE );
- else
- m_commandWindows[ i ]->winEnable( FALSE );
+} // end cycleMultiSelectFocus
+
+//-------------------------------------------------------------------------------------------------
+/** Update logic for the multi select context sensitive GUI. The command area mirrors the
+ * focused type's representative, so the single-selection update does all the work:
+ * availability, build queue panel, reload clocks, queue count badges. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::updateContextMultiSelect( void )
+{
- } // end for i
+ // the representative can die between the deselect event and the UI re-evaluation
+ if( m_currentSelectedDrawable == NULL || m_currentSelectedDrawable->getObject() == NULL )
+ return;
- // After Every change to the m_commandWIndows, we need to show fill in the missing blanks with the images
- // removed from multiplayer branch
- //showCommandMarkers();
+ updateContextCommand();
+ // the update may have traded the portrait for a build queue - keep the type strip alive
+ updateMultiSelectStrip();
} // end updateContextMultiSelect
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp
index e18a06e3a..94af9723d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/Gadget/GadgetPushButton.cpp
@@ -607,10 +607,28 @@ PushButtonData * getNewPushButtonData( void )
p->userData = NULL;
p->drawBorder = FALSE;
p->drawClock = NO_CLOCK;
+ p->drawCount = 0;
p->overlayImage = NULL;
return p;
}
+// GadgetButtonSetCount =======================================================
+/** Set the number badge drawn in the button's bottom right corner, 0 for none */
+//=============================================================================
+void GadgetButtonSetCount( GameWindow *g, Int count )
+{
+ if( g == NULL )
+ return;
+
+ PushButtonData *pData = (PushButtonData *)g->winGetUserData();
+ if(!pData)
+ {
+ pData = getNewPushButtonData();
+ }
+ pData->drawCount = count;
+ g->winSetUserData(pData);
+}
+
// GadgetButtonSetBorder ======================================================
/** Set to draw the special borders in the game */
//=============================================================================
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 2a0f9a1a6..deeca453d 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -2630,6 +2630,21 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
break;
} // end command bar grid slots
+ case GameMessage::MSG_META_SHORTCUT_SLOT01:
+ case GameMessage::MSG_META_SHORTCUT_SLOT02:
+ case GameMessage::MSG_META_SHORTCUT_SLOT03:
+ case GameMessage::MSG_META_SHORTCUT_SLOT04:
+ case GameMessage::MSG_META_SHORTCUT_SLOT05:
+ case GameMessage::MSG_META_SHORTCUT_SLOT06:
+ case GameMessage::MSG_META_SHORTCUT_SLOT07:
+ case GameMessage::MSG_META_SHORTCUT_SLOT08:
+ {
+ // the general's power shortcut bar, one key per visible button
+ TheControlBar->pressSpecialPowerShortcut( t - GameMessage::MSG_META_SHORTCUT_SLOT01 );
+ disp = DESTROY_MESSAGE;
+ break;
+ } // end special power shortcut slots
+
case GameMessage::MSG_META_SELECT_NEXT_WORKER:
{
/* because list is prepended, iterate through backwards */
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index 0977cfc78..cd17eed22 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -37,6 +37,7 @@
#include "Common/Team.h"
#include "Common/ThingTemplate.h"
+#include "GameClient/ControlBar.h"
#include "GameClient/Drawable.h"
#include "GameClient/Mouse.h"
#include "GameClient/GameClient.h"
@@ -153,6 +154,14 @@ static const LookupListRec GameMessageMetaTypeNames[] =
{ "COMMAND_SLOT12", GameMessage::MSG_META_COMMAND_SLOT12 },
{ "COMMAND_SLOT13", GameMessage::MSG_META_COMMAND_SLOT13 },
{ "COMMAND_SLOT14", GameMessage::MSG_META_COMMAND_SLOT14 },
+ { "SHORTCUT_SLOT01", GameMessage::MSG_META_SHORTCUT_SLOT01 },
+ { "SHORTCUT_SLOT02", GameMessage::MSG_META_SHORTCUT_SLOT02 },
+ { "SHORTCUT_SLOT03", GameMessage::MSG_META_SHORTCUT_SLOT03 },
+ { "SHORTCUT_SLOT04", GameMessage::MSG_META_SHORTCUT_SLOT04 },
+ { "SHORTCUT_SLOT05", GameMessage::MSG_META_SHORTCUT_SLOT05 },
+ { "SHORTCUT_SLOT06", GameMessage::MSG_META_SHORTCUT_SLOT06 },
+ { "SHORTCUT_SLOT07", GameMessage::MSG_META_SHORTCUT_SLOT07 },
+ { "SHORTCUT_SLOT08", GameMessage::MSG_META_SHORTCUT_SLOT08 },
{ "SELECT_HERO", GameMessage::MSG_META_SELECT_HERO },
{ "SELECT_ALL", GameMessage::MSG_META_SELECT_ALL },
{ "SELECT_ALL_AIRCRAFT", GameMessage::MSG_META_SELECT_ALL_AIRCRAFT },
@@ -457,6 +466,39 @@ GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessa
newModState |= ALT;
}
+ //
+ // a half-typed structure chord (Q or W pressed on a builder) takes the next plain key:
+ // Q A W S E D R F pick the cell, anything else drops the chord and goes on as usual
+ //
+ if( t == GameMessage::MSG_RAW_KEY_DOWN && ( newModState & ( CTRL | ALT ) ) == 0 &&
+ !( keyState & KEY_STATE_AUTOREPEAT ) &&
+ TheControlBar && TheControlBar->isChordArmed() &&
+ !( TheShell && TheShell->isShellActive() ) )
+ {
+ if( TheControlBar->handleChordKey( key ) )
+ {
+ m_lastModState = newModState;
+ return DESTROY_MESSAGE;
+ }
+ }
+
+ //
+ // Tab / Shift-Tab walks the focus through a multi-selection's units on the control bar.
+ // Handled here rather than through the MetaMap because CommandMap.ini lives in the
+ // shipped game data and has no slot for it.
+ //
+ if( t == GameMessage::MSG_RAW_KEY_DOWN && key == MK_TAB &&
+ ( newModState & ( CTRL | ALT ) ) == 0 &&
+ !( keyState & KEY_STATE_AUTOREPEAT ) &&
+ TheGameClient->getFrame() >= 1 &&
+ !( TheShell && TheShell->isShellActive() ) &&
+ TheInGameUI && TheInGameUI->getSelectCount() > 1 &&
+ TheControlBar )
+ {
+ TheControlBar->cycleMultiSelectFocus( ( newModState & SHIFT ) ? -1 : 1 );
+ m_lastModState = newModState;
+ return DESTROY_MESSAGE;
+ }
for (const MetaMapRec *map = TheMetaMap->getFirstMetaMapRec(); map; map = map->m_next)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
index 64b40aabe..b8475e9cc 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/PlaceEventTranslator.cpp
@@ -27,6 +27,8 @@
#include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
+#include "GameClient/Keyboard.h"
+
#include "Common/BuildAssistant.h"
#include "Common/GameAudio.h"
#include "Common/Player.h"
@@ -286,8 +288,12 @@ GameMessageDisposition PlaceEventTranslator::translateGameMessage(const GameMess
pickAndPlayUnitVoiceResponse( TheInGameUI->getAllSelectedDrawables(), placeMsg->getType() );
- // get out of pending placement mode, this will also clear the arrow anchor status
- TheInGameUI->placeBuildAvailable( NULL, NULL );
+ // get out of pending placement mode, this will also clear the arrow anchor status -
+ // unless shift is held, which keeps placing the same structure until released
+ if( TheKeyboard && TheKeyboard->isShift() && builderObj && builderObj->getDrawable() )
+ TheInGameUI->placeBuildAvailable( build, builderObj->getDrawable() );
+ else
+ TheInGameUI->placeBuildAvailable( NULL, NULL );
} // end if, location legal to build at
else
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
index 0bfba66e2..f2f3b1039 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
@@ -53,6 +53,7 @@
#include "GameClient/GameWindowManager.h"
#include "GameClient/GadgetPushButton.h"
#include "GameClient/Display.h"
+#include "GameClient/DisplayStringManager.h"
#include "W3DDevice/GameClient/W3DGameWindow.h"
#include "W3DDevice/GameClient/W3DDisplay.h"
#include "W3DDevice/GameClient/W3DGadget.h"
@@ -151,6 +152,46 @@ static void drawButtonText( GameWindow *window, WinInstanceData *instData )
} // end drawButtonText
+// drawCountBadge =============================================================
+/** Draw a small number badge in the button's bottom right corner (queued unit
+ * counts, selection sizes). One shared DisplayString serves every button. */
+//=============================================================================
+static void drawCountBadge( GameWindow *window, Int count )
+{
+ static DisplayString *badge = NULL;
+ ICoord2D origin, size, textPos;
+ Int width, height;
+
+ if( badge == NULL )
+ {
+ badge = TheDisplayStringManager->newDisplayString();
+ if( badge == NULL )
+ return;
+ }
+
+ UnicodeString text;
+ text.format( L"%d", count );
+ badge->setText( text );
+
+ if( badge->getFont() != window->winGetFont() )
+ badge->setFont( window->winGetFont() );
+
+ window->winGetScreenPosition( &origin.x, &origin.y );
+ window->winGetSize( &size.x, &size.y );
+ badge->getSize( &width, &height );
+
+ textPos.x = origin.x + size.x - width - 3;
+ textPos.y = origin.y + size.y - height - 1;
+
+ // same translucent plate the shortcut letter wears - button art can be any colour
+ TheDisplay->drawFillRect( textPos.x - 2, textPos.y, width + 4, height,
+ GameMakeColor( 0, 0, 0, 160 ) );
+ badge->draw( textPos.x, textPos.y, GameMakeColor( 255, 255, 255, 255 ),
+ GameMakeColor( 0, 0, 0, 255 ) );
+
+} // end drawCountBadge
+
+
///////////////////////////////////////////////////////////////////////////////
// PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////
@@ -282,6 +323,9 @@ void W3DGadgetPushButtonDraw( GameWindow *window, WinInstanceData *instData )
{
TheDisplay->drawOpenRect(origin.x -1, origin.y - 1, size.x + 2, size.y + 2,1 , pData->colorBorder);
}
+
+ if( pData->drawCount > 0 )
+ drawCountBadge( window, pData->drawCount );
}
} // end W3DGadgetPushButtonDraw
@@ -449,10 +493,13 @@ void W3DGadgetPushButtonImageDrawOne( GameWindow *window,
if( pData->drawBorder && pData->colorBorder != GAME_COLOR_UNDEFINED )
{
-
+
TheDisplay->drawOpenRect(start.x - 1, start.y - 1, size.x + 2, size.y + 2, 1, pData->colorBorder);
}
+
+ if( pData->drawCount > 0 )
+ drawCountBadge( window, pData->drawCount );
}
//Now render overlays that pertain to the correct state.
@@ -710,5 +757,8 @@ void W3DGadgetPushButtonImageDrawThree(GameWindow *window, WinInstanceData *inst
{
TheDisplay->drawOpenRect(start.x - 1, start.y - 1, size.x + 2, size.y + 2, 1, pData->colorBorder);
}
+
+ if( pData->drawCount > 0 )
+ drawCountBadge( window, pData->drawCount );
}
}