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): make the grid the command bar's only keyboard

Olcay Seygan2edb4bda13d9
diff --git a/CHANGELOG.md b/CHANGELOG.md
index d6107d34e..22a45c919 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -319,6 +319,8 @@ found and fixed — EA's own, not port damage.**
- Two buildings can no longer be put down on the same spot online. A build order travels to the other players before anything appears on the ground, and every click made while it was in flight was answered by a map that still showed the square as empty - so a shift-held row on a bad connection came out as buildings standing inside each other. The ghost now knows about the orders you have already spent, and turns red over them or slides to the square beside; and the order itself is checked again where it lands, on every machine, after the first building is standing. A second one aimed at the same ground is refused there and costs you nothing.
- A click clears a half-typed building shortcut.
- The two-key building shortcut survives the command bar's redraw now.
+- Every structure is those two keys and nothing else. The letter written on a cell is the second half of its pair, and pressed on its own it used to build whatever sat in the slot that letter names - so the same barracks went up either by the shortcut painted on it or by one bare key nobody had written anywhere, and a key pressed after a shortcut you had thought better of put a building on your cursor. And the pairs are read off the key bindings now instead of a list written out beside them: the second letters had been left behind when the bottom row of the command bar moved to Z X C V B N M, so half the cells answered a letter that was not on them.
+- The command bar is driven by its own grid of keys - the buttons in the shape they are in, under your left hand - and there is no longer a switch for it. It shipped off by default, which meant nobody ever saw it.
- Escape cancels what you were doing before it opens the menu.
## Where the money is, and where it is coming from
diff --git a/GeneralsMD/Code/Data/INI/CommandMap.ini b/GeneralsMD/Code/Data/INI/CommandMap.ini
index 29bd1ee95..543263b6b 100644
--- a/GeneralsMD/Code/Data/INI/CommandMap.ini
+++ b/GeneralsMD/Code/Data/INI/CommandMap.ini
@@ -11,9 +11,9 @@
; binding this fork adds or moves lives here; KEYMAP.md is the readable
; version of the same table.
;
-; Grid command bar (GlobalData UseGridHotKeys / Options.ini UseGridHotKeys = yes):
-; the command bar is 7 columns x 2 rows and the keys sit under the left hand in
-; the same shape.
+; Grid command bar, which is how the bar is driven - there is no other scheme and
+; no switch: the command bar is 7 columns x 2 rows and the keys sit under the
+; left hand in the same shape.
;
; slot 01 03 05 07 09 11 13 (top row) Q W E R T Y U
; slot 02 04 06 08 10 12 14 (bottom row) Z X C V B N M
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index f528a4596..328ceb35c 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -331,7 +331,6 @@ public:
Real m_scrollAmountCutoff; ///< Scroll speed to not adjust camera height
Real m_cameraAdjustSpeed; ///< Rate at which we adjust camera height
Bool m_enforceMaxCameraHeight; ///< Enfoce max camera height while scrolling?
- Bool m_useGridHotKeys; ///< command bar keys come from the slot grid, not the '&' letter in each button's label
Bool m_edgeScrollInWindowedMode; ///< allow screen-edge scrolling while running in a window
Bool m_snapBuildPlacementTo45; ///< quantize the drag-to-rotate build placement angle to 45 degrees
Bool m_snapCameraRotateTo45; ///< quantize the camera heading to 45 degrees when a middle-drag rotate ends
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
index 4575dc78c..02a793366 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
@@ -107,7 +107,6 @@ public:
Int getStaticGameDetail(void); // detail level selected by the user.
Int getIdealStaticGameDetail(void); // detail level detected for user.
Real getGammaValue(void);
- Bool getUseGridHotKeys(void);
Bool getEdgeScrollInWindowedMode(void);
Bool getSnapBuildPlacementTo45(void);
Bool getSnapCameraRotateTo45(void);
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index 88d5bf8db..8f62deb4f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -742,13 +742,14 @@ public:
(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 */
+ /** a raw key while a chord is armed: the key of one of the group's own cells (the grid's
+ slots 0..7 - Q Z W X E C R V as shipped) 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; }
- /** forget a half-typed chord. An armed chord swallows the next A S D F - attack move, stop -
- and turns it into a structure to place, so anything that says the player has moved on
+ /** forget a half-typed chord. An armed chord swallows the next grid key and turns it into
+ a structure to place, so anything that says the player has moved on
(a click, a new selection, a key that is not part of the chord, or simply time passing)
must drop it. */
void dropChord( void );
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
index 441f5fd65..551929c00 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
@@ -362,8 +362,6 @@ void GameLODManager::init(void)
// Camera zoom-out is deliberately not settable here: how much of the battlefield you can see
// is a competitive advantage, so it stays at the GameData.ini value for everyone.
- // Grid command-bar keys are an input scheme, not a detail level either.
- TheWritableGlobalData->m_useGridHotKeys = optionPref.getUseGridHotKeys();
TheWritableGlobalData->m_edgeScrollInWindowedMode = optionPref.getEdgeScrollInWindowedMode();
TheWritableGlobalData->m_snapBuildPlacementTo45 = optionPref.getSnapBuildPlacementTo45();
TheWritableGlobalData->m_snapCameraRotateTo45 = optionPref.getSnapCameraRotateTo45();
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index ed6ef43cb..76ed08e19 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -186,7 +186,6 @@ GlobalData* GlobalData::m_theOriginal = NULL;
{ "CameraYaw", INI::parseReal, NULL, offsetof( GlobalData, m_cameraYaw ) },
{ "CameraHeight", INI::parseReal, NULL, offsetof( GlobalData, m_cameraHeight ) },
{ "MaxCameraHeight", INI::parseReal, NULL, offsetof( GlobalData, m_maxCameraHeight ) },
- { "UseGridHotKeys", INI::parseBool, NULL, offsetof( GlobalData, m_useGridHotKeys ) },
{ "EdgeScrollInWindowedMode", INI::parseBool, NULL, offsetof( GlobalData, m_edgeScrollInWindowedMode ) },
{ "SnapBuildPlacementTo45", INI::parseBool, NULL, offsetof( GlobalData, m_snapBuildPlacementTo45 ) },
{ "SnapCameraRotateTo45", INI::parseBool, NULL, offsetof( GlobalData, m_snapCameraRotateTo45 ) },
@@ -1028,7 +1027,6 @@ GlobalData::GlobalData()
m_scrollAmountCutoff = 10.0f;
m_cameraAdjustSpeed = 0.1f;
m_enforceMaxCameraHeight = TRUE;
- m_useGridHotKeys = FALSE;
//
// The fork's own conveniences default ON. They were opt-in at first, which in practice meant
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index 3bce628f9..27e2fd44f 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -142,6 +142,30 @@ static void commandButtonTooltip(GameWindow *window,
TheControlBar->showBuildTooltipLayout(window);
}
+//-------------------------------------------------------------------------------------------------
+/** The key command bar slot 'slot' answers to right now, MK_NONE when none does. Read live out of
+ the meta map, which is where CommandMap.ini puts the grid: a second copy of those letters here
+ is a copy that goes stale, and one did - the chord's second keys stayed Q A W S E D R F long
+ after the bottom row of the grid had moved to Z X C V B N M, so half the cells answered to a
+ letter that was not written on them and the letter that was fell straight through to the button
+ underneath. Rebinding a slot in Options > Keyboard now moves its chord with it. */
+//-------------------------------------------------------------------------------------------------
+static MappableKeyType getGridHotKey( Int slot )
+{
+ if( TheMetaMap == NULL || slot < 0 || slot >= MAX_COMMANDS_PER_SET )
+ return MK_NONE;
+
+ const GameMessage::Type wanted =
+ (GameMessage::Type)( GameMessage::MSG_META_COMMAND_SLOT01 + slot );
+
+ for( const MetaMapRec *rec = TheMetaMap->getFirstMetaMapRec(); rec; rec = rec->m_next )
+ if( rec->m_meta == wanted && rec->m_modState == 0 )
+ return rec->m_key;
+
+ return MK_NONE;
+
+} // end getGridHotKey
+
//-------------------------------------------------------------------------------------------------
/** Press a command bar button by slot index. Mirrors HotKeyManager::executeHotKey: a hidden
slot does nothing at all, an enabled one gets the same GBM_SELECTED the mouse would send,
@@ -156,16 +180,22 @@ void ControlBar::pressCommandButton( Int index )
// 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) ...
+ // position - Q-Q, Q-Z, ... W-Q (= T's cell), W-Z (= B's cell) ... A structure has no other
+ // way in: its own letter on its own is the second half of a chord nobody started.
//
Bool hasStructures = FALSE;
- for( Int i = 0; i < MAX_COMMANDS_PER_SET && !hasStructures; i++ )
+ Bool indexIsStructure = FALSE;
+ for( Int i = 0; i < MAX_COMMANDS_PER_SET; 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( c == NULL || c->getCommandType() != GUI_COMMAND_DOZER_CONSTRUCT )
+ continue;
+ hasStructures = TRUE;
+ if( i == index )
+ indexIsStructure = TRUE;
}
if( hasStructures )
{
@@ -180,6 +210,16 @@ void ControlBar::pressCommandButton( Int index )
markUIDirty(); // the group that is armed greys the other one out
return;
}
+
+ //
+ // Every structure is two keys, and only two. The key painted on a cell is the *second*
+ // of its pair, so on its own it used to fall through to whatever sits in the slot that
+ // key names - which for a builder is another structure. So the same building could be
+ // put up either by the chord written on it or by one bare letter nobody wrote anywhere,
+ // and a key pressed after a Q that had already been dropped built something.
+ //
+ if( indexIsStructure )
+ return;
}
else
{
@@ -216,15 +256,10 @@ 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. */
+/** The second key of a structure chord is the cell's own position inside the group, so it is
+ whatever the grid has bound to slots 0..7 - Q Z W X E C R V on the shipped map, which is what is
+ painted on the cells. 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 )
@@ -232,7 +267,9 @@ Bool ControlBar::handleChordKey( Int mappableKey )
for( Int i = 0; i < CHORD_GROUP_SIZE; i++ )
{
- if( s_chordKeys[ i ] == mappableKey )
+ const MappableKeyType key = getGridHotKey( i );
+
+ if( key != MK_NONE && (Int)key == mappableKey )
{
pressCommandButton( i ); // resolves the chord: i + group * CHORD_GROUP_SIZE
return TRUE;
@@ -3430,47 +3467,38 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *com
setCommandBarBorder(button, commandButton->getCommandButtonMappedBorderType());
- // The '&' letter buried in each localized button label and the grid keys are two rival
- // input schemes for the same buttons: the letter fires on KEY_UP out of HotKeyTranslator,
- // the grid keys on KEY_DOWN out of MetaEventTranslator, so leaving both live makes one
- // keystroke do two things. Grid mode therefore never registers the letters.
- if (TheHotKeyManager && !TheGlobalData->m_useGridHotKeys)
- {
- AsciiString hotKey = TheHotKeyManager->searchHotKey(commandButton->getTextLabel());
- if(hotKey.isNotEmpty())
- TheHotKeyManager->addHotKey(button, hotKey);
- }
-
- if( TheGlobalData->m_useGridHotKeys )
+ //
+ // The '&' letter buried in each localized button label and the grid keys are two rival input
+ // schemes for the same buttons: the letter fires on KEY_UP out of HotKeyTranslator, the grid
+ // keys on KEY_DOWN out of MetaEventTranslator, so leaving both live makes one keystroke do two
+ // things. The grid is the scheme, and the letters are not registered at all.
+ //
+ // paint the grid letter in the button's top left corner. Only the real command bar
+ // slots get one - the communicator, options and science buttons are not on the grid.
+ for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )
{
- // paint the grid letter in the button's top left corner. Only the real command bar
- // slots get one - the communicator, options and science buttons are not on the grid.
- for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )
- {
- if( m_commandWindows[ slot ] != button )
- continue;
+ if( m_commandWindows[ slot ] != button )
+ continue;
- UnicodeString label = getGridHotKeyLabel( slot );
+ 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;
- }
+ // structures are reached by a chord: Q or W picks the group (columns 1-4 or 5-7), then
+ // the key of the cell's own position inside that group - paint both, "QQ", "QZ", "WQ" ...
+ 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 );
+ chord.concat( getGridHotKeyLabel( slot - base ) );
+ label = chord;
+ }
- if( label.isEmpty() )
- button->winClearStatus( WIN_STATUS_SHORTCUT_BUTTON );
- else
- button->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );
+ if( label.isEmpty() )
+ button->winClearStatus( WIN_STATUS_SHORTCUT_BUTTON );
+ else
+ button->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );
- GadgetButtonSetText( button, label );
- break;
- }
+ GadgetButtonSetText( button, label );
+ break;
}
//
// the stop button does not live on the grid: MSG_META_STOP presses it whether or not grid hot
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
index d389f544e..b38d1ca98 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -714,18 +714,6 @@ Int OptionPreferences::getParticleCap(void)
mismatch check that refuses to start a LAN game between machines whose data differs. The
ceiling is fixed for everyone at ZOOM_OUT_LIMIT_FACTOR times the GameData.ini value. */
-Bool OptionPreferences::getUseGridHotKeys(void)
-{
- // Not written by the options menu - a power-user Options.ini key. With it on, the
- // command bar is driven by the COMMAND_SLOT01..14 keys from CommandMap.ini instead of
- // the '&' letter buried in each button's localized label.
- OptionPreferences::const_iterator it = find("UseGridHotKeys");
- if (it == end())
- return TheGlobalData->m_useGridHotKeys;
-
- return stricmp(it->second.str(), "yes") == 0;
-}
-
Bool OptionPreferences::getEdgeScrollInWindowedMode(void)
{
// Another power-user Options.ini key. Retail refuses to edge-scroll in a window because the
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 3da66b318..b0db9998e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -2692,13 +2692,8 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
case GameMessage::MSG_META_COMMAND_SLOT13:
case GameMessage::MSG_META_COMMAND_SLOT14:
{
- // Grid mode only. Off, these keys stay unbound so the retail '&' letter hot keys
- // keep the command bar to themselves.
- if( TheGlobalData->m_useGridHotKeys )
- {
- TheControlBar->pressCommandButton( t - GameMessage::MSG_META_COMMAND_SLOT01 );
- disp = DESTROY_MESSAGE;
- }
+ TheControlBar->pressCommandButton( t - GameMessage::MSG_META_COMMAND_SLOT01 );
+ disp = DESTROY_MESSAGE;
break;
} // end command bar grid slots
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index e91ec6b1d..246943a81 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -494,7 +494,8 @@ GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessa
//
// 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
+ // the group's own eight cell keys pick a 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 ) &&