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.

fix(gameclient): keep start spot rings out of the button's user data

Olcay Seygana4262051d19e
diff --git a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
index f62063f11..99e903fd6 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameClient/GUI/GUICallbacks/Menus/SkirmishGameOptionsMenu.cpp
@@ -849,13 +849,43 @@ void positionStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[]
positionStartSpots(localMapFname, buttonMapStartPositions, mapWindow);
}
-// A start spot draws as the button it is, then a taken one gets a ring a third wider than the spot
-// in the colour its user data holds (a Color, 0 for none).
+// A start spot draws as the button it is, then a taken one gets a ring a third wider than the spot in
+// its team's colour. The colour is kept here by window, not in the button's user data, which the
+// push button's own draw reads as its PushButtonData. The skirmish, LAN or online room and the load
+// screen each own one set of spots, so two sets cover every screen that shows them.
+struct StartSpotRing
+{
+ GameWindow *spot;
+ Color ring; // 0 for none
+};
+static StartSpotRing theStartSpotRings[MAX_SLOTS * 2];
static GameWinDrawFunc theStartSpotButtonDraw = NULL;
+
+static StartSpotRing *startSpotRing( GameWindow *spot )
+{
+ StartSpotRing *freeEntry = NULL;
+ for ( Int i = 0; i < (Int)ARRAY_SIZE(theStartSpotRings); ++i )
+ {
+ if ( theStartSpotRings[i].spot == spot )
+ return &theStartSpotRings[i];
+ if ( freeEntry == NULL && theStartSpotRings[i].spot == NULL )
+ freeEntry = &theStartSpotRings[i];
+ }
+ // a full table means a third set of spots is alive: start the table over for the newest one
+ if ( freeEntry == NULL )
+ {
+ memset( theStartSpotRings, 0, sizeof( theStartSpotRings ) );
+ freeEntry = &theStartSpotRings[0];
+ }
+ freeEntry->spot = spot;
+ freeEntry->ring = 0;
+ return freeEntry;
+}
+
static void drawStartSpot( GameWindow *window, WinInstanceData *instData )
{
theStartSpotButtonDraw( window, instData );
- const Color ring = (Color)(uintptr_t)window->winGetUserData();
+ const Color ring = startSpotRing( window )->ring;
if ( ring == 0 )
return;
Int x, y, width, height;
@@ -894,7 +924,7 @@ void updateMapStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[
theStartSpotButtonDraw = buttonMapStartPositions[i]->winGetDrawFunc();
buttonMapStartPositions[i]->winSetDrawFunc( drawStartSpot );
}
- buttonMapStartPositions[i]->winSetUserData( NULL );
+ startSpotRing( buttonMapStartPositions[i] )->ring = 0;
if (!onLoadScreen)
{
buttonMapStartPositions[i]->winSetTooltip(TheGameText->fetch("TOOLTIP:StartPosition"));
@@ -913,7 +943,7 @@ void updateMapStartSpots( GameInfo *myGame, GameWindow *buttonMapStartPositions[
if (spot >= 0 && spot < mmd.m_numPlayers && gs->getPlayerTemplate() > PLAYERTEMPLATE_MIN)
{
const Color ring = gs->getTeamNumber() >= 0 ? LobbyTeamColor(gs->getTeamNumber()) : LobbySeatColor(gs);
- buttonMapStartPositions[spot]->winSetUserData((void *)(uintptr_t)ring);
+ startSpotRing(buttonMapStartPositions[spot])->ring = ring;
}
if(onLoadScreen)
{
diff --git a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp
index 38842fafc..1928fd30e 100644
--- a/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp
+++ b/GeneralsMD/Code/GameEngine/Source/GameNetwork/GUIUtil.cpp
@@ -944,14 +944,17 @@ Color LobbySeatColor(const GameSlot *slot)
}
// The seat's mark, its image drawn in the window's own colour: white art tinted per seat. A mod
-// faction's disc carries its initials, the display string in the window's user data.
+// faction's disc carries its initials, the display string kept beside the seat's emblem window.
static void drawTintedEmblem(GameWindow *window, WinInstanceData *instData)
{
Int x, y, width, height;
window->winGetScreenPosition(&x, &y);
window->winGetSize(&width, &height);
TheDisplay->drawImage(window->winGetEnabledImage(0), x, y, x + width, y + height, window->winGetEnabledColor(0));
- DisplayString *initials = (DisplayString *)window->winGetUserData();
+ Int seat = 0;
+ while (theSeatEmblem[seat] != window)
+ ++seat;
+ DisplayString *initials = theSeatInitials[seat];
if (initials->getTextLength() == 0)
return;
Int textWidth, textHeight;
@@ -975,7 +978,6 @@ void InitLobbySeatVisuals(GameWindow *parent, const char *layoutFilename)
if (theSeatEmblem[i] == NULL)
continue;
theSeatInitials[i] = TheDisplayStringManager->newDisplayString();
- theSeatEmblem[i]->winSetUserData(theSeatInitials[i]);
theSeatEmblem[i]->winSetDrawFunc(drawTintedEmblem);
}
theSeatsShowReady = strcmp(layoutFilename, "SkirmishGameOptionsMenu.wnd") != 0;