Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ServerDetailsDialog.c
Go to the documentation of this file.
1 
8 {
9  protected const string WIDGET_SCROLL = "ScrollSize";
10  protected const string WIDGET_ADDON_LIST = "AddonList";
11  protected const string WIDGET_LOADING = "Loading";
12  protected const string WIDGET_TITLEFRAME = "TitleFrame";
13 
14  protected const string WIDGET_IPADDRESS_TEXT = "IPAddressText";
15  protected const string WIDGET_DISCORD_TEXT = "DiscordText";
16  protected const string WIDGET_MODS_NUMBER_TEXT = "ModsNumberText";
17  protected const string WIDGET_MODS_SIZE_TEXT = "ModsSizeAmount";
18  protected const string WIDGET_ALERT_TEXT = "AlertText";
19  protected const string WIDGET_ALERT_WRAPPER = "AlertOverlay"; //TODO: move alerts handling to a specific component on the button itself
20  protected const string WIDGET_MODS_SIZE_TO_DOWNLOAD_TEXT = "ModsSizeToDownload";
21 
22  protected const string WIDGET_MODS_SIZE_LAYOUT = "ModsSizeLayout";
23  protected const string WIDGET_DETAIL_ICONS_LAYOUT = "DetailIconsLayout";
24  protected const string WIDGET_MODS_SIZE_TO_DOWNLOAD_LAYOUT = "ModsSizeToDownloadLayout";
25 
26  protected const string IMG_WRONG_VERSION = "DetailIcon_WrongVersion";
27  protected const string IMG_PASSWORD_PROTECTED = "Detailicon_PasswordProtected";
28  protected const string IMG_CROSS_PLATFORM = "DetailIcon_CrossPlatform";
29  protected const string IMG_MODDED = "DetailIcon_Modded";
30  protected const string IMG_VERSION_ALERT = "VersionAlertIconButton";
31 
32  protected const string BTN_CONFIRM = "Confirm";
33  protected const string BTN_FAVORITES = "favorites";
34  protected const string BTN_FAVORITES_STAR = "FavoriteButton";
35  protected const string BTN_COPY_IPADDRESS = "IPAddressButton";
36  protected const string BTN_DISCORD = "DiscordButton";
37 
38  protected Widget m_wScroll;
39  protected Widget m_wAddonList;
40  protected Widget m_wLoading;
41  protected Widget m_wModsSizeLayout;
42  protected Widget m_wDetailIconsLayout;
43  protected Widget m_wVersionAlertIcon;
44  protected Widget m_wModsSizeToDownloadLayout;
45  protected Widget m_wAlertWrapper;
46 
47  protected RichTextWidget m_wIPAddressText;
48  protected RichTextWidget m_wDiscordText;
49  protected RichTextWidget m_wModsNumberText;
50  protected RichTextWidget m_wModsSizeText;
51  protected RichTextWidget m_wAlertText;
52  protected RichTextWidget m_wModsSizeToDownloadText;
53 
54  protected SCR_InputButtonComponent m_NavConfirm;
55  protected SCR_InputButtonComponent m_NavFavorites;
56 
57  protected SCR_ModularButtonComponent m_BtnFavorites;
58  protected SCR_ButtonComponent m_BtnCopyIPAddress;
59  protected SCR_ButtonComponent m_BtnDiscord;
60 
61  protected SCR_ScenarioBackendImageComponent m_BackendImageComp;
62  protected Widget m_wBackgroundImageBackend;
63 
64  ref ScriptInvoker m_OnFavorites = new ScriptInvoker();
65 
66  static Room s_Room;
67 
68  protected float m_fVersionAlertIconPaddingLeft;
69 
70  protected const ResourceName ADDON_LINE_LAYOUT_SERVER_BROWSER = "{3BC78F295971FD3D}UI/layouts/Menus/ContentBrowser/DownloadManager/DownloadManager_AddonDownloadLineConfirmation_ServerBrowser.layout";
71  protected const string STR_VERSION_MISMATCH = "#AR-ServerBrowser_JoinModVersionMissmatch";
72  protected const string ICON_VERSION_MISMATCH = "warning";
73 
74  protected const string STR_HIGH_PING = "#AR-ServerBrowser_HighPingWarning_Title";
75  protected const string STR_HIGH_PING_ICON = "ping-low";
76  protected const string STR_HIGH_PING_ICON_SCALE = "1.75";
77 
78  //This should probably be a setting in SCR_HorizontalScrollAnimationComponent, as this is a bandaid solution to the title flickering
79  protected const int MAX_TITLE_LENGTH = 55;
80 
81  //------------------------------------------------------------------------------------------------
82  // Override
83  //------------------------------------------------------------------------------------------------
84 
85  //------------------------------------------------------------------------------------------------
86  override protected void InitWidgets()
87  {
88  super.InitWidgets();
89 
90  m_wScroll = m_wRoot.FindAnyWidget(WIDGET_SCROLL);
91  m_wAddonList = m_wRoot.FindAnyWidget(WIDGET_ADDON_LIST);
92  m_wLoading = m_wRoot.FindAnyWidget(WIDGET_LOADING);
93  m_wModsSizeLayout = m_wRoot.FindAnyWidget(WIDGET_MODS_SIZE_LAYOUT);
94  m_wDetailIconsLayout = m_wRoot.FindAnyWidget(WIDGET_DETAIL_ICONS_LAYOUT);
95  m_wModsSizeToDownloadLayout = m_wRoot.FindAnyWidget(WIDGET_MODS_SIZE_TO_DOWNLOAD_LAYOUT);
96  m_wAlertWrapper = m_wRoot.FindAnyWidget(WIDGET_ALERT_WRAPPER);
97 
98  m_wIPAddressText = RichTextWidget.Cast(m_wRoot.FindAnyWidget(WIDGET_IPADDRESS_TEXT));
99  m_wDiscordText = RichTextWidget.Cast(m_wRoot.FindAnyWidget(WIDGET_DISCORD_TEXT));
100  m_wModsNumberText = RichTextWidget.Cast(m_wRoot.FindAnyWidget(WIDGET_MODS_NUMBER_TEXT));
101  m_wModsSizeText = RichTextWidget.Cast(m_wRoot.FindAnyWidget(WIDGET_MODS_SIZE_TEXT));
102  m_wAlertText = RichTextWidget.Cast(m_wRoot.FindAnyWidget(WIDGET_ALERT_TEXT));
103  m_wModsSizeToDownloadText = RichTextWidget.Cast(m_wRoot.FindAnyWidget(WIDGET_MODS_SIZE_TO_DOWNLOAD_TEXT));
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  override protected void Init(Widget root, SCR_ConfigurableDialogUiPreset preset, MenuBase proxyMenu)
108  {
109  super.Init(root, preset, proxyMenu);
110 
111  m_NavConfirm = SCR_InputButtonComponent.Cast(root.FindAnyWidget(BTN_CONFIRM).FindHandler(SCR_InputButtonComponent));
112  if (m_NavConfirm)
113  BindButtonConfirm(m_NavConfirm);
114 
115  m_NavFavorites = FindButton(BTN_FAVORITES);
116 
117  m_BtnFavorites = SCR_ModularButtonComponent.FindComponent(root.FindAnyWidget(BTN_FAVORITES_STAR));
118 
119  if (m_NavFavorites)
120  m_NavFavorites.m_OnActivated.Insert(OnFavorites);
121 
122  if (m_BtnFavorites)
123  m_BtnFavorites.m_OnClicked.Insert(OnFavorites);
124 
125  m_BtnCopyIPAddress = SCR_ButtonComponent.Cast(root.FindAnyWidget(BTN_COPY_IPADDRESS).FindHandler(SCR_ButtonComponent));
126 
127  if (m_BtnCopyIPAddress)
128  m_BtnCopyIPAddress.m_OnClicked.Insert(OnCopyIPAddress);
129 
130  m_BtnDiscord = SCR_ButtonComponent.Cast(root.FindAnyWidget(BTN_DISCORD).FindHandler(SCR_ButtonComponent));
131 
132  if (m_BtnDiscord)
133  m_BtnDiscord.m_OnClicked.Insert(OnDiscord);
134 
135  m_wBackgroundImageBackend = GetRootWidget().FindAnyWidget("BackgroundImageBackend");
136  if (m_wBackgroundImageBackend)
137  m_BackendImageComp = SCR_ScenarioBackendImageComponent.Cast(m_wBackgroundImageBackend.FindHandler(SCR_ScenarioBackendImageComponent));
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
142  {
143  // Set visibility
144  m_wScroll.SetVisible(false);
145  m_wLoading.SetVisible(true);
146 
147  m_wModsSizeLayout.SetVisible(false);
148  m_wModsSizeToDownloadLayout.SetVisible(false);
149 
151  if (!s_Room)
152  return;
153 
154  SetScenarioImage(s_Room.HostScenario());
155  }
156 
157  //------------------------------------------------------------------------------------------------
158  override void SetTitle(string text)
159  {
160  super.SetTitle(text);
161 
162  Widget titleFrame = m_wRoot.FindAnyWidget(WIDGET_TITLEFRAME);
163  if (!titleFrame)
164  return;
165 
167  if (!scrollComp)
168  return;
169 
170  if (text.Length() < MAX_TITLE_LENGTH)
171  scrollComp.AnimationStop();
172  else
173  scrollComp.AnimationStart();
174  }
175 
176  //------------------------------------------------------------------------------------------------
177  // Public
178  //------------------------------------------------------------------------------------------------
179 
180  //------------------------------------------------------------------------------------------------
181  static SCR_ServerDetailsDialog CreateServerDetailsDialog(Room room, array<ref SCR_WorkshopItem> items, string preset, ResourceName dialogsConfig = "", ScriptInvokerVoid onFavoritesResponse = null)
182  {
183  if (dialogsConfig == "")
184  dialogsConfig = SCR_WorkshopUiCommon.DIALOGS_CONFIG;
185 
186  s_Room = room;
187 
188  SCR_ServerDetailsDialog dialog = new SCR_ServerDetailsDialog(items, "");
189  SCR_ConfigurableDialogUi.CreateFromPreset(dialogsConfig, preset, dialog);
190 
191  dialog.SetTitle(room.Name());
192  dialog.SetIPAddressText("#AR-ServerBrowser_IP: " + room.HostAddress());
193  //dialog.SetDiscordText();
194 
196  if (onFavoritesResponse)
197  onFavoritesResponse.Insert(dialog.OnRoomSetFavoriteResponseDialog);
198 
199  dialog.DisplayFavoriteAction(s_Room.IsFavorite());
200  dialog.UpdateDetailIcons();
201  dialog.UpdateAlertMessage();
202 
203  return dialog;
204  }
205 
206  //------------------------------------------------------------------------------------------------
207  void FillModList(array<ref SCR_WorkshopItem> items, SCR_RoomModsManager modsManager)
208  {
209  m_aItems = items;
210 
211  // Set visibility
212  m_wLoading.SetVisible(false);
213 
214  if (m_aItems.IsEmpty())
215  return;
216 
217  //------------------------------------------------------------------------------------------------
218  // The items must be sorted by size and placed in the following order: Missing, needs download -> Downloaded, needs update -> Downloaded
219  array<SCR_WorkshopItem> itemsSorted = {};
220 
221  array<SCR_WorkshopItem> itemsToUpdate = {};
222  array<SCR_WorkshopItem> itemsToDownload = {};
223  array<SCR_WorkshopItem> itemsDownloaded = {};
224  array<SCR_WorkshopItem> itemsOrdered = {};
225 
226  foreach (SCR_WorkshopItem item : m_aItems)
227  {
228  itemsSorted.Insert(item);
229  }
230 
231  SCR_Sorting<SCR_WorkshopItem, SCR_CompareWorkshopItemTargetSize>.HeapSort(itemsSorted, true);
232 
233  // Split the items based on their state
234  Revision versionFrom;
235  Revision versionTo;
236  foreach (SCR_WorkshopItem item : itemsSorted)
237  {
238  versionFrom = item.GetCurrentLocalRevision();
239  versionTo = item.GetItemTargetRevision();
240 
241  if (!item.GetOffline()) //Missing, needs download
242  itemsToDownload.Insert(item);
243 
244  else if (versionFrom && !Revision.AreEqual(versionFrom, versionTo)) //Downloaded, needs update
245  itemsToUpdate.Insert(item);
246 
247  else //Downloaded
248  itemsDownloaded.Insert(item);
249  }
250 
251  // Create the ordered array
252  itemsOrdered.InsertAll(itemsToDownload);
253  itemsOrdered.InsertAll(itemsToUpdate);
254  itemsOrdered.InsertAll(itemsDownloaded);
255  //------------------------------------------------------------------------------------------------
256 
257  // Setup downloaded
258  foreach (SCR_WorkshopItem item : itemsOrdered)
259  {
260  Widget w = GetGame().GetWorkspace().CreateWidgets(ADDON_LINE_LAYOUT_SERVER_BROWSER, m_wAddonList);
261 
262  if (item == itemsOrdered[itemsOrdered.Count() - 1])
263  AlignableSlot.SetPadding(w, 0, 0, 0, 0);
264 
266  comp.InitForServerBrowser(item, item.GetItemTargetRevision(), true);
267 
268  m_aDownloadLines.Insert(comp);
269  }
270 
271  m_wScroll.SetVisible(true);
272  UpdateModsAmountMessages(modsManager);
273  }
274 
275  //------------------------------------------------------------------------------------------------
276  void SetScenarioImage(MissionWorkshopItem scenario)
277  {
278  if (!m_BackendImageComp)
279  return;
280 
281  if (scenario)
282  m_BackendImageComp.SetScenarioAndImage(scenario, scenario.Thumbnail());
283  else
284  m_BackendImageComp.SetScenarioAndImage(null, null);
285  }
286 
287  //------------------------------------------------------------------------------------------------
288  void SetCanJoin(bool canJoin)
289  {
290  if (!m_NavConfirm)
291  return;
292 
293  m_NavConfirm.SetEnabled(canJoin, false);
294  }
295 
296  //------------------------------------------------------------------------------------------------
297  protected void OnFavorites()
298  {
299  m_OnFavorites.Invoke();
300  }
301 
302  //------------------------------------------------------------------------------------------------
303  protected void DisplayFavoriteAction(bool isFavorite)
304  {
305  if (m_NavFavorites)
306  {
307  if (isFavorite)
308  m_NavFavorites.SetLabel(UIConstants.FAVORITE_LABEL_REMOVE);
309  else
310  m_NavFavorites.SetLabel(UIConstants.FAVORITE_LABEL_ADD);
311  }
312 
313  // Star Button
314  if (m_BtnFavorites)
315  m_BtnFavorites.SetToggled(isFavorite, false);
316  }
317 
318  //------------------------------------------------------------------------------------------------
319  protected void OnRoomSetFavoriteResponseDialog()
320  {
321  DisplayFavoriteAction(s_Room.IsFavorite());
322  }
323 
324  //------------------------------------------------------------------------------------------------
325  protected void OnCopyIPAddress()
326  {
327  System.ExportToClipboard(s_Room.HostAddress());
328  }
329 
330  //------------------------------------------------------------------------------------------------
331  protected void OnDiscord()
332  {
333  //TODO once we introduce the ability for the users to give a discord link on server creation
334  }
335 
336  //------------------------------------------------------------------------------------------------
337  protected void SetIPAddressText(string text)
338  {
339  if (m_wIPAddressText)
340  m_wIPAddressText.SetText(text);
341  }
342 
343  //------------------------------------------------------------------------------------------------
344  protected void SetDiscordText(string text)
345  {
346  if (m_wDiscordText)
347  m_wDiscordText.SetText(text);
348  }
349 
350  //------------------------------------------------------------------------------------------------
351  protected void UpdateModsAmountMessages(SCR_RoomModsManager modsManager = null)
352  {
353  if (m_aItems.IsEmpty())
354  return;
355 
356  m_wModsSizeLayout.SetVisible(true);
357 
358  float totalSize;
359  foreach (ref SCR_WorkshopItem item : m_aItems)
360  {
361  totalSize += item.GetSizeBytes();
362  }
363 
364  if (m_wModsNumberText)
365  m_wModsNumberText.SetTextFormat(m_aItems.Count().ToString());
366 
367  if (m_wModsSizeText)
368  m_wModsSizeText.SetText(SCR_ByteFormat.GetReadableSize(totalSize));
369 
370  // Check mods to update size
371  if (!modsManager)
372  return;
373 
374  array<ref SCR_WorkshopItem> toUpdateMods = modsManager.GetRoomItemsToUpdate();
375 
376  // Display size to update
377  if (m_wModsSizeToDownloadLayout)
378  m_wModsSizeToDownloadLayout.SetVisible(!toUpdateMods.IsEmpty());
379 
380  if (m_wModsSizeToDownloadText)
381  {
382  string toUpdateSize = modsManager.GetModListPatchSizeString(toUpdateMods);
383  m_wModsSizeToDownloadText.SetText(toUpdateSize);
384  }
385  }
386 
387  //------------------------------------------------------------------------------------------------
388  protected void UpdateDetailIcons()
389  {
390  if (!s_Room || !m_wDetailIconsLayout)
391  return;
392 
393  bool isModded = s_Room.IsModded();
394 
395  // Versions mismatch
396  bool wrongVersion = s_Room.GameVersion() != GetGame().GetBuildVersion();
397  bool restrictedUGC = isModded && !SCR_AddonManager.GetInstance().GetUgcPrivilege();
398 
399  //m_wDetailIconsLayout.FindWidget(IMG_WRONG_VERSION).SetVisible(wrongVersion || restrictedUGC);
400  m_wDetailIconsLayout.FindWidget(IMG_WRONG_VERSION).SetVisible(false);
401 
402  // Locked with password
403  m_wDetailIconsLayout.FindWidget(IMG_PASSWORD_PROTECTED).SetVisible(s_Room.PasswordProtected());
404 
405  // Crossplay
406  m_wDetailIconsLayout.FindWidget(IMG_CROSS_PLATFORM).SetVisible(s_Room.IsCrossPlatform());
407 
408  // Moded
409  //m_wDetailIconsLayout.FindWidget(IMG_MODDED).SetVisible(isModded);
410  m_wDetailIconsLayout.FindWidget(IMG_MODDED).SetVisible(false);
411  }
412 
413 
414  //------------------------------------------------------------------------------------------------
415  protected void UpdateAlertMessage()
416  {
417  if (!s_Room || !m_wAlertText || !m_wAlertWrapper || !m_NavConfirm)
418  return;
419 
420  bool versionMismatch = s_Room.GameVersion() != GetGame().GetBuildVersion();
421  bool highPing = ServerBrowserMenuUI.IsServerPingAboveThreshold(s_Room);
422  bool showMessage = versionMismatch || highPing;
423 
424  m_wAlertWrapper.SetVisible(showMessage);
425  m_NavConfirm.ResetTexture();
426 
427  if (!showMessage)
428  return;
429 
430  if (versionMismatch)
431  {
432  m_wAlertText.SetText(s_Room.GameVersion() + " - " + STR_VERSION_MISMATCH);
433  m_NavConfirm.SetTexture(UIConstants.ICONS_IMAGE_SET, ICON_VERSION_MISMATCH, Color.FromInt(UIColors.WARNING.PackToInt()));
434  }
435  else
436  {
437  string icon = string.Format("<image set='%1' name='%2' scale='%3'/>", UIConstants.ICONS_IMAGE_SET, STR_HIGH_PING_ICON, STR_HIGH_PING_ICON_SCALE);
438  m_wAlertText.SetText(icon + " " + STR_HIGH_PING + " ");
439  }
440  }
441 }
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
SCR_WorkshopItem
Definition: SCR_WorkshopItem.c:21
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
SCR_ButtonComponent
Deprecated button component. Still used in many prefabs, so it works, it's just stripped of most of t...
Definition: SCR_ButtonComponent.c:4
UIColors
Definition: Constants.c:16
SCR_ByteFormat
Definition: SCR_ByteFormat.c:5
SCR_ConfigurableDialogUiPreset
Configuration for a dialog.
Definition: SCR_ConfigurableDialogUI.c:809
SCR_ServerDetailsDialog
Definition: SCR_ServerDetailsDialog.c:7
MAX_TITLE_LENGTH
const protected int MAX_TITLE_LENGTH
Definition: SCR_ScenarioDialogs.c:47
ScriptInvokerVoid
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition: SCR_ScriptInvokerHelper.c:9
SCR_RoomModsManager
Definition: SCR_RoomModsManager.c:27
SCR_ConfigurableDialogUi
Definition: SCR_ConfigurableDialogUI.c:13
SCR_AddonManager
Definition: SCR_AddonManager.c:72
SCR_WorkshopUiCommon
Definition: SCR_WorkshopUiCommon.c:5
SCR_AddonListDialog
Shows a list of addons and some text.
Definition: SCR_WorkshopUiCommon.c:820
m_wLoading
protected Widget m_wLoading
Definition: SCR_ServerBrowserEntryComponent.c:40
FindButton
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
Definition: SCR_BrowserHoverTooltipComponent.c:116
SCR_DownloadManager_AddonDownloadLine
Definition: SCR_DownloadManager_AddonDownloadLine.c:5
ServerBrowserMenuUI
Definition: ServerBrowserMenuUI.c:10
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1