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): split a builder's structures across two hotkey pages
Olcay Seygan128d48127e5b
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 0b11b798c..7922299d9 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -215,6 +215,7 @@ enum GUICommandTypeGUI_COMMAND_SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT, ///< do a shortcut special power using the construct building interfaceGUI_COMMAND_SELECT_ALL_UNITS_OF_TYPE,+ GUI_COMMAND_BUILD_PAGE, ///< switch the command bar between the builder's structure pages// add more commands here, don't forget to update the string command list below too ...@@ -265,6 +266,7 @@ static const char *TheGuiCommandNames[] ="SPECIAL_POWER_CONSTRUCT","SPECIAL_POWER_CONSTRUCT_FROM_SHORTCUT","SELECT_ALL_UNITS_OF_TYPE",+ "BUILD_PAGE",NULL};@@ -364,6 +366,8 @@ public:// only for ControlBar!void friend_addToList(CommandButton** list) { m_next = *list; *list = this; }+ void friend_setCommandType(GUICommandType c) { m_command = c; }+ void friend_setBorderType(CommandButtonMappedBorderType t) { m_commandButtonBorder = t; }CommandButton* friend_getNext() { return m_next; }private:@@ -687,6 +691,14 @@ public:a mouse click would. This is what the COMMAND_SLOTnn grid keys are wired to. */void pressCommandButton( Int index );+ /** A builder with more structures than BUILD_PAGE_ONE_SIZE does not show them all at once.+ The command bar opens on two menu buttons instead - the first grid keys, Q and W - and+ each one opens its own page of structures, so a structure is two keystrokes away (Q-Q,+ Q-W, ... W-Q, ...) instead of competing for the fourteen slots. Page one holds the+ first BUILD_PAGE_ONE_SIZE structures of the command set, page two holds the rest. */+ enum { BUILD_PAGE_ROOT = -1, BUILD_PAGE_COUNT = 2, BUILD_PAGE_ONE_SIZE = 4 };+ void setBuildPage( Int page );+/// is the drawable the currently selected drawable for the context sensitive UI?Bool isDrivingContextUI( Drawable *draw ) const { return draw == m_currentSelectedDrawable; }@@ -834,6 +846,8 @@ protected:static void populateButtonProc( Object *obj, void *userData );void populatePurchaseScience(Player* player);void populateCommand( Object *obj );+ void buildCommandLayout( Object *obj, const CommandSet *commandSet, const CommandButton **slot );+ void makeBuildPageButtons( void );void populateMultiSelect( void );void populateBuildQueue( Object *producer );void populateStructureInventory( Object *building );@@ -923,6 +937,11 @@ protected:GameWindow *m_commandWindows[ MAX_COMMANDS_PER_SET ]; ///< command window controls for easy accessconst CommandButton *m_commonCommands[ MAX_COMMANDS_PER_SET ]; ///< shared commands we will use for multi-selection+ CommandButton *m_buildPageButton[ BUILD_PAGE_COUNT ]; ///< the two menu buttons a paged builder opens on+ CommandButton *m_buildPageBackButton; ///< takes a page back to the menu buttons+ Int m_buildPage; ///< BUILD_PAGE_ROOT, or the page being shown+ ObjectID m_buildPageObjectID; ///< builder the page belongs to; a new one starts at the menu+// removed from multiplayer branch//GameWindow *m_commandMarkers[ MAX_COMMANDS_PER_SET ]; ///< When we don't have a command, they want to show an image// removed from multiplayer branchdiff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex 842687aa0..cb60a9e47 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -169,6 +169,44 @@ void ControlBar::pressCommandButton( Int index )} // end pressCommandButton+//-------------------------------------------------------------------------------------------------+/** Build the menu and back buttons a paged builder shows. They carry no thing template and no+ text label of their own - the page they open is told by the cameo of its first structure, and+ by the grid letter setControlCommand paints in the corner. */+//-------------------------------------------------------------------------------------------------+void ControlBar::makeBuildPageButtons( void )+{+ AsciiString name;+ for( Int page = 0; page < BUILD_PAGE_COUNT; page++ )+ {+ name.format( "NonCommand_BuildPage%d", page + 1 );+ m_buildPageButton[ page ] = newCommandButton( name );+ m_buildPageButton[ page ]->friend_setCommandType( GUI_COMMAND_BUILD_PAGE );+ m_buildPageButton[ page ]->friend_setBorderType( COMMAND_BUTTON_BORDER_SYSTEM );+ }++ m_buildPageBackButton = newCommandButton( AsciiString( "NonCommand_BuildPageBack" ) );+ m_buildPageBackButton->friend_setCommandType( GUI_COMMAND_BUILD_PAGE );+ m_buildPageBackButton->friend_setBorderType( COMMAND_BUTTON_BORDER_SYSTEM );++} // end makeBuildPageButtons++//-------------------------------------------------------------------------------------------------+/** Show 'page' of the selected builder's structures, BUILD_PAGE_ROOT for the menu buttons. */+//-------------------------------------------------------------------------------------------------+void ControlBar::setBuildPage( Int page )+{+ if( page < BUILD_PAGE_ROOT || page >= BUILD_PAGE_COUNT )+ page = BUILD_PAGE_ROOT;++ if( m_buildPage == page )+ return;++ m_buildPage = page;+ markUIDirty();++} // end setBuildPage+/// mark the UI as dirty so the context of everything is re-evaluatedvoid ControlBar::markUIDirty( void ){@@ -966,6 +1004,11 @@ ControlBar::ControlBar( void )m_communicatorButton = NULL;m_currentSelectedDrawable = NULL;m_currContext = CB_CONTEXT_NONE;+ for( i = 0; i < BUILD_PAGE_COUNT; i++ )+ m_buildPageButton[ i ] = NULL;+ m_buildPageBackButton = NULL;+ m_buildPage = BUILD_PAGE_ROOT;+ m_buildPageObjectID = INVALID_ID;m_rallyPointDrawableID = INVALID_DRAWABLE_ID;m_displayedConstructPercent = -1.0f;m_displayedOCLTimerSeconds = 0;@@ -1096,6 +1139,9 @@ void ControlBar::init( void )// post process step after loading the command buttons and command setspostProcessCommands();+ // the builder's page menu buttons are ours, not the data's+ makeBuildPageButtons();+// Init the scheme manager, this will call it's won INI init funciton.m_controlBarSchemeManager = NEW ControlBarSchemeManager;m_controlBarSchemeManager->init();@@ -1339,6 +1385,9 @@ void ControlBar::reset( void )m_displayedConstructPercent = -1.0f;m_displayedOCLTimerSeconds = 0;+ m_buildPage = BUILD_PAGE_ROOT;+ m_buildPageObjectID = INVALID_ID;+m_isObserverCommandBar = FALSE; // reset us to use a normal command barm_observerLookAtPlayer = NULL;@@ -2556,7 +2605,12 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *combutton->winSetTooltipFunc(commandButtonTooltip);}else+ {+ // a button with no label has no build tooltip either - clear the func, the window is+ // recycled and would otherwise keep the one the previous occupant installed.+ button->winSetTooltipFunc( NULL );GadgetButtonSetText( button, UnicodeString( L"" ) );+ }// save the command in the user data of the windowGadgetButtonSetData(button, (void*)commandButton);diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cppindex a5777b858..ccc2dec7e 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommand.cpp@@ -59,6 +59,7 @@#include "GameClient/GameWindow.h"#include "GameClient/GameWindowManager.h"#include "GameClient/GadgetPushButton.h"+#include "GameClient/Image.h"#ifdef _INTERNAL// for occasional debugging...@@ -265,6 +266,113 @@ void ControlBar::doTransportInventoryUI( Object *transport, const CommandSet *co} // end doTransportInventoryUI+//-------------------------------------------------------------------------------------------------+/** The command bar is two rows of seven, and the grid keys run along the top row first:+ slot 0 is Q, slot 2 is W, slot 4 is E and so on to slot 12 for U, then the bottom row+ from slot 1 for Z through slot 13 for M. A build page lays its structures out along+ that order so the first four of them are Q, W, E and R. Slot 1 (Z) is left out - it is+ where the back button sits. */+//-------------------------------------------------------------------------------------------------+static const Int s_buildPageSlots[] = { 0, 2, 4, 6, 8, 10, 12, 3, 5, 7, 9, 11, 13 };+static const Int s_buildPageSlotCount = sizeof( s_buildPageSlots ) / sizeof( s_buildPageSlots[ 0 ] );+static const Int s_buildPageBackSlot = 1;++//-------------------------------------------------------------------------------------------------+/** Which command button belongs in each of the command bar's slots for this object. Normally+ that is just the command set, slot for slot. A builder with more structures than one page+ holds instead gets its structures replaced by the two page menu buttons, or - once a page is+ open - by that page's structures plus a button back to the menu. Commands that are not+ structures keep the slot the data gave them on every page. */+//-------------------------------------------------------------------------------------------------+void ControlBar::buildCommandLayout( Object *obj, const CommandSet *commandSet,+ const CommandButton **slot )+{+ Int i;++ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ slot[ i ] = commandSet->getCommandButton( i );++ //+ // the pages are worked with the grid keys, so without them a page would be a menu the+ // keyboard cannot reach. Leave the command set alone.+ //+ if( TheGlobalData->m_useGridHotKeys == FALSE || m_buildPageButton[ 0 ] == NULL )+ {+ m_buildPage = BUILD_PAGE_ROOT;+ return;+ }++ // a different builder starts at the menu rather than wherever the last one was left+ if( obj->getID() != m_buildPageObjectID )+ {+ m_buildPageObjectID = obj->getID();+ m_buildPage = BUILD_PAGE_ROOT;+ }++ // the structures, in command set order+ const CommandButton *structure[ MAX_COMMANDS_PER_SET ];+ Int structureCount = 0;+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ if( slot[ i ] != NULL && slot[ i ]->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT )+ structure[ structureCount++ ] = slot[ i ];++ // a set that already fits on one page has nothing to gain from a menu in front of it+ if( structureCount <= BUILD_PAGE_ONE_SIZE )+ {+ m_buildPage = BUILD_PAGE_ROOT;+ return;+ }++ // page two is whatever page one did not take+ Int pageFirst[ BUILD_PAGE_COUNT ], pageLast[ BUILD_PAGE_COUNT ];+ pageFirst[ 0 ] = 0;+ pageLast[ 0 ] = BUILD_PAGE_ONE_SIZE;+ pageFirst[ 1 ] = BUILD_PAGE_ONE_SIZE;+ pageLast[ 1 ] = structureCount;++ // the structures give their slots up; everything else in the set stays where it is+ for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )+ if( slot[ i ] != NULL && slot[ i ]->getCommandType() == GUI_COMMAND_DOZER_CONSTRUCT )+ slot[ i ] = NULL;++ // what the page puts on the bar, in the order the grid keys run+ const CommandButton *paged[ MAX_COMMANDS_PER_SET ];+ Int pagedCount = 0;+ if( m_buildPage == BUILD_PAGE_ROOT )+ {+ for( Int page = 0; page < BUILD_PAGE_COUNT; page++ )+ {+ // the menu button wears the cameo of the first structure behind it+ m_buildPageButton[ page ]->setButtonImage( structure[ pageFirst[ page ] ]->getButtonImage() );+ paged[ pagedCount++ ] = m_buildPageButton[ page ];+ }+ }+ else+ {+ if( TheMappedImageCollection != NULL && m_buildPageBackButton->getButtonImage() == NULL )+ m_buildPageBackButton->setButtonImage( TheMappedImageCollection->findImageByName( AsciiString( "SSStop" ) ) );+ if( slot[ s_buildPageBackSlot ] == NULL )+ slot[ s_buildPageBackSlot ] = m_buildPageBackButton;++ for( i = pageFirst[ m_buildPage ]; i < pageLast[ m_buildPage ]; i++ )+ paged[ pagedCount++ ] = structure[ i ];+ }++ // drop them into the free slots, keeping the grid key order+ Int next = 0;+ for( i = 0; i < s_buildPageSlotCount && next < pagedCount; i++ )+ {+ Int where = s_buildPageSlots[ i ];+ if( slot[ where ] != NULL )+ continue;+ slot[ where ] = paged[ next++ ];+ }++ DEBUG_ASSERTCRASH( next == pagedCount, ("buildCommandLayout: command set '%s' left %d structures with no slot to sit in\n",+ commandSet->getName().str(), pagedCount - next) );++} // end buildCommandLayout+//-------------------------------------------------------------------------------------------------//-------------------------------------------------------------------------------------------------void ControlBar::populateCommand( Object *obj )@@ -302,6 +410,10 @@ void ControlBar::populateCommand( Object *obj )if( obj->getContain() && obj->getContain()->isDisplayedOnControlBar() )doTransportInventoryUI( obj, commandSet );+ // what goes in each slot; a builder's structures may be spread across pages+ const CommandButton *slot[ MAX_COMMANDS_PER_SET ];+ buildCommandLayout( obj, commandSet, slot );+// populate the button with commands definedconst CommandButton *commandButton;for( i = 0; i < MAX_COMMANDS_PER_SET; i++ )@@ -310,7 +422,7 @@ void ControlBar::populateCommand( Object *obj )if (! m_commandWindows[ i ]) continue;// get command button- commandButton = commandSet->getCommandButton(i);+ commandButton = slot[ i ];// if button is not present, just hide the windowif( commandButton == NULL )diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cppindex 6b1d2242b..0520bef8b 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBarCommandProcessing.cpp@@ -169,6 +169,20 @@ CBCommandStatus ControlBar::processCommandUI( GameWindow *control,if( commandButton == NULL )return CBC_COMMAND_NOT_USED;+ //+ // a builder's page menu buttons only move the command bar between its own pages - none of+ // the command handling below applies to them, they never reach the game logic at all.+ //+ if( commandButton->getCommandType() == GUI_COMMAND_BUILD_PAGE )+ {+ Int page = BUILD_PAGE_ROOT;+ for( Int i = 0; i < BUILD_PAGE_COUNT; i++ )+ if( commandButton == m_buildPageButton[ i ] )+ page = i;+ setBuildPage( page );+ return CBC_COMMAND_USED;+ }+// if the button is flashing, tell it to stop flashingcommandButton->setFlashCount(0);TheControlBar->setFlash( FALSE );