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_MENUS_H
4#define GAME_CLIENT_COMPONENTS_MENUS_H
5
6#include <base/bytes.h>
7#include <base/str.h>
8#include <base/types.h>
9#include <base/vmath.h>
10
11#include <engine/console.h>
12#include <engine/demo.h>
13#include <engine/friends.h>
14#include <engine/serverbrowser.h>
15#include <engine/shared/config.h>
16#include <engine/textrender.h>
17
18#include <game/client/component.h>
19#include <game/client/components/community_icons.h>
20#include <game/client/components/mapimages.h>
21#include <game/client/components/menus_ingame_touch_controls.h>
22#include <game/client/components/menus_settings_controls.h>
23#include <game/client/components/menus_start.h>
24#include <game/client/components/skins7.h>
25#include <game/client/lineinput.h>
26#include <game/client/ui.h>
27#include <game/voting.h>
28
29#include <chrono>
30#include <optional>
31#include <vector>
32
33class CMenus : public CComponent
34{
35 static ColorRGBA ms_GuiColor;
36 static ColorRGBA ms_ColorTabbarInactiveOutgame;
37 static ColorRGBA ms_ColorTabbarActiveOutgame;
38 static ColorRGBA ms_ColorTabbarHoverOutgame;
39 static ColorRGBA ms_ColorTabbarInactiveIngame;
40 static ColorRGBA ms_ColorTabbarActiveIngame;
41 static ColorRGBA ms_ColorTabbarHoverIngame;
42 static ColorRGBA ms_ColorTabbarInactive;
43 static ColorRGBA ms_ColorTabbarActive;
44 static ColorRGBA ms_ColorTabbarHover;
45
46public:
47 // Width of the image in DoButton_Menu, relative to the button height
48 static constexpr float BUTTON_IMAGE_WIDTH_FACTOR = 4.0f;
49
50 int DoButton_Toggle(const void *pId, int Checked, const CUIRect *pRect, bool Active, unsigned Flags = BUTTONFLAG_LEFT);
51 int DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, unsigned Flags = BUTTONFLAG_LEFT, const char *pImageName = nullptr, int Corners = IGraphics::CORNER_ALL, float Rounding = 5.0f, float FontFactor = 0.0f, ColorRGBA Color = ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f), const void *pImageHotId = nullptr);
52 int DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, int Corners, SUIAnimator *pAnimator = nullptr, const ColorRGBA *pDefaultColor = nullptr, const ColorRGBA *pActiveColor = nullptr, const ColorRGBA *pHoverColor = nullptr, float EdgeRounding = 10.0f, const CCommunityIcon *pCommunityIcon = nullptr);
53
54 int DoButton_CheckBox_Common(const void *pId, const char *pText, const char *pBoxText, const CUIRect *pRect, unsigned Flags);
55 int DoButton_CheckBox(const void *pId, const char *pText, int Checked, const CUIRect *pRect);
56 int DoButton_CheckBoxAutoVMarginAndSet(const void *pId, const char *pText, int *pValue, CUIRect *pRect, float VMargin);
57 int DoButton_CheckBox_Number(const void *pId, const char *pText, int Checked, const CUIRect *pRect);
58
59 bool DoLine_RadioMenu(CUIRect &View, const char *pLabel, std::vector<CButtonContainer> &vButtonContainers, const std::vector<const char *> &vLabels, const std::vector<int> &vValues, int &Value);
60
61private:
62 CUi::SColorPickerPopupContext m_ColorPickerPopupContext;
63 ColorHSLA DoLine_ColorPicker(CButtonContainer *pResetId, float LineSize, float LabelSize, float BottomMargin, CUIRect *pMainRect, const char *pText, unsigned int *pColorValue, ColorRGBA DefaultColor, bool CheckBoxSpacing = true, int *pCheckBoxValue = nullptr, bool Alpha = false);
64 ColorHSLA DoButton_ColorPicker(const CUIRect *pRect, unsigned int *pHslaColor, bool Alpha);
65
66 int DoButton_GridHeader(const void *pId, const char *pText, int Checked, const CUIRect *pRect, int Align = TEXTALIGN_ML);
67 int DoButton_Favorite(const void *pButtonId, const void *pParentId, bool Checked, const CUIRect *pRect);
68
69 std::optional<std::chrono::nanoseconds> m_SkinList7LastRefreshTime;
70 std::optional<std::chrono::nanoseconds> m_SkinPartsList7LastRefreshTime;
71
72 int m_DirectionQuadContainerIndex;
73
74 // menus_settings_assets.cpp
75public:
76 struct SCustomItem
77 {
78 IGraphics::CTextureHandle m_RenderTexture;
79
80 char m_aName[50];
81
82 bool operator<(const SCustomItem &Other) const { return str_comp(a: m_aName, b: Other.m_aName) < 0; }
83 };
84
85 struct SCustomEntities : public SCustomItem
86 {
87 struct SEntitiesImage
88 {
89 IGraphics::CTextureHandle m_Texture;
90 };
91 SEntitiesImage m_aImages[MAP_IMAGE_MOD_TYPE_COUNT];
92 };
93
94 struct SCustomGame : public SCustomItem
95 {
96 };
97
98 struct SCustomEmoticon : public SCustomItem
99 {
100 };
101
102 struct SCustomParticle : public SCustomItem
103 {
104 };
105
106 struct SCustomHud : public SCustomItem
107 {
108 };
109
110 struct SCustomExtras : public SCustomItem
111 {
112 };
113
114protected:
115 std::vector<SCustomEntities> m_vEntitiesList;
116 std::vector<SCustomGame> m_vGameList;
117 std::vector<SCustomEmoticon> m_vEmoticonList;
118 std::vector<SCustomParticle> m_vParticlesList;
119 std::vector<SCustomHud> m_vHudList;
120 std::vector<SCustomExtras> m_vExtrasList;
121
122 bool m_IsInit = false;
123
124 static void LoadEntities(struct SCustomEntities *pEntitiesItem, void *pUser);
125 static int EntitiesScan(const char *pName, int IsDir, int DirType, void *pUser);
126
127 static int GameScan(const char *pName, int IsDir, int DirType, void *pUser);
128 static int EmoticonsScan(const char *pName, int IsDir, int DirType, void *pUser);
129 static int ParticlesScan(const char *pName, int IsDir, int DirType, void *pUser);
130 static int HudScan(const char *pName, int IsDir, int DirType, void *pUser);
131 static int ExtrasScan(const char *pName, int IsDir, int DirType, void *pUser);
132
133 static void ConchainAssetsEntities(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
134 static void ConchainAssetGame(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
135 static void ConchainAssetParticles(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
136 static void ConchainAssetEmoticons(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
137 static void ConchainAssetHud(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
138 static void ConchainAssetExtras(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
139
140 void ClearCustomItems(int CurTab);
141
142 int m_MenuPage;
143 int m_GamePage;
144 int m_Popup;
145 bool m_ShowStart;
146 bool m_MenuActive;
147
148 bool m_DummyNamePlatePreview = false;
149
150 class CJoinTutorial
151 {
152 public:
153 bool m_Queued = false;
154 enum class EStatus
155 {
156 REFRESHING,
157 SERVER_LIST_ERROR,
158 NO_TUTORIAL_AVAILABLE,
159 };
160 EStatus m_Status = EStatus::REFRESHING;
161 bool m_TryRefresh = false;
162 bool m_TriedRefresh = false;
163 enum class ELocalServerState
164 {
165 NOT_TRIED,
166 TRY,
167 WAITING_STOP,
168 WAITING_START,
169 };
170 ELocalServerState m_LocalServerState = ELocalServerState::NOT_TRIED;
171 std::chrono::nanoseconds m_StateChange = std::chrono::nanoseconds(0);
172 };
173 CJoinTutorial m_JoinTutorial;
174
175 bool m_CreateDefaultFavoriteCommunities = false;
176 bool m_ForceRefreshLanPage = false;
177
178 char m_aNextServer[256];
179
180 // images
181 struct CMenuImage
182 {
183 char m_aName[64];
184 IGraphics::CTextureHandle m_OrgTexture;
185 IGraphics::CTextureHandle m_GreyTexture;
186 };
187 std::vector<CMenuImage> m_vMenuImages;
188 static int MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser);
189 const CMenuImage *FindMenuImage(const char *pName);
190
191 // loading
192 class CLoadingState
193 {
194 public:
195 std::chrono::nanoseconds m_LastRender{0};
196 int m_Current;
197 int m_Total;
198 };
199 CLoadingState m_LoadingState;
200
201 //
202 char m_aMessageTopic[512];
203 char m_aMessageBody[512];
204 char m_aMessageButton[512];
205
206 CUIElement m_RefreshButton;
207 CUIElement m_ConnectButton;
208
209 // generic popups
210 typedef void (CMenus::*FPopupButtonCallback)();
211 void DefaultButtonCallback()
212 {
213 // do nothing
214 }
215 enum
216 {
217 BUTTON_CONFIRM = 0, // confirm / yes / close / ok
218 BUTTON_CANCEL, // cancel / no
219 NUM_BUTTONS
220 };
221 char m_aPopupTitle[128];
222 char m_aPopupMessage[IO_MAX_PATH_LENGTH + 256];
223 struct
224 {
225 char m_aLabel[64];
226 int m_NextPopup;
227 FPopupButtonCallback m_pfnCallback;
228 } m_aPopupButtons[NUM_BUTTONS];
229
230 void PopupMessage(const char *pTitle, const char *pMessage,
231 const char *pButtonLabel, int NextPopup = POPUP_NONE, FPopupButtonCallback pfnButtonCallback = &CMenus::DefaultButtonCallback);
232 void PopupConfirm(const char *pTitle, const char *pMessage,
233 const char *pConfirmButtonLabel, const char *pCancelButtonLabel,
234 FPopupButtonCallback pfnConfirmButtonCallback = &CMenus::DefaultButtonCallback, int ConfirmNextPopup = POPUP_NONE,
235 FPopupButtonCallback pfnCancelButtonCallback = &CMenus::DefaultButtonCallback, int CancelNextPopup = POPUP_NONE);
236
237 // some settings
238 static float ms_ButtonHeight;
239 static float ms_ListheaderHeight;
240 static float ms_ListitemAdditionalHeight;
241
242 // for settings
243 bool m_NeedRestartGraphics;
244 bool m_NeedRestartSound;
245 bool m_NeedRestartUpdate;
246 bool m_NeedSendinfo;
247 bool m_NeedSendDummyinfo;
248
249 // for map download popup
250 int64_t m_DownloadLastCheckTime;
251 int m_DownloadLastCheckSize;
252 float m_DownloadSpeed;
253
254 // for password popup
255 CLineInput m_PasswordInput;
256
257 // for call vote
258 int m_CallvoteSelectedOption;
259 int m_CallvoteSelectedPlayer;
260 CLineInputBuffered<VOTE_REASON_LENGTH> m_CallvoteReasonInput;
261 CLineInputBuffered<64> m_FilterInput;
262 bool m_ControlPageOpening;
263
264 // demo
265 enum
266 {
267 SORT_DEMONAME = 0,
268 SORT_MARKERS,
269 SORT_LENGTH,
270 SORT_DATE,
271 };
272
273 class CDemoItem
274 {
275 public:
276 char m_aFilename[IO_MAX_PATH_LENGTH];
277 char m_aName[IO_MAX_PATH_LENGTH];
278 bool m_IsDir;
279 bool m_IsLink;
280 int m_StorageType;
281 time_t m_Date;
282 int64_t m_Size;
283
284 bool m_InfosLoaded;
285 bool m_Valid;
286 CDemoHeader m_Info;
287 CTimelineMarkers m_TimelineMarkers;
288 CMapInfo m_MapInfo;
289
290 int NumMarkers() const
291 {
292 return std::clamp<int>(val: bytes_be_to_uint(bytes: m_TimelineMarkers.m_aNumTimelineMarkers), lo: 0, hi: MAX_TIMELINE_MARKERS);
293 }
294
295 int Length() const
296 {
297 return bytes_be_to_uint(bytes: m_Info.m_aLength);
298 }
299
300 unsigned MapSize() const
301 {
302 return bytes_be_to_uint(bytes: m_Info.m_aMapSize);
303 }
304
305 bool operator<(const CDemoItem &Other) const
306 {
307 if(!str_comp(a: Other.m_aFilename, b: ".."))
308 return false;
309 if(!str_comp(a: m_aFilename, b: ".."))
310 return true;
311 if(m_IsDir && !Other.m_IsDir)
312 return true;
313 if(!m_IsDir && Other.m_IsDir)
314 return false;
315
316 const CDemoItem &Left = g_Config.m_BrDemoSortOrder ? Other : *this;
317 const CDemoItem &Right = g_Config.m_BrDemoSortOrder ? *this : Other;
318
319 if(g_Config.m_BrDemoSort == SORT_DEMONAME)
320 return str_comp_filenames(a: Left.m_aFilename, b: Right.m_aFilename) < 0;
321 if(g_Config.m_BrDemoSort == SORT_DATE)
322 return Left.m_Date < Right.m_Date;
323
324 if(!Other.m_InfosLoaded)
325 return m_InfosLoaded;
326 if(!m_InfosLoaded)
327 return !Other.m_InfosLoaded;
328
329 if(g_Config.m_BrDemoSort == SORT_MARKERS)
330 return Left.NumMarkers() < Right.NumMarkers();
331 if(g_Config.m_BrDemoSort == SORT_LENGTH)
332 return Left.Length() < Right.Length();
333
334 // Unknown sort
335 return true;
336 }
337 };
338
339 char m_aCurrentDemoFolder[IO_MAX_PATH_LENGTH];
340 char m_aCurrentDemoSelectionName[IO_MAX_PATH_LENGTH];
341 CLineInputBuffered<IO_MAX_PATH_LENGTH> m_DemoRenameInput;
342 CLineInputBuffered<IO_MAX_PATH_LENGTH> m_DemoSliceInput;
343 CLineInputBuffered<IO_MAX_PATH_LENGTH> m_DemoSearchInput;
344#if defined(CONF_VIDEORECORDER)
345 CLineInputBuffered<IO_MAX_PATH_LENGTH> m_DemoRenderInput;
346#endif
347 int m_DemolistSelectedIndex;
348 bool m_DemolistSelectedReveal = false;
349 int m_DemolistStorageType;
350 bool m_DemolistMultipleStorages = false;
351 int m_Speed = 4;
352 bool m_StartPaused = false;
353
354 std::chrono::nanoseconds m_DemoPopulateStartTime{0};
355
356 void DemolistOnUpdate(bool Reset);
357 void DemolistSelectNeighbor();
358 static int DemolistFetchCallback(const CFsFileInfo *pInfo, int IsDir, int StorageType, void *pUser);
359
360 // friends
361 class CFriendItem
362 {
363 char m_aName[MAX_NAME_LENGTH];
364 char m_aClan[MAX_CLAN_LENGTH];
365 const CServerInfo *m_pServerInfo;
366 int m_FriendState;
367 bool m_IsPlayer;
368 bool m_IsAfk;
369 // skin info 0.6
370 char m_aSkin[MAX_SKIN_LENGTH];
371 bool m_CustomSkinColors;
372 int m_CustomSkinColorBody;
373 int m_CustomSkinColorFeet;
374 // skin info 0.7
375 char m_aaSkin7[protocol7::NUM_SKINPARTS][protocol7::MAX_SKIN_LENGTH];
376 bool m_aUseCustomSkinColor7[protocol7::NUM_SKINPARTS];
377 int m_aCustomSkinColor7[protocol7::NUM_SKINPARTS];
378
379 public:
380 CFriendItem(const CFriendInfo *pFriendInfo) :
381 m_pServerInfo(nullptr),
382 m_IsPlayer(false),
383 m_IsAfk(false),
384 m_CustomSkinColors(false),
385 m_CustomSkinColorBody(0),
386 m_CustomSkinColorFeet(0)
387 {
388 str_copy(dst&: m_aName, src: pFriendInfo->m_aName);
389 str_copy(dst&: m_aClan, src: pFriendInfo->m_aClan);
390 m_FriendState = m_aName[0] == '\0' ? IFriends::FRIEND_CLAN : IFriends::FRIEND_PLAYER;
391 m_aSkin[0] = '\0';
392 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
393 {
394 m_aaSkin7[Part][0] = '\0';
395 m_aUseCustomSkinColor7[Part] = false;
396 m_aCustomSkinColor7[Part] = 0;
397 }
398 }
399 CFriendItem(const CServerInfo::CClient &CurrentClient, const CServerInfo *pServerInfo) :
400 m_pServerInfo(pServerInfo),
401 m_FriendState(CurrentClient.m_FriendState),
402 m_IsPlayer(CurrentClient.m_Player),
403 m_IsAfk(CurrentClient.m_Afk),
404 m_CustomSkinColors(CurrentClient.m_CustomSkinColors),
405 m_CustomSkinColorBody(CurrentClient.m_CustomSkinColorBody),
406 m_CustomSkinColorFeet(CurrentClient.m_CustomSkinColorFeet)
407 {
408 str_copy(dst&: m_aName, src: CurrentClient.m_aName);
409 str_copy(dst&: m_aClan, src: CurrentClient.m_aClan);
410 str_copy(dst&: m_aSkin, src: CurrentClient.m_aSkin);
411 for(int Part = 0; Part < protocol7::NUM_SKINPARTS; Part++)
412 {
413 str_copy(dst&: m_aaSkin7[Part], src: CurrentClient.m_aaSkin7[Part]);
414 m_aUseCustomSkinColor7[Part] = CurrentClient.m_aUseCustomSkinColor7[Part];
415 m_aCustomSkinColor7[Part] = CurrentClient.m_aCustomSkinColor7[Part];
416 }
417 }
418
419 const char *Name() const { return m_aName; }
420 const char *Clan() const { return m_aClan; }
421 const CServerInfo *ServerInfo() const { return m_pServerInfo; }
422 int FriendState() const { return m_FriendState; }
423 bool IsPlayer() const { return m_IsPlayer; }
424 bool IsAfk() const { return m_IsAfk; }
425 // 0.6 skin
426 const char *Skin() const { return m_aSkin; }
427 bool CustomSkinColors() const { return m_CustomSkinColors; }
428 int CustomSkinColorBody() const { return m_CustomSkinColorBody; }
429 int CustomSkinColorFeet() const { return m_CustomSkinColorFeet; }
430 // 0.7 skin
431 const char *Skin7(int Part) const { return m_aaSkin7[Part]; }
432 bool UseCustomSkinColor7(int Part) const { return m_aUseCustomSkinColor7[Part]; }
433 int CustomSkinColor7(int Part) const { return m_aCustomSkinColor7[Part]; }
434
435 const void *ListItemId() const { return &m_aName; }
436 const void *RemoveButtonId() const { return &m_FriendState; }
437 const void *CommunityTooltipId() const { return &m_IsPlayer; }
438 const void *SkinTooltipId() const { return &m_aSkin; }
439
440 bool operator<(const CFriendItem &Other) const
441 {
442 const int Result = str_comp_nocase(a: m_aName, b: Other.m_aName);
443 return Result < 0 || (Result == 0 && str_comp_nocase(a: m_aClan, b: Other.m_aClan) < 0);
444 }
445 };
446
447 enum
448 {
449 FRIEND_PLAYER_ON = 0,
450 FRIEND_CLAN_ON,
451 FRIEND_OFF,
452 NUM_FRIEND_TYPES
453 };
454 std::vector<CFriendItem> m_avFriends[NUM_FRIEND_TYPES];
455 const CFriendItem *m_pRemoveFriend = nullptr;
456
457 // found in menus.cpp
458 void Render();
459 void RenderPopupFullscreen(CUIRect Screen);
460 void RenderPopupConnecting(CUIRect Screen);
461 void RenderPopupLoading(CUIRect Screen);
462#if defined(CONF_VIDEORECORDER)
463 void PopupConfirmDemoReplaceVideo();
464#endif
465 void RenderMenubar(CUIRect Box, IClient::EClientState ClientState);
466 void RenderNews(CUIRect MainView);
467 static void ConchainBackgroundEntities(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
468 static void ConchainUpdateMusicState(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
469 void UpdateMusicState();
470
471 // found in menus_demo.cpp
472 vec2 m_DemoControlsPositionOffset = vec2(0.0f, 0.0f);
473 bool m_PausedBeforeSeeking;
474 float m_PrevSeekAmount;
475 float m_LastPauseChange = -1.0f;
476 float m_LastSpeedChange = -1.0f;
477 static constexpr int DEFAULT_SKIP_DURATION_INDEX = 3;
478 int m_SkipDurationIndex = DEFAULT_SKIP_DURATION_INDEX;
479 static bool DemoFilterChat(const void *pData, int Size, void *pUser);
480 bool FetchHeader(CDemoItem &Item);
481 void FetchAllHeaders();
482 void HandleDemoSeeking(float PositionToSeek, float TimeToSeek);
483 void RenderDemoPlayer(CUIRect MainView);
484 void RenderDemoPlayerSliceSavePopup(CUIRect MainView);
485 bool m_DemoBrowserListInitialized = false;
486 void RenderDemoBrowser(CUIRect MainView);
487 void RenderDemoBrowserList(CUIRect ListView, bool &WasListboxItemActivated);
488 void RenderDemoBrowserDetails(CUIRect DetailsView);
489 void RenderDemoBrowserButtons(CUIRect ButtonsView, bool WasListboxItemActivated);
490 void PopupConfirmPlayDemo();
491 void PopupConfirmDeleteDemo();
492 void PopupConfirmDeleteFolder();
493 static void ConchainDemoPlay(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
494 static void ConchainDemoSpeed(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
495
496 // found in menus_ingame.cpp
497 STextContainerIndex m_MotdTextContainerIndex;
498 void RenderGame(CUIRect MainView);
499 void PopupConfirmDisconnect();
500 void PopupConfirmDisconnectDummy();
501 void PopupConfirmDiscardTouchControlsChanges();
502 void PopupConfirmResetTouchControls();
503 void PopupConfirmImportTouchControlsClipboard();
504 void PopupConfirmDeleteButton();
505 void PopupCancelDeselectButton();
506 void PopupConfirmSelectedNotVisible();
507 void PopupConfirmChangeSelectedButton();
508 void PopupCancelChangeSelectedButton();
509 void PopupConfirmTurnOffEditor();
510 void PopupConfirmOpenWiki();
511 void RenderPlayers(CUIRect MainView);
512 void RenderServerInfo(CUIRect MainView);
513 void RenderServerInfoMotd(CUIRect Motd);
514 void RenderServerControl(CUIRect MainView);
515 bool RenderServerControlKick(CUIRect MainView, bool FilterSpectators, bool UpdateScroll);
516 bool RenderServerControlServer(CUIRect MainView, bool UpdateScroll);
517 void RenderIngameHint();
518
519 // found in menus_browser.cpp
520 int m_SelectedIndex;
521 bool m_ServerBrowserShouldRevealSelection;
522 std::vector<CUIElement *> m_avpServerBrowserUiElements[IServerBrowser::NUM_TYPES];
523 std::vector<char> m_vServerbrowserElementIds[IServerBrowser::NUM_TYPES];
524 void RenderServerbrowserServerList(CUIRect View, bool &WasListboxItemActivated);
525 void RenderServerbrowserStatusBox(CUIRect StatusBox, bool WasListboxItemActivated);
526 void PopupConfirmSwitchServer();
527 void RenderServerbrowserFilters(CUIRect View);
528 void ResetServerbrowserFilters();
529 void RenderServerbrowserDDNetFilter(CUIRect View,
530 IFilterList &Filter,
531 float ItemHeight, int MaxItems, int ItemsPerRow,
532 CScrollRegion &ScrollRegion, std::vector<unsigned char> &vItemIds,
533 bool UpdateCommunityCacheOnChange,
534 const std::function<const char *(int ItemIndex)> &GetItemName,
535 const std::function<void(int ItemIndex, CUIRect Item, const void *pItemId, bool Active)> &RenderItem);
536 void RenderServerbrowserCommunitiesFilter(CUIRect View);
537 void RenderServerbrowserCountriesFilter(CUIRect View);
538 void RenderServerbrowserTypesFilter(CUIRect View);
539 struct SPopupCountrySelectionContext
540 {
541 CMenus *m_pMenus;
542 int m_Selection;
543 bool m_New;
544 };
545 static CUi::EPopupMenuFunctionResult PopupCountrySelection(void *pContext, CUIRect View, bool Active);
546 void RenderServerbrowserInfo(CUIRect View);
547 void RenderServerbrowserInfoScoreboard(CUIRect View, const CServerInfo *pSelectedServer);
548 void RenderServerbrowserFriends(CUIRect View);
549 void FriendlistOnUpdate();
550 void PopupConfirmRemoveFriend();
551 void RenderServerbrowserTabBar(CUIRect TabBar);
552 void RenderServerbrowserToolBox(CUIRect ToolBox);
553 void RenderServerbrowser(CUIRect MainView);
554 template<typename F>
555 bool PrintHighlighted(const char *pName, F &&PrintFn);
556 CTeeRenderInfo GetTeeRenderInfo(vec2 Size, const char *pSkinName, bool CustomSkinColors, int CustomSkinColorBody, int CustomSkinColorFeet) const;
557 static void ConchainFriendlistUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
558 static void ConchainFavoritesUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
559 static void ConchainCommunitiesUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
560 static void ConchainUiPageUpdate(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData);
561 void UpdateCommunityCache(bool Force);
562
563 // found in menus_settings.cpp
564 void RenderSettings(CUIRect MainView);
565 bool RenderHslaScrollbars(CUIRect *pRect, unsigned int *pColor, bool Alpha, float DarkestLight);
566
567 // found in menus_settings_assets.cpp
568 void RenderSettingsAssets(CUIRect MainView);
569
570 // found in menus_settings_appearance.cpp
571 void RenderSettingsAppearance(CUIRect MainView);
572 void DoLaserPreview(const CUIRect *pRect, ColorHSLA OutlineColor, ColorHSLA InnerColor, int LaserType);
573
574 // found in menus_settings_controls.cpp
575 // TODO: Change PopupConfirm to avoid using a function pointer to a CMenus
576 // member function, to move this function to CMenusSettingsControls
577 void ResetSettingsControls();
578
579 // found in menus_settings_credits.cpp
580 void RenderSettingsCredits(CUIRect MainView);
581
582 // found in menus_settings_ddnet.cpp
583 void RenderSettingsDDNet(CUIRect MainView);
584
585 // found in menus_settings_general.cpp
586 void RenderSettingsGeneral(CUIRect MainView);
587 void RenderThemeSelection(CUIRect MainView);
588
589 // found in menus_settings_graphics.cpp
590 void RenderSettingsGraphics(CUIRect MainView);
591
592 // found in menus_settings_language.cpp
593 void RenderLanguageSettings(CUIRect MainView);
594 bool RenderLanguageSelection(CUIRect MainView);
595
596 // found in menus_settings_player.cpp
597 void RenderSettingsPlayer(CUIRect MainView);
598
599 // found in menus_settings_sound.cpp
600 void RenderSettingsSound(CUIRect MainView);
601
602 // found in menus_settings_tee.cpp
603 void RenderSettingsTee(CUIRect MainView);
604 bool m_SkinListScrollToSelected = false;
605
606 // found in menus_settings_tee7.cpp
607 void RenderSettingsTee7(CUIRect MainView);
608 void PopupConfirmDeleteSkin7();
609 void RenderSettingsTeeCustom7(CUIRect MainView);
610 void RenderSkinSelection7(CUIRect MainView);
611 void RenderSkinPartSelection7(CUIRect MainView);
612 bool m_CustomSkinMenu = false;
613 int m_TeePartSelected = protocol7::SKINPART_BODY;
614 const CSkins7::CSkin *m_pSelectedSkin = nullptr;
615 int m_SelectedSkinIndex7 = -1;
616 int m_DeletedSkinIndex7 = -1;
617 CLineInputBuffered<protocol7::MAX_SKIN_ARRAY_SIZE, protocol7::MAX_SKIN_LENGTH> m_SkinNameInput;
618 bool m_SkinPartListNeedsUpdate = false;
619
620 std::vector<CButtonContainer> m_vButtonContainersNamePlateShow = {{}, {}, {}, {}};
621 std::vector<CButtonContainer> m_vButtonContainersNamePlateKeyPresses = {{}, {}, {}, {}};
622 std::vector<CButtonContainer> m_vButtonContainersAntiPingPlayers = {{}, {}, {}};
623
624 class CMapListItem
625 {
626 public:
627 char m_aFilename[IO_MAX_PATH_LENGTH];
628 bool m_IsDirectory;
629 };
630 class CPopupMapPickerContext
631 {
632 public:
633 std::vector<CMapListItem> m_vMaps;
634 char m_aCurrentMapFolder[IO_MAX_PATH_LENGTH] = "";
635 static int MapListFetchCallback(const CFsFileInfo *pInfo, int IsDir, int StorageType, void *pUser);
636 void MapListPopulate();
637 CMenus *m_pMenus;
638 int m_Selection;
639 };
640
641 static bool CompareFilenameAscending(const CMapListItem Lhs, const CMapListItem Rhs)
642 {
643 if(str_comp(a: Rhs.m_aFilename, b: "..") == 0)
644 return false;
645 if(str_comp(a: Lhs.m_aFilename, b: "..") == 0)
646 return true;
647 if(Lhs.m_IsDirectory != Rhs.m_IsDirectory)
648 return Lhs.m_IsDirectory;
649 return str_comp_filenames(a: Lhs.m_aFilename, b: Rhs.m_aFilename) < 0;
650 }
651
652 static CUi::EPopupMenuFunctionResult PopupMapPicker(void *pContext, CUIRect View, bool Active);
653
654 void SetNeedSendInfo();
655 void UpdateColors();
656
657 IGraphics::CTextureHandle m_TextureBlob;
658
659public:
660 void RenderBackground();
661
662 CMenus();
663 int Sizeof() const override { return sizeof(*this); }
664
665 void RenderLoadingDirect(const char *pCaption, const char *pContent, std::optional<float> Progress);
666 void RenderLoading(const char *pCaption, const char *pContent, int IncreaseCounter);
667 void FinishLoading();
668
669 bool IsInit() const { return m_IsInit; }
670
671 bool IsActive() const { return m_MenuActive; }
672 void SetActive(bool Active);
673
674 void OnInterfacesInit(CGameClient *pClient) override;
675 void OnInit() override;
676
677 void OnStateChange(int NewState, int OldState) override;
678 void OnWindowResize() override;
679 void OnRender() override;
680 bool OnInput(const IInput::CEvent &Event) override;
681 bool OnCursorMove(float x, float y, IInput::ECursorType CursorType) override;
682 void OnShutdown() override;
683
684 enum
685 {
686 PAGE_NEWS = 1,
687 PAGE_GAME,
688 PAGE_PLAYERS,
689 PAGE_SERVER_INFO,
690 PAGE_CALLVOTE,
691 PAGE_INTERNET,
692 PAGE_LAN,
693 PAGE_FAVORITES,
694 PAGE_FAVORITE_COMMUNITY_1,
695 PAGE_FAVORITE_COMMUNITY_2,
696 PAGE_FAVORITE_COMMUNITY_3,
697 PAGE_FAVORITE_COMMUNITY_4,
698 PAGE_FAVORITE_COMMUNITY_5,
699 PAGE_DEMOS,
700 PAGE_SETTINGS,
701 PAGE_NETWORK,
702 PAGE_GHOST,
703
704 PAGE_LENGTH,
705 };
706
707 enum
708 {
709 SETTINGS_LANGUAGE = 0,
710 SETTINGS_GENERAL,
711 SETTINGS_PLAYER,
712 SETTINGS_TEE,
713 SETTINGS_APPEARANCE,
714 SETTINGS_CONTROLS,
715 SETTINGS_GRAPHICS,
716 SETTINGS_SOUND,
717 SETTINGS_DDNET,
718 SETTINGS_ASSETS,
719 SETTINGS_CREDITS,
720
721 SETTINGS_LENGTH,
722 };
723
724 enum
725 {
726 BIG_TAB_NEWS = 0,
727 BIG_TAB_INTERNET,
728 BIG_TAB_LAN,
729 BIG_TAB_FAVORITES,
730 BIT_TAB_FAVORITE_COMMUNITY_1,
731 BIT_TAB_FAVORITE_COMMUNITY_2,
732 BIT_TAB_FAVORITE_COMMUNITY_3,
733 BIT_TAB_FAVORITE_COMMUNITY_4,
734 BIT_TAB_FAVORITE_COMMUNITY_5,
735 BIG_TAB_DEMOS,
736
737 BIG_TAB_LENGTH,
738 };
739
740 enum
741 {
742 SMALL_TAB_HOME = 0,
743 SMALL_TAB_QUIT,
744 SMALL_TAB_SETTINGS,
745 SMALL_TAB_EDITOR,
746 SMALL_TAB_DEMOBUTTON,
747 SMALL_TAB_SERVER,
748 SMALL_TAB_BROWSER_FILTER,
749 SMALL_TAB_BROWSER_INFO,
750 SMALL_TAB_BROWSER_FRIENDS,
751
752 SMALL_TAB_LENGTH,
753 };
754
755 SUIAnimator m_aAnimatorsBigPage[BIG_TAB_LENGTH];
756 SUIAnimator m_aAnimatorsSmallPage[SMALL_TAB_LENGTH];
757 SUIAnimator m_aAnimatorsSettingsTab[SETTINGS_LENGTH];
758
759 // DDRace
760 int DoButton_CheckBox_Tristate(const void *pId, const char *pText, TRISTATE Checked, const CUIRect *pRect);
761 std::vector<CDemoItem> m_vDemos;
762 std::vector<CDemoItem *> m_vpFilteredDemos;
763 void DemolistPopulate();
764 void RefreshFilteredDemos();
765 void DemoSeekTick(IDemoPlayer::ETickOffset TickOffset);
766 bool m_Dummy;
767
768 const char *GetCurrentDemoFolder() const { return m_aCurrentDemoFolder; }
769
770 // Ghost
771 struct CGhostItem
772 {
773 char m_aFilename[IO_MAX_PATH_LENGTH];
774 char m_aPlayer[MAX_NAME_LENGTH];
775
776 bool m_Failed;
777 int m_Time;
778 int m_Slot;
779 bool m_Own;
780 time_t m_Date;
781
782 CGhostItem() :
783 m_Slot(-1), m_Own(false) { m_aFilename[0] = 0; }
784
785 bool Active() const { return m_Slot != -1; }
786 bool HasFile() const { return m_aFilename[0]; }
787 };
788
789 enum
790 {
791 GHOST_SORT_NONE = -1,
792 GHOST_SORT_NAME,
793 GHOST_SORT_TIME,
794 GHOST_SORT_DATE,
795 };
796
797 std::vector<CGhostItem> m_vGhosts;
798
799 std::chrono::nanoseconds m_GhostPopulateStartTime{0};
800
801 void GhostlistPopulate();
802 CGhostItem *GetOwnGhost();
803 void UpdateOwnGhost(CGhostItem Item);
804 void DeleteGhostItem(int Index);
805 void SortGhostlist();
806
807 bool CanDisplayWarning() const;
808
809 void PopupWarning(const char *pTopic, const char *pBody, const char *pButton, std::chrono::nanoseconds Duration);
810
811 std::chrono::nanoseconds m_PopupWarningLastTime;
812 std::chrono::nanoseconds m_PopupWarningDuration;
813
814 int m_DemoPlayerState;
815
816 enum
817 {
818 POPUP_NONE = 0,
819 POPUP_MESSAGE, // generic message popup (one button)
820 POPUP_CONFIRM, // generic confirmation popup (two buttons)
821 POPUP_FIRST_LAUNCH,
822 POPUP_JOIN_TUTORIAL,
823 POPUP_POINTS,
824 POPUP_DISCONNECTED,
825 POPUP_LANGUAGE,
826 POPUP_RENAME_DEMO,
827 POPUP_RENDER_DEMO,
828 POPUP_RENDER_DONE,
829 POPUP_PASSWORD,
830 POPUP_QUIT,
831 POPUP_RESTART,
832 POPUP_WARNING,
833 POPUP_SAVE_SKIN,
834 };
835
836 enum
837 {
838 // demo player states
839 DEMOPLAYER_NONE = 0,
840 DEMOPLAYER_SLICE_SAVE,
841 };
842
843 void SetMenuPage(int NewPage);
844 void RefreshBrowserTab(bool Force);
845 void ForceRefreshLanPage();
846 void SetShowStart(bool ShowStart);
847 void ShowQuitPopup();
848 void JoinTutorial();
849 void Connect(const char *pAddress);
850
851private:
852 CCommunityIcons m_CommunityIcons;
853 CMenusIngameTouchControls m_MenusIngameTouchControls;
854 friend CMenusIngameTouchControls;
855 CMenusSettingsControls m_MenusSettingsControls;
856 friend CMenusSettingsControls;
857 CMenusStart m_MenusStart;
858
859 static int GhostlistFetchCallback(const CFsFileInfo *pInfo, int IsDir, int StorageType, void *pUser);
860
861 // found in menus_ingame.cpp
862 void RenderInGameNetwork(CUIRect MainView);
863 void RenderGhost(CUIRect MainView);
864};
865#endif
866