Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ServerBrowserEntryComponent.c
Go to the documentation of this file.
3 {
4  // Attributes
5  [Attribute("999")]
6  protected int m_iPingLimit;
7 
8  [Attribute("download")]
9  protected string m_sTooltipDownloadIcon;
10 
11  [Attribute("1.75")]
12  protected float m_fTooltipDownloadIconScale;
13 
14  // Const
15  protected static const string LAYOUT_CONTENT = "HorizontalLayout";
16  protected static const string LAYOUT_LOADING = "Loading";
17 
18  protected static const string BUTTON_FAVORITE = "FavButton";
19  protected static const string BUTTON_JOIN = "JoinButton";
20  protected static const string BUTTON_PASSWORD = "PasswordButton";
21 
22  protected static const string ICON_WARNING = "VersionWarningIcon";
23  protected static const string ICON_UNJOINABLE = "JoinWarningIcon";
24  protected static const string ICON_MODDED = "ImageModded";
25  protected static const string ICON_PING = "ImgPing";
26 
27  protected static const string FRAME_NAME = "FrameName";
28  protected static const string FRAME_SCENARIO = "FrameScenario";
29 
30  protected static const string TEXT_CELL = "Content";
31 
32  // Base
33  protected Room m_RoomInfo;
34  protected SCR_EServerEntryProperty m_iProperties;
35 
36  // Ping
37  [Attribute("", UIWidgets.Object)]
38  protected ref array<ref ServerBrowserEntryProperty> m_aPingStates;
39 
40  // Backrounds and wrappers
41  protected Widget m_wHorizontalContent;
42  protected Widget m_wLoading;
43 
44  // Favorite widgets and behavior
45  protected Widget m_wUnjoinableIcon;
46 
47  protected ImageWidget m_wImgPing;
48  protected int m_iHighestPing = 0;
49 
50  protected Widget m_wImageModded;
51  protected Widget m_wJoinButton;
52  protected Widget m_wPasswordButton;
53 
54  protected SCR_RoomModsManager m_ModsManager;
55  protected string m_sPatchSize;
56  protected bool m_bIsPatchSizeLoaded;
57 
58  protected Widget m_wVersionWarningIcon;
59 
60  //------------------------------------------------------------------------------------------------
61  // Override
62  //------------------------------------------------------------------------------------------------
63 
64  //------------------------------------------------------------------------------------------------
65  override void HandlerAttached(Widget w)
66  {
67  m_wRoot = w;
68 
69  if (!GetGame().InPlayMode())
70  return;
71 
72  // Get wrappers
73  m_wHorizontalContent = m_wRoot.FindAnyWidget(LAYOUT_CONTENT);
74  m_wLoading = m_wRoot.FindAnyWidget(LAYOUT_LOADING);
75 
76  // Setup favorite button
77  Widget favoriteButton = w.FindAnyWidget(BUTTON_FAVORITE);
78  if (favoriteButton)
79  {
80  m_FavComponent = SCR_ModularButtonComponent.Cast(favoriteButton.FindHandler(SCR_ModularButtonComponent));
81 
82  m_wVersionWarningIcon = w.FindAnyWidget(ICON_WARNING);
83  m_wUnjoinableIcon = w.FindAnyWidget(ICON_UNJOINABLE);
84  }
85 
86  // Property images and buttons
87  m_wImageModded = w.FindAnyWidget(ICON_MODDED);
88  m_wJoinButton = w.FindAnyWidget(BUTTON_JOIN);
89  m_wPasswordButton = w.FindAnyWidget(BUTTON_PASSWORD);
90 
91  // Mouse interaction buttons
92  if (m_FavComponent)
93  m_aMouseButtons.Insert(m_FavComponent);
94 
95  SCR_ModularButtonComponent buttonComp = SCR_ModularButtonComponent.FindComponent(m_wJoinButton);
96  if (buttonComp)
97  {
98  buttonComp.m_OnClicked.Insert(OnJoinInteractionButtonClicked);
99  m_aMouseButtons.Insert(buttonComp);
100  }
101 
102  buttonComp = SCR_ModularButtonComponent.FindComponent(m_wPasswordButton);
103  if (buttonComp)
104  {
105  buttonComp.m_OnClicked.Insert(OnJoinInteractionButtonClicked);
106  m_aMouseButtons.Insert(buttonComp);
107  }
108 
109  // Ping
110  m_wImgPing = ImageWidget.Cast(w.FindAnyWidget(ICON_PING));
111 
112  // Name
114  Widget frameName = m_wRoot.FindAnyWidget(FRAME_NAME);
115  if (frameName)
116  {
117  scrollComp = SCR_HorizontalScrollAnimationComponent.Cast(frameName.FindHandler(SCR_HorizontalScrollAnimationComponent));
118  if (scrollComp)
119  m_aScrollAnimations.Insert(scrollComp);
120  }
121 
122  // Scenario
123  Widget frameScenario = m_wRoot.FindAnyWidget(FRAME_SCENARIO);
124  if (frameScenario)
125  {
126  scrollComp = SCR_HorizontalScrollAnimationComponent.Cast(frameScenario.FindHandler(SCR_HorizontalScrollAnimationComponent));
127  if (scrollComp)
128  m_aScrollAnimations.Insert(scrollComp);
129  }
130 
131  // Loading
132  m_wLoading.SetVisible(false);
133 
134  // Get highest ping
135  foreach (ServerBrowserEntryProperty pingState : m_aPingStates)
136  {
137  int ping = pingState.m_sValue.ToInt();
138  if (m_iHighestPing < ping)
139  m_iHighestPing = ping;
140  }
141 
142  super.HandlerAttached(w);
143  }
144 
145  //------------------------------------------------------------------------------------------------
146  override void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
147  {
148  super.OnTooltipShow(tooltipClass, tooltipWidget, hoverWidget, preset, tag);
149 
150  string message = tooltipClass.GetDefaultMessage();
151 
152  switch (tag)
153  {
154  case "VersionMismatch":
156  if (comp && m_RoomInfo)
157  comp.SetWrongVersionMessage(m_RoomInfo.GameVersion());
158  break;
159 
160  case "Join":
162  message = string.Format(message, GetDownloadSizeMessage());
163 
164  tooltipClass.SetMessage(message);
165  break;
166  }
167  }
168 
169  //------------------------------------------------------------------------------------------------
170  override void UpdateModularButtons()
171  {
172  // Password and Play buttons
173  if (m_wJoinButton)
174  m_wJoinButton.SetVisible(m_bMouseButtonsEnabled && m_bFocused && !(m_iProperties & SCR_EServerEntryProperty.PASSWORD_PROTECTED) && !(m_iProperties & SCR_EServerEntryProperty.UNJOINABLE));
175 
176  super.UpdateModularButtons();
177  }
178 
179  //------------------------------------------------------------------------------------------------
180  override bool OnFocusLost(Widget w, int x, int y)
181  {
182  if (m_ModsManager)
183  {
184  m_ModsManager.GetOnGetAllDependencies().Remove(OnServerDetailModsLoaded);
185  m_bIsPatchSizeLoaded = false;
186  }
187 
188  return super.OnFocusLost(w, x, y);
189  }
190 
191  //------------------------------------------------------------------------------------------------
192  // Protected
193  //------------------------------------------------------------------------------------------------
194 
195  //------------------------------------------------------------------------------------------------
196  protected void OnJoinInteractionButtonClicked()
197  {
198  if (m_OnMouseInteractionButtonClicked)
199  m_OnMouseInteractionButtonClicked.Invoke("");
200  }
201 
202  //------------------------------------------------------------------------------------------------
206  protected void SetCellText(string cellName, string str)
207  {
208  Widget wCell = m_wRoot.FindAnyWidget(cellName);
209  if (!wCell)
210  return;
211 
212  TextWidget wText = TextWidget.Cast(wCell.FindAnyWidget(TEXT_CELL));
213  if (wText)
214  wText.SetText(str);
215  }
216 
217  //------------------------------------------------------------------------------------------------
220  protected void DisplayPing(int ping)
221  {
222  //TODO: the ping threshold are manually set in the layout. This values should be unified with the server browser threshold check and filters .conf 4F6F41C387ADC14E
223 
224  float lastHighest = m_iHighestPing + 1;
225  ServerBrowserEntryProperty displayState;
226 
227  // No ping state
228  if (ping == 0)
229  {
230  if (m_wImgPing)
231  m_wImgPing.SetVisible(false);
232 
233  return;
234  }
235 
236  // Go through available icons
237  foreach (ServerBrowserEntryProperty pingState : m_aPingStates)
238  {
239  float pingFromStr = pingState.m_sValue.ToFloat();
240 
241  // Find smallest ping
242  if (ping < pingFromStr && pingFromStr < lastHighest)
243  {
244  displayState = pingState;
245  lastHighest = pingFromStr;
246  }
247  }
248 
249  // Set ping text
250  string strPing = Math.Floor(ping).ToString();
251 
252  // Over limit
253  if (ping > m_iHighestPing || ping < 0)
254  displayState = m_aPingStates[m_aPingStates.Count() - 1];
255 
256  if (ping > m_iPingLimit)
257  strPing = m_iPingLimit.ToString() + "#ENF-ComboModifier";
258 
259  SetCellText("Ping", strPing);
260 
261  // Set ping icon
262  if (displayState && m_wImgPing)
263  {
264  m_wImgPing.SetVisible(true);
265  m_wImgPing.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, displayState.m_sImageName);
266  m_wImgPing.SetColor(displayState.m_Color);
267  }
268  }
269 
270  //------------------------------------------------------------------------------------------------
272  protected void CheckRoomProperties()
273  {
274  m_iProperties = 0;
275 
276  // Client versions missmatch
277  bool wrongVersion = m_RoomInfo.GameVersion() != GetGame().GetBuildVersion();
278  bool restrictedUGC = m_RoomInfo.IsModded() && !SCR_AddonManager.GetInstance().GetUgcPrivilege();
279 
280  if (wrongVersion || restrictedUGC)
281  m_iProperties |= SCR_EServerEntryProperty.VERSION_MISMATCH;
282 
283  // Locked with password
284  if (m_RoomInfo.PasswordProtected())
285  m_iProperties |= SCR_EServerEntryProperty.PASSWORD_PROTECTED;
286 
287  // Crossplay
288  if (m_RoomInfo.IsCrossPlatform())
289  m_iProperties |= SCR_EServerEntryProperty.CROSS_PLATFORM;
290 
291  // LAN - TODO@wernerjak - add local network check
292  // m_iProperties |= SCR_EServerEntryProperty.LAN;
293 
294  // MODDED
295  if (m_RoomInfo.IsModded())
297 
298  // UNJOINABLE
299  if (!m_RoomInfo.Joinable())
301  }
302 
303  //------------------------------------------------------------------------------------------------
305  protected void DisplayServerProperties()
306  {
307  // Check states
308  if (m_wImageModded)
310 
311  if (m_wPasswordButton)
312  m_wPasswordButton.SetVisible(m_iProperties & SCR_EServerEntryProperty.PASSWORD_PROTECTED && !(m_iProperties & SCR_EServerEntryProperty.UNJOINABLE));
313 
314  // Turn favorites button into warning or unjoinable icon
315  if (!m_FavComponent || !m_wVersionWarningIcon || !m_wUnjoinableIcon)
316  return;
317 
318  bool versionMismatch = m_iProperties & SCR_EServerEntryProperty.VERSION_MISMATCH;
319  bool unjoinable = m_iProperties & SCR_EServerEntryProperty.UNJOINABLE;
320 
321  m_FavComponent.SetEnabled(!versionMismatch && !unjoinable);
322 
323  m_wVersionWarningIcon.SetVisible(versionMismatch && !unjoinable);
324  m_wUnjoinableIcon.SetVisible(unjoinable);
325 
326  m_bDisabled = versionMismatch || unjoinable;
327  UpdateModularButtons();
328  }
329 
330  //------------------------------------------------------------------------------------------------
331  protected string GetDownloadSizeMessage()
332  {
333  if (!m_ModsManager || !(m_iProperties & SCR_EServerEntryProperty.MODDED) || m_sPatchSize.IsEmpty())
334  return string.Empty;
335 
336  string icon, color;
337 
338  icon = string.Format("<image set='%1' name='%2' scale='%3'/>", UIConstants.ICONS_IMAGE_SET, m_sTooltipDownloadIcon, m_fTooltipDownloadIconScale.ToString());
339  return string.Format(" [%1%2 ]", icon, m_sPatchSize);
340  }
341 
342  //------------------------------------------------------------------------------------------------
343  protected void OnServerDetailModsLoaded()
344  {
346  return;
347 
348  array<ref SCR_WorkshopItem> toUpdateMods = m_ModsManager.GetRoomItemsToUpdate();
349  if (!toUpdateMods.IsEmpty())
350  m_sPatchSize = m_ModsManager.GetModListPatchSizeString(toUpdateMods);
351  else
352  m_sPatchSize = string.Empty;
353 
354  m_bIsPatchSizeLoaded = true;
355  UpdateTooltipJoinDownloadSizeMessage();
356  }
357 
358  //------------------------------------------------------------------------------------------------
359  protected void UpdateTooltipJoinDownloadSizeMessage()
360  {
361  if (!m_CurrentTooltip || !m_CurrentTooltip.IsVisible())
362  return;
363 
364  switch (m_CurrentTooltip.GetTag())
365  {
366  case "Join":
367  string message = m_CurrentTooltip.GetDefaultMessage();
368  message = string.Format(message, GetDownloadSizeMessage());
369  m_CurrentTooltip.SetMessage(message);
370  break;
371  }
372  }
373 
374  //------------------------------------------------------------------------------------------------
375  // Public
376  //------------------------------------------------------------------------------------------------
377 
378  //------------------------------------------------------------------------------------------------
381  void SetRoomInfo(Room room)
382  {
383  m_RoomInfo = room;
384 
385  // Visualize as empty?
386  if (!m_RoomInfo)
387  return;
388 
389  // Setup room properties
390  CheckRoomProperties();
391  DisplayServerProperties();
392 
393  // Name
394  SetCellText("Name", m_RoomInfo.Name());
395 
396  // Scenario
397  SetCellText("Scenario", m_RoomInfo.ScenarioName());
398 
399  // Player count
400  string playerCount = m_RoomInfo.PlayerCount().ToString();
401  string playerCountMax = m_RoomInfo.PlayerLimit().ToString();
402 
403  SetCellText("Players", playerCount + "/" + playerCountMax);
404 
405  // Favorite
406  if (m_FavComponent)
407  SetFavorite(m_RoomInfo.IsFavorite());
408 
409  // Ping
410  DisplayPing(room.GetPing());
411  }
412 
413  //------------------------------------------------------------------------------------------------
416  void EmptyVisuals(bool enable)
417  {
418  m_wHorizontalContent.SetVisible(!enable);
419  m_wLoading.SetVisible(enable);
420  }
421 
422  //------------------------------------------------------------------------------------------------
424  void SetModsManager(SCR_RoomModsManager modsManager)
425  {
426  m_ModsManager = modsManager;
427 
428  if (m_ModsManager)
429  {
430  m_ModsManager.GetOnGetAllDependencies().Insert(OnServerDetailModsLoaded);
431  m_bIsPatchSizeLoaded = false;
432  }
433  }
434 
435  //------------------------------------------------------------------------------------------------
437  Room GetRoomInfo()
438  {
439  return m_RoomInfo;
440  }
441 
442  //------------------------------------------------------------------------------------------------
444  bool GetIsModded()
445  {
446  return m_iProperties & SCR_EServerEntryProperty.MODDED;
447  }
448 
449  //------------------------------------------------------------------------------------------------
453  bool GetIsEnabled(out bool versionMismatch, out bool unjoinable)
454  {
455  versionMismatch = m_iProperties & SCR_EServerEntryProperty.VERSION_MISMATCH;
456  unjoinable = m_iProperties & SCR_EServerEntryProperty.UNJOINABLE;
457  return !versionMismatch && !unjoinable;
458  }
459 }
460 
462 class ServerBrowserEntryProperty
463 {
464  [Attribute("1", UIWidgets.ComboBox, "", category:"Selector", ParamEnumArray.FromEnum(SCR_EServerEntryProperty))]
465  SCR_EServerEntryProperty m_iPropertyState;
466 
467  [Attribute("", UIWidgets.EditBox, desc: "Image name to load")]
468  string m_sImageName;
469 
470  [Attribute("", UIWidgets.EditBox, desc: "String value of property")]
471  string m_sValue;
472 
473  [Attribute("1 1 1 1", UIWidgets.ColorPicker)]
474  ref Color m_Color;
475 }
476 
478 {
481  CROSS_PLATFORM = 1 << 2,
482  LAN = 1 << 3,
483  MODDED = 1 << 4,
484  UNJOINABLE = 1 << 5,
485 }
MODDED
@ MODDED
Definition: SCR_ServerBrowserEntryComponent.c:483
m_iProperties
protected SCR_EServerEntryProperty m_iProperties
Definition: SCR_ServerBrowserEntryComponent.c:32
m_wUnjoinableIcon
protected Widget m_wUnjoinableIcon
Definition: SCR_ServerBrowserEntryComponent.c:43
SCR_HorizontalScrollAnimationComponent
Definition: SCR_HorizontalScrollAnimationComponent.c:14
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
m_iPingLimit
protected int m_iPingLimit
Definition: SCR_ServerBrowserEntryComponent.c:4
m_bIsPatchSizeLoaded
protected bool m_bIsPatchSizeLoaded
Definition: SCR_ServerBrowserEntryComponent.c:54
m_wHorizontalContent
protected Widget m_wHorizontalContent
Definition: SCR_ServerBrowserEntryComponent.c:39
m_wPasswordButton
protected Widget m_wPasswordButton
Definition: SCR_ServerBrowserEntryComponent.c:50
m_RoomInfo
protected Room m_RoomInfo
Definition: SCR_ServerBrowserEntryComponent.c:31
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_ServerBrowserEntryComponent
This component handles server entry and visiualization of server data.
Definition: SCR_ServerBrowserEntryComponent.c:2
LAN
@ LAN
Definition: SCR_ServerBrowserEntryComponent.c:482
m_sTooltipDownloadIcon
protected string m_sTooltipDownloadIcon
Definition: SCR_ServerBrowserEntryComponent.c:7
m_sPatchSize
protected string m_sPatchSize
Definition: SCR_ServerBrowserEntryComponent.c:53
m_fTooltipDownloadIconScale
protected float m_fTooltipDownloadIconScale
Definition: SCR_ServerBrowserEntryComponent.c:10
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_aPingStates
protected ref array< ref ServerBrowserEntryProperty > m_aPingStates
Definition: SCR_ServerBrowserEntryComponent.c:36
m_ModsManager
protected SCR_RoomModsManager m_ModsManager
Definition: SCR_ServerBrowserEntryComponent.c:52
SCR_VersionMismatchTooltipComponent
Definition: SCR_VersionMismatchTooltipComponent.c:4
m_wVersionWarningIcon
protected Widget m_wVersionWarningIcon
Definition: SCR_ServerBrowserEntryComponent.c:56
UNJOINABLE
@ UNJOINABLE
Definition: SCR_ServerBrowserEntryComponent.c:484
SCR_EServerEntryProperty
SCR_EServerEntryProperty
Definition: SCR_ServerBrowserEntryComponent.c:477
SCR_ListMenuEntryComponent
Definition: SCR_ListMenuEntryComponent.c:9
SCR_RoomModsManager
Definition: SCR_RoomModsManager.c:27
BaseContainerProps
SCR_ServerBrowserEntryComponent SCR_ListMenuEntryComponent BaseContainerProps()] class ServerBrowserEntryProperty
Definition: SCR_ServerBrowserEntryComponent.c:461
m_Color
ref Color m_Color
Definition: SCR_GeneratorBaseEntity.c:3
SCR_AddonManager
Definition: SCR_AddonManager.c:72
CROSS_PLATFORM
@ CROSS_PLATFORM
Definition: SCR_ServerBrowserEntryComponent.c:481
m_wImgPing
protected ImageWidget m_wImgPing
Definition: SCR_ServerBrowserEntryComponent.c:45
m_wJoinButton
protected Widget m_wJoinButton
Definition: SCR_ServerBrowserEntryComponent.c:49
m_iHighestPing
protected int m_iHighestPing
Definition: SCR_ServerBrowserEntryComponent.c:46
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15
m_wLoading
protected Widget m_wLoading
Definition: SCR_ServerBrowserEntryComponent.c:40
VERSION_MISMATCH
@ VERSION_MISMATCH
Definition: SCR_ServerBrowserEntryComponent.c:479
m_wImageModded
protected Widget m_wImageModded
Definition: SCR_ServerBrowserEntryComponent.c:48
PASSWORD_PROTECTED
@ PASSWORD_PROTECTED
Definition: SCR_ServerBrowserEntryComponent.c:480
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180