2010-11-20 10:37:14 +00:00
|
|
|
/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
|
|
|
|
/* If you are missing that file, acquire a complete release at teeworlds.com. */
|
2010-05-29 07:25:38 +00:00
|
|
|
#include <engine/graphics.h>
|
|
|
|
#include <engine/textrender.h>
|
|
|
|
#include <engine/shared/config.h>
|
|
|
|
|
|
|
|
#include <game/generated/protocol.h>
|
|
|
|
#include <game/generated/client_data.h>
|
|
|
|
#include <game/layers.h>
|
|
|
|
#include <game/client/gameclient.h>
|
|
|
|
#include <game/client/animstate.h>
|
|
|
|
#include <game/client/render.h>
|
|
|
|
|
|
|
|
#include "controls.h"
|
|
|
|
#include "camera.h"
|
|
|
|
#include "hud.h"
|
|
|
|
#include "voting.h"
|
|
|
|
#include "binds.h"
|
|
|
|
|
|
|
|
CHud::CHud()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
// won't work if zero
|
|
|
|
m_AverageFPS = 1.0f;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CHud::OnReset()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2010-05-30 12:01:11 +00:00
|
|
|
void CHud::RenderGameTimer()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-30 12:01:11 +00:00
|
|
|
float Half = 300.0f*Graphics()->ScreenAspect()/2.0f;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-04 16:08:10 +00:00
|
|
|
if(!(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_SUDDENDEATH))
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
char Buf[32];
|
|
|
|
int Time = 0;
|
2011-06-30 10:20:12 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && !m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-03-04 16:08:10 +00:00
|
|
|
Time = m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit*60 - ((Client()->GameTick()-m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick)/Client()->GameTickSpeed());
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2011-03-04 16:08:10 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER)
|
2011-04-13 18:37:12 +00:00
|
|
|
Time = 0;
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
else
|
2011-03-04 16:08:10 +00:00
|
|
|
Time = (Client()->GameTick()-m_pClient->m_Snap.m_pGameInfoObj->m_RoundStartTick)/Client()->GameTickSpeed();
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-30 12:01:11 +00:00
|
|
|
str_format(Buf, sizeof(Buf), "%d:%02d", Time/60, Time%60);
|
|
|
|
float FontSize = 10.0f;
|
|
|
|
float w = TextRender()->TextWidth(0, FontSize, Buf, -1);
|
2011-01-09 23:58:03 +00:00
|
|
|
// last 60 sec red, last 10 sec blink
|
2011-06-30 10:20:12 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj->m_TimeLimit && Time <= 60 && !m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)
|
2011-01-09 23:58:03 +00:00
|
|
|
{
|
|
|
|
float Alpha = Time <= 10 && (2*time_get()/time_freq()) % 2 ? 0.5f : 1.0f;
|
|
|
|
TextRender()->TextColor(1.0f, 0.25f, 0.25f, Alpha);
|
|
|
|
}
|
2010-05-30 12:01:11 +00:00
|
|
|
TextRender()->Text(0, Half-w/2, 2, FontSize, Buf, -1);
|
2011-01-09 23:58:03 +00:00
|
|
|
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
2010-05-30 12:01:11 +00:00
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-30 12:01:11 +00:00
|
|
|
void CHud::RenderSuddenDeath()
|
|
|
|
{
|
2011-03-04 16:08:10 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_SUDDENDEATH)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-30 12:01:11 +00:00
|
|
|
float Half = 300.0f*Graphics()->ScreenAspect()/2.0f;
|
2010-06-03 09:30:05 +00:00
|
|
|
const char *pText = Localize("Sudden Death");
|
2010-05-30 12:01:11 +00:00
|
|
|
float FontSize = 12.0f;
|
|
|
|
float w = TextRender()->TextWidth(0, FontSize, pText, -1);
|
|
|
|
TextRender()->Text(0, Half-w/2, 2, FontSize, pText, -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
2010-05-30 12:01:11 +00:00
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-30 12:01:11 +00:00
|
|
|
void CHud::RenderScoreHud()
|
2011-04-13 18:37:12 +00:00
|
|
|
{
|
2008-08-27 15:48:50 +00:00
|
|
|
// render small score hud
|
2011-03-04 16:08:10 +00:00
|
|
|
if(!(m_pClient->m_Snap.m_pGameInfoObj->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER))
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-03-04 16:08:10 +00:00
|
|
|
int GameFlags = m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags;
|
2011-01-12 00:01:05 +00:00
|
|
|
float Whole = 300*Graphics()->ScreenAspect();
|
|
|
|
|
2011-03-04 16:08:10 +00:00
|
|
|
if(GameFlags&GAMEFLAG_TEAMS && m_pClient->m_Snap.m_pGameDataObj)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-01-12 00:01:05 +00:00
|
|
|
char aScoreTeam[2][32];
|
2011-03-04 16:08:10 +00:00
|
|
|
str_format(aScoreTeam[TEAM_RED], sizeof(aScoreTeam)/2, "%d", m_pClient->m_Snap.m_pGameDataObj->m_TeamscoreRed);
|
|
|
|
str_format(aScoreTeam[TEAM_BLUE], sizeof(aScoreTeam)/2, "%d", m_pClient->m_Snap.m_pGameDataObj->m_TeamscoreBlue);
|
|
|
|
float aScoreTeamWidth[2] = { TextRender()->TextWidth(0, 14.0f, aScoreTeam[TEAM_RED], -1), TextRender()->TextWidth(0, 14.0f, aScoreTeam[TEAM_BLUE], -1) };
|
|
|
|
int FlagCarrier[2] = { m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierRed, m_pClient->m_Snap.m_pGameDataObj->m_FlagCarrierBlue };
|
2011-01-12 00:01:05 +00:00
|
|
|
float ScoreWidthMax = max(max(aScoreTeamWidth[TEAM_RED], aScoreTeamWidth[TEAM_BLUE]), TextRender()->TextWidth(0, 14.0f, "100", -1));
|
|
|
|
float Split = 3.0f;
|
|
|
|
float ImageSize = GameFlags&GAMEFLAG_FLAGS ? 16.0f : Split;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-01-12 00:01:05 +00:00
|
|
|
for(int t = 0; t < 2; t++)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-01-12 00:01:05 +00:00
|
|
|
// draw box
|
|
|
|
Graphics()->BlendNormal();
|
|
|
|
Graphics()->TextureSet(-1);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
if(t == 0)
|
|
|
|
Graphics()->SetColor(1.0f, 0.0f, 0.0f, 0.25f);
|
|
|
|
else
|
|
|
|
Graphics()->SetColor(0.0f, 0.0f, 1.0f, 0.25f);
|
|
|
|
RenderTools()->DrawRoundRectExt(Whole-ScoreWidthMax-ImageSize-2*Split, 245.0f+t*20, ScoreWidthMax+ImageSize+2*Split, 18.0f, 5.0f, CUI::CORNER_L);
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
|
|
|
|
// draw score
|
|
|
|
TextRender()->Text(0, Whole-ScoreWidthMax+(ScoreWidthMax-aScoreTeamWidth[t])/2-Split, 245.0f+t*20, 14.0f, aScoreTeam[t], -1);
|
|
|
|
|
2011-03-04 16:08:10 +00:00
|
|
|
if(GameFlags&GAMEFLAG_FLAGS)
|
2010-06-22 19:27:58 +00:00
|
|
|
{
|
2011-08-11 08:59:14 +00:00
|
|
|
int BlinkTimer = (m_pClient->m_FlagDropTick[t] != 0 &&
|
2011-07-05 21:15:24 +00:00
|
|
|
(Client()->GameTick()-m_pClient->m_FlagDropTick[t])/Client()->GameTickSpeed() >= 25) ? 10 : 20;
|
|
|
|
if(FlagCarrier[t] == FLAG_ATSTAND || (FlagCarrier[t] == FLAG_TAKEN && ((Client()->GameTick()/BlinkTimer)&1)))
|
2011-01-12 00:01:05 +00:00
|
|
|
{
|
|
|
|
// draw flag
|
|
|
|
Graphics()->BlendNormal();
|
|
|
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
RenderTools()->SelectSprite(t==0?SPRITE_FLAG_RED:SPRITE_FLAG_BLUE);
|
|
|
|
IGraphics::CQuadItem QuadItem(Whole-ScoreWidthMax-ImageSize, 246.0f+t*20, ImageSize/2, ImageSize);
|
|
|
|
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
}
|
2011-03-04 16:08:10 +00:00
|
|
|
else if(FlagCarrier[t] >= 0)
|
2011-01-12 00:01:05 +00:00
|
|
|
{
|
|
|
|
// draw name of the flag holder
|
2011-03-04 16:08:10 +00:00
|
|
|
int ID = FlagCarrier[t]%MAX_CLIENTS;
|
2011-02-12 10:40:36 +00:00
|
|
|
const char *pName = m_pClient->m_aClients[ID].m_aName;
|
2011-01-12 00:01:05 +00:00
|
|
|
float w = TextRender()->TextWidth(0, 10.0f, pName, -1);
|
|
|
|
TextRender()->Text(0, Whole-ScoreWidthMax-ImageSize-3*Split-w, 247.0f+t*20, 10.0f, pName, -1);
|
|
|
|
|
|
|
|
// draw tee of the flag holder
|
2011-02-12 10:40:36 +00:00
|
|
|
CTeeRenderInfo Info = m_pClient->m_aClients[ID].m_RenderInfo;
|
2011-01-12 00:01:05 +00:00
|
|
|
Info.m_Size = 18.0f;
|
|
|
|
RenderTools()->RenderTee(CAnimState::GetIdle(), &Info, EMOTE_NORMAL, vec2(1,0),
|
|
|
|
vec2(Whole-ScoreWidthMax-Info.m_Size/2-Split, 246.0f+Info.m_Size/2+t*20));
|
|
|
|
}
|
2010-06-22 19:27:58 +00:00
|
|
|
}
|
2011-01-12 00:01:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-01-18 16:56:09 +00:00
|
|
|
int Local = -1;
|
2011-01-12 00:01:05 +00:00
|
|
|
int aPos[2] = { 1, 2 };
|
2011-01-18 16:56:09 +00:00
|
|
|
const CNetObj_PlayerInfo *apPlayerInfo[2] = { 0, 0 };
|
|
|
|
int i = 0;
|
|
|
|
for(int t = 0; t < 2 && i < MAX_CLIENTS && m_pClient->m_Snap.m_paInfoByScore[i]; ++i)
|
2011-01-12 00:01:05 +00:00
|
|
|
{
|
2011-01-18 16:56:09 +00:00
|
|
|
if(m_pClient->m_Snap.m_paInfoByScore[i]->m_Team != TEAM_SPECTATORS)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-01-18 16:56:09 +00:00
|
|
|
apPlayerInfo[t] = m_pClient->m_Snap.m_paInfoByScore[i];
|
2011-02-12 10:40:36 +00:00
|
|
|
if(apPlayerInfo[t]->m_ClientID == m_pClient->m_Snap.m_LocalClientID)
|
2011-01-18 16:56:09 +00:00
|
|
|
Local = t;
|
|
|
|
++t;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// search local player info if not a spectator, nor within top2 scores
|
|
|
|
if(Local == -1 && m_pClient->m_Snap.m_pLocalInfo && m_pClient->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS)
|
|
|
|
{
|
|
|
|
for(; i < MAX_CLIENTS && m_pClient->m_Snap.m_paInfoByScore[i]; ++i)
|
|
|
|
{
|
|
|
|
if(m_pClient->m_Snap.m_paInfoByScore[i]->m_Team != TEAM_SPECTATORS)
|
|
|
|
++aPos[1];
|
2011-02-12 10:40:36 +00:00
|
|
|
if(m_pClient->m_Snap.m_paInfoByScore[i]->m_ClientID == m_pClient->m_Snap.m_LocalClientID)
|
2011-01-18 16:56:09 +00:00
|
|
|
{
|
|
|
|
apPlayerInfo[1] = m_pClient->m_Snap.m_paInfoByScore[i];
|
|
|
|
Local = 1;
|
|
|
|
break;
|
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
2011-01-12 00:01:05 +00:00
|
|
|
}
|
|
|
|
char aScore[2][32];
|
|
|
|
for(int t = 0; t < 2; ++t)
|
|
|
|
{
|
|
|
|
if(apPlayerInfo[t])
|
|
|
|
str_format(aScore[t], sizeof(aScore)/2, "%d", apPlayerInfo[t]->m_Score);
|
|
|
|
else
|
|
|
|
aScore[t][0] = 0;
|
|
|
|
}
|
|
|
|
float aScoreWidth[2] = {TextRender()->TextWidth(0, 14.0f, aScore[0], -1), TextRender()->TextWidth(0, 14.0f, aScore[1], -1)};
|
|
|
|
float ScoreWidthMax = max(max(aScoreWidth[0], aScoreWidth[1]), TextRender()->TextWidth(0, 14.0f, "10", -1));
|
|
|
|
float Split = 3.0f, ImageSize = 16.0f, PosSize = 16.0f;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-01-12 00:01:05 +00:00
|
|
|
for(int t = 0; t < 2; t++)
|
|
|
|
{
|
|
|
|
// draw box
|
|
|
|
Graphics()->BlendNormal();
|
|
|
|
Graphics()->TextureSet(-1);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
if(t == Local)
|
|
|
|
Graphics()->SetColor(1.0f, 1.0f, 1.0f, 0.25f);
|
|
|
|
else
|
|
|
|
Graphics()->SetColor(0.0f, 0.0f, 0.0f, 0.25f);
|
|
|
|
RenderTools()->DrawRoundRectExt(Whole-ScoreWidthMax-ImageSize-2*Split-PosSize, 245.0f+t*20, ScoreWidthMax+ImageSize+2*Split+PosSize, 18.0f, 5.0f, CUI::CORNER_L);
|
|
|
|
Graphics()->QuadsEnd();
|
|
|
|
|
|
|
|
// draw score
|
|
|
|
TextRender()->Text(0, Whole-ScoreWidthMax+(ScoreWidthMax-aScoreWidth[t])/2-Split, 245.0f+t*20, 14.0f, aScore[t], -1);
|
|
|
|
|
|
|
|
// draw tee
|
|
|
|
if(apPlayerInfo[t])
|
|
|
|
{
|
2011-02-12 10:40:36 +00:00
|
|
|
CTeeRenderInfo Info = m_pClient->m_aClients[apPlayerInfo[t]->m_ClientID].m_RenderInfo;
|
2011-01-12 00:01:05 +00:00
|
|
|
Info.m_Size = 18.0f;
|
|
|
|
RenderTools()->RenderTee(CAnimState::GetIdle(), &Info, EMOTE_NORMAL, vec2(1,0),
|
|
|
|
vec2(Whole-ScoreWidthMax-Info.m_Size/2-Split, 246.0f+Info.m_Size/2+t*20));
|
|
|
|
}
|
|
|
|
|
|
|
|
// draw position
|
|
|
|
char aBuf[32];
|
|
|
|
str_format(aBuf, sizeof(aBuf), "%d.", aPos[t]);
|
|
|
|
TextRender()->Text(0, Whole-ScoreWidthMax-ImageSize-Split-PosSize, 247.0f+t*20, 10.0f, aBuf, -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2010-05-30 12:01:11 +00:00
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-30 12:01:11 +00:00
|
|
|
void CHud::RenderWarmupTimer()
|
|
|
|
{
|
2008-08-27 15:48:50 +00:00
|
|
|
// render warmup timer
|
2011-03-04 16:08:10 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
char Buf[256];
|
2010-05-30 12:01:11 +00:00
|
|
|
float FontSize = 20.0f;
|
2010-06-03 09:30:05 +00:00
|
|
|
float w = TextRender()->TextWidth(0, FontSize, Localize("Warmup"), -1);
|
|
|
|
TextRender()->Text(0, 150*Graphics()->ScreenAspect()+-w/2, 50, FontSize, Localize("Warmup"), -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2011-03-04 16:08:10 +00:00
|
|
|
int Seconds = m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer/SERVER_TICK_SPEED;
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Seconds < 5)
|
2011-03-04 16:08:10 +00:00
|
|
|
str_format(Buf, sizeof(Buf), "%d.%d", Seconds, (m_pClient->m_Snap.m_pGameInfoObj->m_WarmupTimer*10/SERVER_TICK_SPEED)%10);
|
2008-08-27 15:48:50 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
str_format(Buf, sizeof(Buf), "%d", Seconds);
|
2010-05-30 12:01:11 +00:00
|
|
|
w = TextRender()->TextWidth(0, FontSize, Buf, -1);
|
|
|
|
TextRender()->Text(0, 150*Graphics()->ScreenAspect()+-w/2, 75, FontSize, Buf, -1);
|
2011-04-13 18:37:12 +00:00
|
|
|
}
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CHud::MapscreenToGroup(float CenterX, float CenterY, CMapItemGroup *pGroup)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
float Points[4];
|
|
|
|
RenderTools()->MapscreenToWorld(CenterX, CenterY, pGroup->m_ParallaxX/100.0f, pGroup->m_ParallaxY/100.0f,
|
|
|
|
pGroup->m_OffsetX, pGroup->m_OffsetY, Graphics()->ScreenAspect(), 1.0f, Points);
|
|
|
|
Graphics()->MapScreen(Points[0], Points[1], Points[2], Points[3]);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CHud::RenderFps()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(g_Config.m_ClShowfps)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
// calculate avg. fps
|
2012-01-01 12:38:46 +00:00
|
|
|
float FPS = 1.0f / Client()->RenderFrameTime();
|
2010-05-29 07:25:38 +00:00
|
|
|
m_AverageFPS = (m_AverageFPS*(1.0f-(1.0f/m_AverageFPS))) + (FPS*(1.0f/m_AverageFPS));
|
|
|
|
char Buf[512];
|
|
|
|
str_format(Buf, sizeof(Buf), "%d", (int)m_AverageFPS);
|
|
|
|
TextRender()->Text(0, m_Width-10-TextRender()->TextWidth(0,12,Buf,-1), 5, 12, Buf, -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CHud::RenderConnectionWarning()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Client()->ConnectionProblems())
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-06-03 09:30:05 +00:00
|
|
|
const char *pText = Localize("Connection Problems...");
|
2010-05-29 07:25:38 +00:00
|
|
|
float w = TextRender()->TextWidth(0, 24, pText, -1);
|
|
|
|
TextRender()->Text(0, 150*Graphics()->ScreenAspect()-w/2, 50, 24, pText, -1);
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CHud::RenderTeambalanceWarning()
|
2008-09-01 18:17:01 +00:00
|
|
|
{
|
|
|
|
// render prompt about team-balance
|
2010-05-29 07:25:38 +00:00
|
|
|
bool Flash = time_get()/(time_freq()/2)%2 == 0;
|
2011-03-04 16:08:10 +00:00
|
|
|
if(m_pClient->m_Snap.m_pGameInfoObj->m_GameFlags&GAMEFLAG_TEAMS)
|
2011-04-13 18:37:12 +00:00
|
|
|
{
|
2011-01-03 11:50:38 +00:00
|
|
|
int TeamDiff = m_pClient->m_Snap.m_aTeamSize[TEAM_RED]-m_pClient->m_Snap.m_aTeamSize[TEAM_BLUE];
|
2010-05-29 07:25:38 +00:00
|
|
|
if (g_Config.m_ClWarningTeambalance && (TeamDiff >= 2 || TeamDiff <= -2))
|
2008-09-01 18:17:01 +00:00
|
|
|
{
|
2010-06-03 09:30:05 +00:00
|
|
|
const char *pText = Localize("Please balance teams!");
|
2010-05-29 07:25:38 +00:00
|
|
|
if(Flash)
|
|
|
|
TextRender()->TextColor(1,1,0.5f,1);
|
2008-09-01 18:17:01 +00:00
|
|
|
else
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->TextColor(0.7f,0.7f,0.2f,1.0f);
|
|
|
|
TextRender()->Text(0x0, 5, 50, 6, pText, -1);
|
|
|
|
TextRender()->TextColor(1,1,1,1);
|
2008-09-01 18:17:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-09-25 14:04:02 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CHud::RenderVoting()
|
2008-09-25 14:04:02 +00:00
|
|
|
{
|
2010-10-12 23:19:22 +00:00
|
|
|
if(!m_pClient->m_pVoting->IsVoting() || Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
2008-09-25 14:04:02 +00:00
|
|
|
return;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->TextureSet(-1);
|
|
|
|
Graphics()->QuadsBegin();
|
|
|
|
Graphics()->SetColor(0,0,0,0.40f);
|
2011-03-25 09:26:59 +00:00
|
|
|
RenderTools()->DrawRoundRect(-10, 60-2, 100+10+4+5, 46, 5.0f);
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->QuadsEnd();
|
2009-01-21 21:17:25 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
TextRender()->TextColor(1,1,1,1);
|
2009-01-21 21:17:25 +00:00
|
|
|
|
2010-09-12 11:18:11 +00:00
|
|
|
CTextCursor Cursor;
|
2011-03-25 09:26:59 +00:00
|
|
|
char aBuf[512];
|
|
|
|
str_format(aBuf, sizeof(aBuf), Localize("%ds left"), m_pClient->m_pVoting->SecondsLeft());
|
|
|
|
float tw = TextRender()->TextWidth(0x0, 6, aBuf, -1);
|
|
|
|
TextRender()->SetCursor(&Cursor, 5.0f+100.0f-tw, 60.0f, 6.0f, TEXTFLAG_RENDER);
|
|
|
|
TextRender()->TextEx(&Cursor, aBuf, -1);
|
2010-09-12 11:18:11 +00:00
|
|
|
|
2011-03-25 09:26:59 +00:00
|
|
|
TextRender()->SetCursor(&Cursor, 5.0f, 60.0f, 6.0f, TEXTFLAG_RENDER);
|
|
|
|
Cursor.m_LineWidth = 100.0f-tw;
|
|
|
|
Cursor.m_MaxLines = 3;
|
|
|
|
TextRender()->TextEx(&Cursor, m_pClient->m_pVoting->VoteDescription(), -1);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-25 09:26:59 +00:00
|
|
|
// reason
|
|
|
|
str_format(aBuf, sizeof(aBuf), "%s %s", Localize("Reason:"), m_pClient->m_pVoting->VoteReason());
|
|
|
|
TextRender()->SetCursor(&Cursor, 5.0f, 79.0f, 6.0f, TEXTFLAG_RENDER|TEXTFLAG_STOP_AT_END);
|
|
|
|
Cursor.m_LineWidth = 100.0f;
|
|
|
|
TextRender()->TextEx(&Cursor, aBuf, -1);
|
2009-01-21 21:17:25 +00:00
|
|
|
|
2011-03-25 09:26:59 +00:00
|
|
|
CUIRect Base = {5, 88, 100, 4};
|
2010-05-29 07:25:38 +00:00
|
|
|
m_pClient->m_pVoting->RenderBars(Base, false);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
const char *pYesKey = m_pClient->m_pBinds->GetKey("vote yes");
|
|
|
|
const char *pNoKey = m_pClient->m_pBinds->GetKey("vote no");
|
2011-03-25 09:26:59 +00:00
|
|
|
str_format(aBuf, sizeof(aBuf), "%s - %s", pYesKey, Localize("Vote yes"));
|
2010-05-29 07:25:38 +00:00
|
|
|
Base.y += Base.h+1;
|
2011-03-25 09:26:59 +00:00
|
|
|
UI()->DoLabel(&Base, aBuf, 6.0f, -1);
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-03-25 09:26:59 +00:00
|
|
|
str_format(aBuf, sizeof(aBuf), "%s - %s", Localize("Vote no"), pNoKey);
|
|
|
|
UI()->DoLabel(&Base, aBuf, 6.0f, 1);
|
2008-09-25 14:04:02 +00:00
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CHud::RenderCursor()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2010-09-08 00:07:36 +00:00
|
|
|
if(!m_pClient->m_Snap.m_pLocalCharacter || Client()->State() == IClient::STATE_DEMOPLAYBACK)
|
2008-08-31 13:36:30 +00:00
|
|
|
return;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
MapscreenToGroup(m_pClient->m_pCamera->m_Center.x, m_pClient->m_pCamera->m_Center.y, Layers()->GameGroup());
|
|
|
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->QuadsBegin();
|
2008-08-27 15:48:50 +00:00
|
|
|
|
|
|
|
// render cursor
|
2010-05-29 07:25:38 +00:00
|
|
|
RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[m_pClient->m_Snap.m_pLocalCharacter->m_Weapon%NUM_WEAPONS].m_pSpriteCursor);
|
|
|
|
float CursorSize = 64;
|
|
|
|
RenderTools()->DrawSprite(m_pClient->m_pControls->m_TargetPos.x, m_pClient->m_pControls->m_TargetPos.y, CursorSize);
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->QuadsEnd();
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
void CHud::RenderHealthAndAmmo(const CNetObj_Character *pCharacter)
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-03-10 09:08:14 +00:00
|
|
|
if(!pCharacter)
|
|
|
|
return;
|
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
//mapscreen_to_group(gacenter_x, center_y, layers_game_group());
|
|
|
|
|
|
|
|
float x = 5;
|
|
|
|
float y = 5;
|
|
|
|
|
|
|
|
// render ammo count
|
|
|
|
// render gui stuff
|
2008-08-27 20:18:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_GAME].m_Id);
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->QuadsBegin();
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2008-08-27 15:48:50 +00:00
|
|
|
// if weaponstage is active, put a "glow" around the stage ammo
|
2011-03-10 09:08:14 +00:00
|
|
|
RenderTools()->SelectSprite(g_pData->m_Weapons.m_aId[pCharacter->m_Weapon%NUM_WEAPONS].m_pSpriteProj);
|
2010-05-29 07:25:38 +00:00
|
|
|
IGraphics::CQuadItem Array[10];
|
|
|
|
int i;
|
2011-03-10 09:08:14 +00:00
|
|
|
for (i = 0; i < min(pCharacter->m_AmmoCount, 10); i++)
|
2010-05-29 07:25:38 +00:00
|
|
|
Array[i] = IGraphics::CQuadItem(x+i*12,y+24,10,10);
|
|
|
|
Graphics()->QuadsDrawTL(Array, i);
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->QuadsEnd();
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->QuadsBegin();
|
2008-08-27 15:48:50 +00:00
|
|
|
int h = 0;
|
|
|
|
|
|
|
|
// render health
|
2010-05-29 07:25:38 +00:00
|
|
|
RenderTools()->SelectSprite(SPRITE_HEALTH_FULL);
|
2011-03-10 09:08:14 +00:00
|
|
|
for(; h < min(pCharacter->m_Health, 10); h++)
|
2010-05-29 07:25:38 +00:00
|
|
|
Array[h] = IGraphics::CQuadItem(x+h*12,y,10,10);
|
|
|
|
Graphics()->QuadsDrawTL(Array, h);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
i = 0;
|
|
|
|
RenderTools()->SelectSprite(SPRITE_HEALTH_EMPTY);
|
2008-08-27 15:48:50 +00:00
|
|
|
for(; h < 10; h++)
|
2010-05-29 07:25:38 +00:00
|
|
|
Array[i++] = IGraphics::CQuadItem(x+h*12,y,10,10);
|
|
|
|
Graphics()->QuadsDrawTL(Array, i);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
|
|
|
// render armor meter
|
|
|
|
h = 0;
|
2010-05-29 07:25:38 +00:00
|
|
|
RenderTools()->SelectSprite(SPRITE_ARMOR_FULL);
|
2011-03-10 09:08:14 +00:00
|
|
|
for(; h < min(pCharacter->m_Armor, 10); h++)
|
2010-05-29 07:25:38 +00:00
|
|
|
Array[h] = IGraphics::CQuadItem(x+h*12,y+12,10,10);
|
|
|
|
Graphics()->QuadsDrawTL(Array, h);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
i = 0;
|
|
|
|
RenderTools()->SelectSprite(SPRITE_ARMOR_EMPTY);
|
2008-08-27 15:48:50 +00:00
|
|
|
for(; h < 10; h++)
|
2010-05-29 07:25:38 +00:00
|
|
|
Array[i++] = IGraphics::CQuadItem(x+h*12,y+12,10,10);
|
|
|
|
Graphics()->QuadsDrawTL(Array, i);
|
2009-10-27 14:38:53 +00:00
|
|
|
Graphics()->QuadsEnd();
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
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];
|
2011-03-12 17:07:57 +00:00
|
|
|
str_format(aBuf, sizeof(aBuf), "%s: %s", Localize("Spectate"), m_pClient->m_Snap.m_SpecInfo.m_SpectatorID != SPEC_FREEVIEW ?
|
|
|
|
m_pClient->m_aClients[m_pClient->m_Snap.m_SpecInfo.m_SpectatorID].m_aName : Localize("Free-View"));
|
2011-03-10 09:08:14 +00:00
|
|
|
TextRender()->Text(0, m_Width-174.0f, m_Height-13.0f, 8.0f, aBuf, -1);
|
|
|
|
}
|
|
|
|
|
2010-05-29 07:25:38 +00:00
|
|
|
void CHud::OnRender()
|
2008-08-27 15:48:50 +00:00
|
|
|
{
|
2011-03-04 16:08:10 +00:00
|
|
|
if(!m_pClient->m_Snap.m_pGameInfoObj)
|
2008-08-27 15:48:50 +00:00
|
|
|
return;
|
2011-04-13 18:37:12 +00:00
|
|
|
|
2011-03-10 09:08:14 +00:00
|
|
|
m_Width = 300.0f*Graphics()->ScreenAspect();
|
|
|
|
m_Height = 300.0f;
|
|
|
|
Graphics()->MapScreen(0.0f, 0.0f, m_Width, m_Height);
|
2008-08-27 15:48:50 +00:00
|
|
|
|
2011-03-27 12:40:15 +00:00
|
|
|
if(g_Config.m_ClShowhud)
|
2011-03-10 09:08:14 +00:00
|
|
|
{
|
2011-03-27 12:40:15 +00:00
|
|
|
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_SpecInfo.m_Active)
|
|
|
|
{
|
|
|
|
if(m_pClient->m_Snap.m_SpecInfo.m_SpectatorID != SPEC_FREEVIEW)
|
|
|
|
RenderHealthAndAmmo(&m_pClient->m_Snap.m_aCharacters[m_pClient->m_Snap.m_SpecInfo.m_SpectatorID].m_Cur);
|
|
|
|
RenderSpectatorHud();
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
|
2011-03-27 12:40:15 +00:00
|
|
|
RenderGameTimer();
|
|
|
|
RenderSuddenDeath();
|
|
|
|
RenderScoreHud();
|
|
|
|
RenderWarmupTimer();
|
|
|
|
RenderFps();
|
|
|
|
if(Client()->State() != IClient::STATE_DEMOPLAYBACK)
|
|
|
|
RenderConnectionWarning();
|
|
|
|
RenderTeambalanceWarning();
|
|
|
|
RenderVoting();
|
|
|
|
}
|
2010-05-29 07:25:38 +00:00
|
|
|
RenderCursor();
|
2008-08-27 15:48:50 +00:00
|
|
|
}
|