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): side boxes and one-click side random on the army screen

Olcay Seygan7d40bdba2fec
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4ac0c115a..d275d9269 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -22,7 +22,7 @@ found and fixed — EA's own, not port damage.**
## An army screen in every lobby
- Click a seat's army in the skirmish, LAN or online room and a full screen opens in place of the drop-down list. Every army stands on it under its side's heading, USA, China, GLA and Turkiye, with a large portrait of the one you click, its name across a banner, what it is built to do and what it brings. Confirm takes the army; Back or Escape leaves the seat as it was. The host picks for the computer seats the same way, and nobody can open another player's seat.
-- Random gets a pool you choose. Custom Selection puts a tick box on every army, and Random then draws only from the ticked ones: tick China and its three generals and you play Chinese every game, which one is a surprise. With Random focused, the portrait shows every army it can be, lit when it is in the draw and dimmed when it is not. Everyone in the room draws from the same pool, the replay too, so a game never splits over it, and the skirmish room keeps your pool for the next match.
+- Random gets a pool you choose. Custom Selection puts a tick box on every army, and Random then draws only from the ticked ones: tick China and its three generals and you play Chinese every game, which one is a surprise. Each side's heading carries a box that ticks or clears the whole side, and a click on the side's name leaves it alone in the draw, so "Random USA" is one click. With Random focused, the portrait shows every army it can be, lit when it is in the draw and dimmed when it is not. Everyone in the room draws from the same pool, the replay too, so a game never splits over it, and the skirmish room keeps your pool for the next match.
- A plain Random no longer hands you Turkiye. The side is an experiment and a player asking for any army should not get it unasked; tick it into a Custom Selection to have it in the draw. Armies a mod brings in beside ours show on the screen and go into a pool like any other. A replay recorded before this change, with a Random seat in it, plays out differently.
## Music that follows the fight
diff --git a/GeneralsMD/Code/Data/Patch.str b/GeneralsMD/Code/Data/Patch.str
index 3bcac0ab6..07b3456b5 100644
--- a/GeneralsMD/Code/Data/Patch.str
+++ b/GeneralsMD/Code/Data/Patch.str
@@ -3372,3 +3372,16 @@ END
GUI:FactionPickPool
"Random picks one of the %d armies ticked on the left, out of %d. Click an army to tick it or take it out."
END
+
+// %s is a side's name as its heading reads (USA, China, a mod's side): the pool is that side and nothing else.
+GUI:FactionPickRandomSide
+"Random %s"
+END
+
+GUI:FactionPickSideHint
+"A side's box ticks or clears the whole side; its name leaves that side alone in the draw."
+END
+
+GUI:FactionPickSideNameHint
+"Click a side's name to play a random army of that side."
+END
diff --git a/GeneralsMD/Code/Data/Turkish/Generals.str b/GeneralsMD/Code/Data/Turkish/Generals.str
index c6e76fd51..6de11436b 100644
--- a/GeneralsMD/Code/Data/Turkish/Generals.str
+++ b/GeneralsMD/Code/Data/Turkish/Generals.str
@@ -17658,3 +17658,15 @@ END
GUI:FactionPickPool
"Rastgele, solda işaretli %d ordudan birini seçer (toplam %d). Bir orduya tıklayarak onu ekleyin ya da çıkarın."
END
+
+GUI:FactionPickRandomSide
+"Rastgele %s"
+END
+
+GUI:FactionPickSideHint
+"Bir tarafın kutusu o tarafın tamamını işaretler ya da kaldırır; adına tıklamak çekilişte yalnızca o tarafı bırakır."
+END
+
+GUI:FactionPickSideNameHint
+"Bir tarafın rastgele bir ordusuyla oynamak için o tarafın adına tıklayın."
+END
diff --git a/GeneralsMD/Code/GameEngine/Include/GameClient/FactionPicker.h b/GeneralsMD/Code/GameEngine/Include/GameClient/FactionPicker.h
index e892c7b74..8c72a0fa5 100644
--- a/GeneralsMD/Code/GameEngine/Include/GameClient/FactionPicker.h
+++ b/GeneralsMD/Code/GameEngine/Include/GameClient/FactionPicker.h
@@ -41,7 +41,14 @@ void FactionPickerDetach( void );
/// the box's Random line carries the seat's own Random, a pool included, so the box shows it and
/// the screen opens on it
void FactionPickerSyncRandom( GameWindow *combo, Int pick );
-/// -factionpicker: the next room that attaches opens the screen on its first seat, custom shows the pool
-void FactionPickerOpenOnStart( Bool custom );
+/// -factionpicker: the next room that attaches opens the screen on its first seat, custom shows the
+/// pool, and a side's name (America, China, GLA, Turkiye) narrows the pool to that side as a click on
+/// its heading does
+void FactionPickerOpenOnStart( Bool custom, const char *side );
+
+/// a side's tick box is ticked while every army of the side (its bits) is in the pool
+Bool FactionPickerSideTicked( UnsignedInt pool, UnsignedInt side );
+/// a click on a side's tick box: the whole side in, or out when it was all in already
+UnsignedInt FactionPickerToggleSide( UnsignedInt pool, UnsignedInt side );
#endif // _FACTIONPICKER_H_
diff --git a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
index eea0712c4..157fefb4c 100644
--- a/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/Common/CommandLine.cpp
@@ -2526,16 +2526,18 @@ Int parseSkirmishLobby(char *args[], int num)
return 1;
}
-/* -factionpicker [custom] opens the skirmish staging room with the army screen up on the first seat,
- as a click on the seat's army box would, so the screen can be photographed without a click.
- "custom" opens it on Custom Selection with the Random pool's ticks showing. Implies
- -skirmishlobby. */
+/* -factionpicker [custom [<side>]] opens the skirmish staging room with the army screen up on the
+ first seat, as a click on the seat's army box would, so the screen can be photographed without a
+ click. "custom" opens it on Custom Selection with the Random pool's ticks showing, and a side
+ after it (America, China, GLA, Turkiye) narrows the pool to that side as a click on its name
+ does. Implies -skirmishlobby. */
Int parseFactionPicker(char *args[], int num)
{
const Bool custom = num > 1 && args[1] && strcasecmp(args[1], "custom") == 0;
- FactionPickerOpenOnStart(custom);
+ const Bool side = custom && num > 2 && args[2] && args[2][0] != '-';
+ FactionPickerOpenOnStart(custom, side ? args[2] : "");
parseSkirmishLobby(args, num);
- return custom ? 2 : 1;
+ return 1 + (custom ? 1 : 0) + (side ? 1 : 0);
}
/* -optionsmenu opens the options screen over the main menu at startup, where a click on Options
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/FactionPicker.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/FactionPicker.cpp
index 709aeffb9..4d021f8e1 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/FactionPicker.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/FactionPicker.cpp
@@ -78,6 +78,8 @@ static const Real BANNER_BOTTOM = 504.0f;
static const Real DESCRIPTION_TOP = 516.0f;
static const Real PAD = 16.0f;
static const Real POOL_ICON = 96.0f;
+static const Real SIDE_TICK = 26.0f;
+static const Real SIDE_TICK_GAP = 14.0f;
static const Real MAX_PORTRAIT_SCALE = 4.0f; // a 64 px side logo blown up past this is only blur
static const Int POOL_DIM_ALPHA = 190;
static const char *const PICKER_IMAGE_PREFIX = "FactionPicker"; // a template's own picture here, FactionPickerFactionTurkiye
@@ -99,13 +101,18 @@ struct PickerGroup
{
AsciiString leadSide;
Int mod;
+ UnicodeString name;
DisplayString *heading;
ICoord2D at;
+ IRegion2D nameBox; ///< a click on the name narrows the pool to the side
+ IRegion2D tickBox; ///< Custom Selection's box for the whole side
+ UnsignedInt mask; ///< the side's pool bits, 0 for Observer
std::vector<Int> cells;
};
static Bool s_openOnStart = FALSE;
static Bool s_openOnStartCustom = FALSE;
+static AsciiString s_openOnStartSide;
static GameWindow *s_window = NULL;
static GameWindow *s_combo = NULL;
@@ -262,6 +269,31 @@ static Int cellAt( Int x, Int y )
return -1;
}
+/// the side a Custom Selection pool is, every army of it and nothing else, or -1
+static Int poolSide( void )
+{
+ if( !s_custom )
+ return -1;
+ const UnsignedInt pool = s_mask & listedMask();
+ for( size_t group = 0; group < s_groups.size(); group++ )
+ {
+ if( s_groups[ group ].mask != 0 && s_groups[ group ].mask == pool )
+ return (Int)group;
+ }
+ return -1;
+}
+
+static Int sideAt( Int x, Int y, Bool tickBox )
+{
+ for( size_t group = 0; group < s_groups.size(); group++ )
+ {
+ const PickerGroup &g = s_groups[ group ];
+ if( g.mask != 0 && isInside( tickBox ? g.tickBox : g.nameBox, x, y ) )
+ return (Int)group;
+ }
+ return -1;
+}
+
static Bool canConfirm( void )
{
return s_focus >= 0 || !s_custom || tickedCount() > 0;
@@ -345,9 +377,13 @@ static void buildCells( void )
PickerGroup lead;
lead.leadSide = side;
lead.mod = mod;
+ lead.name = cell.name;
lead.heading = newText( cell.name, UIStyle::font( UIStyle::TEXT_HEADING ) );
+ lead.mask = 0;
s_groups.push_back( lead );
}
+ if( cell.poolBit >= 0 )
+ s_groups[ group ].mask |= 1u << cell.poolBit;
s_groups[ group ].cells.push_back( (Int)s_cells.size() );
s_cells.push_back( cell );
}
@@ -383,6 +419,16 @@ static void layout( void )
PickerGroup &g = s_groups[ group ];
g.at.x = UIStyle::boardX( LEFT );
g.at.y = UIStyle::boardY( y );
+ Int nameWidth, nameHeight;
+ g.heading->getSize( &nameWidth, &nameHeight );
+ g.nameBox.lo = g.at;
+ g.nameBox.hi.x = g.at.x + nameWidth;
+ g.nameBox.hi.y = g.at.y + nameHeight;
+ const Int tick = UIStyle::px( SIDE_TICK );
+ g.tickBox.lo.x = g.nameBox.hi.x + UIStyle::px( SIDE_TICK_GAP );
+ g.tickBox.lo.y = g.at.y + ( nameHeight - tick ) / 2;
+ g.tickBox.hi.x = g.tickBox.lo.x + tick;
+ g.tickBox.hi.y = g.tickBox.lo.y + tick;
y += HEADING_HEIGHT;
for( size_t each = 0; each < g.cells.size(); each++ )
{
@@ -416,9 +462,17 @@ static void refresh( void )
}
else
{
- name = TheGameText->fetch( "GUI:Random" );
+ const Int side = poolSide();
+ if( side >= 0 )
+ name.format( TheGameText->fetch( "GUI:FactionPickRandomSide" ), s_groups[ side ].name.str() );
+ else
+ name = TheGameText->fetch( "GUI:Random" );
if( s_custom )
+ {
strategy.format( TheGameText->fetch( "GUI:FactionPickPool" ), tickedCount(), tickableCount() );
+ strategy.concat( u' ' );
+ strategy.concat( TheGameText->fetch( "GUI:FactionPickSideHint" ) );
+ }
else
{
strategy = TheGameText->fetch( "GUI:FactionPickRandom" );
@@ -429,6 +483,8 @@ static void refresh( void )
strategy.concat( u' ' );
strategy.concat( leftOut );
}
+ strategy.concat( u' ' );
+ strategy.concat( TheGameText->fetch( "GUI:FactionPickSideNameHint" ) );
}
// the armies the draw can land on
for( size_t each = 0; each < s_cells.size(); each++ )
@@ -479,6 +535,16 @@ static void drawCellPicture( const PickerCell &cell, const IRegion2D &box )
drawCentred( cell.label, box, UIStyle::INK );
}
+static void drawTickBox( Int x, Int y, Int size, Bool ticked )
+{
+ UIStyle::panel( x, y, size, size, ticked ? UIStyle::ACTIVE : UIStyle::CARD );
+ if( !ticked )
+ return;
+ const Real line = (Real)max( 2, UIStyle::px( 3 ) );
+ TheDisplay->drawLine( x + size / 5, y + size / 2, x + size * 2 / 5, y + size * 3 / 4, line, UIStyle::GROUND );
+ TheDisplay->drawLine( x + size * 2 / 5, y + size * 3 / 4, x + size * 4 / 5, y + size / 4, line, UIStyle::GROUND );
+}
+
/** Random's preview: every army a Random can be, the ones it can land on lit and the rest dimmed. */
static void drawPoolPreview( const IRegion2D &area )
{
@@ -546,7 +612,15 @@ static void drawPicker( GameWindow *window, WinInstanceData *instData )
const ICoord2D mouse = TheMouse->getMouseStatus()->pos;
for( size_t group = 0; group < s_groups.size(); group++ )
- s_groups[ group ].heading->draw( s_groups[ group ].at.x, s_groups[ group ].at.y, UIStyle::ACTIVE, UIStyle::SHADOW );
+ {
+ // the name is a button (that side alone), lit under the mouse; the box is Custom Selection's
+ const PickerGroup &g = s_groups[ group ];
+ const Bool narrows = g.mask != 0;
+ const Bool hovered = narrows && isInside( g.nameBox, mouse.x, mouse.y );
+ g.heading->draw( g.at.x, g.at.y, hovered ? UIStyle::EDGE_LIT : UIStyle::ACTIVE, UIStyle::SHADOW );
+ if( s_custom && narrows )
+ drawTickBox( g.tickBox.lo.x, g.tickBox.lo.y, boxWidth( g.tickBox ), FactionPickerSideTicked( s_mask, g.mask ) );
+ }
for( size_t each = 0; each < s_cells.size(); each++ )
{
const PickerCell &cell = s_cells[ each ];
@@ -562,16 +636,8 @@ static void drawPicker( GameWindow *window, WinInstanceData *instData )
TheDisplay->drawFillRect( box.lo.x, box.lo.y, boxWidth( box ), boxHeight( box ), UIStyle::withAlpha( UIStyle::GROUND, 150 ) );
if( cell.poolBit >= 0 )
{
- const Int size = UIStyle::px( 26 );
- const Int x = box.hi.x - size - inset;
- const Int y = box.lo.y + inset;
- UIStyle::panel( x, y, size, size, isTicked( cell ) ? UIStyle::ACTIVE : UIStyle::CARD );
- if( isTicked( cell ) )
- {
- const Real line = (Real)max( 2, UIStyle::px( 3 ) );
- TheDisplay->drawLine( x + size / 5, y + size / 2, x + size * 2 / 5, y + size * 3 / 4, line, UIStyle::GROUND );
- TheDisplay->drawLine( x + size * 2 / 5, y + size * 3 / 4, x + size * 4 / 5, y + size / 4, line, UIStyle::GROUND );
- }
+ const Int size = UIStyle::px( SIDE_TICK );
+ drawTickBox( box.hi.x - size - inset, box.lo.y + inset, size, isTicked( cell ) );
}
}
if( (Int)each == s_focus )
@@ -679,6 +745,15 @@ static void confirm( void )
}
}
+/// a click on a side's name: Random from that side alone ("USA random")
+static void narrowToSide( Int side )
+{
+ s_custom = TRUE;
+ s_focus = -1;
+ s_mask = s_groups[ side ].mask;
+ refresh();
+}
+
static void pressAt( Int x, Int y )
{
if( isInside( s_backBox, x, y ) )
@@ -709,6 +784,21 @@ static void pressAt( Int x, Int y )
refresh();
return;
}
+ const Int tickedSide = s_custom ? sideAt( x, y, TRUE ) : -1;
+ if( tickedSide >= 0 )
+ {
+ click();
+ s_mask = FactionPickerToggleSide( s_mask & listedMask(), s_groups[ tickedSide ].mask );
+ refresh();
+ return;
+ }
+ const Int namedSide = sideAt( x, y, FALSE );
+ if( namedSide >= 0 )
+ {
+ click();
+ narrowToSide( namedSide );
+ return;
+ }
const Int each = cellAt( x, y );
if( each < 0 )
return;
@@ -874,6 +964,11 @@ void FactionPickerAttach( GameWindow *parent, const char *layoutFilename )
s_focus = -1;
refresh();
}
+ for( size_t group = 0; group < s_groups.size(); group++ )
+ {
+ if( !s_openOnStartSide.isEmpty() && s_groups[ group ].leadSide.compareNoCase( s_openOnStartSide ) == 0 )
+ narrowToSide( (Int)group );
+ }
}
}
@@ -898,8 +993,19 @@ void FactionPickerSyncRandom( GameWindow *combo, Int pick )
}
}
-void FactionPickerOpenOnStart( Bool custom )
+void FactionPickerOpenOnStart( Bool custom, const char *side )
{
s_openOnStart = TRUE;
s_openOnStartCustom = custom;
+ s_openOnStartSide = side;
+}
+
+Bool FactionPickerSideTicked( UnsignedInt pool, UnsignedInt side )
+{
+ return side != 0 && ( pool & side ) == side;
+}
+
+UnsignedInt FactionPickerToggleSide( UnsignedInt pool, UnsignedInt side )
+{
+ return FactionPickerSideTicked( pool, side ) ? pool & ~side : pool | side;
}
diff --git a/GeneralsMD/Code/Tests/test_gameengine.cpp b/GeneralsMD/Code/Tests/test_gameengine.cpp
index bff497cce..60e188149 100644
--- a/GeneralsMD/Code/Tests/test_gameengine.cpp
+++ b/GeneralsMD/Code/Tests/test_gameengine.cpp
@@ -51,6 +51,7 @@
#include "GameNetwork/GameInfo.h"
#include "Common/PlayerTemplate.h"
#include "GameClient/ChallengeGenerals.h"
+#include "GameClient/FactionPicker.h"
#include "GameClient/UIStyle.h"
#include <fstream>
#include <sstream>
@@ -7348,6 +7349,22 @@ TEST(capitals_reach_turkish_and_cyrillic_letters)
TheWritableGlobalData = saved;
}
+/* The army screen's side box is ticked while the whole side is in the pool, and a click puts the
+ side in or takes it out; untick one army and the box clears, tick it back and the box is ticked. */
+TEST(army_screen_side_box_follows_the_side_armies)
+{
+ const UnsignedInt usa = 0xFu; // USA and its three generals
+ const UnsignedInt china = 0xF0u;
+ CHECK( FactionPickerSideTicked( 0xFFu, usa ) );
+ CHECK( !FactionPickerSideTicked( 0xFEu, usa ) );
+ CHECK( !FactionPickerSideTicked( 0xFFu, 0 ) ); // Observer has no armies to tick
+ CHECK_EQ( FactionPickerToggleSide( 0xFFu, usa ), china );
+ CHECK_EQ( FactionPickerToggleSide( china, usa ), 0xFFu );
+ // a side partly in comes in whole on the first click
+ CHECK_EQ( FactionPickerToggleSide( 0x12u, usa ), 0x1Fu );
+ CHECK( FactionPickerSideTicked( FactionPickerToggleSide( 0x12u, usa ), usa ) );
+}
+
static Bool drawIs( Int pick, Bool oldFactionsOnly, const std::vector<Int> &want )
{
std::vector<Int> draw;