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): let the player put a button on a fixed letter

Olcay Seyganc16d3dc0e405
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 76501207e..e029f06a5 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -58,7 +58,7 @@ found and fixed — EA's own, not port damage.**
- Buildings select together again, which the one interface had taken away. Shift-click them, drag a box over them, or double-click one for every building of its kind on the screen; select four War Factories and each tank you click goes to whichever has the shortest queue. Double-click a unit and every one of that kind whose feet sit in the picture is taken, including the ones sitting past the camera's far clip that used to be skipped. A building and a unit still never share a selection.
- Formation lines are back for everyone. With move, attack move or guard armed, a left drag spreads the selection along the line you draw again; since the one interface it drew a selection box instead, because the line was switched off for the Classic mouse that every player now runs. A drag with no order armed is still the selection box.
- Every key is yours to move. The launcher's Hotkeys page draws the command bar of every building and unit each general can field, cameos and letters as the game shows them, and a click and a keypress gives any button a new letter or none. Two buttons on one bar that would share a letter are marked before you play. The keyboard commands are there too, from bookmarks and team keys to the camera, along with the ones Zero Hour never bound: select every fighting unit, vehicle or aircraft, every barracks, war factory or airfield, the next idle worker or unit, pause, the general's promotions, the three signals to your allies and the general's powers. Your keys are yours alone; the other players in a match keep theirs, and a match never refuses you for them. Every mod you install brings its own generals to the page, ShockWave's fifteen next to Zero Hour's thirteen, and a key you give a ShockWave button stays with ShockWave.
-- Some keys now mean one thing on every bar: A attack move, S stop, G guard, Y rally point, V evacuate, N sell, C combat drop, and H for land mines, camo netting and the GLA worker's switch to fake buildings. Sell sits on its own key, so emptying a bunker can never sell it. The 188 buttons Zero Hour had put on one of those letters take another, kept off the grid keys where the bar leaves room (the Avenger is J now), and no bar gained a clash doing it.
+- Some keys now mean one thing on every bar: A attack move, S stop, G guard, Y rally point, V evacuate, N sell, C combat drop, and H for land mines, camo netting and the GLA worker's switch to fake buildings. Sell sits on its own key, so emptying a bunker can never sell it. The 188 buttons Zero Hour had put on one of those letters take another, kept off the grid keys where the bar leaves room (the Avenger is J now), and no bar gained a clash doing it. Those letters are still yours to hand out: the Hotkeys page gives A or H to any other button you pick, and marks the clash. On a bar that has the order as well, the order keeps its key: a Barracks button on A fires from A, and a tank's A is still attack move.
- 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.
- Grid keys, one switch on the Hotkeys page: a button's key is its place on the bar, so the first button of a Command Center is Q and so is the first of a Barracks, a War Factory or a dozer. Every key on the bar sits in the 18-key block under your left hand, Q W E R T Y over A S D F G H over Z X C V B N. Attack move, stop, guard, rally point, evacuate and combat drop keep A, S, G, Y, V and C wherever they stand; the other twelve letters are places, Q W E R T along the top with Z X D F B under them, H in the sixth column and N, still sell, in the last. The places attack move and rally point usually hold have no letter of their own. On a bar without those orders they borrow the free ones: a building has no attack move, so the American War Factory's TOW upgrade at the top of the sixth column is A, and any other button at the top of the seventh column, where a rally point usually stands, is G. A unit's attack move and guard keep A and G as before. A button that still finds no letter there moves to the leftmost free place that has one, so every button on the bar has a key whenever a keyed place is free. The letter on each button changes to match, and type select, select all, scatter and the rest that sat on those letters step aside to P and the keys right of the letters, with the page showing where each went.
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
index 3d89225d7..7cf21b548 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/HotKey.h
@@ -113,7 +113,8 @@ public:
* Hotkeys page writes it, INI::parseCommandButtonHotKeyDefinition reads it), 0 where the player
* took the key away, and labelKey, the letter after the label's '&', where the player left the
* button alone; upper case. Attack move, stop, guard, rally point, evacuate and sell have their
- * fixed letters and no other button gets one. Force Attack is 0: it is Ctrl, painted on the
+ * fixed letters; 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. With grid keys on (INI::parseCommandBarGridDefinition) a button on the command bar,
* barSlot its ButtonCommand number less one, gets its place's key instead, except attack move, stop, guard, rally point, evacuate and combat drop, and any other button
* (barSlot -1) loses a letter the grid uses. */
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
index c4c1ee206..c353e6fef 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
@@ -188,15 +188,19 @@ void HotKeyManager::reset( void )
lendFixedKeys( NULL, NULL, 0 );
}
+static Bool ownsFixedKey( GameWindow *win, const AsciiString& key );
+
//-----------------------------------------------------------------------------
void HotKeyManager::addHotKey( GameWindow *win, const AsciiString& keyIn)
{
AsciiString key = keyIn;
key.toLower();
HotKeyMap::iterator it = m_hotKeyMap.find(key);
- if( it != m_hotKeyMap.end() )
+ // two buttons on one letter is the player's choice on the Hotkeys page, which marks it: the
+ // first keeps the key, except that a fixed order takes its own letter back
+ if( it != m_hotKeyMap.end() && !ownsFixedKey( win, key ) )
{
- DEBUG_ASSERTCRASH(FALSE,("Hotkey %s is already mapped to window %s, current window is %s", key.str(), it->second.m_win->winGetInstanceData()->m_decoratedNameString.str(), win->winGetInstanceData()->m_decoratedNameString.str()));
+ 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;
}
HotKey newHK;
@@ -341,7 +345,9 @@ static Bool s_commandGrid = FALSE;
/** The owner's fixed keys, 2026-10-12, on every bar: A attack move, S stop, G guard, Y rally
* point, V evacuate, N sell, C combat drop, and H for land mines, camo netting and the GLA's fake
- * and real switches, which go by button name. No other button may have one of these letters.
+ * and real switches, which go by button name. No button keeps one of these letters from its
+ * label; the player may give one to any button on the launcher's Hotkeys page, and on a bar where
+ * the fixed order stands too, the order gets the key (addHotKey).
* With grid keys on only GRID_FIXED_KEYS hold, on any bar and slot; sell and the H buttons take
* their place's key. The launcher holds the same tables (hotkeys.js, FIXED_KEYS and
* GRID_FIXED_LETTERS). */
@@ -406,6 +412,18 @@ static std::string withoutModPrefix( const char *lowerName, Int *mod )
return tilde + 1;
}
+/** Whether win is a command button whose fixed letter (fixedButtonKey) is key, the map's lower
+ * case name. */
+static Bool ownsFixedKey( GameWindow *win, const AsciiString& key )
+{
+ const CommandButton *command = (const CommandButton *)GadgetButtonGetData( win );
+ AsciiString lower = command->getName();
+ lower.toLower();
+ Int mod = -1;
+ const WideChar fixed = fixedButtonKey( AsciiString( withoutModPrefix( lower.str(), &mod ).c_str() ), command->getCommandType() );
+ return fixed != 0 && HotKeyManager::nameOf( fixed ) == key;
+}
+
/** The player's key for a button, into *letter; FALSE leaves it alone. A mod's own button (ownMod,
* under -modfactions) takes only its mod's "<scope>:<button>" entry. A plain name, which under a
* plain -mod may be any loaded mod's, takes the last loaded mod's scoped entry that exists, then
@@ -465,10 +483,12 @@ WideChar HotKeyManager::playerButtonKey( const AsciiString& button, WideChar lab
return fixed;
WideChar letter = labelKey;
- findPlayerKey( bare, ownMod, &letter );
+ const Bool chosen = findPlayerKey( bare, ownMod, &letter );
if( letter >= 'a' && letter <= 'z' )
letter -= 'a' - 'A';
- if( isOneOf( letter, FIXED_KEYS, (Int)( sizeof( FIXED_KEYS ) / sizeof( FIXED_KEYS[ 0 ] ) ) ) )
+ // a label's own fixed letter gives way; one the player chose stays, and the bar's fixed order
+ // still takes it first (addHotKey)
+ if( !chosen && isOneOf( letter, FIXED_KEYS, (Int)( sizeof( FIXED_KEYS ) / sizeof( FIXED_KEYS[ 0 ] ) ) ) )
return 0;
// a button off the bar gives a grid letter up to the bar
if( s_commandGrid && isOneOf( letter, GRID_KEYS, GRID_KEY_COUNT ) )