mirror of
https://github.com/ddnet/ddnet.git
synced 2024-11-19 14:38:18 +00:00
Scoreboard fixes & improvements, moved the scoreboard up, just below the HUD. Improve display of spectators
This commit is contained in:
parent
8ec70a1bde
commit
98c99ad631
|
@ -36,7 +36,7 @@ void CScoreboard::OnReset()
|
|||
m_Active = false;
|
||||
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
m_aPlayerStats[i].Reset();
|
||||
ResetPlayerStats(i);
|
||||
}
|
||||
|
||||
void CScoreboard::OnRelease()
|
||||
|
@ -84,7 +84,6 @@ void CScoreboard::RenderGoals(float x, float y, float w)
|
|||
float CScoreboard::RenderSpectators(float x, float y, float w)
|
||||
{
|
||||
float h = 20.0f;
|
||||
float StartY = y;
|
||||
|
||||
int NumSpectators = 0;
|
||||
for(int i = 0; i < MAX_CLIENTS; i++)
|
||||
|
@ -99,7 +98,8 @@ float CScoreboard::RenderSpectators(float x, float y, float w)
|
|||
// do all the text without rendering it once
|
||||
CTextCursor Cursor;
|
||||
TextRender()->SetCursor(&Cursor, x, y, 12.0f, TEXTFLAG_ALLOW_NEWLINE);
|
||||
Cursor.m_LineWidth = w-tw-20.0f;
|
||||
Cursor.m_LineWidth = w-17.0f;
|
||||
Cursor.m_StartX -= tw+3.0f;
|
||||
bool Multiple = false;
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||
{
|
||||
|
@ -109,9 +109,12 @@ float CScoreboard::RenderSpectators(float x, float y, float w)
|
|||
|
||||
if(Multiple)
|
||||
TextRender()->TextEx(&Cursor, ", ", -1);
|
||||
if(m_pClient->m_aClients[i].m_aClan[0])
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "%s ", m_pClient->m_aClients[i].m_aClan);
|
||||
TextRender()->TextEx(&Cursor, aBuf, -1);
|
||||
}
|
||||
TextRender()->TextEx(&Cursor, m_pClient->m_aClients[i].m_aName, -1);
|
||||
str_format(aBuf, sizeof(aBuf), " (%s)", m_pClient->m_aClients[i].m_aClan);
|
||||
TextRender()->TextEx(&Cursor, aBuf, -1);
|
||||
Multiple = true;
|
||||
}
|
||||
|
||||
|
@ -129,7 +132,8 @@ float CScoreboard::RenderSpectators(float x, float y, float w)
|
|||
x += tw+2.0f+10.0f;
|
||||
Multiple = false;
|
||||
TextRender()->SetCursor(&Cursor, x, y, 12.0f, TEXTFLAG_RENDER|TEXTFLAG_ALLOW_NEWLINE);
|
||||
Cursor.m_LineWidth = w-tw-20.0f;
|
||||
Cursor.m_LineWidth = w-17.0f;
|
||||
Cursor.m_StartX -= tw+3.0f;
|
||||
for(int i = 0; i < MAX_CLIENTS; ++i)
|
||||
{
|
||||
const CNetObj_PlayerInfo *pInfo = m_pClient->m_Snap.m_paPlayerInfos[i];
|
||||
|
@ -138,11 +142,14 @@ float CScoreboard::RenderSpectators(float x, float y, float w)
|
|||
|
||||
if(Multiple)
|
||||
TextRender()->TextEx(&Cursor, ", ", -1);
|
||||
if(pInfo->m_PlayerFlags&PLAYERFLAG_WATCHING)
|
||||
TextRender()->TextColor(1.0f, 1.0f, 0.0f, 1.0f);
|
||||
if(m_pClient->m_aClients[i].m_aClan[0])
|
||||
{
|
||||
str_format(aBuf, sizeof(aBuf), "%s ", m_pClient->m_aClients[i].m_aClan);
|
||||
TextRender()->TextColor(1.0f, 1.0f, (pInfo->m_PlayerFlags&PLAYERFLAG_WATCHING) ? 0.0f : 1.0f, 0.7f);
|
||||
TextRender()->TextEx(&Cursor, aBuf, -1);
|
||||
}
|
||||
TextRender()->TextColor(1.0f, 1.0f, (pInfo->m_PlayerFlags&PLAYERFLAG_WATCHING) ? 0.0f : 1.0f, 1.0f);
|
||||
TextRender()->TextEx(&Cursor, m_pClient->m_aClients[i].m_aName, -1);
|
||||
str_format(aBuf, sizeof(aBuf), " (%s)", m_pClient->m_aClients[i].m_aClan);
|
||||
TextRender()->TextEx(&Cursor, aBuf, -1);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
Multiple = true;
|
||||
}
|
||||
|
@ -161,13 +168,13 @@ float CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const c
|
|||
float LineHeight = 20.0f;
|
||||
float TeeSizeMod = 1.0f;
|
||||
float Spacing = 2.0f;
|
||||
float NameOffset = x+4.0f, NameLength = 136.0f;
|
||||
float TeeOffset = x+4.0f, TeeLength = 25*TeeSizeMod;
|
||||
float ScoreOffset = x+4.0f, ScoreLength = 35.0f;
|
||||
float NameOffset = x+4.0f+ScoreLength, NameLength = 136.0f;
|
||||
float TeeOffset = x+4.0f+ScoreLength, TeeLength = 25*TeeSizeMod;
|
||||
float ClanOffset = NameOffset+NameLength, ClanLength = 90.0f;
|
||||
float KillOffset = ClanOffset+ClanLength, KillLength = 30.0f;
|
||||
float DeathOffset = KillOffset+KillLength, DeathLength = 30.0f;
|
||||
float ScoreOffset = DeathOffset+DeathLength, ScoreLength = 35.0f;
|
||||
float PingOffset = ScoreOffset+ScoreLength, PingLength = 35.0f;
|
||||
float PingOffset = DeathOffset+DeathLength, PingLength = 35.0f;
|
||||
float tw = 0.0f;
|
||||
|
||||
bool NoTitle = pTitle? false : true;
|
||||
|
@ -278,9 +285,13 @@ float CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const c
|
|||
CUIRect Rect = {x, y+LineHeight, w, LineHeight*(m_PlayerLines)};
|
||||
RenderTools()->DrawRoundRect(&Rect, vec4(0.0f, 0.0f, 0.0f, 0.25f), 5.0f);
|
||||
}
|
||||
|
||||
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
TextRender()->Text(0, NameOffset, y+Spacing, HeadlineFontsize, Localize("Name"), -1);
|
||||
tw = TextRender()->TextWidth(0, HeadlineFontsize, Localize("Score"), -1);
|
||||
TextRender()->Text(0, ScoreOffset, y+Spacing, HeadlineFontsize, Localize("Score"), -1);
|
||||
|
||||
TextRender()->Text(0, NameOffset+TeeLength, y+Spacing, HeadlineFontsize, Localize("Name"), -1);
|
||||
|
||||
tw = TextRender()->TextWidth(0, HeadlineFontsize, Localize("Clan"), -1);
|
||||
TextRender()->Text(0, ClanOffset+ClanLength/2-tw/2, y+Spacing, HeadlineFontsize, Localize("Clan"), -1);
|
||||
|
@ -293,9 +304,6 @@ float CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const c
|
|||
TextRender()->Text(0, DeathOffset+DeathLength/2-tw/2, y+Spacing, HeadlineFontsize, Localize("D"), -1);
|
||||
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
tw = TextRender()->TextWidth(0, HeadlineFontsize, Localize("Score"), -1);
|
||||
TextRender()->Text(0, ScoreOffset+ScoreLength/2-tw/2, y+Spacing, HeadlineFontsize, Localize("Score"), -1);
|
||||
|
||||
tw = TextRender()->TextWidth(0, HeadlineFontsize, Localize("Ping"), -1);
|
||||
TextRender()->Text(0, PingOffset+PingLength-tw, y+Spacing, HeadlineFontsize, Localize("Ping"), -1);
|
||||
TextRender()->TextColor(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
|
@ -358,7 +366,12 @@ float CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const c
|
|||
Graphics()->BlendNormal();
|
||||
Graphics()->TextureSet(g_pData->m_aImages[IMAGE_DEADTEE].m_Id);
|
||||
Graphics()->QuadsBegin();
|
||||
IGraphics::CQuadItem QuadItem(TeeOffset, y+Spacing, 20*TeeSizeMod, 20*TeeSizeMod);
|
||||
if(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS)
|
||||
{
|
||||
vec4 Color = m_pClient->m_pSkins->GetColorV4(m_pClient->m_pSkins->GetTeamColor(true, 0, m_pClient->m_aClients[pInfo->m_ClientID].m_Team, SKINPART_BODY), false);
|
||||
Graphics()->SetColor(Color.r, Color.g, Color.b, Color.a);
|
||||
}
|
||||
IGraphics::CQuadItem QuadItem(TeeOffset+TeeLength/2 - 10*TeeSizeMod, y+Spacing, 20*TeeSizeMod, 20*TeeSizeMod);
|
||||
Graphics()->QuadsDrawTL(&QuadItem, 1);
|
||||
Graphics()->QuadsEnd();
|
||||
}
|
||||
|
@ -369,6 +382,14 @@ float CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const c
|
|||
RenderTools()->RenderTee(CAnimState::GetIdle(), &TeeInfo, EMOTE_NORMAL, vec2(1.0f, 0.0f), vec2(TeeOffset+TeeLength/2, y+LineHeight/2+Spacing));
|
||||
}
|
||||
|
||||
// score
|
||||
TextRender()->TextColor(TextColor.r, TextColor.g, TextColor.b, ColorAlpha);
|
||||
str_format(aBuf, sizeof(aBuf), "%d", clamp(pInfo->m_pPlayerInfo->m_Score, -999, 999));
|
||||
tw = TextRender()->TextWidth(0, FontSize, aBuf, -1);
|
||||
TextRender()->SetCursor(&Cursor, ScoreOffset+ScoreLength/2-tw/2, y+Spacing, FontSize, TEXTFLAG_RENDER);
|
||||
Cursor.m_LineWidth = ScoreLength;
|
||||
TextRender()->TextEx(&Cursor, aBuf, -1);
|
||||
|
||||
// name
|
||||
// todo: improve visual player ready state
|
||||
if(!(pInfo->m_pPlayerInfo->m_PlayerFlags&PLAYERFLAG_READY))
|
||||
|
@ -401,14 +422,6 @@ float CScoreboard::RenderScoreboard(float x, float y, float w, int Team, const c
|
|||
Cursor.m_LineWidth = DeathLength;
|
||||
TextRender()->TextEx(&Cursor, aBuf, -1);
|
||||
|
||||
// score
|
||||
TextRender()->TextColor(TextColor.r, TextColor.g, TextColor.b, ColorAlpha);
|
||||
str_format(aBuf, sizeof(aBuf), "%d", clamp(pInfo->m_pPlayerInfo->m_Score, -999, 999));
|
||||
tw = TextRender()->TextWidth(0, FontSize, aBuf, -1);
|
||||
TextRender()->SetCursor(&Cursor, ScoreOffset+ScoreLength/2-tw/2, y+Spacing, FontSize, TEXTFLAG_RENDER);
|
||||
Cursor.m_LineWidth = ScoreLength;
|
||||
TextRender()->TextEx(&Cursor, aBuf, -1);
|
||||
|
||||
// country flag
|
||||
/*vec4 Color(1.0f, 1.0f, 1.0f, 0.5f*ColorAlpha);
|
||||
m_pClient->m_pCountryFlags->Render(m_pClient->m_aClients[pInfo->m_ClientID].m_Country, &Color,
|
||||
|
@ -470,20 +483,22 @@ void CScoreboard::OnRender()
|
|||
Graphics()->MapScreen(Screen.x, Screen.y, Screen.w, Screen.h);
|
||||
|
||||
float Width = Screen.w;
|
||||
float y = 85.f;
|
||||
float w = 364.0f;
|
||||
float FontSize = 86.0f;
|
||||
|
||||
if(m_pClient->m_Snap.m_pGameData)
|
||||
{
|
||||
if(!(m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS))
|
||||
{
|
||||
float ScoreboardHeight = RenderScoreboard(Width/2-w/2, 70.0f, w, 0, 0, -1);
|
||||
float ScoreboardHeight = RenderScoreboard(Width/2-w/2, y, w, 0, 0, -1);
|
||||
|
||||
float SpectatorHeight = RenderSpectators(Width/2-w/2, 73.0f+ScoreboardHeight, w);
|
||||
RenderGoals(Width/2-w/2, 73.0f+ScoreboardHeight, w);
|
||||
float SpectatorHeight = RenderSpectators(Width/2-w/2, y+3.0f+ScoreboardHeight, w);
|
||||
RenderGoals(Width/2-w/2, y+3.0f+ScoreboardHeight, w);
|
||||
|
||||
// scoreboard size
|
||||
m_TotalRect.x = Width/2-w/2;
|
||||
m_TotalRect.y = 70.0f;
|
||||
m_TotalRect.y = y;
|
||||
m_TotalRect.w = w;
|
||||
m_TotalRect.h = ScoreboardHeight+SpectatorHeight+3.0f;
|
||||
}
|
||||
|
@ -492,52 +507,60 @@ void CScoreboard::OnRender()
|
|||
const char *pRedClanName = GetClanName(TEAM_RED);
|
||||
const char *pBlueClanName = GetClanName(TEAM_BLUE);
|
||||
|
||||
if(m_pClient->m_Snap.m_pGameData->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER)
|
||||
{
|
||||
char aText[256];
|
||||
str_copy(aText, Localize("Draw!"), sizeof(aText));
|
||||
float ScoreboardHeight = RenderScoreboard(Width/2-w-1.5f, y, w, TEAM_RED, pRedClanName ? pRedClanName : Localize("Red team"), -1);
|
||||
RenderScoreboard(Width/2+1.5f, y, w, TEAM_BLUE, pBlueClanName ? pBlueClanName : Localize("Blue team"), 1);
|
||||
|
||||
if(m_pClient->m_Snap.m_pGameDataTeam->m_TeamscoreRed > m_pClient->m_Snap.m_pGameDataTeam->m_TeamscoreBlue)
|
||||
{
|
||||
if(pRedClanName)
|
||||
str_format(aText, sizeof(aText), Localize("%s wins!"), pRedClanName);
|
||||
else
|
||||
str_copy(aText, Localize("Red team wins!"), sizeof(aText));
|
||||
}
|
||||
else if(m_pClient->m_Snap.m_pGameDataTeam->m_TeamscoreBlue > m_pClient->m_Snap.m_pGameDataTeam->m_TeamscoreRed)
|
||||
{
|
||||
if(pBlueClanName)
|
||||
str_format(aText, sizeof(aText), Localize("%s wins!"), pBlueClanName);
|
||||
else
|
||||
str_copy(aText, Localize("Blue team wins!"), sizeof(aText));
|
||||
}
|
||||
|
||||
float w = TextRender()->TextWidth(0, 86.0f, aText, -1);
|
||||
TextRender()->Text(0, Width/2-w/2, 39, 86.0f, aText, -1);
|
||||
}
|
||||
else if(m_pClient->m_Snap.m_pGameData->m_GameStateFlags&GAMESTATEFLAG_ROUNDOVER)
|
||||
{
|
||||
char aText[256];
|
||||
str_copy(aText, Localize("Round over!"), sizeof(aText));
|
||||
|
||||
float w = TextRender()->TextWidth(0, 86.0f, aText, -1);
|
||||
TextRender()->Text(0, Width/2-w/2, 39, 86.0f, aText, -1);
|
||||
}
|
||||
|
||||
float ScoreboardHeight = RenderScoreboard(Width/2-w-1.5f, 70.0f, w, TEAM_RED, pRedClanName ? pRedClanName : Localize("Red team"), -1);
|
||||
RenderScoreboard(Width/2+1.5f, 70.0f, w, TEAM_BLUE, pBlueClanName ? pBlueClanName : Localize("Blue team"), 1);
|
||||
|
||||
float SpectatorHeight = RenderSpectators(Width/2-w-1.5f, 73.0f+ScoreboardHeight, w*2.0f+3.0f);
|
||||
RenderGoals(Width/2-w-1.5f, 73.0f+ScoreboardHeight, w*2.0f+3.0f);
|
||||
float SpectatorHeight = RenderSpectators(Width/2-w-1.5f, y+3.0f+ScoreboardHeight, w*2.0f+3.0f);
|
||||
RenderGoals(Width/2-w-1.5f, y+3.0f+ScoreboardHeight, w*2.0f+3.0f);
|
||||
|
||||
// scoreboard size
|
||||
m_TotalRect.x = Width/2-w-1.5f;
|
||||
m_TotalRect.y = 70.0f;
|
||||
m_TotalRect.y = y;
|
||||
m_TotalRect.w = w*2.0f+3.0f;
|
||||
m_TotalRect.h = ScoreboardHeight+SpectatorHeight+3.0f;
|
||||
}
|
||||
}
|
||||
|
||||
Width = 400*3.0f*Graphics()->ScreenAspect();
|
||||
Graphics()->MapScreen(0, 0, Width, 400*3.0f);
|
||||
if(m_pClient->m_Snap.m_pGameData && (m_pClient->m_GameInfo.m_GameFlags&GAMEFLAG_TEAMS) && m_pClient->m_Snap.m_pGameDataTeam)
|
||||
{
|
||||
const char *pRedClanName = GetClanName(TEAM_RED);
|
||||
const char *pBlueClanName = GetClanName(TEAM_BLUE);
|
||||
|
||||
if(m_pClient->m_Snap.m_pGameData->m_GameStateFlags&GAMESTATEFLAG_GAMEOVER)
|
||||
{
|
||||
char aText[256];
|
||||
str_copy(aText, Localize("Draw!"), sizeof(aText));
|
||||
|
||||
if(m_pClient->m_Snap.m_pGameDataTeam->m_TeamscoreRed > m_pClient->m_Snap.m_pGameDataTeam->m_TeamscoreBlue)
|
||||
{
|
||||
if(pRedClanName)
|
||||
str_format(aText, sizeof(aText), Localize("%s wins!"), pRedClanName);
|
||||
else
|
||||
str_copy(aText, Localize("Red team wins!"), sizeof(aText));
|
||||
}
|
||||
else if(m_pClient->m_Snap.m_pGameDataTeam->m_TeamscoreBlue > m_pClient->m_Snap.m_pGameDataTeam->m_TeamscoreRed)
|
||||
{
|
||||
if(pBlueClanName)
|
||||
str_format(aText, sizeof(aText), Localize("%s wins!"), pBlueClanName);
|
||||
else
|
||||
str_copy(aText, Localize("Blue team wins!"), sizeof(aText));
|
||||
}
|
||||
|
||||
float tw = TextRender()->TextWidth(0, FontSize, aText, -1);
|
||||
TextRender()->Text(0, Width/2-tw/2, 39, FontSize, aText, -1);
|
||||
}
|
||||
else if(m_pClient->m_Snap.m_pGameData->m_GameStateFlags&GAMESTATEFLAG_ROUNDOVER)
|
||||
{
|
||||
char aText[256];
|
||||
str_copy(aText, Localize("Round over!"), sizeof(aText));
|
||||
|
||||
float tw = TextRender()->TextWidth(0, FontSize, aText, -1);
|
||||
TextRender()->Text(0, Width/2-tw/2, 39, FontSize, aText, -1);
|
||||
}
|
||||
}
|
||||
|
||||
RenderRecordingNotification((Width/7)*4);
|
||||
}
|
||||
|
||||
|
@ -568,11 +591,7 @@ void CScoreboard::OnMessage(int MsgType, void *pRawMsg)
|
|||
|
||||
bool CScoreboard::Active()
|
||||
{
|
||||
// disable scoreboard if the menu is active
|
||||
if(m_pClient->m_pMenus->IsActive())
|
||||
return false;
|
||||
|
||||
// if we activly wanna look on the scoreboard
|
||||
// if we actively wanna look on the scoreboard
|
||||
if(m_Active)
|
||||
return true;
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ class CScoreboard : public CComponent
|
|||
CPlayerStats();
|
||||
void Reset();
|
||||
};
|
||||
CPlayerStats m_aPlayerStats[16];
|
||||
CPlayerStats m_aPlayerStats[MAX_CLIENTS];
|
||||
|
||||
public:
|
||||
CScoreboard();
|
||||
|
|
Loading…
Reference in a new issue