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.

fix(gameengine): keep bare arrow keys on the camera in every language

Olcay Seygana0f721144b97
diff --git a/CHANGELOG.md b/CHANGELOG.md
index bc47333a1..0296e8b6a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -203,6 +203,7 @@ found and fixed — EA's own, not port damage.**
- Those orders move too. Sell, attack move, stop, guard, rally point, evacuate, combat drop, the mines, camo netting and the fake building switch were locked to their letters: the Hotkeys tab refused to wait for a key on them, and a letter given to one in the file was ignored in the match. Each one now takes the letter you give it, or none, on the Hotkeys tab like any other button, and keeps it after a restart; the letters above are only where they start. A letter you set also beats the one a button had from the game: Sell moved to K on the GLA Command Center used to lose K to the Worker button, and now sells. The launcher's Hotkeys page lets them go as well; it used to show the fixed letter whatever you had set and refuse to change it. Two holds Zero Hour put on a modifier alone are on the list of commands now, in the game and the launcher: Alt queues orders and Shift adds to the selection, and either can move to a key or another modifier. With nothing selected and a worker lending you his bar, only his buildings answer a key. H used to throw a GLA worker over to his fake buildings, and S stopped him, though nobody had picked him. The launcher also stops shifting keyboard commands off those letters: it had put View command center on P because H belonged to the mines, and the next time it starts it hands H back. A key you chose yourself stays where you put it.
- 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.
## The command bar moves to the middle
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h b/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
index 3fa201874..a264a9d19 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
@@ -383,6 +383,11 @@ public:
static void parseMetaMap(INI* ini);
void clear(); ///< every record gone, for CommandMap.ini and Hotkeys.ini to be read again
+ /** Bare arrow keys scroll the camera. A language's CommandMap.ini that puts a record on one
+ * (the German file binds next/previous unit and worker there) gets Ctrl added, as the English
+ * file ships them; otherwise the record eats the arrow before LookAtTranslator sees it. Called
+ * after the language file and before Hotkeys.ini, so a player's own bare arrow stands. */
+ void keepArrowsForCamera();
const MetaMapRec *getFirstMetaMapRec() const { return m_metaMaps; }
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index d5217d353..b20581e92 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -1293,6 +1293,7 @@ void GameEngine::init( int argc, char *argv[] )
AsciiString fname;
fname.format("Data\\%s\\CommandMap.ini", GetRegistryLanguage().str());
initSubsystem(TheMetaMap,"TheMetaMap", MSGNEW("GameEngineSubsystem") MetaMap(), NULL, fname.str(), NULL);
+ TheMetaMap->keepArrowsForCamera();
#if defined(_DEBUG) || defined(_INTERNAL)
ini.load("Data\\INI\\CommandMapDebug.ini", INI_LOAD_MULTIFILE, NULL);
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
index 13471676c..64ee3459a 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/HotKey.cpp
@@ -614,6 +614,7 @@ void HotKeyManager::reloadKeys( void )
commandMap.format( "Data\\%s\\CommandMap.ini", GetRegistryLanguage().str() );
INI ini;
ini.load( commandMap, INI_LOAD_OVERWRITE, NULL );
+ TheMetaMap->keepArrowsForCamera();
#if defined(_DEBUG) || defined(_INTERNAL)
ini.load( "Data\\INI\\CommandMapDebug.ini", INI_LOAD_MULTIFILE, NULL );
#endif
@@ -792,7 +793,11 @@ std::vector< HotkeyCommandRow > Hotkeys_commandRows( const std::string& commandM
if( block.type != "CommandMap" || startsWith( block.name, "DEMO_" ) || startsWith( block.name, "DEBUG_" )
|| startsWith( block.name, "CHEAT_" ) || startsWith( block.name, "END_" ) || !Hotkeys_isKeyName( key ) )
continue;
- HotkeyCommandRow row = commandRow( block.name, block.field( "Category", "MISC" ), key.c_str(), block.field( "Modifiers", "NONE" ).c_str() );
+ // a bare arrow goes to Ctrl, as the game loads it (MetaMap::keepArrowsForCamera)
+ std::string modifiers = block.field( "Modifiers", "NONE" );
+ if( modifiers == "NONE" && ( key == "KEY_UP" || key == "KEY_DOWN" || key == "KEY_LEFT" || key == "KEY_RIGHT" ) )
+ modifiers = "CTRL";
+ HotkeyCommandRow row = commandRow( block.name, block.field( "Category", "MISC" ), key.c_str(), modifiers.c_str() );
row.usableIn = block.field( "UseableIn", "GAME" );
row.label = block.field( "DisplayName", "" );
if( startsWith( block.name, "BEGIN_" ) )
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index 76668021b..3a9a5af05 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -872,10 +872,24 @@ MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
m->m_displayName.clear();
m->m_next = m_metaMaps;
m_metaMaps = m;
-
+
return m;
}
+//-------------------------------------------------------------------------------------------------
+void MetaMap::keepArrowsForCamera()
+{
+ for( MetaMapRec *map = m_metaMaps; map; map = map->m_next )
+ {
+ const Bool arrow = map->m_key == MK_UP || map->m_key == MK_DOWN || map->m_key == MK_LEFT || map->m_key == MK_RIGHT;
+ if( arrow && map->m_modState == NONE )
+ {
+ DEBUG_LOG(( "HOTKEYS: %s on a bare arrow, moved to Ctrl so the arrow scrolls\n", findGameMessageNameByType( map->m_meta ) ));
+ map->m_modState = CTRL;
+ }
+ }
+}
+
//-------------------------------------------------------------------------------------------------
UnicodeString MetaMap_formatChord( MappableKeyType key, MappableKeyModState mods, CommandUsableInType usable )
{
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index ae2a793bf..6c545abe9 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -4792,6 +4792,38 @@ TEST(metamap_format_chord_names_the_hold)
CHECK( MetaMap_chordLabel( GameMessage::MSG_META_BEGIN_FORCEATTACK ) == UnicodeString( u"Ctrl" ) );
}
+struct MetaRecProbe : public MetaMap
+{
+ using MetaMap::getMetaMapRec;
+};
+
+// Data\German\CommandMap.ini binds next/previous unit and worker to bare arrows; English to Ctrl (#102)
+TEST(metamap_bare_arrows_stay_with_the_camera)
+{
+ static const char GERMAN[] =
+ "CommandMap SELECT_NEXT_UNIT\r\n Key = KEY_RIGHT\r\n Transition = DOWN\r\n Modifiers = NONE\r\n UseableIn = GAME\r\n Category = SELECTION\r\nEnd\r\n"
+ "CommandMap SELECT_PREV_WORKER\r\n Key = KEY_DOWN\r\n Transition = DOWN\r\n Modifiers = NONE\r\n UseableIn = GAME\r\n Category = SELECTION\r\nEnd\r\n"
+ "CommandMap SELECT_TEAM1\r\n Key = KEY_1\r\n Transition = DOWN\r\n Modifiers = NONE\r\n UseableIn = GAME\r\n Category = SELECTION\r\nEnd\r\n";
+ const std::vector< HotkeyCommandRow > rows = Hotkeys_commandRows( GERMAN );
+ CHECK( rows.size() > 3 );
+ CHECK( rows[ 0 ].binding == HotkeyBinding( "KEY_RIGHT", "CTRL" ) );
+ CHECK( rows[ 1 ].binding == HotkeyBinding( "KEY_DOWN", "CTRL" ) );
+ CHECK( rows[ 2 ].binding == HotkeyBinding( "KEY_1", "NONE" ) );
+
+ MetaRecProbe map;
+ MetaMapRec *next = map.getMetaMapRec( GameMessage::MSG_META_SELECT_NEXT_UNIT );
+ next->m_key = MK_RIGHT;
+ MetaMapRec *ctrl = map.getMetaMapRec( GameMessage::MSG_META_SELECT_PREV_UNIT );
+ ctrl->m_key = MK_LEFT;
+ ctrl->m_modState = CTRL;
+ MetaMapRec *team = map.getMetaMapRec( GameMessage::MSG_META_SELECT_TEAM1 );
+ team->m_key = MK_1;
+ map.keepArrowsForCamera();
+ CHECK_EQ( (Int)next->m_modState, (Int)CTRL );
+ CHECK_EQ( (Int)ctrl->m_modState, (Int)CTRL );
+ CHECK_EQ( (Int)team->m_modState, (Int)NONE );
+}
+
TEST(controlbar_stance_key_takes_what_the_buttons_leave)
{
enum { SLOTS = 14 };