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