Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ServerDetailsDialog.c
Go to the documentation of this file.
1
6
8{
9 protected const string WIDGET_SCROLL = "ScrollSize";
10 protected const string WIDGET_ADDON_LIST = "AddonList";
11
12 protected const string WIDGET_IPADDRESS_TEXT = "IPAddressText";
13 protected const string WIDGET_DISCORD_TEXT = "DiscordText";
14 protected const string WIDGET_MODS_NUMBER_TEXT = "ModsNumberText";
15 protected const string WIDGET_MODS_SIZE_TEXT = "ModsSizeAmount";
16 protected const string WIDGET_ALERT_TEXT = "AlertText";
17 protected const string WIDGET_ALERT_WRAPPER = "AlertOverlay"; //TODO: move alerts handling to a specific component on the button itself
18 protected const string WIDGET_MODS_SIZE_TO_DOWNLOAD_TEXT = "ModsSizeToDownload";
19
20 protected const string WIDGET_MODS_SIZE_LAYOUT = "ModsSizeLayout";
21 protected const string WIDGET_DETAIL_ICONS_LAYOUT = "DetailIconsLayout";
22 protected const string WIDGET_MODS_SIZE_TO_DOWNLOAD_LAYOUT = "ModsSizeToDownloadLayout";
23
24 protected const string IMG_WRONG_VERSION = "DetailIcon_WrongVersion";
25 protected const string IMG_PASSWORD_PROTECTED = "Detailicon_PasswordProtected";
26 protected const string IMG_CROSS_PLATFORM = "DetailIcon_CrossPlatform";
27 protected const string IMG_MODDED = "DetailIcon_Modded";
28 protected const string IMG_VERSION_ALERT = "VersionAlertIconButton";
29
30 protected const string BTN_CONFIRM = "Confirm";
31 protected const string BTN_FAVORITES = "favorites";
32 protected const string BTN_FAVORITES_STAR = "FavoriteButton";
33 protected const string BTN_COPY_IPADDRESS = "IPAddressButton";
34 protected const string BTN_DISCORD = "DiscordButton";
35
36 protected Widget m_wScroll;
43
50
53
54 protected SCR_ModularButtonComponent m_BtnFavorites;
57
60
62
63 static Room s_Room;
64
66
67 protected const ResourceName ADDON_LINE_LAYOUT_SERVER_BROWSER = "{3BC78F295971FD3D}UI/layouts/Menus/ContentBrowser/DownloadManager/DownloadManager_AddonDownloadLineConfirmation_ServerBrowser.layout";
68 protected const string STR_VERSION_MISMATCH = "#AR-ServerBrowser_JoinModVersionMissmatch";
69
70 protected const string STR_HIGH_PING = "#AR-ServerBrowser_HighPingWarning_Title";
71 protected const string STR_HIGH_PING_ICON = "ping-low";
72
73 //------------------------------------------------------------------------------------------------
74 // Override
75 //------------------------------------------------------------------------------------------------
76
77 //------------------------------------------------------------------------------------------------
96
97 //------------------------------------------------------------------------------------------------
98 override protected void Init(Widget root, SCR_ConfigurableDialogUiPreset preset, MenuBase proxyMenu)
99 {
100 super.Init(root, preset, proxyMenu);
101
102 m_NavConfirm = SCR_InputButtonComponent.Cast(root.FindAnyWidget(BTN_CONFIRM).FindHandler(SCR_InputButtonComponent));
103 if (m_NavConfirm)
105
107
108 m_BtnFavorites = SCR_ModularButtonComponent.FindComponent(root.FindAnyWidget(BTN_FAVORITES_STAR));
109
110 if (m_NavFavorites)
111 m_NavFavorites.m_OnActivated.Insert(OnFavorites);
112
113 if (m_BtnFavorites)
114 m_BtnFavorites.m_OnClicked.Insert(OnFavorites);
115
116 m_BtnCopyIPAddress = SCR_ButtonComponent.Cast(root.FindAnyWidget(BTN_COPY_IPADDRESS).FindHandler(SCR_ButtonComponent));
117
119 m_BtnCopyIPAddress.m_OnClicked.Insert(OnCopyIPAddress);
120
121 m_BtnDiscord = SCR_ButtonComponent.Cast(root.FindAnyWidget(BTN_DISCORD).FindHandler(SCR_ButtonComponent));
122
123 if (m_BtnDiscord)
124 m_BtnDiscord.m_OnClicked.Insert(OnDiscord);
125
126 m_wBackgroundImageBackend = GetRootWidget().FindAnyWidget("BackgroundImageBackend");
129 }
130
131 //------------------------------------------------------------------------------------------------
133 {
134 // Set visibility
135 m_wScroll.SetVisible(false);
136
137 m_wModsSizeLayout.SetVisible(false);
138 m_wModsSizeToDownloadLayout.SetVisible(false);
139
141 if (!s_Room)
142 return;
143
144 SetScenarioImage(s_Room.HostScenario());
145 }
146
147 //------------------------------------------------------------------------------------------------
148 // Public
149 //------------------------------------------------------------------------------------------------
150
151 //------------------------------------------------------------------------------------------------
152 static SCR_ServerDetailsDialog CreateServerDetailsDialog(Room room, array<ref SCR_WorkshopItem> items, string preset, ResourceName dialogsConfig = "", ScriptInvokerVoid onFavoritesResponse = null)
153 {
154 if (dialogsConfig == "")
155 dialogsConfig = SCR_WorkshopDialogs.DIALOGS_CONFIG;
156
157 s_Room = room;
158
159 SCR_ServerDetailsDialog dialog = new SCR_ServerDetailsDialog(items, "");
160 SCR_ConfigurableDialogUi.CreateFromPreset(dialogsConfig, preset, dialog);
161
162 dialog.SetTitle(room.Name());
163 dialog.SetIPAddressText(SCR_WorkshopUiCommon.LABEL_IP_ADDRESS + " " + room.HostAddress());
164 //dialog.SetDiscordText();
165
167 if (onFavoritesResponse)
168 onFavoritesResponse.Insert(dialog.OnRoomSetFavoriteResponseDialog);
169
170 dialog.DisplayFavoriteAction(s_Room.IsFavorite());
171 dialog.UpdateDetailIcons();
172 dialog.UpdateAlertMessage();
173
174 return dialog;
175 }
176
177 //------------------------------------------------------------------------------------------------
178 void FillModList(array<ref SCR_WorkshopItem> items, SCR_RoomModsManager modsManager)
179 {
180 m_aItems = items;
181
182 if (m_aItems.IsEmpty())
183 return;
184
185 //------------------------------------------------------------------------------------------------
186 // The items must be sorted by size and placed in the following order: Missing, needs download -> Downloaded, needs update -> Downloaded
187 array<SCR_WorkshopItem> itemsSorted = {};
188
189 array<SCR_WorkshopItem> itemsToUpdate = {};
190 array<SCR_WorkshopItem> itemsToDownload = {};
191 array<SCR_WorkshopItem> itemsDownloaded = {};
192 array<SCR_WorkshopItem> itemsOrdered = {};
193
194 foreach (SCR_WorkshopItem item : m_aItems)
195 {
196 itemsSorted.Insert(item);
197 }
198
199 SCR_Sorting<SCR_WorkshopItem, SCR_CompareWorkshopItemTargetSize>.HeapSort(itemsSorted, true);
200
201 // Split the items based on their state
202 Revision versionFrom;
203 Revision versionTo;
204 foreach (SCR_WorkshopItem item : itemsSorted)
205 {
206 versionFrom = item.GetCurrentLocalRevision();
207 versionTo = item.GetItemTargetRevision();
208
209 if (!item.GetOffline()) //Missing, needs download
210 itemsToDownload.Insert(item);
211
212 else if (versionFrom && !Revision.AreEqual(versionFrom, versionTo)) //Downloaded, needs update
213 itemsToUpdate.Insert(item);
214
215 else //Downloaded
216 itemsDownloaded.Insert(item);
217 }
218
219 // Create the ordered array
220 itemsOrdered.InsertAll(itemsToDownload);
221 itemsOrdered.InsertAll(itemsToUpdate);
222 itemsOrdered.InsertAll(itemsDownloaded);
223 //------------------------------------------------------------------------------------------------
224
225 // Setup downloaded
226 foreach (SCR_WorkshopItem item : itemsOrdered)
227 {
228 Widget w = GetGame().GetWorkspace().CreateWidgets(ADDON_LINE_LAYOUT_SERVER_BROWSER, m_wAddonList);
229
230 if (item == itemsOrdered[itemsOrdered.Count() - 1])
231 AlignableSlot.SetPadding(w, 0, 0, 0, 0);
232
234 comp.InitForServerBrowser(item, item.GetItemTargetRevision(), true);
235
236 m_aDownloadLines.Insert(comp);
237 }
238
239 m_wScroll.SetVisible(true);
240 UpdateModsAmountMessages(modsManager);
241 }
242
243 //------------------------------------------------------------------------------------------------
245 {
247 return;
248
249 if (scenario)
250 m_BackendImageComp.SetImage(scenario.Thumbnail());
251 else
252 m_BackendImageComp.SetImage(null);
253 }
254
255 //------------------------------------------------------------------------------------------------
256 void SetCanJoin(bool canJoin)
257 {
258 if (!m_NavConfirm)
259 return;
260
261 m_NavConfirm.SetEnabled(canJoin, false);
262 }
263
264 //------------------------------------------------------------------------------------------------
265 protected void OnFavorites()
266 {
267 m_OnFavorites.Invoke();
268 }
269
270 //------------------------------------------------------------------------------------------------
271 protected void DisplayFavoriteAction(bool isFavorite)
272 {
273 if (m_NavFavorites)
274 m_NavFavorites.SetLabel(UIConstants.GetFavoriteLabel(isFavorite));
275
276 // Star Button
277 if (m_BtnFavorites)
278 m_BtnFavorites.SetToggled(isFavorite, false);
279 }
280
281 //------------------------------------------------------------------------------------------------
283 {
284 DisplayFavoriteAction(s_Room.IsFavorite());
285 }
286
287 //------------------------------------------------------------------------------------------------
288 protected void OnCopyIPAddress()
289 {
290 System.ExportToClipboard(s_Room.HostAddress());
291 }
292
293 //------------------------------------------------------------------------------------------------
294 protected void OnDiscord()
295 {
296 //TODO once we introduce the ability for the users to give a discord link on server creation
297 }
298
299 //------------------------------------------------------------------------------------------------
300 protected void SetIPAddressText(string text)
301 {
303 m_wIPAddressText.SetText(text);
304 }
305
306 //------------------------------------------------------------------------------------------------
307 protected void SetDiscordText(string text)
308 {
309 if (m_wDiscordText)
310 m_wDiscordText.SetText(text);
311 }
312
313 //------------------------------------------------------------------------------------------------
314 protected void UpdateModsAmountMessages(SCR_RoomModsManager modsManager = null)
315 {
316 if (m_aItems.IsEmpty())
317 return;
318
319 m_wModsSizeLayout.SetVisible(true);
320
321 float totalSize;
322 foreach (ref SCR_WorkshopItem item : m_aItems)
323 {
324 totalSize += item.GetSizeBytes();
325 }
326
328 m_wModsNumberText.SetTextFormat(m_aItems.Count().ToString());
329
330 if (m_wModsSizeText)
331 m_wModsSizeText.SetText(SCR_ByteFormat.GetReadableSize(totalSize));
332
333 // Check mods to update size
334 if (!modsManager)
335 return;
336
337 array<ref SCR_WorkshopItem> toUpdateMods = modsManager.GetRoomItemsToUpdate();
338
339 // Display size to update
341 m_wModsSizeToDownloadLayout.SetVisible(!toUpdateMods.IsEmpty());
342
344 {
345 string toUpdateSize = modsManager.GetModListPatchSizeString(toUpdateMods);
346 m_wModsSizeToDownloadText.SetText(toUpdateSize);
347 }
348 }
349
350 //------------------------------------------------------------------------------------------------
351 protected void UpdateDetailIcons()
352 {
354 return;
355
356 bool isModded = s_Room.IsModded();
357
358 // Versions mismatch
359 bool wrongVersion = s_Room.GameVersion() != GetGame().GetBuildVersion();
360 bool restrictedUGC = isModded && !SCR_AddonManager.GetInstance().GetUgcPrivilege();
361
362 //m_wDetailIconsLayout.FindWidget(IMG_WRONG_VERSION).SetVisible(wrongVersion || restrictedUGC);
363 m_wDetailIconsLayout.FindWidget(IMG_WRONG_VERSION).SetVisible(false);
364
365 // Locked with password
366 m_wDetailIconsLayout.FindWidget(IMG_PASSWORD_PROTECTED).SetVisible(s_Room.PasswordProtected());
367
368 // Crossplay
369 m_wDetailIconsLayout.FindWidget(IMG_CROSS_PLATFORM).SetVisible(s_Room.IsCrossPlatform());
370
371 // Moded
372 //m_wDetailIconsLayout.FindWidget(IMG_MODDED).SetVisible(isModded);
373 m_wDetailIconsLayout.FindWidget(IMG_MODDED).SetVisible(false);
374 }
375
376
377 //------------------------------------------------------------------------------------------------
378 protected void UpdateAlertMessage()
379 {
381 return;
382
383 bool versionMismatch = s_Room.GameVersion() != GetGame().GetBuildVersion();
385 bool showMessage = versionMismatch || highPing;
386
387 m_wAlertWrapper.SetVisible(showMessage);
388 m_NavConfirm.ResetTexture();
389
390 if (!showMessage)
391 return;
392
393 if (versionMismatch)
394 {
395 m_wAlertText.SetText(s_Room.GameVersion() + " - " + STR_VERSION_MISMATCH);
396 m_NavConfirm.SetTexture(UIConstants.ICONS_IMAGE_SET, UIConstants.ICON_WARNING, Color.FromInt(UIColors.WARNING.PackToInt()));
397 }
398 else
399 {
400 string icon = string.Format("<image set='%1' name='%2' scale='%3'/>", UIConstants.ICONS_IMAGE_SET, STR_HIGH_PING_ICON, UIConstants.ACTION_DISPLAY_ICON_SCALE_HUGE);
401 m_wAlertText.SetText(icon + " " + STR_HIGH_PING + " ");
402 }
403 }
404}
ArmaReforgerScripted GetGame()
Definition game.c:1398
ScriptInvokerBase< ScriptInvokerVoidMethod > ScriptInvokerVoid
Definition Color.c:13
Definition Room.c:13
ref array< ref SCR_WorkshopItem > m_aItems
void SCR_AddonListDialog(array< ref SCR_WorkshopItem > items, string preset)
ref array< SCR_DownloadManager_AddonDownloadLine > m_aDownloadLines
bool GetUgcPrivilege()
Returns immediate value of UserPrivilege.USER_GEN_CONTENT.
static SCR_AddonManager GetInstance()
Deprecated button component. Still used in many prefabs, so it works, it's just stripped of most of t...
static SCR_ConfigurableDialogUi CreateFromPreset(ResourceName presetsResourceName, string tag, SCR_ConfigurableDialogUi customDialogObj=null)
Creates a dialog from preset.
void BindButtonConfirm(SCR_InputButtonComponent button)
Allows to register a custom button to call OnConfirm (i.e. one not in the conf files but placed by ha...
SCR_InputButtonComponent FindButton(string tag)
Returns a button with given tag.
void InitForServerBrowser(SCR_WorkshopItem item, Revision overrideTargetVersion=null, bool showVersionAndSize=true)
Initializes the line in non-interactive mode, shows basic data about a download.
Same as SCR_BackendImageComponent, but implements default image based on scenario.
void Init(Widget root, SCR_ConfigurableDialogUiPreset preset, MenuBase proxyMenu)
SCR_ScenarioBackendImageComponent m_BackendImageComp
void FillModList(array< ref SCR_WorkshopItem > items, SCR_RoomModsManager modsManager)
SCR_ModularButtonComponent m_BtnFavorites
void UpdateModsAmountMessages(SCR_RoomModsManager modsManager=null)
SCR_ButtonComponent m_BtnCopyIPAddress
override void OnMenuOpen(SCR_ConfigurableDialogUiPreset preset)
static SCR_ServerDetailsDialog CreateServerDetailsDialog(Room room, array< ref SCR_WorkshopItem > items, string preset, ResourceName dialogsConfig="", ScriptInvokerVoid onFavoritesResponse=null)
SCR_InputButtonComponent m_NavConfirm
void SetScenarioImage(MissionWorkshopItem scenario)
const ResourceName ADDON_LINE_LAYOUT_SERVER_BROWSER
void DisplayFavoriteAction(bool isFavorite)
SCR_InputButtonComponent m_NavFavorites
const string WIDGET_MODS_SIZE_TO_DOWNLOAD_LAYOUT
static bool IsServerPingAboveThreshold(Room room)
ScriptInvokerBase< func > ScriptInvoker
Definition tools.c:134