# HG changeset patch
# User Binary Code
# Date 1731952526 28800
#      Mon Nov 18 09:55:26 2024 -0800
# Node ID 6e04c564e9c1ef8c3594922177f8a52349be47f6
# Parent  4e8342339656a2dbe6538c2276769866481c298f
Added new SBARINFO top level "AppendStatusBar" to allow for adding extra SBARINFO code onto existing custom SBARINFO definitions.

diff -r 4e8342339656 -r 6e04c564e9c1 docs/zandronum-history.txt
--- a/docs/zandronum-history.txt	Sun Oct 27 17:39:14 2024 -0400
+++ b/docs/zandronum-history.txt	Mon Nov 18 09:55:26 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 6e04c564e9c1 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	Mon Nov 18 09:55:26 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( "AppendStatusBar can't be used on a HUD that doesn't exist yet." );
+				}
 				if(barNum == STBAR_AUTOMAP)
 				{
 					automapbar = true;
