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.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
feat(gameclient): command bar grid keys by window slot
Olcay Seygane62f409f830e
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex 764c27629..fde8aec2a 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -367,7 +367,7 @@ found and fixed, EA's own, not port damage.**- The Hotkeys page is in the game as well, as the last tab of the options screen, so a key can move without quitting to the launcher: from the main menu, or from Esc in the middle of a match. Every command sits on the left with its key. On the right you pick a general and one of his buildings or units, and its command bar is listed button by button, each with its cameo and its letter. Double-click a line, or press Enter or Change, and then the key; Esc lets go. Two buttons of one bar on one letter, or two commands on one key, turn red, and the line under the lists names them. Accept writes the file the launcher writes, so a key set in either place is there in the other, and a key changed in a match works from the next press.- Export and Import on the Hotkeys page take your keys to a file and back, for another PC or a fresh install. Before an import the page tells you how many keys it changes and how many would clash; a file with a line it cannot read changes nothing and quotes that line. Keys for a mod you have not installed come along and wait for it.- The arrow keys scroll the camera in the German game, as they do in English. German Zero Hour put next and previous unit and worker on the bare arrows, so the arrows picked units and only Ctrl and an arrow moved the camera; those four now sit on Ctrl and an arrow, as the English game ships them. Any language that puts a command on a bare arrow gets the same, and an arrow you gave a command yourself on the Hotkeys page stays where you put it.-- Grid keys are gone. The switch that made a button's key its place on the bar, Q for the first button of every building, is off the Hotkeys page, and the game no longer moves buttons around to give them a place's letter. Each button wears the letter you gave it or the game's own, and the fixed keys above still hold. A hotkeys file saved with grid keys on loads as before, with the switch ignored, so a player who had them on finds the letters of their own buttons back on the bar.+- Grid keys are back, keyed by the cell a button sits in. The first grid moved buttons around to give them a place's letter and still left two places without one; this one moves nothing. With the grid on, the top row of the bar is Q W E R T Y U and the bottom row A S D F G H J, column by column, so the first cell is Q on a Barracks, a War Factory and a tank alike, and the cell under it A. A mod's nine-column bar adds I O over K L. Upgrades take X C V B N in the order they stand on the bar, so the first upgrade of any building is X. The fixed keys step aside on the bar: attack move and stop take their cells' letters like every other button, while Ctrl still forces an attack. A letter you give a button still beats its cell, and a letter can now go to one cell alone, which is what a transport needs: its passengers' exit buttons are all one button, and with a key per cell the third passenger out can be M while the rest keep the grid. Accept on the in-game Hotkeys tab keeps the grid and every per-cell key, and the tab's list shows the grid's letters.- W no longer starts a War Factory. The launcher had moved China's War Factory onto W, which Zero Hour already gives to Select all aircraft. With a tank selected and no aircraft on the map, W dropped the tank, the idle worker's bar took its place, and the same press let go on that bar's War Factory. The launcher now keeps the buttons it moves off every letter a keyboard command holds on its own, W, Q and the idle worker's I among them, and China's War Factory sits on D. Start the launcher once and it rewrites its part of the file. A letter you picked yourself stays where you put it.## The command bar moves to the middlediff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 1fd655a42..418331159 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -1294,6 +1294,7 @@ protected:GameWindow *m_specialPowerShortcutParent;GameWindow *m_commandWindows[ MAX_COMMANDS_PER_SET ]; ///< command window controls for easy access+ Int m_commandUpgradeRank[ MAX_COMMANDS_PER_SET ]; ///< each window's upgradeRank on the bar populateCommand last filled (HotKeyManager::playerButtonKey)/** A player upgrade is researched once, so it goes to exactly one of the selected buildings -diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.hindex 857ab086c..667126acf 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h@@ -83,7 +83,8 @@ class HotKeypublic:HotKey( void );GameWindow *m_win;- AsciiString m_key;+ AsciiString m_key;+ Int m_claim; ///< how strongly m_win holds m_key, see keyClaim in HotKey.cpp// we may need a checkmark system.};@@ -99,7 +100,8 @@ public:virtual void reset( void ); ///< Reset//------------------------------------------------------------------------------------------------ void addHotKey( GameWindow *win, const AsciiString& key);+ /// barSlot: win's command bar window slot (0-based), -1 off the bar; see playerButtonKey+ void addHotKey( GameWindow *win, const AsciiString& key, Int barSlot = -1 );Bool executeHotKey( const AsciiString& key); // called fromt eh HotKeyTranslatorAsciiString searchHotKey( const AsciiString& label);@@ -119,11 +121,26 @@ public:* letters in place of the label's, which the player's own letter still overrides; another button* gets one only from the player, and loses it to the fixed order on a bar holding both* (addHotKey). Force Attack is 0: it is Ctrl, painted on the- * cameo, never a letter. */- static WideChar playerButtonKey( const AsciiString& button, WideChar labelKey, Int commandType );+ * cameo, never a letter.+ * On the command bar, barSlot is the button's window slot (0-based ButtonCommandNN less one) and+ * upgradeRank its place among the bar's upgrades in slot order (-1 for no upgrade). There the+ * player's "<button>@<barSlot + 1>" comes before his "<button>", and with CommandBarGrid on the+ * grid's letter (commandBarGridKey) comes before the fixed and label letters. */+ static WideChar playerButtonKey( const AsciiString& button, WideChar labelKey, Int commandType,+ Int barSlot = -1, Int upgradeRank = -1 );/// playerButtonKey over `keys` (lower case button name to letter, 0 for none) in place of the file'sstatic WideChar buttonKeyIn( const AsciiString& button, WideChar labelKey, Int commandType,- const std::map< std::string, WideChar >& keys );+ const std::map< std::string, WideChar >& keys, Int barSlot = -1, Int upgradeRank = -1 );+ /** The grid's letter for command bar window slot barSlot: column barSlot / 2, row barSlot % 2,+ * Q W E R T Y U I O along the top and A S D F G H J K L along the bottom. The k-th upgrade+ * (upgradeRank k) takes X C V B N instead, a sixth or later its slot's letter. 0 past the grid. */+ static WideChar commandBarGridKey( Int barSlot, Int upgradeRank );+ /** Each of `count` command bar slots' upgradeRank: GUI_COMMAND_PLAYER_UPGRADE and+ * GUI_COMMAND_OBJECT_UPGRADE count 0, 1, 2 in slot order, any other type is -1. */+ static void commandBarUpgradeRanks( const Int *types, Int count, Int *ranks );+ /// CommandBarGrid in Hotkeys.ini: every command bar button keyed by its window slot+ static Bool commandBarGrid( void );+ static void setCommandBarGrid( Bool grid );static WideChar fixedKey( const AsciiString& button, Int commandType ); ///< the bar's fixed letter, or 0/// FixedOrderKeys in Hotkeys.ini: FALSE gives the orders their labels' letters, as shippedstatic Bool fixedOrderKeys( void );@@ -184,7 +201,8 @@ struct HotkeysFilestd::map< std::string, HotkeyBinding > commands; ///< command to its key, key "" for nonestd::string launcherPart; ///< what followed HOTKEYS_LAUNCHER_PART, verbatim; empty when the file had noneBool fixedOrderKeys; ///< FixedOrderKeys' Enabled; written only when off- HotkeysFile() : fixedOrderKeys( TRUE ) {}+ Bool commandBarGrid; ///< CommandBarGrid's Enabled; written only when on+ HotkeysFile() : fixedOrderKeys( TRUE ), commandBarGrid( FALSE ) {}};/** The rows of the shipped Data\<language>\CommandMap.ini text, then the commands it leaves unbounddiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex d113e95d9..415afc824 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -1652,6 +1652,7 @@ ControlBar::ControlBar( void )for( i = 0; i < MAX_COMMANDS_PER_SET; i++ ){m_commandWindows[ i ] = NULL;+ m_commandUpgradeRank[ i ] = -1;// removed from multiplayer branch//m_commandMarkers[ i ] = NULL;}@@ -4569,25 +4570,28 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *com// A builder standing in for an empty selection lends the keys its buildings and nothing else.// Nobody selected it, so its orders keep no letter: H with nothing selected is the command map's// (view the command center), not the GLA worker's switch to fake buildings, and S stops nothing.- Bool standInOrder = FALSE;- if( m_standInBuilderID != INVALID_DRAWABLE_ID && m_currentSelectedDrawable- && m_currentSelectedDrawable->getID() == m_standInBuilderID- && commandButton->getCommandType() != GUI_COMMAND_DOZER_CONSTRUCT )- for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )- standInOrder = standInOrder || m_commandWindows[ slot ] == button;+ // the command bar window slot the button sits in, -1 off the bar+ Int barSlot = -1;+ for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )+ if( m_commandWindows[ slot ] == button )+ barSlot = slot;+ const Bool standInOrder = barSlot >= 0 && m_standInBuilderID != INVALID_DRAWABLE_ID && m_currentSelectedDrawable+ && m_currentSelectedDrawable->getID() == m_standInBuilderID+ && commandButton->getCommandType() != GUI_COMMAND_DOZER_CONSTRUCT;// the key is the one the player gave the button on the launcher's Hotkeys page, or else the// game's own, the letter after the '&' in the button's label - the English label's in every// language, so a Turkish or German player presses what an English one does - and the button- // wears it in its top left corner.+ // wears it in its top left corner. With the command bar grid on, a bar button's key is its+ // window slot's letter unless the player gave it one.if( TheHotKeyManager ){const WideChar letter = standInOrder ? 0 : HotKeyManager::playerButtonKey( commandButton->getName(),TheGameText ? TheGameText->fetchEnglishHotKey( commandButton->getTextLabel() ) : 0,- commandButton->getCommandType() );+ commandButton->getCommandType(), barSlot, barSlot >= 0 ? m_commandUpgradeRank[ barSlot ] : -1 );if( letter != 0 ){- TheHotKeyManager->addHotKey( button, HotKeyManager::nameOf( letter ) );+ TheHotKeyManager->addHotKey( button, HotKeyManager::nameOf( letter ), barSlot );const WideChar text[ 2 ] = { letter, 0 };GadgetButtonSetText( button, UnicodeString( text ) );button->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cppindex 34b0e9213..c3f9d6a84 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp@@ -414,6 +414,14 @@ void ControlBar::populateCommand( Object *obj )slot[ i ] = NULL;}+ // the order of the bar's upgrades, which the command bar grid keys X C V B N+ {+ Int types[ MAX_COMMANDS_PER_SET ];+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ types[ i ] = ( m_commandWindows[ i ] && slot[ i ] ) ? slot[ i ]->getCommandType() : GUI_COMMAND_NONE;+ HotKeyManager::commandBarUpgradeRanks( types, MAX_COMMANDS_PER_SET, m_commandUpgradeRank );+ }+// populate the button with commands definedconst CommandButton *commandButton;for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cppindex c00ada0bd..a5e204d66 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenuHotkeys.cpp@@ -221,13 +221,18 @@ std::map< std::string, WideChar > buttonKeys( void )return keys;}-/// A button's key on a bar as text: Force Attack's chord, else its letter; empty for none.-UnicodeString buttonKeyText( const CommandButton *button, const std::map< std::string, WideChar >& keys )+/// A button's key in a bar's slot as text: Force Attack's chord, else its letter; empty for none.+UnicodeString buttonKeyText( const BarObject *object, Int slot, const std::map< std::string, WideChar >& keys ){+ const CommandButton *button = object->slots[ slot ];if( button->getCommandType() == GUI_COMMAND_FORCE_ATTACK )return wide( Hotkeys_chordText( bindingOf( *forceAttackRow() ) ) );+ Int types[ BAR_SLOTS ], ranks[ BAR_SLOTS ];+ for( Int each = 0; each < BAR_SLOTS; each++ )+ types[ each ] = object->slots[ each ] ? object->slots[ each ]->getCommandType() : GUI_COMMAND_NONE;+ HotKeyManager::commandBarUpgradeRanks( types, BAR_SLOTS, ranks );const WideChar letter = HotKeyManager::buttonKeyIn( button->getName(),- TheGameText->fetchEnglishHotKey( button->getTextLabel() ), button->getCommandType(), keys );+ TheGameText->fetchEnglishHotKey( button->getTextLabel() ), button->getCommandType(), keys, slot, ranks[ slot ] );return letterText( letter );}@@ -346,7 +351,7 @@ std::map< KeyText, std::vector< UnicodeString > > barClashes( const BarObject *ofor( Int slot = 0; slot < BAR_SLOTS; slot++ )if( object->slots[ slot ] ){- const UnicodeString key = buttonKeyText( object->slots[ slot ], keys );+ const UnicodeString key = buttonKeyText( object, slot, keys );if( !key.isEmpty() )byKey[ key.str() ].push_back( buttonName( object->slots[ slot ] ) );}@@ -455,7 +460,7 @@ void fillButtons( void )const CommandButton *button = object->slots[ slot ];if( button == NULL )continue;- const UnicodeString key = buttonKeyText( button, keys );+ const UnicodeString key = buttonKeyText( object, slot, keys );const Bool waiting = s_capture == CAPTURE_BUTTON && button == s_button;const Bool changed = button->getCommandType() == GUI_COMMAND_FORCE_ATTACK? s_file.commands.count( "BEGIN_FORCEATTACK" ) != 0diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cppindex 1d2a1ac6b..143aba29e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp@@ -165,6 +165,7 @@ HotKey::HotKey()//Initializations missing and neededm_key.clear();//+ m_claim = 0;}//-----------------------------------------------------------------------------@@ -191,17 +192,18 @@ void HotKeyManager::reset( void )m_hotKeyMap.clear();}-static Int keyClaim( GameWindow *win, const AsciiString& key );+static Int keyClaim( GameWindow *win, const AsciiString& key, Int barSlot );//------------------------------------------------------------------------------void HotKeyManager::addHotKey( GameWindow *win, const AsciiString& keyIn)+void HotKeyManager::addHotKey( GameWindow *win, const AsciiString& keyIn, Int barSlot ){AsciiString key = keyIn;key.toLower();HotKeyMap::iterator it = m_hotKeyMap.find(key);// two buttons on one letter, which the Hotkeys page marks: a fixed order on its own letter keeps- // it, a letter the player gave beats a label's, and between equals the first keeps it- if( it != m_hotKeyMap.end() && keyClaim( win, key ) <= keyClaim( it->second.m_win, key ) )+ // it, a letter the player gave beats a label's or the grid's, and between equals the first keeps it+ const Int claim = keyClaim( win, key, barSlot );+ if( it != m_hotKeyMap.end() && it->second.m_win != win && claim <= it->second.m_claim ){DEBUG_LOG(( "HOTKEYS: %s already on %s, not on %s\n", key.str(), it->second.m_win->winGetInstanceData()->m_decoratedNameString.str(), win->winGetInstanceData()->m_decoratedNameString.str() ));return;@@ -209,6 +211,7 @@ void HotKeyManager::addHotKey( GameWindow *win, const AsciiString& keyIn)HotKey newHK;newHK.m_key.set(key);newHK.m_win = win;+ newHK.m_claim = claim;m_hotKeyMap[key] = newHK;}@@ -345,6 +348,13 @@ static const WideChar FIXED_KEYS[] = { 'A', 'S', 'G', 'Y', 'V', 'N', 'C', 'H' };* orders included, wears its label's letter or the player's, as in the game as shipped. Read with* the button keys, back to on before each read. */static Bool s_fixedOrderKeys = TRUE;+/** CommandBarGrid in Hotkeys.ini: a command bar button takes its window slot's letter+ * (HotKeyManager::commandBarGridKey) in place of its fixed and label letters. Read with the button+ * keys, back to off before each read. The launcher holds the same tables (hotkeys.js, GRID_ROWS+ * and GRID_UPGRADE_KEYS). */+static Bool s_commandBarGrid = FALSE;+static const char GRID_ROWS[ 2 ][ 10 ] = { "QWERTYUIO", "ASDFGHJKL" };+static const char GRID_UPGRADE_KEYS[] = "XCVBN";static const char *const FIXED_H_BUTTONS[] ={"command_upgradechinamines", "command_upgradeempmines", "command_upgradecamonetting", "command_upgradeglacamonetting",@@ -408,10 +418,25 @@ static std::string withoutModPrefix( const char *lowerName, Int *mod )static Bool findPlayerKey( const std::map< std::string, WideChar >& keys, const std::string& bare, Int ownMod, WideChar *letter );-/** How strongly the command button win holds key, the map's lower case name: 2 when it is the- * button's fixed letter (fixedButtonKey) and the player left the button alone, 1 when the player- * gave it that letter in Hotkeys.ini, 0 for the label's. */-static Int keyClaim( GameWindow *win, const AsciiString& key )+/** The player's key for a button standing in command bar slot barSlot (-1 off the bar), into *letter:+ * his "<button>@<barSlot + 1>" there, else his "<button>". FALSE leaves *letter alone. */+static Bool findPlayerSlotKey( const std::map< std::string, WideChar >& keys, const std::string& bare, Int ownMod, Int barSlot, WideChar *letter )+{+ if( barSlot >= 0 )+ {+ char at[ 16 ];+ snprintf( at, sizeof( at ), "@%d", barSlot + 1 );+ if( findPlayerKey( keys, bare + at, ownMod, letter ) )+ return TRUE;+ }+ return findPlayerKey( keys, bare, ownMod, letter );+}++/** How strongly the command button win, in command bar slot barSlot or -1, holds key, the map's+ * lower case name: 2 when it is the button's fixed letter (fixedButtonKey) and the player left the+ * button alone, 1 when the player gave it that letter in Hotkeys.ini, 0 for the label's or the+ * grid's. With the grid on a bar button has no fixed letter. */+static Int keyClaim( GameWindow *win, const AsciiString& key, Int barSlot ){const CommandButton *command = (const CommandButton *)GadgetButtonGetData( win );AsciiString lower = command->getName();@@ -419,8 +444,10 @@ static Int keyClaim( GameWindow *win, const AsciiString& key )Int mod = -1;const std::string bare = withoutModPrefix( lower.str(), &mod );WideChar letter = 0;- if( findPlayerKey( s_playerButtonKeys, bare, mod, &letter ) )+ if( findPlayerSlotKey( s_playerButtonKeys, bare, mod, barSlot, &letter ) )return letter != 0 && HotKeyManager::nameOf( letter ) == key ? 1 : 0;+ if( s_commandBarGrid && barSlot >= 0 )+ return 0;const WideChar fixed = fixedButtonKey( AsciiString( bare.c_str() ), command->getCommandType() );return fixed != 0 && HotKeyManager::nameOf( fixed ) == key ? 2 : 0;}@@ -462,9 +489,42 @@ static Bool isOneOf( WideChar letter, const WideChar *letters, Int count )}//------------------------------------------------------------------------------WideChar HotKeyManager::playerButtonKey( const AsciiString& button, WideChar labelKey, Int commandType )+WideChar HotKeyManager::playerButtonKey( const AsciiString& button, WideChar labelKey, Int commandType,+ Int barSlot, Int upgradeRank )+{+ return buttonKeyIn( button, labelKey, commandType, s_playerButtonKeys, barSlot, upgradeRank );+}++//-----------------------------------------------------------------------------+WideChar HotKeyManager::commandBarGridKey( Int barSlot, Int upgradeRank )+{+ if( barSlot < 0 || barSlot >= 2 * (Int)strlen( GRID_ROWS[ 0 ] ) )+ return 0;+ if( upgradeRank >= 0 && upgradeRank < (Int)strlen( GRID_UPGRADE_KEYS ) )+ return GRID_UPGRADE_KEYS[ upgradeRank ];+ return GRID_ROWS[ barSlot % 2 ][ barSlot / 2 ];+}++//-----------------------------------------------------------------------------+void HotKeyManager::commandBarUpgradeRanks( const Int *types, Int count, Int *ranks )+{+ Int upgrades = 0;+ for( Int slot = 0; slot < count; slot++ )+ {+ const Bool upgrade = types[ slot ] == GUI_COMMAND_PLAYER_UPGRADE || types[ slot ] == GUI_COMMAND_OBJECT_UPGRADE;+ ranks[ slot ] = upgrade ? upgrades++ : -1;+ }+}++//-----------------------------------------------------------------------------+Bool HotKeyManager::commandBarGrid( void )+{+ return s_commandBarGrid;+}++void HotKeyManager::setCommandBarGrid( Bool grid ){- return buttonKeyIn( button, labelKey, commandType, s_playerButtonKeys );+ s_commandBarGrid = grid;}//-----------------------------------------------------------------------------@@ -493,7 +553,7 @@ std::string HotKeyManager::fileButtonName( const AsciiString& button )//-----------------------------------------------------------------------------WideChar HotKeyManager::buttonKeyIn( const AsciiString& button, WideChar labelKey, Int commandType,- const std::map< std::string, WideChar >& keys )+ const std::map< std::string, WideChar >& keys, Int barSlot, Int upgradeRank ){// Force Attack is Ctrl. The English label's F is not the key and may not bind the button.if( commandType == GUI_COMMAND_FORCE_ATTACK )@@ -502,9 +562,15 @@ WideChar HotKeyManager::buttonKeyIn( const AsciiString& button, WideChar labelKelower.toLower();Int ownMod = -1;const std::string bare = withoutModPrefix( lower.str(), &ownMod );- // the player's letter first, a fixed order's included: the fixed letter is only its default+ // the player's letter first, his for this slot before his for the button, a fixed order's+ // included: the fixed letter is only its default. With the grid on, the bar's place is nextWideChar letter = labelKey;- const Bool chosen = findPlayerKey( keys, bare, ownMod, &letter );+ const Bool chosen = findPlayerSlotKey( keys, bare, ownMod, barSlot, &letter );+ if( !chosen && s_commandBarGrid && barSlot >= 0 )+ {+ const Bool upgrade = commandType == GUI_COMMAND_PLAYER_UPGRADE || commandType == GUI_COMMAND_OBJECT_UPGRADE;+ return commandBarGridKey( barSlot, upgrade ? upgradeRank : -1 );+ }if( !chosen ){const WideChar fixed = fixedButtonKey( AsciiString( bare.c_str() ), commandType );@@ -547,8 +613,9 @@ void HotKeyManager::setFixedOrderKeys( Bool fixed )}//------------------------------------------------------------------------------/** CommandBarGrid, Enabled = Yes or No, End: the grid keys a launcher before 2026-10-15 wrote into- * Hotkeys.ini. Grid keys are gone, so the block is read and ignored. */+/** CommandBarGrid, Enabled = Yes or No, End: whether command bar buttons take their window slot's+ * letter (s_commandBarGrid). A launcher before 2026-10-15 wrote the same block for the place-based+ * grid it had then; that file now turns this one on. *//*static*/ void INI::parseCommandBarGridDefinition( INI *ini ){static const FieldParse fields[] =@@ -556,8 +623,10 @@ void HotKeyManager::setFixedOrderKeys( Bool fixed ){ "Enabled", INI::parseBool, NULL, 0 },{ NULL, NULL, NULL, 0 }};- Bool ignored = FALSE;- ini->initFromINI( &ignored, fields );+ Bool enabled = FALSE;+ ini->initFromINI( &enabled, fields );+ s_commandBarGrid = enabled;+ DEBUG_LOG(( "HOTKEYS: command bar grid %s\n", enabled ? "on" : "off" ));}//-----------------------------------------------------------------------------@@ -591,6 +660,7 @@ void HotKeyManager::loadPlayerKeys( void ){s_playerButtonKeys.clear();s_fixedOrderKeys = TRUE;+ s_commandBarGrid = FALSE;AsciiString hotkeys = TheGlobalData->getPath_UserData();hotkeys.concat( "Hotkeys.ini" );if( !TheFileSystem->doesFileExist( hotkeys.str() ) )@@ -884,6 +954,8 @@ HotkeysFile Hotkeys_parse( const std::string& text, const std::vector< HotkeyComconst std::string enabled = lowered( block.field( "Enabled", "yes" ) );file.fixedOrderKeys = !( enabled == "no" || enabled == "false" );}+ else if( block.type == "CommandBarGrid" )+ file.commandBarGrid = lowered( block.field( "Enabled", "no" ) ) == "yes";else if( block.type == "CommandButtonHotKey" ){const Bool letter = key.size() == 1 && isalpha( (unsigned char)key[ 0 ] );@@ -1007,6 +1079,8 @@ std::string Hotkeys_format( const HotkeysFile& file, const std::vector< HotkeyCo"\r\n";if( !file.fixedOrderKeys )out += "FixedOrderKeys\r\n Enabled = No\r\nEnd\r\n\r\n";+ if( file.commandBarGrid )+ out += "CommandBarGrid\r\n Enabled = Yes\r\nEnd\r\n\r\n";std::map< std::string, Bool > named;std::vector< std::string > ids = sortedNames( file.commands );for( size_t each = 0; each < ids.size(); each++ )diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cppindex 9ae8964a9..ffb82315d 100644--- a/GeneralsMD/Code/Tests/test_gameengine.cpp+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp@@ -5396,6 +5396,76 @@ TEST(hotkeys_fixed_order_keys_switch_off_gives_the_labels_letters)CHECK( Hotkeys_format( file, rows ).find( "FixedOrderKeys" ) == std::string::npos );}+/* CommandBarGrid, Enabled = Yes: a bar button's key is its window slot, ButtonCommand01 Q over 02 A+ down the columns, the bar's upgrades X C V B N in slot order, and the player's Name@slot over his+ Name over the grid */+TEST(hotkeys_command_bar_grid_keys_by_window_slot)+{+ // two rows read down the columns, seven on the bar, nine on the wide one+ static const char TOP[] = "QWERTYUIO", BOTTOM[] = "ASDFGHJKL";+ for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )+ CHECK_EQ( HotKeyManager::commandBarGridKey( slot, -1 ), (WideChar)( slot % 2 == 0 ? TOP : BOTTOM )[ slot / 2 ] );+ CHECK_EQ( HotKeyManager::commandBarGridKey( 13, -1 ), (WideChar)'J' ); // ButtonCommand14, the narrow bar's last+ CHECK_EQ( HotKeyManager::commandBarGridKey( 14, -1 ), (WideChar)'I' ); // 15, the wide bar's eighth column+ CHECK_EQ( HotKeyManager::commandBarGridKey( 17, -1 ), (WideChar)'L' ); // 18, its ninth, bottom+ CHECK_EQ( HotKeyManager::commandBarGridKey( 18, -1 ), 0 );+ CHECK_EQ( HotKeyManager::commandBarGridKey( -1, -1 ), 0 );++ // upgrades in slot order, whatever else stands between; the sixth keeps its slot's letter+ const Int N = GUI_COMMAND_NONE, U = GUI_COMMAND_PLAYER_UPGRADE, O = GUI_COMMAND_OBJECT_UPGRADE, B = GUI_COMMAND_UNIT_BUILD;+ const Int types[ MAX_COMMANDS_PER_SET ] = { B, U, N, O, B, U, U, N, O, N, U, N, N, N, N, N, N, N };+ Int ranks[ MAX_COMMANDS_PER_SET ];+ HotKeyManager::commandBarUpgradeRanks( types, MAX_COMMANDS_PER_SET, ranks );+ static const Int RANKS[ MAX_COMMANDS_PER_SET ] = { -1, 0, -1, 1, -1, 2, 3, -1, 4, -1, 5, -1, -1, -1, -1, -1, -1, -1 };+ for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )+ CHECK_EQ( ranks[ slot ], RANKS[ slot ] );+ static const char KEYS[] = "QXWCEVBFNGYHUJIKOL";+ for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )+ CHECK_EQ( HotKeyManager::commandBarGridKey( slot, ranks[ slot ] ), (WideChar)KEYS[ slot ] );++ std::map< std::string, WideChar > keys;+ const AsciiString guard( "Command_Guard" ), exit( "Command_TransportExit" ), mines( "Command_UpgradeChinaMines" );+ CHECK( !HotKeyManager::commandBarGrid() );+ HotKeyManager::setCommandBarGrid( TRUE );+ // the fixed keys are off on the bar: guard in slot 13 is U; off the bar it is still G+ CHECK_EQ( HotKeyManager::buttonKeyIn( guard, 'G', GUI_COMMAND_GUARD, keys, 12, -1 ), (WideChar)'U' );+ CHECK_EQ( HotKeyManager::buttonKeyIn( guard, 'G', GUI_COMMAND_GUARD, keys ), (WideChar)'G' );+ CHECK_EQ( HotKeyManager::buttonKeyIn( mines, 'M', GUI_COMMAND_PLAYER_UPGRADE, keys, 4, 1 ), (WideChar)'C' );+ CHECK_EQ( HotKeyManager::buttonKeyIn( mines, 'M', GUI_COMMAND_PLAYER_UPGRADE, keys, 4, 5 ), (WideChar)'E' );+ // a rank on anything but an upgrade means nothing; Force Attack is Ctrl+ CHECK_EQ( HotKeyManager::buttonKeyIn( exit, 0, GUI_COMMAND_EXIT_CONTAINER, keys, 2, 0 ), (WideChar)'W' );+ CHECK_EQ( HotKeyManager::buttonKeyIn( AsciiString( "Command_ForceAttack" ), 'F', GUI_COMMAND_FORCE_ATTACK, keys, 11, -1 ), 0 );++ // the player's Name beats the grid, his Name@slot beats Name in that slot only, and NONE is none+ keys[ "command_transportexit" ] = 'Z';+ keys[ "command_transportexit@4" ] = 'M';+ keys[ "command_transportexit@6" ] = 0;+ CHECK_EQ( HotKeyManager::buttonKeyIn( exit, 0, GUI_COMMAND_EXIT_CONTAINER, keys, 0, -1 ), (WideChar)'Z' );+ CHECK_EQ( HotKeyManager::buttonKeyIn( exit, 0, GUI_COMMAND_EXIT_CONTAINER, keys, 3, -1 ), (WideChar)'M' );+ CHECK_EQ( HotKeyManager::buttonKeyIn( exit, 0, GUI_COMMAND_EXIT_CONTAINER, keys, 5, -1 ), 0 );+ CHECK_EQ( HotKeyManager::buttonKeyIn( exit, 0, GUI_COMMAND_EXIT_CONTAINER, keys ), (WideChar)'Z' );+ HotKeyManager::setCommandBarGrid( FALSE );+ // a slot's own key holds without the grid too; the rest is as before+ CHECK_EQ( HotKeyManager::buttonKeyIn( exit, 0, GUI_COMMAND_EXIT_CONTAINER, keys, 3, -1 ), (WideChar)'M' );+ CHECK_EQ( HotKeyManager::buttonKeyIn( guard, 'W', GUI_COMMAND_GUARD, keys, 12, -1 ), (WideChar)'G' );++ // the options page's Accept keeps the switch and every slot's key+ const std::vector< HotkeyCommandRow > rows = Hotkeys_commandRows( HOTKEYS_COMMAND_MAP );+ static const char FILE_TEXT[] =+ "CommandBarGrid\r\n Enabled = Yes\r\nEnd\r\n\r\n"+ "CommandButtonHotKey Command_TransportExit@4\r\n Key = M\r\nEnd\r\n\r\n"+ "CommandButtonHotKey shockwave:Command_TransportExit@12\r\n Key = NONE\r\nEnd\r\n\r\n";+ HotkeysFile file = Hotkeys_parse( FILE_TEXT, rows );+ CHECK( file.commandBarGrid );+ CHECK_STR( file.buttons[ "Command_TransportExit@4" ].c_str(), "M" );+ CHECK( file.buttons.count( "shockwave:Command_TransportExit@12" ) == 1 );+ const std::string text = Hotkeys_format( file, rows );+ CHECK( text.find( FILE_TEXT ) != std::string::npos );+ CHECK( Hotkeys_format( Hotkeys_parse( text, rows ), rows ) == text );+ file.commandBarGrid = FALSE;+ CHECK( Hotkeys_format( file, rows ).find( "CommandBarGrid" ) == std::string::npos );+}+TEST(metamap_format_chord_names_the_hold){CHECK( MetaMap_formatChord( MK_NONE, CTRL, COMMANDUSABLE_GAME ) == UnicodeString( u"Ctrl" ) );diff --git a/README.md b/README.mdindex 86f6a2659..8318f00d2 100644--- a/README.md+++ b/README.md@@ -302,6 +302,20 @@ FixedOrderKeysEnd```+Another block keys the command bar by place. Every button takes the letter of the cell it sits in,+Q W E R T Y U over A S D F G H J down the columns (I O over K L on the nine-column bar), and the bar's+upgrades take X C V B N in order. The fixed keys are off on the bar while it is on.++```ini+CommandBarGrid+ Enabled = Yes+End+```++A button's own letter still beats its cell's. `CommandButtonHotKey Command_TransportExit@3` with+`Key = M` keys that button only while it stands in the third cell, so the passenger buttons of one+transport can each have their own key.+</details>## Build it