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#include "ghost.h"
4#include "menus.h"
5#include "motd.h"
6#include "voting.h"
7
8#include <base/color.h>
9#include <base/dbg.h>
10#include <base/math.h>
11#include <base/str.h>
12#include <base/time.h>
13
14#include <engine/console.h>
15#include <engine/demo.h>
16#include <engine/favorites.h>
17#include <engine/font_icons.h>
18#include <engine/friends.h>
19#include <engine/ghost.h>
20#include <engine/graphics.h>
21#include <engine/keys.h>
22#include <engine/serverbrowser.h>
23#include <engine/shared/config.h>
24#include <engine/shared/localization.h>
25#include <engine/storage.h>
26#include <engine/textrender.h>
27
28#include <generated/client_data.h>
29#include <generated/protocol.h>
30
31#include <game/client/animstate.h>
32#include <game/client/components/countryflags.h>
33#include <game/client/components/touch_controls.h>
34#include <game/client/gameclient.h>
35#include <game/client/ui.h>
36#include <game/client/ui_listbox.h>
37#include <game/client/ui_scrollregion.h>
38#include <game/localization.h>
39
40#include <algorithm>
41#include <chrono>
42
43using namespace std::chrono_literals;
44
45void CMenus::RenderGame(CUIRect MainView)
46{
47 CUIRect Button, ButtonBars, ButtonBar, ButtonBar2;
48 bool ShowDDRaceButtons = MainView.w > 855.0f;
49 MainView.HSplitTop(Cut: 45.0f + (g_Config.m_ClTouchControls ? 35.0f : 0.0f), pTop: &ButtonBars, pBottom: &MainView);
50 ButtonBars.Draw(Color: ms_ColorTabbarActive, Corners: IGraphics::CORNER_B, Rounding: 10.0f);
51 ButtonBars.Margin(Cut: 10.0f, pOtherRect: &ButtonBars);
52 ButtonBars.HSplitTop(Cut: 25.0f, pTop: &ButtonBar, pBottom: &ButtonBars);
53 if(g_Config.m_ClTouchControls)
54 {
55 ButtonBars.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &ButtonBars);
56 ButtonBars.HSplitTop(Cut: 25.0f, pTop: &ButtonBar2, pBottom: &ButtonBars);
57 }
58
59 ButtonBar.VSplitRight(Cut: 120.0f, pLeft: &ButtonBar, pRight: &Button);
60 static CButtonContainer s_DisconnectButton;
61 if(DoButton_Menu(pButtonContainer: &s_DisconnectButton, pText: Localize(pStr: "Disconnect"), Checked: 0, pRect: &Button))
62 {
63 if((GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0) ||
64 GameClient()->m_TouchControls.HasEditingChanges() ||
65 GameClient()->m_Menus.m_MenusIngameTouchControls.UnsavedChanges())
66 {
67 char aBuf[256] = {'\0'};
68 if(GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
69 {
70 str_copy(dst&: aBuf, src: Localize(pStr: "Are you sure that you want to disconnect?"));
71 }
72 if(GameClient()->m_TouchControls.HasEditingChanges() ||
73 GameClient()->m_Menus.m_MenusIngameTouchControls.UnsavedChanges())
74 {
75 if(aBuf[0] != '\0')
76 {
77 str_append(dst&: aBuf, src: "\n\n");
78 }
79 str_append(dst&: aBuf, src: Localize(pStr: "There's an unsaved change in the touch controls editor, you might want to save it."));
80 }
81 PopupConfirm(pTitle: Localize(pStr: "Disconnect"), pMessage: aBuf, pConfirmButtonLabel: Localize(pStr: "Yes"), pCancelButtonLabel: Localize(pStr: "No"), pfnConfirmButtonCallback: &CMenus::PopupConfirmDisconnect);
82 }
83 else
84 {
85 Client()->Disconnect();
86 RefreshBrowserTab(Force: true);
87 }
88 }
89
90 ButtonBar.VSplitRight(Cut: 5.0f, pLeft: &ButtonBar, pRight: nullptr);
91 ButtonBar.VSplitRight(Cut: 170.0f, pLeft: &ButtonBar, pRight: &Button);
92
93 static CButtonContainer s_DummyButton;
94 if(!Client()->DummyAllowed())
95 {
96 DoButton_Menu(pButtonContainer: &s_DummyButton, pText: Localize(pStr: "Connect Dummy"), Checked: 1, pRect: &Button);
97 Ui()->DoToolTip(pId: &s_DummyButton, pNearRect: &Button, pText: Localize(pStr: "Dummy is not allowed on this server"));
98 }
99 else if(Client()->DummyConnectingDelayed())
100 {
101 DoButton_Menu(pButtonContainer: &s_DummyButton, pText: Localize(pStr: "Connect Dummy"), Checked: 1, pRect: &Button);
102 Ui()->DoToolTip(pId: &s_DummyButton, pNearRect: &Button, pText: Localize(pStr: "Please wait…"));
103 }
104 else if(Client()->DummyConnecting())
105 {
106 DoButton_Menu(pButtonContainer: &s_DummyButton, pText: Localize(pStr: "Connecting dummy"), Checked: 1, pRect: &Button);
107 }
108 else if(DoButton_Menu(pButtonContainer: &s_DummyButton, pText: Client()->DummyConnected() ? Localize(pStr: "Disconnect Dummy") : Localize(pStr: "Connect Dummy"), Checked: 0, pRect: &Button))
109 {
110 if(!Client()->DummyConnected())
111 {
112 Client()->DummyConnect();
113 }
114 else
115 {
116 if(GameClient()->CurrentRaceTime() / 60 >= g_Config.m_ClConfirmDisconnectTime && g_Config.m_ClConfirmDisconnectTime >= 0)
117 {
118 PopupConfirm(pTitle: Localize(pStr: "Disconnect Dummy"), pMessage: Localize(pStr: "Are you sure that you want to disconnect your dummy?"), pConfirmButtonLabel: Localize(pStr: "Yes"), pCancelButtonLabel: Localize(pStr: "No"), pfnConfirmButtonCallback: &CMenus::PopupConfirmDisconnectDummy);
119 }
120 else
121 {
122 Client()->DummyDisconnect(pReason: nullptr);
123 SetActive(false);
124 }
125 }
126 }
127
128 ButtonBar.VSplitRight(Cut: 5.0f, pLeft: &ButtonBar, pRight: nullptr);
129 ButtonBar.VSplitRight(Cut: 140.0f, pLeft: &ButtonBar, pRight: &Button);
130 static CButtonContainer s_DemoButton;
131 const bool Recording = DemoRecorder(Recorder: RECORDER_MANUAL)->IsRecording();
132 if(DoButton_Menu(pButtonContainer: &s_DemoButton, pText: Recording ? Localize(pStr: "Stop record") : Localize(pStr: "Record demo"), Checked: 0, pRect: &Button))
133 {
134 if(!Recording)
135 Client()->DemoRecorder_Start(pFilename: GameClient()->Map()->BaseName(), WithTimestamp: true, Recorder: RECORDER_MANUAL);
136 else
137 Client()->DemoRecorder(Recorder: RECORDER_MANUAL)->Stop(Mode: IDemoRecorder::EStopMode::KEEP_FILE);
138 }
139
140 bool Paused = false;
141 bool Spec = false;
142 if(GameClient()->m_Snap.m_LocalClientId >= 0)
143 {
144 Paused = GameClient()->m_aClients[GameClient()->m_Snap.m_LocalClientId].m_Paused;
145 Spec = GameClient()->m_aClients[GameClient()->m_Snap.m_LocalClientId].m_Spec;
146 }
147
148 if(GameClient()->m_Snap.m_pLocalInfo && GameClient()->m_Snap.m_pGameInfoObj && !Paused && !Spec)
149 {
150 if(GameClient()->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS)
151 {
152 ButtonBar.VSplitLeft(Cut: 120.0f, pLeft: &Button, pRight: &ButtonBar);
153 ButtonBar.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &ButtonBar);
154 static CButtonContainer s_SpectateButton;
155 if(!Client()->DummyConnecting() && DoButton_Menu(pButtonContainer: &s_SpectateButton, pText: Localize(pStr: "Spectate"), Checked: 0, pRect: &Button))
156 {
157 if(g_Config.m_ClDummy == 0 || Client()->DummyConnected())
158 {
159 GameClient()->SendSwitchTeam(Team: TEAM_SPECTATORS);
160 SetActive(false);
161 }
162 }
163 }
164
165 if(GameClient()->IsTeamPlay())
166 {
167 if(GameClient()->m_Snap.m_pLocalInfo->m_Team != TEAM_RED)
168 {
169 ButtonBar.VSplitLeft(Cut: 100.0f, pLeft: &Button, pRight: &ButtonBar);
170 ButtonBar.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &ButtonBar);
171 static CButtonContainer s_JoinRedButton;
172 if(!Client()->DummyConnecting() && DoButton_Menu(pButtonContainer: &s_JoinRedButton, pText: Localize(pStr: "Join red"), Checked: 0, pRect: &Button))
173 {
174 GameClient()->SendSwitchTeam(Team: TEAM_RED);
175 SetActive(false);
176 }
177 }
178
179 if(GameClient()->m_Snap.m_pLocalInfo->m_Team != TEAM_BLUE)
180 {
181 ButtonBar.VSplitLeft(Cut: 100.0f, pLeft: &Button, pRight: &ButtonBar);
182 ButtonBar.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &ButtonBar);
183 static CButtonContainer s_JoinBlueButton;
184 if(!Client()->DummyConnecting() && DoButton_Menu(pButtonContainer: &s_JoinBlueButton, pText: Localize(pStr: "Join blue"), Checked: 0, pRect: &Button))
185 {
186 GameClient()->SendSwitchTeam(Team: TEAM_BLUE);
187 SetActive(false);
188 }
189 }
190 }
191 else
192 {
193 if(GameClient()->m_Snap.m_pLocalInfo->m_Team != TEAM_GAME)
194 {
195 ButtonBar.VSplitLeft(Cut: 120.0f, pLeft: &Button, pRight: &ButtonBar);
196 ButtonBar.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &ButtonBar);
197 static CButtonContainer s_JoinGameButton;
198 if(!Client()->DummyConnecting() && DoButton_Menu(pButtonContainer: &s_JoinGameButton, pText: Localize(pStr: "Join game"), Checked: 0, pRect: &Button))
199 {
200 GameClient()->SendSwitchTeam(Team: TEAM_GAME);
201 SetActive(false);
202 }
203 }
204 }
205
206 if(GameClient()->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS && (ShowDDRaceButtons || !GameClient()->IsTeamPlay()))
207 {
208 ButtonBar.VSplitLeft(Cut: 65.0f, pLeft: &Button, pRight: &ButtonBar);
209 ButtonBar.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &ButtonBar);
210
211 static CButtonContainer s_KillButton;
212 if(DoButton_Menu(pButtonContainer: &s_KillButton, pText: Localize(pStr: "Kill"), Checked: 0, pRect: &Button))
213 {
214 GameClient()->SendKill();
215 SetActive(false);
216 }
217 }
218 }
219
220 if(GameClient()->m_ReceivedDDNetPlayer && GameClient()->m_Snap.m_pLocalInfo && (ShowDDRaceButtons || !GameClient()->IsTeamPlay()))
221 {
222 if(GameClient()->m_Snap.m_pLocalInfo->m_Team != TEAM_SPECTATORS || Paused || Spec)
223 {
224 ButtonBar.VSplitLeft(Cut: (!Paused && !Spec) ? 65.0f : 120.0f, pLeft: &Button, pRight: &ButtonBar);
225 ButtonBar.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &ButtonBar);
226
227 static CButtonContainer s_PauseButton;
228 if(DoButton_Menu(pButtonContainer: &s_PauseButton, pText: (!Paused && !Spec) ? Localize(pStr: "Pause") : Localize(pStr: "Join game"), Checked: 0, pRect: &Button))
229 {
230 Console()->ExecuteLine(pStr: "say /pause", ClientId: IConsole::CLIENT_ID_UNSPECIFIED);
231 SetActive(false);
232 }
233 }
234 }
235
236 if(GameClient()->m_Snap.m_pLocalInfo && (GameClient()->m_Snap.m_pLocalInfo->m_Team == TEAM_SPECTATORS || Paused || Spec))
237 {
238 ButtonBar.VSplitLeft(Cut: 32.0f, pLeft: &Button, pRight: &ButtonBar);
239 ButtonBar.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &ButtonBar);
240
241 static CButtonContainer s_AutoCameraButton;
242
243 bool Active = GameClient()->m_Camera.m_AutoSpecCamera && GameClient()->m_Camera.SpectatingPlayer() && GameClient()->m_Camera.CanUseAutoSpecCamera();
244 bool Enabled = g_Config.m_ClSpecAutoSync;
245 if(Ui()->DoButton_FontIcon(pButtonContainer: &s_AutoCameraButton, pText: FontIcon::CAMERA, Checked: !Active, pRect: &Button, Flags: BUTTONFLAG_LEFT, Corners: IGraphics::CORNER_ALL, Enabled))
246 {
247 GameClient()->m_Camera.ToggleAutoSpecCamera();
248 }
249 GameClient()->m_Camera.UpdateAutoSpecCameraTooltip();
250 Ui()->DoToolTip(pId: &s_AutoCameraButton, pNearRect: &Button, pText: GameClient()->m_Camera.AutoSpecCameraTooltip());
251 }
252
253 if(g_Config.m_ClTouchControls)
254 {
255 ButtonBar2.VSplitLeft(Cut: 200.0f, pLeft: &Button, pRight: &ButtonBar2);
256 static char s_TouchControlsEditCheckbox;
257 if(DoButton_CheckBox(pId: &s_TouchControlsEditCheckbox, pText: Localize(pStr: "Edit touch controls"), Checked: GameClient()->m_TouchControls.IsEditingActive(), pRect: &Button))
258 {
259 if(GameClient()->m_TouchControls.IsEditingActive() && m_MenusIngameTouchControls.UnsavedChanges())
260 {
261 m_MenusIngameTouchControls.m_pOldSelectedButton = GameClient()->m_TouchControls.SelectedButton();
262 m_MenusIngameTouchControls.m_pNewSelectedButton = nullptr;
263 PopupConfirm(pTitle: Localize(pStr: "Unsaved changes"), pMessage: Localize(pStr: "Save all changes before turning off the editor?"), pConfirmButtonLabel: Localize(pStr: "Save"), pCancelButtonLabel: Localize(pStr: "Cancel"), pfnConfirmButtonCallback: &CMenus::PopupConfirmTurnOffEditor);
264 }
265 else
266 {
267 GameClient()->m_TouchControls.SetEditingActive(!GameClient()->m_TouchControls.IsEditingActive());
268 if(GameClient()->m_TouchControls.IsEditingActive())
269 {
270 GameClient()->m_TouchControls.ResetVirtualVisibilities();
271 m_MenusIngameTouchControls.m_EditElement = CMenusIngameTouchControls::EElementType::LAYOUT;
272 }
273 else
274 {
275 m_MenusIngameTouchControls.ResetButtonPointers();
276 }
277 }
278 }
279
280 ButtonBar2.VSplitRight(Cut: 80.0f, pLeft: &ButtonBar2, pRight: &Button);
281 static CButtonContainer s_CloseButton;
282 if(DoButton_Menu(pButtonContainer: &s_CloseButton, pText: Localize(pStr: "Close"), Checked: 0, pRect: &Button))
283 {
284 SetActive(false);
285 }
286
287 ButtonBar2.VSplitRight(Cut: 5.0f, pLeft: &ButtonBar2, pRight: nullptr);
288 ButtonBar2.VSplitRight(Cut: 160.0f, pLeft: &ButtonBar2, pRight: &Button);
289 static CButtonContainer s_RemoveConsoleButton;
290 if(DoButton_Menu(pButtonContainer: &s_RemoveConsoleButton, pText: Localize(pStr: "Remote console"), Checked: 0, pRect: &Button))
291 {
292 Console()->ExecuteLine(pStr: "toggle_remote_console", ClientId: IConsole::CLIENT_ID_UNSPECIFIED);
293 }
294
295 ButtonBar2.VSplitRight(Cut: 5.0f, pLeft: &ButtonBar2, pRight: nullptr);
296 ButtonBar2.VSplitRight(Cut: 120.0f, pLeft: &ButtonBar2, pRight: &Button);
297 static CButtonContainer s_LocalConsoleButton;
298 if(DoButton_Menu(pButtonContainer: &s_LocalConsoleButton, pText: Localize(pStr: "Console"), Checked: 0, pRect: &Button))
299 {
300 Console()->ExecuteLine(pStr: "toggle_local_console", ClientId: IConsole::CLIENT_ID_UNSPECIFIED);
301 }
302 // Only when these are all false, the preview page is rendered. Once the page is not rendered, update is needed upon next rendering.
303 if(!GameClient()->m_TouchControls.IsEditingActive() || m_MenusIngameTouchControls.m_CurrentMenu != CMenusIngameTouchControls::EMenuType::MENU_BUTTONS || GameClient()->m_TouchControls.IsButtonEditing())
304 m_MenusIngameTouchControls.m_NeedUpdatePreview = true;
305 // Quit preview all buttons automatically.
306 if(!GameClient()->m_TouchControls.IsEditingActive() || m_MenusIngameTouchControls.m_CurrentMenu != CMenusIngameTouchControls::EMenuType::MENU_PREVIEW)
307 GameClient()->m_TouchControls.SetPreviewAllButtons(false);
308 if(GameClient()->m_TouchControls.IsEditingActive())
309 {
310 // Resolve issues if needed before rendering, so the elements could have a correct value on this frame.
311 // Issues need to be resolved before popup. So CheckCachedSettings could not be bad.
312 m_MenusIngameTouchControls.ResolveIssues();
313 // Do Popups if needed.
314 CTouchControls::CPopupParam PopupParam = GameClient()->m_TouchControls.RequiredPopup();
315 if(PopupParam.m_PopupType != CTouchControls::EPopupType::NUM_POPUPS)
316 {
317 m_MenusIngameTouchControls.DoPopupType(PopupParam);
318 return;
319 }
320 if(m_MenusIngameTouchControls.m_FirstEnter)
321 {
322 m_MenusIngameTouchControls.m_aCachedVisibilities[(int)CTouchControls::EButtonVisibility::DEMO_PLAYER] = CMenusIngameTouchControls::EVisibilityType::EXCLUDE;
323 m_MenusIngameTouchControls.m_ColorActive = color_cast<ColorHSLA>(rgb: GameClient()->m_TouchControls.BackgroundColorActive()).Pack(Alpha: true);
324 m_MenusIngameTouchControls.m_ColorInactive = color_cast<ColorHSLA>(rgb: GameClient()->m_TouchControls.BackgroundColorInactive()).Pack(Alpha: true);
325 m_MenusIngameTouchControls.m_FirstEnter = false;
326 }
327 // Their width is all 505.0f, height is adjustable, you can directly change its h value, so no need for changing where tab is.
328 CUIRect SelectingTab;
329 MainView.HSplitTop(Cut: 40.0f, pTop: nullptr, pBottom: &MainView);
330 MainView.VMargin(Cut: (MainView.w - CMenusIngameTouchControls::BUTTON_EDITOR_WIDTH) / 2.0f, pOtherRect: &MainView);
331 MainView.HSplitTop(Cut: 25.0f, pTop: &SelectingTab, pBottom: &MainView);
332
333 m_MenusIngameTouchControls.RenderSelectingTab(SelectingTab);
334 switch(m_MenusIngameTouchControls.m_CurrentMenu)
335 {
336 case CMenusIngameTouchControls::EMenuType::MENU_FILE: m_MenusIngameTouchControls.RenderTouchControlsEditor(MainView); break;
337 case CMenusIngameTouchControls::EMenuType::MENU_BUTTONS: m_MenusIngameTouchControls.RenderTouchButtonEditor(MainView); break;
338 case CMenusIngameTouchControls::EMenuType::MENU_SETTINGS: m_MenusIngameTouchControls.RenderConfigSettings(MainView); break;
339 case CMenusIngameTouchControls::EMenuType::MENU_PREVIEW: m_MenusIngameTouchControls.RenderPreviewSettings(MainView); break;
340 default: dbg_assert_failed("Unknown selected tab value = %d.", (int)m_MenusIngameTouchControls.m_CurrentMenu);
341 }
342 }
343 }
344}
345
346void CMenus::PopupConfirmDisconnect()
347{
348 Client()->Disconnect();
349}
350
351void CMenus::PopupConfirmDisconnectDummy()
352{
353 Client()->DummyDisconnect(pReason: nullptr);
354 SetActive(false);
355}
356
357void CMenus::PopupConfirmDiscardTouchControlsChanges()
358{
359 if(GameClient()->m_TouchControls.LoadConfigurationFromFile(StorageType: IStorage::TYPE_ALL))
360 {
361 m_MenusIngameTouchControls.m_ColorActive = color_cast<ColorHSLA>(rgb: GameClient()->m_TouchControls.BackgroundColorActive()).Pack(Alpha: true);
362 m_MenusIngameTouchControls.m_ColorInactive = color_cast<ColorHSLA>(rgb: GameClient()->m_TouchControls.BackgroundColorInactive()).Pack(Alpha: true);
363 GameClient()->m_TouchControls.SetEditingChanges(false);
364 }
365 else
366 {
367 SWarning Warning(Localize(pStr: "Error loading touch controls"), Localize(pStr: "Could not load touch controls from file. See local console for details."));
368 Warning.m_AutoHide = false;
369 Client()->AddWarning(Warning);
370 }
371}
372
373void CMenus::PopupConfirmResetTouchControls()
374{
375 bool Success = false;
376 for(int StorageType = IStorage::TYPE_SAVE + 1; StorageType < Storage()->NumPaths(); ++StorageType)
377 {
378 if(GameClient()->m_TouchControls.LoadConfigurationFromFile(StorageType))
379 {
380 Success = true;
381 break;
382 }
383 }
384 if(Success)
385 {
386 m_MenusIngameTouchControls.m_ColorActive = color_cast<ColorHSLA>(rgb: GameClient()->m_TouchControls.BackgroundColorActive()).Pack(Alpha: true);
387 m_MenusIngameTouchControls.m_ColorInactive = color_cast<ColorHSLA>(rgb: GameClient()->m_TouchControls.BackgroundColorInactive()).Pack(Alpha: true);
388 GameClient()->m_TouchControls.SetEditingChanges(true);
389 }
390 else
391 {
392 SWarning Warning(Localize(pStr: "Error loading touch controls"), Localize(pStr: "Could not load default touch controls from file. See local console for details."));
393 Warning.m_AutoHide = false;
394 Client()->AddWarning(Warning);
395 }
396}
397
398void CMenus::PopupConfirmImportTouchControlsClipboard()
399{
400 if(GameClient()->m_TouchControls.LoadConfigurationFromClipboard())
401 {
402 m_MenusIngameTouchControls.m_ColorActive = color_cast<ColorHSLA>(rgb: GameClient()->m_TouchControls.BackgroundColorActive()).Pack(Alpha: true);
403 m_MenusIngameTouchControls.m_ColorInactive = color_cast<ColorHSLA>(rgb: GameClient()->m_TouchControls.BackgroundColorInactive()).Pack(Alpha: true);
404 GameClient()->m_TouchControls.SetEditingChanges(true);
405 }
406 else
407 {
408 SWarning Warning(Localize(pStr: "Error loading touch controls"), Localize(pStr: "Could not load touch controls from clipboard. See local console for details."));
409 Warning.m_AutoHide = false;
410 Client()->AddWarning(Warning);
411 }
412}
413
414void CMenus::PopupConfirmDeleteButton()
415{
416 GameClient()->m_TouchControls.DeleteSelectedButton();
417 m_MenusIngameTouchControls.ResetCachedSettings();
418 GameClient()->m_TouchControls.SetEditingChanges(true);
419}
420
421void CMenus::PopupCancelDeselectButton()
422{
423 m_MenusIngameTouchControls.ResetButtonPointers();
424 m_MenusIngameTouchControls.SetUnsavedChanges(false);
425 m_MenusIngameTouchControls.ResetCachedSettings();
426}
427
428void CMenus::PopupConfirmSelectedNotVisible()
429{
430 if(m_MenusIngameTouchControls.UnsavedChanges())
431 {
432 // The m_pSelectedButton can't nullptr, because this function is triggered when selected button not visible.
433 m_MenusIngameTouchControls.m_pOldSelectedButton = GameClient()->m_TouchControls.SelectedButton();
434 m_MenusIngameTouchControls.m_pNewSelectedButton = nullptr;
435 m_MenusIngameTouchControls.m_CloseMenu = true;
436 m_MenusIngameTouchControls.ChangeSelectedButtonWhileHavingUnsavedChanges();
437 }
438 else
439 {
440 m_MenusIngameTouchControls.ResetButtonPointers();
441 GameClient()->m_Menus.SetActive(false);
442 }
443}
444
445void CMenus::PopupConfirmChangeSelectedButton()
446{
447 if(m_MenusIngameTouchControls.CheckCachedSettings())
448 {
449 GameClient()->m_TouchControls.SetSelectedButton(m_MenusIngameTouchControls.m_pNewSelectedButton);
450 m_MenusIngameTouchControls.SaveCachedSettingsToTarget(pTargetButton: m_MenusIngameTouchControls.m_pOldSelectedButton);
451 // Update wild pointer.
452 if(m_MenusIngameTouchControls.m_pNewSelectedButton != nullptr)
453 m_MenusIngameTouchControls.m_pNewSelectedButton = GameClient()->m_TouchControls.SelectedButton();
454 GameClient()->m_TouchControls.SetEditingChanges(true);
455 m_MenusIngameTouchControls.SetUnsavedChanges(false);
456 PopupCancelChangeSelectedButton();
457 }
458}
459
460void CMenus::PopupCancelChangeSelectedButton()
461{
462 GameClient()->m_TouchControls.SetSelectedButton(m_MenusIngameTouchControls.m_pNewSelectedButton);
463 m_MenusIngameTouchControls.CacheAllSettingsFromTarget(pTargetButton: m_MenusIngameTouchControls.m_pNewSelectedButton);
464 m_MenusIngameTouchControls.SetUnsavedChanges(false);
465 if(m_MenusIngameTouchControls.m_pNewSelectedButton != nullptr)
466 {
467 m_MenusIngameTouchControls.UpdateSampleButton();
468 }
469 else
470 {
471 m_MenusIngameTouchControls.ResetButtonPointers();
472 }
473 if(m_MenusIngameTouchControls.m_CloseMenu)
474 GameClient()->m_Menus.SetActive(false);
475}
476
477void CMenus::PopupConfirmTurnOffEditor()
478{
479 if(m_MenusIngameTouchControls.CheckCachedSettings())
480 {
481 m_MenusIngameTouchControls.SaveCachedSettingsToTarget(pTargetButton: m_MenusIngameTouchControls.m_pOldSelectedButton);
482 GameClient()->m_TouchControls.SetEditingActive(!GameClient()->m_TouchControls.IsEditingActive());
483 m_MenusIngameTouchControls.ResetButtonPointers();
484 }
485}
486
487void CMenus::PopupConfirmOpenWiki()
488{
489 Client()->ViewLink(pLink: Localize(pStr: "https://wiki.ddnet.org/wiki/Touch_controls"));
490}
491
492void CMenus::RenderPlayers(CUIRect MainView)
493{
494 CUIRect Button, Button2, ButtonBar, PlayerList, Player;
495 MainView.Draw(Color: ms_ColorTabbarActive, Corners: IGraphics::CORNER_B, Rounding: 10.0f);
496
497 // list background color
498 MainView.Margin(Cut: 10.0f, pOtherRect: &PlayerList);
499 PlayerList.Draw(Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), Corners: IGraphics::CORNER_ALL, Rounding: 10.0f);
500 PlayerList.Margin(Cut: 10.0f, pOtherRect: &PlayerList);
501
502 // headline
503 PlayerList.HSplitTop(Cut: 34.0f, pTop: &ButtonBar, pBottom: &PlayerList);
504 ButtonBar.VSplitRight(Cut: 231.0f, pLeft: &Player, pRight: &ButtonBar);
505 Ui()->DoLabel(pRect: &Player, pText: Localize(pStr: "Player"), Size: 24.0f, Align: TEXTALIGN_ML);
506
507 ButtonBar.HMargin(Cut: 1.0f, pOtherRect: &ButtonBar);
508 float Width = ButtonBar.h * 2.0f;
509 ButtonBar.VSplitLeft(Cut: Width, pLeft: &Button, pRight: &ButtonBar);
510 RenderTools()->RenderIcon(ImageId: IMAGE_GUIICONS, SpriteId: SPRITE_GUIICON_MUTE, pRect: &Button);
511
512 ButtonBar.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &ButtonBar);
513 ButtonBar.VSplitLeft(Cut: Width, pLeft: &Button, pRight: &ButtonBar);
514 RenderTools()->RenderIcon(ImageId: IMAGE_GUIICONS, SpriteId: SPRITE_GUIICON_EMOTICON_MUTE, pRect: &Button);
515
516 ButtonBar.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &ButtonBar);
517 ButtonBar.VSplitLeft(Cut: Width, pLeft: &Button, pRight: &ButtonBar);
518 RenderTools()->RenderIcon(ImageId: IMAGE_GUIICONS, SpriteId: SPRITE_GUIICON_FRIEND, pRect: &Button);
519
520 int TotalPlayers = 0;
521 for(const auto &pInfoByName : GameClient()->m_Snap.m_apInfoByName)
522 {
523 if(!pInfoByName)
524 continue;
525
526 int Index = pInfoByName->m_ClientId;
527
528 if(Index == GameClient()->m_Snap.m_LocalClientId)
529 continue;
530
531 TotalPlayers++;
532 }
533
534 static CListBox s_ListBox;
535 s_ListBox.DoStart(RowHeight: 24.0f, NumItems: TotalPlayers, ItemsPerRow: 1, RowsPerScroll: 3, SelectedIndex: -1, pRect: &PlayerList);
536
537 // options
538 static char s_aPlayerIds[MAX_CLIENTS][4] = {{0}};
539
540 for(int i = 0, Count = 0; i < MAX_CLIENTS; ++i)
541 {
542 if(!GameClient()->m_Snap.m_apInfoByName[i])
543 continue;
544
545 int Index = GameClient()->m_Snap.m_apInfoByName[i]->m_ClientId;
546 if(Index == GameClient()->m_Snap.m_LocalClientId)
547 continue;
548
549 CGameClient::CClientData &CurrentClient = GameClient()->m_aClients[Index];
550 const CListboxItem Item = s_ListBox.DoNextItem(pId: &CurrentClient);
551
552 Count++;
553
554 if(!Item.m_Visible)
555 continue;
556
557 CUIRect Row = Item.m_Rect;
558 if(Count % 2 == 1)
559 Row.Draw(Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), Corners: IGraphics::CORNER_ALL, Rounding: 5.0f);
560 Row.VSplitRight(Cut: s_ListBox.ScrollbarWidthMax() - s_ListBox.ScrollbarWidth(), pLeft: &Row, pRight: nullptr);
561 Row.VSplitRight(Cut: 300.0f, pLeft: &Player, pRight: &Row);
562
563 // player info
564 Player.VSplitLeft(Cut: 28.0f, pLeft: &Button, pRight: &Player);
565
566 CTeeRenderInfo TeeInfo = CurrentClient.m_RenderInfo;
567 TeeInfo.m_Size = Button.h;
568
569 RenderTools()->RenderIdleTeeAtCenter(pInfo: &TeeInfo, Center: vec2(Button.x + Button.h / 2, Button.y + Button.h / 2));
570 Ui()->DoButtonLogic(pId: &s_aPlayerIds[Index][3], Checked: 0, pRect: &Button, Flags: BUTTONFLAG_NONE);
571 Ui()->DoToolTip(pId: &s_aPlayerIds[Index][3], pNearRect: &Button, pText: CurrentClient.m_aSkinName);
572
573 Player.HSplitTop(Cut: 1.5f, pTop: nullptr, pBottom: &Player);
574 Player.VSplitMid(pLeft: &Player, pRight: &Button);
575 Row.VSplitRight(Cut: 210.0f, pLeft: &Button2, pRight: &Row);
576
577 Ui()->DoLabel(pRect: &Player, pText: CurrentClient.m_aName, Size: 14.0f, Align: TEXTALIGN_ML);
578 Ui()->DoLabel(pRect: &Button, pText: CurrentClient.m_aClan, Size: 14.0f, Align: TEXTALIGN_ML);
579
580 GameClient()->m_CountryFlags.Render(CountryCode: CurrentClient.m_Country, Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.5f),
581 x: Button2.x, y: Button2.y + Button2.h / 2.0f - 0.75f * Button2.h / 2.0f, w: 1.5f * Button2.h, h: 0.75f * Button2.h);
582
583 // ignore chat button
584 Row.HMargin(Cut: 2.0f, pOtherRect: &Row);
585 Row.VSplitLeft(Cut: Width, pLeft: &Button, pRight: &Row);
586 Button.VSplitLeft(Cut: (Width - Button.h) / 4.0f, pLeft: nullptr, pRight: &Button);
587 Button.VSplitLeft(Cut: Button.h, pLeft: &Button, pRight: nullptr);
588 if(g_Config.m_ClShowChatFriends && !CurrentClient.m_Friend)
589 DoButton_Toggle(pId: &s_aPlayerIds[Index][0], Checked: 1, pRect: &Button, Active: false);
590 else if(DoButton_Toggle(pId: &s_aPlayerIds[Index][0], Checked: CurrentClient.m_ChatIgnore, pRect: &Button, Active: true))
591 CurrentClient.m_ChatIgnore ^= 1;
592
593 // ignore emoticon button
594 Row.VSplitLeft(Cut: 30.0f, pLeft: nullptr, pRight: &Row);
595 Row.VSplitLeft(Cut: Width, pLeft: &Button, pRight: &Row);
596 Button.VSplitLeft(Cut: (Width - Button.h) / 4.0f, pLeft: nullptr, pRight: &Button);
597 Button.VSplitLeft(Cut: Button.h, pLeft: &Button, pRight: nullptr);
598 if(g_Config.m_ClShowChatFriends && !CurrentClient.m_Friend)
599 DoButton_Toggle(pId: &s_aPlayerIds[Index][1], Checked: 1, pRect: &Button, Active: false);
600 else if(DoButton_Toggle(pId: &s_aPlayerIds[Index][1], Checked: CurrentClient.m_EmoticonIgnore, pRect: &Button, Active: true))
601 CurrentClient.m_EmoticonIgnore ^= 1;
602
603 // friend button
604 Row.VSplitLeft(Cut: 10.0f, pLeft: nullptr, pRight: &Row);
605 Row.VSplitLeft(Cut: Width, pLeft: &Button, pRight: &Row);
606 Button.VSplitLeft(Cut: (Width - Button.h) / 4.0f, pLeft: nullptr, pRight: &Button);
607 Button.VSplitLeft(Cut: Button.h, pLeft: &Button, pRight: nullptr);
608 if(DoButton_Toggle(pId: &s_aPlayerIds[Index][2], Checked: CurrentClient.m_Friend, pRect: &Button, Active: true))
609 {
610 if(CurrentClient.m_Friend)
611 GameClient()->Friends()->RemoveFriend(pName: CurrentClient.m_aName, pClan: CurrentClient.m_aClan);
612 else
613 GameClient()->Friends()->AddFriend(pName: CurrentClient.m_aName, pClan: CurrentClient.m_aClan);
614
615 GameClient()->Client()->ServerBrowserUpdate();
616 }
617 }
618
619 s_ListBox.DoEnd();
620}
621
622void CMenus::RenderServerInfo(CUIRect MainView)
623{
624 const float FontSizeTitle = 32.0f;
625 const float FontSizeBody = 20.0f;
626
627 const CServerInfo &CurrentServerInfo = Client()->ServerInfo();
628
629 CUIRect ServerInfo, GameInfo, Motd;
630 MainView.Draw(Color: ms_ColorTabbarActive, Corners: IGraphics::CORNER_B, Rounding: 10.0f);
631 MainView.Margin(Cut: 10.0f, pOtherRect: &MainView);
632 MainView.HSplitMid(pTop: &ServerInfo, pBottom: &Motd, Spacing: 10.0f);
633 ServerInfo.VSplitMid(pLeft: &ServerInfo, pRight: &GameInfo, Spacing: 10.0f);
634
635 ServerInfo.Draw(Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), Corners: IGraphics::CORNER_ALL, Rounding: 10.0f);
636 ServerInfo.Margin(Cut: 10.0f, pOtherRect: &ServerInfo);
637
638 CUIRect Label;
639 ServerInfo.HSplitTop(Cut: FontSizeTitle, pTop: &Label, pBottom: &ServerInfo);
640 ServerInfo.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &ServerInfo);
641 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Server info"), Size: FontSizeTitle, Align: TEXTALIGN_ML);
642
643 ServerInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &ServerInfo);
644 ServerInfo.HSplitTop(Cut: FontSizeBody, pTop: nullptr, pBottom: &ServerInfo);
645 Ui()->DoLabel(pRect: &Label, pText: CurrentServerInfo.m_aName, Size: FontSizeBody, Align: TEXTALIGN_ML);
646
647 ServerInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &ServerInfo);
648 char aBuf[256];
649 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s", Localize(pStr: "Address"), CurrentServerInfo.m_aAddress);
650 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
651
652 if(GameClient()->m_Snap.m_pLocalInfo)
653 {
654 ServerInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &ServerInfo);
655 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %d", Localize(pStr: "Ping"), GameClient()->m_Snap.m_pLocalInfo->m_Latency);
656 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
657 }
658
659 ServerInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &ServerInfo);
660 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s", Localize(pStr: "Version"), CurrentServerInfo.m_aVersion);
661 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
662
663 ServerInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &ServerInfo);
664 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s", Localize(pStr: "Password"), CurrentServerInfo.m_Flags & SERVER_FLAG_PASSWORD ? Localize(pStr: "Yes") : Localize(pStr: "No"));
665 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
666
667 const CCommunity *pCommunity = ServerBrowser()->Community(pCommunityId: CurrentServerInfo.m_aCommunityId);
668 if(pCommunity != nullptr)
669 {
670 ServerInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &ServerInfo);
671 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s:", Localize(pStr: "Community"));
672 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
673
674 const CCommunityIcon *pIcon = m_CommunityIcons.Find(pCommunityId: pCommunity->Id());
675 if(pIcon != nullptr)
676 {
677 Label.VSplitLeft(Cut: TextRender()->TextWidth(Size: FontSizeBody, pText: aBuf) + 8.0f, pLeft: nullptr, pRight: &Label);
678 Label.VSplitLeft(Cut: 2.0f * Label.h, pLeft: &Label, pRight: nullptr);
679 m_CommunityIcons.Render(pIcon, Rect: Label, Active: true);
680 static char s_CommunityTooltipButtonId;
681 Ui()->DoButtonLogic(pId: &s_CommunityTooltipButtonId, Checked: 0, pRect: &Label, Flags: BUTTONFLAG_NONE);
682 Ui()->DoToolTip(pId: &s_CommunityTooltipButtonId, pNearRect: &Label, pText: pCommunity->Name());
683 }
684 }
685
686 // copy info button
687 {
688 CUIRect Button;
689 ServerInfo.HSplitBottom(Cut: 20.0f, pTop: &ServerInfo, pBottom: &Button);
690 Button.VSplitRight(Cut: 200.0f, pLeft: &ServerInfo, pRight: &Button);
691 static CButtonContainer s_CopyButton;
692 if(DoButton_Menu(pButtonContainer: &s_CopyButton, pText: Localize(pStr: "Copy info"), Checked: 0, pRect: &Button))
693 {
694 char aInfo[256];
695 str_format(
696 buffer: aInfo,
697 buffer_size: sizeof(aInfo),
698 format: "%s\n"
699 "Address: ddnet://%s\n"
700 "My IGN: %s\n",
701 CurrentServerInfo.m_aName,
702 CurrentServerInfo.m_aAddress,
703 Client()->PlayerName());
704 Input()->SetClipboardText(aInfo);
705 }
706 }
707
708 // favorite checkbox
709 {
710 CUIRect Button;
711 TRISTATE IsFavorite = Favorites()->IsFavorite(pAddrs: CurrentServerInfo.m_aAddresses, NumAddrs: CurrentServerInfo.m_NumAddresses);
712 ServerInfo.HSplitBottom(Cut: 20.0f, pTop: &ServerInfo, pBottom: &Button);
713 static int s_AddFavButton = 0;
714 if(DoButton_CheckBox(pId: &s_AddFavButton, pText: Localize(pStr: "Favorite"), Checked: IsFavorite != TRISTATE::NONE, pRect: &Button))
715 {
716 if(IsFavorite != TRISTATE::NONE)
717 Favorites()->Remove(pAddrs: CurrentServerInfo.m_aAddresses, NumAddrs: CurrentServerInfo.m_NumAddresses);
718 else
719 Favorites()->Add(pAddrs: CurrentServerInfo.m_aAddresses, NumAddrs: CurrentServerInfo.m_NumAddresses);
720 }
721 }
722
723 GameInfo.Draw(Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), Corners: IGraphics::CORNER_ALL, Rounding: 10.0f);
724 GameInfo.Margin(Cut: 10.0f, pOtherRect: &GameInfo);
725
726 GameInfo.HSplitTop(Cut: FontSizeTitle, pTop: &Label, pBottom: &GameInfo);
727 GameInfo.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &GameInfo);
728 Ui()->DoLabel(pRect: &Label, pText: Localize(pStr: "Game info"), Size: FontSizeTitle, Align: TEXTALIGN_ML);
729
730 GameInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &GameInfo);
731 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s", Localize(pStr: "Game type"), CurrentServerInfo.m_aGameType);
732 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
733
734 GameInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &GameInfo);
735 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s", Localize(pStr: "Map"), CurrentServerInfo.m_aMap);
736 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
737
738 const auto *pGameInfoObj = GameClient()->m_Snap.m_pGameInfoObj;
739 if(pGameInfoObj)
740 {
741 if(pGameInfoObj->m_ScoreLimit)
742 {
743 GameInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &GameInfo);
744 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %d", Localize(pStr: "Score limit"), pGameInfoObj->m_ScoreLimit);
745 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
746 }
747
748 if(pGameInfoObj->m_TimeLimit)
749 {
750 GameInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &GameInfo);
751 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Time limit: %d min"), pGameInfoObj->m_TimeLimit);
752 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
753 }
754
755 if(pGameInfoObj->m_RoundCurrent && pGameInfoObj->m_RoundNum)
756 {
757 GameInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &GameInfo);
758 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: Localize(pStr: "Round %d/%d"), pGameInfoObj->m_RoundCurrent, pGameInfoObj->m_RoundNum);
759 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
760 }
761 }
762
763 if(GameClient()->m_GameInfo.m_DDRaceTeam)
764 {
765 const char *pTeamMode = nullptr;
766 switch(Config()->m_SvTeam)
767 {
768 case SV_TEAM_FORBIDDEN:
769 pTeamMode = Localize(pStr: "forbidden", pContext: "Team status");
770 break;
771 case SV_TEAM_ALLOWED:
772 if(g_Config.m_SvSoloServer)
773 pTeamMode = Localize(pStr: "solo", pContext: "Team status");
774 else
775 pTeamMode = Localize(pStr: "allowed", pContext: "Team status");
776 break;
777 case SV_TEAM_MANDATORY:
778 pTeamMode = Localize(pStr: "required", pContext: "Team status");
779 break;
780 case SV_TEAM_FORCED_SOLO:
781 pTeamMode = Localize(pStr: "solo", pContext: "Team status");
782 break;
783 default:
784 dbg_assert_failed("unknown team mode");
785 }
786 int MinTeamSize = GameClient()->MinTeamSize();
787 int MaxTeamSize = GameClient()->MaxTeamSize();
788 if((Config()->m_SvTeam == SV_TEAM_ALLOWED || Config()->m_SvTeam == SV_TEAM_MANDATORY) && (MinTeamSize != DefaultConfig::SvMinTeamSize || MaxTeamSize != DefaultConfig::SvMaxTeamSize))
789 {
790 if(MinTeamSize != DefaultConfig::SvMinTeamSize && MaxTeamSize != DefaultConfig::SvMaxTeamSize)
791 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s (%s %d, %s %d)", Localize(pStr: "Teams"), pTeamMode, Localize(pStr: "minimum", pContext: "Team size"), MinTeamSize, Localize(pStr: "maximum", pContext: "Team size"), MaxTeamSize);
792 else if(MinTeamSize != DefaultConfig::SvMinTeamSize)
793 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s (%s %d)", Localize(pStr: "Teams"), pTeamMode, Localize(pStr: "minimum", pContext: "Team size"), MinTeamSize);
794 else
795 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s (%s %d)", Localize(pStr: "Teams"), pTeamMode, Localize(pStr: "maximum", pContext: "Team size"), MaxTeamSize);
796 }
797 else
798 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %s", Localize(pStr: "Teams"), pTeamMode);
799 GameInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &GameInfo);
800 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
801 }
802
803 GameInfo.HSplitTop(Cut: FontSizeBody, pTop: &Label, pBottom: &GameInfo);
804 str_format(buffer: aBuf, buffer_size: sizeof(aBuf), format: "%s: %d/%d", Localize(pStr: "Players"), GameClient()->m_Snap.m_NumPlayers, CurrentServerInfo.m_MaxClients);
805 Ui()->DoLabel(pRect: &Label, pText: aBuf, Size: FontSizeBody, Align: TEXTALIGN_ML);
806
807 RenderServerInfoMotd(Motd);
808}
809
810void CMenus::RenderServerInfoMotd(CUIRect Motd)
811{
812 const float MotdFontSize = 16.0f;
813 Motd.Draw(Color: ColorRGBA(1.0f, 1.0f, 1.0f, 0.25f), Corners: IGraphics::CORNER_ALL, Rounding: 10.0f);
814 Motd.Margin(Cut: 10.0f, pOtherRect: &Motd);
815
816 CUIRect MotdHeader;
817 Motd.HSplitTop(Cut: 2.0f * MotdFontSize, pTop: &MotdHeader, pBottom: &Motd);
818 Motd.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &Motd);
819 Ui()->DoLabel(pRect: &MotdHeader, pText: Localize(pStr: "MOTD"), Size: 2.0f * MotdFontSize, Align: TEXTALIGN_ML);
820
821 if(!GameClient()->m_Motd.ServerMotd()[0])
822 return;
823
824 static CScrollRegion s_ScrollRegion;
825 CScrollRegionParams ScrollParams;
826 ScrollParams.m_ScrollUnit = 5 * MotdFontSize;
827 s_ScrollRegion.Begin(pClipRect: &Motd, pParams: &ScrollParams);
828
829 static float s_MotdHeight = 0.0f;
830 static int64_t s_MotdLastUpdateTime = -1;
831 if(!m_MotdTextContainerIndex.Valid() || s_MotdLastUpdateTime == -1 || s_MotdLastUpdateTime != GameClient()->m_Motd.ServerMotdUpdateTime())
832 {
833 CTextCursor Cursor;
834 Cursor.m_FontSize = MotdFontSize;
835 Cursor.m_LineWidth = Motd.w;
836 TextRender()->RecreateTextContainer(TextContainerIndex&: m_MotdTextContainerIndex, pCursor: &Cursor, pText: GameClient()->m_Motd.ServerMotd());
837 s_MotdHeight = Cursor.Height();
838 s_MotdLastUpdateTime = GameClient()->m_Motd.ServerMotdUpdateTime();
839 }
840
841 CUIRect MotdTextArea;
842 Motd.HSplitTop(Cut: s_MotdHeight, pTop: &MotdTextArea, pBottom: &Motd);
843 s_ScrollRegion.AddRect(Rect: MotdTextArea);
844
845 if(m_MotdTextContainerIndex.Valid())
846 TextRender()->RenderTextContainer(TextContainerIndex: m_MotdTextContainerIndex, TextColor: TextRender()->DefaultTextColor(), TextOutlineColor: TextRender()->DefaultTextOutlineColor(), X: MotdTextArea.x, Y: MotdTextArea.y);
847
848 s_ScrollRegion.End();
849}
850
851bool CMenus::RenderServerControlServer(CUIRect MainView, bool UpdateScroll)
852{
853 CUIRect List = MainView;
854 int NumVoteOptions = 0;
855 int aIndices[MAX_VOTE_OPTIONS];
856 int Selected = -1;
857 int TotalShown = 0;
858
859 int i = 0;
860 for(const CVoteOptionClient *pOption = GameClient()->m_Voting.FirstOption(); pOption; pOption = pOption->m_pNext, i++)
861 {
862 if(!m_FilterInput.IsEmpty() && !str_utf8_find_nocase(haystack: pOption->m_aDescription, needle: m_FilterInput.GetString()))
863 continue;
864 if(i == m_CallvoteSelectedOption)
865 Selected = TotalShown;
866 TotalShown++;
867 }
868
869 static CListBox s_ListBox;
870 s_ListBox.DoStart(RowHeight: 19.0f, NumItems: TotalShown, ItemsPerRow: 1, RowsPerScroll: 3, SelectedIndex: Selected, pRect: &List);
871
872 i = 0;
873 for(const CVoteOptionClient *pOption = GameClient()->m_Voting.FirstOption(); pOption; pOption = pOption->m_pNext, i++)
874 {
875 if(!m_FilterInput.IsEmpty() && !str_utf8_find_nocase(haystack: pOption->m_aDescription, needle: m_FilterInput.GetString()))
876 continue;
877 aIndices[NumVoteOptions] = i;
878 NumVoteOptions++;
879
880 const CListboxItem Item = s_ListBox.DoNextItem(pId: pOption);
881 if(!Item.m_Visible)
882 continue;
883
884 CUIRect Label;
885 Item.m_Rect.VMargin(Cut: 2.0f, pOtherRect: &Label);
886 Ui()->DoLabel(pRect: &Label, pText: pOption->m_aDescription, Size: 13.0f, Align: TEXTALIGN_ML);
887 }
888
889 Selected = s_ListBox.DoEnd();
890 if(UpdateScroll)
891 s_ListBox.ScrollToSelected();
892 m_CallvoteSelectedOption = Selected != -1 ? aIndices[Selected] : -1;
893 return s_ListBox.WasItemActivated();
894}
895
896bool CMenus::RenderServerControlKick(CUIRect MainView, bool FilterSpectators, bool UpdateScroll)
897{
898 int NumOptions = 0;
899 int Selected = -1;
900 int aPlayerIds[MAX_CLIENTS];
901 for(const auto &pInfoByName : GameClient()->m_Snap.m_apInfoByName)
902 {
903 if(!pInfoByName)
904 continue;
905
906 int Index = pInfoByName->m_ClientId;
907 if(Index == GameClient()->m_Snap.m_LocalClientId || (FilterSpectators && pInfoByName->m_Team == TEAM_SPECTATORS))
908 continue;
909
910 if(!str_utf8_find_nocase(haystack: GameClient()->m_aClients[Index].m_aName, needle: m_FilterInput.GetString()))
911 continue;
912
913 if(m_CallvoteSelectedPlayer == Index)
914 Selected = NumOptions;
915 aPlayerIds[NumOptions] = Index;
916 NumOptions++;
917 }
918
919 static CListBox s_ListBox;
920 s_ListBox.DoStart(RowHeight: 24.0f, NumItems: NumOptions, ItemsPerRow: 1, RowsPerScroll: 3, SelectedIndex: Selected, pRect: &MainView);
921
922 for(int i = 0; i < NumOptions; i++)
923 {
924 const CListboxItem Item = s_ListBox.DoNextItem(pId: &aPlayerIds[i]);
925 if(!Item.m_Visible)
926 continue;
927
928 CUIRect TeeRect, Label;
929 Item.m_Rect.VSplitLeft(Cut: Item.m_Rect.h, pLeft: &TeeRect, pRight: &Label);
930
931 CTeeRenderInfo TeeInfo = GameClient()->m_aClients[aPlayerIds[i]].m_RenderInfo;
932 TeeInfo.m_Size = TeeRect.h;
933
934 RenderTools()->RenderIdleTeeAtCenter(pInfo: &TeeInfo, Center: vec2(TeeRect.x + TeeInfo.m_Size / 2, TeeRect.y + TeeInfo.m_Size / 2));
935
936 Ui()->DoLabel(pRect: &Label, pText: GameClient()->m_aClients[aPlayerIds[i]].m_aName, Size: 16.0f, Align: TEXTALIGN_ML);
937 }
938
939 Selected = s_ListBox.DoEnd();
940 if(UpdateScroll)
941 s_ListBox.ScrollToSelected();
942 m_CallvoteSelectedPlayer = Selected != -1 ? aPlayerIds[Selected] : -1;
943 return s_ListBox.WasItemActivated();
944}
945
946void CMenus::RenderServerControl(CUIRect MainView)
947{
948 enum class EServerControlTab
949 {
950 SETTINGS,
951 KICKVOTE,
952 SPECVOTE,
953 };
954 static EServerControlTab s_ControlPage = EServerControlTab::SETTINGS;
955
956 // render background
957 CUIRect Bottom, RconExtension, TabBar, Button;
958 MainView.HSplitTop(Cut: 20.0f, pTop: &Bottom, pBottom: &MainView);
959 Bottom.Draw(Color: ms_ColorTabbarActive, Corners: IGraphics::CORNER_NONE, Rounding: 0.0f);
960 MainView.HSplitTop(Cut: 20.0f, pTop: &TabBar, pBottom: &MainView);
961 MainView.Draw(Color: ms_ColorTabbarActive, Corners: IGraphics::CORNER_B, Rounding: 10.0f);
962 MainView.Margin(Cut: 10.0f, pOtherRect: &MainView);
963
964 if(Client()->RconAuthed())
965 MainView.HSplitBottom(Cut: 90.0f, pTop: &MainView, pBottom: &RconExtension);
966
967 // tab bar
968 TabBar.VSplitLeft(Cut: TabBar.w / 3, pLeft: &Button, pRight: &TabBar);
969 static CButtonContainer s_Button0;
970 if(DoButton_MenuTab(pButtonContainer: &s_Button0, pText: Localize(pStr: "Change settings"), Checked: s_ControlPage == EServerControlTab::SETTINGS, pRect: &Button, Corners: IGraphics::CORNER_NONE))
971 s_ControlPage = EServerControlTab::SETTINGS;
972
973 TabBar.VSplitMid(pLeft: &Button, pRight: &TabBar);
974 static CButtonContainer s_Button1;
975 if(DoButton_MenuTab(pButtonContainer: &s_Button1, pText: Localize(pStr: "Kick player"), Checked: s_ControlPage == EServerControlTab::KICKVOTE, pRect: &Button, Corners: IGraphics::CORNER_NONE))
976 s_ControlPage = EServerControlTab::KICKVOTE;
977
978 static CButtonContainer s_Button2;
979 if(DoButton_MenuTab(pButtonContainer: &s_Button2, pText: Localize(pStr: "Move player to spectators"), Checked: s_ControlPage == EServerControlTab::SPECVOTE, pRect: &TabBar, Corners: IGraphics::CORNER_NONE))
980 s_ControlPage = EServerControlTab::SPECVOTE;
981
982 // render page
983 MainView.HSplitBottom(Cut: ms_ButtonHeight + 5 * 2, pTop: &MainView, pBottom: &Bottom);
984 Bottom.HMargin(Cut: 5.0f, pOtherRect: &Bottom);
985 Bottom.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &Bottom);
986
987 // render quick search
988 CUIRect QuickSearch;
989 Bottom.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Bottom);
990 Bottom.VSplitLeft(Cut: 250.0f, pLeft: &QuickSearch, pRight: &Bottom);
991 if(m_ControlPageOpening)
992 {
993 m_ControlPageOpening = false;
994 Ui()->SetActiveItem(&m_FilterInput);
995 m_FilterInput.SelectAll();
996 }
997 bool Searching = Ui()->DoEditBox_Search(pLineInput: &m_FilterInput, pRect: &QuickSearch, FontSize: 14.0f, HotkeyEnabled: !Ui()->IsPopupOpen() && !GameClient()->m_GameConsole.IsActive());
998
999 // vote menu
1000 bool Call = false;
1001 if(s_ControlPage == EServerControlTab::SETTINGS)
1002 Call = RenderServerControlServer(MainView, UpdateScroll: Searching);
1003 else if(s_ControlPage == EServerControlTab::KICKVOTE)
1004 Call = RenderServerControlKick(MainView, FilterSpectators: false, UpdateScroll: Searching);
1005 else if(s_ControlPage == EServerControlTab::SPECVOTE)
1006 Call = RenderServerControlKick(MainView, FilterSpectators: true, UpdateScroll: Searching);
1007
1008 // call vote
1009 Bottom.VSplitRight(Cut: 10.0f, pLeft: &Bottom, pRight: nullptr);
1010 Bottom.VSplitRight(Cut: 120.0f, pLeft: &Bottom, pRight: &Button);
1011
1012 static CButtonContainer s_CallVoteButton;
1013 if(DoButton_Menu(pButtonContainer: &s_CallVoteButton, pText: Localize(pStr: "Call vote"), Checked: 0, pRect: &Button) || Call)
1014 {
1015 if(s_ControlPage == EServerControlTab::SETTINGS)
1016 {
1017 if(0 <= m_CallvoteSelectedOption && m_CallvoteSelectedOption < GameClient()->m_Voting.NumOptions())
1018 {
1019 GameClient()->m_Voting.CallvoteOption(OptionId: m_CallvoteSelectedOption, pReason: m_CallvoteReasonInput.GetString());
1020 if(g_Config.m_UiCloseWindowAfterChangingSetting)
1021 SetActive(false);
1022 }
1023 }
1024 else if(s_ControlPage == EServerControlTab::KICKVOTE)
1025 {
1026 if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS &&
1027 GameClient()->m_Snap.m_apPlayerInfos[m_CallvoteSelectedPlayer])
1028 {
1029 GameClient()->m_Voting.CallvoteKick(ClientId: m_CallvoteSelectedPlayer, pReason: m_CallvoteReasonInput.GetString());
1030 SetActive(false);
1031 }
1032 }
1033 else if(s_ControlPage == EServerControlTab::SPECVOTE)
1034 {
1035 if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS &&
1036 GameClient()->m_Snap.m_apPlayerInfos[m_CallvoteSelectedPlayer])
1037 {
1038 GameClient()->m_Voting.CallvoteSpectate(ClientId: m_CallvoteSelectedPlayer, pReason: m_CallvoteReasonInput.GetString());
1039 SetActive(false);
1040 }
1041 }
1042 m_CallvoteReasonInput.Clear();
1043 }
1044
1045 // render kick reason
1046 CUIRect Reason;
1047 Bottom.VSplitRight(Cut: 20.0f, pLeft: &Bottom, pRight: nullptr);
1048 Bottom.VSplitRight(Cut: 200.0f, pLeft: &Bottom, pRight: &Reason);
1049 const char *pLabel = Localize(pStr: "Reason:");
1050 Ui()->DoLabel(pRect: &Reason, pText: pLabel, Size: 14.0f, Align: TEXTALIGN_ML);
1051 float w = TextRender()->TextWidth(Size: 14.0f, pText: pLabel, StrLength: -1, LineWidth: -1.0f);
1052 Reason.VSplitLeft(Cut: w + 10.0f, pLeft: nullptr, pRight: &Reason);
1053 if(Input()->KeyPress(Key: KEY_R) && Input()->ModifierIsPressed())
1054 {
1055 Ui()->SetActiveItem(&m_CallvoteReasonInput);
1056 m_CallvoteReasonInput.SelectAll();
1057 }
1058 Ui()->DoEditBox(pLineInput: &m_CallvoteReasonInput, pRect: &Reason, FontSize: 14.0f);
1059
1060 // vote option loading indicator
1061 if(s_ControlPage == EServerControlTab::SETTINGS && GameClient()->m_Voting.IsReceivingOptions())
1062 {
1063 CUIRect Spinner, LoadingLabel;
1064 Bottom.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &Bottom);
1065 Bottom.VSplitLeft(Cut: 16.0f, pLeft: &Spinner, pRight: &Bottom);
1066 Bottom.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Bottom);
1067 Bottom.VSplitRight(Cut: 10.0f, pLeft: &LoadingLabel, pRight: nullptr);
1068 Ui()->RenderProgressSpinner(Center: Spinner.Center(), OuterRadius: 8.0f);
1069 Ui()->DoLabel(pRect: &LoadingLabel, pText: Localize(pStr: "Loading…"), Size: 14.0f, Align: TEXTALIGN_ML);
1070 }
1071
1072 // extended features (only available when authed in rcon)
1073 if(Client()->RconAuthed())
1074 {
1075 // background
1076 RconExtension.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &RconExtension);
1077 RconExtension.HSplitTop(Cut: 20.0f, pTop: &Bottom, pBottom: &RconExtension);
1078 RconExtension.HSplitTop(Cut: 5.0f, pTop: nullptr, pBottom: &RconExtension);
1079
1080 // force vote
1081 Bottom.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Bottom);
1082 Bottom.VSplitLeft(Cut: 120.0f, pLeft: &Button, pRight: &Bottom);
1083
1084 static CButtonContainer s_ForceVoteButton;
1085 if(DoButton_Menu(pButtonContainer: &s_ForceVoteButton, pText: Localize(pStr: "Force vote"), Checked: 0, pRect: &Button))
1086 {
1087 if(s_ControlPage == EServerControlTab::SETTINGS)
1088 {
1089 GameClient()->m_Voting.CallvoteOption(OptionId: m_CallvoteSelectedOption, pReason: m_CallvoteReasonInput.GetString(), ForceVote: true);
1090 }
1091 else if(s_ControlPage == EServerControlTab::KICKVOTE)
1092 {
1093 if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS &&
1094 GameClient()->m_Snap.m_apPlayerInfos[m_CallvoteSelectedPlayer])
1095 {
1096 GameClient()->m_Voting.CallvoteKick(ClientId: m_CallvoteSelectedPlayer, pReason: m_CallvoteReasonInput.GetString(), ForceVote: true);
1097 SetActive(false);
1098 }
1099 }
1100 else if(s_ControlPage == EServerControlTab::SPECVOTE)
1101 {
1102 if(m_CallvoteSelectedPlayer >= 0 && m_CallvoteSelectedPlayer < MAX_CLIENTS &&
1103 GameClient()->m_Snap.m_apPlayerInfos[m_CallvoteSelectedPlayer])
1104 {
1105 GameClient()->m_Voting.CallvoteSpectate(ClientId: m_CallvoteSelectedPlayer, pReason: m_CallvoteReasonInput.GetString(), ForceVote: true);
1106 SetActive(false);
1107 }
1108 }
1109 m_CallvoteReasonInput.Clear();
1110 }
1111
1112 if(s_ControlPage == EServerControlTab::SETTINGS)
1113 {
1114 // remove vote
1115 Bottom.VSplitRight(Cut: 10.0f, pLeft: &Bottom, pRight: nullptr);
1116 Bottom.VSplitRight(Cut: 120.0f, pLeft: nullptr, pRight: &Button);
1117 static CButtonContainer s_RemoveVoteButton;
1118 if(DoButton_Menu(pButtonContainer: &s_RemoveVoteButton, pText: Localize(pStr: "Remove"), Checked: 0, pRect: &Button))
1119 GameClient()->m_Voting.RemovevoteOption(OptionId: m_CallvoteSelectedOption);
1120
1121 // add vote
1122 RconExtension.HSplitTop(Cut: 20.0f, pTop: &Bottom, pBottom: &RconExtension);
1123 Bottom.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Bottom);
1124 Bottom.VSplitLeft(Cut: 250.0f, pLeft: &Button, pRight: &Bottom);
1125 Ui()->DoLabel(pRect: &Button, pText: Localize(pStr: "Vote description:"), Size: 14.0f, Align: TEXTALIGN_ML);
1126
1127 Bottom.VSplitLeft(Cut: 20.0f, pLeft: nullptr, pRight: &Button);
1128 Ui()->DoLabel(pRect: &Button, pText: Localize(pStr: "Vote command:"), Size: 14.0f, Align: TEXTALIGN_ML);
1129
1130 static CLineInputBuffered<VOTE_DESC_LENGTH> s_VoteDescriptionInput;
1131 static CLineInputBuffered<VOTE_CMD_LENGTH> s_VoteCommandInput;
1132 RconExtension.HSplitTop(Cut: 20.0f, pTop: &Bottom, pBottom: &RconExtension);
1133 Bottom.VSplitRight(Cut: 10.0f, pLeft: &Bottom, pRight: nullptr);
1134 Bottom.VSplitRight(Cut: 120.0f, pLeft: &Bottom, pRight: &Button);
1135 static CButtonContainer s_AddVoteButton;
1136 if(DoButton_Menu(pButtonContainer: &s_AddVoteButton, pText: Localize(pStr: "Add"), Checked: 0, pRect: &Button))
1137 if(!s_VoteDescriptionInput.IsEmpty() && !s_VoteCommandInput.IsEmpty())
1138 GameClient()->m_Voting.AddvoteOption(pDescription: s_VoteDescriptionInput.GetString(), pCommand: s_VoteCommandInput.GetString());
1139
1140 Bottom.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &Bottom);
1141 Bottom.VSplitLeft(Cut: 250.0f, pLeft: &Button, pRight: &Bottom);
1142 Ui()->DoEditBox(pLineInput: &s_VoteDescriptionInput, pRect: &Button, FontSize: 14.0f);
1143
1144 Bottom.VMargin(Cut: 20.0f, pOtherRect: &Button);
1145 Ui()->DoEditBox(pLineInput: &s_VoteCommandInput, pRect: &Button, FontSize: 14.0f);
1146 }
1147 }
1148}
1149
1150void CMenus::RenderInGameNetwork(CUIRect MainView)
1151{
1152 MainView.Draw(Color: ms_ColorTabbarActive, Corners: IGraphics::CORNER_B, Rounding: 10.0f);
1153
1154 CUIRect TabBar, Button;
1155 MainView.HSplitTop(Cut: 24.0f, pTop: &TabBar, pBottom: &MainView);
1156
1157 int NewPage = g_Config.m_UiPage;
1158
1159 TextRender()->SetFontPreset(EFontPreset::ICON_FONT);
1160 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);
1161
1162 TabBar.VSplitLeft(Cut: 75.0f, pLeft: &Button, pRight: &TabBar);
1163 static CButtonContainer s_InternetButton;
1164 if(DoButton_MenuTab(pButtonContainer: &s_InternetButton, pText: FontIcon::EARTH_AMERICAS, Checked: g_Config.m_UiPage == PAGE_INTERNET, pRect: &Button, Corners: IGraphics::CORNER_NONE))
1165 {
1166 NewPage = PAGE_INTERNET;
1167 }
1168 Ui()->DoToolTip(pId: &s_InternetButton, pNearRect: &Button, pText: Localize(pStr: "Internet"));
1169
1170 TabBar.VSplitLeft(Cut: 75.0f, pLeft: &Button, pRight: &TabBar);
1171 static CButtonContainer s_LanButton;
1172 if(DoButton_MenuTab(pButtonContainer: &s_LanButton, pText: FontIcon::NETWORK_WIRED, Checked: g_Config.m_UiPage == PAGE_LAN, pRect: &Button, Corners: IGraphics::CORNER_NONE))
1173 {
1174 NewPage = PAGE_LAN;
1175 }
1176 Ui()->DoToolTip(pId: &s_LanButton, pNearRect: &Button, pText: Localize(pStr: "LAN"));
1177
1178 TabBar.VSplitLeft(Cut: 75.0f, pLeft: &Button, pRight: &TabBar);
1179 static CButtonContainer s_FavoritesButton;
1180 if(DoButton_MenuTab(pButtonContainer: &s_FavoritesButton, pText: FontIcon::STAR, Checked: g_Config.m_UiPage == PAGE_FAVORITES, pRect: &Button, Corners: IGraphics::CORNER_NONE))
1181 {
1182 NewPage = PAGE_FAVORITES;
1183 }
1184 Ui()->DoToolTip(pId: &s_FavoritesButton, pNearRect: &Button, pText: Localize(pStr: "Favorites"));
1185
1186 const std::vector<const CCommunity *> vpFavoriteCommunities = ServerBrowser()->FavoriteCommunities();
1187 const int MaxPage = PAGE_FAVORITES + vpFavoriteCommunities.size();
1188 if(
1189 !Ui()->IsPopupOpen() &&
1190 CLineInput::GetActiveInput() == nullptr &&
1191 (g_Config.m_UiPage >= PAGE_INTERNET && g_Config.m_UiPage <= MaxPage) &&
1192 (m_MenuPage >= PAGE_INTERNET && m_MenuPage <= PAGE_FAVORITE_COMMUNITY_5))
1193 {
1194 if(Input()->KeyPress(Key: KEY_RIGHT))
1195 {
1196 NewPage = g_Config.m_UiPage + 1;
1197 if(NewPage > MaxPage)
1198 NewPage = PAGE_INTERNET;
1199 }
1200 if(Input()->KeyPress(Key: KEY_LEFT))
1201 {
1202 NewPage = g_Config.m_UiPage - 1;
1203 if(NewPage < PAGE_INTERNET)
1204 NewPage = MaxPage;
1205 }
1206 }
1207
1208 size_t FavoriteCommunityIndex = 0;
1209 static CButtonContainer s_aFavoriteCommunityButtons[5];
1210 static_assert(std::size(s_aFavoriteCommunityButtons) == (size_t)PAGE_FAVORITE_COMMUNITY_5 - PAGE_FAVORITE_COMMUNITY_1 + 1);
1211 for(const CCommunity *pCommunity : vpFavoriteCommunities)
1212 {
1213 TabBar.VSplitLeft(Cut: 75.0f, pLeft: &Button, pRight: &TabBar);
1214 const int Page = PAGE_FAVORITE_COMMUNITY_1 + FavoriteCommunityIndex;
1215 if(DoButton_MenuTab(pButtonContainer: &s_aFavoriteCommunityButtons[FavoriteCommunityIndex], pText: FontIcon::ELLIPSIS, Checked: g_Config.m_UiPage == Page, pRect: &Button, Corners: IGraphics::CORNER_NONE, pAnimator: nullptr, pDefaultColor: nullptr, pActiveColor: nullptr, pHoverColor: nullptr, EdgeRounding: 10.0f, pCommunityIcon: m_CommunityIcons.Find(pCommunityId: pCommunity->Id())))
1216 {
1217 NewPage = Page;
1218 }
1219 Ui()->DoToolTip(pId: &s_aFavoriteCommunityButtons[FavoriteCommunityIndex], pNearRect: &Button, pText: pCommunity->Name());
1220
1221 ++FavoriteCommunityIndex;
1222 if(FavoriteCommunityIndex >= std::size(s_aFavoriteCommunityButtons))
1223 break;
1224 }
1225
1226 TextRender()->SetRenderFlags(0);
1227 TextRender()->SetFontPreset(EFontPreset::DEFAULT_FONT);
1228
1229 if(NewPage != g_Config.m_UiPage)
1230 {
1231 SetMenuPage(NewPage);
1232 }
1233
1234 RenderServerbrowser(MainView);
1235}
1236
1237// ghost stuff
1238int CMenus::GhostlistFetchCallback(const CFsFileInfo *pInfo, int IsDir, int StorageType, void *pUser)
1239{
1240 CMenus *pSelf = (CMenus *)pUser;
1241 const char *pMap = pSelf->GameClient()->Map()->BaseName();
1242 if(IsDir || !str_endswith(str: pInfo->m_pName, suffix: ".gho") || !str_startswith(str: pInfo->m_pName, prefix: pMap))
1243 return 0;
1244
1245 char aFilename[IO_MAX_PATH_LENGTH];
1246 str_format(buffer: aFilename, buffer_size: sizeof(aFilename), format: "%s/%s", pSelf->GameClient()->m_Ghost.GetGhostDir(), pInfo->m_pName);
1247
1248 CGhostInfo Info;
1249 if(!pSelf->GameClient()->m_Ghost.GhostLoader()->GetGhostInfo(pFilename: aFilename, pInfo: &Info, pMap, MapSha256: pSelf->GameClient()->Map()->Sha256(), MapCrc: pSelf->GameClient()->Map()->Crc()))
1250 return 0;
1251
1252 CGhostItem Item;
1253 str_copy(dst&: Item.m_aFilename, src: aFilename);
1254 str_copy(dst&: Item.m_aPlayer, src: Info.m_aOwner);
1255 Item.m_Date = pInfo->m_TimeModified;
1256 Item.m_Time = Info.m_Time;
1257 if(Item.m_Time > 0)
1258 pSelf->m_vGhosts.push_back(x: Item);
1259
1260 if(time_get_nanoseconds() - pSelf->m_GhostPopulateStartTime > 500ms)
1261 {
1262 pSelf->RenderLoading(pCaption: Localize(pStr: "Loading ghost files"), pContent: "", IncreaseCounter: 0);
1263 }
1264
1265 return 0;
1266}
1267
1268void CMenus::GhostlistPopulate()
1269{
1270 m_vGhosts.clear();
1271 m_GhostPopulateStartTime = time_get_nanoseconds();
1272 Storage()->ListDirectoryInfo(Type: IStorage::TYPE_ALL, pPath: GameClient()->m_Ghost.GetGhostDir(), pfnCallback: GhostlistFetchCallback, pUser: this);
1273 SortGhostlist();
1274
1275 CGhostItem *pOwnGhost = nullptr;
1276 for(auto &Ghost : m_vGhosts)
1277 {
1278 Ghost.m_Failed = false;
1279 if(str_comp(a: Ghost.m_aPlayer, b: Client()->PlayerName()) == 0 && (!pOwnGhost || Ghost.m_Time < pOwnGhost->m_Time))
1280 pOwnGhost = &Ghost;
1281 }
1282
1283 if(pOwnGhost)
1284 {
1285 pOwnGhost->m_Own = true;
1286 pOwnGhost->m_Slot = GameClient()->m_Ghost.Load(pFilename: pOwnGhost->m_aFilename);
1287 }
1288}
1289
1290CMenus::CGhostItem *CMenus::GetOwnGhost()
1291{
1292 for(auto &Ghost : m_vGhosts)
1293 if(Ghost.m_Own)
1294 return &Ghost;
1295 return nullptr;
1296}
1297
1298void CMenus::UpdateOwnGhost(CGhostItem Item)
1299{
1300 int Own = -1;
1301 for(size_t i = 0; i < m_vGhosts.size(); i++)
1302 if(m_vGhosts[i].m_Own)
1303 Own = i;
1304
1305 if(Own == -1)
1306 {
1307 Item.m_Own = true;
1308 }
1309 else if(g_Config.m_ClRaceGhostSaveBest && (Item.HasFile() || !m_vGhosts[Own].HasFile()))
1310 {
1311 Item.m_Own = true;
1312 DeleteGhostItem(Index: Own);
1313 }
1314 else if(m_vGhosts[Own].m_Time > Item.m_Time)
1315 {
1316 Item.m_Own = true;
1317 m_vGhosts[Own].m_Own = false;
1318 m_vGhosts[Own].m_Slot = -1;
1319 }
1320 else
1321 {
1322 Item.m_Own = false;
1323 Item.m_Slot = -1;
1324 }
1325
1326 Item.m_Date = std::time(timer: nullptr);
1327 Item.m_Failed = false;
1328 m_vGhosts.push_back(x: Item);
1329 SortGhostlist();
1330}
1331
1332void CMenus::DeleteGhostItem(int Index)
1333{
1334 if(m_vGhosts[Index].HasFile())
1335 Storage()->RemoveFile(pFilename: m_vGhosts[Index].m_aFilename, Type: IStorage::TYPE_SAVE);
1336 m_vGhosts.erase(position: m_vGhosts.begin() + Index);
1337}
1338
1339void CMenus::SortGhostlist()
1340{
1341 if(g_Config.m_GhSort == GHOST_SORT_NAME)
1342 std::stable_sort(first: m_vGhosts.begin(), last: m_vGhosts.end(), comp: [](const CGhostItem &Left, const CGhostItem &Right) {
1343 return g_Config.m_GhSortOrder ? (str_comp(a: Left.m_aPlayer, b: Right.m_aPlayer) > 0) : (str_comp(a: Left.m_aPlayer, b: Right.m_aPlayer) < 0);
1344 });
1345 else if(g_Config.m_GhSort == GHOST_SORT_TIME)
1346 std::stable_sort(first: m_vGhosts.begin(), last: m_vGhosts.end(), comp: [](const CGhostItem &Left, const CGhostItem &Right) {
1347 return g_Config.m_GhSortOrder ? (Left.m_Time > Right.m_Time) : (Left.m_Time < Right.m_Time);
1348 });
1349 else if(g_Config.m_GhSort == GHOST_SORT_DATE)
1350 std::stable_sort(first: m_vGhosts.begin(), last: m_vGhosts.end(), comp: [](const CGhostItem &Left, const CGhostItem &Right) {
1351 return g_Config.m_GhSortOrder ? (Left.m_Date > Right.m_Date) : (Left.m_Date < Right.m_Date);
1352 });
1353}
1354
1355void CMenus::RenderGhost(CUIRect MainView)
1356{
1357 // render background
1358 MainView.Draw(Color: ms_ColorTabbarActive, Corners: IGraphics::CORNER_B, Rounding: 10.0f);
1359
1360 MainView.HSplitTop(Cut: 10.0f, pTop: nullptr, pBottom: &MainView);
1361 MainView.HSplitBottom(Cut: 5.0f, pTop: &MainView, pBottom: nullptr);
1362 MainView.VSplitLeft(Cut: 5.0f, pLeft: nullptr, pRight: &MainView);
1363 MainView.VSplitRight(Cut: 5.0f, pLeft: &MainView, pRight: nullptr);
1364
1365 CUIRect Headers, Status;
1366 CUIRect View = MainView;
1367
1368 View.HSplitTop(Cut: 17.0f, pTop: &Headers, pBottom: &View);
1369 View.HSplitBottom(Cut: 28.0f, pTop: &View, pBottom: &Status);
1370
1371 // split of the scrollbar
1372 Headers.Draw(Color: ColorRGBA(1, 1, 1, 0.25f), Corners: IGraphics::CORNER_T, Rounding: 5.0f);
1373 Headers.VSplitRight(Cut: 20.0f, pLeft: &Headers, pRight: nullptr);
1374
1375 class CColumn
1376 {
1377 public:
1378 const char *m_pCaption;
1379 int m_Id;
1380 int m_Sort;
1381 float m_Width;
1382 CUIRect m_Rect;
1383 };
1384
1385 enum
1386 {
1387 COL_ACTIVE = 0,
1388 COL_NAME,
1389 COL_TIME,
1390 COL_DATE,
1391 };
1392
1393 static CColumn s_aCols[] = {
1394 {.m_pCaption: "", .m_Id: -1, .m_Sort: GHOST_SORT_NONE, .m_Width: 2.0f, .m_Rect: {.x: 0}},
1395 {.m_pCaption: "", .m_Id: COL_ACTIVE, .m_Sort: GHOST_SORT_NONE, .m_Width: 30.0f, .m_Rect: {.x: 0}},
1396 {.m_pCaption: Localizable(pStr: "Name"), .m_Id: COL_NAME, .m_Sort: GHOST_SORT_NAME, .m_Width: 200.0f, .m_Rect: {.x: 0}},
1397 {.m_pCaption: Localizable(pStr: "Time"), .m_Id: COL_TIME, .m_Sort: GHOST_SORT_TIME, .m_Width: 90.0f, .m_Rect: {.x: 0}},
1398 {.m_pCaption: Localizable(pStr: "Date"), .m_Id: COL_DATE, .m_Sort: GHOST_SORT_DATE, .m_Width: 150.0f, .m_Rect: {.x: 0}},
1399 };
1400
1401 int NumCols = std::size(s_aCols);
1402
1403 // do layout
1404 for(int i = 0; i < NumCols; i++)
1405 {
1406 Headers.VSplitLeft(Cut: s_aCols[i].m_Width, pLeft: &s_aCols[i].m_Rect, pRight: &Headers);
1407
1408 if(i + 1 < NumCols)
1409 Headers.VSplitLeft(Cut: 2, pLeft: nullptr, pRight: &Headers);
1410 }
1411
1412 // do headers
1413 for(const auto &Col : s_aCols)
1414 {
1415 if(DoButton_GridHeader(pId: &Col.m_Id, pText: Localize(pStr: Col.m_pCaption), Checked: g_Config.m_GhSort == Col.m_Sort, pRect: &Col.m_Rect))
1416 {
1417 if(Col.m_Sort != GHOST_SORT_NONE)
1418 {
1419 if(g_Config.m_GhSort == Col.m_Sort)
1420 g_Config.m_GhSortOrder ^= 1;
1421 else
1422 g_Config.m_GhSortOrder = 0;
1423 g_Config.m_GhSort = Col.m_Sort;
1424
1425 SortGhostlist();
1426 }
1427 }
1428 }
1429
1430 View.Draw(Color: ColorRGBA(0, 0, 0, 0.15f), Corners: 0, Rounding: 0);
1431
1432 int NumGhosts;
1433 int NumFailed;
1434 int NumActivated;
1435 const auto &&UpdateCounts = [&]() {
1436 NumGhosts = m_vGhosts.size();
1437 NumFailed = 0;
1438 NumActivated = 0;
1439 for(const CGhostItem &Ghost : m_vGhosts)
1440 {
1441 if(Ghost.m_Failed || !Ghost.HasFile())
1442 {
1443 NumFailed++;
1444 }
1445 else if(Ghost.Active())
1446 {
1447 NumActivated++;
1448 }
1449 }
1450 };
1451 UpdateCounts();
1452
1453 static int s_SelectedIndex = 0;
1454 static CListBox s_ListBox;
1455 s_ListBox.DoStart(RowHeight: 17.0f, NumItems: NumGhosts, ItemsPerRow: 1, RowsPerScroll: 3, SelectedIndex: s_SelectedIndex, pRect: &View, Background: false);
1456
1457 for(int i = 0; i < NumGhosts; i++)
1458 {
1459 const CGhostItem *pGhost = &m_vGhosts[i];
1460 const CListboxItem Item = s_ListBox.DoNextItem(pId: pGhost);
1461
1462 if(!Item.m_Visible)
1463 continue;
1464
1465 ColorRGBA Color = ColorRGBA(1.0f, 1.0f, 1.0f);
1466 if(pGhost->m_Own)
1467 Color = color_cast<ColorRGBA>(hsl: ColorHSLA(0.33f, 1.0f, 0.75f));
1468
1469 if(pGhost->m_Failed)
1470 Color = ColorRGBA(0.6f, 0.6f, 0.6f, 1.0f);
1471
1472 TextRender()->TextColor(Color: Color.WithAlpha(alpha: pGhost->HasFile() ? 1.0f : 0.5f));
1473
1474 for(int c = 0; c < NumCols; c++)
1475 {
1476 CUIRect Button;
1477 Button.x = s_aCols[c].m_Rect.x;
1478 Button.y = Item.m_Rect.y;
1479 Button.h = Item.m_Rect.h;
1480 Button.w = s_aCols[c].m_Rect.w;
1481
1482 int Id = s_aCols[c].m_Id;
1483
1484 if(Id == COL_ACTIVE)
1485 {
1486 if(pGhost->Active())
1487 {
1488 Graphics()->WrapClamp();
1489 Graphics()->TextureSet(Texture: GameClient()->m_EmoticonsSkin.m_aSpriteEmoticons[(SPRITE_OOP + 7) - SPRITE_OOP]);
1490 Graphics()->QuadsBegin();
1491 IGraphics::CQuadItem QuadItem(Button.x + Button.w / 2, Button.y + Button.h / 2, 20.0f, 20.0f);
1492 Graphics()->QuadsDraw(pArray: &QuadItem, Num: 1);
1493
1494 Graphics()->QuadsEnd();
1495 Graphics()->WrapNormal();
1496 }
1497 }
1498 else if(Id == COL_NAME)
1499 {
1500 Ui()->DoLabel(pRect: &Button, pText: pGhost->m_aPlayer, Size: 12.0f, Align: TEXTALIGN_ML);
1501 }
1502 else if(Id == COL_TIME)
1503 {
1504 char aBuf[64];
1505 str_time(centisecs: pGhost->m_Time / 10, format: ETimeFormat::HOURS_CENTISECS, buffer: aBuf, buffer_size: sizeof(aBuf));
1506 Ui()->DoLabel(pRect: &Button, pText: aBuf, Size: 12.0f, Align: TEXTALIGN_ML);
1507 }
1508 else if(Id == COL_DATE)
1509 {
1510 char aBuf[64];
1511 str_timestamp_ex(time: pGhost->m_Date, buffer: aBuf, buffer_size: sizeof(aBuf), format: TimestampFormat::SPACE);
1512 Ui()->DoLabel(pRect: &Button, pText: aBuf, Size: 12.0f, Align: TEXTALIGN_ML);
1513 }
1514 }
1515
1516 TextRender()->TextColor(r: 1.0f, g: 1.0f, b: 1.0f, a: 1.0f);
1517 }
1518
1519 s_SelectedIndex = s_ListBox.DoEnd();
1520
1521 Status.Draw(Color: ColorRGBA(1, 1, 1, 0.25f), Corners: IGraphics::CORNER_B, Rounding: 5.0f);
1522 Status.Margin(Cut: 5.0f, pOtherRect: &Status);
1523
1524 CUIRect Button;
1525 Status.VSplitLeft(Cut: 25.0f, pLeft: &Button, pRight: &Status);
1526
1527 static CButtonContainer s_ReloadButton;
1528 static CButtonContainer s_DirectoryButton;
1529 static CButtonContainer s_ActivateAll;
1530
1531 if(Ui()->DoButton_FontIcon(pButtonContainer: &s_ReloadButton, pText: FontIcon::ARROW_ROTATE_RIGHT, Checked: 0, pRect: &Button, Flags: BUTTONFLAG_LEFT) || Input()->KeyPress(Key: KEY_F5) || (Input()->KeyPress(Key: KEY_R) && Input()->ModifierIsPressed()))
1532 {
1533 GameClient()->m_Ghost.UnloadAll();
1534 GhostlistPopulate();
1535 UpdateCounts();
1536 }
1537
1538 Status.VSplitLeft(Cut: 5.0f, pLeft: &Button, pRight: &Status);
1539 Status.VSplitLeft(Cut: 175.0f, pLeft: &Button, pRight: &Status);
1540 if(DoButton_Menu(pButtonContainer: &s_DirectoryButton, pText: Localize(pStr: "Ghosts directory"), Checked: 0, pRect: &Button))
1541 {
1542 char aBuf[IO_MAX_PATH_LENGTH];
1543 Storage()->GetCompletePath(Type: IStorage::TYPE_SAVE, pDir: "ghosts", pBuffer: aBuf, BufferSize: sizeof(aBuf));
1544 Storage()->CreateFolder(pFoldername: "ghosts", Type: IStorage::TYPE_SAVE);
1545 Client()->ViewFile(pFilename: aBuf);
1546 }
1547
1548 Status.VSplitLeft(Cut: 5.0f, pLeft: &Button, pRight: &Status);
1549 if(NumGhosts - NumFailed > 0)
1550 {
1551 Status.VSplitLeft(Cut: 175.0f, pLeft: &Button, pRight: &Status);
1552 bool ActivateAll = ((NumGhosts - NumFailed) != NumActivated) && GameClient()->m_Ghost.FreeSlots();
1553
1554 const char *pActionText = ActivateAll ? Localize(pStr: "Activate all") : Localize(pStr: "Deactivate all");
1555 if(DoButton_Menu(pButtonContainer: &s_ActivateAll, pText: pActionText, Checked: 0, pRect: &Button))
1556 {
1557 for(int i = 0; i < NumGhosts; i++)
1558 {
1559 CGhostItem *pGhost = &m_vGhosts[i];
1560 if(pGhost->m_Failed || !pGhost->HasFile())
1561 continue;
1562
1563 if(ActivateAll)
1564 {
1565 if(!pGhost->Active())
1566 {
1567 if(!GameClient()->m_Ghost.FreeSlots())
1568 break;
1569
1570 pGhost->m_Slot = GameClient()->m_Ghost.Load(pFilename: pGhost->m_aFilename);
1571 if(pGhost->m_Slot == -1)
1572 pGhost->m_Failed = true;
1573 }
1574 }
1575 else
1576 {
1577 if(pGhost->Active())
1578 {
1579 GameClient()->m_Ghost.Unload(Slot: pGhost->m_Slot);
1580 pGhost->m_Slot = -1;
1581 }
1582 }
1583 }
1584 }
1585 }
1586
1587 if(s_SelectedIndex == -1 || s_SelectedIndex >= (int)m_vGhosts.size())
1588 return;
1589
1590 CGhostItem *pGhost = &m_vGhosts[s_SelectedIndex];
1591
1592 CGhostItem *pOwnGhost = GetOwnGhost();
1593 int ReservedSlots = !pGhost->m_Own && !(pOwnGhost && pOwnGhost->Active());
1594 if(!pGhost->m_Failed && pGhost->HasFile() && (pGhost->Active() || GameClient()->m_Ghost.FreeSlots() > ReservedSlots))
1595 {
1596 Status.VSplitRight(Cut: 120.0f, pLeft: &Status, pRight: &Button);
1597
1598 static CButtonContainer s_GhostButton;
1599 const char *pText = pGhost->Active() ? Localize(pStr: "Deactivate") : Localize(pStr: "Activate");
1600 if(DoButton_Menu(pButtonContainer: &s_GhostButton, pText, Checked: 0, pRect: &Button) || s_ListBox.WasItemActivated())
1601 {
1602 if(pGhost->Active())
1603 {
1604 GameClient()->m_Ghost.Unload(Slot: pGhost->m_Slot);
1605 pGhost->m_Slot = -1;
1606 }
1607 else
1608 {
1609 pGhost->m_Slot = GameClient()->m_Ghost.Load(pFilename: pGhost->m_aFilename);
1610 if(pGhost->m_Slot == -1)
1611 pGhost->m_Failed = true;
1612 }
1613 }
1614 Status.VSplitRight(Cut: 5.0f, pLeft: &Status, pRight: nullptr);
1615 }
1616
1617 Status.VSplitRight(Cut: 120.0f, pLeft: &Status, pRight: &Button);
1618
1619 static CButtonContainer s_DeleteButton;
1620 if(DoButton_Menu(pButtonContainer: &s_DeleteButton, pText: Localize(pStr: "Delete"), Checked: 0, pRect: &Button))
1621 {
1622 if(pGhost->Active())
1623 GameClient()->m_Ghost.Unload(Slot: pGhost->m_Slot);
1624 DeleteGhostItem(Index: s_SelectedIndex);
1625 s_SelectedIndex = std::min(a: s_SelectedIndex, b: (int)m_vGhosts.size() - 1);
1626 if(s_SelectedIndex == -1)
1627 {
1628 return;
1629 }
1630 pGhost = &m_vGhosts[s_SelectedIndex];
1631 }
1632
1633 Status.VSplitRight(Cut: 5.0f, pLeft: &Status, pRight: nullptr);
1634
1635 bool Recording = GameClient()->m_Ghost.GhostRecorder()->IsRecording();
1636 if(!pGhost->HasFile() && !Recording && pGhost->Active())
1637 {
1638 static CButtonContainer s_SaveButton;
1639 Status.VSplitRight(Cut: 120.0f, pLeft: &Status, pRight: &Button);
1640 if(DoButton_Menu(pButtonContainer: &s_SaveButton, pText: Localize(pStr: "Save"), Checked: 0, pRect: &Button))
1641 GameClient()->m_Ghost.SaveGhost(pItem: pGhost);
1642 }
1643}
1644
1645void CMenus::RenderIngameHint()
1646{
1647 // With touch controls enabled there is a Close button in the menu and usually no Escape key available.
1648 if(g_Config.m_ClTouchControls)
1649 return;
1650
1651 float Width = 300 * Graphics()->ScreenAspect();
1652 Graphics()->MapScreenToSize(Width, Height: 300);
1653 TextRender()->TextColor(r: 1, g: 1, b: 1, a: 1);
1654 TextRender()->Text(x: 5, y: 280, Size: 5, pText: Localize(pStr: "Menu opened. Press Esc key again to close menu."), LineWidth: -1.0f);
1655 Ui()->MapScreen();
1656}
1657