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))
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()->ResetMouseSlow();
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
1399 // buttons
1400 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1401 Part.VSplitMid(pLeft: &No, pRight: &Yes);
1402 Yes.VMargin(Cut: 20.0f, pOtherRect: &Yes);
1403 No.VMargin(Cut: 20.0f, pOtherRect: &No);
1404
1405 static CButtonContainer s_ButtonAbort;
1406 if(DoButton_Menu(pButtonContainer: &s_ButtonAbort, pText: Localize(pStr: "No"), Checked: 0, pRect: &No) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1407 m_Popup = POPUP_NONE;
1408
1409 static CButtonContainer s_ButtonTryAgain;
1410 if(DoButton_Menu(pButtonContainer: &s_ButtonTryAgain, pText: Localize(pStr: "Yes"), Checked: 0, pRect: &Yes) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1411 {
1412 if(m_Popup == POPUP_RESTART)
1413 {
1414 m_Popup = POPUP_NONE;
1415 Client()->Restart();
1416 }
1417 else
1418 {
1419 m_Popup = POPUP_NONE;
1420 Client()->Quit();
1421 }
1422 }
1423 }
1424 else if(m_Popup == POPUP_PASSWORD)
1425 {
1426 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1427 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1428 Part.VMargin(Cut: 100.0f, pOtherRect: &Part);
1429
1430 CUIRect TryAgain, Abort;
1431 Part.VSplitMid(pLeft: &Abort, pRight: &TryAgain, Spacing: 40.0f);
1432
1433 static CButtonContainer s_ButtonAbort;
1434 if(DoButton_Menu(pButtonContainer: &s_ButtonAbort, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Abort) ||
1435 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1436 {
1437 m_Popup = POPUP_NONE;
1438 }
1439
1440 char aAddr[NETADDR_MAXSTRSIZE];
1441 net_addr_str(addr: &Client()->ServerAddress(), string: aAddr, max_length: sizeof(aAddr), add_port: true);
1442
1443 static CButtonContainer s_ButtonTryAgain;
1444 if(DoButton_Menu(pButtonContainer: &s_ButtonTryAgain, pText: Localize(pStr: "Try again"), Checked: 0, pRect: &TryAgain) ||
1445 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1446 {
1447 Client()->Connect(pAddress: aAddr, pPassword: g_Config.m_Password);
1448 }
1449
1450 Box.VMargin(Cut: 60.0f, pOtherRect: &Box);
1451 Box.HSplitBottom(Cut: 32.0f, pTop: &Box, pBottom: nullptr);
1452 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1453
1454 CUIRect Label, TextBox;
1455 Part.VSplitLeft(Cut: 100.0f, pLeft: &Label, pRight: &TextBox);
1456 TextBox.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &TextBox);
1457 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Password"), Size: 18.0f, Align: TEXTALIGN_ML);
1458 Ui()->DoClearableEditBox(pLineInput: &m_PasswordInput, pRect: &TextBox, FontSize: 12.0f);
1459
1460 Box.HSplitBottom(Cut: 32.0f, pTop: &Box, pBottom: nullptr);
1461 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1462
1463 CUIRect Address;
1464 Part.VSplitLeft(Cut: 100.0f, pLeft: &Label, pRight: &Address);
1465 Address.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &Address);
1466 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Address"), Size: 18.0f, Align: TEXTALIGN_ML);
1467 Ui()->DoLabel(pRect: &Address, pText: aAddr, Size: 18.0f, Align: TEXTALIGN_ML);
1468
1469 const CServerBrowser::CServerEntry *pEntry = ServerBrowser()->Find(Addr: Client()->ServerAddress());
1470 if(pEntry != nullptr && pEntry->m_GotInfo)
1471 {
1472 const CCommunity *pCommunity = ServerBrowser()->Community(pCommunityId: pEntry->m_Info.m_aCommunityId);
1473 const CCommunityIcon *pIcon = pCommunity == nullptr ? nullptr : m_CommunityIcons.Find(pCommunityId: pCommunity->Id());
1474
1475 Box.HSplitBottom(Cut: 32.0f, pTop: &Box, pBottom: nullptr);
1476 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1477
1478 CUIRect Name;
1479 Part.VSplitLeft(Cut: 100.0f, pLeft: &Label, pRight: &Name);
1480 Name.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &Name);
1481 if(pIcon != nullptr)
1482 {
1483 CUIRect Icon;
1484 static char s_CommunityTooltipButtonId;
1485 Name.VSplitLeft(Cut: 2.5f * Name.h, pLeft: &Icon, pRight: &Name);
1486 m_CommunityIcons.Render(pIcon, Rect: Icon, Active: true);
1487 Ui()->DoButtonLogic(pId: &s_CommunityTooltipButtonId, Checked: 0, pRect: &Icon, Flags: BUTTONFLAG_NONE);
1488 GameClient()->m_Tooltips.DoToolTip(pId: &s_CommunityTooltipButtonId, pNearRect: &Icon, pText: pCommunity->Name());
1489 }
1490
1491 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Name"), Size: 18.0f, Align: TEXTALIGN_ML);
1492 Ui()->DoLabel(pRect: &Name, pText: pEntry->m_Info.m_aName, Size: 18.0f, Align: TEXTALIGN_ML);
1493 }
1494 }
1495 else if(m_Popup == POPUP_LANGUAGE)
1496 {
1497 CUIRect Button;
1498 Screen.Margin(Cut: 150.0f, pOtherRect: &Box);
1499 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
1500 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1501 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Button);
1502 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1503 Box.VMargin(Cut: 20.0f, pOtherRect: &Box);
1504 const bool Activated = RenderLanguageSelection(MainView: Box);
1505 Button.VMargin(Cut: 120.0f, pOtherRect: &Button);
1506
1507 static CButtonContainer s_Button;
1508 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)
1509 m_Popup = POPUP_FIRST_LAUNCH;
1510 }
1511 else if(m_Popup == POPUP_RENAME_DEMO)
1512 {
1513 CUIRect Label, TextBox, Ok, Abort;
1514
1515 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1516 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1517 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1518
1519 Part.VSplitMid(pLeft: &Abort, pRight: &Ok);
1520
1521 Ok.VMargin(Cut: 20.0f, pOtherRect: &Ok);
1522 Abort.VMargin(Cut: 20.0f, pOtherRect: &Abort);
1523
1524 static CButtonContainer s_ButtonAbort;
1525 if(DoButton_Menu(pButtonContainer: &s_ButtonAbort, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Abort) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1526 m_Popup = POPUP_NONE;
1527
1528 static CButtonContainer s_ButtonOk;
1529 if(DoButton_Menu(pButtonContainer: &s_ButtonOk, pText: Localize(pStr: "Ok"), Checked: 0, pRect: &Ok) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1530 {
1531 m_Popup = POPUP_NONE;
1532 // rename demo
1533 char aBufOld[IO_MAX_PATH_LENGTH];
1534 str_format(buffer: aBufOld, buffer_size: sizeof(aBufOld), format: "%s/%s", m_aCurrentDemoFolder, m_vpFilteredDemos[m_DemolistSelectedIndex]->m_aFilename);
1535 char aBufNew[IO_MAX_PATH_LENGTH];
1536 str_format(buffer: aBufNew, buffer_size: sizeof(aBufNew), format: "%s/%s", m_aCurrentDemoFolder, m_DemoRenameInput.GetString());
1537 if(!m_vpFilteredDemos[m_DemolistSelectedIndex]->m_IsDir && !str_endswith(str: aBufNew, suffix: ".demo"))
1538 str_append(dst&: aBufNew, src: ".demo");
1539
1540 if(str_comp(a: aBufOld, b: aBufNew) == 0)
1541 {
1542 // Nothing to rename, also same capitalization
1543 }
1544 else if(!str_valid_filename(str: m_DemoRenameInput.GetString()))
1545 {
1546 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);
1547 }
1548 else if(str_utf8_comp_nocase(a: aBufOld, b: aBufNew) != 0 && // Allow renaming if it only changes capitalization to support case-insensitive filesystems
1549 Storage()->FileExists(pFilename: aBufNew, Type: m_vpFilteredDemos[m_DemolistSelectedIndex]->m_StorageType))
1550 {
1551 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "A demo with this name already exists"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENAME_DEMO);
1552 }
1553 else if(Storage()->FolderExists(pFilename: aBufNew, Type: m_vpFilteredDemos[m_DemolistSelectedIndex]->m_StorageType))
1554 {
1555 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "A folder with this name already exists"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENAME_DEMO);
1556 }
1557 else if(Storage()->RenameFile(pOldFilename: aBufOld, pNewFilename: aBufNew, Type: m_vpFilteredDemos[m_DemolistSelectedIndex]->m_StorageType))
1558 {
1559 str_copy(dst&: m_aCurrentDemoSelectionName, src: m_DemoRenameInput.GetString());
1560 if(!m_vpFilteredDemos[m_DemolistSelectedIndex]->m_IsDir)
1561 fs_split_file_extension(filename: m_DemoRenameInput.GetString(), name: m_aCurrentDemoSelectionName, name_size: sizeof(m_aCurrentDemoSelectionName));
1562 DemolistPopulate();
1563 DemolistOnUpdate(Reset: false);
1564 }
1565 else
1566 {
1567 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);
1568 }
1569 }
1570
1571 Box.HSplitBottom(Cut: 60.f, pTop: &Box, pBottom: &Part);
1572 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1573
1574 Part.VSplitLeft(Cut: 60.0f, pLeft: nullptr, pRight: &Label);
1575 Label.VSplitLeft(Cut: 120.0f, pLeft: nullptr, pRight: &TextBox);
1576 TextBox.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &TextBox);
1577 TextBox.VSplitRight(Cut: 60.0f, pLeft: &TextBox, pRight: nullptr);
1578 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "New name:"), Size: 18.0f, Align: TEXTALIGN_ML);
1579 Ui()->DoEditBox(pLineInput: &m_DemoRenameInput, pRect: &TextBox, FontSize: 12.0f);
1580 }
1581#if defined(CONF_VIDEORECORDER)
1582 else if(m_Popup == POPUP_RENDER_DEMO)
1583 {
1584 CUIRect Row, Ok, Abort;
1585 Box.VMargin(Cut: 60.0f, pOtherRect: &Box);
1586 Box.HMargin(Cut: 20.0f, pOtherRect: &Box);
1587 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Row);
1588 Box.HSplitBottom(Cut: 40.0f, pTop: &Box, pBottom: nullptr);
1589 Row.VMargin(Cut: 40.0f, pOtherRect: &Row);
1590 Row.VSplitMid(pLeft: &Abort, pRight: &Ok, Spacing: 40.0f);
1591
1592 static CButtonContainer s_ButtonAbort;
1593 if(DoButton_Menu(pButtonContainer: &s_ButtonAbort, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Abort) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1594 {
1595 m_DemoRenderInput.Clear();
1596 m_Popup = POPUP_NONE;
1597 }
1598
1599 static CButtonContainer s_ButtonOk;
1600 if(DoButton_Menu(pButtonContainer: &s_ButtonOk, pText: Localize(pStr: "Ok"), Checked: 0, pRect: &Ok) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1601 {
1602 m_Popup = POPUP_NONE;
1603 // render video
1604 char aVideoPath[IO_MAX_PATH_LENGTH];
1605 str_format(buffer: aVideoPath, buffer_size: sizeof(aVideoPath), format: "videos/%s", m_DemoRenderInput.GetString());
1606 if(!str_endswith(str: aVideoPath, suffix: ".mp4"))
1607 str_append(dst&: aVideoPath, src: ".mp4");
1608
1609 if(!str_valid_filename(str: m_DemoRenderInput.GetString()))
1610 {
1611 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);
1612 }
1613 else if(Storage()->FolderExists(pFilename: aVideoPath, Type: IStorage::TYPE_SAVE))
1614 {
1615 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "A folder with this name already exists"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_RENDER_DEMO);
1616 }
1617 else if(Storage()->FileExists(pFilename: aVideoPath, Type: IStorage::TYPE_SAVE))
1618 {
1619 char aMessage[128 + IO_MAX_PATH_LENGTH];
1620 str_format(buffer: aMessage, buffer_size: sizeof(aMessage), format: Localize(pStr: "File '%s' already exists, do you want to overwrite it?"), m_DemoRenderInput.GetString());
1621 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);
1622 }
1623 else
1624 {
1625 PopupConfirmDemoReplaceVideo();
1626 }
1627 }
1628
1629 CUIRect ShowChatCheckbox, UseSoundsCheckbox;
1630 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: &Row);
1631 Box.HSplitBottom(Cut: 10.0f, pTop: &Box, pBottom: nullptr);
1632 Row.VSplitMid(pLeft: &ShowChatCheckbox, pRight: &UseSoundsCheckbox, Spacing: 20.0f);
1633
1634 if(DoButton_CheckBox(pId: &g_Config.m_ClVideoShowChat, pText: Localize(pStr: "Show chat"), Checked: g_Config.m_ClVideoShowChat, pRect: &ShowChatCheckbox))
1635 g_Config.m_ClVideoShowChat ^= 1;
1636
1637 if(DoButton_CheckBox(pId: &g_Config.m_ClVideoSndEnable, pText: Localize(pStr: "Use sounds"), Checked: g_Config.m_ClVideoSndEnable, pRect: &UseSoundsCheckbox))
1638 g_Config.m_ClVideoSndEnable ^= 1;
1639
1640 CUIRect ShowHudButton;
1641 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: &Row);
1642 Row.VSplitMid(pLeft: &Row, pRight: &ShowHudButton, Spacing: 20.0f);
1643
1644 if(DoButton_CheckBox(pId: &g_Config.m_ClVideoShowhud, pText: Localize(pStr: "Show ingame HUD"), Checked: g_Config.m_ClVideoShowhud, pRect: &ShowHudButton))
1645 g_Config.m_ClVideoShowhud ^= 1;
1646
1647 // slowdown
1648 CUIRect SlowDownButton;
1649 Row.VSplitLeft(Cut: 20.0f, pLeft: &SlowDownButton, pRight: &Row);
1650 Row.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Row);
1651 static CButtonContainer s_SlowDownButton;
1652 if(Ui()->DoButton_FontIcon(pButtonContainer: &s_SlowDownButton, pText: FONT_ICON_BACKWARD, Checked: 0, pRect: &SlowDownButton, Flags: BUTTONFLAG_LEFT))
1653 m_Speed = std::clamp(val: m_Speed - 1, lo: 0, hi: (int)(std::size(DEMO_SPEEDS) - 1));
1654
1655 // paused
1656 CUIRect PausedButton;
1657 Row.VSplitLeft(Cut: 20.0f, pLeft: &PausedButton, pRight: &Row);
1658 Row.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Row);
1659 static CButtonContainer s_PausedButton;
1660 if(Ui()->DoButton_FontIcon(pButtonContainer: &s_PausedButton, pText: FONT_ICON_PAUSE, Checked: 0, pRect: &PausedButton, Flags: BUTTONFLAG_LEFT))
1661 m_StartPaused ^= 1;
1662
1663 // fastforward
1664 CUIRect FastForwardButton;
1665 Row.VSplitLeft(Cut: 20.0f, pLeft: &FastForwardButton, pRight: &Row);
1666 Row.VSplitLeft(Cut: 8.0f, pLeft: nullptr, pRight: &Row);
1667 static CButtonContainer s_FastForwardButton;
1668 if(Ui()->DoButton_FontIcon(pButtonContainer: &s_FastForwardButton, pText: FONT_ICON_FORWARD, Checked: 0, pRect: &FastForwardButton, Flags: BUTTONFLAG_LEFT))
1669 m_Speed = std::clamp(val: m_Speed + 1, lo: 0, hi: (int)(std::size(DEMO_SPEEDS) - 1));
1670
1671 // speed meter
1672 char aBuffer[128];
1673 const char *pPaused = m_StartPaused ? Localize(pStr: "(paused)") : "";
1674 str_format(buffer: aBuffer, buffer_size: sizeof(aBuffer), format: "%s: ×%g %s", Localize(pStr: "Speed"), DEMO_SPEEDS[m_Speed], pPaused);
1675 Ui()->DoLabel(pRect: &Row, pText: aBuffer, Size: 12.8f, Align: TEXTALIGN_ML);
1676 Box.HSplitBottom(Cut: 16.0f, pTop: &Box, pBottom: nullptr);
1677 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Row);
1678
1679 CUIRect Label, TextBox;
1680 Row.VSplitLeft(Cut: 110.0f, pLeft: &Label, pRight: &TextBox);
1681 TextBox.VSplitLeft(Cut: 10.0f, pLeft: nullptr, pRight: &TextBox);
1682 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Video name:"), Size: 12.8f, Align: TEXTALIGN_ML);
1683 Ui()->DoEditBox(pLineInput: &m_DemoRenderInput, pRect: &TextBox, FontSize: 12.8f);
1684
1685 // Warn about disconnect if online
1686 if(Client()->State() == IClient::STATE_ONLINE)
1687 {
1688 Box.HSplitBottom(Cut: 10.0f, pTop: &Box, pBottom: nullptr);
1689 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: &Row);
1690 SLabelProperties LabelProperties;
1691 LabelProperties.SetColor(ColorRGBA(1.0f, 0.0f, 0.0f));
1692 Ui()->DoLabel(pRect: &Row, pText: Localize(pStr: "You will be disconnected from the server."), Size: 12.8f, Align: TEXTALIGN_MC, LabelProps: LabelProperties);
1693 }
1694 }
1695 else if(m_Popup == POPUP_RENDER_DONE)
1696 {
1697 CUIRect Ok, OpenFolder;
1698
1699 char aFilePath[IO_MAX_PATH_LENGTH];
1700 char aSaveFolder[IO_MAX_PATH_LENGTH];
1701 Storage()->GetCompletePath(Type: IStorage::TYPE_SAVE, pDir: "videos", pBuffer: aSaveFolder, BufferSize: sizeof(aSaveFolder));
1702 str_format(buffer: aFilePath, buffer_size: sizeof(aFilePath), format: "%s/%s.mp4", aSaveFolder, m_DemoRenderInput.GetString());
1703
1704 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1705 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1706 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1707
1708 Part.VSplitMid(pLeft: &OpenFolder, pRight: &Ok);
1709
1710 Ok.VMargin(Cut: 20.0f, pOtherRect: &Ok);
1711 OpenFolder.VMargin(Cut: 20.0f, pOtherRect: &OpenFolder);
1712
1713 static CButtonContainer s_ButtonOpenFolder;
1714 if(DoButton_Menu(pButtonContainer: &s_ButtonOpenFolder, pText: Localize(pStr: "Videos directory"), Checked: 0, pRect: &OpenFolder))
1715 {
1716 Client()->ViewFile(pFilename: aSaveFolder);
1717 }
1718
1719 static CButtonContainer s_ButtonOk;
1720 if(DoButton_Menu(pButtonContainer: &s_ButtonOk, pText: Localize(pStr: "Ok"), Checked: 0, pRect: &Ok) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1721 {
1722 m_Popup = POPUP_NONE;
1723 m_DemoRenderInput.Clear();
1724 }
1725
1726 Box.HSplitBottom(Cut: 160.f, pTop: &Box, pBottom: &Part);
1727 Part.VMargin(Cut: 20.0f, pOtherRect: &Part);
1728
1729 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Video was saved to '%s'"), aFilePath);
1730
1731 SLabelProperties MessageProps;
1732 MessageProps.m_MaxWidth = (int)Part.w;
1733 Ui()->DoLabel(pRect: &Part, pText: aBuf, Size: 18.0f, Align: TEXTALIGN_TL, LabelProps: MessageProps);
1734 }
1735#endif
1736 else if(m_Popup == POPUP_FIRST_LAUNCH)
1737 {
1738 CUIRect Label, TextBox, Skip, Join;
1739
1740 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1741 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1742 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1743 Part.VSplitMid(pLeft: &Skip, pRight: &Join);
1744 Skip.VMargin(Cut: 20.0f, pOtherRect: &Skip);
1745 Join.VMargin(Cut: 20.0f, pOtherRect: &Join);
1746
1747 static CButtonContainer s_JoinTutorialButton;
1748 if(DoButton_Menu(pButtonContainer: &s_JoinTutorialButton, pText: Localize(pStr: "Join Tutorial Server"), Checked: 0, pRect: &Join) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1749 {
1750 m_JoinTutorial = true;
1751 Client()->RequestDDNetInfo();
1752 m_Popup = g_Config.m_BrIndicateFinished ? POPUP_POINTS : POPUP_NONE;
1753 }
1754
1755 static CButtonContainer s_SkipTutorialButton;
1756 if(DoButton_Menu(pButtonContainer: &s_SkipTutorialButton, pText: Localize(pStr: "Skip Tutorial"), Checked: 0, pRect: &Skip) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1757 {
1758 m_JoinTutorial = false;
1759 Client()->RequestDDNetInfo();
1760 m_Popup = g_Config.m_BrIndicateFinished ? POPUP_POINTS : POPUP_NONE;
1761 }
1762
1763 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1764 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1765
1766 Part.VSplitLeft(Cut: 30.0f, pLeft: nullptr, pRight: &Part);
1767 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s\n(%s)",
1768 Localize(pStr: "Show DDNet map finishes in server browser"),
1769 Localize(pStr: "transmits your player name to info.ddnet.org"));
1770
1771 if(DoButton_CheckBox(pId: &g_Config.m_BrIndicateFinished, pText: aBuf, Checked: g_Config.m_BrIndicateFinished, pRect: &Part))
1772 g_Config.m_BrIndicateFinished ^= 1;
1773
1774 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1775 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1776
1777 Part.VSplitLeft(Cut: 60.0f, pLeft: nullptr, pRight: &Label);
1778 Label.VSplitLeft(Cut: 100.0f, pLeft: nullptr, pRight: &TextBox);
1779 TextBox.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &TextBox);
1780 TextBox.VSplitRight(Cut: 60.0f, pLeft: &TextBox, pRight: nullptr);
1781 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Nickname"), Size: 16.0f, Align: TEXTALIGN_ML);
1782 static CLineInput s_PlayerNameInput(g_Config.m_PlayerName, sizeof(g_Config.m_PlayerName));
1783 s_PlayerNameInput.SetEmptyText(Client()->PlayerName());
1784 Ui()->DoEditBox(pLineInput: &s_PlayerNameInput, pRect: &TextBox, FontSize: 12.0f);
1785 }
1786 else if(m_Popup == POPUP_POINTS)
1787 {
1788 Box.HSplitBottom(Cut: 20.0f, pTop: &Box, pBottom: nullptr);
1789 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Part);
1790 Part.VMargin(Cut: 120.0f, pOtherRect: &Part);
1791
1792 if(Client()->InfoState() == IClient::EInfoState::SUCCESS && Client()->Points() > 50)
1793 {
1794 CUIRect Yes, No;
1795 Part.VSplitMid(pLeft: &No, pRight: &Yes, Spacing: 40.0f);
1796 static CButtonContainer s_ButtonNo;
1797 if(DoButton_Menu(pButtonContainer: &s_ButtonNo, pText: Localize(pStr: "No"), Checked: 0, pRect: &No) ||
1798 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1799 {
1800 m_Popup = POPUP_FIRST_LAUNCH;
1801 }
1802
1803 static CButtonContainer s_ButtonYes;
1804 if(DoButton_Menu(pButtonContainer: &s_ButtonYes, pText: Localize(pStr: "Yes"), Checked: 0, pRect: &Yes) ||
1805 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1806 {
1807 m_Popup = POPUP_NONE;
1808 }
1809 }
1810 else
1811 {
1812 static CButtonContainer s_Button;
1813 if(DoButton_Menu(pButtonContainer: &s_Button, pText: Localize(pStr: "Cancel"), Checked: 0, pRect: &Part) ||
1814 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE) ||
1815 Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER) ||
1816 Client()->InfoState() == IClient::EInfoState::SUCCESS)
1817 {
1818 m_Popup = POPUP_NONE;
1819 }
1820 if(Client()->InfoState() == IClient::EInfoState::ERROR)
1821 {
1822 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"));
1823 }
1824 }
1825 }
1826 else if(m_Popup == POPUP_WARNING)
1827 {
1828 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1829 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1830 Part.VMargin(Cut: 120.0f, pOtherRect: &Part);
1831
1832 static CButtonContainer s_Button;
1833 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))
1834 {
1835 m_Popup = POPUP_NONE;
1836 SetActive(false);
1837 }
1838 }
1839 else if(m_Popup == POPUP_SAVE_SKIN)
1840 {
1841 CUIRect Label, TextBox, Yes, No;
1842
1843 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1844 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1845 Part.VMargin(Cut: 80.0f, pOtherRect: &Part);
1846
1847 Part.VSplitMid(pLeft: &No, pRight: &Yes);
1848
1849 Yes.VMargin(Cut: 20.0f, pOtherRect: &Yes);
1850 No.VMargin(Cut: 20.0f, pOtherRect: &No);
1851
1852 static CButtonContainer s_ButtonNo;
1853 if(DoButton_Menu(pButtonContainer: &s_ButtonNo, pText: Localize(pStr: "No"), Checked: 0, pRect: &No) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1854 m_Popup = POPUP_NONE;
1855
1856 static CButtonContainer s_ButtonYes;
1857 if(DoButton_Menu(pButtonContainer: &s_ButtonYes, pText: Localize(pStr: "Yes"), Checked: m_SkinNameInput.IsEmpty() ? 1 : 0, pRect: &Yes) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1858 {
1859 if(!str_valid_filename(str: m_SkinNameInput.GetString()))
1860 {
1861 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);
1862 }
1863 else if(CSkins7::IsSpecialSkin(pName: m_SkinNameInput.GetString()))
1864 {
1865 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);
1866 }
1867 else if(!GameClient()->m_Skins7.SaveSkinfile(pName: m_SkinNameInput.GetString(), Dummy: m_Dummy))
1868 {
1869 PopupMessage(pTitle: Localize(pStr: "Error"), pMessage: Localize(pStr: "Unable to save the skin"), pButtonLabel: Localize(pStr: "Ok"), NextPopup: POPUP_SAVE_SKIN);
1870 }
1871 else
1872 {
1873 m_Popup = POPUP_NONE;
1874 m_SkinList7LastRefreshTime = std::nullopt;
1875 }
1876 }
1877
1878 Box.HSplitBottom(Cut: 60.f, pTop: &Box, pBottom: &Part);
1879 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1880
1881 Part.VMargin(Cut: 60.0f, pOtherRect: &Label);
1882 Label.VSplitLeft(Cut: 100.0f, pLeft: &Label, pRight: &TextBox);
1883 TextBox.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &TextBox);
1884 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Name"), Size: 18.0f, Align: TEXTALIGN_ML);
1885 Ui()->DoClearableEditBox(pLineInput: &m_SkinNameInput, pRect: &TextBox, FontSize: 12.0f);
1886 }
1887 else
1888 {
1889 Box.HSplitBottom(Cut: 20.f, pTop: &Box, pBottom: &Part);
1890 Box.HSplitBottom(Cut: 24.f, pTop: &Box, pBottom: &Part);
1891 Part.VMargin(Cut: 120.0f, pOtherRect: &Part);
1892
1893 static CButtonContainer s_Button;
1894 if(DoButton_Menu(pButtonContainer: &s_Button, pText: pButtonText, Checked: 0, pRect: &Part) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ENTER))
1895 {
1896 if(m_Popup == POPUP_DISCONNECTED && Client()->ReconnectTime() > 0)
1897 Client()->SetReconnectTime(0);
1898 m_Popup = POPUP_NONE;
1899 }
1900 }
1901
1902 if(m_Popup == POPUP_NONE)
1903 Ui()->SetActiveItem(nullptr);
1904}
1905
1906void CMenus::RenderPopupConnecting(CUIRect Screen)
1907{
1908 const float FontSize = 20.0f;
1909
1910 CUIRect Box, Label;
1911 Screen.Margin(Cut: 150.0f, pOtherRect: &Box);
1912 Box.Draw(Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners: IGraphics::CORNER_ALL, Rounding: 15.0f);
1913 Box.Margin(Cut: 20.0f, pOtherRect: &Box);
1914
1915 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
1916 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Connecting to"), Size: 24.0f, Align: TEXTALIGN_MC);
1917
1918 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
1919 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
1920 SLabelProperties Props;
1921 Props.m_MaxWidth = Label.w;
1922 Props.m_EllipsisAtEnd = true;
1923 Ui()->DoLabel(pRect: &Label, pText: Client()->ConnectAddressString(), Size: FontSize, Align: TEXTALIGN_MC, LabelProps: Props);
1924
1925 if(time_get() - Client()->StateStartTime() > time_freq())
1926 {
1927 const char *pConnectivityLabel = "";
1928 switch(Client()->UdpConnectivity(NetType: Client()->ConnectNetTypes()))
1929 {
1930 case IClient::CONNECTIVITY_UNKNOWN:
1931 break;
1932 case IClient::CONNECTIVITY_CHECKING:
1933 pConnectivityLabel = Localize(pStr: "Trying to determine UDP connectivity…");
1934 break;
1935 case IClient::CONNECTIVITY_UNREACHABLE:
1936 pConnectivityLabel = Localize(pStr: "UDP seems to be filtered.");
1937 break;
1938 case IClient::CONNECTIVITY_DIFFERING_UDP_TCP_IP_ADDRESSES:
1939 pConnectivityLabel = Localize(pStr: "UDP and TCP IP addresses seem to be different. Try disabling VPN, proxy or network accelerators.");
1940 break;
1941 case IClient::CONNECTIVITY_REACHABLE:
1942 pConnectivityLabel = Localize(pStr: "No answer from server yet.");
1943 break;
1944 }
1945 if(pConnectivityLabel[0] != '\0')
1946 {
1947 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
1948 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
1949 SLabelProperties ConnectivityLabelProps;
1950 ConnectivityLabelProps.m_MaxWidth = Label.w;
1951 if(TextRender()->TextWidth(Size: FontSize, pText: pConnectivityLabel) > Label.w)
1952 Ui()->DoLabel(pRect: &Label, pText: pConnectivityLabel, Size: FontSize, Align: TEXTALIGN_ML, LabelProps: ConnectivityLabelProps);
1953 else
1954 Ui()->DoLabel(pRect: &Label, pText: pConnectivityLabel, Size: FontSize, Align: TEXTALIGN_MC);
1955 }
1956 }
1957
1958 CUIRect Button;
1959 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Button);
1960 Button.VMargin(Cut: 100.0f, pOtherRect: &Button);
1961
1962 static CButtonContainer s_Button;
1963 if(DoButton_Menu(pButtonContainer: &s_Button, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Button) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
1964 {
1965 Client()->Disconnect();
1966 Ui()->SetActiveItem(nullptr);
1967 RefreshBrowserTab(Force: true);
1968 }
1969}
1970
1971void CMenus::RenderPopupLoading(CUIRect Screen)
1972{
1973 char aTitle[256];
1974 char aLabel1[128];
1975 char aLabel2[128];
1976 if(Client()->MapDownloadTotalsize() > 0)
1977 {
1978 const int64_t Now = time_get();
1979 if(Now - m_DownloadLastCheckTime >= time_freq())
1980 {
1981 if(m_DownloadLastCheckSize > Client()->MapDownloadAmount())
1982 {
1983 // map downloaded restarted
1984 m_DownloadLastCheckSize = 0;
1985 }
1986
1987 // update download speed
1988 const float Diff = (Client()->MapDownloadAmount() - m_DownloadLastCheckSize) / ((int)((Now - m_DownloadLastCheckTime) / time_freq()));
1989 const float StartDiff = m_DownloadLastCheckSize - 0.0f;
1990 if(StartDiff + Diff > 0.0f)
1991 m_DownloadSpeed = (Diff / (StartDiff + Diff)) * (Diff / 1.0f) + (StartDiff / (Diff + StartDiff)) * m_DownloadSpeed;
1992 else
1993 m_DownloadSpeed = 0.0f;
1994 m_DownloadLastCheckTime = Now;
1995 m_DownloadLastCheckSize = Client()->MapDownloadAmount();
1996 }
1997
1998 str_format(buffer: aTitle, buffer_size: sizeof(aTitle), format: "%s: %s", Localize(pStr: "Downloading map"), Client()->MapDownloadName());
1999
2000 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);
2001
2002 const int SecondsLeft = maximum(a: 1, b: m_DownloadSpeed > 0.0f ? static_cast<int>((Client()->MapDownloadTotalsize() - Client()->MapDownloadAmount()) / m_DownloadSpeed) : 1);
2003 const int MinutesLeft = SecondsLeft / 60;
2004 if(MinutesLeft > 0)
2005 {
2006 str_format(buffer: aLabel2, buffer_size: sizeof(aLabel2), format: MinutesLeft == 1 ? Localize(pStr: "%i minute left") : Localize(pStr: "%i minutes left"), MinutesLeft);
2007 }
2008 else
2009 {
2010 str_format(buffer: aLabel2, buffer_size: sizeof(aLabel2), format: SecondsLeft == 1 ? Localize(pStr: "%i second left") : Localize(pStr: "%i seconds left"), SecondsLeft);
2011 }
2012 }
2013 else
2014 {
2015 str_copy(dst&: aTitle, src: Localize(pStr: "Connected"));
2016 switch(Client()->LoadingStateDetail())
2017 {
2018 case IClient::LOADING_STATE_DETAIL_INITIAL:
2019 str_copy(dst&: aLabel1, src: Localize(pStr: "Getting game info"));
2020 break;
2021 case IClient::LOADING_STATE_DETAIL_LOADING_MAP:
2022 str_copy(dst&: aLabel1, src: Localize(pStr: "Loading map file from storage"));
2023 break;
2024 case IClient::LOADING_STATE_DETAIL_LOADING_DEMO:
2025 str_copy(dst&: aLabel1, src: Localize(pStr: "Loading demo file from storage"));
2026 break;
2027 case IClient::LOADING_STATE_DETAIL_SENDING_READY:
2028 str_copy(dst&: aLabel1, src: Localize(pStr: "Requesting to join the game"));
2029 break;
2030 case IClient::LOADING_STATE_DETAIL_GETTING_READY:
2031 str_copy(dst&: aLabel1, src: Localize(pStr: "Sending initial client info"));
2032 break;
2033 default:
2034 dbg_assert_failed("Invalid loading state %d for RenderPopupLoading", static_cast<int>(Client()->LoadingStateDetail()));
2035 }
2036 aLabel2[0] = '\0';
2037 }
2038
2039 const float FontSize = 20.0f;
2040
2041 CUIRect Box, Label;
2042 Screen.Margin(Cut: 150.0f, pOtherRect: &Box);
2043 Box.Draw(Color: ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f), Corners: IGraphics::CORNER_ALL, Rounding: 15.0f);
2044 Box.Margin(Cut: 20.0f, pOtherRect: &Box);
2045
2046 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2047 Ui()->DoLabel(pRect: &Label, pText: aTitle, Size: 24.0f, Align: TEXTALIGN_MC);
2048
2049 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
2050 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2051 Ui()->DoLabel(pRect: &Label, pText: aLabel1, Size: FontSize, Align: TEXTALIGN_MC);
2052
2053 if(aLabel2[0] != '\0')
2054 {
2055 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
2056 Box.HSplitTop(Cut: 24.0f, pTop: &Label, pBottom: &Box);
2057 SLabelProperties ExtraTextProps;
2058 ExtraTextProps.m_MaxWidth = Label.w;
2059 if(TextRender()->TextWidth(Size: FontSize, pText: aLabel2) > Label.w)
2060 Ui()->DoLabel(pRect: &Label, pText: aLabel2, Size: FontSize, Align: TEXTALIGN_ML, LabelProps: ExtraTextProps);
2061 else
2062 Ui()->DoLabel(pRect: &Label, pText: aLabel2, Size: FontSize, Align: TEXTALIGN_MC);
2063 }
2064
2065 if(Client()->MapDownloadTotalsize() > 0)
2066 {
2067 CUIRect ProgressBar;
2068 Box.HSplitTop(Cut: 20.0f, pTop: nullptr, pBottom: &Box);
2069 Box.HSplitTop(Cut: 24.0f, pTop: &ProgressBar, pBottom: &Box);
2070 ProgressBar.VMargin(Cut: 20.0f, pOtherRect: &ProgressBar);
2071 Ui()->RenderProgressBar(ProgressBar, Progress: Client()->MapDownloadAmount() / (float)Client()->MapDownloadTotalsize());
2072 }
2073
2074 CUIRect Button;
2075 Box.HSplitBottom(Cut: 24.0f, pTop: &Box, pBottom: &Button);
2076 Button.VMargin(Cut: 100.0f, pOtherRect: &Button);
2077
2078 static CButtonContainer s_Button;
2079 if(DoButton_Menu(pButtonContainer: &s_Button, pText: Localize(pStr: "Abort"), Checked: 0, pRect: &Button) || Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
2080 {
2081 Client()->Disconnect();
2082 Ui()->SetActiveItem(nullptr);
2083 RefreshBrowserTab(Force: true);
2084 }
2085}
2086
2087#if defined(CONF_VIDEORECORDER)
2088void CMenus::PopupConfirmDemoReplaceVideo()
2089{
2090 char aBuf[IO_MAX_PATH_LENGTH];
2091 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s/%s.demo", m_aCurrentDemoFolder, m_aCurrentDemoSelectionName);
2092 char aVideoName[IO_MAX_PATH_LENGTH];
2093 str_copy(dst&: aVideoName, src: m_DemoRenderInput.GetString());
2094 const char *pError = Client()->DemoPlayer_Render(pFilename: aBuf, StorageType: m_DemolistStorageType, pVideoName: aVideoName, SpeedIndex: m_Speed, StartPaused: m_StartPaused);
2095 m_Speed = DEMO_SPEED_INDEX_DEFAULT;
2096 m_StartPaused = false;
2097 m_LastPauseChange = -1.0f;
2098 m_LastSpeedChange = -1.0f;
2099 if(pError)
2100 {
2101 m_DemoRenderInput.Clear();
2102 PopupMessage(pTitle: Localize(pStr: "Error loading demo"), pMessage: pError, pButtonLabel: Localize(pStr: "Ok"));
2103 }
2104}
2105#endif
2106
2107void CMenus::RenderThemeSelection(CUIRect MainView)
2108{
2109 const std::vector<CTheme> &vThemes = GameClient()->m_MenuBackground.GetThemes();
2110
2111 int SelectedTheme = -1;
2112 for(int i = 0; i < (int)vThemes.size(); i++)
2113 {
2114 if(str_comp(a: vThemes[i].m_Name.c_str(), b: g_Config.m_ClMenuMap) == 0)
2115 {
2116 SelectedTheme = i;
2117 break;
2118 }
2119 }
2120 const int OldSelected = SelectedTheme;
2121
2122 static CListBox s_ListBox;
2123 s_ListBox.DoHeader(pRect: &MainView, pTitle: Localize(pStr: "Theme"), HeaderHeight: 20.0f);
2124 s_ListBox.DoStart(RowHeight: 20.0f, NumItems: vThemes.size(), ItemsPerRow: 1, RowsPerScroll: 3, SelectedIndex: SelectedTheme);
2125
2126 for(int i = 0; i < (int)vThemes.size(); i++)
2127 {
2128 const CTheme &Theme = vThemes[i];
2129 const CListboxItem Item = s_ListBox.DoNextItem(pId: &Theme.m_Name, Selected: i == SelectedTheme);
2130
2131 if(!Item.m_Visible)
2132 continue;
2133
2134 CUIRect Icon, Label;
2135 Item.m_Rect.VSplitLeft(Cut: Item.m_Rect.h * 2.0f, pLeft: &Icon, pRight: &Label);
2136
2137 // draw icon if it exists
2138 if(Theme.m_IconTexture.IsValid())
2139 {
2140 Icon.VMargin(Cut: 6.0f, pOtherRect: &Icon);
2141 Icon.HMargin(Cut: 3.0f, pOtherRect: &Icon);
2142 Graphics()->TextureSet(Texture: Theme.m_IconTexture);
2143 Graphics()->QuadsBegin();
2144 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
2145 IGraphics::CQuadItem QuadItem(Icon.x, Icon.y, Icon.w, Icon.h);
2146 Graphics()->QuadsDrawTL(pArray: &QuadItem, Num: 1);
2147 Graphics()->QuadsEnd();
2148 }
2149
2150 char aName[128];
2151 if(Theme.m_Name.empty())
2152 str_copy(dst&: aName, src: "(none)");
2153 else if(str_comp(a: Theme.m_Name.c_str(), b: "auto") == 0)
2154 str_copy(dst&: aName, src: "(seasons)");
2155 else if(str_comp(a: Theme.m_Name.c_str(), b: "rand") == 0)
2156 str_copy(dst&: aName, src: "(random)");
2157 else if(Theme.m_HasDay && Theme.m_HasNight)
2158 str_copy(dst&: aName, src: Theme.m_Name.c_str());
2159 else if(Theme.m_HasDay && !Theme.m_HasNight)
2160 str_format(buffer: aName, buffer_size: sizeof(aName), format: "%s (day)", Theme.m_Name.c_str());
2161 else if(!Theme.m_HasDay && Theme.m_HasNight)
2162 str_format(buffer: aName, buffer_size: sizeof(aName), format: "%s (night)", Theme.m_Name.c_str());
2163 else // generic
2164 str_copy(dst&: aName, src: Theme.m_Name.c_str());
2165
2166 Ui()->DoLabel(pRect: &Label, pText: aName, Size: 16.0f * CUi::ms_FontmodHeight, Align: TEXTALIGN_ML);
2167 }
2168
2169 SelectedTheme = s_ListBox.DoEnd();
2170
2171 if(OldSelected != SelectedTheme)
2172 {
2173 const CTheme &Theme = vThemes[SelectedTheme];
2174 str_copy(dst&: g_Config.m_ClMenuMap, src: Theme.m_Name.c_str());
2175 GameClient()->m_MenuBackground.LoadMenuBackground(HasDayHint: Theme.m_HasDay, HasNightHint: Theme.m_HasNight);
2176 }
2177}
2178
2179void CMenus::SetActive(bool Active)
2180{
2181 if(Active != m_MenuActive)
2182 {
2183 Ui()->SetHotItem(nullptr);
2184 Ui()->SetActiveItem(nullptr);
2185 }
2186 m_MenuActive = Active;
2187 if(!m_MenuActive)
2188 {
2189 if(m_NeedSendinfo)
2190 {
2191 GameClient()->SendInfo(Start: false);
2192 m_NeedSendinfo = false;
2193 }
2194
2195 if(m_NeedSendDummyinfo)
2196 {
2197 GameClient()->SendDummyInfo(Start: false);
2198 m_NeedSendDummyinfo = false;
2199 }
2200
2201 if(Client()->State() == IClient::STATE_ONLINE)
2202 {
2203 GameClient()->OnRelease();
2204 }
2205 }
2206 else if(Client()->State() == IClient::STATE_DEMOPLAYBACK)
2207 {
2208 GameClient()->OnRelease();
2209 }
2210}
2211
2212void CMenus::OnReset()
2213{
2214}
2215
2216void CMenus::OnShutdown()
2217{
2218 m_CommunityIcons.Shutdown();
2219}
2220
2221bool CMenus::OnCursorMove(float x, float y, IInput::ECursorType CursorType)
2222{
2223 if(!m_MenuActive)
2224 return false;
2225
2226 Ui()->ConvertMouseMove(pX: &x, pY: &y, CursorType);
2227 Ui()->OnCursorMove(X: x, Y: y);
2228
2229 return true;
2230}
2231
2232bool CMenus::OnInput(const IInput::CEvent &Event)
2233{
2234 // Escape key is always handled to activate/deactivate menu
2235 if((Event.m_Flags & IInput::FLAG_PRESS && Event.m_Key == KEY_ESCAPE) || IsActive())
2236 {
2237 Ui()->OnInput(Event);
2238 return true;
2239 }
2240 return false;
2241}
2242
2243void CMenus::OnStateChange(int NewState, int OldState)
2244{
2245 // reset active item
2246 Ui()->SetActiveItem(nullptr);
2247
2248 if(OldState == IClient::STATE_ONLINE || OldState == IClient::STATE_OFFLINE)
2249 TextRender()->DeleteTextContainer(TextContainerIndex&: m_MotdTextContainerIndex);
2250
2251 if(NewState == IClient::STATE_OFFLINE)
2252 {
2253 if(OldState >= IClient::STATE_ONLINE && NewState < IClient::STATE_QUITTING)
2254 UpdateMusicState();
2255 m_Popup = POPUP_NONE;
2256 if(Client()->ErrorString() && Client()->ErrorString()[0] != 0)
2257 {
2258 if(str_find(haystack: Client()->ErrorString(), needle: "password"))
2259 {
2260 m_Popup = POPUP_PASSWORD;
2261 m_PasswordInput.SelectAll();
2262 Ui()->SetActiveItem(&m_PasswordInput);
2263 }
2264 else
2265 m_Popup = POPUP_DISCONNECTED;
2266 }
2267 }
2268 else if(NewState == IClient::STATE_LOADING)
2269 {
2270 m_DownloadLastCheckTime = time_get();
2271 m_DownloadLastCheckSize = 0;
2272 m_DownloadSpeed = 0.0f;
2273 }
2274 else if(NewState == IClient::STATE_ONLINE || NewState == IClient::STATE_DEMOPLAYBACK)
2275 {
2276 if(m_Popup != POPUP_WARNING)
2277 {
2278 m_Popup = POPUP_NONE;
2279 SetActive(false);
2280 }
2281 }
2282}
2283
2284void CMenus::OnWindowResize()
2285{
2286 TextRender()->DeleteTextContainer(TextContainerIndex&: m_MotdTextContainerIndex);
2287}
2288
2289void CMenus::OnRender()
2290{
2291 if(Client()->State() != IClient::STATE_ONLINE && Client()->State() != IClient::STATE_DEMOPLAYBACK)
2292 SetActive(true);
2293
2294 if(Client()->State() == IClient::STATE_ONLINE && GameClient()->m_ServerMode == CGameClient::SERVERMODE_PUREMOD)
2295 {
2296 Client()->Disconnect();
2297 SetActive(true);
2298 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"));
2299 }
2300
2301 if(!IsActive())
2302 {
2303 if(Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
2304 {
2305 SetActive(true);
2306 }
2307 else if(Client()->State() != IClient::STATE_DEMOPLAYBACK)
2308 {
2309 Ui()->ClearHotkeys();
2310 return;
2311 }
2312 }
2313
2314 Ui()->StartCheck();
2315 UpdateColors();
2316
2317 Ui()->Update();
2318
2319 Render();
2320
2321 if(IsActive())
2322 {
2323 RenderTools()->RenderCursor(Center: Ui()->MousePos(), Size: 24.0f);
2324 }
2325
2326 // render debug information
2327 if(g_Config.m_Debug)
2328 Ui()->DebugRender(X: 2.0f, Y: Ui()->Screen()->h - 12.0f);
2329
2330 if(Ui()->ConsumeHotkey(Hotkey: CUi::HOTKEY_ESCAPE))
2331 SetActive(false);
2332
2333 Ui()->FinishCheck();
2334 Ui()->ClearHotkeys();
2335}
2336
2337void CMenus::UpdateColors()
2338{
2339 ms_GuiColor = color_cast<ColorRGBA>(hsl: ColorHSLA(g_Config.m_UiColor, true));
2340
2341 ms_ColorTabbarInactiveOutgame = ColorRGBA(0.0f, 0.0f, 0.0f, 0.25f);
2342 ms_ColorTabbarActiveOutgame = ColorRGBA(0.0f, 0.0f, 0.0f, 0.5f);
2343 ms_ColorTabbarHoverOutgame = ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f);
2344
2345 const float ColorIngameScaleI = 0.5f;
2346 const float ColorIngameScaleA = 0.2f;
2347
2348 ms_ColorTabbarInactiveIngame = ColorRGBA(
2349 ms_GuiColor.r * ColorIngameScaleI,
2350 ms_GuiColor.g * ColorIngameScaleI,
2351 ms_GuiColor.b * ColorIngameScaleI,
2352 ms_GuiColor.a * 0.8f);
2353
2354 ms_ColorTabbarActiveIngame = ColorRGBA(
2355 ms_GuiColor.r * ColorIngameScaleA,
2356 ms_GuiColor.g * ColorIngameScaleA,
2357 ms_GuiColor.b * ColorIngameScaleA,
2358 ms_GuiColor.a);
2359
2360 ms_ColorTabbarHoverIngame = ColorRGBA(1.0f, 1.0f, 1.0f, 0.75f);
2361}
2362
2363void CMenus::RenderBackground()
2364{
2365 Graphics()->BlendNormal();
2366
2367 const float ScreenHeight = 300.0f;
2368 const float ScreenWidth = ScreenHeight * Graphics()->ScreenAspect();
2369 Graphics()->MapScreen(TopLeftX: 0.0f, TopLeftY: 0.0f, BottomRightX: ScreenWidth, BottomRightY: ScreenHeight);
2370
2371 // render background color
2372 Graphics()->TextureClear();
2373 Graphics()->QuadsBegin();
2374 Graphics()->SetColor(ms_GuiColor.WithAlpha(alpha: 1.0f));
2375 const IGraphics::CQuadItem BackgroundQuadItem = IGraphics::CQuadItem(0, 0, ScreenWidth, ScreenHeight);
2376 Graphics()->QuadsDrawTL(pArray: &BackgroundQuadItem, Num: 1);
2377 Graphics()->QuadsEnd();
2378
2379 // render the tiles
2380 Graphics()->TextureClear();
2381 Graphics()->QuadsBegin();
2382 Graphics()->SetColor(r: 0.0f, g: 0.0f, b: 0.0f, a: 0.045f);
2383 const float Size = 15.0f;
2384 const float OffsetTime = std::fmod(x: Client()->GlobalTime() * 0.15f, y: 2.0f);
2385 IGraphics::CQuadItem aCheckerItems[64];
2386 size_t NumCheckerItems = 0;
2387 const int NumItemsWidth = std::ceil(x: ScreenWidth / Size);
2388 const int NumItemsHeight = std::ceil(x: ScreenHeight / Size);
2389 for(int y = -2; y < NumItemsHeight; y++)
2390 {
2391 for(int x = 0; x < NumItemsWidth + 4; x += 2)
2392 {
2393 aCheckerItems[NumCheckerItems] = IGraphics::CQuadItem((x - 2 * OffsetTime + (y & 1)) * Size, (y + OffsetTime) * Size, Size, Size);
2394 NumCheckerItems++;
2395 if(NumCheckerItems == std::size(aCheckerItems))
2396 {
2397 Graphics()->QuadsDrawTL(pArray: aCheckerItems, Num: NumCheckerItems);
2398 NumCheckerItems = 0;
2399 }
2400 }
2401 }
2402 if(NumCheckerItems != 0)
2403 Graphics()->QuadsDrawTL(pArray: aCheckerItems, Num: NumCheckerItems);
2404 Graphics()->QuadsEnd();
2405
2406 // render border fade
2407 Graphics()->TextureSet(Texture: m_TextureBlob);
2408 Graphics()->QuadsBegin();
2409 Graphics()->SetColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
2410 const IGraphics::CQuadItem BlobQuadItem = IGraphics::CQuadItem(-100, -100, ScreenWidth + 200, ScreenHeight + 200);
2411 Graphics()->QuadsDrawTL(pArray: &BlobQuadItem, Num: 1);
2412 Graphics()->QuadsEnd();
2413
2414 // restore screen
2415 Ui()->MapScreen();
2416}
2417
2418int CMenus::DoButton_CheckBox_Tristate(const void *pId, const char *pText, TRISTATE Checked, const CUIRect *pRect)
2419{
2420 switch(Checked)
2421 {
2422 case TRISTATE::NONE:
2423 return DoButton_CheckBox_Common(pId, pText, pBoxText: "", pRect, Flags: BUTTONFLAG_LEFT);
2424 case TRISTATE::SOME:
2425 return DoButton_CheckBox_Common(pId, pText, pBoxText: "O", pRect, Flags: BUTTONFLAG_LEFT);
2426 case TRISTATE::ALL:
2427 return DoButton_CheckBox_Common(pId, pText, pBoxText: "X", pRect, Flags: BUTTONFLAG_LEFT);
2428 default:
2429 dbg_assert_failed("Invalid tristate. Checked: %d", static_cast<int>(Checked));
2430 }
2431}
2432
2433int CMenus::MenuImageScan(const char *pName, int IsDir, int DirType, void *pUser)
2434{
2435 const char *pExtension = ".png";
2436 CMenuImage MenuImage;
2437 CMenus *pSelf = static_cast<CMenus *>(pUser);
2438 if(IsDir || !str_endswith(str: pName, suffix: pExtension) || str_length(str: pName) - str_length(str: pExtension) >= (int)sizeof(MenuImage.m_aName))
2439 return 0;
2440
2441 char aPath[IO_MAX_PATH_LENGTH];
2442 str_format(buffer: aPath, buffer_size: sizeof(aPath), format: "menuimages/%s", pName);
2443
2444 CImageInfo Info;
2445 if(!pSelf->Graphics()->LoadPng(Image&: Info, pFilename: aPath, StorageType: DirType))
2446 {
2447 char aError[IO_MAX_PATH_LENGTH + 64];
2448 str_format(buffer: aError, buffer_size: sizeof(aError), format: "Failed to load menu image from '%s'", aPath);
2449 pSelf->Console()->Print(Level: IConsole::OUTPUT_LEVEL_ADDINFO, pFrom: "menus", pStr: aError);
2450 return 0;
2451 }
2452 if(Info.m_Format != CImageInfo::FORMAT_RGBA)
2453 {
2454 Info.Free();
2455 char aError[IO_MAX_PATH_LENGTH + 64];
2456 str_format(buffer: aError, buffer_size: sizeof(aError), format: "Failed to load menu image from '%s': must be an RGBA image", aPath);
2457 pSelf->Console()->Print(Level: IConsole::OUTPUT_LEVEL_ADDINFO, pFrom: "menus", pStr: aError);
2458 return 0;
2459 }
2460
2461 MenuImage.m_OrgTexture = pSelf->Graphics()->LoadTextureRaw(Image: Info, Flags: 0, pTexName: aPath);
2462
2463 ConvertToGrayscale(Image: Info);
2464 MenuImage.m_GreyTexture = pSelf->Graphics()->LoadTextureRawMove(Image&: Info, Flags: 0, pTexName: aPath);
2465
2466 str_truncate(dst: MenuImage.m_aName, dst_size: sizeof(MenuImage.m_aName), src: pName, truncation_len: str_length(str: pName) - str_length(str: pExtension));
2467 pSelf->m_vMenuImages.push_back(x: MenuImage);
2468
2469 pSelf->RenderLoading(pCaption: Localize(pStr: "Loading DDNet Client"), pContent: Localize(pStr: "Loading menu images"), IncreaseCounter: 0);
2470
2471 return 0;
2472}
2473
2474const CMenus::CMenuImage *CMenus::FindMenuImage(const char *pName)
2475{
2476 for(auto &Image : m_vMenuImages)
2477 if(str_comp(a: Image.m_aName, b: pName) == 0)
2478 return &Image;
2479 return nullptr;
2480}
2481
2482void CMenus::SetMenuPage(int NewPage)
2483{
2484 const int OldPage = m_MenuPage;
2485 m_MenuPage = NewPage;
2486 if(NewPage >= PAGE_INTERNET && NewPage <= PAGE_FAVORITE_COMMUNITY_5)
2487 {
2488 g_Config.m_UiPage = NewPage;
2489 bool ForceRefresh = false;
2490 if(m_ForceRefreshLanPage)
2491 {
2492 ForceRefresh = NewPage == PAGE_LAN;
2493 m_ForceRefreshLanPage = false;
2494 }
2495 if(OldPage != NewPage || ForceRefresh)
2496 {
2497 RefreshBrowserTab(Force: ForceRefresh);
2498 }
2499 }
2500}
2501
2502void CMenus::RefreshBrowserTab(bool Force)
2503{
2504 if(g_Config.m_UiPage == PAGE_INTERNET)
2505 {
2506 if(Force || ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_INTERNET)
2507 {
2508 if(Force || ServerBrowser()->GetCurrentType() == IServerBrowser::TYPE_LAN)
2509 {
2510 Client()->RequestDDNetInfo();
2511 }
2512 ServerBrowser()->Refresh(Type: IServerBrowser::TYPE_INTERNET);
2513 UpdateCommunityCache(Force: true);
2514 }
2515 }
2516 else if(g_Config.m_UiPage == PAGE_LAN)
2517 {
2518 if(Force || ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_LAN)
2519 {
2520 ServerBrowser()->Refresh(Type: IServerBrowser::TYPE_LAN);
2521 UpdateCommunityCache(Force: true);
2522 }
2523 }
2524 else if(g_Config.m_UiPage == PAGE_FAVORITES)
2525 {
2526 if(Force || ServerBrowser()->GetCurrentType() != IServerBrowser::TYPE_FAVORITES)
2527 {
2528 if(Force || ServerBrowser()->GetCurrentType() == IServerBrowser::TYPE_LAN)
2529 {
2530 Client()->RequestDDNetInfo();
2531 }
2532 ServerBrowser()->Refresh(Type: IServerBrowser::TYPE_FAVORITES);
2533 UpdateCommunityCache(Force: true);
2534 }
2535 }
2536 else if(g_Config.m_UiPage >= PAGE_FAVORITE_COMMUNITY_1 && g_Config.m_UiPage <= PAGE_FAVORITE_COMMUNITY_5)
2537 {
2538 const int BrowserType = g_Config.m_UiPage - PAGE_FAVORITE_COMMUNITY_1 + IServerBrowser::TYPE_FAVORITE_COMMUNITY_1;
2539 if(Force || ServerBrowser()->GetCurrentType() != BrowserType)
2540 {
2541 if(Force || ServerBrowser()->GetCurrentType() == IServerBrowser::TYPE_LAN)
2542 {
2543 Client()->RequestDDNetInfo();
2544 }
2545 ServerBrowser()->Refresh(Type: BrowserType);
2546 UpdateCommunityCache(Force: true);
2547 }
2548 }
2549}
2550
2551void CMenus::ForceRefreshLanPage()
2552{
2553 m_ForceRefreshLanPage = true;
2554}
2555
2556void CMenus::SetShowStart(bool ShowStart)
2557{
2558 m_ShowStart = ShowStart;
2559}
2560
2561void CMenus::ShowQuitPopup()
2562{
2563 m_Popup = POPUP_QUIT;
2564}
2565