DayZ 1.24
Loading...
Searching...
No Matches
ServerBrowserEntry.c
Go to the documentation of this file.
1class ServerBrowserEntry extends ScriptedWidgetEventHandler
2{
3 protected Widget m_Root;
4 protected Widget m_Favorite;
5 protected Widget m_Expand;
6
7 //Basic info
16
17 //Detailed info
29
30 protected bool m_IsExpanded;
31 protected bool m_IsFavorited;
32 protected bool m_IsOnline;
33
35 protected int m_Index;
37 protected bool m_Selected;
38 protected bool m_FirstExpand = true;
39
41 {
42#ifdef PLATFORM_CONSOLE
43 m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/server_browser/xbox/server_browser_list_entry.layout", parent);
44#else
45 m_Root = GetGame().GetWorkspace().CreateWidgets("gui/layouts/new_ui/server_browser/pc/server_browser_list_entry_pages.layout", parent);
46#endif
47
48 m_Root.Enable(true);
49 m_Favorite = m_Root.FindAnyWidget("favorite_button");
50 m_Expand = m_Root.FindAnyWidget("expand_button");
51 m_ServerName = TextWidget.Cast(m_Root.FindAnyWidget("server_name"));
52 m_ServerPopulation = TextWidget.Cast(m_Root.FindAnyWidget("server_population"));
53 m_ServerSlots = TextWidget.Cast(m_Root.FindAnyWidget("server_slots"));
54 m_ServerPing = TextWidget.Cast(m_Root.FindAnyWidget("server_ping"));
55 m_ServerTime = ImageWidget.Cast(m_Root.FindAnyWidget("server_time"));
56 m_ServerLock = ImageWidget.Cast(m_Root.FindAnyWidget("lock_icon"));
57 m_ServerModIcon = ImageWidget.Cast(m_Root.FindAnyWidget("modded_icon"));
58 m_ServerMaKIcon = ImageWidget.Cast(m_Root.FindAnyWidget("mandk_icon"));
59
60 m_ServerShard = TextWidget.Cast(m_Root.FindAnyWidget("shard_text"));
61 m_ServerCharacterAlive = TextWidget.Cast(m_Root.FindAnyWidget("character_alive_text"));
62 m_ServerFriends = TextWidget.Cast(m_Root.FindAnyWidget("steam_friends_text"));
63 m_ServerMode = TextWidget.Cast(m_Root.FindAnyWidget("mode_text"));
64 m_ServerBattleye = TextWidget.Cast(m_Root.FindAnyWidget("battlleye_text"));
65 m_ServerIP = TextWidget.Cast(m_Root.FindAnyWidget("ip_text"));
66 m_ServerAcceleration = TextWidget.Cast(m_Root.FindAnyWidget("server_acceleration_text"));
67 m_ServerMap = TextWidget.Cast(m_Root.FindAnyWidget("map_text"));
68 m_ServerMods = TextWidget.Cast(m_Root.FindAnyWidget("mods_text"));
69 m_ServerModsExpand = ButtonWidget.Cast(m_Root.FindAnyWidget("mods_expand"));
70
71 m_Root.FindAnyWidget("basic_info").Show(true);
72 m_Root.FindAnyWidget("favorite_image").Update();
73 m_Root.FindAnyWidget("unfavorite_image").Update();
74
75 m_Index = index;
76 m_Tab = tab;
77 m_IsOnline = true;
78
79 m_ServerTime.LoadImageFile(0, "set:dayz_gui image:icon_sun");
80 m_ServerTime.LoadImageFile(1, "set:dayz_gui image:icon_sun_accel");
81 m_ServerTime.LoadImageFile(2, "set:dayz_gui image:icon_moon");
82 m_ServerTime.LoadImageFile(3, "set:dayz_gui image:icon_moon_accel");
83
84 m_Root.SetHandler(this);
85 }
86
88 {
89 delete m_Root;
90 }
91
93 {
94 return m_Root;
95 }
96
97 void Show(bool show)
98 {
99 m_Root.Show(show);
100 }
101
102 override bool OnClick(Widget w, int x, int y, int button)
103 {
104 if (!IsOnline())
105 return false;
106
107#ifdef PLATFORM_CONSOLE
108 if (w == m_Root)
109 {
110 m_Tab.Connect(this);
111 return true;
112 }
113#endif
114
115 if (w == m_ServerModsExpand)
116 {
117 string mods_text;
118 if (m_Mods && m_Mods.Count() > 0)
119 {
120 mods_text = m_Mods[0];
121 for (int i = 1; i < m_Mods.Count(); i++)
122 mods_text += "\n" + m_Mods[i];
123 }
124
125 GetGame().GetUIManager().ShowDialog("#main_menu_mods", mods_text, 0, 0, 0, 0, GetGame().GetUIManager().GetMenu());
126 }
127
128 return false;
129 }
130
131 override bool OnDoubleClick(Widget w, int x, int y, int button)
132 {
133 if (!IsOnline())
134 return false;
135
136 if (button == MouseState.LEFT)
137 {
138 if (w == m_Root)
139 {
140 m_Tab.Connect(this);
141 return true;
142 }
143 }
144
145 return false;
146 }
147
148 override bool OnMouseButtonUp(Widget w, int x, int y, int button)
149 {
150 if (button == MouseState.LEFT)
151 {
152 if (w == m_Favorite)
153 {
155 return true;
156 }
157 else if (w == m_Expand)
158 {
159 ToggleExpand();
160 return true;
161 }
162 else if (w == m_Root)
163 {
164 Darken(w, x, y);
165 Select();
167 return true;
168 }
169 }
170 return false;
171 }
172
173 override bool OnMouseEnter(Widget w, int x, int y)
174 {
175 if (IsFocusable(w))
176 {
177 Preview(w, x, y);
178 return true;
179 }
180
181 return false;
182 }
183
184 override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
185 {
187 {
188 Lighten(w, enterW, x, y);
189 return true;
190 }
191
192 return false;
193 }
194
195 void Focus()
196 {
198 }
199
201 {
202 m_Tab.ServerListFocus(focus, m_IsFavorited);
203 }
204
205 override bool OnFocus(Widget w, int x, int y)
206 {
207 if (!m_Selected)
208 {
209 if (IsFocusable(w))
210 Darken(w, x, y);
211
212#ifdef PLATFORM_CONSOLE
213 if (w == m_Root)
214 {
215 Select();
216 ServerListFocus(true);
217 }
218#endif
219
220 return true;
221 }
222 return false;
223 }
224
225 override bool OnFocusLost(Widget w, int x, int y)
226 {
227#ifdef PLATFORM_CONSOLE
228
229 if (w == m_Root)
230 {
231 Deselect();
232 ServerListFocus(false);
233 }
234#endif
235
236 if (IsFocusable(w))
237 Lighten(w, null, x, y);
238
239 return true;
240 return false;
241 }
242
243 bool IsOnline()
244 {
245 return m_IsOnline;
246 }
247
249 {
250 if (w)
251 return (w == m_Root || w == m_Favorite || w == m_Expand || w == m_ServerModsExpand);
252
253 return false;
254 }
255
257 {
258 m_ServerData = server_info;
259 m_FirstExpand = true;
260
261#ifndef PLATFORM_CONSOLE
262 m_Root.FindAnyWidget("detailed_info").Show(server_info.m_IsExpanded);
263#endif
264
265 SetName(server_info.m_Name);
266 SetPasswordLocked(server_info.m_IsPasswordProtected);
268 SetSlots(server_info.m_MaxPlayers);
269 SetPing(server_info.m_Ping);
270 SetTime(server_info.m_TimeOfDay, server_info.m_EnvironmentTimeMul);
271 SetFavorite(server_info.m_Favorite);
272 SetModded(server_info.m_Modded);
273 SetMapName(server_info.m_MapNameToRun);
274
275#ifdef PLATFORM_CONSOLE
276 SetMouseAndKeyboard(server_info.m_MouseAndKeyboardEnabled);
277#endif
278
279#ifdef PLATFORM_WINDOWS
280#ifndef PLATFORM_CONSOLE
281 SetExpand(server_info.m_IsExpanded);
282
283 int pp = 0; // private
284 if (server_info.m_ShardId.Length() == 3 && server_info.m_ShardId.ToInt() < 200)
285 {
286 pp = 1; // official
287 }
288
289 SetShard(pp);
290 SetCharacterAlive(server_info.m_CharactersAlive);
291 SetFriends(server_info.m_SteamFriends);
292 SetMode(server_info.m_Disable3rdPerson);
293 SetBattleye(server_info.m_AntiCheat);
294 SetIP(server_info.m_Id);
295 SetAcceleration(server_info.m_EnvironmentTimeMul);
297#endif
298#endif
299 }
300
302 {
303 if (m_ServerData.m_IsSelected)
304 {
305 Darken(m_Root, 0, 0);
306 Select();
308 }
309 else
310 Lighten(m_Root, null, 0, 0);
311 }
312
313 void SetName(string name)
314 {
315 m_ServerName.SetText(name);
316 }
317
319 {
320 m_ServerLock.Show(locked);
321 }
322
323 // DEPRECATED
325 {
326 int color = ARGBF(1, 1, 1, 1);
327 string pop_text = population.ToString() + "/" + slots.ToString();
328
329 if (slots > 0)
330 {
332
333 if (pop_percentage >= 1)
334 color = ARGBF(1, 1, 0, 0);
335 else if (pop_percentage >= 0.8)
336 color = ARGBF(1, 1, 0.5, 0);
337 }
338
339 m_ServerPopulation.SetText(pop_text);
340 m_ServerPopulation.SetColor(color);
341 m_ServerPopulation.SetBold(true);
342 m_ServerPopulation.SetOutline(1);
343
344 }
345
347 {
348 string popText = "";
349 int population = serverInfo.m_CurrentNumberPlayers;
350 int maxPlayers = serverInfo.m_MaxPlayers;
351 int playersInQueue = serverInfo.m_PlayersInQueue;
352
353 if (IsOnline())
354 {
355 // sometimes servers report a queue size even though server isn't full,
356 // in which case we ignore queue size
358 popText = population.ToString() + "+" + playersInQueue.ToString() + "/" + maxPlayers.ToString();
359 else
360 popText = population.ToString() + "/" + maxPlayers.ToString();
361 }
362
363 else
364 popText = "-";
365
366 m_ServerPopulation.SetText(popText);
367 }
368
369 void SetSlots(int slots)
370 {
371 if (IsOnline())
372 m_ServerSlots.SetText(slots.ToString());
373 else
374 m_ServerSlots.SetText("-");
375 }
376
377 void SetPing(int ping)
378 {
379 int color;
380 string displayValue;
381
382 if (ping < 50)
383 color = ARGBF(1, 0, 1, 0);
384 else if (ping < 100)
385 color = ARGBF(1, 0.8, 0.8, 0);
386 else if (ping < 200)
387 color = ARGBF(1, 1, 0.5, 0);
388 else
389 color = ARGBF(1, 1, 0, 0);
390
391 if (IsOnline())
392 displayValue = ping.ToString();
393
394 else
395 displayValue = "-";
396
397 m_ServerPing.SetColor(color);
398 m_ServerPing.SetText(displayValue);
399 }
400
401 void SetTime(string time, float multiplier)
402 {
403 if (time != "")
404 {
406
407 time.Split(":", arr);
408
409 if (arr.Count() == 2)
410 {
411 int hour = arr.Get(0).ToInt();
412 int minute = arr.Get(1).ToInt();
413
414 if (hour >= 19 || hour <= 5) //Night
415 {
416 if (multiplier > 1)
417 m_ServerTime.SetImage(3);
418 else
419 m_ServerTime.SetImage(2);
420 }
421 else //Day
422 {
423 if (multiplier > 1)
424 m_ServerTime.SetImage(1);
425 else
426 m_ServerTime.SetImage(0);
427 }
428 }
429 }
430 }
431
432 void SetShard(int shard)
433 {
434 string text;
435 switch (shard)
436 {
437 case 0:
438 {
439 text = "#server_browser_entry_private";
440 break;
441 }
442 case 1:
443 {
444 text = "#server_browser_entry_official";
445 break;
446 }
447 }
448 m_ServerShard.SetText(text);
449 }
450
451 void SetMapName(string mapName)
452 {
454 }
455
457 {
458 if (m_ServerData.m_IsDLC)
459 {
460 bool own = GetGame().VerifyWorldOwnership(GetMapToRun());
461 m_ServerModIcon.Show(true);
462 m_ServerModIcon.FindWidget("Owned").Show(own);
463 m_ServerModIcon.FindWidget("Unowned").Show(!own);
464 }
465 else
466 {
467 m_ServerModIcon.FindWidget("Owned").Show(false);
468 m_ServerModIcon.FindWidget("Unowned").Show(false);
469 }
470 }
471
473 {
474 if (char_alive == "")
475 m_ServerCharacterAlive.SetText("#STR_server_browser_char_not_alive");
476 else
477 m_ServerCharacterAlive.SetText(char_alive);
478 }
479
481 {
482 m_ServerFriends.SetText(friends_text);
483 }
484
485 void SetMode(int mode)
486 {
487 string text;
488 switch (mode)
489 {
490 case 0:
491 {
492 text = "#server_browser_entry_person_both";
493 break;
494 }
495 case 1:
496 {
497 text = "#server_browser_entry_person_first";
498 break;
499 }
500 }
501 m_ServerMode.SetText(text);
502 }
503
505 {
506 if (battleye)
507 {
508 m_ServerBattleye.SetText("#server_browser_entry_enabled");
509 m_ServerBattleye.SetColor(ARGBF(1, 0, 1, 0));
510 }
511 else
512 {
513 m_ServerBattleye.SetText("#server_browser_entry_disabled");
514 m_ServerBattleye.SetColor(ARGBF(1, 1, 0, 0));
515 }
516 }
517
518 void SetIP(string ip)
519 {
520 m_ServerIP.SetText(ip);
521 }
522
523 string GetIP()
524 {
525 return m_ServerData.GetIP();
526 }
527
529 {
530 return m_ServerData.m_HostPort;
531 }
532
533 string GetServerID()
534 {
535 return m_ServerData.m_Id;
536 }
537
538 string GetMapToRun()
539 {
540 return m_ServerData.m_MapNameToRun;
541 }
542
543 string GetMapName()
544 {
545 string map_name = m_ServerData.m_MapNameToRun;
546 map_name.ToLower();
547
548 if (map_name == "enoch")
549 return "Livonia";
550 if (map_name == "chernarusplus")
551 return "Chernarus";
552
553 return m_ServerData.m_MapNameToRun;
554 }
555
557 {
558 m_IsFavorited = favorite;
559 m_Root.FindAnyWidget("favorite_image").Show(favorite);
560 m_Root.FindAnyWidget("unfavorite_image").Show(!favorite);
561 }
562
564 {
565 if (mult > 1)
566 {
567 m_ServerAcceleration.Show(true);
568 m_ServerAcceleration.SetText(mult.ToString() + "x");
569 }
570 else
571 m_ServerAcceleration.Show(false);
572 }
573
575 {
576 m_ServerModIcon.Show(is_modded);
577 }
578
580 {
581 m_ServerMap.SetText(GetMapName());
582 }
583
585 {
586 m_Mods = mods;
587
588 //string mods_text = "#STR_USRACT_MAP" + ": " + GetMapName() + " | ";
589 if (mods && mods.Count() > 0)
590 {
591 string mods_text = mods[0];
592 for (int i = 1; i < mods.Count(); i++)
593 mods_text += ", " + mods[i];
594
595 m_ServerMods.SetText(mods_text);
596 }
597
598#ifdef PLATFORM_WINDOWS
599 m_ServerModsExpand.Show((mods && mods.Count() > 0));
600#endif
601 }
602
604 {
605 m_ServerMaKIcon.Show(is_mkenabled);
606 }
607
609 {
610 m_IsOnline = isOnline;
611 }
612
614 {
615 m_IsFavorited = !m_IsFavorited;
616 string ip = m_ServerData.GetIP();
617#ifdef PLATFORM_WINDOWS
618 //Save Data PC
619 m_Tab.GetRootMenu().AddFavorite(ip, m_ServerData.m_SteamQueryPort, m_IsFavorited);
620
621#ifdef PLATFORM_CONSOLE
622 OnlineServices.SetServerFavorited(ip, 0, m_ServerData.m_SteamQueryPort, m_IsFavorited);
623#else
624 OnlineServices.SetServerFavorited(ip, m_ServerData.m_HostPort, m_ServerData.m_SteamQueryPort, m_IsFavorited);
625#endif
626#else
627 //Save Data Console
628 m_IsFavorited = m_Tab.GetRootMenu().SetFavoriteConsoles(ip, m_ServerData.m_HostPort, m_IsFavorited);
629#endif
630
631 m_Root.FindAnyWidget("unfavorite_image").Show(!m_IsFavorited);
632 m_Root.FindAnyWidget("favorite_image").Show(m_IsFavorited);
633
634 return m_IsFavorited;
635 }
636
638 {
639 return SetExpand(!m_IsExpanded);
640 }
641
642 bool SetExpand(bool expand)
643 {
645 m_Root.FindAnyWidget("collapse_image").Show(m_IsExpanded);
646 m_Root.FindAnyWidget("expand_image").Show(!m_IsExpanded);
647 m_Root.FindAnyWidget("detailed_info").Show(m_IsExpanded);
648
649 if (m_ServerData)
650 m_ServerData.m_IsExpanded = m_IsExpanded;
651
652 if (expand && m_FirstExpand)
653 {
654 if (m_ServerData.m_Modded)
655 OnlineServices.GetServerModList(m_ServerData.m_Id);
656 /*
657 else
658 m_ServerMods.SetText( "#STR_USRACT_MAP" + ": " + GetMapName() );
659 */
660
661 m_FirstExpand = false;
662 }
663
664 return m_IsExpanded;
665 }
666
667 void Select(bool notify = true)
668 {
669 if (!m_Selected)
670 {
671 if (notify)
672 m_Tab.SelectServer(this);
673
674 m_ServerData.m_IsSelected = true;
675
676 m_Selected = true;
677#ifdef PLATFROM_XBOX
678 m_Root.SetColor(ARGB(1, 50, 50, 50));
679#endif
680 }
681 }
682
683 void Deselect()
684 {
685 if (m_Selected)
686 {
687 m_ServerData.m_IsSelected = false;
688 m_Selected = false;
689
690 Lighten(m_Root, null, 0, 0);
691 }
692 }
693
695 {
696 float alpha = 1;
697 int maxPlayers = m_ServerData.m_MaxPlayers;
698 int whiteColor = ARGBF(1, 1, 1, 1);
700 int populationOutline = 1;
701
702 if (IsOnline())
703 {
704 if (maxPlayers > 0)
705 {
706 int population = m_ServerData.m_CurrentNumberPlayers;
708
709 if (pop_percentage >= 1)
710 populationColor = ARGBF(1, 1, 0, 0);
711 else if (pop_percentage >= 0.8)
712 populationColor = ARGBF(1, 1, 0.5, 0);
713 }
714 }
715
716 else
717 {
718 alpha = 0.5;
720
721 m_ServerPing.SetColor(whiteColor);
722 }
723
724 m_ServerTime.Show(IsOnline());
725 m_ServerName.SetColor(whiteColor);
726 m_ServerName.SetAlpha(alpha);
727 m_ServerPopulation.SetBold(IsOnline());
728 m_ServerPopulation.SetColor(populationColor);
729 m_ServerPopulation.SetOutline(populationOutline);
730 m_ServerPopulation.SetAlpha(alpha);
731 m_ServerSlots.SetAlpha(alpha);
732 m_ServerPing.SetAlpha(alpha);
733 m_Root.SetAlpha(alpha);
734
735#ifndef PLATFORM_CONSOLE
736 m_Expand.Show(IsOnline());
737#endif
738 }
739
740 //Coloring functions (Until WidgetStyles are useful)
741 void Preview(Widget w, int x, int y)
742 {
743 if (m_Selected)
744 return;
745
746 if (w == m_Root || w == m_Favorite || w == m_Expand)
747 {
748 m_Root.SetColor(ARGB(255, 0, 0, 0));
749 m_Root.SetAlpha(1);
750 UpdateColors();
751
752 m_ServerName.SetColor(ARGB(255, 255, 0, 0));
753 if (!IsOnline())
754 m_ServerName.SetAlpha(0.5);
755 }
756 }
757
758 //Coloring functions (Until WidgetStyles are useful)
759 void Darken(Widget w, int x, int y)
760 {
761 if (m_Selected)
762 return;
763
764 if (w == m_Root || w == m_Favorite || w == m_Expand)
765 {
766 m_Root.SetColor(ARGB(255, 200, 0, 0));
767 SetPopulationEx(m_ServerData);
768 UpdateColors();
769 }
770 }
771
772 void Lighten(Widget w, Widget enterW, int x, int y)
773 {
774 float alpha = 0.3;
775
776 if (GetFocus() == w || m_Selected)
777 return;
778
779 if (w == m_Root && ((m_Favorite && enterW == m_Favorite) || (m_Expand && enterW == m_Expand)))
780 return;
781
782 m_Root.SetColor(ARGB(255, 0, 0, 0));
783 SetPopulationEx(m_ServerData);
784 UpdateColors();
785
786 if (m_Index % 2)
787 alpha = 0;
788
789 m_Root.SetAlpha(alpha);
790 }
791}
bool m_Favorite
bool m_IsExpanded
PlayerSpawnPresetDiscreteItemSetSlotData name
one set for cargo
Icon x
Icon y
Widget m_Root
Definition SizeToChild.c:85
static void GetServerModList(string server_id)
static void SetServerFavorited(string ipAddress, int port, int steamQueryPort, bool is_favorited)
map: item x vector(index, width, height)
Definition EnWidgets.c:651
void Select(bool notify=true)
void SetModded(bool is_modded)
void SetFavorite(bool favorite)
void SetTime(string time, float multiplier)
override bool OnFocusLost(Widget w, int x, int y)
override bool OnMouseButtonUp(Widget w, int x, int y, int button)
override bool OnDoubleClick(Widget w, int x, int y, int button)
void SetFriends(string friends_text)
void SetMods(array< string > mods)
void SetPopulationEx(GetServersResultRow serverInfo)
void Lighten(Widget w, Widget enterW, int x, int y)
void Preview(Widget w, int x, int y)
void SetCharacterAlive(string char_alive)
override bool OnMouseLeave(Widget w, Widget enterW, int x, int y)
override bool OnClick(Widget w, int x, int y, int button)
void SetBattleye(bool battleye)
void SetMapName(string mapName)
void Darken(Widget w, int x, int y)
void SetPasswordLocked(bool locked)
bool IsFocusable(Widget w)
Definition CTKeyframe.c:156
void SetMouseAndKeyboard(bool is_mkenabled)
void ServerBrowserEntry(Widget parent, int index, ServerBrowserTab tab)
void SetIsOnline(bool isOnline)
override bool OnFocus(Widget w, int x, int y)
void FillInfo(GetServersResultRow server_info)
override bool OnMouseEnter(Widget w, int x, int y)
void SetPopulation(int population, int slots)
ref GetServersResultRow m_ServerData
override void SelectServer(ServerBrowserEntry server)
proto native CGame GetGame()
array< string > TStringArray
Definition EnScript.c:666
MouseState
Definition EnSystem.c:311
proto native Widget GetFocus()
proto native void SetFocus(Widget w)
int ARGB(int a, int r, int g, int b)
Definition proto.c:322
int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
Definition proto.c:332