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): add grid command bar keys, attack move and idle worker

Olcay Seygan4d254693a2b5
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
index 792945072..4bcf1e1a3 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/GlobalData.h
@@ -323,6 +323,7 @@ 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_buildMapCache;
AsciiString m_initialFile; ///< If this is specified, load a specific map/replay from the command-line
AsciiString m_pendingFile; ///< If this is specified, use this map at the next game start
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
index 27b5755a4..68aff94d5 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/MessageStream.h
@@ -221,6 +221,24 @@ public:
MSG_META_SELECT_PREV_UNIT, ///< select 'prev' unit
MSG_META_SELECT_NEXT_WORKER, ///< select 'next' worker
MSG_META_SELECT_PREV_WORKER, ///< select 'prev' worker
+ MSG_META_SELECT_NEXT_IDLE_WORKER, ///< select 'next' idle worker
+
+ // command-bar grid hot keys: one per visible command button, laid out 7 columns x 2 rows
+ // (slot 01/02 = column 1 top/bottom, 03/04 = column 2, ... 13/14 = column 7)
+ MSG_META_COMMAND_SLOT01, ///< press command bar slot 01
+ MSG_META_COMMAND_SLOT02, ///< press command bar slot 02
+ MSG_META_COMMAND_SLOT03, ///< press command bar slot 03
+ MSG_META_COMMAND_SLOT04, ///< press command bar slot 04
+ MSG_META_COMMAND_SLOT05, ///< press command bar slot 05
+ MSG_META_COMMAND_SLOT06, ///< press command bar slot 06
+ MSG_META_COMMAND_SLOT07, ///< press command bar slot 07
+ MSG_META_COMMAND_SLOT08, ///< press command bar slot 08
+ MSG_META_COMMAND_SLOT09, ///< press command bar slot 09
+ MSG_META_COMMAND_SLOT10, ///< press command bar slot 10
+ MSG_META_COMMAND_SLOT11, ///< press command bar slot 11
+ MSG_META_COMMAND_SLOT12, ///< press command bar slot 12
+ MSG_META_COMMAND_SLOT13, ///< press command bar slot 13
+ MSG_META_COMMAND_SLOT14, ///< press command bar slot 14
MSG_META_VIEW_COMMAND_CENTER, ///< center view on command center
MSG_META_VIEW_LAST_RADAR_EVENT, ///< center view on last radar event
MSG_META_SELECT_HERO, ///< selects player's hero character, if exists...
diff --git a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
index a559b496c..3011783ce 100644
--- a/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
+++ b/GeneralsMD/Code/GameEngine/Include/Common/UserPreferences.h
@@ -108,6 +108,7 @@ public:
Int getIdealStaticGameDetail(void); // detail level detected for user.
Real getGammaValue(void);
Real getMaxCameraHeight(void);
+ Bool getUseGridHotKeys(void);
Int getTextureReduction(void);
void getResolution(Int *xres, Int *yres);
Bool get3DShadowsEnabled(void);
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
index fee923ff9..0b11b798c 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h
@@ -683,6 +683,10 @@ public:
GadgetGameMessage gadgetMessage );
+ /** press a command bar button by its slot index (0..MAX_COMMANDS_PER_SET-1), exactly as
+ a mouse click would. This is what the COMMAND_SLOTnn grid keys are wired to. */
+ void pressCommandButton( Int index );
+
/// is the drawable the currently selected drawable for the context sensitive UI?
Bool isDrivingContextUI( Drawable *draw ) const { return draw == m_currentSelectedDrawable; }
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
index d73aecd5b..2f0b67879 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GameLOD.cpp
@@ -363,6 +363,9 @@ void GameLODManager::init(void)
// every preset, floored at the GameData.ini value (see getMaxCameraHeight).
TheWritableGlobalData->m_maxCameraHeight = optionPref.getMaxCameraHeight();
+ // Grid command-bar keys are an input scheme, not a detail level either.
+ TheWritableGlobalData->m_useGridHotKeys = optionPref.getUseGridHotKeys();
+
setStaticLODLevel(userSetDetail);
}
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
index d9ad94723..eb96cac69 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/GlobalData.cpp
@@ -180,6 +180,7 @@ 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 ) },
{ "MinCameraHeight", INI::parseReal, NULL, offsetof( GlobalData, m_minCameraHeight ) },
{ "TerrainHeightAtEdgeOfMap", INI::parseReal, NULL, offsetof( GlobalData, m_terrainHeightAtEdgeOfMap ) },
{ "UnitDamagedThreshold", INI::parseReal, NULL, offsetof( GlobalData, m_unitDamagedThresh ) },
@@ -980,6 +981,7 @@ GlobalData::GlobalData()
m_scrollAmountCutoff = 10.0f;
m_cameraAdjustSpeed = 0.1f;
m_enforceMaxCameraHeight = TRUE;
+ m_useGridHotKeys = FALSE;
m_animateWindows = TRUE;
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
index 77339a362..0fdbcef2b 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/MessageStream.cpp
@@ -332,6 +332,21 @@ AsciiString GameMessage::getCommandTypeAsAsciiString(GameMessage::Type t)
CHECK_IF(MSG_META_SELECT_PREV_UNIT)
CHECK_IF(MSG_META_SELECT_NEXT_WORKER)
CHECK_IF(MSG_META_SELECT_PREV_WORKER)
+ CHECK_IF(MSG_META_SELECT_NEXT_IDLE_WORKER)
+ CHECK_IF(MSG_META_COMMAND_SLOT01)
+ CHECK_IF(MSG_META_COMMAND_SLOT02)
+ CHECK_IF(MSG_META_COMMAND_SLOT03)
+ CHECK_IF(MSG_META_COMMAND_SLOT04)
+ CHECK_IF(MSG_META_COMMAND_SLOT05)
+ CHECK_IF(MSG_META_COMMAND_SLOT06)
+ CHECK_IF(MSG_META_COMMAND_SLOT07)
+ CHECK_IF(MSG_META_COMMAND_SLOT08)
+ CHECK_IF(MSG_META_COMMAND_SLOT09)
+ CHECK_IF(MSG_META_COMMAND_SLOT10)
+ CHECK_IF(MSG_META_COMMAND_SLOT11)
+ CHECK_IF(MSG_META_COMMAND_SLOT12)
+ CHECK_IF(MSG_META_COMMAND_SLOT13)
+ CHECK_IF(MSG_META_COMMAND_SLOT14)
CHECK_IF(MSG_META_VIEW_COMMAND_CENTER)
CHECK_IF(MSG_META_VIEW_LAST_RADAR_EVENT)
CHECK_IF(MSG_META_SELECT_HERO)
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
index b487e33d7..842687aa0 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp
@@ -36,6 +36,7 @@
#define DEFINE_RADIUSCURSOR_NAMES
#include "Common/ActionManager.h"
+#include "Common/GameAudio.h"
#include "Common/GameType.h"
#include "Common/MultiplayerSettings.h"
#include "Common/NameKeyGenerator.h"
@@ -78,6 +79,8 @@
#include "GameClient/ControlBarResizer.h"
#include "GameClient/GadgetListBox.h"
#include "GameClient/HotKey.h"
+#include "GameClient/Keyboard.h"
+#include "GameClient/MetaEvent.h"
#include "GameClient/GameWindowTransitions.h"
#include "GameClient/GUICallbacks.h"
@@ -134,6 +137,38 @@ static void commandButtonTooltip(GameWindow *window,
TheControlBar->showBuildTooltipLayout(window);
}
+//-------------------------------------------------------------------------------------------------
+/** 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,
+ and a disabled one just makes the rejection noise. */
+//-------------------------------------------------------------------------------------------------
+void ControlBar::pressCommandButton( Int index )
+{
+ if( index < 0 || index >= MAX_COMMANDS_PER_SET )
+ return;
+
+ GameWindow *win = m_commandWindows[ index ];
+ if( win == NULL || BitTest( win->winGetStatus(), WIN_STATUS_HIDDEN ) )
+ return;
+
+ if( BitTest( win->winGetStatus(), WIN_STATUS_ENABLED ) )
+ {
+ TheWindowManager->winSendSystemMsg( win->winGetParent(), GBM_SELECTED,
+ (WindowMsgData)win, win->winGetWindowId() );
+
+ AudioEventRTS buttonClick( "GUIClick" );
+ if( TheAudio )
+ TheAudio->addAudioEvent( &buttonClick );
+ }
+ else
+ {
+ AudioEventRTS disabledClick( "GUIClickDisabled" );
+ if( TheAudio )
+ TheAudio->addAudioEvent( &disabledClick );
+ }
+
+} // end pressCommandButton
+
/// mark the UI as dirty so the context of everything is re-evaluated
void ControlBar::markUIDirty( void )
{
@@ -2423,6 +2458,42 @@ void ControlBar::setCommandBarBorder( GameWindow *button, CommandButtonMappedBor
//-------------------------------------------------------------------------------------------------
/** Set the command data into the control */
+//-------------------------------------------------------------------------------------------------
+//-------------------------------------------------------------------------------------------------
+/** The letter currently bound to command bar slot 'slot' (0 based), or an empty string when the
+ slot has no unmodified binding. Read live out of the meta map so rebinding the key in
+ Options > Keyboard re-labels the button. */
+//-------------------------------------------------------------------------------------------------
+static UnicodeString getGridHotKeyLabel( Int slot )
+{
+ UnicodeString label;
+
+ if( TheMetaMap == NULL || TheKeyboard == NULL )
+ return label;
+
+ GameMessage::Type wanted = (GameMessage::Type)(GameMessage::MSG_META_COMMAND_SLOT01 + slot);
+ for( const MetaMapRec *rec = TheMetaMap->getFirstMetaMapRec(); rec; rec = rec->m_next )
+ {
+ // only a plain, unmodified key makes a readable one character label
+ if( rec->m_meta != wanted || rec->m_modState != 0 )
+ continue;
+
+ WideChar c = TheKeyboard->getPrintableKey( (UnsignedByte)rec->m_key, 0 );
+ if( c )
+ {
+ if( c >= L'a' && c <= L'z' )
+ c -= (L'a' - L'A');
+
+ WideChar text[ 2 ] = { c, 0 };
+ label.set( text );
+ }
+ break;
+ }
+
+ return label;
+
+} // end getGridHotKeyLabel
+
//-------------------------------------------------------------------------------------------------
void ControlBar::setControlCommand( GameWindow *button, const CommandButton *commandButton )
{
@@ -2493,12 +2564,36 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *com
setCommandBarBorder(button, commandButton->getCommandButtonMappedBorderType());
- if (TheHotKeyManager)
+ // 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 )
+ {
+ // 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;
+
+ UnicodeString label = getGridHotKeyLabel( slot );
+ if( label.isEmpty() )
+ button->winClearStatus( WIN_STATUS_SHORTCUT_BUTTON );
+ else
+ button->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );
+
+ GadgetButtonSetText( button, label );
+ break;
+ }
+ }
GadgetButtonSetAltSound(button, "GUICommandBarClick");
} // end setControlCommand
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 cb3039d63..dd4a92449 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/OptionsMenu.cpp
@@ -724,6 +724,18 @@ Real OptionPreferences::getMaxCameraHeight(void)
return height;
}
+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;
+}
+
Int OptionPreferences::getTextureReduction(void)
{
OptionPreferences::const_iterator it = find("TextureReduction");
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
index 6b0fcc693..2a0f9a1a6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/CommandXlat.cpp
@@ -2594,6 +2594,42 @@ GameMessageDisposition CommandTranslator::translateGameMessage(const GameMessage
} // end select previous unit
//-----------------------------------------------------------------------------------------
+ //-----------------------------------------------------------------------------------------
+ case GameMessage::MSG_META_SELECT_NEXT_IDLE_WORKER:
+ {
+ // same list the control bar's idle-worker button cycles; when every dozer and worker
+ // has a job the list is empty and selectNextIdleWorker returns without doing anything.
+ TheInGameUI->selectNextIdleWorker();
+
+ disp = DESTROY_MESSAGE;
+ break;
+ } // end select next idle worker
+
+ case GameMessage::MSG_META_COMMAND_SLOT01:
+ case GameMessage::MSG_META_COMMAND_SLOT02:
+ case GameMessage::MSG_META_COMMAND_SLOT03:
+ case GameMessage::MSG_META_COMMAND_SLOT04:
+ case GameMessage::MSG_META_COMMAND_SLOT05:
+ case GameMessage::MSG_META_COMMAND_SLOT06:
+ case GameMessage::MSG_META_COMMAND_SLOT07:
+ case GameMessage::MSG_META_COMMAND_SLOT08:
+ case GameMessage::MSG_META_COMMAND_SLOT09:
+ case GameMessage::MSG_META_COMMAND_SLOT10:
+ case GameMessage::MSG_META_COMMAND_SLOT11:
+ case GameMessage::MSG_META_COMMAND_SLOT12:
+ 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;
+ }
+ break;
+ } // end command bar grid slots
+
case GameMessage::MSG_META_SELECT_NEXT_WORKER:
{
/* because list is prepended, iterate through backwards */
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
index 5bd5734b0..6993ff4ad 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/MessageStream/MetaEvent.cpp
@@ -138,6 +138,21 @@ static const LookupListRec GameMessageMetaTypeNames[] =
{ "SELECT_PREV_UNIT", GameMessage::MSG_META_SELECT_PREV_UNIT },
{ "SELECT_NEXT_WORKER", GameMessage::MSG_META_SELECT_NEXT_WORKER },
{ "SELECT_PREV_WORKER", GameMessage::MSG_META_SELECT_PREV_WORKER },
+ { "SELECT_NEXT_IDLE_WORKER", GameMessage::MSG_META_SELECT_NEXT_IDLE_WORKER },
+ { "COMMAND_SLOT01", GameMessage::MSG_META_COMMAND_SLOT01 },
+ { "COMMAND_SLOT02", GameMessage::MSG_META_COMMAND_SLOT02 },
+ { "COMMAND_SLOT03", GameMessage::MSG_META_COMMAND_SLOT03 },
+ { "COMMAND_SLOT04", GameMessage::MSG_META_COMMAND_SLOT04 },
+ { "COMMAND_SLOT05", GameMessage::MSG_META_COMMAND_SLOT05 },
+ { "COMMAND_SLOT06", GameMessage::MSG_META_COMMAND_SLOT06 },
+ { "COMMAND_SLOT07", GameMessage::MSG_META_COMMAND_SLOT07 },
+ { "COMMAND_SLOT08", GameMessage::MSG_META_COMMAND_SLOT08 },
+ { "COMMAND_SLOT09", GameMessage::MSG_META_COMMAND_SLOT09 },
+ { "COMMAND_SLOT10", GameMessage::MSG_META_COMMAND_SLOT10 },
+ { "COMMAND_SLOT11", GameMessage::MSG_META_COMMAND_SLOT11 },
+ { "COMMAND_SLOT12", GameMessage::MSG_META_COMMAND_SLOT12 },
+ { "COMMAND_SLOT13", GameMessage::MSG_META_COMMAND_SLOT13 },
+ { "COMMAND_SLOT14", GameMessage::MSG_META_COMMAND_SLOT14 },
{ "SELECT_HERO", GameMessage::MSG_META_SELECT_HERO },
{ "SELECT_ALL", GameMessage::MSG_META_SELECT_ALL },
{ "SELECT_ALL_AIRCRAFT", GameMessage::MSG_META_SELECT_ALL_AIRCRAFT },
@@ -145,6 +160,7 @@ static const LookupListRec GameMessageMetaTypeNames[] =
{ "VIEW_LAST_RADAR_EVENT", GameMessage::MSG_META_VIEW_LAST_RADAR_EVENT },
{ "SCATTER", GameMessage::MSG_META_SCATTER },
{ "STOP", GameMessage::MSG_META_STOP },
+ { "TOGGLE_ATTACKMOVE", GameMessage::MSG_META_TOGGLE_ATTACKMOVE },
{ "DEPLOY", GameMessage::MSG_META_DEPLOY },
{ "CREATE_FORMATION", GameMessage::MSG_META_CREATE_FORMATION },
{ "FOLLOW", GameMessage::MSG_META_FOLLOW },
diff --git a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
index 51e898f85..0bfba66e2 100644
--- a/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
+++ b/GeneralsMD/Code/GameEngineDevice/Source/W3DDevice/GameClient/GUI/Gadget/W3DPushButton.cpp
@@ -138,6 +138,14 @@ static void drawButtonText( GameWindow *window, WinInstanceData *instData )
textPos.y = origin.y + (size.y / 2) - (height / 2);
}
+ // Shortcut text sits on top of the button's own art, which can be any colour at all -
+ // a light unit portrait swallowed the letter. Lay a translucent black plate under it.
+ if( BitTest( window->winGetStatus(), WIN_STATUS_SHORTCUT_BUTTON ) && width > 0 && height > 0 )
+ {
+ TheDisplay->drawFillRect( textPos.x - 2, textPos.y, width + 4, height,
+ GameMakeColor( 0, 0, 0, 160 ) );
+ }
+
// draw it
text->draw( textPos.x, textPos.y, textColor, dropColor );