about summary refs log tree commit diff
path: root/src/game/client/components/hud.cpp
diff options
context:
space:
mode:
authoroy <Tom_Adams@web.de>2011-03-10 10:08:14 +0100
committeroy <Tom_Adams@web.de>2011-03-10 10:08:14 +0100
commitee2f625754ca9f01be6732550f16098c5afa704a (patch)
tree9776edf90fac02d1bf03606dbc8b79fd071ed917 /src/game/client/components/hud.cpp
parent6205583d6411e300edd1ebf2eb170fbc8e7119e8 (diff)
downloadzcatch-ee2f625754ca9f01be6732550f16098c5afa704a.tar.gz
zcatch-ee2f625754ca9f01be6732550f16098c5afa704a.zip
added extended spectator mode. Closes #28
Diffstat (limited to 'src/game/client/components/hud.cpp')
-rw-r--r--src/game/client/components/hud.cpp49
1 files changed, 35 insertions, 14 deletions
diff --git a/src/game/client/components/hud.cpp b/src/game/client/components/hud.cpp
index ca100f9d..aff76bc8 100644
--- a/src/game/client/components/hud.cpp
+++ b/src/game/client/components/hud.cpp
@@ -30,7 +30,6 @@ void CHud::OnReset()
 void CHud::RenderGameTimer()
 {
 	float Half = 300.0f*Graphics()->ScreenAspect()/2.0f;
-	Graphics()->MapScreen(0, 0, 300.0f*Graphics()->ScreenAspect(), 300.0f);
 	
 	if(!(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_SUDDENDEATH))
 	{
@@ -340,8 +339,11 @@ void CHud::RenderCursor()
 	Graphics()->QuadsEnd();
 }
 
-void CHud::RenderHealthAndAmmo()
+void CHud::RenderHealthAndAmmo(const CNetObj_Character *pCharacter)
 {
+	if(!pCharacter)
+		return;
+
 	//mapscreen_to_group(gacenter_x, center_y, layers_game_group());
 
 	float x = 5;
@@ -351,15 +353,14 @@ void CHud::RenderHealthAndAmmo()
 	// render gui stuff
 
 	Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
-	Graphics()->MapScreen(0,0,m_Width,300);
 	
 	Graphics()->QuadsBegin();
 	
 	// if weaponstage is active, put a "glow" around the stage ammo
-	RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[m_pClient->m_Snap.m_pLocalCharacter->m_Weapon%NUM_WEAPONS].m_pSpriteProj);
+	RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[pCharacter->m_Weapon%NUM_WEAPONS].m_pSpriteProj);
 	IGraphics::CQuadItem Array[10];
 	int i;
-	for (i = 0; i < min(m_pClient->m_Snap.m_pLocalCharacter->m_AmmoCount, 10); i++)
+	for (i = 0; i < min(pCharacter->m_AmmoCount, 10); i++)
 		Array[i] = IGraphics::CQuadItem(x+i*12,y+24,10,10);
 	Graphics()->QuadsDrawTL(Array, i);
 	Graphics()->QuadsEnd();
@@ -369,7 +370,7 @@ void CHud::RenderHealthAndAmmo()
 
 	// render health
 	RenderTools()->SelectSprite(SPRITE_HEALTH_FULL);
-	for(; h < min(m_pClient->m_Snap.m_pLocalCharacter->m_Health, 10); h++)
+	for(; h < min(pCharacter->m_Health, 10); h++)
 		Array[h] = IGraphics::CQuadItem(x+h*12,y,10,10);
 	Graphics()->QuadsDrawTL(Array, h);
 
@@ -382,7 +383,7 @@ void CHud::RenderHealthAndAmmo()
 	// render armor meter
 	h = 0;
 	RenderTools()->SelectSprite(SPRITE_ARMOR_FULL);
-	for(; h < min(m_pClient->m_Snap.m_pLocalCharacter->m_Armor, 10); h++)
+	for(; h < min(pCharacter->m_Armor, 10); h++)
 		Array[h] = IGraphics::CQuadItem(x+h*12,y+12,10,10);
 	Graphics()->QuadsDrawTL(Array, h);
 
@@ -394,19 +395,39 @@ void CHud::RenderHealthAndAmmo()
 	Graphics()->QuadsEnd();
 }
 
+void CHud::RenderSpectatorHud()
+{
+	// draw the box
+	Graphics()->TextureSet(-1);
+	Graphics()->QuadsBegin();
+	Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.4f);
+	RenderTools()->DrawRoundRectExt(m_Width-180.0f, m_Height-15.0f, 180.0f, 15.0f, 5.0f, CUI::CORNER_TL);
+	Graphics()->QuadsEnd();
+
+	// draw the text
+	char aBuf[128];
+	str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Spectate"), m_pClient->m_Snap.m_pSpectatorInfo && m_pClient->m_Snap.m_pSpectatorInfo->m_SpectatorID != SPEC_FREEVIEW ?
+		m_pClient->m_aClients[m_pClient->m_Snap.m_pSpectatorInfo->m_SpectatorID].m_aName : Localize("Free-View"));
+	TextRender()->Text(0, m_Width-174.0f, m_Height-13.0f, 8.0f, aBuf, -1);
+}
+
 void CHud::OnRender()
 {
 	if(!m_pClient->m_Snap.m_pGameInfoObj)
 		return;
 		
-	m_Width = 300*Graphics()->ScreenAspect();
+	m_Width = 300.0f*Graphics()->ScreenAspect();
+	m_Height = 300.0f;
+	Graphics()->MapScreen(0.0f, 0.0f, m_Width, m_Height);
 
-	bool Spectate = false;
-	if(m_pClient->m_Snap.m_pLocalInfo && m_pClient->m_Snap.m_pLocalInfo->m_Team == TEAM_SPECTATORS)
-		Spectate = true;
-	
-	if(m_pClient->m_Snap.m_pLocalCharacter && !Spectate && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER))
-		RenderHealthAndAmmo();
+	if(m_pClient->m_Snap.m_pLocalCharacter && !(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER))
+		RenderHealthAndAmmo(m_pClient->m_Snap.m_pLocalCharacter);
+	else if(m_pClient->m_Snap.m_Spectate)
+	{
+		if(m_pClient->m_Snap.m_pSpectatorInfo && m_pClient->m_Snap.m_pSpectatorInfo->m_SpectatorID != SPEC_FREEVIEW)
+			RenderHealthAndAmmo(&m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_pSpectatorInfo->m_SpectatorID].m_Cur);
+		RenderSpectatorHud();
+	}
 
 	RenderGameTimer();
 	RenderSuddenDeath();