DayZ 1.24
Loading...
Searching...
No Matches
ServerBrowserMenuNew.c
Go to the documentation of this file.
1const int MAX_FAVORITES = 25;
2
3#ifdef PLATFORM_CONSOLE
4 const int SERVER_BROWSER_PAGE_SIZE = 22;
5#else
7#endif
8
10{
11 protected Widget m_Play;
12 protected Widget m_Back;
13 protected Widget m_CustomizeCharacter;
14 protected TextWidget m_PlayerName;
15
16 protected TabberUI m_Tabber;
21
22 protected TabType m_IsRefreshing = TabType.NONE;
24 protected ServerBrowserEntry m_SelectedServer;
25
26 override Widget Init()
27 {
28#ifdef PLATFORM_CONSOLE
29 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/server_browser/xbox/server_browser.layout");
30 m_FavoritesTab = new ServerBrowserFavoritesTabConsolePages(layoutRoot.FindAnyWidget("Tab_0"), this, TabType.FAVORITE);
31 m_OfficialTab = new ServerBrowserTabConsolePages(layoutRoot.FindAnyWidget("Tab_1"), this, TabType.OFFICIAL);
32 m_CommunityTab = new ServerBrowserTabConsolePages(layoutRoot.FindAnyWidget("Tab_2"), this, TabType.COMMUNITY);
33#else
34 layoutRoot = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/server_browser/pc/server_browser.layout");
35 m_FavoritesTab = new ServerBrowserFavoritesTabPc(layoutRoot.FindAnyWidget("Tab_0"), this, TabType.FAVORITE);
36 m_OfficialTab = new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_1"), this, TabType.OFFICIAL);
37 m_CommunityTab = new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_2"), this, TabType.COMMUNITY);
38 m_LANTab = new ServerBrowserTabPc(layoutRoot.FindAnyWidget("Tab_3"), this, TabType.LAN);
39#endif
40
41 layoutRoot.FindAnyWidget("Tabber").GetScript(m_Tabber);
42
43 m_Play = layoutRoot.FindAnyWidget("play");
44 m_Back = layoutRoot.FindAnyWidget("back_button");
45 m_CustomizeCharacter = layoutRoot.FindAnyWidget("customize_character");
46 m_PlayerName = TextWidget.Cast(layoutRoot.FindAnyWidget("character_name_text"));
47 m_Favorites = new TStringArray;
48
49#ifndef PLATFORM_CONSOLE
50 layoutRoot.FindAnyWidget("customize_character").Show(false);
51 layoutRoot.FindAnyWidget("character").Show(false);
52#endif
53
54 Refresh();
55
56 string version;
57 GetGame().GetVersion(version);
58
59#ifdef PLATFORM_CONSOLE
60 version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
61 if (GetGame().GetInput().IsEnabledMouseAndKeyboard())
62 {
63 layoutRoot.FindAnyWidget("play_panel_root").Show(true);
64 layoutRoot.FindAnyWidget("MouseAndKeyboardWarning").Show(true);
65 layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
66 }
67#else
68 version = "#main_menu_version" + " " + version;
69#endif
70
71 OnlineServices.m_ServersAsyncInvoker.Insert(OnLoadServersAsync);
73 LoadFavoriteServers();
74
75 m_Tabber.m_OnTabSwitch.Insert(OnTabSwitch);
76
77 m_FavoritesTab.RefreshList();
78
79#ifdef PLATFORM_CONSOLE
81 //Sort init
82 TextWidget sort_text = TextWidget.Cast(layoutRoot.FindAnyWidget("SortText"));
83 sort_text.SetText("#str_serverbrowserroot_toolbar_bg_consoletoolbar_sort_sorttext0");
84#endif
85
87
88 GetGame().GetMission().GetOnInputPresetChanged().Insert(OnInputPresetChanged);
89 GetGame().GetMission().GetOnInputDeviceChanged().Insert(OnInputDeviceChanged);
90 OnInputDeviceChanged(GetGame().GetInput().GetCurrentInputDevice());
91
92 return layoutRoot;
93 }
94
96 {
97#ifdef PLATFORM_CONSOLE
98 SaveFavoriteServersConsoles();
99#endif
100
101 OnlineServices.m_ServersAsyncInvoker.Remove(OnLoadServersAsync);
103 m_Tabber.m_OnTabSwitch.Remove(OnTabSwitch);
105 }
106
108 {
109 return m_Favorites;
110 }
111
112 protected void OnInputPresetChanged()
113 {
114#ifdef PLATFORM_CONSOLE
116#endif
117 }
118
120 {
121 switch (pInputDeviceType)
122 {
123 case EInputDeviceType.CONTROLLER:
124#ifdef PLATFORM_CONSOLE
126 layoutRoot.FindAnyWidget("toolbar_bg").Show(true);
127 layoutRoot.FindAnyWidget("ConsoleControls").Show(true);
128#endif
129 break;
130
131 default:
132#ifdef PLATFORM_CONSOLE
133 if (GetGame().GetInput().IsEnabledMouseAndKeyboardEvenOnServer())
134 {
135 layoutRoot.FindAnyWidget("toolbar_bg").Show(false);
136 layoutRoot.FindAnyWidget("ConsoleControls").Show(false);
137 }
138#endif
139 break;
140 }
141 }
142
143 override bool OnClick(Widget w, int x, int y, int button)
144 {
145 if (button == MouseState.LEFT)
146 {
147 if (w == m_Play)
148 {
149 Play();
150 return true;
151 }
152 else if (w == m_Back)
153 {
154 Back();
155 return true;
156 }
157 else if (w == m_CustomizeCharacter)
158 {
159 CustomizeCharacter();
160 return true;
161 }
162 }
163 return false;
164 }
165
166 override bool OnMouseEnter(Widget w, int x, int y)
167 {
168 if (IsFocusable(w))
169 {
171 return true;
172 }
173 return false;
174 }
175
176 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
177 {
178 if (IsFocusable(w))
179 {
180 ColorNormal(w);
181 return true;
182 }
183 return false;
184 }
185
187 {
188 m_IsRefreshing = refreshing;
189
190 OnlineServices.m_ServersAsyncInvoker.Remove(OnLoadServersAsync);
191 OnlineServices.m_ServersAsyncInvoker.Insert(OnLoadServersAsync, EScriptInvokerInsertFlags.NONE);
192 }
193
195 {
196 return m_IsRefreshing;
197 }
198
200 {
201 foreach (string id : m_Favorites)
202 {
204 id.Split(":", output);
205 if (output.Count() == 2)
206 {
207 string ip = output[0];
208 int port = output[1].ToInt();
209 input.AddFavourite(ip, port);
210 }
211 }
212 }
213
215 {
216 int index = -1;
217 if (m_Favorites)
218 index = m_Favorites.Find(server_id);
219 return (index >= 0);
220 }
221
222 // Returns whether server was favorited or not
224 {
225 if (favorite && m_Favorites.Count() >= MAX_FAVORITES)
226 {
227 g_Game.GetUIManager().ShowDialog("#layout_notification_info_warning", "#STR_MaxFavouriteReached", 0, DBT_OK, DBB_YES, DMT_EXCLAMATION, this);
228 return false;
229 }
230
231 AddFavorite(ipAddress, port, favorite);
232 SaveFavoriteServersConsoles();
233
234 return favorite;
235 }
236
237 void AddFavorite(string ipAddress, int port, bool favorite)
238 {
239 string serverId = ipAddress + ":" + port;
240 bool isFavorited = IsFavorited(serverId);
241
242 if (favorite && !isFavorited)
243 m_Favorites.Insert(serverId);
244 else if (isFavorited)
245 {
246 m_Favorites.RemoveItem(serverId);
247 m_OfficialTab.Unfavorite(serverId);
248 m_CommunityTab.Unfavorite(serverId);
249 m_FavoritesTab.Unfavorite(serverId);
250#ifndef PLATFORM_CONSOLE
251 m_LANTab.Unfavorite(serverId);
252#endif
253 }
254 }
255
256 void Back()
257 {
258 GetGame().GetUIManager().Back();
259 }
260
261 void ShowYButton(bool show)
262 {
263 RichTextWidget yIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ResetIcon"));
264 TextWidget yText = TextWidget.Cast(layoutRoot.FindAnyWidget("ResetText"));
265
266 if (yIcon)
267 yIcon.Show(show);
268
269 if (yText)
270 yText.Show(show);
271 }
272
273 void ShowAButton(bool show)
274 {
275 RichTextWidget aIcon = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ConnectIcon"));
276 TextWidget aText = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
277
278 if (aIcon)
279 aIcon.Show(show);
280
281 if (aText)
282 aText.Show(show);
283
284 }
285
287 {
288#ifdef PLATFORM_CONSOLE
289 TextWidget con_text = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
290 TextWidget ref_text = TextWidget.Cast(layoutRoot.FindAnyWidget("RefreshText"));
291 TextWidget res_text = TextWidget.Cast(layoutRoot.FindAnyWidget("ResetText"));
292
293 if (focus)
294 {
295 con_text.SetText("#dialog_change");
296 ref_text.SetText("#server_browser_menu_refresh");
297 res_text.SetText("#server_browser_menu_reset_filters");
298
299 con_text.Update();
300 ref_text.Update();
301 res_text.Update();
302 }
303#endif
304 }
305
307 {
309 }
310
312 {
313#ifdef PLATFORM_CONSOLE
314 TextWidget con_text = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
315 TextWidget ref_text = TextWidget.Cast(layoutRoot.FindAnyWidget("RefreshText"));
316 TextWidget res_text = TextWidget.Cast(layoutRoot.FindAnyWidget("ResetText"));
317
318 if (focus)
319 {
320 con_text.SetText("#server_browser_menu_connect");
321
322 float x, y;
323 res_text.GetSize(x, y);
324 if (favorite)
325 res_text.SetText("#server_browser_menu_unfavorite");
326 else
327 res_text.SetText("#server_browser_menu_favorite");
328 con_text.Update();
329 res_text.Update();
330 }
331#endif
332 }
333
334 override bool OnFocus(Widget w, int x, int y)
335 {
336 if (IsFocusable(w))
337 {
339 return true;
340 }
341 return false;
342 }
343
344 override bool OnFocusLost(Widget w, int x, int y)
345 {
346 if (IsFocusable(w))
347 {
348 ColorNormal(w);
349 return true;
350 }
351 return false;
352 }
353
354 override void Refresh()
355 {
356 string name;
357
358#ifdef PLATFORM_CONSOLE
359 if (GetGame().GetUserManager() && GetGame().GetUserManager().GetSelectedUser())
360 {
361 name = GetGame().GetUserManager().GetSelectedUser().GetName();
362 if (name.LengthUtf8() > 18)
363 {
364 name = name.SubstringUtf8(0, 18);
365 name += "...";
366 }
367 }
368#else
369 g_Game.GetPlayerNameShort(14, name);
370#endif
371
372 if (m_PlayerName)
373 m_PlayerName.SetText(name);
374
375 string version;
376 GetGame().GetVersion(version);
377#ifdef PLATFORM_CONSOLE
378 version = "#main_menu_version" + " " + version + " (" + g_Game.GetDatabaseID() + ")";
379#else
380 version = "#main_menu_version" + " " + version;
381#endif
382 }
383
384 override void Update(float timeslice)
385 {
386 if (!GetGame().GetUIManager().IsDialogVisible() && !GetDayZGame().IsConnecting())
387 {
388 if (GetUApi().GetInputByID(UAUITabLeft).LocalPress())
389 m_Tabber.PreviousTab();
390
391 if (GetUApi().GetInputByID(UAUITabRight).LocalPress())
392 m_Tabber.NextTab();
393
394 if (GetUApi().GetInputByID(UAUINextDown).LocalPress())
395 GetSelectedTab().PressSholderLeft();
396
397 if (GetUApi().GetInputByID(UAUINextUp).LocalPress())
398 GetSelectedTab().PressSholderRight();
399
400 if (GetUApi().GetInputByID(UAUISelect).LocalPress())
401 GetSelectedTab().PressA();
402
403 if (GetUApi().GetInputByID(UAUICtrlX).LocalPress())
404 GetSelectedTab().PressX();
405
406 if (GetUApi().GetInputByID(UAUICtrlY).LocalPress())
407 GetSelectedTab().PressY();
408
409 if (GetUApi().GetInputByID(UAUILeft).LocalPress())
410 GetSelectedTab().Left();
411
412 // LEFT HOLD
413 if (GetUApi().GetInputByID(UAUILeft).LocalHold())
414 GetSelectedTab().LeftHold();
415
416 // LEFT RELEASE
417 if (GetUApi().GetInputByID(UAUILeft).LocalRelease())
418 GetSelectedTab().LeftRelease();
419
420 if (GetUApi().GetInputByID(UAUIRight).LocalPress())
421 GetSelectedTab().Right();
422
423 // RIGHT HOLD
424 if (GetUApi().GetInputByID(UAUIRight).LocalHold())
425 GetSelectedTab().RightHold();
426
427 // RIGHT RELEASE
428 if (GetUApi().GetInputByID(UAUIRight).LocalRelease())
429 GetSelectedTab().RightRelease();
430
431 if (GetUApi().GetInputByID(UAUIUp).LocalPress())
432 GetSelectedTab().Up();
433
434 if (GetUApi().GetInputByID(UAUIDown).LocalPress())
435 GetSelectedTab().Down();
436
437 if (GetUApi().GetInputByID(UAUIBack).LocalPress())
438 Back();
439 }
440
441 super.Update(timeslice);
442 }
443
445 {
446 if (w)
447 return (w == m_Play || w == m_CustomizeCharacter || w == m_Back);
448 return false;
449 }
450
452 {
453 m_Favorites = new TStringArray;
454
455#ifdef PLATFORM_WINDOWS
457#else
458 GetGame().GetProfileStringList("SB_Favorites", m_Favorites);
459
460 // ignore any ids that do not follow correct IP:PORT format
461 for (int i = 0; i < m_Favorites.Count(); ++i)
462 {
463 string id = m_Favorites[i];
465
466 id.Split(":", output);
467 if (output.Count() != 2)
468 {
469 m_Favorites.Remove(i);
470 --i;
471 }
472 }
473
474 // only handle MAX_FAVORITES on consoles
475 if (m_Favorites.Count() > MAX_FAVORITES)
476 {
477 // favorites are ordered by when they were favorited
478 // so keep most recent favorites and ignore oldest favorites
479 m_Favorites.Invert();
480 m_Favorites.Resize(MAX_FAVORITES);
481 m_Favorites.Invert();
482 }
483#endif
484 }
485
487 {
488 GetGame().SetProfileStringList("SB_Favorites", m_Favorites);
489 GetGame().SaveProfile();
490
491 }
492
493 void SelectServer(ServerBrowserEntry server)
494 {
495
497 m_SelectedServer.Deselect();
498
500
501#ifdef PLATFORM_CONSOLE
502 // disable CONNECT button if server is offline
503 RichTextWidget aButton = RichTextWidget.Cast(layoutRoot.FindAnyWidget("ConnectIcon"));
504 TextWidget connectText = TextWidget.Cast(layoutRoot.FindAnyWidget("ConnectText"));
505
506 aButton.Show(server.IsOnline());
507 connectText.Show(server.IsOnline());
508#endif
509 }
510
511 void Connect(ServerBrowserEntry server)
512 {
514#ifdef PLATFORM_CONSOLE
515 SaveFavoriteServersConsoles();
516#endif
517 Play();
518 }
519
520 void Play()
521 {
523 {
524 string mapNM = m_SelectedServer.GetMapToRun();
525 if (!g_Game.VerifyWorldOwnership(mapNM))
526 {
527 GetGame().GetUIManager().ShowDialog("#server_browser_connect_label", "#mod_detail_info_warning", 232, DBT_OK, DBB_NONE, DMT_INFO, GetGame().GetUIManager().GetMenu());
528 g_Game.GoBuyWorldDLC(mapNM);
529 return;
530 }
531
532 string ip = m_SelectedServer.GetIP();
533 int port = m_SelectedServer.GetPort();
534 g_Game.ConnectFromServerBrowser(ip, port, "");
535 }
536 }
537
539 {
541 EnterScriptedMenu(MENU_CHARACTER);
542 }
543
545 {
546
547 }
548
550 {
551
552 }
553
555 {
556 switch (m_Tabber.GetSelectedIndex())
557 {
558 case 0:
559 {
560 return m_FavoritesTab;
561 }
562 case 1:
563 {
564 return m_OfficialTab;
565 }
566 case 2:
567 {
568 return m_CommunityTab;
569 }
570 case 3:
571 {
572 return m_LANTab;
573 }
574 }
575 return null;
576 }
577
579 {
580 LoadFavoriteServers();
581 SetServersLoadingTab(TabType.NONE);
582
583 if (GetSelectedTab().IsNotInitialized())
584 GetSelectedTab().RefreshList();
585
586 GetSelectedTab().Focus();
587 }
588
590 {
591 if (GetSelectedTab())
592 GetSelectedTab().OnLoadServerModsAsync(result_list.m_Id, result_list.m_Mods);
593 }
594
596 {
597#ifdef PLATFORM_WINDOWS
598#ifdef PLATFORM_CONSOLE
599 GetSelectedTab().OnLoadServersAsyncConsole(result_list, error, response);
600#else
601 GetSelectedTab().OnLoadServersAsyncPC(result_list, error, response);
602#endif
603#else
604 GetSelectedTab().OnLoadServersAsyncConsole(result_list, error, response);
605#endif
606 }
607
608 //Coloring functions (Until WidgetStyles are useful)
610 {
611 if (!w)
612 return;
613
614 int color_pnl = ARGB(255, 0, 0, 0);
615 int color_lbl = ARGB(255, 255, 0, 0);
616
617#ifdef PLATFORM_CONSOLE
618 color_pnl = ARGB(255, 200, 0, 0);
619 color_lbl = ARGB(255, 255, 255, 255);
620#endif
621
622 ButtonSetColor(w, color_pnl);
623 ButtonSetTextColor(w, color_lbl);
624 }
625
627 {
628 if (!w)
629 return;
630
631 int color_pnl = ARGB(0, 0, 0, 0);
632 int color_lbl = ARGB(255, 255, 255, 255);
633
634 ButtonSetColor(w, color_pnl);
635 ButtonSetTextColor(w, color_lbl);
636 }
637
639 {
640 if (!w)
641 return;
642
643 TextWidget label = TextWidget.Cast(w.FindWidget(w.GetName() + "_label"));
644
645 if (label)
646 label.SetText(text);
647
648 }
649
651 {
652 if (!w)
653 return;
654
655 Widget panel = w.FindWidget(w.GetName() + "_panel");
656
657 if (panel)
658 panel.SetColor(color);
659 }
660
662 {
663 if (!w)
664 return;
665
666 TextWidget label = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_label"));
667 TextWidget text = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text"));
668 TextWidget text2 = TextWidget.Cast(w.FindAnyWidget(w.GetName() + "_text_1"));
669
670 if (label)
671 label.SetColor(color);
672
673 if (text)
674 text.SetColor(color);
675
676 if (text2)
677 text2.SetColor(color);
678 }
679
691}
EScriptInvokerInsertFlags
Definition tools.c:130
void OnInputPresetChanged()
Definition Inventory.c:160
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
Definition Inventory.c:167
ActionInput GetInput()
Definition ActionBase.c:989
EBiosError
Possible Error codes for bios API. This is the list of errors that can be returned from bios API....
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
ButtonWidget m_Back
void Back()
DayZGame g_Game
Definition DayZGame.c:3528
DayZGame GetDayZGame()
Definition DayZGame.c:3530
Icon x
Icon y
void UpdateControlsElements()
const int MAX_FAVORITES
const int SERVER_BROWSER_PAGE_SIZE
void SelectServer(ServerBrowserEntry server)
ServerBrowserEntry m_SelectedServer
TabType
void ColorNormal(Widget w)
bool IsNotInitialized()
bool IsFocusable(Widget w)
void OnLoadServerModsAsync(string server_id, array< string > mods)
void ColorHighlight(Widget w)
void Refresh()
EAnimPlayState Play()
proto native UAInputAPI GetUApi()
GetServersInput the input structure of the GetServers operation.
GetServersResult the output structure of the GetServers operation.
static string GetRichtextButtonIconFromInputAction(notnull UAInput pInput, string pLocalizedDescription, int pInputDeviceType=EUAINPUT_DEVICE_CONTROLLER, float pScale=ICON_SCALE_NORMAL, bool pVertical=false)
Definition InputUtils.c:151
static const float ICON_SCALE_TOOLBAR
Definition InputUtils.c:15
static ref ScriptInvoker m_ServersAsyncInvoker
static ref ScriptInvoker m_ServerModLoadAsyncInvoker
static void GetFavoriteServers(TStringArray favServers)
ref ServerBrowserTab m_OfficialTab
override bool OnMouseEnter(Widget w, int x, int y)
void ServerListFocus(bool focus, bool favorite)
bool SetFavoriteConsoles(string ipAddress, int port, bool favorite)
void FilterFocus(bool focus)
override bool OnFocus(Widget w, int x, int y)
override void Update(float timeslice)
override void Refresh()
void SelectServer(ServerBrowserEntry server)
void Connect(ServerBrowserEntry server)
void ColorHighlight(Widget w)
bool IsFocusable(Widget w)
ServerBrowserEntry m_SelectedServer
void OnInputDeviceChanged(EInputDeviceType pInputDeviceType)
void ButtonSetText(Widget w, string text)
void ShowAButton(bool show)
void OnLoadServerModsAsync(GetServerModListResult result_list)
override bool OnFocusLost(Widget w, int x, int y)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
void SetServersLoadingTab(TabType refreshing)
void OnLoadServersAsync(GetServersResult result_list, EBiosError error, string response)
ref ServerBrowserTab m_LANTab
void ButtonSetTextColor(Widget w, int color)
void AddFavoritesToFilter(GetServersInput input)
override Widget Init()
ref ServerBrowserTab m_CommunityTab
ref TStringArray m_Favorites
TStringArray GetFavoritedServerIds()
void AddFavorite(string ipAddress, int port, bool favorite)
override bool OnClick(Widget w, int x, int y, int button)
bool IsFavorited(string server_id)
void ButtonSetColor(Widget w, int color)
void ColorNormal(Widget w)
ref ServerBrowserTab m_FavoritesTab
ServerBrowserTab GetSelectedTab()
void ShowYButton(bool show)
proto native CGame GetGame()
array< string > TStringArray
Definition EnScript.c:666
const int MENU_CHARACTER
Definition constants.c:164
MouseState
Definition EnSystem.c:311
proto native void SetFocus(Widget w)
EInputDeviceType
Definition input.c:3
int ARGB(int a, int r, int g, int b)
Definition proto.c:322