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): add an opt-in W A S D camera for Modern input

Olcay Seygan01d34d954f82
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e44babd46..e6f9f757d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -419,6 +419,7 @@ found and fixed — EA's own, not port damage.**
- 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.
+- W A S D can move the camera. It is a box on the Controls page, off until you tick it, and it only takes with the Modern input scheme: pick Legacy and the box goes grey. On top of the arrow keys and everything the mouse already does, and it moves the keys a fight is fought with one row down to meet the hand: F attacks, G stops, H attack-moves, J holds position, K guards. The grid's top row steps over W and reads Q E R T Y U I, which pushes the idle-worker key from I to O, and every letter painted on the command bar follows the moment you press Accept. Let go of a camera key with Ctrl held for a control group and the camera still stops. The pointer stays the pointer while the keys scroll, instead of turning into the scroll arrows the mouse uses.
- 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/CommandMapWASD.ini b/GeneralsMD/Code/Data/INI/CommandMapWASD.ini
new file mode 100644
index 000000000..00f791dd1
--- /dev/null
+++ b/GeneralsMD/Code/Data/INI/CommandMapWASD.ini
@@ -0,0 +1,103 @@
+;//////////////////////////////////////////////////////////////////////////////
+;FILE: CommandMapWASD.ini (SYSTEM) ////////////////////////////////////////////
+;//////////////////////////////////////////////////////////////////////////////
+;
+; MASTER COPY - the build copies it to Run/Data/INI/ with CommandMap.ini.
+;
+; The keys that move when the W A S D camera box is ticked on the Controls page.
+; MetaMap::loadWasdBindings copies the finished Modern map - the language's own
+; CommandMap.ini with this fork's CommandMap.ini over it - into a list of its
+; own and lays this file over that copy, so a block here only has to name what
+; changes: every field it leaves out keeps the Modern value. Legacy input never
+; reads this file and the box is grey while Legacy is picked.
+;
+; The camera keys themselves are not in here. Scrolling is read as a raw key
+; in LookAtXlat.cpp, beside the arrow keys: the meta map holds one key per
+; command, so binding W A S D would take the arrows away, and a meta record
+; fires its UP only while the modifiers match the ones the key went down with,
+; so letting go of W with ctrl held for a control group would leave the camera
+; running.
+;
+; The grid's top row steps over W:
+;
+; slot 01 03 05 07 09 11 13 (top row) Q E R T Y U I
+; slot 02 04 06 08 10 12 14 (bottom row) Z X C V B N M
+;
+; and the orders the camera hand took off A and S move one row down, reading
+; left to right along it with no modifier on any of them:
+;
+; F attack G stop H attack move J hold position K guard
+;
+; Idle workers go from I, which slot 13 now wants, to O.
+
+CommandMap COMMAND_SLOT03
+ Key = KEY_E
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap COMMAND_SLOT05
+ Key = KEY_R
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap COMMAND_SLOT07
+ Key = KEY_T
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap COMMAND_SLOT09
+ Key = KEY_Y
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap COMMAND_SLOT11
+ Key = KEY_U
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap COMMAND_SLOT13
+ Key = KEY_I
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap SELECT_NEXT_IDLE_WORKER
+ Key = KEY_O
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap TOGGLE_FORCEATTACK
+ Key = KEY_F
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap STOP
+ Key = KEY_G
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap TOGGLE_ATTACKMOVE
+ Key = KEY_H
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap HOLD_POSITION
+ Key = KEY_J
+ Transition = DOWN
+ Modifiers = NONE
+End
+
+CommandMap TOGGLE_GUARD
+ Key = KEY_K
+ Transition = DOWN
+ Modifiers = NONE
+End
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 15768e366..94f77612a 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -846,6 +846,14 @@ TOOLTIP:InputScheme
"Modern: left selects, right orders, the middle button moves the camera and the grid keys run the command bar. Legacy: the mouse and keys the game shipped with, without any of the additions."
END
+GUI:WasdCamera
+"W A S D Camera"
+END
+
+TOOLTIP:WasdCamera
+"W A S D move the camera. F attacks, G stops, H attack-moves, J holds position and K guards, and the command bar's top row reads Q E R T Y U I. Modern input only."
+END
+
GUI:OrderLines
"Order Lines"
END
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index 2b67b6d2d..6022d3468 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -15405,6 +15405,14 @@ TOOLTIP:InputScheme
"Modern: sol tık seçer, sağ tık emir verir, orta tuş kamerayı gezdirir, komut çubuğu ızgara tuşlarıyla kullanılır. Legacy: oyunun çıktığı hâldeki fare ve tuşlar, sonradan eklenenlerin hiçbiri olmadan."
END
+GUI:WasdCamera
+"W A S D Kamera"
+END
+
+TOOLTIP:WasdCamera
+"W A S D kamerayı gezdirir. F saldırır, G durdurur, H saldırarak ilerler, J konumu korur, K gözcü koyar; komut çubuğunun üst sırası Q E R T Y U I olur. Yalnızca Modern girişte."
+END
+
GUI:OrderLines
"Emir Çizgileri"
END
diff --git a/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd b/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd
index 7773bb92c..008163e3e 100644
--- a/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd
+++ b/GeneralsMD/Code/Data/Window/Menus/OptionsMenu.wnd
@@ -7138,6 +7138,53 @@ WINDOW
IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
END
+ CHILD
+ WINDOW
+ WINDOWTYPE = CHECKBOX;
+ SCREENRECT = UPPERLEFT: 536 238, BOTTOMRIGHT: 760 262, CREATIONRESOLUTION: 800 600;
+ NAME = "OptionsMenu.wnd:CheckWasdCamera";
+ STATUS = ENABLED+IMAGE+BORDER;
+ STYLE = CHECKBOX+MOUSETRACK;
+ SYSTEMCALLBACK = "[None]";
+ INPUTCALLBACK = "[None]";
+ TOOLTIPCALLBACK = "[None]";
+ DRAWCALLBACK = "[None]";
+ FONT = NAME: "Arial", SIZE: 14, BOLD: 0;
+ HEADERTEMPLATE = "MinorTitle";
+ TOOLTIPTEXT = "TOOLTIP:WasdCamera";
+ TOOLTIPDELAY = -1;
+ TEXT = "GUI:WasdCamera";
+ TEXTCOLOR = ENABLED: 255 255 255 255, ENABLEDBORDER: 0 0 0 255,
+ DISABLED: 192 192 192 255, DISABLEDBORDER: 64 64 64 255,
+ HILITE: 186 255 12 255, HILITEBORDER: 0 0 0 255;
+ ENABLEDDRAWDATA = IMAGE: NoImage, COLOR: 255 0 0 255, BORDERCOLOR: 255 128 128 255,
+ IMAGE: Active-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 0 0 255 255, BORDERCOLOR: 128 128 255 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ DISABLEDDRAWDATA = IMAGE: NoImage, COLOR: 128 128 128 255, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Unchecked, COLOR: 255 255 255 0, BORDERCOLOR: 192 192 192 255,
+ IMAGE: Disabled-Checked, COLOR: 64 64 64 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ HILITEDRAWDATA = IMAGE: NoImage, COLOR: 0 255 0 255, BORDERCOLOR: 128 255 128 255,
+ IMAGE: Active-HiLighted, COLOR: 255 255 255 0, BORDERCOLOR: 128 128 255 255,
+ IMAGE: Active-Checked, COLOR: 255 255 0 255, BORDERCOLOR: 254 254 254 255,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0,
+ IMAGE: NoImage, COLOR: 255 255 255 0, BORDERCOLOR: 255 255 255 0;
+ END
ENDALLCHILDREN
END
CHILD
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 8eaab4a45..ba63f2b8e 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -309,6 +309,8 @@ public:
Int m_textLanguage; ///< TextLanguageType: the translation GameText lays over the CSF, read once at startup (client only)
Int m_inputScheme; ///< InputSchemeType: which mouse and keyboard the client answers to, read on every click and key (client only)
Bool isLegacyInput( void ) const { return m_inputScheme == INPUT_SCHEME_LEGACY; }
+ Bool m_wasdCamera; ///< W A S D scroll the camera and the unit keys move to F G H J K; Modern input only (client only)
+ Bool isWasdCamera( void ) const { return m_wasdCamera && !isLegacyInput(); }
Bool m_showOrderLines; ///< draw a line from each selected unit to where it is going, and its queue (client only)
Bool m_scriptDebug; ///< Should we attempt to load the script debugger window (.DLL)
Bool m_particleEdit; ///< Should we attempt to load the particle editor (.DLL)
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
index a67b06a6c..8bbd6782f 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/InGameUI.h
@@ -511,7 +511,7 @@ public: // ********************************************************************
void showNamedTimerDisplay( Bool show );
// mouse mode interface
- virtual void setScrolling( Bool isScrolling ); ///< set right-click scroll mode
+ virtual void setScrolling( Bool isScrolling, Bool moveCursor = TRUE ); ///< set scroll mode; moveCursor puts up the scroll arrows and takes them down
virtual Bool isScrolling( void ); ///< are we scrolling?
virtual void setSelecting( Bool isSelecting ); ///< set drag select mode
virtual Bool isSelecting( void ); ///< are we selecting?
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
index f2e286cfc..09cebed30 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/LookAtXlat.h
@@ -73,6 +73,7 @@ private:
DrawableID m_lastPlaneID;
ViewLocation m_viewLocation[ MAX_VIEW_LOCS ];
Int m_scrollType;
+ Bool m_scrollMovesCursor; // the scroll in progress swapped the cursor for the scroll arrows and puts it back when it stops
void setScrolling( Int );
void stopScrolling( void );
UnsignedInt m_lastMouseMoveFrame;
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h b/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
index 453a13778..25fad79c0 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/MetaEvent.h
@@ -366,7 +366,10 @@ class MetaMap : public SubsystemInterface
friend class MetaEventTranslator;
private:
- MetaMapRec *m_metaMaps[ INPUT_SCHEME_COUNT ]; ///< one list of bindings per InputSchemeType
+ /// one list of bindings per InputSchemeType, and a third for Modern with W A S D on the camera
+ enum { BINDINGS_WASD = INPUT_SCHEME_COUNT, BINDING_LIST_COUNT };
+
+ MetaMapRec *m_metaMaps[ BINDING_LIST_COUNT ];
Int m_parseScheme; ///< the list parseMetaMap is filling
protected:
@@ -389,7 +392,11 @@ public:
* Modern list reads that. */
void loadLegacyBindings( const AsciiString& languageMapFile );
- /// the bindings the player's InputScheme answers to
+ /** Fill the W A S D list: a copy of the finished Modern list, in the same order, with overlayFile
+ * laid over it. Runs after everything else that binds into Modern, so the copy has it all. */
+ void loadWasdBindings( const AsciiString& overlayFile );
+
+ /// the bindings the player's InputScheme, and the W A S D box under Modern, answer to
const MetaMapRec *getFirstMetaMapRec() const;
const MetaMapRec *getFirstMetaMapRec( Int scheme ) const { return m_metaMaps[ scheme ]; }
};
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
index b749f387f..7a822865e 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameEngine.cpp
@@ -896,6 +896,9 @@ void GameEngine::init( int argc, char *argv[] )
ini.load("Data\\INI\\CommandMapDemo.ini", INI_LOAD_MULTIFILE, NULL);
#endif
+ // Modern with W A S D on the camera: everything Modern binds above, and the keys that moves
+ TheMetaMap->loadWasdBindings("Data\\INI\\CommandMapWASD.ini");
+
initSubsystem(TheActionManager,"TheActionManager", MSGNEW("GameEngineSubsystem") ActionManager(), NULL);
//initSubsystem((CComObject<WebBrowser> *)TheWebBrowser,"(CComObject<WebBrowser> *)TheWebBrowser", (CComObject<WebBrowser> *)createWebBrowser(), NULL);
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index d40e6af64..4efb2241d 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -918,6 +918,8 @@ GlobalData::GlobalData()
m_textLanguage = TEXT_LANGUAGE_ENGLISH;
// the mouse and keys this fork plays with until somebody asks for the ones the game shipped with
m_inputScheme = INPUT_SCHEME_MODERN;
+ // W A S D stay on the grid and the unit keys until somebody asks for them on the camera
+ m_wasdCamera = FALSE;
// the lines have been on since they were added, so nobody loses them until they say so
m_showOrderLines = TRUE;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
index abe20da4b..1810ed19c 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/OptionsCatalog.cpp
@@ -71,6 +71,7 @@ OPTION_INT_ACCESSORS( m_healthBarMode )
OPTION_INT_ACCESSORS( m_playerColorScheme )
OPTION_INT_ACCESSORS( m_textLanguage )
OPTION_INT_ACCESSORS( m_inputScheme )
+OPTION_BOOL_ACCESSORS( m_wasdCamera )
OPTION_BOOL_ACCESSORS( m_showOrderLines )
OPTION_BOOL_ACCESSORS( m_useShadowVolumesForSkins )
OPTION_BOOL_ACCESSORS( m_shadowsForProjectiles )
@@ -332,6 +333,13 @@ const OptionDef TheOptionCatalog[] =
OPTION_ENUM, APPLY_LIVE, 0, INPUT_SCHEME_COUNT - 1,
get_m_inputScheme, set_m_inputScheme },
+ // W A S D on the camera, and the keys they held moved to F G H J K. Modern only: the box greys
+ // while Legacy is picked, and a tick saved under Modern is kept but ignored until Modern is back.
+ // Every key asks, and Accept rebuilds the command bar's letters, so it changes at once.
+ { "WasdCamera", OPT_WND( "CheckWasdCamera" ), "GUI:WasdCamera",
+ OPTION_BOOL, APPLY_LIVE, 0, 1,
+ get_m_wasdCamera, set_m_wasdCamera },
+
// Which language the words are in. English is the string table the game shipped with, and every
// other entry is a translation laid over it, so a line the translation lacks stays English. The
// table is built once while the game starts: a new language is on screen from the next launch.
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index d8aa94a23..803084308 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -185,7 +185,8 @@ void ControlBar::pressCommandButton( Int index )
// 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-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.
+ // way in: its own letter on its own is the second half of a chord nobody started. Q and W
+ // are whatever the grid binds to slots 0 and 2, so with W A S D on the camera they are Q and E.
//
Bool hasStructures = FALSE;
Bool indexIsStructure = FALSE;
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 06352740f..5a7b19ed7 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -1128,6 +1128,23 @@ static void updateResolutionEnabled( void )
comboBoxResolution->winEnable( value != WINDOW_MODE_BORDERLESS );
}
+//-------------------------------------------------------------------------------------------------
+/** The W A S D camera box only means something under Modern input, so it goes grey while Legacy is
+ * picked. The tick stays as it was: going back to Modern brings back what the player chose. Read
+ * off the input scheme combo box, like the resolution list above, so it follows the dropdown. */
+//-------------------------------------------------------------------------------------------------
+static void updateWasdCameraEnabled( void )
+{
+ GameWindow *check = findOptionWidget( *findOptionDef( "WasdCamera" ) );
+ GameWindow *schemeWidget = findOptionWidget( *findOptionDef( "InputScheme" ) );
+
+ Int selected = -1;
+ GadgetComboBoxGetSelectedPos( schemeWidget, &selected );
+
+ const Int scheme = ( selected >= 0 ) ? selected : TheGlobalData->m_inputScheme;
+ check->winEnable( scheme != INPUT_SCHEME_LEGACY );
+}
+
static void saveOptions( void )
{
Int index;
@@ -2548,6 +2565,7 @@ void OptionsMenuInit( WindowLayout *layout, void *userData )
// borderless owns the resolution; the list is grey while it is picked
updateResolutionEnabled();
+ updateWasdCameraEnabled();
TheWindowManager->winSetModal(parent);
ignoreSelected = FALSE;
@@ -2706,6 +2724,8 @@ WindowMsgHandledType OptionsMenuSystem( GameWindow *window, UnsignedInt msg,
// picking borderless greys the resolution list out, the other two hand it back
updateResolutionEnabled();
+ // picking Legacy greys the W A S D box out, Modern hands it back
+ updateWasdCameraEnabled();
break;
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
index a895edd1c..d02256eee 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp
@@ -4862,7 +4862,7 @@ DrawableID InGameUI::getMousedOverDrawableID( void ) const
//-------------------------------------------------------------------------------------------------
/// set right-click scroll mode
//-------------------------------------------------------------------------------------------------
-void InGameUI::setScrolling( Bool isScrolling )
+void InGameUI::setScrolling( Bool isScrolling, Bool moveCursor )
{
if (m_isScrolling == isScrolling)
{
@@ -4872,7 +4872,8 @@ void InGameUI::setScrolling( Bool isScrolling )
if (isScrolling)
{
TheMouse->capture();
- setMouseCursor( Mouse::SCROLL );
+ if (moveCursor)
+ setMouseCursor( Mouse::SCROLL );
// break any camera locks
TheTacticalView->setCameraLock( INVALID_ID );
@@ -4880,7 +4881,8 @@ void InGameUI::setScrolling( Bool isScrolling )
}
else
{
- setMouseCursor( Mouse::ARROW );
+ if (moveCursor)
+ setMouseCursor( Mouse::ARROW );
TheMouse->releaseCapture();
}
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
index 6936ec022..a6b765116 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/LookAtXlat.cpp
@@ -65,6 +65,20 @@ static enum
static Bool scrollDir[4] = { false, false, false, false };
+// The directions a W A S D key is holding. A release only ends a scroll its own press started: with
+// the box off W is a grid key, and letting go of it must not stop the up arrow; with the box
+// unticked while W is held, letting go must still stop the camera.
+static Bool letterScrollDir[4] = { false, false, false, false };
+
+static void scrollByLetter( Int dir, Bool isPressed, Bool pressScrolls )
+{
+ if( isPressed ? !pressScrolls : !letterScrollDir[ dir ] )
+ return;
+
+ letterScrollDir[ dir ] = isPressed;
+ scrollDir[ dir ] = isPressed;
+}
+
Int SCROLL_AMT = 100;
static const Int edgeScrollSize = 3;
@@ -77,9 +91,14 @@ void LookAtTranslator::setScrolling(Int x)
if (!TheInGameUI->getInputEnabled())
return;
- prevCursor = TheMouse->getMouseCursor();
+ // With the W A S D box ticked a keyboard scroll leaves the cursor alone - arrow keys too, it is the
+ // same scroll - because the mouse is not the thing moving the camera. A mouse scroll, and every
+ // keyboard scroll with the box off, still turns the cursor into the scroll arrows.
+ m_scrollMovesCursor = !( x == SCROLL_KEY && TheGlobalData->isWasdCamera() );
+ if( m_scrollMovesCursor )
+ prevCursor = TheMouse->getMouseCursor();
m_isScrolling = true;
- TheInGameUI->setScrolling( TRUE );
+ TheInGameUI->setScrolling( TRUE, m_scrollMovesCursor );
TheTacticalView->setMouseLock( TRUE );
m_scrollType = x;
// A manual pan restores map constraints widened by scripted camera paths.
@@ -93,9 +112,10 @@ void LookAtTranslator::setScrolling(Int x)
void LookAtTranslator::stopScrolling( void )
{
m_isScrolling = false;
- TheInGameUI->setScrolling( FALSE );
+ TheInGameUI->setScrolling( FALSE, m_scrollMovesCursor );
TheTacticalView->setMouseLock( FALSE );
- TheMouse->setCursor(prevCursor);
+ if( m_scrollMovesCursor )
+ TheMouse->setCursor(prevCursor);
m_scrollType = SCROLL_NONE;
// if we have a stats collectore increment the stats
@@ -114,7 +134,8 @@ LookAtTranslator::LookAtTranslator() :
m_timestamp(0),
m_lastPlaneID(INVALID_DRAWABLE_ID),
m_lastMouseMoveFrame(0),
- m_scrollType(SCROLL_NONE)
+ m_scrollType(SCROLL_NONE),
+ m_scrollMovesCursor(true)
{
//Added By Sadullah Nader
//Initializations misssing and needed
@@ -184,6 +205,19 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
if (TheShell && TheShell->isShellActive())
break;
+ //
+ // With the W A S D box ticked those four scroll alongside the arrow keys, and
+ // CommandMapWASD.ini moves what they were bound to. They are read here as raw keys
+ // instead of being bound there for two reasons: the meta map holds one key per command, so
+ // binding them would have taken the arrows away, and a meta record fires its UP only while
+ // the modifier state still matches the one the key went down with - letting go of W with
+ // ctrl held for a control group would have left the camera scrolling with nothing to stop
+ // it. A press with ctrl or alt down belongs to whatever that combination is bound to.
+ //
+ const Bool letterPressScrolls = TheGlobalData->isWasdCamera() &&
+ !BitTest( state, KEY_STATE_CONTROL ) &&
+ !BitTest( state, KEY_STATE_ALT );
+
switch (key)
{
case KEY_UP:
@@ -198,6 +232,18 @@ GameMessageDisposition LookAtTranslator::translateGameMessage(const GameMessage
case KEY_RIGHT:
scrollDir[DIR_RIGHT] = isPressed;
break;
+ case KEY_W:
+ scrollByLetter( DIR_UP, isPressed, letterPressScrolls );
+ break;
+ case KEY_S:
+ scrollByLetter( DIR_DOWN, isPressed, letterPressScrolls );
+ break;
+ case KEY_A:
+ scrollByLetter( DIR_LEFT, isPressed, letterPressScrolls );
+ break;
+ case KEY_D:
+ scrollByLetter( DIR_RIGHT, isPressed, letterPressScrolls );
+ break;
}
if (TheInGameUI->isSelecting() || (m_isScrolling && m_scrollType != SCROLL_KEY))
@@ -768,7 +814,10 @@ void LookAtTranslator::resetModes()
// the flags that say a scroll is in progress.
//
for( Int i = 0; i < 4; ++i )
+ {
scrollDir[i] = false;
+ letterScrollDir[i] = false;
+ }
if( m_isScrolling && TheInGameUI && TheTacticalView && TheMouse )
stopScrolling();
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index 49d9232e9..dfecab6c0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -820,14 +820,14 @@ GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessa
MetaMap::MetaMap() :
m_parseScheme(INPUT_SCHEME_MODERN)
{
- for (Int scheme = 0; scheme < INPUT_SCHEME_COUNT; ++scheme)
+ for (Int scheme = 0; scheme < BINDING_LIST_COUNT; ++scheme)
m_metaMaps[scheme] = NULL;
}
//-------------------------------------------------------------------------------------------------
MetaMap::~MetaMap()
{
- for (Int scheme = 0; scheme < INPUT_SCHEME_COUNT; ++scheme)
+ for (Int scheme = 0; scheme < BINDING_LIST_COUNT; ++scheme)
{
while (m_metaMaps[scheme])
{
@@ -841,7 +841,10 @@ MetaMap::~MetaMap()
//-------------------------------------------------------------------------------------------------
const MetaMapRec *MetaMap::getFirstMetaMapRec() const
{
- return m_metaMaps[ TheGlobalData->isLegacyInput() ? INPUT_SCHEME_LEGACY : INPUT_SCHEME_MODERN ];
+ if( TheGlobalData->isLegacyInput() )
+ return m_metaMaps[ INPUT_SCHEME_LEGACY ];
+
+ return m_metaMaps[ TheGlobalData->isWasdCamera() ? BINDINGS_WASD : INPUT_SCHEME_MODERN ];
}
//-------------------------------------------------------------------------------------------------
@@ -853,6 +856,37 @@ void MetaMap::loadLegacyBindings( const AsciiString& languageMapFile )
m_parseScheme = INPUT_SCHEME_MODERN;
}
+//-------------------------------------------------------------------------------------------------
+void MetaMap::loadWasdBindings( const AsciiString& overlayFile )
+{
+ //
+ // Appended at the tail, not through getMetaMapRec, which puts a new record at the head: the
+ // translator stops at the first record that matches a key, so the copy keeps Modern's order and
+ // answers a key the way Modern does wherever the overlay does not reach.
+ //
+ MetaMapRec **tail = &m_metaMaps[ BINDINGS_WASD ];
+ for( const MetaMapRec *modern = m_metaMaps[ INPUT_SCHEME_MODERN ]; modern; modern = modern->m_next )
+ {
+ MetaMapRec *copy = newInstance( MetaMapRec );
+ copy->m_next = NULL;
+ copy->m_meta = modern->m_meta;
+ copy->m_key = modern->m_key;
+ copy->m_transition = modern->m_transition;
+ copy->m_modState = modern->m_modState;
+ copy->m_usableIn = modern->m_usableIn;
+ copy->m_category = modern->m_category;
+ copy->m_description = modern->m_description;
+ copy->m_displayName = modern->m_displayName;
+ *tail = copy;
+ tail = &copy->m_next;
+ }
+
+ m_parseScheme = BINDINGS_WASD;
+ INI ini;
+ ini.load( overlayFile, INI_LOAD_OVERWRITE, NULL );
+ m_parseScheme = INPUT_SCHEME_MODERN;
+}
+
//-------------------------------------------------------------------------------------------------
GameMessage::Type MetaMap::findGameMessageMetaType(const char* name)
{
diff --git a/GeneralsMD/Code/Tests/test_camera_behavior.inc b/GeneralsMD/Code/Tests/test_camera_behavior.inc
index aae6ef027..100308ed5 100644
--- a/GeneralsMD/Code/Tests/test_camera_behavior.inc
+++ b/GeneralsMD/Code/Tests/test_camera_behavior.inc
@@ -38,7 +38,7 @@ public:
void draw() {}
View *createView() { return NULL; }
Bool scrolling = FALSE, selecting = FALSE, enabled = TRUE;
- void setScrolling(Bool value) { InGameUI::setScrolling(value); scrolling = value; }
+ void setScrolling(Bool value, Bool moveCursor = TRUE) { InGameUI::setScrolling(value, moveCursor); scrolling = value; }
Bool isScrolling() { return scrolling; }
Bool isSelecting() { return selecting; }
Bool getInputEnabled() { return enabled; }
@@ -226,3 +226,46 @@ TEST(camera_wheel_anchors_zoom_to_cursor_only_under_modern_with_the_box_ticked)
spinWheel();
CHECK_EQ(f.view.zoomAnchors, 1);
}
+
+TEST(wasd_camera_scrolls_without_touching_the_cursor_and_only_with_the_box_ticked)
+{
+ CHECK(bootOnce());
+ CameraInputFixture f;
+ const auto press = [&f](UnsignedByte key, Bool down)
+ {
+ GameMessage *message = newInstance(GameMessage)(down ? GameMessage::MSG_RAW_KEY_DOWN : GameMessage::MSG_RAW_KEY_UP);
+ message->appendIntegerArgument(key);
+ message->appendIntegerArgument(down ? KEY_STATE_DOWN : KEY_STATE_UP);
+ f.camera.translateGameMessage(message);
+ message->deleteInstance();
+ };
+
+ // Box off: D is a unit key and scrolls nothing; the arrow keys scroll behind the scroll arrows.
+ CHECK(!f.global->isWasdCamera());
+ press(KEY_D, TRUE);
+ CHECK(!f.ui->scrolling);
+ press(KEY_D, FALSE);
+ press(KEY_RIGHT, TRUE);
+ CHECK(f.ui->scrolling);
+ CHECK_EQ(f.mouse.getMouseCursor(), Mouse::SCROLL);
+ // letting go of a D that never scrolled leaves the arrow key's scroll running
+ press(KEY_D, FALSE);
+ CHECK(f.ui->scrolling);
+ press(KEY_RIGHT, FALSE);
+ CHECK(!f.ui->scrolling);
+
+ // Box on: D scrolls, and the cursor is not touched on the way in or out.
+ f.global->m_wasdCamera = TRUE;
+ const Int cursorChanges = f.mouse.cursorChanges;
+ press(KEY_D, TRUE);
+ CHECK(f.ui->scrolling);
+ press(KEY_D, FALSE);
+ CHECK(!f.ui->scrolling);
+ CHECK_EQ(f.mouse.cursorChanges, cursorChanges);
+
+ // Legacy keeps the game's own keys: the box is ignored.
+ f.global->m_inputScheme = INPUT_SCHEME_LEGACY;
+ press(KEY_D, TRUE);
+ CHECK(!f.ui->scrolling);
+ press(KEY_D, FALSE);
+}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index e11d1e0f4..0805f8e36 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -10250,6 +10250,37 @@ TEST(the_input_scheme_is_a_live_menu_choice_that_starts_modern)
delete scratch;
}
+TEST(wasd_camera_is_a_live_check_box_that_starts_off_and_needs_modern_input)
+{
+ /* The box moves eleven keys a player already has in their hands, so nobody gets it without asking.
+ A tick saved under Modern is kept through a switch to Legacy, which plays the game's own map,
+ and comes back with Modern. */
+ const OptionDef *def = findOptionDef( "WasdCamera" );
+ CHECK( def != NULL );
+ if( def == NULL )
+ return;
+ CHECK_EQ( def->kind, OPTION_BOOL );
+ CHECK_EQ( def->apply, APPLY_LIVE );
+ CHECK( def->widgetName != NULL && def->widgetName[ 0 ] != '\0' );
+
+ GlobalData *saved = TheWritableGlobalData;
+ GlobalData *scratch = NEW GlobalData;
+ TheWritableGlobalData = scratch;
+
+ CHECK( !scratch->m_wasdCamera );
+ CHECK( !scratch->isWasdCamera() );
+ def->set( 1 );
+ CHECK( scratch->isWasdCamera() );
+ scratch->m_inputScheme = INPUT_SCHEME_LEGACY;
+ CHECK( !scratch->isWasdCamera() );
+ CHECK_EQ( def->get(), 1 );
+ scratch->m_inputScheme = INPUT_SCHEME_MODERN;
+ CHECK( scratch->isWasdCamera() );
+
+ TheWritableGlobalData = saved;
+ delete scratch;
+}
+
TEST(order_lines_are_a_live_check_box_that_starts_on)
{
/* The lines are rebuilt from the units every frame, so the box takes effect at Accept, and a player
diff --git a/GeneralsMD/Code/Tests/test_minimap_input.inc b/GeneralsMD/Code/Tests/test_minimap_input.inc
index 926899dc3..8e973aada 100644
--- a/GeneralsMD/Code/Tests/test_minimap_input.inc
+++ b/GeneralsMD/Code/Tests/test_minimap_input.inc
@@ -39,7 +39,7 @@ public:
void draw() {}
View *createView() { return NULL; }
Bool scrolling = FALSE, selecting = FALSE, enabled = TRUE;
- void setScrolling(Bool value) { InGameUI::setScrolling(value); scrolling = value; }
+ void setScrolling(Bool value, Bool moveCursor = TRUE) { InGameUI::setScrolling(value, moveCursor); scrolling = value; }
Bool isScrolling() { return scrolling; }
Bool isSelecting() { return selecting; }
Bool getInputEnabled() { return enabled; }
diff --git a/GeneralsMD/Code/Tools/optionsmenu_layout.py b/GeneralsMD/Code/Tools/optionsmenu_layout.py
index faf724644..5a736789e 100644
--- a/GeneralsMD/Code/Tools/optionsmenu_layout.py
+++ b/GeneralsMD/Code/Tools/optionsmenu_layout.py
@@ -156,6 +156,7 @@ NEW_CONTROLS = [
(CHECK, "CheckParticleBounce", "GUI:ParticleBounce"),
(LABEL, "LabelInputScheme", "GUI:InputScheme"),
(COMBO, "ComboBoxInputScheme", None),
+ (CHECK, "CheckWasdCamera", "GUI:WasdCamera"),
]
# A slider on its own says nothing about where it stands, so each one has a readout beside it that
@@ -255,7 +256,8 @@ GROUP_LAYOUT = [
("check", "Retaliation"),
("check", "CheckDoubleClickAttackMove")]),
("PageControls", 2, "GUI:OptionsGroupInput", [
- setting("LabelInputScheme", "ComboBoxInputScheme")]),
+ setting("LabelInputScheme", "ComboBoxInputScheme"),
+ ("check", "CheckWasdCamera")]),
("PageGameplay", 0, "GUI:OptionsGroupBattlefield", [
setting("LabelHealthBars", "ComboBoxHealthBars"),