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
fix(gameengine): show cancel and unit-drop controls on the grid
Olcay Seygana3ceb219089a
diff --git a/CHANGELOG.md b/CHANGELOG.mdindex ad6e78bba..1e25e323e 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -644,6 +644,7 @@ A third pass went through the generals' powers, promotions and unit abilities.- The top of the screen is battlefield. The players, their teams, their superweapons with the seconds left and the match clock are all on Tab, which already had every one of them, so the column of superweapon countdowns that used to sit in the top right is gone while you play, and so is a strip of flags that repeated the scoreboard across the top edge.- The steel between the build buttons, the portrait's grid and the promotion screen's cells is half as wide as it was, so the pictures take the room. The queue's tray has a thinner rim. The portrait and its upgrade icons sit under the portrait's grid, framed the same way as every other picture on the bar.- The command bar slides up from the bottom of the screen again when a match starts. The new steel frame had been drawn at its final place from the first frame, so the buttons rose into a frame that was already standing.+- A building that is still going up shows Cancel on S, and the seconds it has left across the top of the grid. A map building that hands out units shows that countdown there too, with the bar under it. Sell stands on N. One that sets a rally point puts that on B instead. Both used to stay where the old command panel had drawn them, off the new grid.- The Escape menu is in the bar's steel too: a plate in your side's colour, no bigger than its keys, in the middle of the screen, the keys sunk in a well and lit gold under the pointer and pressed in when clicked. The Generals logo that took the top third of it is gone. It comes up over a dimmed battlefield: the screen darkens as the plate fades in, then the keys fade in top to bottom out of nothing, each lit bright in your side's own steel for a moment as it lands: pale steel for America, red for China, sand for the GLA. A single-player game stutters for half a second as it pauses under the menu, and the fade no longer races through in those few frames: the keys used to seem to pop up at once there. The old menu's flash used to light up a patch of the screen where the old, bigger menu had stood; that is gone, and the menu closes at once. The promotion screen opens across the middle of the screen. Restart reads Surrender or Restart Mission as the game you are in calls for.## Placing buildingsdiff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.hindex 0e6e23f16..622e50792 100644--- a/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/ControlBar.h@@ -818,7 +818,9 @@ public:/** press the command at grid place `place` (a CommandPlace), exactly as a mouse click would.This is what the COMMAND_SLOTnn grid keys are wired to. Where the place holds one of theorders every unit shares, or nothing, the key sends that order's own message, the one its- key sent before the grid took it: A force fire, S stop, D attack move, X guard, C hold. */+ key sent before the grid took it: A force fire, S stop, D attack move, X guard, C hold.+ A building going up and a building counting down to a unit answer from their own button+ when the command group is hidden. */void pressCommandButton( Int place );/** The place each command window stands at right now, -1 for a hidden one, and whether the@@ -828,6 +830,9 @@ public:/** paint each command window's key, its place's, in its top left corner; `places` as above */void labelCommandPlaces( const Int *places );+ /** paint `button`'s key, the one `place` is bound to. `place` below 0 clears it. */+ void labelPlaceButton( GameWindow *button, Int place );+/** The general's powers are laid out SPECIAL_POWER_SHORTCUT_COLS to a row, so one key presscannot reach eleven of them. The first press picks a row (F1 is the row in the corner,F2 the one above it) and the second picks a power inside that row (F1 is the rightmost),@@ -1097,6 +1102,12 @@ public:* they were on screen. The place layoutPanels recorded for it moves with it, so a rebuild of the* layout reads the window as put there and not as moved in the loader's stretched space. */void placeWindowAt( GameWindow *window, const IRegion2D &rect );++ /** A context that hides the command group still has its own button, and it stands where that+ command stands on a finished building: cancel on S, sell on N, the rally point on B. The+ countdown keeps the top row and a reinforcement pad's bar the middle one. `cells` is one+ screen rect per CommandPlace, and `taken` gains the button's place so the page draws its cell. */+ void placeContextOnGrid( const IRegion2D &frame, const IRegion2D *cells, Bool *taken );GameWindow *getSpecialPowerShortcutParent( void ) { return m_specialPowerShortcutParent; }/// a multi-selection's type cells, one a selected type, shown or hidden; see updateMultiSelectStripconst std::vector< GameWindow * > &getMultiSelectTiles( void ) const { return m_multiSelectTiles; }diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cppindex b4c1f150c..57597a3cc 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/ControlBar/ControlBar.cpp@@ -184,6 +184,44 @@ static GameMessage::Type orderAtPlace( Int place )return GameMessage::MSG_INVALID;}+//-------------------------------------------------------------------------------------------------+static GameWindow *barWindow( const char *name )+{+ return TheWindowManager->winGetWindowFromId( NULL, TheNameKeyGenerator->nameToKey( name ) );+}++/** Shown, and every parent of it shown. winIsHidden stops at the window itself, and a context+ parent hides its buttons by hiding itself. */+static Bool barWindowShown( GameWindow *window )+{+ if( window == NULL || window->winIsHidden() )+ return FALSE;+ for( GameWindow *parent = window->winGetParent(); parent; parent = parent->winGetParent() )+ if( parent->winIsHidden() )+ return FALSE;+ return TRUE;+}++/** The button a hidden command group still offers at `place`: cancel while a building goes up,+ sell or the rally point on a building counting down to a unit. */+static GameWindow *contextButtonAtPlace( Int place )+{+ if( place == COMMAND_PLACE_STOP )+ {+ GameWindow *cancel = barWindow( "ControlBar.wnd:ButtonCancelConstruction" );+ if( barWindowShown( cancel ) )+ return cancel;+ }++ GameWindow *sell = barWindow( "ControlBar.wnd:OCLTimerSellButton" );+ if( !barWindowShown( sell ) )+ return NULL;+ const CommandButton *command = (const CommandButton *)GadgetButtonGetData( sell );+ if( command && fixedCommandPlace( command->getCommandType() ) == place )+ return sell;+ return NULL;+}+//-------------------------------------------------------------------------------------------------/** What a set builds, which takes the free places before the rest of the set. */static Bool isProduction( Int type )@@ -263,8 +301,9 @@ Bool ControlBar_commandPlaces( const Int *types, const Int *pinned, Int count, I//-------------------------------------------------------------------------------------------------Bool ControlBar::getCommandPlaces( Int *places ) const{- // a context without the command group (nothing selected, a building going up, a beacon) hides the- // group's parent and leaves the buttons as the last selection set them: those are not on the bar+ // a context without the command group hides the group's parent. Its buttons stay as the last+ // selection set them and are not on the bar. A building going up and one counting down to a+ // unit put their own button on the grid in placeContextOnGrid.const Bool groupShown = !m_contextParent[ CP_COMMAND ]->winIsHidden();Int types[ MAX_COMMANDS_PER_SET ];Int pinned[ MAX_COMMANDS_PER_SET ];@@ -319,6 +358,8 @@ void ControlBar::pressCommandButton( Int place )const Int slot = resolveCommandSlot( place );GameWindow *win = ( slot == SLOT_NOTHING ) ? NULL : m_commandWindows[ slot ];+ if( win == NULL )+ win = contextButtonAtPlace( place );const CommandButton *command = win ? (const CommandButton *)GadgetButtonGetData( win ) : NULL;const GameMessage::Type order = orderAtPlace( place );if( order != GameMessage::MSG_INVALID && ( command == NULL || fixedCommandPlace( command->getCommandType() ) == place ) )@@ -4883,26 +4924,91 @@ void ControlBar::setControlCommand( GameWindow *button, const CommandButton *com} // end setControlCommand//-------------------------------------------------------------------------------------------------+void ControlBar::labelPlaceButton( GameWindow *button, Int place )+{+ if( button == NULL )+ return;++ const UnicodeString label = place >= 0 ? getGridHotKeyLabel( place ) : UnicodeString();+ if( label.isEmpty() )+ button->winClearStatus( WIN_STATUS_SHORTCUT_BUTTON );+ else+ button->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );++ // every frame, so only a changed key goes to the button+ if( button->winGetText().compare( label ) != 0 )+ GadgetButtonSetText( button, label );++}+void ControlBar::labelCommandPlaces( const Int *places ){for( Int slot = 0; slot < MAX_COMMANDS_PER_SET; slot++ )+ labelPlaceButton( m_commandWindows[ slot ], places[ slot ] );++} // end labelCommandPlaces++//-------------------------------------------------------------------------------------------------+static IRegion2D spanCells( const IRegion2D *cells, Int first, Int last )+{+ IRegion2D span = cells[ first ];+ span.hi.x = cells[ last ].hi.x;+ if( cells[ last ].lo.y < span.lo.y )+ span.lo.y = cells[ last ].lo.y;+ if( cells[ last ].hi.y > span.hi.y )+ span.hi.y = cells[ last ].hi.y;+ return span;+}++void ControlBar::placeContextOnGrid( const IRegion2D &frame, const IRegion2D *cells, Bool *taken )+{+ // the command group is up, so its own buttons already fill the grid+ if( m_contextParent[ CP_COMMAND ] && !m_contextParent[ CP_COMMAND ]->winIsHidden() )+ return;++ GameWindow *building = m_contextParent[ CP_UNDER_CONSTRUCTION ];+ if( building && !building->winIsHidden() ){- GameWindow *button = m_commandWindows[ slot ];- if( button == NULL )- continue;+ // the parent has to cover the cell or the click never arrives+ placeWindowAt( building, frame );+ GameWindow *cancel = barWindow( "ControlBar.wnd:ButtonCancelConstruction" );+ if( barWindowShown( cancel ) )+ {+ taken[ COMMAND_PLACE_STOP ] = TRUE;+ placeWindowAt( cancel, cells[ COMMAND_PLACE_STOP ] );+ labelPlaceButton( cancel, COMMAND_PLACE_STOP );+ }+ GameWindow *desc = barWindow( "ControlBar.wnd:UnderConstructionDesc" );+ if( barWindowShown( desc ) )+ placeWindowAt( desc, spanCells( cells, COMMAND_PLACE_Q, COMMAND_PLACE_Y ) );+ return;+ }- const UnicodeString label = places[ slot ] >= 0 ? getGridHotKeyLabel( places[ slot ] ) : UnicodeString();- if( label.isEmpty() )- button->winClearStatus( WIN_STATUS_SHORTCUT_BUTTON );- else- button->winSetStatus( WIN_STATUS_SHORTCUT_BUTTON );+ GameWindow *timer = m_contextParent[ CP_OCL_TIMER ];+ if( timer == NULL || timer->winIsHidden() )+ return;- // every frame, so only a changed key goes to the button- if( button->winGetText().compare( label ) != 0 )- GadgetButtonSetText( button, label );+ placeWindowAt( timer, frame );+ GameWindow *sell = barWindow( "ControlBar.wnd:OCLTimerSellButton" );+ if( barWindowShown( sell ) )+ {+ const CommandButton *command = (const CommandButton *)GadgetButtonGetData( sell );+ const Int where = command ? fixedCommandPlace( command->getCommandType() ) : -1;+ if( where >= 0 )+ {+ taken[ where ] = TRUE;+ placeWindowAt( sell, cells[ where ] );+ labelPlaceButton( sell, where );+ }}+ GameWindow *text = barWindow( "ControlBar.wnd:OCLTimerStaticText" );+ if( barWindowShown( text ) )+ placeWindowAt( text, spanCells( cells, COMMAND_PLACE_Q, COMMAND_PLACE_Y ) );+ GameWindow *bar = barWindow( "ControlBar.wnd:OCLTimerProgressBar" );+ if( barWindowShown( bar ) )+ placeWindowAt( bar, spanCells( cells, COMMAND_PLACE_A, COMMAND_PLACE_H ) );-} // end labelCommandPlaces+} // end placeContextOnGrid//-------------------------------------------------------------------------------------------------void CommandButton::cacheButtonImage()diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cppindex 925ac91e3..3f368c74f 100644--- a/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/InGameUI.cpp@@ -11711,13 +11711,18 @@ Bool InGameUI::drawControlBarPage( const IRegion2D *panels, const Bool *shown, ITheControlBar->placeWindowAt( controlBarWindow( "CenterBackground" ), frameRect );TheControlBar->placeWindowAt( controlBarWindow( "CommandWindow" ), frameRect );- // a cell only for a place a command stands in; an empty one is the panel's steel+ // a cell only for a place a command stands in; an empty one is the panel's steel. A building+ // going up and one counting down to a unit hide the command group, and their own button takes+ // its place before the cells are drawnIRegion2D place[ COMMAND_PLACE_COUNT ];- std::vector< HtmlValues > &commandCells = lists[ "commandcells" ];for( Int each = 0; each < COMMAND_PLACE_COUNT; each++ )- {place[ each ] = gridCell( commandBox, each % COMMAND_COLUMNS, each / COMMAND_COLUMNS,COMMAND_CELL_WIDTH, COMMAND_CELL_HEIGHT );+ if( centreShown )+ TheControlBar->placeContextOnGrid( frameRect, place, taken );+ std::vector< HtmlValues > &commandCells = lists[ "commandcells" ];+ for( Int each = 0; each < COMMAND_PLACE_COUNT; each++ )+ {if( !centreShown || !taken[ each ] )continue;HtmlValues entry;