Maelstrom: Removed DrawText(), moving the multiplayer UI elements into game.xml

https://github.com/libsdl-org/Maelstrom/commit/f1668cd3875c9a18c779c4f4d7e2523cda695fff

From f1668cd3875c9a18c779c4f4d7e2523cda695fff Mon Sep 17 00:00:00 2001
From: Sam Lantinga <[EMAIL REDACTED]>
Date: Thu, 27 Oct 2011 23:41:18 -0400
Subject: [PATCH] Removed DrawText(), moving the multiplayer UI elements into
 game.xml

---
 UI/game.xml               | 15 +++++++++++
 main.cpp                  | 32 +++++++---------------
 netlogic/game.cpp         | 57 ++++++++++++++++++++++++++++++---------
 netlogic/game.h           |  6 +++++
 screenlib/UIElementLine.h |  4 +++
 screenlib/UIElementRect.h |  4 +++
 screenlib/UITemplates.cpp |  3 ++-
 7 files changed, 86 insertions(+), 35 deletions(-)

diff --git a/UI/game.xml b/UI/game.xml
index ef80764a..73098346 100644
--- a/UI/game.xml
+++ b/UI/game.xml
@@ -77,5 +77,20 @@
 		<Icon name="longfire" id="136">
 			<Anchor anchorFrom="TOPLEFT" anchorTo="BOTTOMLEFT" anchor="status_line" x="502" y="3"/>
 		</Icon>
+
+		<!-- Multiplayer elements -->
+		<Label name="multiplayer_caption" template="SmallBlue">
+			<Anchor anchorFrom="TOPLEFT" anchorTo="TOPLEFT" x="32" y="1"/>
+		</Label>
+		<Rectangle name="multiplayer_color" fill="true">
+			<Size w="4" h="8"/>
+			<Anchor anchorFrom="TOPLEFT" anchorTo="TOPLEFT" anchor="status_line" x="518" y="4"/>
+		</Label>
+		<Label name="frags_label" template="SmallBlue" text="Frags:">
+			<Anchor anchorFrom="TOPLEFT" anchorTo="TOPLEFT" anchor="status_line" x="530" y="1"/>
+		</Label>
+		<Label name="frags" template="SmallWhite">
+			<Anchor anchorFrom="LEFT" anchorTo="RIGHT" anchor="frags_label" x="4"/>
+		</Label>
 	</Elements>
 </UIPanel>
diff --git a/main.cpp b/main.cpp
index a2396954..2603ee01 100644
--- a/main.cpp
+++ b/main.cpp
@@ -342,24 +342,6 @@ int main(int argc, char *argv[])
 }	/* -- main */
 
 
-int DrawText(int x, int y, const char *text, MFont *font, Uint8 style,
-					Uint8 R, Uint8 G, Uint8 B)
-{
-	SDL_Texture *textimage;
-	int width;
-
-	textimage = fontserv->TextImage(text, font, style, R, G, B);
-	if ( textimage == NULL ) {
-		width = 0;
-	} else {
-		screen->QueueBlit(x, y-screen->GetImageHeight(textimage)+2, textimage, NOCLIP);
-		width = screen->GetImageWidth(textimage);
-		fontserv->FreeText(textimage);
-	}
-	return(width);
-}
-
-
 /* ----------------------------------------------------------------- */
 /* -- Setup the main screen */
 
@@ -533,14 +515,20 @@ MainPanelDelegate::OnTick()
 void Message(const char *message)
 {
 // FIXME: This totally doesn't work anymore, but that may not matter if we're cutting network support.
-	int xOff;
+	int x, y;
+	SDL_Texture *textimage;
+	int width;
 
 	if (!message) {
 		return;
 	}
 
 	/* This was taken from the DrawMainScreen function */
-	xOff = (SCREEN_WIDTH - 512) / 2;
-	DrawText(xOff, 25, message, fonts[NEWYORK_14], STYLE_BOLD,
-						0xCC, 0xCC, 0xCC);
+	x = (SCREEN_WIDTH - 512) / 2;
+	y = 25;
+	textimage = fontserv->TextImage(message, fonts[NEWYORK_14], STYLE_BOLD, 0xCC, 0xCC, 0xCC);
+	if ( textimage ) {
+		screen->QueueBlit(x, y-screen->GetImageHeight(textimage)+2, textimage, NOCLIP);
+		fontserv->FreeText(textimage);
+	}
 }
diff --git a/netlogic/game.cpp b/netlogic/game.cpp
index 115056af..af9b818f 100644
--- a/netlogic/game.cpp
+++ b/netlogic/game.cpp
@@ -8,6 +8,7 @@
 #include "game.h"
 #include "../UIElementIcon.h"
 #include "../UIElementLabel.h"
+#include "../screenlib/UIElementRect.h"
 
 
 #ifdef MOVIE_SUPPORT
@@ -199,6 +200,11 @@ GamePanelDelegate::OnLoad()
 	m_triplefire = m_panel->GetElement<UIElementIcon>("triplefire");
 	m_longfire = m_panel->GetElement<UIElementIcon>("longfire");
 
+	m_multiplayerCaption = m_panel->GetElement<UIElementLabel>("multiplayer_caption");
+	m_multiplayerColor = m_panel->GetElement<UIElementRect>("multiplayer_color");
+	m_fragsLabel = m_panel->GetElement<UIElementLabel>("frags_label");
+	m_frags = m_panel->GetElement<UIElementLabel>("frags");
+
 	return true;
 }
 
@@ -217,6 +223,34 @@ GamePanelDelegate::OnShow()
 	gLastDrawn = 0L;
 	gNumSprites = 0;
 
+	if ( gNumPlayers > 1 ) {
+		if (m_multiplayerCaption) {
+			m_multiplayerCaption->Show();
+		}
+		if (m_multiplayerColor) {
+			m_multiplayerColor->Show();
+		}
+		if (m_fragsLabel) {
+			m_fragsLabel->Show();
+		}
+		if (m_frags) {
+			m_frags->Show();
+		}
+	} else {
+		if (m_multiplayerCaption) {
+			m_multiplayerCaption->Hide();
+		}
+		if (m_multiplayerColor) {
+			m_multiplayerColor->Hide();
+		}
+		if (m_fragsLabel) {
+			m_fragsLabel->Hide();
+		}
+		if (m_frags) {
+			m_frags->Hide();
+		}
+	}
+
 	NextWave();
 }
 
@@ -387,25 +421,24 @@ GamePanelDelegate::DrawStatus(Bool first)
 		}
 	}
 
-	/* Heh, DOOM style frag count */
-	if ( gNumPlayers > 1 ) {
-		x = 530;
-		i = DrawText(x, gStatusLine+11, "Frags:", geneva,
-				STYLE_BOLD, 30000>>8, 30000>>8, 0xFF);
-		sprintf(numbuf, "%-3.1d", TheShip->GetFrags());
-		DrawText(x+i+4, gStatusLine+11, numbuf, geneva, STYLE_BOLD, 0xFF, 0xFF, 0xFF);
-	}
-
 	if ( gNumPlayers > 1 ) {
 		char caption[BUFSIZ];
 
 		sprintf(caption, "You are player %d --- displaying player %d",
 					gOurPlayer+1, gDisplayed+1);
-		DrawText(SPRITES_WIDTH, 11, caption, geneva,
-				STYLE_BOLD, 30000>>8, 30000>>8, 0xFF);
+		if (m_multiplayerCaption) {
+			m_multiplayerCaption->SetText(caption);
+		}
 
 		/* Fill in the color by the frag count */
-		screen->FillRect(518, gStatusLine+4, 4, 8, TheShip->Color());
+		if (m_multiplayerColor) {
+			m_multiplayerColor->SetColor(TheShip->Color());
+		}
+
+		sprintf(numbuf, "%-3.1d", TheShip->GetFrags());
+		if (m_frags) {
+			m_frags->SetText(numbuf);
+		}
 	}
 
 	int fact = ((SHIELD_WIDTH - 2) * TheShip->GetShieldLevel()) / MAX_SHIELD;
diff --git a/netlogic/game.h b/netlogic/game.h
index 387c9035..3f6a6417 100644
--- a/netlogic/game.h
+++ b/netlogic/game.h
@@ -5,6 +5,7 @@
 class UIElement;
 class UIElementIcon;
 class UIElementLabel;
+class UIElementRect;
 
 class GamePanelDelegate : public UIPanelDelegate
 {
@@ -38,6 +39,11 @@ class GamePanelDelegate : public UIPanelDelegate
 	UIElementIcon *m_lucky;
 	UIElementIcon *m_triplefire;
 	UIElementIcon *m_longfire;
+
+	UIElementLabel *m_multiplayerCaption;
+	UIElementRect *m_multiplayerColor;
+	UIElementLabel *m_fragsLabel;
+	UIElementLabel *m_frags;
 };
 
 #endif // _game_h
diff --git a/screenlib/UIElementLine.h b/screenlib/UIElementLine.h
index c7e35a1d..6581e630 100644
--- a/screenlib/UIElementLine.h
+++ b/screenlib/UIElementLine.h
@@ -17,6 +17,10 @@ class UIElementLine : public UIElement
 
 	virtual void Draw();
 
+	void SetColor(Uint32 color) {
+		m_color = color;
+	}
+
 private:
 	Uint32 m_color;
 
diff --git a/screenlib/UIElementRect.h b/screenlib/UIElementRect.h
index 8aa828bf..9934de8d 100644
--- a/screenlib/UIElementRect.h
+++ b/screenlib/UIElementRect.h
@@ -17,6 +17,10 @@ class UIElementRect : public UIElement
 
 	virtual void Draw();
 
+	void SetColor(Uint32 color) {
+		m_color = color;
+	}
+
 private:
 	bool m_fill;
 	Uint32 m_color;
diff --git a/screenlib/UITemplates.cpp b/screenlib/UITemplates.cpp
index de6226a2..b3914c4b 100644
--- a/screenlib/UITemplates.cpp
+++ b/screenlib/UITemplates.cpp
@@ -156,7 +156,8 @@ UITemplates::HashTable_KeyMatch(const void *_a, const void *_b, void *data)
 	const HashKey *a = static_cast<const HashKey *>(_a);
 	const HashKey *b = static_cast<const HashKey *>(_a);
 
-	return strcmp(a->type, b->type) == 0 && strcmp(a->name, b->name) == 0;
+	return strcasecmp(a->type, b->type) == 0 && 
+	       strcasecmp(a->name, b->name) == 0;
 }
 
 void