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