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(gameengine): two-key general power shortcuts on a wrapped bar

Olcay Seyganbb85e582dd78
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e8bf29209..3715afdc4 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -281,6 +281,7 @@ found and fixed — EA's own, not port damage.**
- A superweapon's wait is written in plain seconds - 200, not 3:20 - so it compares with every other countdown on the screen at a glance. Once it is charged the number goes away entirely and the picture itself breathes in your colour, which is the one thing you want to catch out of the corner of your eye.
- The countdown inside a strip picture lost its black backing plate. On a picture that small the plate was most of the picture; the number now sits straight on the sweeping clock.
- A game opens with nothing selected, so your first click is not a rally point.
+- Your general's powers no longer climb the right hand edge of the screen. They sit three abreast, filling from the bottom corner where the first one has always been and wrapping upward, so a general holding eleven of them still reads as a block instead of a ladder from the radar to the sky. The keys follow the same shape: the first press picks a row, the second picks the power in it, so every power is two keys away - F1 F1 for the one in the corner, F2 F1 for the row above it. Only the keys you can press next are written on the pictures, so you are never reading eleven labels to find one, and Escape drops a row you thought better of - so does clicking a power with the mouse, and so does a couple of seconds' pause, so a key hit by mistake in a fight never turns your next one into a superweapon. Rows with nothing in them yet cannot be picked at all: early on, when you hold three powers, only the row you have answers a key.
- The tilde key opens the general's promotions.
- `S` stops your units again; the key was simply never bound.
- Every button carries its build, research or cooldown time in the corner.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index 3fcb07c63..eab53b17e 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -420,6 +420,7 @@ enum {
enum { MAX_STRUCTURE_INVENTORY_BUTTONS = 10 }; // there are this many physical buttons in "inventory" windows for structures
enum { MAX_BUILD_QUEUE_BUTTONS = 9 };// physical button count for the build queue
enum { MAX_SPECIAL_POWER_SHORTCUTS = 11};
+enum { SPECIAL_POWER_SHORTCUT_COLS = 3 }; ///< general's powers side by side in one row; the rest wrap upward
class CommandSet : public Overridable
{
@@ -694,10 +695,17 @@ 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. */
+ /** The general's powers are laid out SPECIAL_POWER_SHORTCUT_COLS to a row, so one key press
+ cannot reach eleven of them. The first press picks a row (F1 is the row in the corner,
+ F2 the one above it) and the second picks a power inside that row (F1 is the rightmost),
+ which puts every power two keystrokes away: F1-F1, F2-F1, F2-F3. This is what the
+ SHORTCUT_SLOTnn keys are wired to. */
void pressSpecialPowerShortcut( Int index );
+ /** forget a half-finished row-then-power keystroke, so the next key picks a row again.
+ TRUE when there was one to forget. */
+ Bool clearSpecialPowerShortcutRow( void );
+
/** 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 - 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, ...)
@@ -935,6 +943,8 @@ protected:
void populateSpecialPowerShortcut( Player *player);
void updateSpecialPowerShortcut( void );
+ void arrangeSpecialPowerShortcutGrid( void ); ///< re-lay the layout's single column as rows of SPECIAL_POWER_SHORTCUT_COLS
+ Int countVisibleSpecialPowerShortcuts( void ); ///< how many slots carry a power right now, which is not the command set's size
static const Image* calculateVeterancyOverlayForThing( const ThingTemplate *thingTemplate );
static const Image* calculateVeterancyOverlayForObject( const Object *obj );
@@ -995,6 +1005,8 @@ protected:
GameWindow *m_specialPowerShortcutButtonParents[ MAX_SPECIAL_POWER_SHORTCUTS ];
DisplayString *m_shortcutDisplayStrings[ MAX_SPECIAL_POWER_SHORTCUTS ];
Int m_currentlyUsedSpecialPowersButtons; ///< Value will be <= MAX_SPECIAL_POWER_SHORTCUTS;
+ Int m_specialPowerShortcutRow; ///< row a first key press picked, -1 when none is pending
+ UnsignedInt m_specialPowerShortcutRowMs; ///< millisecond that row was picked on, for CHORD_TIMEOUT_MS
WindowLayout *m_specialPowerLayout;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 1331fd286..d0aacc0d0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -1088,6 +1088,8 @@ ControlBar::ControlBar( void )
}
m_specialPowerShortcutParent = NULL;
+ m_specialPowerShortcutRow = -1;
+ m_specialPowerShortcutRowMs = 0;
m_specialPowerLayout = NULL;
m_scienceLayout = NULL;
m_rightHUDWindow = NULL;
@@ -1644,6 +1646,24 @@ void ControlBar::update( void )
if( nowShowing != m_chordDrawableID )
dropChord();
}
+
+ //
+ // a general's power row goes the same way: it expires on its own, and it drops the moment the
+ // bar it was picked against is off screen - hidden with the command bar, animated out, or
+ // repopulated with fewer powers than the row names. Otherwise a key pressed in a hurry and
+ // then thought better of sits armed, and the next one fires a power instead of picking a row
+ //
+ if( m_specialPowerShortcutRow >= 0 )
+ {
+ const Int visibleRows = ( countVisibleSpecialPowerShortcuts() + SPECIAL_POWER_SHORTCUT_COLS - 1 )
+ / SPECIAL_POWER_SHORTCUT_COLS;
+ if( timeGetTime() - m_specialPowerShortcutRowMs > CHORD_TIMEOUT_MS
+ || m_specialPowerShortcutParent == NULL
+ || m_specialPowerShortcutParent->winIsHidden()
+ || m_specialPowerShortcutRow >= visibleRows )
+ clearSpecialPowerShortcutRow();
+ }
+
if(m_controlBarSchemeManager)
m_controlBarSchemeManager->update();
@@ -2425,6 +2445,13 @@ CBCommandStatus ControlBar::processContextSensitiveButtonClick( GameWindow *butt
GadgetGameMessage gadgetMessage )
{
+ //
+ // clicking anything on the bar ends a half-typed general's power row - the player has clearly
+ // moved on, and the keys go back to picking rows instead of one of them firing a power. The
+ // keyboard path spends its own row before it sends this, so it is already clear by here
+ //
+ clearSpecialPowerShortcutRow();
+
//
// The right button only ever takes things back out of a queue - the build queue panel no
// longer sits in the right HUD to click on. It never runs the command: firing a build or a
@@ -2613,12 +2640,76 @@ Drawable *ControlBar::findStandInBuilder( Bool freeOnly )
//-------------------------------------------------------------------------------------------------
/** Press the index'th general's power shortcut button, as a mouse click would */
//-------------------------------------------------------------------------------------------------
+Bool ControlBar::clearSpecialPowerShortcutRow( void )
+{
+ if( m_specialPowerShortcutRow < 0 )
+ return FALSE;
+
+ m_specialPowerShortcutRow = -1;
+ m_specialPowerShortcutRowMs = 0;
+ return TRUE;
+
+} // end clearSpecialPowerShortcutRow
+
+//-------------------------------------------------------------------------------------------------
+/** How many of the slots carry a power right now. populateSpecialPowerShortcut() fills them from
+ * the corner and hides the rest, so the ones in use are always the first n - and n is not
+ * m_currentlyUsedSpecialPowersButtons, which is how many the general's command set holds in all. */
+//-------------------------------------------------------------------------------------------------
+Int ControlBar::countVisibleSpecialPowerShortcuts( void )
+{
+ Int count = 0;
+ for( Int i = 0; i < m_currentlyUsedSpecialPowersButtons && i < MAX_SPECIAL_POWER_SHORTCUTS; i++ )
+ {
+ GameWindow *win = m_specialPowerShortcutButtons[ i ];
+ if( win == NULL || win->winIsHidden() )
+ break;
+ count++;
+ }
+ return count;
+
+} // end countVisibleSpecialPowerShortcuts
+
+//-------------------------------------------------------------------------------------------------
+/** One key cannot reach eleven powers laid out three to a row, so it takes two: the first press
+ * picks the row - F1 the row in the corner, F2 the one above it - and the second picks the power
+ * in it, F1 being the rightmost. Until a row is picked only the head of each row is labelled,
+ * with the key that picks that row; once one is, the labels move onto its three powers. */
+//-------------------------------------------------------------------------------------------------
void ControlBar::pressSpecialPowerShortcut( Int index )
{
- if( index < 0 || index >= m_currentlyUsedSpecialPowersButtons || m_specialPowerShortcutParent == NULL )
+ if( index < 0 || m_specialPowerShortcutParent == NULL || m_specialPowerShortcutParent->winIsHidden() )
+ return;
+
+ //
+ // what the keys can reach is what is on screen, not the size of the command set the general
+ // could eventually fill: a USA player with three powers has one row, and arming the second
+ // one would swallow the key after it with nothing to spend it on
+ //
+ const Int visible = countVisibleSpecialPowerShortcuts();
+ const Int rows = ( visible + SPECIAL_POWER_SHORTCUT_COLS - 1 ) / SPECIAL_POWER_SHORTCUT_COLS;
+
+ // nothing pending: this press names a row and stops there
+ if( m_specialPowerShortcutRow < 0 )
+ {
+ if( index < rows )
+ {
+ m_specialPowerShortcutRow = index;
+ m_specialPowerShortcutRowMs = timeGetTime();
+ }
+ return;
+ }
+
+ //
+ // a row is pending: this press names the power in it, and either way the row is spent - a key
+ // that names no power in that row simply cancels
+ //
+ const Int slot = m_specialPowerShortcutRow * SPECIAL_POWER_SHORTCUT_COLS + index;
+ clearSpecialPowerShortcutRow();
+ if( index >= SPECIAL_POWER_SHORTCUT_COLS || slot >= visible )
return;
- GameWindow *win = m_specialPowerShortcutButtons[ index ];
+ GameWindow *win = m_specialPowerShortcutButtons[ slot ];
if( win == NULL || win->winIsHidden() || m_specialPowerShortcutParent->winIsHidden() )
return;
@@ -3935,10 +4026,113 @@ void ControlBar::initSpecialPowershortcutBar( Player *player)
windowName.format( parentName, i+1 );
id = TheNameKeyGenerator->nameToKey( windowName.str() );
- m_specialPowerShortcutButtonParents[ i ] =
+ m_specialPowerShortcutButtonParents[ i ] =
TheWindowManager->winGetWindowFromId( m_specialPowerShortcutParent, id );
} // end for i
+ arrangeSpecialPowerShortcutGrid();
+
+}
+
+//-------------------------------------------------------------------------------------------------
+/** The shipped layout is one slot wide and eleven tall, so a general late in a game runs his powers
+ * from the radar all the way to the top of the screen - a column nobody can take in at a glance.
+ * The same slots are re-laid here as rows of SPECIAL_POWER_SHORTCUT_COLS, filling right to left
+ * and then upward, so the first shortcut keeps the corner it has always been in and the bar grows
+ * sideways instead of climbing.
+ *
+ * Every measurement is read back off the layout - each side ships its own bar, and the loader has
+ * already scaled it to the running resolution - so nothing here is in 800x600 pixels. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::arrangeSpecialPowerShortcutGrid( void )
+{
+ if( m_specialPowerShortcutParent == NULL || m_currentlyUsedSpecialPowersButtons < 2 )
+ return;
+
+ //
+ // the two lowest slots give the step the artwork was drawn with: the column runs upward, so
+ // the second slot sits above the first and the difference is one row
+ //
+ Int firstX, firstY, secondX, secondY, slotWidth, slotHeight;
+ m_specialPowerShortcutButtonParents[ 0 ]->winGetPosition( &firstX, &firstY );
+ m_specialPowerShortcutButtonParents[ 1 ]->winGetPosition( &secondX, &secondY );
+ m_specialPowerShortcutButtonParents[ 0 ]->winGetSize( &slotWidth, &slotHeight );
+
+ const Int rowStep = firstY - secondY;
+ if( rowStep <= 0 || slotWidth <= 0 || slotHeight <= 0 )
+ return;
+
+ //
+ // where the cameo goes is the hole in the tray artwork, not a guess: SATraySmall is the 60x56
+ // patch at 413,1 of SAControlBar512_001.tga and its transparent middle runs x 4..48, y 9..46.
+ // Those are fractions of the art, so they hold at whatever size the loader gave the tray
+ //
+ const Int ART_WIDTH = 60;
+ const Int ART_HEIGHT = 56;
+ const Int HOLE_X = 4;
+ const Int HOLE_Y = 9;
+ const Int HOLE_WIDTH = 45;
+ const Int HOLE_HEIGHT = 38;
+
+ //
+ // the tray's right edge is the thick one - eleven of the artwork's sixty columns. A row set
+ // side by side shows that slab between every pair of cameos, so each slot after the rightmost
+ // slides eight (of the tray's authored forty-eight) back under its neighbour, and the rightmost
+ // is drawn last so it covers the slab rather than being covered by it
+ //
+ const Int TRAY_WIDTH = 48;
+ const Int OVERLAP = 8;
+ const Int columnStep = slotWidth - ( slotWidth * OVERLAP ) / TRAY_WIDTH;
+
+ const Int columns = MIN( m_currentlyUsedSpecialPowersButtons, (Int)SPECIAL_POWER_SHORTCUT_COLS );
+ const Int widen = ( columns - 1 ) * columnStep;
+
+ //
+ // the bar itself has to cover the columns we are adding. winPointInChild only descends into
+ // the children of a window the cursor is already inside, so a button hanging off the left edge
+ // of its parent would draw fine and never take a click.
+ //
+ Int barX, barY, barWidth, barHeight;
+ m_specialPowerShortcutParent->winGetPosition( &barX, &barY );
+ m_specialPowerShortcutParent->winGetSize( &barWidth, &barHeight );
+ m_specialPowerShortcutParent->winSetSize( barWidth + widen, barHeight );
+ m_specialPowerShortcutParent->winSetPosition( barX - widen, barY );
+
+ //
+ // slot positions are relative to that bar, so widening it to the left moves every slot right by
+ // the same amount first: the rightmost column has to land back where the old column stood
+ //
+ for( Int i = 0; i < MAX_SPECIAL_POWER_SHORTCUTS; i++ )
+ {
+ GameWindow *slot = m_specialPowerShortcutButtonParents[ i ];
+ GameWindow *button = m_specialPowerShortcutButtons[ i ];
+ if( slot == NULL || button == NULL )
+ continue;
+
+ const Int column = i % SPECIAL_POWER_SHORTCUT_COLS;
+ const Int row = i / SPECIAL_POWER_SHORTCUT_COLS;
+
+ slot->winSetPosition( firstX + widen - column * columnStep, firstY - row * rowStep );
+
+ //
+ // the cameo fills that hole exactly, rounded to the nearest pixel. The layout put it at
+ // 1,7 39x27, which sat over the frame on the left and left a gap under it
+ //
+ button->winSetSize( ( slotWidth * HOLE_WIDTH + ART_WIDTH / 2 ) / ART_WIDTH,
+ ( slotHeight * HOLE_HEIGHT + ART_HEIGHT / 2 ) / ART_HEIGHT );
+ button->winSetPosition( ( slotWidth * HOLE_X + ART_WIDTH / 2 ) / ART_WIDTH,
+ ( slotHeight * HOLE_Y + ART_HEIGHT / 2 ) / ART_HEIGHT );
+ }
+
+ //
+ // children draw from the tail of the list back to the head, so the head is the one on top.
+ // Bringing them to the top in reverse leaves slot 1 at the head and the order running down
+ // the list from there: in a row the slot to the right covers the one to its left, and the row
+ // nearest the corner covers the row above it.
+ //
+ for( Int j = MAX_SPECIAL_POWER_SHORTCUTS - 1; j >= 0; j-- )
+ if( m_specialPowerShortcutButtonParents[ j ] )
+ m_specialPowerShortcutButtonParents[ j ]->winBringToTop();
}
//-------------------------------------------------------------------------------------------------
@@ -3961,6 +4155,9 @@ void ControlBar::populateSpecialPowerShortcut( Player *player)
{
const CommandSet *commandSet;
Int i;
+
+ // the bar is being rebuilt, so a row picked against the old one means nothing
+ clearSpecialPowerShortcutRow();
if(!player || !player->getPlayerTemplate()
|| !player->isLocalPlayer() || m_currentlyUsedSpecialPowersButtons == 0
|| m_specialPowerShortcutButtons == NULL || m_specialPowerShortcutButtonParents == NULL)
@@ -4362,12 +4559,25 @@ void ControlBar::drawSpecialPowerShortcutMultiplierText()
// 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;
- // the bar holds MAX_SPECIAL_POWER_SHORTCUTS buttons, but only eight SHORTCUT_SLOT meta
- // events existed, so slots 9-11 could never be labelled or bound. They have events now;
- // whether they carry a key is up to CommandMap.ini, and getMetaKeyLabel returns empty
- // for an unbound one.
- if( i < MAX_SPECIAL_POWER_SHORTCUTS )
- text = getMetaKeyLabel( (GameMessage::Type)(GameMessage::MSG_META_SHORTCUT_SLOT01 + i) );
+
+ //
+ // a power takes two keys, so only the half of them that the next press can reach is
+ // labelled: with no row pending that is the head of each row, carrying the key that
+ // picks the row; with one pending it is that row's powers, carrying their own keys.
+ // Which key a slot number means is up to CommandMap.ini - getMetaKeyLabel returns
+ // nothing for an unbound one.
+ //
+ Int keySlot = -1;
+ if( m_specialPowerShortcutRow < 0 )
+ {
+ if( i % SPECIAL_POWER_SHORTCUT_COLS == 0 )
+ keySlot = i / SPECIAL_POWER_SHORTCUT_COLS;
+ }
+ else if( i / SPECIAL_POWER_SHORTCUT_COLS == m_specialPowerShortcutRow )
+ keySlot = i % SPECIAL_POWER_SHORTCUT_COLS;
+
+ if( keySlot >= 0 && keySlot < MAX_SPECIAL_POWER_SHORTCUTS )
+ text = getMetaKeyLabel( (GameMessage::Type)(GameMessage::MSG_META_SHORTCUT_SLOT01 + keySlot) );
const SpecialPowerTemplate *spTemplate = command->getSpecialPowerTemplate();
Int numReady = 0;
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 0606fa3a9..be10aab4b 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -3231,6 +3231,10 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
cancelledSomething = TRUE;
}
+ // a general's power row picked but not yet spent goes the same way
+ if( TheControlBar && TheControlBar->clearSpecialPowerShortcutRow() )
+ cancelledSomething = TRUE;
+
if( TheInGameUI->getPendingPlaceType() != NULL )
{
TheInGameUI->placeBuildAvailable( NULL, NULL );