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
4#include "menus.h"
5
6#include <base/color.h>
7#include <base/dbg.h>
8#include <base/fs.h>
9#include <base/log.h>
10#include <base/str.h>
11#include <base/time.h>
12#include <base/vmath.h>
13
14#include <engine/client.h>
15#include <engine/client/updater.h>
16#include <engine/config.h>
17#include <engine/editor.h>
18#include <engine/font_icons.h>
19#include <engine/friends.h>
20#include <engine/gfx/image_manipulation.h>
21#include <engine/graphics.h>
22#include <engine/keys.h>
23#include <engine/serverbrowser.h>
24#include <engine/shared/config.h>
25#include <engine/storage.h>
26#include <engine/textrender.h>
27
28#include <generated/client_data.h>
29#include <generated/protocol.h>
30
31#include <game/client/animstate.h>
32#include <game/client/components/binds.h>
33#include <game/client/components/console.h>
34#include <game/client/components/key_binder.h>
35#include <game/client/components/menu_background.h>
36#include <game/client/components/sounds.h>
37#include <game/client/gameclient.h>
38#include <game/client/ui_listbox.h>
39#include <game/localization.h>
40
41#include <algorithm>
42#include <chrono>
43#include <cmath>
44#include <vector>
45
46using namespace std::chrono_literals;
47
48ColorRGBA CMenus::ms_GuiColor;
49ColorRGBA CMenus::ms_ColorTabbarInactiveOutgame;
50ColorRGBA CMenus::ms_ColorTabbarActiveOutgame;
51ColorRGBA CMenus::ms_ColorTabbarHoverOutgame;
52ColorRGBA CMenus::ms_ColorTabbarInactive;
53ColorRGBA CMenus::ms_ColorTabbarActive = ColorRGBA(0, 0, 0, 0.5f);
54ColorRGBA CMenus::ms_ColorTabbarHover;
55ColorRGBA CMenus::ms_ColorTabbarInactiveIngame;
56ColorRGBA CMenus::ms_ColorTabbarActiveIngame;
57ColorRGBA CMenus::ms_ColorTabbarHoverIngame;
58
59float CMenus::ms_ButtonHeight = 25.0f;
60float CMenus::ms_ListheaderHeight = 17.0f;
61
62CMenus::CMenus()
63{
64 m_Popup = POPUP_NONE;
65 m_MenuPage = 0;
66 m_GamePage = PAGE_GAME;
67
68 m_NeedRestartGraphics = false;
69 m_NeedRestartSound = false;
70 m_NeedSendinfo = false;
71 m_NeedSendDummyinfo = false;
72 m_MenuActive = true;
73 m_ShowStart = true;
74
75 str_copy(dst&: m_aCurrentDemoFolder, src: "demos");
76 m_DemolistStorageType = IStorage::TYPE_ALL;
77
78 m_DemoPlayerState = DEMOPLAYER_NONE;
79 m_Dummy = false;
80
81 for(SUIAnimator &Animator : m_aAnimatorsSettingsTab)
82 {
83 Animator.m_YOffset = -2.5f;
84 Animator.m_HOffset = 5.0f;
85 Animator.m_WOffset = 5.0f;
86 Animator.m_RepositionLabel = true;
87 }
88
89 for(SUIAnimator &Animator : m_aAnimatorsBigPage)
90 {
91 Animator.m_YOffset = -5.0f;
92 Animator.m_HOffset = 5.0f;
93 }
94
95 for(SUIAnimator &Animator : m_aAnimatorsSmallPage)
96 {
97 Animator.m_YOffset = -2.5f;
98 Animator.m_HOffset = 2.5f;
99 }
100
101 m_PasswordInput.SetBuffer(pStr: g_Config.m_Password, MaxSize: sizeof(g_Config.m_Password));
102 m_PasswordInput.SetHidden(true);
103}
104
105int CMenus::DoButton_Toggle(const void *pId, int Checked, const CUIRect *pRect, bool Active, const unsigned Flags)
106{
107 Graphics()->TextureSet(Texture: g_pData->m_aImages[IMAGE_GUIBUTTONS].m_Id);
108 Graphics()->QuadsBegin();
109 if(!Active)
110 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 0.5f);
111 Graphics()->SelectSprite(Id: Checked ? SPRITE_GUIBUTTON_ON : SPRITE_GUIBUTTON_OFF);
112 IGraphics::CQuadItem QuadItem(pRect->x, pRect->y, pRect->w, pRect->h);
113 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
114 if(Ui()->HotItem() == pId && Active)
115 {
116 Graphics()->SelectSprite(Id: SPRITE_GUIBUTTON_HOVER);
117 QuadItem = IGraphics::CQuadItem(pRect->x, pRect->y, pRect->w, pRect->h);
118 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
119 }
120 Graphics()->QuadsEnd();
121
122 return Active ? Ui()->DoButtonLogic(pId, Checked, pRect, Flags) : 0;
123}
124
125int CMenus::DoButton_Menu(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, const unsigned Flags, const char *pImageName, int Corners, float Rounding, float FontFactor, ColorRGBA Color, const void *pImageHotId)
126{
127 CUIRect Text = *pRect;
128
129 if(Checked)
130 Color = ColorRGBA(0.6f, 0.6f, 0.6f, 0.5f);
131 Color.a *= Ui()->ButtonColorMul(pId: pButtonContainer);
132
133 pRect->Draw(Color, Corners, Rounding);
134
135 if(pImageName)
136 {
137 CUIRect Image;
138 pRect->VSplitRight(Cut: pRect->h * BUTTON_IMAGE_WIDTH_FACTOR, pLeft: &Text, pRight: &Image); // always correct ratio for image
139
140 // render image
141 const CMenuImage *pImage = FindMenuImage(pName: pImageName);
142 if(pImage)
143 {
144 const bool ImageHot = Ui()->HotItem() == pButtonContainer || (pImageHotId != nullptr && Ui()->HotItem() == pImageHotId);
145 Graphics()->TextureSet(Texture: ImageHot ? pImage->m_OrgTexture : pImage->m_GreyTexture);
146 Graphics()->WrapClamp();
147 Graphics()->QuadsBegin();
148 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
149 IGraphics::CQuadItem QuadItem(Image.x, Image.y, Image.w, Image.h);
150 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
151 Graphics()->QuadsEnd();
152 Graphics()->WrapNormal();
153 }
154 }
155
156 Text.HMargin(Cut: pRect->h >= 20.0f ? 2.0f : 1.0f, pOtherRect: &Text);
157 Text.HMargin(Cut: (Text.h * FontFactor) / 2.0f, pOtherRect: &Text);
158 Ui()->DoLabel(pRect: &Text, pText, Size: Text.h * CUi::ms_FontmodHeight, Align: TEXTALIGN_MC);
159
160 return Ui()->DoButtonLogic(pId: pButtonContainer, Checked, pRect, Flags);
161}
162
163int CMenus::DoButton_MenuTab(CButtonContainer *pButtonContainer, const char *pText, int Checked, const CUIRect *pRect, int Corners, SUIAnimator *pAnimator, const ColorRGBA *pDefaultColor, const ColorRGBA *pActiveColor, const ColorRGBA *pHoverColor, float EdgeRounding, const CCommunityIcon *pCommunityIcon)
164{
165 const bool MouseInside = Ui()->HotItem() == pButtonContainer;
166 CUIRect Rect = *pRect;
167
168 if(pAnimator != nullptr)
169 {
170 auto Time = time_get_nanoseconds();
171
172 if(pAnimator->m_Time + 100ms < Time)
173 {
174 pAnimator->m_Value = pAnimator->m_Active ? 1 : 0;
175 pAnimator->m_Time = Time;
176 }
177
178 pAnimator->m_Active = Checked || MouseInside;
179
180 if(pAnimator->m_Active)
181 pAnimator->m_Value = std::clamp<float>(val: pAnimator->m_Value + (Time - pAnimator->m_Time).count() / (double)std::chrono::nanoseconds(100ms).count(), lo: 0, hi: 1);
182 else
183 pAnimator->m_Value = std::clamp<float>(val: pAnimator->m_Value - (Time - pAnimator->m_Time).count() / (double)std::chrono::nanoseconds(100ms).count(), lo: 0, hi: 1);
184
185 Rect.w += pAnimator->m_Value * pAnimator->m_WOffset;
186 Rect.h += pAnimator->m_Value * pAnimator->m_HOffset;
187 Rect.x += pAnimator->m_Value * pAnimator->m_XOffset;
188 Rect.y += pAnimator->m_Value * pAnimator->m_YOffset;
189
190 pAnimator->m_Time = Time;
191 }
192
193 if(Checked)
194 {
195 ColorRGBA ColorMenuTab = ms_ColorTabbarActive;
196 if(pActiveColor)
197 ColorMenuTab = *pActiveColor;
198
199 Rect.Draw(Color: ColorMenuTab, Corners, Rounding: EdgeRounding);
200 }
201 else
202 {
203 if(MouseInside)
204 {
205 ColorRGBA HoverColorMenuTab = ms_ColorTabbarHover;
206 if(pHoverColor)
207 HoverColorMenuTab = *pHoverColor;
208
209 Rect.Draw(Color: HoverColorMenuTab, Corners, Rounding: EdgeRounding);
210 }
211 else
212 {
213 ColorRGBA ColorMenuTab = ms_ColorTabbarInactive;
214 if(pDefaultColor)
215 ColorMenuTab = *pDefaultColor;
216
217 Rect.Draw(Color: ColorMenuTab, Corners, Rounding: EdgeRounding);
218 }
219 }
220
221 if(pAnimator != nullptr)
222 {
223 if(pAnimator->m_RepositionLabel)
224 {
225 Rect.x += Rect.w - pRect->w + Rect.x - pRect->x;
226 Rect.y += Rect.h - pRect->h + Rect.y - pRect->y;
227 }
228
229 if(!pAnimator->m_ScaleLabel)
230 {
231 Rect.w = pRect->w;
232 Rect.h = pRect->h;
233 }
234 }
235
236 if(pCommunityIcon)
237 {
238 CUIRect CommunityIcon;
239 Rect.Margin(Cut: 2.0f, pOtherRect: &CommunityIcon);
240 m_CommunityIcons.Render(pIcon: pCommunityIcon, Rect: CommunityIcon, Active: true);
241 }
242 else
243 {
244 CUIRect Label;
245 Rect.HMargin(Cut: 2.0f, pOtherRect: &Label);
246 Ui()->DoLabel(pRect: &Label, pText, Size: Label.h * CUi::ms_FontmodHeight, Align: TEXTALIGN_MC);
247 }
248
249 return Ui()->DoButtonLogic(pId: pButtonContainer, Checked, pRect, Flags: BUTTONFLAG_LEFT);
250}
251
252int CMenus::DoButton_GridHeader(const void *pId, const char *pText, int Checked, const CUIRect *pRect, int Align)
253{
254 if(Checked == 2)
255 pRect->Draw(Color: ColorRGBA(1, 0.98f, 0.5f, 0.55f), Corners: IGraphics::CORNER_T, Rounding: 5.0f);
256 else if(Checked)
257 pRect->Draw(Color: ColorRGBA(1, 1, 1, 0.5f), Corners: IGraphics::CORNER_T, Rounding: 5.0f);
258
259 CUIRect Temp;
260 pRect->VMargin(Cut: 5.0f, pOtherRect: &Temp);
261 Ui()->DoLabel(pRect: &Temp, pText, Size: pRect->h * CUi::ms_FontmodHeight, Align);
262 return Ui()->DoButtonLogic(pId, Checked, pRect, Flags: BUTTONFLAG_LEFT);
263}
264
265int CMenus::DoButton_Favorite(const void *pButtonId, const void *pParentId, bool Checked, const CUIRect *pRect)
266{
267 if(Checked || (pParentId != nullptr && Ui()->HotItem() == pParentId) || Ui()->HotItem() == pButtonId)
268 {
269 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
270 TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGNMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE);
271 const float Alpha = Ui()->HotItem() == pButtonId ? 0.2f : 0.0f;
272 TextRender()->TextColor(Color: Checked ? ColorRGBA(1.0f, 0.85f, 0.3f, 0.8f + Alpha) : ColorRGBA(0.5f, 0.5f, 0.5f, 0.8f + Alpha));
273 SLabelProperties Props;
274 Props.m_MaxWidth = pRect->w;
275 Ui()->DoLabel(pRect, pText: FontIcon::STAR, Size: 12.0f, Align: TEXTALIGN_MC, LabelProps: Props);
276 TextRender()->TextColor(Color: TextRender()->DefaultTextColor());
277 TextRender()->SetRenderFlags(0);
278 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
279 }
280 return Ui()->DoButtonLogic(pId: pButtonId, Checked: 0, pRect, Flags: BUTTONFLAG_LEFT);
281}
282
283int CMenus::DoButton_CheckBox_Common(const void *pId, const char *pText, const char *pBoxText, const CUIRect *pRect, const unsigned Flags)
284{
285 CUIRect Box, Label;
286 pRect->VSplitLeft(Cut: pRect->h, pLeft: &Box, pRight: &Label);
287 Label.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Label);
288
289 Box.Margin(Cut: 2.0f, pOtherRect: &Box);
290 Box.Draw(Color: ColorRGBA(1, 1, 1, 0.25f * Ui()->ButtonColorMul(pId)), Corners: IGraphics::CORNER_ALL, Rounding: 3.0f);
291
292 const bool Checkable = *pBoxText == 'X';
293 if(Checkable)
294 {
295 TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGNMENT);
296 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
297 Ui()->DoLabel(pRect: &Box, pText: FontIcon::XMARK, Size: Box.h * CUi::ms_FontmodHeight, Align: TEXTALIGN_MC);
298 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
299 }
300 else
301 {
302 Ui()->DoLabel(pRect: &Box, pText: pBoxText, Size: Box.h * CUi::ms_FontmodHeight, Align: TEXTALIGN_MC);
303 }
304
305 TextRender()->SetRenderFlags(0);
306 Ui()->DoLabel(pRect: &Label, pText, Size: Box.h * CUi::ms_FontmodHeight, Align: TEXTALIGN_ML);
307
308 return Ui()->DoButtonLogic(pId, Checked: 0, pRect, Flags);
309}
310
311bool CMenus::DoLine_RadioMenu(CUIRect &View, const char *pLabel, std::vector<CButtonContainer> &vButtonContainers, const std::vector<const char *> &vLabels, const std::vector<int> &vValues, int &Value)
312{
313 dbg_assert(vButtonContainers.size() == vValues.size(), "vButtonContainers and vValues must have the same size");
314 dbg_assert(vButtonContainers.size() == vLabels.size(), "vButtonContainers and vLabels must have the same size");
315 const int N = vButtonContainers.size();
316 const float Spacing = 2.0f;
317 const float ButtonHeight = 20.0f;
318 CUIRect Label, Buttons;
319 View.HSplitTop(Cut: Spacing, pTop: nullptr, pBottom: &View);
320 View.HSplitTop(Cut: ButtonHeight, pTop: &Buttons, pBottom: &View);
321 Buttons.VSplitMid(pLeft: &Label, pRight: &Buttons, Spacing: 10.0f);
322 Buttons.HMargin(Cut: 2.0f, pOtherRect: &Buttons);
323 Ui()->DoLabel(pRect: &Label, pText: pLabel, Size: 13.0f, Align: TEXTALIGN_ML);
324 const float W = Buttons.w / N;
325 bool Pressed = false;
326 for(int i = 0; i < N; ++i)
327 {
328 CUIRect Button;
329 Buttons.VSplitLeft(Cut: W, pLeft: &Button, pRight: &Buttons);
330 int Corner = IGraphics::CORNER_NONE;
331 if(i == 0)
332 Corner = IGraphics::CORNER_L;
333 if(i == N - 1)
334 Corner = IGraphics::CORNER_R;
335 if(DoButton_Menu(pButtonContainer: &vButtonContainers[i], pText: vLabels[i], Checked: vValues[i] == Value, pRect: &Button, Flags: BUTTONFLAG_LEFT, pImageName: nullptr, Corners: Corner))
336 {
337 Pressed = true;
338 Value = vValues[i];
339 }
340 }
341 return Pressed;
342}
343
344ColorHSLA CMenus::DoLine_ColorPicker(CButtonContainer *pResetId, const float LineSize, const float LabelSize, const float BottomMargin, CUIRect *pMainRect, const char *pText, unsigned int *pColorValue, const ColorRGBA DefaultColor, bool CheckBoxSpacing, int *pCheckBoxValue, bool Alpha)
345{
346 CUIRect Section, ColorPickerButton, ResetButton, Label;
347
348 pMainRect->HSplitTop(Cut: LineSize, pTop: &Section, pBottom: pMainRect);
349 pMainRect->HSplitTop(Cut: BottomMargin, pTop: nullptr, pBottom: pMainRect);
350
351 Section.VSplitRight(Cut: 60.0f, pLeft: &Section, pRight: &ResetButton);
352 Section.VSplitRight(Cut: 8.0f, pLeft: &Section, pRight: nullptr);
353 Section.VSplitRight(Cut: Section.h, pLeft: &Section, pRight: &ColorPickerButton);
354 Section.VSplitRight(Cut: 8.0f, pLeft: &Label, pRight: nullptr);
355
356 if(pCheckBoxValue != nullptr)
357 {
358 Label.Margin(Cut: 2.0f, pOtherRect: &Label);
359 if(DoButton_CheckBox(pId: pCheckBoxValue, pText, Checked: *pCheckBoxValue, pRect: &Label))
360 *pCheckBoxValue ^= 1;
361 }
362 else if(CheckBoxSpacing)
363 {
364 Label.VSplitLeft(Cut: Label.h + 5.0f, pLeft: nullptr, pRight: &Label);
365 }
366 if(pCheckBoxValue == nullptr)
367 {
368 Ui()->DoLabel(pRect: &Label, pText, Size: LabelSize, Align: TEXTALIGN_ML);
369 }
370
371 const ColorHSLA PickedColor = DoButton_ColorPicker(pRect: &ColorPickerButton, pHslaColor: pColorValue, Alpha);
372
373 ResetButton.HMargin(Cut: 2.0f, pOtherRect: &ResetButton);
374 if(DoButton_Menu(pButtonContainer: pResetId, pText: Localize(pStr: "Reset"), Checked: 0, pRect: &ResetButton, Flags: BUTTONFLAG_LEFT, pImageName: nullptr, Corners: IGraphics::CORNER_ALL, Rounding: 4.0f, FontFactor: 0.1f, Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f)))
375 {
376 *pColorValue = color_cast<ColorHSLA>(rgb: DefaultColor).Pack(Alpha);
377 }
378
379 return PickedColor;
380}
381
382ColorHSLA CMenus::DoButton_ColorPicker(const CUIRect *pRect, unsigned int *pHslaColor, bool Alpha)
383{
384 ColorHSLA HslaColor = ColorHSLA(*pHslaColor, Alpha);
385
386 ColorRGBA Outline = ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f);
387 Outline.a *= Ui()->ButtonColorMul(pId: pHslaColor);
388
389 CUIRect Rect;
390 pRect->Margin(Cut: 3.0f, pOtherRect: &Rect);
391
392 pRect->Draw(Color: Outline, Corners: IGraphics::CORNER_ALL, Rounding: 4.0f);
393 Rect.Draw(Color: color_cast<ColorRGBA>(hsl: HslaColor), Corners: IGraphics::CORNER_ALL, Rounding: 4.0f);
394
395 if(Ui()->DoButtonLogic(pId: pHslaColor, Checked: 0, pRect, Flags: BUTTONFLAG_LEFT))
396 {
397 m_ColorPickerPopupContext.m_pHslaColor = pHslaColor;
398 m_ColorPickerPopupContext.m_HslaColor = HslaColor;
399 m_ColorPickerPopupContext.m_HsvaColor = color_cast<ColorHSVA>(hsl: HslaColor);
400 m_ColorPickerPopupContext.m_RgbaColor = color_cast<ColorRGBA>(hsv: m_ColorPickerPopupContext.m_HsvaColor);
401 m_ColorPickerPopupContext.m_Alpha = Alpha;
402 Ui()->ShowPopupColorPicker(X: Ui()->MouseX(), Y: Ui()->MouseY(), pContext: &m_ColorPickerPopupContext);
403 }
404 else if(Ui()->IsPopupOpen(pId: &m_ColorPickerPopupContext) && m_ColorPickerPopupContext.m_pHslaColor == pHslaColor)
405 {
406 HslaColor = color_cast<ColorHSLA>(hsv: m_ColorPickerPopupContext.m_HsvaColor);
407 }
408
409 return HslaColor;
410}
411
412int CMenus::DoButton_CheckBoxAutoVMarginAndSet(const void *pId, const char *pText, int *pValue, CUIRect *pRect, float VMargin)
413{
414 CUIRect CheckBoxRect;
415 pRect->HSplitTop(Cut: VMargin, pTop: &CheckBoxRect, pBottom: pRect);
416
417 int Logic = DoButton_CheckBox_Common(pId, pText, pBoxText: *pValue ? "X" : "", pRect: &CheckBoxRect, Flags: BUTTONFLAG_LEFT);
418
419 if(Logic)
420 *pValue ^= 1;
421
422 return Logic;
423}
424
425int CMenus::DoButton_CheckBox(const void *pId, const char *pText, int Checked, const CUIRect *pRect)
426{
427 return DoButton_CheckBox_Common(pId, pText, pBoxText: Checked ? "X" : "", pRect, Flags: BUTTONFLAG_LEFT);
428}
429
430int CMenus::DoButton_CheckBox_Number(const void *pId, const char *pText, int Checked, const CUIRect *pRect)
431{
432 char aBuf[16];
433 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%d", Checked);
434 return DoButton_CheckBox_Common(pId, pText, pBoxText: aBuf, pRect, Flags: BUTTONFLAG_LEFT | BUTTONFLAG_RIGHT);
435}
436
437void CMenus::RenderMenubar(CUIRect Box, IClient::EClientState ClientState)
438{
439 CUIRect Button;
440
441 int NewPage = -1;
442 int ActivePage = -1;
443 if(ClientState == IClient::STATE_OFFLINE)
444 {
445 ActivePage = m_MenuPage;
446 }
447 else if(ClientState == IClient::STATE_ONLINE)
448 {
449 ActivePage = m_GamePage;
450 }
451 else
452 {
453 dbg_assert_failed("Client state %d is invalid for RenderMenubar", ClientState);
454 }
455
456 // First render buttons aligned from right side so remaining
457 // width is known when rendering buttons from left side.
458 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
459 TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGNMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE);
460
461 Box.VSplitRight(Cut: 33.0f, pLeft: &Box, pRight: &Button);
462 static CButtonContainer s_QuitButton;
463 ColorRGBA QuitColor(1, 0, 0, 0.5f);
464 if(DoButton_MenuTab(pButtonContainer: &s_QuitButton, pText: FontIcon::POWER_OFF, Checked: 0, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsSmallPage[SMALL_TAB_QUIT], pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: &QuitColor, EdgeRounding: 10.0f))
465 {
466 if(GameClient()->Editor()->HasUnsavedData() || (GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmQuitTime && g_Config.m_ClConfirmQuitTime >= 0) || m_MenusIngameTouchControls.UnsavedChanges() || GameClient()->m_TouchControls.HasEditingChanges())
467 {
468 m_Popup = POPUP_QUIT;
469 }
470 else
471 {
472 Client()->Quit();
473 }
474 }
475 Ui()->DoToolTip(pId: &s_QuitButton, pNearRect: &Button, pText: Localize(pStr: "Quit"));
476
477 Box.VSplitRight(Cut: 10.0f, pLeft: &Box, pRight: nullptr);
478 Box.VSplitRight(Cut: 33.0f, pLeft: &Box, pRight: &Button);
479 static CButtonContainer s_SettingsButton;
480 if(DoButton_MenuTab(pButtonContainer: &s_SettingsButton, pText: FontIcon::GEAR, Checked: ActivePage == PAGE_SETTINGS, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsSmallPage[SMALL_TAB_SETTINGS]))
481 {
482 NewPage = PAGE_SETTINGS;
483 }
484 Ui()->DoToolTip(pId: &s_SettingsButton, pNearRect: &Button, pText: Localize(pStr: "Settings"));
485
486 Box.VSplitRight(Cut: 10.0f, pLeft: &Box, pRight: nullptr);
487 Box.VSplitRight(Cut: 33.0f, pLeft: &Box, pRight: &Button);
488 static CButtonContainer s_EditorButton;
489 if(DoButton_MenuTab(pButtonContainer: &s_EditorButton, pText: FontIcon::PEN_TO_SQUARE, Checked: 0, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsSmallPage[SMALL_TAB_EDITOR]))
490 {
491 g_Config.m_ClEditor = 1;
492 }
493 Ui()->DoToolTip(pId: &s_EditorButton, pNearRect: &Button, pText: Localize(pStr: "Editor"));
494
495 if(ClientState == IClient::STATE_OFFLINE)
496 {
497 Box.VSplitRight(Cut: 10.0f, pLeft: &Box, pRight: nullptr);
498 Box.VSplitRight(Cut: 33.0f, pLeft: &Box, pRight: &Button);
499 static CButtonContainer s_DemoButton;
500 if(DoButton_MenuTab(pButtonContainer: &s_DemoButton, pText: FontIcon::CLAPPERBOARD, Checked: ActivePage == PAGE_DEMOS, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsSmallPage[SMALL_TAB_DEMOBUTTON]))
501 {
502 NewPage = PAGE_DEMOS;
503 }
504 Ui()->DoToolTip(pId: &s_DemoButton, pNearRect: &Button, pText: Localize(pStr: "Demos"));
505 Box.VSplitRight(Cut: 10.0f, pLeft: &Box, pRight: nullptr);
506
507 Box.VSplitLeft(Cut: 33.0f, pLeft: &Button, pRight: &Box);
508
509 bool GotNewsOrUpdate = false;
510
511#if defined(CONF_AUTOUPDATE)
512 int State = Updater()->GetCurrentState();
513 bool NeedUpdate = str_comp(a: Client()->LatestVersion(), b: "0");
514 if(State == IUpdater::CLEAN && NeedUpdate)
515 {
516 GotNewsOrUpdate = true;
517 }
518#endif
519
520 GotNewsOrUpdate |= (bool)g_Config.m_UiUnreadNews;
521
522 ColorRGBA HomeButtonColorAlert(0, 1, 0, 0.25f);
523 ColorRGBA HomeButtonColorAlertHover(0, 1, 0, 0.5f);
524 ColorRGBA *pHomeButtonColor = nullptr;
525 ColorRGBA *pHomeButtonColorHover = nullptr;
526
527 const char *pHomeScreenButtonLabel = FontIcon::HOUSE;
528 if(GotNewsOrUpdate)
529 {
530 pHomeScreenButtonLabel = FontIcon::NEWSPAPER;
531 pHomeButtonColor = &HomeButtonColorAlert;
532 pHomeButtonColorHover = &HomeButtonColorAlertHover;
533 }
534
535 static CButtonContainer s_StartButton;
536 if(DoButton_MenuTab(pButtonContainer: &s_StartButton, pText: pHomeScreenButtonLabel, Checked: false, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsSmallPage[SMALL_TAB_HOME], pDefaultColor: pHomeButtonColor, pActiveColor: pHomeButtonColor, pHoverColor: pHomeButtonColorHover, EdgeRounding: 10.0f))
537 {
538 m_ShowStart = true;
539 }
540 Ui()->DoToolTip(pId: &s_StartButton, pNearRect: &Button, pText: Localize(pStr: "Main menu"));
541
542 const float BrowserButtonWidth = 75.0f;
543 Box.VSplitLeft(Cut: 10.0f, pLeft: nullptr, pRight: &Box);
544 Box.VSplitLeft(Cut: BrowserButtonWidth, pLeft: &Button, pRight: &Box);
545 static CButtonContainer s_InternetButton;
546 if(DoButton_MenuTab(pButtonContainer: &s_InternetButton, pText: FontIcon::EARTH_AMERICAS, Checked: ActivePage == PAGE_INTERNET, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsBigPage[BIG_TAB_INTERNET]))
547 {
548 NewPage = PAGE_INTERNET;
549 }
550 Ui()->DoToolTip(pId: &s_InternetButton, pNearRect: &Button, pText: Localize(pStr: "Internet"));
551
552 Box.VSplitLeft(Cut: BrowserButtonWidth, pLeft: &Button, pRight: &Box);
553 static CButtonContainer s_LanButton;
554 if(DoButton_MenuTab(pButtonContainer: &s_LanButton, pText: FontIcon::NETWORK_WIRED, Checked: ActivePage == PAGE_LAN, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsBigPage[BIG_TAB_LAN]))
555 {
556 NewPage = PAGE_LAN;
557 }
558 Ui()->DoToolTip(pId: &s_LanButton, pNearRect: &Button, pText: Localize(pStr: "LAN"));
559
560 Box.VSplitLeft(Cut: BrowserButtonWidth, pLeft: &Button, pRight: &Box);
561 static CButtonContainer s_FavoritesButton;
562 if(DoButton_MenuTab(pButtonContainer: &s_FavoritesButton, pText: FontIcon::STAR, Checked: ActivePage == PAGE_FAVORITES, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsBigPage[BIG_TAB_FAVORITES]))
563 {
564 NewPage = PAGE_FAVORITES;
565 }
566 Ui()->DoToolTip(pId: &s_FavoritesButton, pNearRect: &Button, pText: Localize(pStr: "Favorites"));
567
568 const std::vector<const CCommunity *> vpFavoriteCommunities = ServerBrowser()->FavoriteCommunities();
569 const int MaxPage = PAGE_FAVORITES + vpFavoriteCommunities.size();
570 if(
571 !Ui()->IsPopupOpen() &&
572 CLineInput::GetActiveInput() == nullptr &&
573 (g_Config.m_UiPage >= PAGE_INTERNET && g_Config.m_UiPage <= MaxPage) &&
574 (m_MenuPage >= PAGE_INTERNET && m_MenuPage <= PAGE_FAVORITE_COMMUNITY_5))
575 {
576 if(Input()->KeyPress(Key: KEY_RIGHT))
577 {
578 NewPage = g_Config.m_UiPage + 1;
579 if(NewPage > MaxPage)
580 NewPage = PAGE_INTERNET;
581 }
582 if(Input()->KeyPress(Key: KEY_LEFT))
583 {
584 NewPage = g_Config.m_UiPage - 1;
585 if(NewPage < PAGE_INTERNET)
586 NewPage = MaxPage;
587 }
588 }
589
590 size_t FavoriteCommunityIndex = 0;
591 static CButtonContainer s_aFavoriteCommunityButtons[5];
592 static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
593 static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)BIT_TAB_FAVORITE_COMMUNITY_5 - BIT_TAB_FAVORITE_COMMUNITY_1 + 1);
594 static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)IServerBrowser::TYPE_FAVORITE_COMMUNITY_5 - IServerBrowser::TYPE_FAVORITE_COMMUNITY_1 + 1);
595 for(const CCommunity *pCommunity : vpFavoriteCommunities)
596 {
597 if(Box.w < BrowserButtonWidth)
598 break;
599 Box.VSplitLeft(Cut: BrowserButtonWidth, pLeft: &Button, pRight: &Box);
600 const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
601 if(DoButton_MenuTab(pButtonContainer: &s_aFavoriteCommunityButtons[FavoriteCommunityIndex], pText: FontIcon::ELLIPSIS, Checked: ActivePage == Page, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsBigPage[BIT_TAB_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex], pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 10.0f, pCommunityIcon: m_CommunityIcons.Find(pCommunityId: pCommunity->Id())))
602 {
603 NewPage = Page;
604 }
605 Ui()->DoToolTip(pId: &s_aFavoriteCommunityButtons[FavoriteCommunityIndex], pNearRect: &Button, pText: pCommunity->Name());
606
607 ++FavoriteCommunityIndex;
608 if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
609 break;
610 }
611
612 TextRender()->SetRenderFlags(0);
613 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
614 }
615 else
616 {
617 TextRender()->SetRenderFlags(0);
618 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
619
620 // online menus
621 Box.VSplitLeft(Cut: 90.0f, pLeft: &Button, pRight: &Box);
622 static CButtonContainer s_GameButton;
623 if(DoButton_MenuTab(pButtonContainer: &s_GameButton, pText: Localize(pStr: "Game"), Checked: ActivePage == PAGE_GAME, pRect: &Button, Corners: IGraphics::CORNER_TL))
624 NewPage = PAGE_GAME;
625
626 Box.VSplitLeft(Cut: 90.0f, pLeft: &Button, pRight: &Box);
627 static CButtonContainer s_PlayersButton;
628 if(DoButton_MenuTab(pButtonContainer: &s_PlayersButton, pText: Localize(pStr: "Players"), Checked: ActivePage == PAGE_PLAYERS, pRect: &Button, Corners: IGraphics::CORNER_NONE))
629 NewPage = PAGE_PLAYERS;
630
631 Box.VSplitLeft(Cut: 130.0f, pLeft: &Button, pRight: &Box);
632 static CButtonContainer s_ServerInfoButton;
633 if(DoButton_MenuTab(pButtonContainer: &s_ServerInfoButton, pText: Localize(pStr: "Server info"), Checked: ActivePage == PAGE_SERVER_INFO, pRect: &Button, Corners: IGraphics::CORNER_NONE))
634 NewPage = PAGE_SERVER_INFO;
635
636 Box.VSplitLeft(Cut: 90.0f, pLeft: &Button, pRight: &Box);
637 static CButtonContainer s_NetworkButton;
638 if(DoButton_MenuTab(pButtonContainer: &s_NetworkButton, pText: Localize(pStr: "Browser"), Checked: ActivePage == PAGE_NETWORK, pRect: &Button, Corners: IGraphics::CORNER_NONE))
639 NewPage = PAGE_NETWORK;
640
641 if(GameClient()->m_GameInfo.m_Race)
642 {
643 Box.VSplitLeft(Cut: 90.0f, pLeft: &Button, pRight: &Box);
644 static CButtonContainer s_GhostButton;
645 if(DoButton_MenuTab(pButtonContainer: &s_GhostButton, pText: Localize(pStr: "Ghost"), Checked: ActivePage == PAGE_GHOST, pRect: &Button, Corners: IGraphics::CORNER_NONE))
646 NewPage = PAGE_GHOST;
647 }
648
649 Box.VSplitLeft(Cut: 100.0f, pLeft: &Button, pRight: &Box);
650 Box.VSplitLeft(Cut: 4.0f, pLeft: nullptr, pRight: &Box);
651 static CButtonContainer s_CallVoteButton;
652 if(DoButton_MenuTab(pButtonContainer: &s_CallVoteButton, pText: Localize(pStr: "Call vote"), Checked: ActivePage == PAGE_CALLVOTE, pRect: &Button, Corners: IGraphics::CORNER_TR))
653 {
654 NewPage = PAGE_CALLVOTE;
655 m_ControlPageOpening = true;
656 }
657
658 if(Box.w >= 10.0f + 33.0f + 10.0f)
659 {
660 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
661 TextRender()->SetRenderFlags(ETextRenderFlags::TEXT_RENDER_FLAG_ONLY_ADVANCE_WIDTH | ETextRenderFlags::TEXT_RENDER_FLAG_NO_X_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_Y_BEARING | ETextRenderFlags::TEXT_RENDER_FLAG_NO_PIXEL_ALIGNMENT | ETextRenderFlags::TEXT_RENDER_FLAG_NO_OVERSIZE);
662
663 Box.VSplitRight(Cut: 10.0f, pLeft: &Box, pRight: nullptr);
664 Box.VSplitRight(Cut: 33.0f, pLeft: &Box, pRight: &Button);
665 static CButtonContainer s_DemoButton;
666 if(DoButton_MenuTab(pButtonContainer: &s_DemoButton, pText: FontIcon::CLAPPERBOARD, Checked: ActivePage == PAGE_DEMOS, pRect: &Button, Corners: IGraphics::CORNER_T, pAnimator: &m_aAnimatorsSmallPage[SMALL_TAB_DEMOBUTTON]))
667 {
668 NewPage = PAGE_DEMOS;
669 }
670 Ui()->DoToolTip(pId: &s_DemoButton, pNearRect: &Button, pText: Localize(pStr: "Demos"));
671 Box.VSplitRight(Cut: 10.0f, pLeft: &Box, pRight: nullptr);
672
673 TextRender()->SetRenderFlags(0);
674 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
675 }
676 }
677
678 if(NewPage != -1)
679 {
680 if(ClientState == IClient::STATE_OFFLINE)
681 SetMenuPage(NewPage);
682 else
683 m_GamePage = NewPage;
684 }
685}
686
687void CMenus::RenderLoadingDirect(const char *pCaption, const char *pContent, std::optional<float> Progress)
688{
689 // TODO: not supported right now due to separate render thread
690
691 // make sure that we don't render for each little thing we load
692 // because that will slow down loading if we have vsync
693 // make sure we otherwise update the progressbar if we have one for a smoother animation
694 const std::chrono::nanoseconds Now = time_get_nanoseconds();
695
696 /* Limit FPS to something reasonable. Ideally the values would just be stored and the rendering would be on a **consistent** timer with 60Hz
697 * Waiting for calls of this function makes the rendering stutter, which you can notice with the background
698 */
699 int RefreshRate = g_Config.m_GfxVsync || !Progress.has_value() ? 60 : (in_range(a: g_Config.m_GfxRefreshRate, lower: 1, upper: 300) ? g_Config.m_GfxRefreshRate : 300);
700 if(RefreshRate > 0 && Now - m_LoadingState.m_LastRender < std::chrono::nanoseconds(1s) / RefreshRate)
701 return;
702
703 // need up date this here to get correct
704 ms_GuiColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_UiColor, true));
705
706 Ui()->MapScreen();
707
708 if(GameClient()->m_MenuBackground.IsLoading())
709 {
710 // Avoid rendering while loading the menu background as this would otherwise
711 // cause the regular menu background to be rendered for a few frames while
712 // the menu background is not loaded yet.
713 return;
714 }
715 if(!GameClient()->m_MenuBackground.Render())
716 {
717 RenderBackground();
718 }
719
720 m_LoadingState.m_LastRender = Now;
721
722 CUIRect Box;
723 Ui()->Screen()->Margin(Cut: 160.0f, pOtherRect: &Box);
724
725 Graphics()->TextureClear();
726 Box.Draw(Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners: IGraphics::CORNER_ALL, Rounding: 15.0f);
727 Box.Margin(Cut: 20.0f, pOtherRect: &Box);
728
729 CUIRect Label;
730 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
731 Ui()->DoLabel(pRect: &Label, pText: pCaption, Size: 24.0f, Align: TEXTALIGN_MC);
732
733 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
734 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
735 Ui()->DoLabel(pRect: &Label, pText: pContent, Size: 20.0f, Align: TEXTALIGN_MC);
736
737 if(Progress.has_value())
738 {
739 CUIRect ProgressBar;
740 Box.HSplitBottom(Cut: 30.0f, pTop: &Box, pBottom: nullptr);
741 Box.HSplitBottom(Cut: 25.0f, pTop: &Box, pBottom: &ProgressBar);
742 ProgressBar.VMargin(Cut: 20.0f, pOtherRect: &ProgressBar);
743 Ui()->RenderProgressBar(ProgressBar, Progress: std::clamp(val: Progress.value(), lo: 0.0f, hi: 1.0f));
744 }
745
746 Graphics()->SetColor(r: 1.0, g: 1.0, b: 1.0, a: 1.0);
747
748 Client()->UpdateAndSwap();
749}
750
751void CMenus::RenderLoading(const char *pCaption, const char *pContent, int IncreaseCounter)
752{
753 // does not support multithreading
754
755 const int CurLoadRenderCount = m_LoadingState.m_Current;
756 m_LoadingState.m_Current += IncreaseCounter;
757 dbg_assert(m_LoadingState.m_Current <= m_LoadingState.m_Total, "Invalid progress for RenderLoading");
758 RenderLoadingDirect(pCaption, pContent, Progress: m_LoadingState.m_Total > 0 ? std::make_optional(t: CurLoadRenderCount / (float)m_LoadingState.m_Total) : std::nullopt);
759}
760
761void CMenus::FinishLoading()
762{
763 m_LoadingState.m_Current = 0;
764 m_LoadingState.m_Total = 0;
765}
766
767void CMenus::RenderNews(CUIRect MainView)
768{
769 GameClient()->m_MenuBackground.ChangePosition(PositionNumber: CMenuBackground::POS_NEWS);
770
771 g_Config.m_UiUnreadNews = false;
772
773 MainView.Draw(Color: ms_ColorTabbarActive, Corners: IGraphics::CORNER_B, Rounding: 10.0f);
774
775 MainView.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &MainView);
776 MainView.VSplitLeft(Cut: 15.0f, pLeft: nullptr, pRight: &MainView);
777
778 CUIRect Label;
779
780 const char *pStr = Client()->News();
781 char aLine[256];
782 while((pStr = str_next_token(str: pStr, delim: "\n", buffer: aLine, buffer_size: sizeof(aLine))))
783 {
784 const int Len = str_length(str: aLine);
785 if(Len > 0 && aLine[0] == '|' && aLine[Len - 1] == '|')
786 {
787 MainView.HSplitTop(Cut: 30.0f, pTop: &Label, pBottom: &MainView);
788 aLine[Len - 1] = '\0';
789 Ui()->DoLabel(pRect: &Label, pText: aLine + 1, Size: 20.0f, Align: TEXTALIGN_ML);
790 }
791 else
792 {
793 MainView.HSplitTop(Cut: 20.0f, pTop: &Label, pBottom: &MainView);
794 Ui()->DoLabel(pRect: &Label, pText: aLine, Size: 15.f, Align: TEXTALIGN_ML);
795 }
796 }
797}
798
799void CMenus::OnInterfacesInit(CGameClient *pClient)
800{
801 CComponentInterfaces::OnInterfacesInit(pClient);
802 m_MenusIngameTouchControls.OnInterfacesInit(pClient);
803 m_MenusSettingsControls.OnInterfacesInit(pClient);
804 m_MenusStart.OnInterfacesInit(pClient);
805 m_CommunityIcons.OnInterfacesInit(pClient);
806}
807
808void CMenus::OnInit()
809{
810 if(g_Config.m_ClShowWelcome)
811 {
812 m_Popup = POPUP_LANGUAGE;
813 m_CreateDefaultFavoriteCommunities = true;
814 }
815
816 if(g_Config.m_UiPage >= PAGE_FAVORITE_COMMUNITY_1 && g_Config.m_UiPage <= PAGE_FAVORITE_COMMUNITY_5 &&
817 (size_t)(g_Config.m_UiPage - PAGE_FAVORITE_COMMUNITY_1) >= ServerBrowser()->FavoriteCommunities().size())
818 {
819 // Reset page to internet when there is no favorite community for this page.
820 g_Config.m_UiPage = PAGE_INTERNET;
821 }
822
823 if(g_Config.m_ClSkipStartMenu)
824 {
825 m_ShowStart = false;
826 }
827 m_MenuPage = g_Config.m_UiPage;
828
829 m_RefreshButton.Init(pUI: Ui(), RequestedRectCount: -1);
830 m_ConnectButton.Init(pUI: Ui(), RequestedRectCount: -1);
831
832 Console()->Chain(pName: "add_favorite", pfnChainFunc: ConchainFavoritesUpdate, pUser: this);
833 Console()->Chain(pName: "remove_favorite", pfnChainFunc: ConchainFavoritesUpdate, pUser: this);
834 Console()->Chain(pName: "add_friend", pfnChainFunc: ConchainFriendlistUpdate, pUser: this);
835 Console()->Chain(pName: "remove_friend", pfnChainFunc: ConchainFriendlistUpdate, pUser: this);
836
837 Console()->Chain(pName: "add_excluded_community", pfnChainFunc: ConchainCommunitiesUpdate, pUser: this);
838 Console()->Chain(pName: "remove_excluded_community", pfnChainFunc: ConchainCommunitiesUpdate, pUser: this);
839 Console()->Chain(pName: "add_excluded_country", pfnChainFunc: ConchainCommunitiesUpdate, pUser: this);
840 Console()->Chain(pName: "remove_excluded_country", pfnChainFunc: ConchainCommunitiesUpdate, pUser: this);
841 Console()->Chain(pName: "add_excluded_type", pfnChainFunc: ConchainCommunitiesUpdate, pUser: this);
842 Console()->Chain(pName: "remove_excluded_type", pfnChainFunc: ConchainCommunitiesUpdate, pUser: this);
843
844 Console()->Chain(pName: "ui_page", pfnChainFunc: ConchainUiPageUpdate, pUser: this);
845
846 Console()->Chain(pName: "snd_enable", pfnChainFunc: ConchainUpdateMusicState, pUser: this);
847 Console()->Chain(pName: "snd_enable_music", pfnChainFunc: ConchainUpdateMusicState, pUser: this);
848 Console()->Chain(pName: "cl_background_entities", pfnChainFunc: ConchainBackgroundEntities, pUser: this);
849
850 Console()->Chain(pName: "cl_assets_entities", pfnChainFunc: ConchainAssetsEntities, pUser: this);
851 Console()->Chain(pName: "cl_asset_game", pfnChainFunc: ConchainAssetGame, pUser: this);
852 Console()->Chain(pName: "cl_asset_emoticons", pfnChainFunc: ConchainAssetEmoticons, pUser: this);
853 Console()->Chain(pName: "cl_asset_particles", pfnChainFunc: ConchainAssetParticles, pUser: this);
854 Console()->Chain(pName: "cl_asset_hud", pfnChainFunc: ConchainAssetHud, pUser: this);
855 Console()->Chain(pName: "cl_asset_extras", pfnChainFunc: ConchainAssetExtras, pUser: this);
856
857 Console()->Chain(pName: "demo_play", pfnChainFunc: ConchainDemoPlay, pUser: this);
858 Console()->Chain(pName: "demo_speed", pfnChainFunc: ConchainDemoSpeed, pUser: this);
859
860 m_TextureBlob = Graphics()->LoadTexture(pFilename: "blob.png", StorageType: IStorage::TYPE_ALL);
861
862 // setup load amount
863 m_LoadingState.m_Current = 0;
864 m_LoadingState.m_Total = g_pData->m_NumImages + GameClient()->ComponentCount();
865 if(!g_Config.m_ClThreadsoundloading)
866 m_LoadingState.m_Total += g_pData->m_NumSounds;
867
868 m_IsInit = true;
869
870 // load menu images
871 m_vMenuImages.clear();
872 Storage()->ListDirectory(Type: IStorage::TYPE_ALL, pPath: "menuimages", pfnCallback: MenuImageScan, pUser: this);
873
874 m_CommunityIcons.Load();
875
876 // Quad for the direction arrows above the player
877 m_DirectionQuadContainerIndex = Graphics()->CreateQuadContainer(AutomaticUpload: false);
878 Graphics()->QuadContainerAddSprite(QuadContainerIndex: m_DirectionQuadContainerIndex, x: 0.f, y: 0.f, Size: 22.f);
879 Graphics()->QuadContainerUpload(ContainerIndex: m_DirectionQuadContainerIndex);
880}
881
882void CMenus::ConchainBackgroundEntities(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
883{
884 pfnCallback(pResult, pCallbackUserData);
885 if(pResult->NumArguments())
886 {
887 CMenus *pSelf = (CMenus *)pUserData;
888 if(str_comp(a: g_Config.m_ClBackgroundEntities, b: pSelf->GameClient()->m_Background.MapName()) != 0)
889 pSelf->GameClient()->m_Background.LoadBackground();
890 }
891}
892
893void CMenus::ConchainUpdateMusicState(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)
894{
895 pfnCallback(pResult, pCallbackUserData);
896 auto *pSelf = (CMenus *)pUserData;
897 if(pResult->NumArguments())
898 pSelf->UpdateMusicState();
899}
900
901void CMenus::UpdateMusicState()
902{
903 const bool ShouldPlay = Client()->State() == IClient::STATE_OFFLINE && g_Config.m_SndEnable && g_Config.m_SndMusic;
904 if(ShouldPlay && !GameClient()->m_Sounds.IsPlaying(SetId: SOUND_MENU))
905 GameClient()->m_Sounds.Enqueue(Channel: CSounds::CHN_MUSIC, SetId: SOUND_MENU);
906 else if(!ShouldPlay && GameClient()->m_Sounds.IsPlaying(SetId: SOUND_MENU))
907 GameClient()->m_Sounds.Stop(SetId: SOUND_MENU);
908 if(!ShouldPlay)
909 GameClient()->m_MapSounds.StopAll();
910}
911
912void CMenus::PopupMessage(const char *pTitle, const char *pMessage, const char *pButtonLabel, int NextPopup, FPopupButtonCallback pfnButtonCallback)
913{
914 // reset active item
915 Ui()->SetActiveItem(nullptr);
916
917 str_copy(dst&: m_aPopupTitle, src: pTitle);
918 str_copy(dst&: m_aPopupMessage, src: pMessage);
919 str_copy(dst&: m_aPopupButtons[BUTTON_CONFIRM].m_aLabel, src: pButtonLabel);
920 m_aPopupButtons[BUTTON_CONFIRM].m_NextPopup = NextPopup;
921 m_aPopupButtons[BUTTON_CONFIRM].m_pfnCallback = pfnButtonCallback;
922 m_Popup = POPUP_MESSAGE;
923}
924
925void CMenus::PopupConfirm(const char *pTitle, const char *pMessage, const char *pConfirmButtonLabel, const char *pCancelButtonLabel,
926 FPopupButtonCallback pfnConfirmButtonCallback, int ConfirmNextPopup, FPopupButtonCallback pfnCancelButtonCallback, int CancelNextPopup)
927{
928 // reset active item
929 Ui()->SetActiveItem(nullptr);
930
931 str_copy(dst&: m_aPopupTitle, src: pTitle);
932 str_copy(dst&: m_aPopupMessage, src: pMessage);
933 str_copy(dst&: m_aPopupButtons[BUTTON_CONFIRM].m_aLabel, src: pConfirmButtonLabel);
934 m_aPopupButtons[BUTTON_CONFIRM].m_NextPopup = ConfirmNextPopup;
935 m_aPopupButtons[BUTTON_CONFIRM].m_pfnCallback = pfnConfirmButtonCallback;
936 str_copy(dst&: m_aPopupButtons[BUTTON_CANCEL].m_aLabel, src: pCancelButtonLabel);
937 m_aPopupButtons[BUTTON_CANCEL].m_NextPopup = CancelNextPopup;
938 m_aPopupButtons[BUTTON_CANCEL].m_pfnCallback = pfnCancelButtonCallback;
939 m_Popup = POPUP_CONFIRM;
940}
941
942void CMenus::PopupWarning(const char *pTopic, const char *pBody, const char *pButton, std::chrono::nanoseconds Duration)
943{
944 // no multiline support for console
945 std::string BodyStr = pBody;
946 std::replace(first: BodyStr.begin(), last: BodyStr.end(), old_value: '\n', new_value: ' ');
947 log_warn("client", "%s: %s", pTopic, BodyStr.c_str());
948
949 Ui()->SetActiveItem(nullptr);
950
951 str_copy(dst&: m_aMessageTopic, src: pTopic);
952 str_copy(dst&: m_aMessageBody, src: pBody);
953 str_copy(dst&: m_aMessageButton, src: pButton);
954 m_Popup = POPUP_WARNING;
955 SetActive(true);
956
957 m_PopupWarningDuration = Duration;
958 m_PopupWarningLastTime = time_get_nanoseconds();
959}
960
961bool CMenus::CanDisplayWarning() const
962{
963 return m_Popup == POPUP_NONE;
964}
965
966void CMenus::Render()
967{
968 Ui()->MapScreen();
969 Ui()->SetMouseSlow(false);
970
971 static int s_Frame = 0;
972 if(s_Frame == 0)
973 {
974 RefreshBrowserTab(Force: true);
975 s_Frame++;
976 }
977 else if(s_Frame == 1)
978 {
979 UpdateMusicState();
980 s_Frame++;
981 }
982 else
983 {
984 m_CommunityIcons.Update();
985 }
986
987 // Initially add DDNet as favorite community and select its tab.
988 // This must be delayed until the DDNet info is available.
989 if(m_CreateDefaultFavoriteCommunities &&
990 ServerBrowser()->DDNetInfoAvailable())
991 {
992 m_CreateDefaultFavoriteCommunities = false;
993 if(ServerBrowser()->Community(pCommunityId: IServerBrowser::COMMUNITY_DDNET) != nullptr)
994 {
995 ServerBrowser()->FavoriteCommunitiesFilter().Clear();
996 ServerBrowser()->FavoriteCommunitiesFilter().Add(pElement: IServerBrowser::COMMUNITY_DDNET);
997 SetMenuPage(PAGE_FAVORITE_COMMUNITY_1);
998 ServerBrowser()->Refresh(Type: IServerBrowser::TYPE_FAVORITE_COMMUNITY_1);
999 }
1000 }
1001 if(m_JoinTutorial.m_Queued && m_Popup == POPUP_NONE)
1002 {
1003 const char *pAddr = ServerBrowser()->GetTutorialServer();
1004 if(pAddr)
1005 {
1006 Client()->Connect(pAddress: pAddr);
1007 }
1008 else
1009 {
1010 m_Popup = POPUP_JOIN_TUTORIAL;
1011 }
1012 m_JoinTutorial.m_Queued = false;
1013 }
1014
1015 // Determine the client state once before rendering because it can change
1016 // while rendering which causes frames with broken user interface.
1017 const IClient::EClientState ClientState = Client()->State();
1018
1019 if(ClientState == IClient::STATE_ONLINE || ClientState == IClient::STATE_DEMOPLAYBACK)
1020 {
1021 ms_ColorTabbarInactive = ms_ColorTabbarInactiveIngame;
1022 ms_ColorTabbarActive = ms_ColorTabbarActiveIngame;
1023 ms_ColorTabbarHover = ms_ColorTabbarHoverIngame;
1024 }
1025 else
1026 {
1027 if(!GameClient()->m_MenuBackground.Render())
1028 {
1029 RenderBackground();
1030 }
1031 ms_ColorTabbarInactive = ms_ColorTabbarInactiveOutgame;
1032 ms_ColorTabbarActive = ms_ColorTabbarActiveOutgame;
1033 ms_ColorTabbarHover = ms_ColorTabbarHoverOutgame;
1034 }
1035
1036 CUIRect Screen = *Ui()->Screen();
1037 if(Client()->State() != IClient::STATE_DEMOPLAYBACK || m_Popup != POPUP_NONE)
1038 {
1039 Screen.Margin(Cut: 10.0f, pOtherRect: &Screen);
1040 }
1041
1042 switch(ClientState)
1043 {
1044 case IClient::STATE_QUITTING:
1045 case IClient::STATE_RESTARTING:
1046 // Render nothing except menu background. This should not happen for more than one frame.
1047 return;
1048
1049 case IClient::STATE_CONNECTING:
1050 RenderPopupConnecting(Screen);
1051 break;
1052
1053 case IClient::STATE_LOADING:
1054 RenderPopupLoading(Screen);
1055 break;
1056
1057 case IClient::STATE_OFFLINE:
1058 if(m_Popup != POPUP_NONE)
1059 {
1060 RenderPopupFullscreen(Screen);
1061 }
1062 else if(m_ShowStart)
1063 {
1064 m_MenusStart.RenderStartMenu(MainView: Screen);
1065 }
1066 else
1067 {
1068 CUIRect TabBar, MainView;
1069 Screen.HSplitTop(Cut: 24.0f, pTop: &TabBar, pBottom: &MainView);
1070
1071 if(m_MenuPage == PAGE_NEWS)
1072 {
1073 RenderNews(MainView);
1074 }
1075 else if(m_MenuPage >= PAGE_INTERNET && m_MenuPage <= PAGE_FAVORITE_COMMUNITY_5)
1076 {
1077 RenderServerbrowser(MainView);
1078 }
1079 else if(m_MenuPage == PAGE_DEMOS)
1080 {
1081 RenderDemoBrowser(MainView);
1082 }
1083 else if(m_MenuPage == PAGE_SETTINGS)
1084 {
1085 RenderSettings(MainView);
1086 }
1087 else
1088 {
1089 dbg_assert_failed("Invalid m_MenuPage: %d", m_MenuPage);
1090 }
1091
1092 RenderMenubar(Box: TabBar, ClientState);
1093 }
1094 break;
1095
1096 case IClient::STATE_ONLINE:
1097 if(m_Popup != POPUP_NONE)
1098 {
1099 RenderPopupFullscreen(Screen);
1100 }
1101 else
1102 {
1103 CUIRect TabBar, MainView;
1104 Screen.HSplitTop(Cut: 24.0f, pTop: &TabBar, pBottom: &MainView);
1105
1106 if(m_GamePage == PAGE_GAME)
1107 {
1108 RenderGame(MainView);
1109 RenderIngameHint();
1110 }
1111 else if(m_GamePage == PAGE_PLAYERS)
1112 {
1113 RenderPlayers(MainView);
1114 }
1115 else if(m_GamePage == PAGE_SERVER_INFO)
1116 {
1117 RenderServerInfo(MainView);
1118 }
1119 else if(m_GamePage == PAGE_NETWORK)
1120 {
1121 RenderInGameNetwork(MainView);
1122 }
1123 else if(m_GamePage == PAGE_GHOST)
1124 {
1125 RenderGhost(MainView);
1126 }
1127 else if(m_GamePage == PAGE_CALLVOTE)
1128 {
1129 RenderServerControl(MainView);
1130 }
1131 else if(m_GamePage == PAGE_DEMOS)
1132 {
1133 RenderDemoBrowser(MainView);
1134 }
1135 else if(m_GamePage == PAGE_SETTINGS)
1136 {
1137 RenderSettings(MainView);
1138 }
1139 else
1140 {
1141 dbg_assert_failed("Invalid m_GamePage: %d", m_GamePage);
1142 }
1143
1144 RenderMenubar(Box: TabBar, ClientState);
1145 }
1146 break;
1147
1148 case IClient::STATE_DEMOPLAYBACK:
1149 if(m_Popup != POPUP_NONE)
1150 {
1151 RenderPopupFullscreen(Screen);
1152 }
1153 else
1154 {
1155 RenderDemoPlayer(MainView: Screen);
1156 }
1157 break;
1158 }
1159
1160 Ui()->RenderPopupMenus();
1161
1162 // Prevent UI elements from being hovered while a key reader is active
1163 if(GameClient()->m_KeyBinder.IsActive())
1164 {
1165 Ui()->SetHotItem(nullptr);
1166 }
1167
1168 // Handle this escape hotkey after popup menus
1169 if(!m_ShowStart && ClientState == IClient::STATE_OFFLINE && Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1170 {
1171 m_ShowStart = true;
1172 }
1173}
1174
1175void CMenus::RenderPopupFullscreen(CUIRect Screen)
1176{
1177 char aBuf[1536];
1178 const char *pTitle = "";
1179 const char *pExtraText = "";
1180 const char *pButtonText = "";
1181 bool TopAlign = false;
1182
1183 ColorRGBA BgColor = ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f);
1184 if(m_Popup == POPUP_MESSAGE || m_Popup == POPUP_CONFIRM)
1185 {
1186 pTitle = m_aPopupTitle;
1187 pExtraText = m_aPopupMessage;
1188 TopAlign = true;
1189 }
1190 else if(m_Popup == POPUP_DISCONNECTED)
1191 {
1192 pTitle = Localize(pStr: "Disconnected");
1193 pExtraText = Client()->ErrorString();
1194 pButtonText = Localize(pStr: "Ok");
1195 if(Client()->ReconnectTime() > 0)
1196 {
1197 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Reconnect in %d sec"), (int)((Client()->ReconnectTime() - time_get()) / time_freq()) + 1);
1198 pTitle = Client()->ErrorString();
1199 pExtraText = aBuf;
1200 pButtonText = Localize(pStr: "Abort");
1201 }
1202 }
1203 else if(m_Popup == POPUP_RENAME_DEMO)
1204 {
1205 dbg_assert(m_DemolistSelectedIndex >= 0, "m_DemolistSelectedIndex invalid for POPUP_RENAME_DEMO");
1206 pTitle = m_vpFilteredDemos[m_DemolistSelectedIndex]->m_IsDir ? Localize(pStr: "Rename folder") : Localize(pStr: "Rename demo");
1207 }
1208#if defined(CONF_VIDEORECORDER)
1209 else if(m_Popup == POPUP_RENDER_DEMO)
1210 {
1211 pTitle = Localize(pStr: "Render demo");
1212 }
1213 else if(m_Popup == POPUP_RENDER_DONE)
1214 {
1215 pTitle = Localize(pStr: "Render complete");
1216 }
1217#endif
1218 else if(m_Popup == POPUP_PASSWORD)
1219 {
1220 pTitle = Localize(pStr: "Password incorrect");
1221 pButtonText = Localize(pStr: "Try again");
1222 }
1223 else if(m_Popup == POPUP_RESTART)
1224 {
1225 pTitle = Localize(pStr: "Restart");
1226 pExtraText = Localize(pStr: "Are you sure that you want to restart?");
1227 }
1228 else if(m_Popup == POPUP_QUIT)
1229 {
1230 pTitle = Localize(pStr: "Quit");
1231 pExtraText = Localize(pStr: "Are you sure that you want to quit?");
1232 }
1233 else if(m_Popup == POPUP_FIRST_LAUNCH)
1234 {
1235 pTitle = Localize(pStr: "Welcome to DDNet");
1236 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s\n\n%s\n\n%s\n\n%s",
1237 Localize(pStr: "DDraceNetwork is a cooperative online game where the goal is for you and your group of tees to reach the finish line of the map. As a newcomer you should start on Novice servers, which host the easiest maps. Consider the ping to choose a server close to you."),
1238 Localize(pStr: "Use k key to kill (restart), q to pause and watch other players. See settings for other key binds."),
1239 Localize(pStr: "It's recommended that you check the settings to adjust them to your liking before joining a server."),
1240 Localize(pStr: "Please enter your nickname below."));
1241 pExtraText = aBuf;
1242 pButtonText = Localize(pStr: "Ok");
1243 TopAlign = true;
1244 }
1245 else if(m_Popup == POPUP_JOIN_TUTORIAL)
1246 {
1247 pTitle = Localize(pStr: "Joining Tutorial server");
1248 }
1249 else if(m_Popup == POPUP_POINTS)
1250 {
1251 pTitle = Localize(pStr: "Existing Player");
1252 if(Client()->InfoState() == IClient::EInfoState::SUCCESS && Client()->Points() > 50)
1253 {
1254 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Your nickname '%s' is already used (%d points). Do you still want to use it?"), Client()->PlayerName(), Client()->Points());
1255 pExtraText = aBuf;
1256 TopAlign = true;
1257 }
1258 else
1259 {
1260 pExtraText = Localize(pStr: "Checking for existing player with your name");
1261 }
1262 }
1263 else if(m_Popup == POPUP_WARNING)
1264 {
1265 BgColor = ColorRGBA(0.5f, 0.0f, 0.0f, 0.7f);
1266 pTitle = m_aMessageTopic;
1267 pExtraText = m_aMessageBody;
1268 pButtonText = m_aMessageButton;
1269 TopAlign = true;
1270 }
1271 else if(m_Popup == POPUP_SAVE_SKIN)
1272 {
1273 pTitle = Localize(pStr: "Save skin");
1274 pExtraText = Localize(pStr: "Are you sure you want to save your skin? If a skin with this name already exists, it will be replaced.");
1275 }
1276
1277 CUIRect Box, Part;
1278 Box = Screen;
1279 if(m_Popup != POPUP_FIRST_LAUNCH)
1280 {
1281 Box.Margin(Cut: 150.0f, pOtherRect: &Box);
1282 }
1283
1284 // Background
1285 Box.Draw(Color: BgColor, Corners: IGraphics::CORNER_ALL, Rounding: 15.0f);
1286
1287 // Title
1288 {
1289 CUIRect Title;
1290 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
1291 Box.HSplitTop(Cut: 24.0f, pTop: &Title, pBottom: &Box);
1292 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
1293 Title.VMargin(Cut: 20.0f, pOtherRect: &Title);
1294
1295 const float TitleFontSize = 24.0f;
1296 if(TextRender()->TextWidth(Size: TitleFontSize, pText: pTitle) > Title.w)
1297 Ui()->DoLabel(pRect: &Title, pText: pTitle, Size: TitleFontSize, Align: TEXTALIGN_ML, LabelProps: {.m_MaxWidth = Title.w});
1298 else
1299 Ui()->DoLabel(pRect: &Title, pText: pTitle, Size: TitleFontSize, Align: TEXTALIGN_MC);
1300 }
1301
1302 // Extra text (optional)
1303 if(m_Popup != POPUP_JOIN_TUTORIAL)
1304 {
1305 CUIRect ExtraText;
1306 Box.HSplitTop(Cut: 24.0f, pTop: &ExtraText, pBottom: &Box);
1307 ExtraText.VMargin(Cut: 20.0f, pOtherRect: &ExtraText);
1308 if(pExtraText[0] != '\0')
1309 {
1310 const float ExtraTextFontSize = m_Popup == POPUP_FIRST_LAUNCH ? 16.0f : 20.0f;
1311
1312 if(TopAlign)
1313 Ui()->DoLabel(pRect: &ExtraText, pText: pExtraText, Size: ExtraTextFontSize, Align: TEXTALIGN_TL, LabelProps: {.m_MaxWidth = ExtraText.w});
1314 else if(TextRender()->TextWidth(Size: ExtraTextFontSize, pText: pExtraText) > ExtraText.w)
1315 Ui()->DoLabel(pRect: &ExtraText, pText: pExtraText, Size: ExtraTextFontSize, Align: TEXTALIGN_ML, LabelProps: {.m_MaxWidth = ExtraText.w});
1316 else
1317 Ui()->DoLabel(pRect: &ExtraText, pText: pExtraText, Size: ExtraTextFontSize, Align: TEXTALIGN_MC);
1318 }
1319 }
1320
1321 if(m_Popup == POPUP_MESSAGE || m_Popup == POPUP_CONFIRM)
1322 {
1323 CUIRect ButtonBar;
1324 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1325 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &ButtonBar);
1326 ButtonBar.VMargin(Cut: 100.0f, pOtherRect: &ButtonBar);
1327
1328 if(m_Popup == POPUP_MESSAGE)
1329 {
1330 static CButtonContainer s_ButtonConfirm;
1331 if(DoButton_Menu(pButtonContainer: &s_ButtonConfirm, pText: m_aPopupButtons[BUTTON_CONFIRM].m_aLabel, Checked: 0, pRect: &ButtonBar) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1332 {
1333 m_Popup = m_aPopupButtons[BUTTON_CONFIRM].m_NextPopup;
1334 (this->*m_aPopupButtons[BUTTON_CONFIRM].m_pfnCallback)();
1335 }
1336 }
1337 else if(m_Popup == POPUP_CONFIRM)
1338 {
1339 CUIRect CancelButton, ConfirmButton;
1340 ButtonBar.VSplitMid(pLeft: &CancelButton, pRight: &ConfirmButton, Spacing: 40.0f);
1341
1342 static CButtonContainer s_ButtonCancel;
1343 if(DoButton_Menu(pButtonContainer: &s_ButtonCancel, pText: m_aPopupButtons[BUTTON_CANCEL].m_aLabel, Checked: 0, pRect: &CancelButton) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1344 {
1345 m_Popup = m_aPopupButtons[BUTTON_CANCEL].m_NextPopup;
1346 (this->*m_aPopupButtons[BUTTON_CANCEL].m_pfnCallback)();
1347 }
1348
1349 static CButtonContainer s_ButtonConfirm;
1350 if(DoButton_Menu(pButtonContainer: &s_ButtonConfirm, pText: m_aPopupButtons[BUTTON_CONFIRM].m_aLabel, Checked: 0, pRect: &ConfirmButton) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1351 {
1352 m_Popup = m_aPopupButtons[BUTTON_CONFIRM].m_NextPopup;
1353 (this->*m_aPopupButtons[BUTTON_CONFIRM].m_pfnCallback)();
1354 }
1355 }
1356 }
1357 else if(m_Popup == POPUP_QUIT || m_Popup == POPUP_RESTART)
1358 {
1359 CUIRect Yes, No;
1360 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1361 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1362
1363 // additional info
1364 Box.VMargin(Cut: 20.f, pOtherRect: &Box);
1365 if(GameClient()->Editor()->HasUnsavedData())
1366 {
1367 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s\n\n%s", Localize(pStr: "There's an unsaved map in the editor, you might want to save it."), Localize(pStr: "Continue anyway?"));
1368 Ui()->DoLabel(pRect: &Box, pText: aBuf, Size: 20.0f, Align: TEXTALIGN_ML, LabelProps: {.m_MaxWidth = Part.w - 20.0f});
1369 }
1370 else if(GameClient()->m_TouchControls.HasEditingChanges() || m_MenusIngameTouchControls.UnsavedChanges())
1371 {
1372 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s\n\n%s", Localize(pStr: "There's an unsaved change in the touch controls editor, you might want to save it."), Localize(pStr: "Continue anyway?"));
1373 Ui()->DoLabel(pRect: &Box, pText: aBuf, Size: 20.0f, Align: TEXTALIGN_ML, LabelProps: {.m_MaxWidth = Part.w - 20.0f});
1374 }
1375
1376 // buttons
1377 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1378 Part.VSplitMid(pLeft: &No, pRight: &Yes);
1379 Yes.VMargin(Cut: 20.0f, pOtherRect: &Yes);
1380 No.VMargin(Cut: 20.0f, pOtherRect: &No);
1381
1382 static CButtonContainer s_ButtonAbort;
1383 if(DoButton_Menu(pButtonContainer: &s_ButtonAbort, pText: Localize(pStr: "No"), Checked: 0, pRect: &No) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1384 m_Popup = POPUP_NONE;
1385
1386 static CButtonContainer s_ButtonTryAgain;
1387 if(DoButton_Menu(pButtonContainer: &s_ButtonTryAgain, pText: Localize(pStr: "Yes"), Checked: 0, pRect: &Yes) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1388 {
1389 if(m_Popup == POPUP_RESTART)
1390 {
1391 m_Popup = POPUP_NONE;
1392 Client()->Restart();
1393 }
1394 else
1395 {
1396 m_Popup = POPUP_NONE;
1397 Client()->Quit();
1398 }
1399 }
1400 }
1401 else if(m_Popup == POPUP_PASSWORD)
1402 {
1403 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1404 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1405 Part.VMargin(Cut: 100.0f, pOtherRect: &Part);
1406
1407 CUIRect TryAgain, Abort;
1408 Part.VSplitMid(pLeft: &Abort, pRight: &TryAgain, Spacing: 40.0f);
1409
1410 static CButtonContainer s_ButtonAbort;
1411 if(DoButton_Menu(pButtonContainer: &s_ButtonAbort, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Abort) ||
1412 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1413 {
1414 m_Popup = POPUP_NONE;
1415 }
1416
1417 char aAddr[NETADDR_MAXSTRSIZE];
1418 net_addr_str(addr: &Client()->ServerAddress(), string: aAddr, max_length: sizeof(aAddr), add_port: true);
1419
1420 static CButtonContainer s_ButtonTryAgain;
1421 if(DoButton_Menu(pButtonContainer: &s_ButtonTryAgain, pText: Localize(pStr: "Try again"), Checked: 0, pRect: &TryAgain) ||
1422 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1423 {
1424 Client()->Connect(pAddress: aAddr, pPassword: g_Config.m_Password);
1425 }
1426
1427 Box.VMargin(Cut: 60.0f, pOtherRect: &Box);
1428 Box.HSplitBottom(Cut: 32.0f, pTop: &Box, pBottom: nullptr);
1429 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1430
1431 CUIRect Label, TextBox;
1432 Part.VSplitLeft(Cut: 100.0f, pLeft: &Label, pRight: &TextBox);
1433 TextBox.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &TextBox);
1434 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Password"), Size: 18.0f, Align: TEXTALIGN_ML);
1435 Ui()->DoClearableEditBox(pLineInput: &m_PasswordInput, pRect: &TextBox, FontSize: 12.0f);
1436
1437 Box.HSplitBottom(Cut: 32.0f, pTop: &Box, pBottom: nullptr);
1438 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1439
1440 CUIRect Address;
1441 Part.VSplitLeft(Cut: 100.0f, pLeft: &Label, pRight: &Address);
1442 Address.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &Address);
1443 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Address"), Size: 18.0f, Align: TEXTALIGN_ML);
1444 Ui()->DoLabel(pRect: &Address, pText: aAddr, Size: 18.0f, Align: TEXTALIGN_ML);
1445
1446 const CServerBrowser::CServerEntry *pEntry = ServerBrowser()->Find(Addr: Client()->ServerAddress());
1447 if(pEntry != nullptr && pEntry->m_GotInfo)
1448 {
1449 const CCommunity *pCommunity = ServerBrowser()->Community(pCommunityId: pEntry->m_Info.m_aCommunityId);
1450 const CCommunityIcon *pIcon = pCommunity == nullptr ? nullptr : m_CommunityIcons.Find(pCommunityId: pCommunity->Id());
1451
1452 Box.HSplitBottom(Cut: 32.0f, pTop: &Box, pBottom: nullptr);
1453 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1454
1455 CUIRect Name;
1456 Part.VSplitLeft(Cut: 100.0f, pLeft: &Label, pRight: &Name);
1457 Name.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &Name);
1458 if(pIcon != nullptr)
1459 {
1460 CUIRect Icon;
1461 static char s_CommunityTooltipButtonId;
1462 Name.VSplitLeft(Cut: 2.5f * Name.h, pLeft: &Icon, pRight: &Name);
1463 m_CommunityIcons.Render(pIcon, Rect: Icon, Active: true);
1464 Ui()->DoButtonLogic(pId: &s_CommunityTooltipButtonId, Checked: 0, pRect: &Icon, Flags: BUTTONFLAG_NONE);
1465 Ui()->DoToolTip(pId: &s_CommunityTooltipButtonId, pNearRect: &Icon, pText: pCommunity->Name());
1466 }
1467
1468 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Name"), Size: 18.0f, Align: TEXTALIGN_ML);
1469 Ui()->DoLabel(pRect: &Name, pText: pEntry->m_Info.m_aName, Size: 18.0f, Align: TEXTALIGN_ML);
1470 }
1471 }
1472 else if(m_Popup == POPUP_LANGUAGE)
1473 {
1474 CUIRect Button;
1475 Screen.Margin(Cut: 150.0f, pOtherRect: &Box);
1476 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
1477 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1478 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Button);
1479 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1480 Box.VMargin(Cut: 20.0f, pOtherRect: &Box);
1481 const bool Activated = RenderLanguageSelection(MainView: Box);
1482 Button.VMargin(Cut: 120.0f, pOtherRect: &Button);
1483
1484 static CButtonContainer s_Button;
1485 if(DoButton_Menu(pButtonContainer: &s_Button, pText: Localize(pStr: "Ok"), Checked: 0, pRect: &Button) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER) || Activated)
1486 m_Popup = POPUP_FIRST_LAUNCH;
1487 }
1488 else if(m_Popup == POPUP_RENAME_DEMO)
1489 {
1490 CUIRect Label, TextBox, Ok, Abort;
1491
1492 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1493 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1494 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1495
1496 Part.VSplitMid(pLeft: &Abort, pRight: &Ok);
1497
1498 Ok.VMargin(Cut: 20.0f, pOtherRect: &Ok);
1499 Abort.VMargin(Cut: 20.0f, pOtherRect: &Abort);
1500
1501 static CButtonContainer s_ButtonAbort;
1502 if(DoButton_Menu(pButtonContainer: &s_ButtonAbort, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Abort) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1503 m_Popup = POPUP_NONE;
1504
1505 static CButtonContainer s_ButtonOk;
1506 if(DoButton_Menu(pButtonContainer: &s_ButtonOk, pText: Localize(pStr: "Ok"), Checked: 0, pRect: &Ok) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1507 {
1508 m_Popup = POPUP_NONE;
1509 // rename demo
1510 char aBufOld[IO_MAX_PATH_LENGTH];
1511 str_format(buffer: aBufOld, buffer_size: sizeof(aBufOld), format: "%s/%s", m_aCurrentDemoFolder, m_vpFilteredDemos[m_DemolistSelectedIndex]->m_aFilename);
1512 char aBufNew[IO_MAX_PATH_LENGTH];
1513 str_format(buffer: aBufNew, buffer_size: sizeof(aBufNew), format: "%s/%s", m_aCurrentDemoFolder, m_DemoRenameInput.GetString());
1514 if(!m_vpFilteredDemos[m_DemolistSelectedIndex]->m_IsDir && !str_endswith(str: aBufNew, suffix: ".demo"))
1515 str_append(dst&: aBufNew, src: ".demo");
1516
1517 if(str_comp(a: aBufOld, b: aBufNew) == 0)
1518 {
1519 // Nothing to rename, also same capitalization
1520 }
1521 else if(!str_valid_filename(str: m_DemoRenameInput.GetString()))
1522 {
1523 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "This name cannot be used for files and folders"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENAME_DEMO);
1524 }
1525 else if(str_utf8_comp_nocase(a: aBufOld, b: aBufNew) != 0 && // Allow renaming if it only changes capitalization to support case-insensitive filesystems
1526 Storage()->FileExists(pFilename: aBufNew, Type: m_vpFilteredDemos[m_DemolistSelectedIndex]->m_StorageType))
1527 {
1528 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "A demo with this name already exists"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENAME_DEMO);
1529 }
1530 else if(Storage()->FolderExists(pFilename: aBufNew, Type: m_vpFilteredDemos[m_DemolistSelectedIndex]->m_StorageType))
1531 {
1532 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "A folder with this name already exists"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENAME_DEMO);
1533 }
1534 else if(Storage()->RenameFile(pOldFilename: aBufOld, pNewFilename: aBufNew, Type: m_vpFilteredDemos[m_DemolistSelectedIndex]->m_StorageType))
1535 {
1536 str_copy(dst&: m_aCurrentDemoSelectionName, src: m_DemoRenameInput.GetString());
1537 if(!m_vpFilteredDemos[m_DemolistSelectedIndex]->m_IsDir)
1538 fs_split_file_extension(filename: m_DemoRenameInput.GetString(), name: m_aCurrentDemoSelectionName, name_size: sizeof(m_aCurrentDemoSelectionName));
1539 DemolistPopulate();
1540 DemolistOnUpdate(Reset: false);
1541 }
1542 else
1543 {
1544 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: m_vpFilteredDemos[m_DemolistSelectedIndex]->m_IsDir ? Localize(pStr: "Unable to rename the folder") : Localize(pStr: "Unable to rename the demo"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENAME_DEMO);
1545 }
1546 }
1547
1548 Box.HSplitBottom(Cut: 60.f, pTop: &Box, pBottom: &Part);
1549 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1550
1551 Part.VSplitLeft(Cut: 60.0f, pLeft: nullptr, pRight: &Label);
1552 Label.VSplitLeft(Cut: 120.0f, pLeft: nullptr, pRight: &TextBox);
1553 TextBox.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &TextBox);
1554 TextBox.VSplitRight(Cut: 60.0f, pLeft: &TextBox, pRight: nullptr);
1555 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "New name:"), Size: 18.0f, Align: TEXTALIGN_ML);
1556 Ui()->DoEditBox(pLineInput: &m_DemoRenameInput, pRect: &TextBox, FontSize: 12.0f);
1557 }
1558#if defined(CONF_VIDEORECORDER)
1559 else if(m_Popup == POPUP_RENDER_DEMO)
1560 {
1561 CUIRect Row, Ok, Abort;
1562 Box.VMargin(Cut: 60.0f, pOtherRect: &Box);
1563 Box.HMargin(Cut: 20.0f, pOtherRect: &Box);
1564 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Row);
1565 Box.HSplitBottom(Cut: 40.0f, pTop: &Box, pBottom: nullptr);
1566 Row.VMargin(Cut: 40.0f, pOtherRect: &Row);
1567 Row.VSplitMid(pLeft: &Abort, pRight: &Ok, Spacing: 40.0f);
1568
1569 static CButtonContainer s_ButtonAbort;
1570 if(DoButton_Menu(pButtonContainer: &s_ButtonAbort, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Abort) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1571 {
1572 m_DemoRenderInput.Clear();
1573 m_Popup = POPUP_NONE;
1574 }
1575
1576 static CButtonContainer s_ButtonOk;
1577 if(DoButton_Menu(pButtonContainer: &s_ButtonOk, pText: Localize(pStr: "Ok"), Checked: 0, pRect: &Ok) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1578 {
1579 m_Popup = POPUP_NONE;
1580 // render video
1581 char aVideoPath[IO_MAX_PATH_LENGTH];
1582 str_format(buffer: aVideoPath, buffer_size: sizeof(aVideoPath), format: "videos/%s", m_DemoRenderInput.GetString());
1583 if(!str_endswith(str: aVideoPath, suffix: ".mp4"))
1584 str_append(dst&: aVideoPath, src: ".mp4");
1585
1586 if(!str_valid_filename(str: m_DemoRenderInput.GetString()))
1587 {
1588 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "This name cannot be used for files and folders"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENDER_DEMO);
1589 }
1590 else if(Storage()->FolderExists(pFilename: aVideoPath, Type: IStorage::TYPE_SAVE))
1591 {
1592 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "A folder with this name already exists"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENDER_DEMO);
1593 }
1594 else if(Storage()->FileExists(pFilename: aVideoPath, Type: IStorage::TYPE_SAVE))
1595 {
1596 char aMessage[128 + IO_MAX_PATH_LENGTH];
1597 str_format(buffer: aMessage, buffer_size: sizeof(aMessage), format: Localize(pStr: "File '%s' already exists, do you want to overwrite it?"), m_DemoRenderInput.GetString());
1598 PopupConfirm(pTitle: Localize(pStr: "Replace video"), pMessage: aMessage, pConfirmButtonLabel: Localize(pStr: "Yes"), pCancelButtonLabel: Localize(pStr: "No"), pfnConfirmButtonCallback: &CMenus::PopupConfirmDemoReplaceVideo, ConfirmNextPopup: POPUP_NONE, pfnCancelButtonCallback: &CMenus::DefaultButtonCallback, CancelNextPopup: POPUP_RENDER_DEMO);
1599 }
1600 else
1601 {
1602 PopupConfirmDemoReplaceVideo();
1603 }
1604 }
1605
1606 CUIRect ShowChatCheckbox, UseSoundsCheckbox;
1607 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: &Row);
1608 Box.HSplitBottom(Cut: 10.0f, pTop: &Box, pBottom: nullptr);
1609 Row.VSplitMid(pLeft: &ShowChatCheckbox, pRight: &UseSoundsCheckbox, Spacing: 20.0f);
1610
1611 if(DoButton_CheckBox(pId: &g_Config.m_ClVideoShowChat, pText: Localize(pStr: "Show chat"), Checked: g_Config.m_ClVideoShowChat, pRect: &ShowChatCheckbox))
1612 g_Config.m_ClVideoShowChat ^= 1;
1613
1614 if(DoButton_CheckBox(pId: &g_Config.m_ClVideoSndEnable, pText: Localize(pStr: "Use sounds"), Checked: g_Config.m_ClVideoSndEnable, pRect: &UseSoundsCheckbox))
1615 g_Config.m_ClVideoSndEnable ^= 1;
1616
1617 CUIRect ShowHudButton;
1618 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: &Row);
1619 Row.VSplitMid(pLeft: &Row, pRight: &ShowHudButton, Spacing: 20.0f);
1620
1621 if(DoButton_CheckBox(pId: &g_Config.m_ClVideoShowhud, pText: Localize(pStr: "Show ingame HUD"), Checked: g_Config.m_ClVideoShowhud, pRect: &ShowHudButton))
1622 g_Config.m_ClVideoShowhud ^= 1;
1623
1624 // slowdown
1625 CUIRect SlowDownButton;
1626 Row.VSplitLeft(Cut: 20.0f, pLeft: &SlowDownButton, pRight: &Row);
1627 Row.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Row);
1628 static CButtonContainer s_SlowDownButton;
1629 if(Ui()->DoButton_FontIcon(pButtonContainer: &s_SlowDownButton, pText: FontIcon::BACKWARD, Checked: 0, pRect: &SlowDownButton, Flags: BUTTONFLAG_LEFT))
1630 m_Speed = std::clamp(val: m_Speed - 1, lo: 0, hi: (int)(std::size(DEMO_SPEEDS) - 1));
1631
1632 // paused
1633 CUIRect PausedButton;
1634 Row.VSplitLeft(Cut: 20.0f, pLeft: &PausedButton, pRight: &Row);
1635 Row.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Row);
1636 static CButtonContainer s_PausedButton;
1637 if(Ui()->DoButton_FontIcon(pButtonContainer: &s_PausedButton, pText: FontIcon::PAUSE, Checked: 0, pRect: &PausedButton, Flags: BUTTONFLAG_LEFT))
1638 m_StartPaused ^= 1;
1639
1640 // fastforward
1641 CUIRect FastForwardButton;
1642 Row.VSplitLeft(Cut: 20.0f, pLeft: &FastForwardButton, pRight: &Row);
1643 Row.VSplitLeft(Cut: 8.0f, pLeft: nullptr, pRight: &Row);
1644 static CButtonContainer s_FastForwardButton;
1645 if(Ui()->DoButton_FontIcon(pButtonContainer: &s_FastForwardButton, pText: FontIcon::FORWARD, Checked: 0, pRect: &FastForwardButton, Flags: BUTTONFLAG_LEFT))
1646 m_Speed = std::clamp(val: m_Speed + 1, lo: 0, hi: (int)(std::size(DEMO_SPEEDS) - 1));
1647
1648 // speed meter
1649 char aBuffer[128];
1650 const char *pPaused = m_StartPaused ? Localize(pStr: "(paused)") : "";
1651 str_format(buffer: aBuffer, buffer_size: sizeof(aBuffer), format: "%s: ×%g %s", Localize(pStr: "Speed"), DEMO_SPEEDS[m_Speed], pPaused);
1652 Ui()->DoLabel(pRect: &Row, pText: aBuffer, Size: 12.8f, Align: TEXTALIGN_ML);
1653 Box.HSplitBottom(Cut: 16.0f, pTop: &Box, pBottom: nullptr);
1654 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Row);
1655
1656 CUIRect Label, TextBox;
1657 Row.VSplitLeft(Cut: 110.0f, pLeft: &Label, pRight: &TextBox);
1658 TextBox.VSplitLeft(Cut: 10.0f, pLeft: nullptr, pRight: &TextBox);
1659 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Video name:"), Size: 12.8f, Align: TEXTALIGN_ML);
1660 Ui()->DoEditBox(pLineInput: &m_DemoRenderInput, pRect: &TextBox, FontSize: 12.8f);
1661
1662 // Warn about disconnect if online
1663 if(Client()->State() == IClient::STATE_ONLINE)
1664 {
1665 Box.HSplitBottom(Cut: 10.0f, pTop: &Box, pBottom: nullptr);
1666 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: &Row);
1667 SLabelProperties LabelProperties;
1668 LabelProperties.SetColor(ColorRGBA(1.0f, 0.0f, 0.0f));
1669 Ui()->DoLabel(pRect: &Row, pText: Localize(pStr: "You will be disconnected from the server."), Size: 12.8f, Align: TEXTALIGN_MC, LabelProps: LabelProperties);
1670 }
1671 }
1672 else if(m_Popup == POPUP_RENDER_DONE)
1673 {
1674 CUIRect Ok, OpenFolder;
1675
1676 char aFilePath[IO_MAX_PATH_LENGTH];
1677 char aSaveFolder[IO_MAX_PATH_LENGTH];
1678 Storage()->GetCompletePath(Type: IStorage::TYPE_SAVE, pDir: "videos", pBuffer: aSaveFolder, BufferSize: sizeof(aSaveFolder));
1679 str_format(buffer: aFilePath, buffer_size: sizeof(aFilePath), format: "%s/%s.mp4", aSaveFolder, m_DemoRenderInput.GetString());
1680
1681 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1682 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1683 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1684
1685 Part.VSplitMid(pLeft: &OpenFolder, pRight: &Ok);
1686
1687 Ok.VMargin(Cut: 20.0f, pOtherRect: &Ok);
1688 OpenFolder.VMargin(Cut: 20.0f, pOtherRect: &OpenFolder);
1689
1690 static CButtonContainer s_ButtonOpenFolder;
1691 if(DoButton_Menu(pButtonContainer: &s_ButtonOpenFolder, pText: Localize(pStr: "Videos directory"), Checked: 0, pRect: &OpenFolder))
1692 {
1693 Client()->ViewFile(pFilename: aSaveFolder);
1694 }
1695
1696 static CButtonContainer s_ButtonOk;
1697 if(DoButton_Menu(pButtonContainer: &s_ButtonOk, pText: Localize(pStr: "Ok"), Checked: 0, pRect: &Ok) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1698 {
1699 m_Popup = POPUP_NONE;
1700 m_DemoRenderInput.Clear();
1701 }
1702
1703 Box.HSplitBottom(Cut: 160.f, pTop: &Box, pBottom: &Part);
1704 Part.VMargin(Cut: 20.0f, pOtherRect: &Part);
1705
1706 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Video was saved to '%s'"), aFilePath);
1707
1708 SLabelProperties MessageProps;
1709 MessageProps.m_MaxWidth = (int)Part.w;
1710 Ui()->DoLabel(pRect: &Part, pText: aBuf, Size: 18.0f, Align: TEXTALIGN_TL, LabelProps: MessageProps);
1711 }
1712#endif
1713 else if(m_Popup == POPUP_FIRST_LAUNCH)
1714 {
1715 CUIRect Label, TextBox, Skip, Join;
1716
1717 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1718 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1719 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1720 Part.VSplitMid(pLeft: &Skip, pRight: &Join);
1721 Skip.VMargin(Cut: 20.0f, pOtherRect: &Skip);
1722 Join.VMargin(Cut: 20.0f, pOtherRect: &Join);
1723
1724 static CButtonContainer s_JoinTutorialButton;
1725 if(DoButton_Menu(pButtonContainer: &s_JoinTutorialButton, pText: Localize(pStr: "Join Tutorial Server"), Checked: 0, pRect: &Join) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1726 {
1727 Client()->RequestDDNetInfo();
1728 m_Popup = g_Config.m_BrIndicateFinished ? POPUP_POINTS : POPUP_NONE;
1729 JoinTutorial();
1730 }
1731
1732 static CButtonContainer s_SkipTutorialButton;
1733 if(DoButton_Menu(pButtonContainer: &s_SkipTutorialButton, pText: Localize(pStr: "Skip Tutorial"), Checked: 0, pRect: &Skip) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1734 {
1735 Client()->RequestDDNetInfo();
1736 m_JoinTutorial.m_Queued = false;
1737 m_Popup = g_Config.m_BrIndicateFinished ? POPUP_POINTS : POPUP_NONE;
1738 }
1739
1740 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1741 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1742
1743 Part.VSplitLeft(Cut: 30.0f, pLeft: nullptr, pRight: &Part);
1744 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s\n(%s)",
1745 Localize(pStr: "Show DDNet map finishes in server browser"),
1746 Localize(pStr: "transmits your player name to info.ddnet.org"));
1747
1748 if(DoButton_CheckBox(pId: &g_Config.m_BrIndicateFinished, pText: aBuf, Checked: g_Config.m_BrIndicateFinished, pRect: &Part))
1749 g_Config.m_BrIndicateFinished ^= 1;
1750
1751 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1752 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1753
1754 Part.VSplitLeft(Cut: 60.0f, pLeft: nullptr, pRight: &Label);
1755 Label.VSplitLeft(Cut: 100.0f, pLeft: nullptr, pRight: &TextBox);
1756 TextBox.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &TextBox);
1757 TextBox.VSplitRight(Cut: 60.0f, pLeft: &TextBox, pRight: nullptr);
1758 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Nickname"), Size: 16.0f, Align: TEXTALIGN_ML);
1759 static CLineInput s_PlayerNameInput(g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName));
1760 s_PlayerNameInput.SetEmptyText(Client()->PlayerName());
1761 Ui()->DoEditBox(pLineInput: &s_PlayerNameInput, pRect: &TextBox, FontSize: 12.0f);
1762 }
1763 else if(m_Popup == POPUP_JOIN_TUTORIAL)
1764 {
1765 CUIRect ButtonBar, StatusLabel, ProgressLabel, ProgressIndicator;
1766 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1767 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &ButtonBar);
1768 ButtonBar.VMargin(Cut: 120.0f, pOtherRect: &ButtonBar);
1769 Box.HSplitBottom(Cut: 20.0f, pTop: &StatusLabel, pBottom: nullptr);
1770 StatusLabel.VMargin(Cut: 20.0f, pOtherRect: &StatusLabel);
1771 StatusLabel.HSplitMid(pTop: &StatusLabel, pBottom: &ProgressLabel);
1772 ProgressLabel.VSplitLeft(Cut: 50.0f, pLeft: &ProgressIndicator, pRight: &ProgressLabel);
1773
1774 if(m_JoinTutorial.m_Status == CJoinTutorial::EStatus::REFRESHING)
1775 {
1776 if(ServerBrowser()->IsGettingServerlist() ||
1777 Client()->InfoState() == IClient::EInfoState::LOADING)
1778 {
1779 // Still refreshing
1780 }
1781 else if(ServerBrowser()->IsServerlistError() ||
1782 Client()->InfoState() == IClient::EInfoState::ERROR)
1783 {
1784 m_JoinTutorial.m_Status = CJoinTutorial::EStatus::SERVER_LIST_ERROR;
1785 }
1786 else
1787 {
1788 const char *pAddr = ServerBrowser()->GetTutorialServer();
1789 if(pAddr)
1790 {
1791 Client()->Connect(pAddress: pAddr);
1792 }
1793 else
1794 {
1795 m_JoinTutorial.m_Status = CJoinTutorial::EStatus::NO_TUTORIAL_AVAILABLE;
1796 }
1797 }
1798 }
1799
1800 const char *pStatusLabel = nullptr;
1801 switch(m_JoinTutorial.m_Status)
1802 {
1803 case CJoinTutorial::EStatus::REFRESHING:
1804 pStatusLabel = Localize(pStr: "Getting server list from master server");
1805 break;
1806 case CJoinTutorial::EStatus::SERVER_LIST_ERROR:
1807 pStatusLabel = Localize(pStr: "Could not get server list from master server");
1808 break;
1809 case CJoinTutorial::EStatus::NO_TUTORIAL_AVAILABLE:
1810 pStatusLabel = Localize(pStr: "There are no Tutorial servers available");
1811 break;
1812 }
1813 if(pStatusLabel != nullptr)
1814 {
1815 Ui()->DoLabel(pRect: &StatusLabel, pText: pStatusLabel, Size: 20.0f, Align: TEXTALIGN_ML);
1816 }
1817
1818 const char *pProgressLabel = nullptr;
1819 bool ProgressDeterminate = true;
1820 const float LastStateChangeSeconds = std::chrono::duration_cast<std::chrono::duration<float>>(d: time_get_nanoseconds() - m_JoinTutorial.m_StateChange).count();
1821 constexpr float RefreshDelay = 5.0f;
1822
1823 if(m_JoinTutorial.m_Status == CJoinTutorial::EStatus::REFRESHING)
1824 {
1825 pProgressLabel = Localize(pStr: "Please wait…");
1826 ProgressDeterminate = false;
1827 }
1828 else if(!m_JoinTutorial.m_TryRefresh)
1829 {
1830 if(!m_JoinTutorial.m_TriedRefresh)
1831 {
1832 m_JoinTutorial.m_TryRefresh = true;
1833 m_JoinTutorial.m_StateChange = time_get_nanoseconds();
1834 }
1835 else if(m_JoinTutorial.m_LocalServerState == CJoinTutorial::ELocalServerState::NOT_TRIED)
1836 {
1837 m_JoinTutorial.m_LocalServerState = CJoinTutorial::ELocalServerState::TRY;
1838 m_JoinTutorial.m_StateChange = time_get_nanoseconds();
1839 }
1840 }
1841
1842 if(m_JoinTutorial.m_TryRefresh)
1843 {
1844 if(LastStateChangeSeconds >= RefreshDelay)
1845 {
1846 // Activate internet tab before joining tutorial to make sure the server info
1847 // for the tutorial servers is available.
1848 GameClient()->m_Menus.SetMenuPage(CMenus::PAGE_INTERNET);
1849 GameClient()->m_Menus.RefreshBrowserTab(Force: true);
1850 m_JoinTutorial.m_Status = CJoinTutorial::EStatus::REFRESHING;
1851 m_JoinTutorial.m_TryRefresh = false;
1852 m_JoinTutorial.m_TriedRefresh = true;
1853 m_JoinTutorial.m_StateChange = time_get_nanoseconds();
1854 }
1855 else
1856 {
1857 pProgressLabel = Localize(pStr: "Retrying…");
1858 }
1859 }
1860
1861 const auto &&ShowFinalErrorMessage = [&]() {
1862 PopupMessage(pTitle: Localize(pStr: "Error joining Tutorial server"), pMessage: Localize(pStr: "Could not find a Tutorial server. Check your internet connection."), pButtonLabel: Localize(pStr: "Ok"));
1863 };
1864 const auto &&RunServer = [&]() {
1865 char aMotd[256];
1866 str_copy(dst&: aMotd, src: "sv_motd \"");
1867 char *pDst = aMotd + str_length(str: aMotd);
1868 str_escape(dst: &pDst, src: Localize(pStr: "You're playing on a local server because no online Tutorial server could be found.\n\nYour record will only be saved locally."), end: aMotd + sizeof(aMotd) - 1);
1869 str_append(dst&: aMotd, src: "\"");
1870 if(GameClient()->m_LocalServer.RunServer(vpArguments: {"sv_register 0", "sv_map Tutorial", aMotd}))
1871 {
1872 m_JoinTutorial.m_LocalServerState = CJoinTutorial::ELocalServerState::WAITING_START;
1873 m_JoinTutorial.m_StateChange = time_get_nanoseconds();
1874 }
1875 else
1876 {
1877 ShowFinalErrorMessage();
1878 }
1879 };
1880 if(m_JoinTutorial.m_LocalServerState == CJoinTutorial::ELocalServerState::TRY)
1881 {
1882 if(LastStateChangeSeconds >= RefreshDelay)
1883 {
1884 if(GameClient()->m_LocalServer.IsServerRunning())
1885 {
1886 GameClient()->m_LocalServer.KillServer();
1887 m_JoinTutorial.m_LocalServerState = CJoinTutorial::ELocalServerState::WAITING_STOP;
1888 m_JoinTutorial.m_StateChange = time_get_nanoseconds();
1889 }
1890 else
1891 {
1892 RunServer();
1893 }
1894 }
1895 else
1896 {
1897 pProgressLabel = Localize(pStr: "Could not find online Tutorial server.\nStarting and connecting to local server…");
1898 }
1899 }
1900 else if(m_JoinTutorial.m_LocalServerState == CJoinTutorial::ELocalServerState::WAITING_STOP)
1901 {
1902 if(LastStateChangeSeconds >= 5.0f)
1903 {
1904 ShowFinalErrorMessage();
1905 }
1906 else
1907 {
1908 if(!GameClient()->m_LocalServer.IsServerRunning())
1909 {
1910 RunServer();
1911 }
1912
1913 pProgressLabel = Localize(pStr: "Waiting for local server to stop…");
1914 ProgressDeterminate = false;
1915 }
1916 }
1917 else if(m_JoinTutorial.m_LocalServerState == CJoinTutorial::ELocalServerState::WAITING_START)
1918 {
1919 if(LastStateChangeSeconds >= 5.0f && !GameClient()->m_LocalServer.IsStarting())
1920 {
1921 ShowFinalErrorMessage();
1922 }
1923 else
1924 {
1925 if(LastStateChangeSeconds >= 2.0f &&
1926 GameClient()->m_LocalServer.IsServerRunning())
1927 {
1928 GameClient()->m_LocalServer.Connect();
1929 }
1930
1931 pProgressLabel = Localize(pStr: "Waiting for local server to start…");
1932 ProgressDeterminate = false;
1933 }
1934 }
1935
1936 if(pProgressLabel != nullptr)
1937 {
1938 Ui()->RenderProgressSpinner(Center: ProgressIndicator.Center(), OuterRadius: 12.0f, Props: {.m_Progress = ProgressDeterminate ? (LastStateChangeSeconds / RefreshDelay) : -1.0f});
1939 Ui()->DoLabel(pRect: &ProgressLabel, pText: pProgressLabel, Size: 20.0f, Align: TEXTALIGN_ML);
1940 }
1941
1942 static CButtonContainer s_Button;
1943 if(DoButton_Menu(pButtonContainer: &s_Button, pText: Localize(pStr: "Cancel"), Checked: 0, pRect: &ButtonBar) ||
1944 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE) ||
1945 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1946 {
1947 GameClient()->m_LocalServer.CancelConnect();
1948 m_Popup = POPUP_NONE;
1949 }
1950 }
1951 else if(m_Popup == POPUP_POINTS)
1952 {
1953 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1954 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1955 Part.VMargin(Cut: 120.0f, pOtherRect: &Part);
1956
1957 if(Client()->InfoState() == IClient::EInfoState::SUCCESS && Client()->Points() > 50)
1958 {
1959 CUIRect Yes, No;
1960 Part.VSplitMid(pLeft: &No, pRight: &Yes, Spacing: 40.0f);
1961 static CButtonContainer s_ButtonNo;
1962 if(DoButton_Menu(pButtonContainer: &s_ButtonNo, pText: Localize(pStr: "No"), Checked: 0, pRect: &No) ||
1963 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1964 {
1965 m_Popup = POPUP_FIRST_LAUNCH;
1966 }
1967
1968 static CButtonContainer s_ButtonYes;
1969 if(DoButton_Menu(pButtonContainer: &s_ButtonYes, pText: Localize(pStr: "Yes"), Checked: 0, pRect: &Yes) ||
1970 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1971 {
1972 m_Popup = POPUP_NONE;
1973 }
1974 }
1975 else
1976 {
1977 static CButtonContainer s_Button;
1978 if(DoButton_Menu(pButtonContainer: &s_Button, pText: Localize(pStr: "Cancel"), Checked: 0, pRect: &Part) ||
1979 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE) ||
1980 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER) ||
1981 Client()->InfoState() == IClient::EInfoState::SUCCESS)
1982 {
1983 m_Popup = POPUP_NONE;
1984 }
1985 if(Client()->InfoState() == IClient::EInfoState::ERROR)
1986 {
1987 PopupMessage(pTitle: Localize(pStr: "Error checking player name"), pMessage: Localize(pStr: "Could not check for existing player with your name. Check your internet connection."), pButtonLabel: Localize(pStr: "Ok"));
1988 }
1989 }
1990 }
1991 else if(m_Popup == POPUP_WARNING)
1992 {
1993 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1994 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1995 Part.VMargin(Cut: 120.0f, pOtherRect: &Part);
1996
1997 static CButtonContainer s_Button;
1998 if(DoButton_Menu(pButtonContainer: &s_Button, pText: pButtonText, Checked: 0, pRect: &Part) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER) || (m_PopupWarningDuration > 0s && time_get_nanoseconds() - m_PopupWarningLastTime >= m_PopupWarningDuration))
1999 {
2000 m_Popup = POPUP_NONE;
2001 SetActive(false);
2002 }
2003 }
2004 else if(m_Popup == POPUP_SAVE_SKIN)
2005 {
2006 CUIRect Label, TextBox, Yes, No;
2007
2008 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
2009 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
2010 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
2011
2012 Part.VSplitMid(pLeft: &No, pRight: &Yes);
2013
2014 Yes.VMargin(Cut: 20.0f, pOtherRect: &Yes);
2015 No.VMargin(Cut: 20.0f, pOtherRect: &No);
2016
2017 static CButtonContainer s_ButtonNo;
2018 if(DoButton_Menu(pButtonContainer: &s_ButtonNo, pText: Localize(pStr: "No"), Checked: 0, pRect: &No) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
2019 m_Popup = POPUP_NONE;
2020
2021 static CButtonContainer s_ButtonYes;
2022 if(DoButton_Menu(pButtonContainer: &s_ButtonYes, pText: Localize(pStr: "Yes"), Checked: m_SkinNameInput.IsEmpty() ? 1 : 0, pRect: &Yes) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
2023 {
2024 if(!str_valid_filename(str: m_SkinNameInput.GetString()))
2025 {
2026 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "This name cannot be used for files and folders"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_SAVE_SKIN);
2027 }
2028 else if(CSkins7::IsSpecialSkin(pName: m_SkinNameInput.GetString()))
2029 {
2030 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "Unable to save the skin with a reserved name"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_SAVE_SKIN);
2031 }
2032 else if(!GameClient()->m_Skins7.SaveSkinfile(pName: m_SkinNameInput.GetString(), Dummy: m_Dummy))
2033 {
2034 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "Unable to save the skin"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_SAVE_SKIN);
2035 }
2036 else
2037 {
2038 m_Popup = POPUP_NONE;
2039 m_SkinList7LastRefreshTime = std::nullopt;
2040 }
2041 }
2042
2043 Box.HSplitBottom(Cut: 60.f, pTop: &Box, pBottom: &Part);
2044 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
2045
2046 Part.VMargin(Cut: 60.0f, pOtherRect: &Label);
2047 Label.VSplitLeft(Cut: 100.0f, pLeft: &Label, pRight: &TextBox);
2048 TextBox.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &TextBox);
2049 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Name"), Size: 18.0f, Align: TEXTALIGN_ML);
2050 Ui()->DoClearableEditBox(pLineInput: &m_SkinNameInput, pRect: &TextBox, FontSize: 12.0f);
2051 }
2052 else
2053 {
2054 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
2055 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
2056 Part.VMargin(Cut: 120.0f, pOtherRect: &Part);
2057
2058 static CButtonContainer s_Button;
2059 if(DoButton_Menu(pButtonContainer: &s_Button, pText: pButtonText, Checked: 0, pRect: &Part) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
2060 {
2061 if(m_Popup == POPUP_DISCONNECTED && Client()->ReconnectTime() > 0)
2062 Client()->SetReconnectTime(0);
2063 m_Popup = POPUP_NONE;
2064 }
2065 }
2066
2067 if(m_Popup == POPUP_NONE)
2068 Ui()->SetActiveItem(nullptr);
2069}
2070
2071void CMenus::RenderPopupConnecting(CUIRect Screen)
2072{
2073 const float FontSize = 20.0f;
2074
2075 CUIRect Box, Label;
2076 Screen.Margin(Cut: 150.0f, pOtherRect: &Box);
2077 Box.Draw(Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners: IGraphics::CORNER_ALL, Rounding: 15.0f);
2078 Box.Margin(Cut: 20.0f, pOtherRect: &Box);
2079
2080 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2081 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Connecting to"), Size: 24.0f, Align: TEXTALIGN_MC);
2082
2083 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
2084 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2085 SLabelProperties Props;
2086 Props.m_MaxWidth = Label.w;
2087 Props.m_EllipsisAtEnd = true;
2088 Ui()->DoLabel(pRect: &Label, pText: Client()->ConnectAddressString(), Size: FontSize, Align: TEXTALIGN_MC, LabelProps: Props);
2089
2090 if(time_get() - Client()->StateStartTime() > time_freq())
2091 {
2092 const char *pConnectivityLabel = "";
2093 switch(Client()->UdpConnectivity(NetType: Client()->ConnectNetTypes()))
2094 {
2095 case IClient::EConnectivity::UNKNOWN:
2096 break;
2097 case IClient::EConnectivity::CHECKING:
2098 pConnectivityLabel = Localize(pStr: "Trying to determine UDP connectivity…");
2099 break;
2100 case IClient::EConnectivity::UNREACHABLE:
2101 pConnectivityLabel = Localize(pStr: "UDP seems to be filtered.");
2102 break;
2103 case IClient::EConnectivity::DIFFERING_UDP_TCP_IP_ADDRESSES:
2104 pConnectivityLabel = Localize(pStr: "UDP and TCP IP addresses seem to be different. Try disabling VPN, proxy or network accelerators.");
2105 break;
2106 case IClient::EConnectivity::REACHABLE:
2107 pConnectivityLabel = Localize(pStr: "No answer from server yet.");
2108 break;
2109 }
2110 if(pConnectivityLabel[0] != '\0')
2111 {
2112 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
2113 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2114 SLabelProperties ConnectivityLabelProps;
2115 ConnectivityLabelProps.m_MaxWidth = Label.w;
2116 if(TextRender()->TextWidth(Size: FontSize, pText: pConnectivityLabel) > Label.w)
2117 Ui()->DoLabel(pRect: &Label, pText: pConnectivityLabel, Size: FontSize, Align: TEXTALIGN_ML, LabelProps: ConnectivityLabelProps);
2118 else
2119 Ui()->DoLabel(pRect: &Label, pText: pConnectivityLabel, Size: FontSize, Align: TEXTALIGN_MC);
2120 }
2121 }
2122
2123 CUIRect Button;
2124 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Button);
2125 Button.VMargin(Cut: 100.0f, pOtherRect: &Button);
2126
2127 static CButtonContainer s_Button;
2128 if(DoButton_Menu(pButtonContainer: &s_Button, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Button) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
2129 {
2130 Client()->Disconnect();
2131 Ui()->SetActiveItem(nullptr);
2132 RefreshBrowserTab(Force: true);
2133 }
2134}
2135
2136void CMenus::RenderPopupLoading(CUIRect Screen)
2137{
2138 char aTitle[256];
2139 char aLabel1[128];
2140 char aLabel2[128];
2141 if(Client()->MapDownloadTotalsize() > 0)
2142 {
2143 const int64_t Now = time_get();
2144 if(Now - m_DownloadLastCheckTime >= time_freq())
2145 {
2146 if(m_DownloadLastCheckSize > Client()->MapDownloadAmount())
2147 {
2148 // map downloaded restarted
2149 m_DownloadLastCheckSize = 0;
2150 }
2151
2152 // update download speed
2153 const float Diff = (Client()->MapDownloadAmount() - m_DownloadLastCheckSize) / ((int)((Now - m_DownloadLastCheckTime) / time_freq()));
2154 const float StartDiff = m_DownloadLastCheckSize - 0.0f;
2155 if(StartDiff + Diff > 0.0f)
2156 m_DownloadSpeed = (Diff / (StartDiff + Diff)) * (Diff / 1.0f) + (StartDiff / (Diff + StartDiff)) * m_DownloadSpeed;
2157 else
2158 m_DownloadSpeed = 0.0f;
2159 m_DownloadLastCheckTime = Now;
2160 m_DownloadLastCheckSize = Client()->MapDownloadAmount();
2161 }
2162
2163 str_format(buffer: aTitle, buffer_size: sizeof(aTitle), format: "%s: %s", Localize(pStr: "Downloading map"), Client()->MapDownloadName());
2164
2165 str_format(buffer: aLabel1, buffer_size: sizeof(aLabel1), format: Localize(pStr: "%d/%d KiB (%.1f KiB/s)"), Client()->MapDownloadAmount() / 1024, Client()->MapDownloadTotalsize() / 1024, m_DownloadSpeed / 1024.0f);
2166
2167 const int SecondsLeft = std::max(a: 1, b: m_DownloadSpeed > 0.0f ? static_cast<int>((Client()->MapDownloadTotalsize() - Client()->MapDownloadAmount()) / m_DownloadSpeed) : 1);
2168 const int MinutesLeft = SecondsLeft / 60;
2169 if(MinutesLeft > 0)
2170 {
2171 str_format(buffer: aLabel2, buffer_size: sizeof(aLabel2), format: MinutesLeft == 1 ? Localize(pStr: "%i minute left") : Localize(pStr: "%i minutes left"), MinutesLeft);
2172 }
2173 else
2174 {
2175 str_format(buffer: aLabel2, buffer_size: sizeof(aLabel2), format: SecondsLeft == 1 ? Localize(pStr: "%i second left") : Localize(pStr: "%i seconds left"), SecondsLeft);
2176 }
2177 }
2178 else
2179 {
2180 str_copy(dst&: aTitle, src: Localize(pStr: "Connected"));
2181 switch(Client()->LoadingStateDetail())
2182 {
2183 case IClient::ELoadingStateDetail::INITIAL:
2184 str_copy(dst&: aLabel1, src: Localize(pStr: "Getting game info"));
2185 break;
2186 case IClient::ELoadingStateDetail::LOADING_MAP:
2187 str_copy(dst&: aLabel1, src: Localize(pStr: "Loading map file from storage"));
2188 break;
2189 case IClient::ELoadingStateDetail::LOADING_DEMO:
2190 str_copy(dst&: aLabel1, src: Localize(pStr: "Loading demo file from storage"));
2191 break;
2192 case IClient::ELoadingStateDetail::SENDING_READY:
2193 str_copy(dst&: aLabel1, src: Localize(pStr: "Requesting to join the game"));
2194 break;
2195 case IClient::ELoadingStateDetail::GETTING_READY:
2196 str_copy(dst&: aLabel1, src: Localize(pStr: "Sending initial client info"));
2197 break;
2198 default:
2199 dbg_assert_failed("Invalid loading state %d for RenderPopupLoading", static_cast<int>(Client()->LoadingStateDetail()));
2200 }
2201 aLabel2[0] = '\0';
2202 }
2203
2204 const float FontSize = 20.0f;
2205
2206 CUIRect Box, Label;
2207 Screen.Margin(Cut: 150.0f, pOtherRect: &Box);
2208 Box.Draw(Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners: IGraphics::CORNER_ALL, Rounding: 15.0f);
2209 Box.Margin(Cut: 20.0f, pOtherRect: &Box);
2210
2211 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2212 Ui()->DoLabel(pRect: &Label, pText: aTitle, Size: 24.0f, Align: TEXTALIGN_MC);
2213
2214 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
2215 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2216 Ui()->DoLabel(pRect: &Label, pText: aLabel1, Size: FontSize, Align: TEXTALIGN_MC);
2217
2218 if(aLabel2[0] != '\0')
2219 {
2220 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
2221 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2222 SLabelProperties ExtraTextProps;
2223 ExtraTextProps.m_MaxWidth = Label.w;
2224 if(TextRender()->TextWidth(Size: FontSize, pText: aLabel2) > Label.w)
2225 Ui()->DoLabel(pRect: &Label, pText: aLabel2, Size: FontSize, Align: TEXTALIGN_ML, LabelProps: ExtraTextProps);
2226 else
2227 Ui()->DoLabel(pRect: &Label, pText: aLabel2, Size: FontSize, Align: TEXTALIGN_MC);
2228 }
2229
2230 if(Client()->MapDownloadTotalsize() > 0)
2231 {
2232 CUIRect ProgressBar;
2233 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
2234 Box.HSplitTop(Cut: 24.0f, pTop: &ProgressBar, pBottom: &Box);
2235 ProgressBar.VMargin(Cut: 20.0f, pOtherRect: &ProgressBar);
2236 Ui()->RenderProgressBar(ProgressBar, Progress: Client()->MapDownloadAmount() / (float)Client()->MapDownloadTotalsize());
2237 }
2238
2239 CUIRect Button;
2240 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Button);
2241 Button.VMargin(Cut: 100.0f, pOtherRect: &Button);
2242
2243 static CButtonContainer s_Button;
2244 if(DoButton_Menu(pButtonContainer: &s_Button, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Button) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
2245 {
2246 Client()->Disconnect();
2247 Ui()->SetActiveItem(nullptr);
2248 RefreshBrowserTab(Force: true);
2249 }
2250}
2251
2252#if defined(CONF_VIDEORECORDER)
2253void CMenus::PopupConfirmDemoReplaceVideo()
2254{
2255 char aBuf[IO_MAX_PATH_LENGTH];
2256 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s/%s.demo", m_aCurrentDemoFolder, m_aCurrentDemoSelectionName);
2257 char aVideoName[IO_MAX_PATH_LENGTH];
2258 str_copy(dst&: aVideoName, src: m_DemoRenderInput.GetString());
2259 const char *pError = Client()->DemoPlayer_Render(pFilename: aBuf, StorageType: m_DemolistStorageType, pVideoName: aVideoName, SpeedIndex: m_Speed, StartPaused: m_StartPaused);
2260 m_Speed = DEMO_SPEED_INDEX_DEFAULT;
2261 m_StartPaused = false;
2262 m_LastPauseChange = -1.0f;
2263 m_LastSpeedChange = -1.0f;
2264 if(pError)
2265 {
2266 m_DemoRenderInput.Clear();
2267 PopupMessage(pTitle: Localize(pStr: "Error loading demo"), pMessage: pError, pButtonLabel: Localize(pStr: "Ok"));
2268 }
2269}
2270#endif
2271
2272void CMenus::SetActive(bool Active)
2273{
2274 if(Active != m_MenuActive)
2275 {
2276 Ui()->SetHotItem(nullptr);
2277 Ui()->SetActiveItem(nullptr);
2278 }
2279 m_MenuActive = Active;
2280 if(!m_MenuActive)
2281 {
2282 if(m_NeedSendinfo)
2283 {
2284 GameClient()->SendInfo(Start: false);
2285 m_NeedSendinfo = false;
2286 }
2287
2288 if(m_NeedSendDummyinfo)
2289 {
2290 GameClient()->SendDummyInfo(Start: false);
2291 m_NeedSendDummyinfo = false;
2292 }
2293
2294 if(Client()->State() == IClient::STATE_ONLINE)
2295 {
2296 GameClient()->OnRelease();
2297 }
2298 }
2299 else if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
2300 {
2301 GameClient()->OnRelease();
2302 }
2303}
2304
2305void CMenus::OnShutdown()
2306{
2307 m_CommunityIcons.Shutdown();
2308}
2309
2310bool CMenus::OnCursorMove(float x, float y, IInput::ECursorType CursorType)
2311{
2312 if(!m_MenuActive)
2313 return false;
2314
2315 Ui()->ConvertMouseMove(pX: &x, pY: &y, CursorType);
2316 Ui()->OnCursorMove(X: x, Y: y);
2317
2318 return true;
2319}
2320
2321bool CMenus::OnInput(const IInput::CEvent &Event)
2322{
2323 // Escape key is always handled to activate/deactivate menu
2324 if((Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE) || IsActive())
2325 {
2326 Ui()->OnInput(Event);
2327 return true;
2328 }
2329 return false;
2330}
2331
2332void CMenus::OnStateChange(int NewState, int OldState)
2333{
2334 // reset active item
2335 Ui()->SetActiveItem(nullptr);
2336
2337 if(OldState == IClient::STATE_ONLINE || OldState == IClient::STATE_OFFLINE)
2338 TextRender()->DeleteTextContainer(TextContainerIndex&: m_MotdTextContainerIndex);
2339
2340 if(NewState == IClient::STATE_OFFLINE)
2341 {
2342 if(OldState >= IClient::STATE_ONLINE && NewState < IClient::STATE_QUITTING)
2343 UpdateMusicState();
2344 m_Popup = POPUP_NONE;
2345 if(Client()->ErrorString() && Client()->ErrorString()[0] != 0)
2346 {
2347 if(str_find(haystack: Client()->ErrorString(), needle: "password"))
2348 {
2349 m_Popup = POPUP_PASSWORD;
2350 m_PasswordInput.SelectAll();
2351 Ui()->SetActiveItem(&m_PasswordInput);
2352 }
2353 else
2354 {
2355 m_Popup = POPUP_DISCONNECTED;
2356 }
2357 }
2358 }
2359 else if(NewState == IClient::STATE_LOADING)
2360 {
2361 m_DownloadLastCheckTime = time_get();
2362 m_DownloadLastCheckSize = 0;
2363 m_DownloadSpeed = 0.0f;
2364 }
2365 else if(NewState == IClient::STATE_ONLINE || NewState == IClient::STATE_DEMOPLAYBACK)
2366 {
2367 if(m_Popup != POPUP_WARNING)
2368 {
2369 m_Popup = POPUP_NONE;
2370 SetActive(false);
2371 }
2372 }
2373}
2374
2375void CMenus::OnWindowResize()
2376{
2377 TextRender()->DeleteTextContainer(TextContainerIndex&: m_MotdTextContainerIndex);
2378}
2379
2380void CMenus::OnRender()
2381{
2382 if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
2383 SetActive(true);
2384
2385 if(Client()->State() == IClient::STATE_ONLINE && GameClient()->m_ServerMode == CGameClient::SERVERMODE_PUREMOD)
2386 {
2387 Client()->Disconnect();
2388 SetActive(true);
2389 PopupMessage(pTitle: Localize(pStr: "Disconnected"), pMessage: Localize(pStr: "The server is running a non-standard tuning on a pure game type."), pButtonLabel: Localize(pStr: "Ok"));
2390 }
2391
2392 if(!IsActive())
2393 {
2394 if(Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
2395 {
2396 SetActive(true);
2397 }
2398 else if(Client()->State() != IClient::STATE_DEMOPLAYBACK)
2399 {
2400 Ui()->ClearHotkeys();
2401 return;
2402 }
2403 }
2404
2405 Ui()->StartCheck();
2406 UpdateColors();
2407
2408 Ui()->Update();
2409
2410 if(IsActive())
2411 Ui()->DoBackButton();
2412
2413 Render();
2414
2415 if(IsActive())
2416 {
2417 Ui()->RenderBackButton();
2418 RenderTools()->RenderCursor(Center: Ui()->MousePos(), Size: 24.0f);
2419 }
2420
2421 // render debug information
2422 if(g_Config.m_Debug)
2423 Ui()->DebugRender(X: 2.0f, Y: Ui()->Screen()->h - 12.0f);
2424
2425 if(Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
2426 SetActive(false);
2427
2428 Ui()->FinishCheck();
2429 Ui()->ClearHotkeys();
2430}
2431
2432void CMenus::UpdateColors()
2433{
2434 ms_GuiColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_UiColor, true));
2435
2436 ms_ColorTabbarInactiveOutgame = ColorRGBA(0.0f, 0.0f, 0.0f, 0.25f);
2437 ms_ColorTabbarActiveOutgame = ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f);
2438 ms_ColorTabbarHoverOutgame = ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f);
2439
2440 const float ColorIngameScaleI = 0.5f;
2441 const float ColorIngameScaleA = 0.2f;
2442
2443 ms_ColorTabbarInactiveIngame = ColorRGBA(
2444 ms_GuiColor.r * ColorIngameScaleI,
2445 ms_GuiColor.g * ColorIngameScaleI,
2446 ms_GuiColor.b * ColorIngameScaleI,
2447 ms_GuiColor.a * 0.8f);
2448
2449 ms_ColorTabbarActiveIngame = ColorRGBA(
2450 ms_GuiColor.r * ColorIngameScaleA,
2451 ms_GuiColor.g * ColorIngameScaleA,
2452 ms_GuiColor.b * ColorIngameScaleA,
2453 ms_GuiColor.a);
2454
2455 ms_ColorTabbarHoverIngame = ColorRGBA(1.0f, 1.0f, 1.0f, 0.75f);
2456}
2457
2458void CMenus::RenderBackground()
2459{
2460 const float ScreenHeight = 300.0f;
2461 const float ScreenWidth = ScreenHeight * Graphics()->ScreenAspect();
2462 Graphics()->MapScreenToSize(Width: ScreenWidth, Height: ScreenHeight);
2463
2464 // render background color
2465 Graphics()->TextureClear();
2466 Graphics()->QuadsBegin();
2467 Graphics()->SetColor(ms_GuiColor.WithAlpha(alpha: 1.0f));
2468 const IGraphics::CQuadItem BackgroundQuadItem = IGraphics::CQuadItem(0, 0, ScreenWidth, ScreenHeight);
2469 Graphics()->QuadsDrawTL(pArray: &BackgroundQuadItem, Num: 1);
2470 Graphics()->QuadsEnd();
2471
2472 // render the tiles
2473 Graphics()->TextureClear();
2474 Graphics()->QuadsBegin();
2475 Graphics()->SetColor(r: 0.0f, g: 0.0f, b: 0.0f, a: 0.045f);
2476 const float Size = 15.0f;
2477 const float OffsetTime = std::fmod(x: Client()->GlobalTime() * 0.15f, y: 2.0f);
2478 IGraphics::CQuadItem aCheckerItems[64];
2479 size_t NumCheckerItems = 0;
2480 const int NumItemsWidth = std::ceil(x: ScreenWidth / Size);
2481 const int NumItemsHeight = std::ceil(x: ScreenHeight / Size);
2482 for(int y = -2; y < NumItemsHeight; y++)
2483 {
2484 for(int x = 0; x < NumItemsWidth + 4; x += 2)
2485 {
2486 aCheckerItems[NumCheckerItems] = IGraphics::CQuadItem((x - 2 * OffsetTime + (y & 1)) * Size, (y + OffsetTime) * Size, Size, Size);
2487 NumCheckerItems++;
2488 if(NumCheckerItems == std::size(aCheckerItems))
2489 {
2490 Graphics()->QuadsDrawTL(pArray: aCheckerItems, Num: NumCheckerItems);
2491 NumCheckerItems = 0;
2492 }
2493 }
2494 }
2495 if(NumCheckerItems != 0)
2496 Graphics()->QuadsDrawTL(pArray: aCheckerItems, Num: NumCheckerItems);
2497 Graphics()->QuadsEnd();
2498
2499 // render border fade
2500 Graphics()->TextureSet(Texture: m_TextureBlob);
2501 Graphics()->QuadsBegin();
2502 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
2503 const IGraphics::CQuadItem BlobQuadItem = IGraphics::CQuadItem(-100, -100, ScreenWidth + 200, ScreenHeight + 200);
2504 Graphics()->QuadsDrawTL(pArray: &BlobQuadItem, Num: 1);
2505 Graphics()->QuadsEnd();
2506
2507 // restore screen
2508 Ui()->MapScreen();
2509}
2510
2511int CMenus::DoButton_CheckBox_Tristate(const void *pId, const char *pText, TRISTATE Checked, const CUIRect *pRect)
2512{
2513 switch(Checked)
2514 {
2515 case TRISTATE::NONE:
2516 return DoButton_CheckBox_Common(pId, pText, pBoxText: "", pRect, Flags: BUTTONFLAG_LEFT);
2517 case TRISTATE::SOME:
2518 return DoButton_CheckBox_Common(pId, pText, pBoxText: "O", pRect, Flags: BUTTONFLAG_LEFT);
2519 case TRISTATE::ALL:
2520 return DoButton_CheckBox_Common(pId, pText, pBoxText: "X", pRect, Flags: BUTTONFLAG_LEFT);
2521 default:
2522 dbg_assert_failed("Invalid tristate. Checked: %d", static_cast<int>(Checked));
2523 }
2524}
2525
2526int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser)
2527{
2528 const char *pExtension = ".png";
2529 CMenuImage MenuImage;
2530 CMenus *pSelf = static_cast<CMenus *>(pUser);
2531 if(IsDir || !str_endswith(str: pName, suffix: pExtension) || str_length(str: pName) - str_length(str: pExtension) >= (int)sizeof(MenuImage.m_aName))
2532 return 0;
2533
2534 char aPath[IO_MAX_PATH_LENGTH];
2535 str_format(buffer: aPath, buffer_size: sizeof(aPath), format: "menuimages/%s", pName);
2536
2537 CImageInfo Info;
2538 if(!pSelf->Graphics()->LoadPng(Image&: Info, pFilename: aPath, StorageType: DirType))
2539 {
2540 log_error("menus", "Failed to load menu image from '%s'", aPath);
2541 return 0;
2542 }
2543 if(Info.m_Format != CImageInfo::FORMAT_RGBA)
2544 {
2545 Info.Free();
2546 log_error("menus", "Failed to load menu image from '%s': must be an RGBA image", aPath);
2547 return 0;
2548 }
2549
2550 MenuImage.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Image: Info, Flags: 0, pTexName: aPath);
2551
2552 ConvertToGrayscale(Image: Info);
2553 MenuImage.m_GreyTexture = pSelf->Graphics()->LoadTextureRawMove(Image&: Info, Flags: 0, pTexName: aPath);
2554
2555 str_truncate(dst: MenuImage.m_aName, dst_size: sizeof(MenuImage.m_aName), src: pName, truncation_len: str_length(str: pName) - str_length(str: pExtension));
2556 pSelf->m_vMenuImages.push_back(x: MenuImage);
2557
2558 pSelf->RenderLoading(pCaption: Localize(pStr: "Loading DDNet Client"), pContent: Localize(pStr: "Loading menu images"), IncreaseCounter: 0);
2559
2560 return 0;
2561}
2562
2563const CMenus::CMenuImage *CMenus::FindMenuImage(const char *pName)
2564{
2565 for(auto &Image : m_vMenuImages)
2566 if(str_comp(a: Image.m_aName, b: pName) == 0)
2567 return &Image;
2568 return nullptr;
2569}
2570
2571void CMenus::SetMenuPage(int NewPage)
2572{
2573 const int OldPage = m_MenuPage;
2574 m_MenuPage = NewPage;
2575 if(NewPage >= PAGE_INTERNET && NewPage <= PAGE_FAVORITE_COMMUNITY_5)
2576 {
2577 g_Config.m_UiPage = NewPage;
2578 bool ForceRefresh = false;
2579 if(m_ForceRefreshLanPage && NewPage == PAGE_LAN)
2580 {
2581 ForceRefresh = true;
2582 m_ForceRefreshLanPage = false;
2583 }
2584 if(OldPage != NewPage || ForceRefresh)
2585 {
2586 RefreshBrowserTab(Force: ForceRefresh);
2587 }
2588 }
2589}
2590
2591void CMenus::RefreshBrowserTab(bool Force)
2592{
2593 if(g_Config.m_UiPage == PAGE_INTERNET)
2594 {
2595 if(Force || ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_INTERNET)
2596 {
2597 if(Force || ServerBrowser()->GetCurrentType() == IServerBrowser::TYPE_LAN)
2598 {
2599 Client()->RequestDDNetInfo();
2600 }
2601 ServerBrowser()->Refresh(Type: IServerBrowser::TYPE_INTERNET);
2602 UpdateCommunityCache(Force: true);
2603 }
2604 }
2605 else if(g_Config.m_UiPage == PAGE_LAN)
2606 {
2607 if(Force || ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_LAN)
2608 {
2609 ServerBrowser()->Refresh(Type: IServerBrowser::TYPE_LAN);
2610 UpdateCommunityCache(Force: true);
2611 }
2612 }
2613 else if(g_Config.m_UiPage == PAGE_FAVORITES)
2614 {
2615 if(Force || ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_FAVORITES)
2616 {
2617 if(Force || ServerBrowser()->GetCurrentType() == IServerBrowser::TYPE_LAN)
2618 {
2619 Client()->RequestDDNetInfo();
2620 }
2621 ServerBrowser()->Refresh(Type: IServerBrowser::TYPE_FAVORITES);
2622 UpdateCommunityCache(Force: true);
2623 }
2624 }
2625 else if(g_Config.m_UiPage >= PAGE_FAVORITE_COMMUNITY_1 && g_Config.m_UiPage <= PAGE_FAVORITE_COMMUNITY_5)
2626 {
2627 const int BrowserType = g_Config.m_UiPage - PAGE_FAVORITE_COMMUNITY_1 + IServerBrowser::TYPE_FAVORITE_COMMUNITY_1;
2628 if(Force || ServerBrowser()->GetCurrentType() != BrowserType)
2629 {
2630 if(Force || ServerBrowser()->GetCurrentType() == IServerBrowser::TYPE_LAN)
2631 {
2632 Client()->RequestDDNetInfo();
2633 }
2634 ServerBrowser()->Refresh(Type: BrowserType);
2635 UpdateCommunityCache(Force: true);
2636 }
2637 }
2638}
2639
2640void CMenus::ForceRefreshLanPage()
2641{
2642 m_ForceRefreshLanPage = true;
2643}
2644
2645void CMenus::SetShowStart(bool ShowStart)
2646{
2647 m_ShowStart = ShowStart;
2648}
2649
2650void CMenus::ShowQuitPopup()
2651{
2652 m_Popup = POPUP_QUIT;
2653}
2654
2655void CMenus::JoinTutorial()
2656{
2657 m_JoinTutorial.m_Queued = true;
2658 m_JoinTutorial.m_Status = CJoinTutorial::EStatus::REFRESHING;
2659 m_JoinTutorial.m_TryRefresh = false;
2660 m_JoinTutorial.m_TriedRefresh = false;
2661 m_JoinTutorial.m_LocalServerState = CJoinTutorial::ELocalServerState::NOT_TRIED;
2662 m_JoinTutorial.m_StateChange = time_get_nanoseconds();
2663}
2664