1/* (c) Magnus Auvinen. See licence.txt in the root of the distribution for more information. */
2/* If you are missing that file, acquire a complete release at teeworlds.com. */
3#include "scoreboard.h"
4
5#include <base/dbg.h>
6#include <base/time.h>
7
8#include <engine/console.h>
9#include <engine/demo.h>
10#include <engine/font_icons.h>
11#include <engine/graphics.h>
12#include <engine/shared/config.h>
13#include <engine/textrender.h>
14
15#include <generated/client_data7.h>
16#include <generated/protocol.h>
17
18#include <game/client/animstate.h>
19#include <game/client/components/countryflags.h>
20#include <game/client/components/motd.h>
21#include <game/client/components/statboard.h>
22#include <game/client/gameclient.h>
23#include <game/client/ui.h>
24#include <game/localization.h>
25
26// Horizontal spacing of the scoreboard contents, both to its edges and between columns
27static constexpr float MARGIN = 10.0f;
28static constexpr float ROUNDING = 7.5f;
29static constexpr ColorRGBA BACKGROUND_COLOR(0.0f, 0.0f, 0.0f, 0.5f);
30
31static constexpr float POPUP_WIDTH = 110.0f;
32
33static constexpr ColorRGBA TEAM_RED_TITLE_COLOR(0.975f, 0.17f, 0.17f);
34static constexpr ColorRGBA TEAM_BLUE_TITLE_COLOR(0.17f, 0.46f, 0.975f);
35
36static constexpr const char *TIME_WIDTH_TEXT = "00:00:00";
37
38CScoreboard::CScoreboard()
39{
40 CScoreboard::OnReset();
41}
42
43void CScoreboard::SetUiMousePos(vec2 Pos)
44{
45 const vec2 WindowSize = vec2(Graphics()->WindowWidth(), Graphics()->WindowHeight());
46 const CUIRect *pScreen = Ui()->Screen();
47
48 const vec2 UpdatedMousePos = Ui()->UpdatedMousePos();
49 Pos = Pos / vec2(pScreen->w, pScreen->h) * WindowSize;
50 Ui()->OnCursorMove(X: Pos.x - UpdatedMousePos.x, Y: Pos.y - UpdatedMousePos.y);
51}
52
53void CScoreboard::LockMouse()
54{
55 Ui()->ClosePopupMenus();
56 m_MouseUnlocked = false;
57 SetUiMousePos(m_LastMousePos.value());
58 m_LastMousePos = Ui()->MousePos();
59}
60
61void CScoreboard::ConKeyScoreboard(IConsole::IResult *pResult, void *pUserData)
62{
63 CScoreboard *pSelf = static_cast<CScoreboard *>(pUserData);
64
65 pSelf->GameClient()->m_Spectator.OnRelease();
66 pSelf->GameClient()->m_Emoticon.OnRelease();
67
68 pSelf->m_Active = pResult->GetInteger(Index: 0) != 0;
69
70 if(!pSelf->IsActive() && pSelf->m_MouseUnlocked)
71 {
72 pSelf->LockMouse();
73 }
74}
75
76void CScoreboard::ConToggleScoreboardCursor(IConsole::IResult *pResult, void *pUserData)
77{
78 CScoreboard *pSelf = static_cast<CScoreboard *>(pUserData);
79
80 if(!pSelf->IsActive() ||
81 pSelf->GameClient()->m_Menus.IsActive() ||
82 pSelf->GameClient()->m_Chat.IsActive() ||
83 pSelf->Client()->State() == IClient::STATE_DEMOPLAYBACK)
84 {
85 return;
86 }
87
88 pSelf->m_MouseUnlocked = !pSelf->m_MouseUnlocked;
89
90 if(!pSelf->m_MouseUnlocked)
91 {
92 pSelf->Ui()->ClosePopupMenus();
93 }
94
95 vec2 OldMousePos = pSelf->Ui()->MousePos();
96
97 if(pSelf->m_LastMousePos == std::nullopt)
98 {
99 pSelf->SetUiMousePos(pSelf->Ui()->Screen()->Center());
100 }
101 else
102 {
103 pSelf->SetUiMousePos(pSelf->m_LastMousePos.value());
104 }
105
106 // save pos, so moving the mouse in esc menu doesn't change the position
107 pSelf->m_LastMousePos = OldMousePos;
108}
109
110void CScoreboard::OnConsoleInit()
111{
112 Console()->Register(pName: "+scoreboard", pParams: "", Flags: CFGFLAG_CLIENT, pfnFunc: ConKeyScoreboard, pUser: this, pHelp: "Show scoreboard");
113 Console()->Register(pName: "toggle_scoreboard_cursor", pParams: "", Flags: CFGFLAG_CLIENT, pfnFunc: ConToggleScoreboardCursor, pUser: this, pHelp: "Toggle scoreboard cursor");
114}
115
116void CScoreboard::OnInit()
117{
118 m_DeadTeeTexture = Graphics()->LoadTexture(pFilename: "deadtee.png", StorageType: IStorage::TYPE_ALL);
119}
120
121void CScoreboard::OnReset()
122{
123 m_Active = false;
124 m_MouseUnlocked = false;
125 m_LastMousePos = std::nullopt;
126}
127
128void CScoreboard::ResetTexts()
129{
130 for(CPlayerElement &Player : m_aPlayers)
131 {
132 Player.m_Score.Reset(pTextRender: TextRender());
133 Player.m_ScoreMillis.Reset(pTextRender: TextRender());
134 Player.m_Name.Reset(pTextRender: TextRender());
135 Player.m_ReadyMark.Reset(pTextRender: TextRender());
136 Player.m_Clan.Reset(pTextRender: TextRender());
137 Player.m_Ping.Reset(pTextRender: TextRender());
138 }
139 m_TitleScore.Reset(pTextRender: TextRender());
140 m_TitleScoreMillis.Reset(pTextRender: TextRender());
141 m_HeadlineScore.Reset(pTextRender: TextRender());
142 m_HeadlineName.Reset(pTextRender: TextRender());
143 m_HeadlineClan.Reset(pTextRender: TextRender());
144 m_HeadlinePing.Reset(pTextRender: TextRender());
145}
146
147void CScoreboard::OnShutdown()
148{
149 ResetTexts();
150}
151
152void CScoreboard::OnWindowResize()
153{
154 ResetTexts();
155}
156
157void CScoreboard::OnRelease()
158{
159 m_Active = false;
160
161 if(m_MouseUnlocked)
162 {
163 LockMouse();
164 }
165}
166
167bool CScoreboard::OnCursorMove(float x, float y, IInput::ECursorType CursorType)
168{
169 if(!IsActive() || !m_MouseUnlocked)
170 return false;
171
172 Ui()->ConvertMouseMove(pX: &x, pY: &y, CursorType);
173 Ui()->OnCursorMove(X: x, Y: y);
174
175 return true;
176}
177
178bool CScoreboard::OnInput(const IInput::CEvent &Event)
179{
180 if(m_MouseUnlocked && Event.m_Key == KEY_ESCAPE && (Event.m_Flags & IInput::FLAG_PRESS))
181 {
182 LockMouse();
183 return true;
184 }
185
186 return IsActive() && m_MouseUnlocked;
187}
188
189void CScoreboard::RenderTitle(CUIRect TitleLabel, int Team, const char *pTitle, float TitleFontSize)
190{
191 const bool IsMapTitle = !GameClient()->IsTeamPlay();
192 if(IsMapTitle && m_MouseUnlocked && GameClient()->m_aMapDescription[0] != '\0')
193 {
194 const int ButtonResult = Ui()->DoButtonLogic(pId: &m_MapTitleButtonId, Checked: 0, pRect: &TitleLabel, Flags: BUTTONFLAG_LEFT | BUTTONFLAG_RIGHT);
195 if(ButtonResult != 0)
196 {
197 m_MapTitlePopupContext.m_pScoreboard = this;
198
199 m_MapTitlePopupContext.m_FontSize = 12.0f;
200 const float MaxWidth = 300.0f;
201 const float Margin = 5.0f;
202 const char *pDescription = GameClient()->m_aMapDescription;
203 const float TextWidth = std::min(a: std::ceil(x: TextRender()->TextWidth(Size: m_MapTitlePopupContext.m_FontSize, pText: pDescription) + 0.5f), b: MaxWidth);
204 float TextHeight = 0.0f;
205 STextSizeProperties TextSizeProps{};
206 TextSizeProps.m_pHeight = &TextHeight;
207 TextRender()->TextWidth(Size: m_MapTitlePopupContext.m_FontSize, pText: pDescription, StrLength: -1, LineWidth: TextWidth, Flags: 0, TextSizeProps);
208
209 Ui()->DoPopupMenu(pId: &m_MapTitlePopupContext, X: Ui()->MouseX(), Y: Ui()->MouseY(), Width: TextWidth + Margin * 2, Height: TextHeight + Margin * 2, pContext: &m_MapTitlePopupContext, pfnFunc: CMapTitlePopupContext::Render);
210 }
211 if(Ui()->HotItem() == &m_MapTitleButtonId)
212 {
213 TitleLabel.Draw(Color: ColorRGBA(0.7f, 0.7f, 0.7f, 0.3f), Corners: IGraphics::CORNER_ALL, Rounding: 5.0f);
214 }
215 }
216
217 SLabelProperties Props;
218 Props.m_MaxWidth = TitleLabel.w;
219 Props.m_EllipsisAtEnd = true;
220 Ui()->DoLabel(pRect: &TitleLabel, pText: pTitle, Size: TitleFontSize, Align: Team == TEAM_RED ? TEXTALIGN_ML : TEXTALIGN_MR, LabelProps: Props);
221}
222
223void CScoreboard::RenderTitleScore(CUIRect ScoreLabel, int Team, float TitleFontSize)
224{
225 // map best
226 char aScore[128] = "";
227 const CNetObj_GameInfo *pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj;
228 const bool TimeScore = GameClient()->m_GameInfo.m_TimeScore;
229 const bool Race7 = Client()->IsSixup() && pGameInfoObj && pGameInfoObj->m_GameFlags & protocol7::GAMEFLAG_RACE;
230 if(GameClient()->m_ReceivedDDNetPlayerFinishTimes || TimeScore || Race7)
231 {
232 if(GameClient()->m_MapBestTimeSeconds != FinishTime::UNSET)
233 {
234 Ui()->RenderTime(TimeRect: ScoreLabel,
235 FontSize: TitleFontSize,
236 Seconds: GameClient()->m_MapBestTimeSeconds,
237 NotFinished: GameClient()->m_MapBestTimeSeconds == FinishTime::NOT_FINISHED_MILLIS,
238 Millis: GameClient()->m_MapBestTimeMillis,
239 TrueMilliseconds: GameClient()->m_ReceivedDDNetPlayerFinishTimesMillis,
240 SecondsText&: m_TitleScore, MillisText&: m_TitleScoreMillis, Color: TextRender()->DefaultTextColor());
241 return;
242 }
243 }
244 else if(GameClient()->IsTeamPlay()) // normal score
245 {
246 const CNetObj_GameData *pGameDataObj = GameClient()->m_Snap.m_pGameDataObj;
247 if(pGameDataObj)
248 {
249 str_format(buffer: aScore, buffer_size: sizeof(aScore), format: "%d", Team == TEAM_RED ? pGameDataObj->m_TeamscoreRed : pGameDataObj->m_TeamscoreBlue);
250 }
251 }
252 else
253 {
254 if(GameClient()->m_Snap.m_SpecInfo.m_Active &&
255 GameClient()->m_Snap.m_SpecInfo.m_SpectatorId != SPEC_FREEVIEW &&
256 GameClient()->m_Snap.m_apPlayerInfos[GameClient()->m_Snap.m_SpecInfo.m_SpectatorId])
257 {
258 str_format(buffer: aScore, buffer_size: sizeof(aScore), format: "%d", GameClient()->m_Snap.m_apPlayerInfos[GameClient()->m_Snap.m_SpecInfo.m_SpectatorId]->m_Score);
259 }
260 else if(GameClient()->m_Snap.m_pLocalInfo)
261 {
262 str_format(buffer: aScore, buffer_size: sizeof(aScore), format: "%d", GameClient()->m_Snap.m_pLocalInfo->m_Score);
263 }
264 }
265
266 const float ScoreTextWidth = aScore[0] != '\0' ? TextRender()->TextWidth(Size: TitleFontSize, pText: aScore, StrLength: -1, LineWidth: -1.0f, Flags: 0) : 0.0f;
267 if(ScoreTextWidth != 0.0f)
268 {
269 Ui()->DoLabel(pRect: &ScoreLabel, pText: aScore, Size: TitleFontSize, Align: Team == TEAM_RED ? TEXTALIGN_MR : TEXTALIGN_ML);
270 }
271}
272
273void CScoreboard::RenderTitleBar(CUIRect TitleBar, int Team, const char *pTitle)
274{
275 dbg_assert(Team == TEAM_RED || Team == TEAM_BLUE, "Team invalid");
276
277 const float TitleFontSize = 20.0f;
278 const float ScoreTextWidth = TextRender()->TextWidth(Size: TitleFontSize, pText: TIME_WIDTH_TEXT);
279 const float TitleTextWidth = TextRender()->TextWidth(Size: TitleFontSize, pText: pTitle);
280
281 TitleBar.VMargin(Cut: MARGIN, pOtherRect: &TitleBar);
282 CUIRect TitleLabel, ScoreLabel;
283 if(Team == TEAM_RED)
284 {
285 TitleBar.VSplitRight(Cut: ScoreTextWidth, pLeft: &TitleLabel, pRight: &ScoreLabel);
286 TitleLabel.VSplitRight(Cut: 5.0f, pLeft: &TitleLabel, pRight: nullptr);
287 TitleLabel.VSplitLeft(Cut: std::min(a: TitleTextWidth + 2.0f, b: TitleLabel.w), pLeft: &TitleLabel, pRight: nullptr);
288 }
289 else
290 {
291 TitleBar.VSplitLeft(Cut: ScoreTextWidth, pLeft: &ScoreLabel, pRight: &TitleLabel);
292 TitleLabel.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &TitleLabel);
293 TitleLabel.VSplitRight(Cut: std::min(a: TitleTextWidth + 2.0f, b: TitleLabel.w), pLeft: nullptr, pRight: &TitleLabel);
294 }
295
296 RenderTitle(TitleLabel, Team, pTitle, TitleFontSize);
297 RenderTitleScore(ScoreLabel, Team, TitleFontSize);
298}
299
300void CScoreboard::RenderGoals(CUIRect Goals)
301{
302 Goals.Draw(Color: BACKGROUND_COLOR, Corners: IGraphics::CORNER_ALL, Rounding: ROUNDING);
303 Goals.VMargin(Cut: 5.0f, pOtherRect: &Goals);
304
305 const float FontSize = 10.0f;
306 const CNetObj_GameInfo *pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj;
307 char aBuf[64];
308
309 if(pGameInfoObj->m_ScoreLimit)
310 {
311 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %d", Localize(pStr: "Score limit"), pGameInfoObj->m_ScoreLimit);
312 Ui()->DoLabel(pRect: &Goals, pText: aBuf, Size: FontSize, Align: TEXTALIGN_ML);
313 }
314
315 if(pGameInfoObj->m_TimeLimit)
316 {
317 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Time limit: %d min"), pGameInfoObj->m_TimeLimit);
318 Ui()->DoLabel(pRect: &Goals, pText: aBuf, Size: FontSize, Align: TEXTALIGN_MC);
319 }
320
321 if(pGameInfoObj->m_RoundNum && pGameInfoObj->m_RoundCurrent)
322 {
323 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Round %d/%d"), pGameInfoObj->m_RoundCurrent, pGameInfoObj->m_RoundNum);
324 Ui()->DoLabel(pRect: &Goals, pText: aBuf, Size: FontSize, Align: TEXTALIGN_MR);
325 }
326}
327
328void CScoreboard::RenderSpectators(CUIRect Spectators)
329{
330 Spectators.Draw(Color: BACKGROUND_COLOR, Corners: IGraphics::CORNER_ALL, Rounding: ROUNDING);
331 constexpr float SpectatorCut = 5.0f;
332 Spectators.Margin(Cut: SpectatorCut, pOtherRect: &Spectators);
333
334 CTextCursor Cursor;
335 Cursor.SetPosition(Spectators.TopLeft());
336 Cursor.m_FontSize = 11.0f;
337 Cursor.m_LineWidth = Spectators.w;
338 Cursor.m_MaxLines = round_truncate(f: Spectators.h / Cursor.m_FontSize);
339
340 int RemainingSpectators = 0;
341 for(const CNetObj_PlayerInfo *pInfo : GameClient()->m_Snap.m_apInfoByName)
342 {
343 if(!pInfo || pInfo->m_Team != TEAM_SPECTATORS)
344 continue;
345 ++RemainingSpectators;
346 }
347
348 TextRender()->TextEx(pCursor: &Cursor, pText: Localize(pStr: "Spectators"));
349
350 if(RemainingSpectators > 0)
351 {
352 TextRender()->TextEx(pCursor: &Cursor, pText: ": ");
353 }
354
355 bool CommaNeeded = false;
356 for(const CNetObj_PlayerInfo *pInfo : GameClient()->m_Snap.m_apInfoByName)
357 {
358 if(!pInfo || pInfo->m_Team != TEAM_SPECTATORS)
359 continue;
360
361 if(CommaNeeded)
362 {
363 TextRender()->TextEx(pCursor: &Cursor, pText: ", ");
364 }
365
366 if(Cursor.m_LineCount == Cursor.m_MaxLines && RemainingSpectators >= 2)
367 {
368 // This is less expensive than checking with a separate invisible
369 // text cursor though we waste some space at the end of the line.
370 char aRemaining[64];
371 str_format(buffer: aRemaining, buffer_size: sizeof(aRemaining), format: Localize(pStr: "%d others…", pContext: "Spectators"), RemainingSpectators);
372 TextRender()->TextEx(pCursor: &Cursor, pText: aRemaining);
373 break;
374 }
375
376 CUIRect SpectatorRect, SpectatorRectLineBreak;
377 const float Margin = 1.0f;
378 SpectatorRect.x = Cursor.m_X - Margin;
379 SpectatorRect.y = Cursor.m_Y;
380
381 // id, clan and name of the spectator, advanced through the given cursor
382 const CGameClient::CClientData &ClientData = GameClient()->m_aClients[pInfo->m_ClientId];
383 auto RenderEntryText = [&](CTextCursor *pCursor) {
384 if(g_Config.m_ClShowIds)
385 {
386 char aClientId[16];
387 GameClient()->FormatClientId(ClientId: pInfo->m_ClientId, aClientId, Format: EClientIdFormat::NO_INDENT);
388 TextRender()->TextEx(pCursor, pText: aClientId);
389 }
390
391 {
392 const char *pClanName = ClientData.m_aClan;
393 if(pClanName[0] != '\0')
394 {
395 if(GameClient()->m_aLocalIds[g_Config.m_ClDummy] >= 0 && str_comp(a: pClanName, b: GameClient()->m_aClients[GameClient()->m_aLocalIds[g_Config.m_ClDummy]].m_aClan) == 0)
396 {
397 TextRender()->TextColor(Color: color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClSameClanColor)));
398 }
399 else
400 {
401 TextRender()->TextColor(Color: ColorRGBA(0.7f, 0.7f, 0.7f));
402 }
403
404 TextRender()->TextEx(pCursor, pText: pClanName);
405 TextRender()->TextEx(pCursor, pText: " ");
406
407 TextRender()->TextColor(Color: TextRender()->DefaultTextColor());
408 }
409 }
410
411 if(ClientData.m_AuthLevel)
412 {
413 TextRender()->TextColor(Color: color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClAuthedPlayerColor)));
414 }
415
416 TextRender()->TextEx(pCursor, pText: ClientData.m_aName);
417 TextRender()->TextColor(Color: TextRender()->DefaultTextColor());
418 };
419
420 if(m_MouseUnlocked)
421 {
422 // measure the entry's extent without rendering, so the highlight can be drawn behind the text
423 CTextCursor MeasureCursor = Cursor;
424 MeasureCursor.m_Flags &= ~TEXTFLAG_RENDER;
425 RenderEntryText(&MeasureCursor);
426
427 bool LineBreakDetected = false;
428 SpectatorRect.h = Cursor.m_FontSize;
429
430 // detect line breaks
431 if(MeasureCursor.m_Y != SpectatorRect.y)
432 {
433 LineBreakDetected = true;
434 SpectatorRectLineBreak.x = Spectators.x - SpectatorCut;
435 SpectatorRectLineBreak.y = MeasureCursor.m_Y;
436 SpectatorRectLineBreak.h = Cursor.m_FontSize;
437 SpectatorRectLineBreak.w = MeasureCursor.m_X - Spectators.x + SpectatorCut + 2 * Margin;
438
439 SpectatorRect.w = Spectators.x + Spectators.w + SpectatorCut - SpectatorRect.x;
440 }
441 else
442 {
443 SpectatorRect.w = MeasureCursor.m_X - SpectatorRect.x + 2 * Margin;
444 }
445
446 int ButtonResult = Ui()->DoButtonLogic(pId: &m_aPlayers[pInfo->m_ClientId].m_PlayerButtonId, Checked: 0, pRect: &SpectatorRect, Flags: BUTTONFLAG_LEFT | BUTTONFLAG_RIGHT);
447
448 if(LineBreakDetected && ButtonResult == 0)
449 {
450 ButtonResult = Ui()->DoButtonLogic(pId: &m_aPlayers[pInfo->m_ClientId].m_SpectatorSecondLineButtonId, Checked: 0, pRect: &SpectatorRectLineBreak, Flags: BUTTONFLAG_LEFT | BUTTONFLAG_RIGHT);
451 }
452 if(ButtonResult != 0)
453 {
454 m_ScoreboardPopupContext.m_pScoreboard = this;
455 m_ScoreboardPopupContext.m_ClientId = pInfo->m_ClientId;
456 m_ScoreboardPopupContext.m_IsLocal = GameClient()->m_aLocalIds[0] == pInfo->m_ClientId ||
457 (Client()->DummyConnected() && GameClient()->m_aLocalIds[1] == pInfo->m_ClientId);
458 m_ScoreboardPopupContext.m_IsSpectating = true;
459
460 Ui()->DoPopupMenu(pId: &m_ScoreboardPopupContext, X: Ui()->MouseX(), Y: Ui()->MouseY(), Width: POPUP_WIDTH,
461 Height: m_ScoreboardPopupContext.m_IsLocal ? 30.0f : 60.0f, pContext: &m_ScoreboardPopupContext, pfnFunc: CScoreboardPopupContext::Render);
462 }
463
464 if(Ui()->HotItem() == &m_aPlayers[pInfo->m_ClientId].m_PlayerButtonId ||
465 Ui()->HotItem() == &m_aPlayers[pInfo->m_ClientId].m_SpectatorSecondLineButtonId ||
466 (Ui()->IsPopupOpen(pId: &m_ScoreboardPopupContext) && m_ScoreboardPopupContext.m_ClientId == pInfo->m_ClientId))
467 {
468 // draw the highlight behind the text
469 if(!LineBreakDetected)
470 {
471 SpectatorRect.Draw(Color: TextRender()->DefaultTextSelectionColor(), Corners: IGraphics::CORNER_ALL, Rounding: 2.5f);
472 }
473 else
474 {
475 SpectatorRect.Draw(Color: TextRender()->DefaultTextSelectionColor(), Corners: IGraphics::CORNER_L, Rounding: 2.5f);
476 SpectatorRectLineBreak.Draw(Color: TextRender()->DefaultTextSelectionColor(), Corners: IGraphics::CORNER_R, Rounding: 2.5f);
477 }
478 }
479 }
480
481 // render the entry's text on top of the highlight
482 RenderEntryText(&Cursor);
483
484 CommaNeeded = true;
485 --RemainingSpectators;
486 }
487}
488
489void CScoreboard::RenderScoreboard(CUIRect Scoreboard, int Team, int CountStart, int CountEnd, CScoreboardRenderState &State, int NumPlayersForSize)
490{
491 dbg_assert(Team == TEAM_RED || Team == TEAM_BLUE, "Team invalid");
492
493 const CNetObj_GameInfo *pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj;
494 const CNetObj_GameData *pGameDataObj = GameClient()->m_Snap.m_pGameDataObj;
495 const bool TimeScore = GameClient()->m_GameInfo.m_TimeScore;
496 const bool MillisecondScore = GameClient()->m_ReceivedDDNetPlayerFinishTimes;
497 const bool TrueMilliseconds = GameClient()->m_ReceivedDDNetPlayerFinishTimesMillis;
498 const int NumPlayers = NumPlayersForSize >= 0 ? NumPlayersForSize : (CountEnd - CountStart);
499 const bool LowScoreboardWidth = Scoreboard.w < 350.0f;
500
501 bool Race7 = Client()->IsSixup() && pGameInfoObj && pGameInfoObj->m_GameFlags & protocol7::GAMEFLAG_RACE;
502
503 const bool UseTime = Race7 || TimeScore || MillisecondScore;
504
505 // calculate measurements
506 float LineHeight;
507 float TeeSizeMod;
508 float Spacing;
509 float RoundRadius;
510 float FontSize;
511 if(NumPlayers <= 8)
512 {
513 LineHeight = 30.0f;
514 TeeSizeMod = 0.5f;
515 Spacing = 8.0f;
516 RoundRadius = 5.0f;
517 FontSize = 12.0f;
518 }
519 else if(NumPlayers <= 12)
520 {
521 LineHeight = 25.0f;
522 TeeSizeMod = 0.45f;
523 Spacing = 2.5f;
524 RoundRadius = 5.0f;
525 FontSize = 12.0f;
526 }
527 else if(NumPlayers <= 16)
528 {
529 LineHeight = 20.0f;
530 TeeSizeMod = 0.4f;
531 Spacing = 0.0f;
532 RoundRadius = 2.5f;
533 FontSize = 12.0f;
534 }
535 else if(NumPlayers <= 24)
536 {
537 LineHeight = 13.5f;
538 TeeSizeMod = 0.3f;
539 Spacing = 0.0f;
540 RoundRadius = 2.5f;
541 FontSize = 10.0f;
542 }
543 else if(NumPlayers <= 32)
544 {
545 LineHeight = 10.0f;
546 TeeSizeMod = 0.2f;
547 Spacing = 0.0f;
548 RoundRadius = 2.5f;
549 FontSize = 8.0f;
550 }
551 else if(LowScoreboardWidth && NumPlayers <= 48)
552 {
553 LineHeight = 7.5f;
554 TeeSizeMod = 0.125f;
555 Spacing = 0.0f;
556 RoundRadius = 1.0f;
557 FontSize = 7.0f;
558 }
559 else
560 {
561 LineHeight = 5.0f;
562 TeeSizeMod = 0.1f;
563 Spacing = 0.0f;
564 RoundRadius = 1.0f;
565 FontSize = 5.0f;
566 }
567
568 const float ScoreOffset = Scoreboard.x + MARGIN;
569 const float ScoreLength = TextRender()->TextWidth(Size: FontSize, pText: UseTime ? TIME_WIDTH_TEXT : "99999");
570 const float TeeOffset = ScoreOffset + ScoreLength + MARGIN;
571 const float TeeLength = 60.0f * TeeSizeMod;
572 const float NameOffset = TeeOffset + TeeLength;
573 const float CountryFlagSize = TeeSizeMod * 5.0f;
574 const float CountryLength = (LineHeight - Spacing - CountryFlagSize) * 2.0f;
575 constexpr float PingLength = 27.5f;
576 const float PingOffset = Scoreboard.x + Scoreboard.w - PingLength - MARGIN;
577 const float CountryOffset = PingOffset - CountryLength;
578
579 float NameLength = (LowScoreboardWidth ? 90.0f : 150.0f) - TeeLength;
580 const float MinMiddleGap = 5.0f; // 2.5 before and after clan
581 const float AvailableMiddle = CountryOffset - NameOffset;
582 if(NameLength + MinMiddleGap > AvailableMiddle)
583 {
584 const float Shrinkable = AvailableMiddle - MinMiddleGap;
585 NameLength = std::max(a: 0.0f, b: Shrinkable * 0.7f);
586 }
587
588 const float ClanOffset = NameOffset + NameLength + 2.5f;
589 const float ClanLength = std::max(a: 0.0f, b: CountryOffset - ClanOffset - 2.5f);
590
591 // render headlines
592 constexpr float HeadlineFontsize = 11.0f;
593 CUIRect Headline;
594 Scoreboard.HSplitTop(Cut: HeadlineFontsize * 2.0f, pTop: &Headline, pBottom: &Scoreboard);
595 const float HeadlineY = Headline.y + Headline.h / 2.0f - HeadlineFontsize / 2.0f;
596 const ColorRGBA HeadlineColor = TextRender()->DefaultTextColor();
597 m_HeadlineScore.Update(pTextRender: TextRender(), pText: UseTime ? Localize(pStr: "Time") : Localize(pStr: "Score"), FontSize: HeadlineFontsize);
598 m_HeadlineName.Update(pTextRender: TextRender(), pText: Localize(pStr: "Name"), FontSize: HeadlineFontsize);
599 m_HeadlineClan.Update(pTextRender: TextRender(), pText: Localize(pStr: "Clan"), FontSize: HeadlineFontsize);
600 m_HeadlinePing.Update(pTextRender: TextRender(), pText: Localize(pStr: "Ping"), FontSize: HeadlineFontsize);
601 m_HeadlineScore.Render(pTextRender: TextRender(), Pos: vec2(ScoreOffset + ScoreLength - m_HeadlineScore.Width(), HeadlineY), Color: HeadlineColor);
602 m_HeadlineName.Render(pTextRender: TextRender(), Pos: vec2(NameOffset, HeadlineY), Color: HeadlineColor);
603 m_HeadlineClan.Render(pTextRender: TextRender(), Pos: vec2(ClanOffset + (ClanLength - m_HeadlineClan.Width()) / 2.0f, HeadlineY), Color: HeadlineColor);
604 m_HeadlinePing.Render(pTextRender: TextRender(), Pos: vec2(PingOffset + PingLength - m_HeadlinePing.Width(), HeadlineY), Color: HeadlineColor);
605
606 // render player entries
607 int CountRendered = 0;
608 int PrevDDTeam = -1;
609 int &CurrentDDTeamSize = State.m_CurrentDDTeamSize;
610
611 char aBuf[64];
612 int MaxTeamSize = GameClient()->MaxTeamSize();
613
614 for(int RenderDead = 0; RenderDead < 2; RenderDead++)
615 {
616 for(int i = 0; i < MAX_CLIENTS; i++)
617 {
618 // make sure that we render the correct team
619 const CNetObj_PlayerInfo *pInfo = GameClient()->m_Snap.m_apInfoByDDTeamScore[i];
620 if(!pInfo || pInfo->m_Team != Team)
621 continue;
622 bool IsDead = Client()->m_TranslationContext.m_aClients[pInfo->m_ClientId].m_PlayerFlags7 & protocol7::PLAYERFLAG_DEAD;
623 if(!RenderDead && IsDead)
624 continue;
625 if(RenderDead && !IsDead)
626 continue;
627 if(CountRendered++ < CountStart)
628 continue;
629
630 int DDTeam = GameClient()->m_Teams.Team(ClientId: pInfo->m_ClientId);
631 int NextDDTeam = 0;
632
633 ColorRGBA TextColor = TextRender()->DefaultTextColor();
634 TextColor.a = RenderDead ? 0.5f : 1.0f;
635 TextRender()->TextColor(Color: TextColor);
636
637 for(int j = i + 1; j < MAX_CLIENTS; j++)
638 {
639 const CNetObj_PlayerInfo *pInfoNext = GameClient()->m_Snap.m_apInfoByDDTeamScore[j];
640 if(!pInfoNext || pInfoNext->m_Team != Team)
641 continue;
642
643 NextDDTeam = GameClient()->m_Teams.Team(ClientId: pInfoNext->m_ClientId);
644 break;
645 }
646
647 if(PrevDDTeam == -1)
648 {
649 for(int j = i - 1; j >= 0; j--)
650 {
651 const CNetObj_PlayerInfo *pInfoPrev = GameClient()->m_Snap.m_apInfoByDDTeamScore[j];
652 if(!pInfoPrev || pInfoPrev->m_Team != Team)
653 continue;
654
655 PrevDDTeam = GameClient()->m_Teams.Team(ClientId: pInfoPrev->m_ClientId);
656 break;
657 }
658 }
659
660 CUIRect RowAndSpacing, Row;
661 Scoreboard.HSplitTop(Cut: LineHeight + Spacing, pTop: &RowAndSpacing, pBottom: &Scoreboard);
662 RowAndSpacing.HSplitTop(Cut: LineHeight, pTop: &Row, pBottom: nullptr);
663 const float TextY = Row.y + (Row.h - FontSize) / 2.0f;
664
665 // team background
666 if(DDTeam != TEAM_FLOCK)
667 {
668 const ColorRGBA Color = GameClient()->GetDDTeamColor(DDTeam).WithAlpha(alpha: 0.5f);
669 int TeamRectCorners = 0;
670 if(PrevDDTeam != DDTeam)
671 {
672 TeamRectCorners |= IGraphics::CORNER_T;
673 State.m_TeamStartX = Row.x;
674 State.m_TeamStartY = Row.y;
675 }
676 if(NextDDTeam != DDTeam)
677 TeamRectCorners |= IGraphics::CORNER_B;
678 RowAndSpacing.Draw(Color, Corners: TeamRectCorners, Rounding: RoundRadius);
679
680 CurrentDDTeamSize++;
681
682 if(NextDDTeam != DDTeam)
683 {
684 const float TeamFontSize = FontSize / 1.5f;
685
686 if(NumPlayers > 8)
687 {
688 if(DDTeam == GameClient()->m_Teams.TeamSuper())
689 str_copy(dst&: aBuf, src: Localize(pStr: "Super"));
690 else if(CurrentDDTeamSize <= 1)
691 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", DDTeam);
692 else
693 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "%d\n(%d/%d)", pContext: "Team and size"), DDTeam, CurrentDDTeamSize, MaxTeamSize);
694 TextRender()->Text(x: State.m_TeamStartX, y: std::max(a: State.m_TeamStartY + Row.h / 2.0f - TeamFontSize, b: State.m_TeamStartY + 1.5f /* padding top */), Size: TeamFontSize, pText: aBuf);
695 }
696 else
697 {
698 if(DDTeam == GameClient()->m_Teams.TeamSuper())
699 str_copy(dst&: aBuf, src: Localize(pStr: "Super"));
700 else if(CurrentDDTeamSize > 1)
701 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Team %d (%d/%d)"), DDTeam, CurrentDDTeamSize, MaxTeamSize);
702 else
703 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Team %d"), DDTeam);
704 TextRender()->Text(x: Row.x + Row.w / 2.0f - TextRender()->TextWidth(Size: TeamFontSize, pText: aBuf) / 2.0f + 5.0f, y: Row.y + Row.h, Size: TeamFontSize, pText: aBuf);
705 }
706
707 CurrentDDTeamSize = 0;
708 }
709 }
710 PrevDDTeam = DDTeam;
711
712 // background so it's easy to find the local player or the followed one in spectator mode
713 if((!GameClient()->m_Snap.m_SpecInfo.m_Active && pInfo->m_Local) ||
714 (GameClient()->m_Snap.m_SpecInfo.m_SpectatorId == SPEC_FREEVIEW && pInfo->m_Local) ||
715 (GameClient()->m_Snap.m_SpecInfo.m_Active && pInfo->m_ClientId == GameClient()->m_Snap.m_SpecInfo.m_SpectatorId))
716 {
717 Row.Draw(Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), Corners: IGraphics::CORNER_ALL, Rounding: RoundRadius);
718 }
719
720 const CGameClient::CClientData &ClientData = GameClient()->m_aClients[pInfo->m_ClientId];
721 CPlayerElement &Player = m_aPlayers[pInfo->m_ClientId];
722
723 if(m_MouseUnlocked)
724 {
725 const int ButtonResult = Ui()->DoButtonLogic(pId: &Player.m_PlayerButtonId, Checked: 0, pRect: &Row, Flags: BUTTONFLAG_LEFT | BUTTONFLAG_RIGHT);
726 if(ButtonResult != 0)
727 {
728 m_ScoreboardPopupContext.m_pScoreboard = this;
729 m_ScoreboardPopupContext.m_ClientId = pInfo->m_ClientId;
730 m_ScoreboardPopupContext.m_IsLocal = GameClient()->m_aLocalIds[0] == pInfo->m_ClientId ||
731 (Client()->DummyConnected() && GameClient()->m_aLocalIds[1] == pInfo->m_ClientId);
732 m_ScoreboardPopupContext.m_IsSpectating = false;
733
734 Ui()->DoPopupMenu(pId: &m_ScoreboardPopupContext, X: Ui()->MouseX(), Y: Ui()->MouseY(), Width: POPUP_WIDTH,
735 Height: m_ScoreboardPopupContext.m_IsLocal ? 58.5f : 87.5f, pContext: &m_ScoreboardPopupContext, pfnFunc: CScoreboardPopupContext::Render);
736 }
737
738 if(Ui()->HotItem() == &Player.m_PlayerButtonId ||
739 Ui()->HotItem() == &Player.m_TimeTooltipId ||
740 (Ui()->IsPopupOpen(pId: &m_ScoreboardPopupContext) && m_ScoreboardPopupContext.m_ClientId == pInfo->m_ClientId))
741 {
742 Row.Draw(Color: ColorRGBA(0.7f, 0.7f, 0.7f, 0.7f), Corners: IGraphics::CORNER_ALL, Rounding: RoundRadius);
743 }
744 }
745
746 // score
747 CUIRect ScorePosition;
748 ScorePosition.x = ScoreOffset;
749 ScorePosition.w = ScoreLength;
750 ScorePosition.y = Row.y;
751 ScorePosition.h = Row.h;
752
753 auto DoMillisecondTooltip = [&](const CUIRect *pRect, int64_t TimeInMillis, float WidthHint) {
754 if(m_MouseUnlocked && pRect->Inside(Point: Ui()->MousePos()))
755 {
756 Ui()->SetHotItem(&Player.m_TimeTooltipId);
757 str_time(centisecs: TimeInMillis / 10, format: ETimeFormat::HOURS_CENTISECS, buffer: Player.m_aTimeTooltip, buffer_size: sizeof(Player.m_aTimeTooltip));
758 Ui()->DoToolTip(Tooltip: {&Player.m_TimeTooltipId,
759 *pRect,
760 Player.m_aTimeTooltip,
761 WidthHint * 1.5f,
762 FontSize,
763 true});
764 }
765 };
766 constexpr int SecondsPerHour = 60 * 60;
767
768 if(Race7)
769 {
770 Ui()->RenderTime(TimeRect: ScorePosition, FontSize, Seconds: pInfo->m_Score / 1000, NotFinished: pInfo->m_Score == protocol7::FinishTime::NOT_FINISHED, Millis: pInfo->m_Score % 1000, TrueMilliseconds: true,
771 SecondsText&: Player.m_Score, MillisText&: Player.m_ScoreMillis, Color: TextColor);
772 if(pInfo->m_Score / 1000 >= SecondsPerHour)
773 {
774 DoMillisecondTooltip(&ScorePosition, time_milliseconds_from_seconds(seconds: pInfo->m_Score / 1000.0f), Player.m_Score.Width());
775 }
776 }
777 else if(MillisecondScore)
778 {
779 Ui()->RenderTime(TimeRect: ScorePosition, FontSize, Seconds: ClientData.m_FinishTimeSeconds, NotFinished: ClientData.m_FinishTimeSeconds == FinishTime::NOT_FINISHED_MILLIS, Millis: ClientData.m_FinishTimeMillis, TrueMilliseconds,
780 SecondsText&: Player.m_Score, MillisText&: Player.m_ScoreMillis, Color: TextColor);
781 if(ClientData.m_FinishTimeSeconds >= SecondsPerHour)
782 {
783 DoMillisecondTooltip(&ScorePosition, static_cast<int64_t>(ClientData.m_FinishTimeSeconds) * 1000 + ClientData.m_FinishTimeMillis, Player.m_Score.Width());
784 }
785 }
786 else if(TimeScore)
787 {
788 Ui()->RenderTime(TimeRect: ScorePosition, FontSize, Seconds: pInfo->m_Score, NotFinished: pInfo->m_Score == FinishTime::NOT_FINISHED_TIMESCORE, Millis: -1, TrueMilliseconds: false,
789 SecondsText&: Player.m_Score, MillisText&: Player.m_ScoreMillis, Color: TextColor);
790 }
791 else
792 {
793 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", std::clamp(val: pInfo->m_Score, lo: -999, hi: 99999));
794 Player.m_Score.Update(pTextRender: TextRender(), pText: aBuf, FontSize);
795 Player.m_Score.Render(pTextRender: TextRender(), Pos: vec2(ScoreOffset + ScoreLength - Player.m_Score.Width(), TextY), Color: TextColor);
796 }
797
798 // CTF flag
799 if(pGameInfoObj && (pGameInfoObj->m_GameFlags & GAMEFLAG_FLAGS) &&
800 pGameDataObj && (pGameDataObj->m_FlagCarrierRed == pInfo->m_ClientId || pGameDataObj->m_FlagCarrierBlue == pInfo->m_ClientId))
801 {
802 Graphics()->TextureSet(Texture: pGameDataObj->m_FlagCarrierBlue == pInfo->m_ClientId ? GameClient()->m_GameSkin.m_SpriteFlagBlue : GameClient()->m_GameSkin.m_SpriteFlagRed);
803 Graphics()->QuadsBegin();
804 Graphics()->QuadsSetSubset(TopLeftU: 1.0f, TopLeftV: 0.0f, BottomRightU: 0.0f, BottomRightV: 1.0f);
805 IGraphics::CQuadItem QuadItem(TeeOffset, Row.y - 2.5f - Spacing / 2.0f, Row.h / 2.0f, Row.h);
806 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
807 Graphics()->QuadsEnd();
808 }
809
810 // skin
811 if(RenderDead)
812 {
813 Graphics()->TextureSet(Texture: m_DeadTeeTexture);
814 Graphics()->QuadsBegin();
815 if(GameClient()->IsTeamPlay())
816 {
817 Graphics()->SetColor(GameClient()->m_Skins7.GetTeamColor(UseCustomColors: true, PartColor: 0, Team: GameClient()->m_aClients[pInfo->m_ClientId].m_Team, Part: protocol7::SKINPART_BODY));
818 }
819 CTeeRenderInfo TeeInfo = GameClient()->m_aClients[pInfo->m_ClientId].m_RenderInfo;
820 TeeInfo.m_Size *= TeeSizeMod;
821 IGraphics::CQuadItem QuadItem(TeeOffset, Row.y, TeeInfo.m_Size, TeeInfo.m_Size);
822 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
823 Graphics()->QuadsEnd();
824 }
825 else
826 {
827 CTeeRenderInfo TeeInfo = ClientData.m_RenderInfo;
828 TeeInfo.m_Size *= TeeSizeMod;
829 RenderTools()->RenderIdleTeeAtCenter(pInfo: &TeeInfo, Center: vec2(TeeOffset + TeeLength / 2, Row.y + Row.h / 2.0f));
830
831 if(m_MouseUnlocked)
832 {
833 const CUIRect SkinRect = {.x: TeeOffset, .y: Row.y, .w: TeeLength, .h: Row.h};
834 Ui()->DoToolTip(pId: &m_aPlayers[pInfo->m_ClientId].m_PlayerButtonId, pNearRect: &SkinRect, pText: ClientData.m_aSkinName);
835 }
836 }
837
838 // name
839 {
840 if(g_Config.m_ClShowIds)
841 {
842 char aClientId[16];
843 GameClient()->FormatClientId(ClientId: pInfo->m_ClientId, aClientId, Format: EClientIdFormat::INDENT_AUTO);
844 str_copy(dst&: aBuf, src: aClientId);
845 str_append(dst&: aBuf, src: ClientData.m_aName);
846 }
847 else
848 {
849 str_copy(dst&: aBuf, src: ClientData.m_aName);
850 }
851 Player.m_Name.Update(pTextRender: TextRender(), pText: aBuf, FontSize, LineWidth: NameLength, CursorFlags: TEXTFLAG_RENDER | TEXTFLAG_ELLIPSIS_AT_END);
852
853 ColorRGBA NameColor = TextColor;
854 if(ClientData.m_AuthLevel)
855 {
856 NameColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClAuthedPlayerColor));
857 }
858 Player.m_Name.Render(pTextRender: TextRender(), Pos: vec2(NameOffset, TextY), Color: NameColor);
859
860 // ready / watching
861 if(Client()->IsSixup() && Client()->m_TranslationContext.m_aClients[pInfo->m_ClientId].m_PlayerFlags7 & protocol7::PLAYERFLAG_READY)
862 {
863 Player.m_ReadyMark.Update(pTextRender: TextRender(), pText: "✓", FontSize);
864 Player.m_ReadyMark.Render(pTextRender: TextRender(), Pos: vec2(NameOffset + Player.m_Name.Width(), TextY), Color: ColorRGBA(0.1f, 1.0f, 0.1f, TextColor.a));
865 }
866 }
867
868 // clan
869 {
870 ColorRGBA ClanColor = TextColor;
871 if(GameClient()->m_aLocalIds[g_Config.m_ClDummy] >= 0 && str_comp(a: ClientData.m_aClan, b: GameClient()->m_aClients[GameClient()->m_aLocalIds[g_Config.m_ClDummy]].m_aClan) == 0)
872 {
873 ClanColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_ClSameClanColor));
874 }
875 Player.m_Clan.Update(pTextRender: TextRender(), pText: ClientData.m_aClan, FontSize, LineWidth: ClanLength, CursorFlags: TEXTFLAG_RENDER | TEXTFLAG_ELLIPSIS_AT_END);
876 Player.m_Clan.Render(pTextRender: TextRender(), Pos: vec2(ClanOffset + (ClanLength - std::min(a: Player.m_Clan.Width(), b: ClanLength)) / 2.0f, TextY), Color: ClanColor);
877 }
878
879 // country flag
880 GameClient()->m_CountryFlags.Render(CountryCode: ClientData.m_Country, Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f),
881 x: CountryOffset, y: Row.y + (Spacing + CountryFlagSize) / 2.0f, w: CountryLength, h: Row.h - Spacing - CountryFlagSize);
882
883 // ping
884 ColorRGBA PingColor = g_Config.m_ClEnablePingColor ? CRenderTools::GetPingTextColor(Latency: pInfo->m_Latency) : TextRender()->DefaultTextColor();
885 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", std::clamp(val: pInfo->m_Latency, lo: 0, hi: 999));
886 Player.m_Ping.Update(pTextRender: TextRender(), pText: aBuf, FontSize);
887 Player.m_Ping.Render(pTextRender: TextRender(), Pos: vec2(PingOffset + PingLength - Player.m_Ping.Width(), TextY), Color: PingColor);
888 TextRender()->TextColor(Color: TextRender()->DefaultTextColor());
889
890 if(CountRendered == CountEnd)
891 break;
892 }
893 if(CountRendered == CountEnd)
894 break;
895 }
896}
897
898void CScoreboard::RenderMouseHint(CUIRect MouseHint)
899{
900 constexpr float FontSize = 11.0f;
901 constexpr float PillPaddingX = 8.0f;
902 constexpr float PillPaddingY = 5.0f;
903 constexpr float TextKeycapGap = 5.0f;
904 constexpr float KeycapPaddingX = 4.0f;
905 constexpr float KeycapPaddingY = 2.0f;
906 constexpr float KeycapRadius = 3.5f;
907
908 char aKey[64];
909 GameClient()->m_Binds.GetKey(pBindStr: "toggle_scoreboard_cursor", pBuf: aKey, BufSize: sizeof(aKey));
910
911 char aHint[128];
912 if(!aKey[0])
913 {
914 str_copy(dst&: aHint, src: Localize(pStr: "not bound"));
915 }
916 else
917 {
918 str_copy(dst&: aHint, src: Localize(pStr: "Show cursor"));
919 }
920
921 const bool HasKeycap = aKey[0] != '\0';
922 const char *pChipText = HasKeycap ? aKey : "toggle_scoreboard_cursor";
923 const float TextWidth = TextRender()->TextWidth(Size: FontSize, pText: aHint, StrLength: -1);
924 const float ChipWidth = TextRender()->TextWidth(Size: FontSize, pText: pChipText, StrLength: -1) + 2 * KeycapPaddingX;
925 const float ContentWidth = ChipWidth + TextKeycapGap + TextWidth;
926 const float PillHeight = FontSize + 2 * PillPaddingY;
927 const float PillWidth = std::min(a: ContentWidth + 2 * PillPaddingX, b: MouseHint.w);
928
929 // content-sized pill, top center in the available space
930 CUIRect Pill = {.x: MouseHint.x + (MouseHint.w - PillWidth) / 2.0f, .y: MouseHint.y, .w: PillWidth, .h: PillHeight};
931 Pill.Draw(Color: BACKGROUND_COLOR, Corners: IGraphics::CORNER_ALL, Rounding: ROUNDING);
932
933 CUIRect Content = Pill;
934 Content.x += (Pill.w - ContentWidth) / 2.0f;
935 Content.w = ContentWidth;
936
937 CUIRect Label, Chip;
938 if(HasKeycap)
939 {
940 // key behind the text: "Show cursor [key]"
941 Content.VSplitLeft(Cut: TextWidth, pLeft: &Label, pRight: &Content);
942 Content.VSplitLeft(Cut: TextKeycapGap, pLeft: nullptr, pRight: &Content);
943 Content.VSplitLeft(Cut: ChipWidth, pLeft: &Chip, pRight: nullptr);
944 }
945 else
946 {
947 // bind name in front of the text: "[bind name] not bound"
948 Content.VSplitLeft(Cut: ChipWidth, pLeft: &Chip, pRight: &Content);
949 Content.VSplitLeft(Cut: TextKeycapGap, pLeft: nullptr, pRight: &Content);
950 Label = Content;
951 }
952
953 // floating chip, vertically centered in the pill
954 Chip.HMargin(Cut: (Chip.h - (FontSize + 2 * KeycapPaddingY)) / 2.0f, pOtherRect: &Chip);
955 Chip.Draw(Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.15f), Corners: IGraphics::CORNER_ALL, Rounding: KeycapRadius);
956
957 Ui()->DoLabel(pRect: &Label, pText: aHint, Size: FontSize, Align: TEXTALIGN_ML);
958 Ui()->DoLabel(pRect: &Chip, pText: pChipText, Size: FontSize, Align: TEXTALIGN_MC);
959}
960
961void CScoreboard::RenderRecordingNotification(float x)
962{
963 char aBuf[512] = "";
964
965 const auto &&AppendRecorderInfo = [&](int Recorder, const char *pName) {
966 if(GameClient()->DemoRecorder(Recorder)->IsRecording())
967 {
968 char aTime[32];
969 str_time(centisecs: (int64_t)GameClient()->DemoRecorder(Recorder)->Length() * 100, format: ETimeFormat::HOURS, buffer: aTime, buffer_size: sizeof(aTime));
970 str_append(dst&: aBuf, src: pName);
971 str_append(dst&: aBuf, src: " ");
972 str_append(dst&: aBuf, src: aTime);
973 str_append(dst&: aBuf, src: " ");
974 }
975 };
976
977 AppendRecorderInfo(RECORDER_MANUAL, Localize(pStr: "Manual"));
978 AppendRecorderInfo(RECORDER_RACE, Localize(pStr: "Race"));
979 AppendRecorderInfo(RECORDER_AUTO, Localize(pStr: "Auto"));
980 AppendRecorderInfo(RECORDER_REPLAYS, Localize(pStr: "Replay"));
981
982 if(aBuf[0] == '\0')
983 return;
984
985 constexpr float FontSize = 10.0f;
986 constexpr float CircleSize = 10.0f;
987 constexpr float Gap = 5.0f;
988
989 CUIRect Rect = {.x: x, .y: 0.0f, .w: TextRender()->TextWidth(Size: FontSize, pText: aBuf) + 30.0f, .h: 25.0f};
990 Rect.Draw(Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.4f), Corners: IGraphics::CORNER_B, Rounding: ROUNDING);
991 Rect.VSplitLeft(Cut: CircleSize, pLeft: nullptr, pRight: &Rect);
992 Rect.VSplitRight(Cut: Gap, pLeft: &Rect, pRight: nullptr);
993
994 CUIRect Circle;
995 Rect.VSplitLeft(Cut: CircleSize, pLeft: &Circle, pRight: &Rect);
996 Circle.HMargin(Cut: (Circle.h - Circle.w) / 2.0f, pOtherRect: &Circle);
997 Circle.Draw(Color: ColorRGBA(1.0f, 0.0f, 0.0f, 1.0f), Corners: IGraphics::CORNER_ALL, Rounding: Circle.h / 2.0f);
998
999 Rect.VSplitLeft(Cut: Gap, pLeft: nullptr, pRight: &Rect);
1000 Ui()->DoLabel(pRect: &Rect, pText: aBuf, Size: FontSize, Align: TEXTALIGN_ML);
1001}
1002
1003void CScoreboard::OnRender()
1004{
1005 if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
1006 return;
1007
1008 if(!IsActive())
1009 {
1010 // lock mouse if scoreboard was opened by being dead or game pause
1011 if(m_MouseUnlocked)
1012 {
1013 LockMouse();
1014 }
1015 return;
1016 }
1017
1018 if(!GameClient()->m_Menus.IsActive() && !GameClient()->m_Chat.IsActive())
1019 {
1020 Ui()->StartCheck();
1021 Ui()->Update();
1022 }
1023
1024 constexpr float TitleHeight = 30.0f;
1025 constexpr float ScoreboardSmallWidth = 375.0f + 10.0f;
1026 constexpr float ScoreboardSpacing = 5.0f;
1027
1028 // if the score board is active, then we should clear the motd message as well
1029 if(GameClient()->m_Motd.IsActive())
1030 GameClient()->m_Motd.Clear();
1031
1032 const CUIRect Screen = *Ui()->Screen();
1033 Ui()->MapScreen();
1034
1035 const CNetObj_GameInfo *pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj;
1036 const bool Teams = GameClient()->IsTeamPlay();
1037 const auto &aTeamSize = GameClient()->m_Snap.m_aTeamSize;
1038 const int NumPlayers = Teams ? std::max(a: aTeamSize[TEAM_RED], b: aTeamSize[TEAM_BLUE]) : aTeamSize[TEAM_RED];
1039
1040 const float ScoreboardWidth = !Teams && NumPlayers <= 16 ? ScoreboardSmallWidth : 750.0f;
1041
1042 CUIRect Scoreboard = {.x: (Screen.w - ScoreboardWidth) / 2.0f, .y: 75.0f, .w: ScoreboardWidth, .h: 355.0f + TitleHeight};
1043 CScoreboardRenderState RenderState{};
1044
1045 if(Teams)
1046 {
1047 const char *pRedTeamName = GetTeamName(Team: TEAM_RED);
1048 const char *pBlueTeamName = GetTeamName(Team: TEAM_BLUE);
1049
1050 // Game over title
1051 const CNetObj_GameData *pGameDataObj = GameClient()->m_Snap.m_pGameDataObj;
1052 if((pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_GAMEOVER) && pGameDataObj)
1053 {
1054 char aTitle[256];
1055 if(pGameDataObj->m_TeamscoreRed > pGameDataObj->m_TeamscoreBlue)
1056 {
1057 TextRender()->TextColor(Color: TEAM_RED_TITLE_COLOR);
1058 if(pRedTeamName == nullptr)
1059 {
1060 str_copy(dst&: aTitle, src: Localize(pStr: "Red team wins!"));
1061 }
1062 else
1063 {
1064 str_format(buffer: aTitle, buffer_size: sizeof(aTitle), format: Localize(pStr: "%s wins!"), pRedTeamName);
1065 }
1066 }
1067 else if(pGameDataObj->m_TeamscoreBlue > pGameDataObj->m_TeamscoreRed)
1068 {
1069 TextRender()->TextColor(Color: TEAM_BLUE_TITLE_COLOR);
1070 if(pBlueTeamName == nullptr)
1071 {
1072 str_copy(dst&: aTitle, src: Localize(pStr: "Blue team wins!"));
1073 }
1074 else
1075 {
1076 str_format(buffer: aTitle, buffer_size: sizeof(aTitle), format: Localize(pStr: "%s wins!"), pBlueTeamName);
1077 }
1078 }
1079 else
1080 {
1081 TextRender()->TextColor(Color: ColorRGBA(0.91f, 0.78f, 0.33f, 1.0f));
1082 str_copy(dst&: aTitle, src: Localize(pStr: "Draw!"));
1083 }
1084
1085 const float TitleFontSize = 36.0f;
1086 CUIRect GameOverTitle = {.x: Scoreboard.x, .y: Scoreboard.y - TitleFontSize - 6.0f, .w: Scoreboard.w, .h: TitleFontSize};
1087 Ui()->DoLabel(pRect: &GameOverTitle, pText: aTitle, Size: TitleFontSize, Align: TEXTALIGN_MC);
1088 TextRender()->TextColor(Color: TextRender()->DefaultTextColor());
1089 }
1090
1091 CUIRect RedScoreboard, BlueScoreboard, RedTitle, BlueTitle;
1092 Scoreboard.VSplitMid(pLeft: &RedScoreboard, pRight: &BlueScoreboard, Spacing: ROUNDING);
1093 RedScoreboard.HSplitTop(Cut: TitleHeight, pTop: &RedTitle, pBottom: &RedScoreboard);
1094 BlueScoreboard.HSplitTop(Cut: TitleHeight, pTop: &BlueTitle, pBottom: &BlueScoreboard);
1095
1096 RedTitle.Draw(Color: TEAM_RED_TITLE_COLOR.WithAlpha(alpha: 0.5f), Corners: IGraphics::CORNER_T, Rounding: ROUNDING);
1097 BlueTitle.Draw(Color: TEAM_BLUE_TITLE_COLOR.WithAlpha(alpha: 0.5f), Corners: IGraphics::CORNER_T, Rounding: ROUNDING);
1098 RedScoreboard.Draw(Color: BACKGROUND_COLOR, Corners: IGraphics::CORNER_B, Rounding: ROUNDING);
1099 BlueScoreboard.Draw(Color: BACKGROUND_COLOR, Corners: IGraphics::CORNER_B, Rounding: ROUNDING);
1100
1101 RenderTitleBar(TitleBar: RedTitle, Team: TEAM_RED, pTitle: pRedTeamName == nullptr ? Localize(pStr: "Red team") : pRedTeamName);
1102 RenderTitleBar(TitleBar: BlueTitle, Team: TEAM_BLUE, pTitle: pBlueTeamName == nullptr ? Localize(pStr: "Blue team") : pBlueTeamName);
1103
1104 auto RenderTeamScoreboard = [&](CUIRect TeamScoreboard, int Team, int TeamSize) {
1105 if(TeamSize <= 64)
1106 {
1107 RenderScoreboard(Scoreboard: TeamScoreboard, Team, CountStart: 0, CountEnd: TeamSize, State&: RenderState);
1108 }
1109 else
1110 {
1111 const int FirstColumnSize = 64;
1112 CUIRect LeftColumn, RightColumn;
1113 TeamScoreboard.VSplitMid(pLeft: &LeftColumn, pRight: &RightColumn, Spacing: 2.5f);
1114
1115 RenderScoreboard(Scoreboard: LeftColumn, Team, CountStart: 0, CountEnd: FirstColumnSize, State&: RenderState, NumPlayersForSize: FirstColumnSize);
1116 RenderScoreboard(Scoreboard: RightColumn, Team, CountStart: FirstColumnSize, CountEnd: TeamSize, State&: RenderState, NumPlayersForSize: FirstColumnSize);
1117 }
1118 };
1119
1120 RenderTeamScoreboard(RedScoreboard, TEAM_RED, aTeamSize[TEAM_RED]);
1121 RenderTeamScoreboard(BlueScoreboard, TEAM_BLUE, aTeamSize[TEAM_BLUE]);
1122 }
1123 else
1124 {
1125 Scoreboard.Draw(Color: BACKGROUND_COLOR, Corners: IGraphics::CORNER_ALL, Rounding: ROUNDING);
1126
1127 const char *pTitle;
1128 if(pGameInfoObj && (pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_GAMEOVER))
1129 {
1130 pTitle = Localize(pStr: "Game over");
1131 }
1132 else
1133 {
1134 pTitle = GameClient()->Map()->BaseName();
1135 }
1136
1137 CUIRect Title;
1138 Scoreboard.HSplitTop(Cut: TitleHeight, pTop: &Title, pBottom: &Scoreboard);
1139 RenderTitleBar(TitleBar: Title, Team: TEAM_GAME, pTitle);
1140
1141 if(NumPlayers <= 16)
1142 {
1143 RenderScoreboard(Scoreboard, Team: TEAM_GAME, CountStart: 0, CountEnd: NumPlayers, State&: RenderState);
1144 }
1145 else if(NumPlayers <= 64)
1146 {
1147 int PlayersPerSide;
1148 if(NumPlayers <= 24)
1149 PlayersPerSide = 12;
1150 else if(NumPlayers <= 32)
1151 PlayersPerSide = 16;
1152 else if(NumPlayers <= 48)
1153 PlayersPerSide = 24;
1154 else
1155 PlayersPerSide = 32;
1156
1157 CUIRect LeftScoreboard, RightScoreboard;
1158 Scoreboard.VSplitMid(pLeft: &LeftScoreboard, pRight: &RightScoreboard);
1159 RenderScoreboard(Scoreboard: LeftScoreboard, Team: TEAM_GAME, CountStart: 0, CountEnd: PlayersPerSide, State&: RenderState);
1160 RenderScoreboard(Scoreboard: RightScoreboard, Team: TEAM_GAME, CountStart: PlayersPerSide, CountEnd: 2 * PlayersPerSide, State&: RenderState);
1161 }
1162 else
1163 {
1164 const int NumColumns = 3;
1165 const int PlayersPerColumn = std::ceil(x: 128.0f / NumColumns);
1166 CUIRect RemainingScoreboard = Scoreboard;
1167 for(int i = 0; i < NumColumns; ++i)
1168 {
1169 CUIRect Column;
1170 RemainingScoreboard.VSplitLeft(Cut: Scoreboard.w / NumColumns, pLeft: &Column, pRight: &RemainingScoreboard);
1171 RenderScoreboard(Scoreboard: Column, Team: TEAM_GAME, CountStart: i * PlayersPerColumn, CountEnd: (i + 1) * PlayersPerColumn, State&: RenderState);
1172 }
1173 }
1174 }
1175
1176 CUIRect Spectators = {.x: (Screen.w - ScoreboardSmallWidth) / 2.0f, .y: Scoreboard.y + Scoreboard.h + ScoreboardSpacing, .w: ScoreboardSmallWidth, .h: 100.0f};
1177 if(pGameInfoObj && (pGameInfoObj->m_ScoreLimit || pGameInfoObj->m_TimeLimit || (pGameInfoObj->m_RoundNum && pGameInfoObj->m_RoundCurrent)))
1178 {
1179 CUIRect Goals;
1180 Spectators.HSplitTop(Cut: 25.0f, pTop: &Goals, pBottom: &Spectators);
1181 Spectators.HSplitTop(Cut: ScoreboardSpacing, pTop: nullptr, pBottom: &Spectators);
1182 RenderGoals(Goals);
1183 }
1184 RenderSpectators(Spectators);
1185
1186 if(!m_MouseUnlocked)
1187 {
1188 constexpr float MouseHintSize = 26.0f;
1189 CUIRect MouseHint = {.x: Spectators.x, .y: Spectators.y + Spectators.h + ScoreboardSpacing, .w: ScoreboardSmallWidth, .h: MouseHintSize};
1190 RenderMouseHint(MouseHint);
1191 }
1192
1193 RenderRecordingNotification(x: (Screen.w / 7) * 4 + 10);
1194
1195 if(!GameClient()->m_Menus.IsActive() && !GameClient()->m_Chat.IsActive())
1196 {
1197 Ui()->RenderPopupMenus();
1198
1199 if(m_MouseUnlocked)
1200 RenderTools()->RenderCursor(Center: Ui()->MousePos(), Size: 24.0f);
1201
1202 Ui()->FinishCheck();
1203 }
1204}
1205
1206bool CScoreboard::IsActive() const
1207{
1208 // if statboard is active don't show scoreboard
1209 if(GameClient()->m_Statboard.IsActive())
1210 return false;
1211
1212 if(m_Active)
1213 return true;
1214
1215 const CNetObj_GameInfo *pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj;
1216 if(GameClient()->m_Snap.m_pLocalInfo && !GameClient()->m_Snap.m_SpecInfo.m_Active)
1217 {
1218 // we are not a spectator, check if we are dead and the game isn't paused
1219 if(!GameClient()->m_Snap.m_pLocalCharacter && g_Config.m_ClScoreboardOnDeath &&
1220 !(pGameInfoObj && pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_PAUSED))
1221 return true;
1222 }
1223
1224 // if the game is over
1225 if(pGameInfoObj && pGameInfoObj->m_GameStateFlags & GAMESTATEFLAG_GAMEOVER)
1226 return true;
1227
1228 return false;
1229}
1230
1231const char *CScoreboard::GetTeamName(int Team) const
1232{
1233 dbg_assert(Team == TEAM_RED || Team == TEAM_BLUE, "Team invalid");
1234
1235 int ClanPlayers = 0;
1236 const char *pClanName = nullptr;
1237 for(const CNetObj_PlayerInfo *pInfo : GameClient()->m_Snap.m_apInfoByScore)
1238 {
1239 if(!pInfo || pInfo->m_Team != Team)
1240 continue;
1241
1242 if(!pClanName)
1243 {
1244 pClanName = GameClient()->m_aClients[pInfo->m_ClientId].m_aClan;
1245 ClanPlayers++;
1246 }
1247 else
1248 {
1249 if(str_comp(a: GameClient()->m_aClients[pInfo->m_ClientId].m_aClan, b: pClanName) == 0)
1250 ClanPlayers++;
1251 else
1252 return nullptr;
1253 }
1254 }
1255
1256 if(ClanPlayers > 1 && pClanName[0] != '\0')
1257 return pClanName;
1258 else
1259 return nullptr;
1260}
1261
1262CUi::EPopupMenuFunctionResult CScoreboard::CScoreboardPopupContext::Render(void *pContext, CUIRect View, bool Active)
1263{
1264 CScoreboardPopupContext *pPopupContext = static_cast<CScoreboardPopupContext *>(pContext);
1265 CScoreboard *pScoreboard = pPopupContext->m_pScoreboard;
1266 CUi *pUi = pPopupContext->m_pScoreboard->Ui();
1267
1268 CGameClient::CClientData &Client = pScoreboard->GameClient()->m_aClients[pPopupContext->m_ClientId];
1269
1270 if(!Client.m_Active)
1271 return CUi::POPUP_CLOSE_CURRENT;
1272
1273 constexpr float Margin = 5.0f;
1274 constexpr float ItemSpacing = 2.0f;
1275 constexpr float FontSize = 12.0f;
1276 constexpr float ButtonSize = 17.5f;
1277
1278 View.Margin(Cut: Margin, pOtherRect: &View);
1279
1280 CUIRect Label, Container, Action;
1281
1282 View.HSplitTop(Cut: FontSize, pTop: &Label, pBottom: &View);
1283 pUi->DoLabel(pRect: &Label, pText: Client.m_aName, Size: FontSize, Align: TEXTALIGN_ML);
1284
1285 if(!pPopupContext->m_IsLocal)
1286 {
1287 constexpr int ActionsNum = 3;
1288 constexpr float ActionSize = 25.0f;
1289 const float ActionSpacing = (View.w - (ActionsNum * ActionSize)) / 2;
1290 int ActionCorners = IGraphics::CORNER_ALL;
1291
1292 View.HSplitTop(Cut: ItemSpacing * 2, pTop: nullptr, pBottom: &View);
1293 View.HSplitTop(Cut: ActionSize, pTop: &Container, pBottom: &View);
1294
1295 Container.VSplitLeft(Cut: ActionSize, pLeft: &Action, pRight: &Container);
1296
1297 ColorRGBA FriendActionColor = Client.m_Friend ? ColorRGBA(0.95f, 0.3f, 0.3f, 0.85f * pUi->ButtonColorMul(pId: &pPopupContext->m_FriendAction)) :
1298 ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f * pUi->ButtonColorMul(pId: &pPopupContext->m_FriendAction));
1299 const char *pFriendActionIcon = pUi->HotItem() == &pPopupContext->m_FriendAction && Client.m_Friend ? FontIcon::HEART_CRACK : FontIcon::HEART;
1300 if(pUi->DoButton_FontIcon(pButtonContainer: &pPopupContext->m_FriendAction, pText: pFriendActionIcon, Checked: Client.m_Friend, pRect: &Action, Flags: BUTTONFLAG_LEFT, Corners: ActionCorners, Enabled: true, ButtonColor: FriendActionColor))
1301 {
1302 if(Client.m_Friend)
1303 {
1304 pScoreboard->GameClient()->Friends()->RemoveFriend(pName: Client.m_aName, pClan: Client.m_aClan);
1305 }
1306 else
1307 {
1308 pScoreboard->GameClient()->Friends()->AddFriend(pName: Client.m_aName, pClan: Client.m_aClan);
1309 }
1310 }
1311
1312 pScoreboard->Ui()->DoToolTip(pId: &pPopupContext->m_FriendAction, pNearRect: &Action, pText: Client.m_Friend ? Localize(pStr: "Remove friend") : Localize(pStr: "Add friend"));
1313
1314 Container.VSplitLeft(Cut: ActionSpacing, pLeft: nullptr, pRight: &Container);
1315 Container.VSplitLeft(Cut: ActionSize, pLeft: &Action, pRight: &Container);
1316
1317 if(pUi->DoButton_FontIcon(pButtonContainer: &pPopupContext->m_MuteAction, pText: FontIcon::BAN, Checked: Client.m_ChatIgnore, pRect: &Action, Flags: BUTTONFLAG_LEFT, Corners: ActionCorners))
1318 {
1319 Client.m_ChatIgnore ^= 1;
1320 }
1321 pScoreboard->Ui()->DoToolTip(pId: &pPopupContext->m_MuteAction, pNearRect: &Action, pText: Client.m_ChatIgnore ? Localize(pStr: "Unmute") : Localize(pStr: "Mute"));
1322
1323 Container.VSplitLeft(Cut: ActionSpacing, pLeft: nullptr, pRight: &Container);
1324 Container.VSplitLeft(Cut: ActionSize, pLeft: &Action, pRight: &Container);
1325
1326 const char *EmoticonActionIcon = Client.m_EmoticonIgnore ? FontIcon::COMMENT_SLASH : FontIcon::COMMENT;
1327 if(pUi->DoButton_FontIcon(pButtonContainer: &pPopupContext->m_EmoticonAction, pText: EmoticonActionIcon, Checked: Client.m_EmoticonIgnore, pRect: &Action, Flags: BUTTONFLAG_LEFT, Corners: ActionCorners))
1328 {
1329 Client.m_EmoticonIgnore ^= 1;
1330 }
1331 pScoreboard->Ui()->DoToolTip(pId: &pPopupContext->m_EmoticonAction, pNearRect: &Action, pText: Client.m_EmoticonIgnore ? Localize(pStr: "Unmute emoticons") : Localize(pStr: "Mute emoticons"));
1332 }
1333
1334 View.HSplitTop(Cut: ItemSpacing * 2, pTop: nullptr, pBottom: &View);
1335 View.HSplitTop(Cut: ButtonSize, pTop: &Container, pBottom: &View);
1336
1337 bool IsSpectating = pScoreboard->GameClient()->m_Snap.m_SpecInfo.m_Active && pScoreboard->GameClient()->m_Snap.m_SpecInfo.m_SpectatorId == pPopupContext->m_ClientId;
1338 ColorRGBA SpectateButtonColor = ColorRGBA(1.0f, 1.0f, 1.0f, (IsSpectating ? 0.25f : 0.5f) * pUi->ButtonColorMul(pId: &pPopupContext->m_SpectateButton));
1339 if(!pPopupContext->m_IsSpectating)
1340 {
1341 if(pUi->DoButton_PopupMenu(pButtonContainer: &pPopupContext->m_SpectateButton, pText: Localize(pStr: "Spectate"), pRect: &Container, Size: FontSize, Align: TEXTALIGN_MC, Padding: 0.0f, TransparentInactive: false, Enabled: true, ButtonColor: SpectateButtonColor))
1342 {
1343 if(IsSpectating)
1344 {
1345 pScoreboard->GameClient()->m_Spectator.Spectate(SpectatorId: SPEC_FREEVIEW);
1346 pScoreboard->Console()->ExecuteLine(pStr: "say /spec", ClientId: IConsole::CLIENT_ID_UNSPECIFIED);
1347 }
1348 else
1349 {
1350 if(pScoreboard->GameClient()->m_Snap.m_SpecInfo.m_Active)
1351 {
1352 pScoreboard->GameClient()->m_Spectator.Spectate(SpectatorId: pPopupContext->m_ClientId);
1353 }
1354 else
1355 {
1356 // escape the name
1357 char aEscapedCommand[2 * MAX_NAME_LENGTH + 32];
1358 str_copy(dst&: aEscapedCommand, src: "say /spec \"");
1359 char *pDst = aEscapedCommand + str_length(str: aEscapedCommand);
1360 str_escape(dst: &pDst, src: Client.m_aName, end: aEscapedCommand + sizeof(aEscapedCommand));
1361 str_append(dst&: aEscapedCommand, src: "\"");
1362
1363 pScoreboard->Console()->ExecuteLine(pStr: aEscapedCommand, ClientId: IConsole::CLIENT_ID_UNSPECIFIED);
1364 }
1365 }
1366 }
1367 }
1368
1369 return CUi::POPUP_KEEP_OPEN;
1370}
1371
1372CUi::EPopupMenuFunctionResult CScoreboard::CMapTitlePopupContext::Render(void *pContext, CUIRect View, bool Active)
1373{
1374 CMapTitlePopupContext *pPopupContext = static_cast<CMapTitlePopupContext *>(pContext);
1375 CScoreboard *pScoreboard = pPopupContext->m_pScoreboard;
1376
1377 pScoreboard->TextRender()->Text(x: View.x, y: View.y, Size: pPopupContext->m_FontSize, pText: pScoreboard->GameClient()->m_aMapDescription, LineWidth: View.w);
1378
1379 return CUi::POPUP_KEEP_OPEN;
1380}
1381