From 83f151529bbf04e4cf068d18b64d43f9d805cd42 Mon Sep 17 00:00:00 2001
From: Christoph Oelckers <coelckers@users.noreply.github.com>
Date: Sun, 16 May 2021 10:25:56 +0200
Subject: [PATCH] - fixed SW status bar.

---
 source/games/sw/src/game.cpp              |  4 ++--
 source/games/sw/src/namelist.h            | 12 ++++++------
 source/games/sw/src/player.cpp            |  3 ++-
 source/games/sw/src/sbar.cpp              | 13 ++++++++++++-
 wadsrc/static/zscript/games/sw/ui/sbar.zs | 11 ++++++-----
 5 files changed, 28 insertions(+), 15 deletions(-)

diff --git a/source/games/sw/src/game.cpp b/source/games/sw/src/game.cpp
index c10f7b06d..ef08d5ea9 100644
--- a/source/games/sw/src/game.cpp
+++ b/source/games/sw/src/game.cpp
@@ -531,9 +531,9 @@ void GameInterface::LevelCompleted(MapRecord* map, int skill)
 
     SummaryInfo info{};
 
-    info.kills = Player->Kills;
+    info.kills = Player[screenpeek].Kills;
     info.maxkills = TotalKillable;
-    info.secrets = Player->SecretsFound;
+    info.secrets = Player[screenpeek].SecretsFound;
     info.maxsecrets = LevelSecrets;
     info.time = PlayClock / 120;
 
diff --git a/source/games/sw/src/namelist.h b/source/games/sw/src/namelist.h
index 05bb8760c..9b1c0ca3b 100644
--- a/source/games/sw/src/namelist.h
+++ b/source/games/sw/src/namelist.h
@@ -245,8 +245,8 @@ x(PANEL_SM_FONT_G6, 3607)
 x(PANEL_SM_FONT_G7, 3608)
 x(PANEL_SM_FONT_G8, 3609)
 x(PANEL_SM_FONT_G9, 3610)
-x(PANEL_SM_FONT_G10, 3611)
-x(PANEL_SM_FONT_G11, 3612)
+x(PANEL_SM_FONT_G10, 3600)
+x(PANEL_SM_FONT_G11, 3611)
 x(PANEL_SM_FONT_Y0, 3613)
 x(PANEL_SM_FONT_Y1, 3614)
 x(PANEL_SM_FONT_Y2, 3615)
@@ -257,8 +257,8 @@ x(PANEL_SM_FONT_Y6, 3619)
 x(PANEL_SM_FONT_Y7, 3620)
 x(PANEL_SM_FONT_Y8, 3621)
 x(PANEL_SM_FONT_Y9, 3622)
-x(PANEL_SM_FONT_Y10, 3623)
-x(PANEL_SM_FONT_Y11, 3624)
+x(PANEL_SM_FONT_Y10, 3612)
+x(PANEL_SM_FONT_Y11, 3623)
 x(PANEL_SM_FONT_R0, 3625)
 x(PANEL_SM_FONT_R1, 3626)
 x(PANEL_SM_FONT_R2, 3627)
@@ -269,8 +269,8 @@ x(PANEL_SM_FONT_R6, 3631)
 x(PANEL_SM_FONT_R7, 3632)
 x(PANEL_SM_FONT_R8, 3633)
 x(PANEL_SM_FONT_R9, 3634)
-x(PANEL_SM_FONT_R10, 3635)
-x(PANEL_SM_FONT_R11, 3636)
+x(PANEL_SM_FONT_R10, 3624)
+x(PANEL_SM_FONT_R11, 3635)
 x(PANEL_KEY_RED, 2392)
 x(PANEL_KEY_GREEN, 2393)
 x(PANEL_KEY_BLUE, 2394)
diff --git a/source/games/sw/src/player.cpp b/source/games/sw/src/player.cpp
index 229ce6f24..276bc2152 100644
--- a/source/games/sw/src/player.cpp
+++ b/source/games/sw/src/player.cpp
@@ -7765,7 +7765,8 @@ DEFINE_ACTION_FUNCTION(_SW, RealWeapon)
 {
     PARAM_PROLOGUE;
     PARAM_INT(inv);
-    ACTION_RETURN_INT(DamageData[inv].with_weapon);
+    int w = DamageData[inv].with_weapon;
+    ACTION_RETURN_INT(w == -1? inv : w);
 }
 
 END_SW_NS
diff --git a/source/games/sw/src/sbar.cpp b/source/games/sw/src/sbar.cpp
index 0b1ba4eff..bd7c116ff 100644
--- a/source/games/sw/src/sbar.cpp
+++ b/source/games/sw/src/sbar.cpp
@@ -152,6 +152,8 @@ public:
     {
         numberFont = Create<DHUDFont>( BigFont, 0, Off, 1, 1 );
         miniFont = Create<DHUDFont>(SmallFont2, 0, Off, 1, 1 );
+        numberFont->Release();
+        miniFont->Release();
     }
 
 private:
@@ -1088,7 +1090,16 @@ void UpdateStatusBar()
         UpdateFrame();
     }
 
-    StatusBar->UpdateStatusBar();
+    SummaryInfo info{};
+    info.kills = Player[screenpeek].Kills;
+    info.maxkills = TotalKillable;
+    info.secrets = Player[screenpeek].SecretsFound;
+    info.maxsecrets = LevelSecrets;
+    info.time = Scale(PlayClock, 1000, 120);
+
+    ::UpdateStatusBar(&info);
+
+
     PLAYERp pp = &Player[screenpeek];
     if (pp->cookieTime > 0)
     {
diff --git a/wadsrc/static/zscript/games/sw/ui/sbar.zs b/wadsrc/static/zscript/games/sw/ui/sbar.zs
index 214c4ffba..dd4b9625f 100644
--- a/wadsrc/static/zscript/games/sw/ui/sbar.zs
+++ b/wadsrc/static/zscript/games/sw/ui/sbar.zs
@@ -152,14 +152,15 @@ class SWStatusBar : RazeStatusBar
 		{
 			let ch = buffer.ByteAt(i);
 
-			if (ch == " ")
+			if (ch == "/") ch = 10;
+			else if (ch == ":") ch = 11;
+			else if (ch >= "0" && ch <= "9") ch -= 48;
+			else
 			{
+				if (ch != " ") Console.Printf("Invalid char %c", ch);
 				x += 4;
 				continue;
 			}
-			else if (ch == 0x5c) ch = 0;
-			else if (ch == ":") ch = 11;
-			else ch -= 47;
 
 			let font_pic = SmallSBFont[color][ch];
 			DrawTexture(font_pic, (x, y), DI_ITEM_LEFT_TOP, col:Raze.shadeToLight(shade));
@@ -375,7 +376,7 @@ class SWStatusBar : RazeStatusBar
 			"PANEL_SKELKEY_RED"
 		};
 		let tex = TexMan.CheckForTexture("PANEL_KEY_RED", TexMan.Type_Any);
-		let size = TexMan.GetScaledSize(tex);
+		let size = TexMan.GetScaledSize(tex) + (1, 2);
 
 		i = 0;
 		for (row = 0; row < 2; row++)