# HG changeset patch
# User Binary Code
# Date 1732379039 28800
#      Sat Nov 23 08:23:59 2024 -0800
# Node ID 0f7e4a2a172c8411d4f8525c299d79decb2548e3
# Parent  4e8342339656a2dbe6538c2276769866481c298f
Added new SBARINFO top level "AppendStatusBar" to allow for adding extra SBARINFO code onto existing custom SBARINFO definitions.

diff -r 4e8342339656 -r 0f7e4a2a172c docs/zandronum-history.txt
--- a/docs/zandronum-history.txt	Sun Oct 27 17:39:14 2024 -0400
+++ b/docs/zandronum-history.txt	Sat Nov 23 08:23:59 2024 -0800
@@ -72,6 +72,7 @@
 +	- Added the CVar "cl_showscoreleft", which if disabled will turn "x things left" messages on the scoreboard into "x things to win" and show the current score limit instead of how much is left to win. This only affects frags, points, and wins. [Kaminsky]
 +	- Added ACS functions: "GetPlayerJoinQueuePosition" and "SkipJoinQueue", to return the player's position in the join queue and allow true spectators in the join queue to join the game outside of normal game mode rules. Modders can also take advantage of the new GAMEEVENT_JOINQUEUECHANGED EVENT script type to know when players are added or removed from the join queue. [Kaminsky]
 +	- Added over a hundred new text colors recently made by Fuzzball. [Kaminsky]
++	- Added new SBARINFO top level "AppendStatusBar" to allow for adding extra SBARINFO code onto existing custom SBARINFO definitions. [Binary]
 -	- Fixed: clients didn't initialize a sector's friction properly in some cases due to a superfluous check that wasn't removed earlier. [Kaminsky]
 -	- Fixed: the server wouldn't initialize compatflags and compatflags2 properly if entered as command line parameters. [Kaminsky]
 -	- Fixed: serverinfo CVars entered on the command line were restored in reverse order. [Kaminsky]
diff -r 4e8342339656 -r 0f7e4a2a172c src/g_shared/sbarinfo.cpp
--- a/src/g_shared/sbarinfo.cpp	Sun Oct 27 17:39:14 2024 -0400
+++ b/src/g_shared/sbarinfo.cpp	Sat Nov 23 08:23:59 2024 -0800
@@ -373,6 +373,7 @@
 	SBARINFO_STATUSBAR,
 	SBARINFO_MUGSHOT,
 	SBARINFO_CREATEPOPUP,
+	SBARINFO_APPENDSTATUSBAR, // [Binary] Additive SBARINFO implementation.
 };
 
 enum //Bar types
@@ -401,6 +402,7 @@
 	"statusbar",
 	"mugshot",
 	"createpopup",
+	"appendstatusbar", // [Binary] Additive SBARINFO implementation.
 	NULL
 };
 
@@ -482,7 +484,9 @@
 			continue;
 		}
 		int baselump = -2;
-		switch(sc.MustMatchString(SBarInfoTopLevel))
+		// [Binary] Store the command, used for the switch statement and case SBARINFO_APPENDSTATUSBAR.
+		const int command = sc.MustMatchString(SBarInfoTopLevel);
+		switch(command)
 		{
 			case SBARINFO_BASE:
 				baseSet = true;
@@ -623,6 +627,7 @@
 				sc.MustGetToken(';');
 				break;
 			case SBARINFO_STATUSBAR:
+			case SBARINFO_APPENDSTATUSBAR: // [Binary] This uses the same code as the above case.
 			{
 				if(!baseSet) //If the user didn't explicitly define a base, do so now.
 					gameType = GAME_Any;
@@ -632,11 +637,19 @@
 					sc.MustGetToken(TK_Identifier);
 					barNum = sc.MustMatchString(StatusBars);
 				}
-				if (this->huds[barNum] != NULL)
+				// [Binary] SBARINFO_APPENDSTATUSBAR shouldn't delete the old HUD if it exists.
+				if (command != SBARINFO_APPENDSTATUSBAR)
 				{
-					delete this->huds[barNum];
+					if (this->huds[barNum] != NULL)
+					{
+						delete this->huds[barNum];
+					}
+					this->huds[barNum] = new SBarInfoMainBlock(this);
 				}
-				this->huds[barNum] = new SBarInfoMainBlock(this);
+				else if (this->huds[barNum] == NULL)
+				{
+					sc.ScriptError("Status bar '%s' has not been created and cannot be appended to. Use 'StatusBar' instead.", StatusBars[barNum]);
+				}
 				if(barNum == STBAR_AUTOMAP)
 				{
 					automapbar = true;
