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#ifndef GAME_CLIENT_COMPONENTS_SCOREBOARD_H
4#define GAME_CLIENT_COMPONENTS_SCOREBOARD_H
5
6#include <engine/console.h>
7#include <engine/graphics.h>
8
9#include <game/client/component.h>
10#include <game/client/ui.h>
11#include <game/client/ui_rect.h>
12
13class CScoreboard : public CComponent
14{
15 struct CScoreboardRenderState
16 {
17 float m_TeamStartX;
18 float m_TeamStartY;
19 int m_CurrentDDTeamSize;
20
21 CScoreboardRenderState() :
22 m_TeamStartX(0), m_TeamStartY(0), m_CurrentDDTeamSize(0) {}
23 };
24
25 void RenderTitleScore(CUIRect ScoreLabel, int Team, float TitleFontSize);
26 void RenderTitle(CUIRect TitleLabel, int Team, const char *pTitle, float TitleFontSize);
27 void RenderTitleBar(CUIRect TitleBar, int Team, const char *pTitle);
28 void RenderGoals(CUIRect Goals);
29 void RenderSpectators(CUIRect Spectators);
30 void RenderMouseHint(CUIRect MouseHint);
31 void RenderScoreboard(CUIRect Scoreboard, int Team, int CountStart, int CountEnd, CScoreboardRenderState &State, int NumPlayersForSize = -1);
32 void RenderRecordingNotification(float x);
33
34 static void ConKeyScoreboard(IConsole::IResult *pResult, void *pUserData);
35 static void ConToggleScoreboardCursor(IConsole::IResult *pResult, void *pUserData);
36
37 const char *GetTeamName(int Team) const;
38
39 bool m_Active;
40
41 IGraphics::CTextureHandle m_DeadTeeTexture;
42
43 std::optional<vec2> m_LastMousePos;
44 bool m_MouseUnlocked = false;
45
46 void SetUiMousePos(vec2 Pos);
47 void LockMouse();
48
49 class CScoreboardPopupContext : public SPopupMenuId
50 {
51 public:
52 CScoreboard *m_pScoreboard = nullptr;
53 CButtonContainer m_FriendAction;
54 CButtonContainer m_MuteAction;
55 CButtonContainer m_EmoticonAction;
56
57 CButtonContainer m_SpectateButton;
58
59 int m_ClientId;
60 bool m_IsLocal;
61 bool m_IsSpectating;
62
63 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
64 } m_ScoreboardPopupContext;
65
66 class CMapTitlePopupContext : public SPopupMenuId
67 {
68 public:
69 CScoreboard *m_pScoreboard = nullptr;
70
71 float m_FontSize;
72
73 static CUi::EPopupMenuFunctionResult Render(void *pContext, CUIRect View, bool Active);
74 } m_MapTitlePopupContext;
75 char m_MapTitleButtonId;
76
77 class CPlayerElement
78 {
79 public:
80 char m_PlayerButtonId;
81 char m_TimeTooltipId;
82 char m_SpectatorSecondLineButtonId;
83 char m_aTimeTooltip[32];
84
85 CCachedText m_Score;
86 CCachedText m_ScoreMillis;
87 CCachedText m_Name;
88 CCachedText m_ReadyMark;
89 CCachedText m_Clan;
90 CCachedText m_Ping;
91 };
92 CPlayerElement m_aPlayers[MAX_CLIENTS];
93
94 CCachedText m_TitleScore;
95 CCachedText m_TitleScoreMillis;
96 CCachedText m_HeadlineScore;
97 CCachedText m_HeadlineName;
98 CCachedText m_HeadlineClan;
99 CCachedText m_HeadlinePing;
100
101 void ResetTexts();
102
103public:
104 CScoreboard();
105 int Sizeof() const override { return sizeof(*this); }
106 void OnConsoleInit() override;
107 void OnInit() override;
108 void OnReset() override;
109 void OnShutdown() override;
110 void OnWindowResize() override;
111 void OnRender() override;
112 void OnRelease() override;
113 bool OnCursorMove(float x, float y, IInput::ECursorType CursorType) override;
114 bool OnInput(const IInput::CEvent &Event) override;
115
116 bool IsActive() const;
117};
118
119#endif
120