Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ServerBrowserEntryComponent.c
Go to the documentation of this file.
3{
4 // Attributes
5 [Attribute("999")]
6 protected int m_iPingLimit;
7
8 [Attribute(SCR_WorkshopUiCommon.ICON_DOWNLOAD)]
9 protected string m_sTooltipDownloadIcon;
10
11 [Attribute(UIConstants.ACTION_DISPLAY_ICON_SCALE_HUGE)]
13
14 [Attribute("", UIWidgets.Object)]
15 protected ref array<ref ServerBrowserEntryProperty> m_aPingStates;
16
17 // Const
18 protected const string LAYOUT_CONTENT = "HorizontalLayout";
19 protected const string LAYOUT_LOADING = "Loading";
20
21 protected const string TEXT_WIDGET_QUEUE = "Queue";
22
23 protected const string BUTTON_JOIN = "JoinButton";
24 protected const string BUTTON_PASSWORD = "PasswordButton";
25
26 protected const string ICON_WARNING = "VersionWarningIcon";
27 protected const string ICON_UNJOINABLE = "JoinWarningIcon";
28 protected const string ICON_MODDED = "ImageModded";
29 protected const string ICON_PING = "ImgPing";
30
31 protected const string FRAME_NAME = "FrameName";
32 protected const string FRAME_SCENARIO = "FrameScenario";
33
34 protected const string TOOLTIP_JOIN = "Join";
35 protected const string TOOLTIP_VERSION_MISMATCH = "VersionMismatch";
36
37 // Base
38 protected Room m_RoomInfo;
40
42 protected string m_sPatchSize;
43 protected bool m_bIsPatchSizeLoaded;
44 protected int m_iHighestPing;
45
46 // Widgets
49 protected Widget m_wLoading;
56
57 protected SCR_ModularButtonComponent m_JoinButton;
58 protected SCR_ModularButtonComponent m_PasswordButton;
59
60 //------------------------------------------------------------------------------------------------
61 // Override
62 //------------------------------------------------------------------------------------------------
63
64 //------------------------------------------------------------------------------------------------
65 override void HandlerAttached(Widget w)
66 {
67 if (!GetGame().InPlayMode())
68 return;
69
70 // Get wrappers
71 m_wHorizontalContent = w.FindAnyWidget(LAYOUT_CONTENT);
72 m_wLoading = w.FindAnyWidget(LAYOUT_LOADING);
73
74 // Setup favorite button
75 m_wVersionWarningIcon = w.FindAnyWidget(ICON_WARNING);
76 m_wUnjoinableIcon = w.FindAnyWidget(ICON_UNJOINABLE);
77
78 // Property images and buttons
79 m_wImageModded = w.FindAnyWidget(ICON_MODDED);
80 m_wJoinButton = w.FindAnyWidget(BUTTON_JOIN);
81 m_wPasswordButton = w.FindAnyWidget(BUTTON_PASSWORD);
82
83 // Mouse interaction buttons
84 m_JoinButton = SCR_ModularButtonComponent.FindComponent(m_wJoinButton);
85 if (m_JoinButton)
86 {
89 }
90
91 m_PasswordButton = SCR_ModularButtonComponent.FindComponent(m_wPasswordButton);
93 {
96 }
97
98 // Ping
99 m_wImgPing = ImageWidget.Cast(w.FindAnyWidget(ICON_PING));
100
101 // Name
102 SCR_HorizontalScrollAnimationComponent scrollComp;
103 Widget frameName = w.FindAnyWidget(FRAME_NAME);
104 if (frameName)
105 {
106 scrollComp = SCR_HorizontalScrollAnimationComponent.Cast(frameName.FindHandler(SCR_HorizontalScrollAnimationComponent));
107 if (scrollComp)
108 m_aScrollAnimations.Insert(scrollComp);
109 }
110
111 // Scenario
112 Widget frameScenario = w.FindAnyWidget(FRAME_SCENARIO);
113 if (frameScenario)
114 {
115 scrollComp = SCR_HorizontalScrollAnimationComponent.Cast(frameScenario.FindHandler(SCR_HorizontalScrollAnimationComponent));
116 if (scrollComp)
117 m_aScrollAnimations.Insert(scrollComp);
118 }
119
120 // Loading
121 m_wLoading.SetVisible(false);
122
123 // Get highest ping
124 foreach (ServerBrowserEntryProperty pingState : m_aPingStates)
125 {
126 int ping = pingState.m_sValue.ToInt();
127 if (m_iHighestPing < ping)
128 m_iHighestPing = ping;
129 }
130
131 // Queue
132 m_wQueue = TextWidget.Cast(w.FindAnyWidget(TEXT_WIDGET_QUEUE));
133
134 super.HandlerAttached(w);
135 }
136
137 //------------------------------------------------------------------------------------------------
139 {
140 super.OnTooltipShow(tooltip);
141
143 if (!content)
144 return;
145
146 string message = content.GetDefaultMessage();
147
148 switch (tooltip.GetTag())
149 {
152 if (comp && m_RoomInfo)
153 comp.SetWrongVersionMessage(m_RoomInfo.GameVersion());
154 break;
155
156 case TOOLTIP_JOIN:
158 message = string.Format(message, GetDownloadSizeMessage());
159
160 content.SetMessage(message);
161 break;
162 }
163 }
164
165 //------------------------------------------------------------------------------------------------
166 override void UpdateModularButtons()
167 {
168 // Password and Play buttons
169 if (m_wJoinButton)
170 m_wJoinButton.SetVisible(m_bFocused && !(m_iProperties & SCR_EServerEntryProperty.PASSWORD_PROTECTED) && !(m_iProperties & SCR_EServerEntryProperty.UNJOINABLE));
171
174
175 super.UpdateModularButtons();
176 }
177
178 //------------------------------------------------------------------------------------------------
179 override bool OnFocus(Widget w, int x, int y)
180 {
181 bool result = super.OnFocus(w, x, y);
182
183 DisplayQueue();
184
185 return result;
186 }
187
188 //------------------------------------------------------------------------------------------------
189 override bool OnFocusLost(Widget w, int x, int y)
190 {
191 bool result = super.OnFocusLost(w, x, y);
192
193 if (m_ModsManager)
194 {
195 m_ModsManager.GetOnGetAllDependencies().Remove(OnServerDetailModsLoaded);
196 m_bIsPatchSizeLoaded = false;
197 }
198
199 DisplayQueue();
200
201 return result;
202 }
203
204 //------------------------------------------------------------------------------------------------
205 // Protected
206 //------------------------------------------------------------------------------------------------
207
208 //------------------------------------------------------------------------------------------------
214
215 //------------------------------------------------------------------------------------------------
219 protected void SetCellText(string cellName, string str, string widgetName = "Content")
220 {
221 Widget wCell = m_wRoot.FindAnyWidget(cellName);
222 if (!wCell)
223 return;
224
225 TextWidget wText = TextWidget.Cast(wCell.FindAnyWidget(widgetName));
226 if (wText)
227 wText.SetText(str);
228 }
229
230 //------------------------------------------------------------------------------------------------
233 protected void DisplayPing(int ping)
234 {
235 //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
236
237 float lastHighest = m_iHighestPing + 1;
238 ServerBrowserEntryProperty displayState;
239
240 // No ping state
241 if (ping == 0)
242 {
243 if (m_wImgPing)
244 m_wImgPing.SetVisible(false);
245
246 return;
247 }
248
249 // Go through available icons
250 foreach (ServerBrowserEntryProperty pingState : m_aPingStates)
251 {
252 float pingFromStr = pingState.m_sValue.ToFloat();
253
254 // Find smallest ping
255 if (ping < pingFromStr && pingFromStr < lastHighest)
256 {
257 displayState = pingState;
258 lastHighest = pingFromStr;
259 }
260 }
261
262 // Set ping text
263 string strPing = Math.Floor(ping).ToString();
264
265 // Over limit
266 if (ping > m_iHighestPing || ping < 0)
267 displayState = m_aPingStates[m_aPingStates.Count() - 1];
268
269 if (ping > m_iPingLimit)
270 strPing = m_iPingLimit.ToString() + "#ENF-ComboModifier";
271
272 SetCellText("Ping", strPing);
273
274 // Set ping icon
275 if (displayState && m_wImgPing)
276 {
277 m_wImgPing.SetVisible(true);
278 m_wImgPing.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, displayState.m_sImageName);
279 m_wImgPing.SetColor(displayState.m_Color);
280 }
281 }
282
283 //------------------------------------------------------------------------------------------------
284 protected void DisplayQueue()
285 {
286 if (!m_wQueue || !m_RoomInfo)
287 return;
288
289 // Text
290 string queue;
291 int queueSize = m_RoomInfo.GetQueueSize();
292 if (queueSize > 0)
293 queue = string.Format("(%1)", UIConstants.FormatUnitShortPlus(queueSize));
294
295 m_wQueue.SetText(queue);
296
297 // Color
298 bool maxed = m_RoomInfo.GetQueueSize() >= m_RoomInfo.GetQueueMaxSize();
299 Color color;
300
301 if (m_bFocused)
302 {
303 if (maxed)
304 color = UIColors.CopyColor(UIColors.WARNING);
305 else
306 color = UIColors.CopyColor(UIColors.NEUTRAL_INFORMATION);
307 }
308
309 else if (m_bUnavailable)
310 {
311 if (maxed)
312 color = UIColors.CopyColor(UIColors.WARNING_DISABLED);
313 else
314 color = UIColors.CopyColor(UIColors.IDLE_DISABLED);
315 }
316
317 else
318 {
319 if (maxed)
320 color = UIColors.CopyColor(UIColors.WARNING_DISABLED);
321 else
322 color = UIColors.CopyColor(UIColors.NEUTRAL_ACTIVE_STANDBY);
323 }
324
325 m_wQueue.SetColor(color);
326 }
327
328 //------------------------------------------------------------------------------------------------
330 protected void CheckRoomProperties()
331 {
332 m_iProperties = 0;
333
334 // Client versions missmatch
335 bool wrongVersion = m_RoomInfo.GameVersion() != GetGame().GetBuildVersion();
336 bool restrictedUGC = m_RoomInfo.IsModded() && !SCR_AddonManager.GetInstance().GetUgcPrivilege();
337
338 if (wrongVersion || restrictedUGC)
339 m_iProperties |= SCR_EServerEntryProperty.VERSION_MISMATCH;
340
341 // Locked with password
342 if (m_RoomInfo.PasswordProtected())
343 m_iProperties |= SCR_EServerEntryProperty.PASSWORD_PROTECTED;
344
345 // Crossplay
346 if (m_RoomInfo.IsCrossPlatform())
347 m_iProperties |= SCR_EServerEntryProperty.CROSS_PLATFORM;
348
349 // LAN - TODO@wernerjak - add local network check
350 // m_iProperties |= SCR_EServerEntryProperty.LAN;
351
352 // MODDED
353 if (m_RoomInfo.IsModded())
355
356 // UNJOINABLE
357 if (!m_RoomInfo.Joinable())
359 }
360
361 //------------------------------------------------------------------------------------------------
363 protected void DisplayServerProperties()
364 {
365 // Check states
366 if (m_wImageModded)
368
370 m_wPasswordButton.SetVisible(m_iProperties & SCR_EServerEntryProperty.PASSWORD_PROTECTED && !(m_iProperties & SCR_EServerEntryProperty.UNJOINABLE));
371
372 // Turn favorites button into warning or unjoinable icon
374 return;
375
376 bool versionMismatch = m_iProperties & SCR_EServerEntryProperty.VERSION_MISMATCH;
377 bool unjoinable = m_iProperties & SCR_EServerEntryProperty.UNJOINABLE;
378
379 m_FavoriteButton.SetEnabled(!versionMismatch && !unjoinable);
380
381 m_wVersionWarningIcon.SetVisible(versionMismatch && !unjoinable);
382 m_wUnjoinableIcon.SetVisible(unjoinable);
383
384 m_bUnavailable = versionMismatch || unjoinable;
386 }
387
388 //------------------------------------------------------------------------------------------------
389 protected string GetDownloadSizeMessage()
390 {
391 if (!m_ModsManager || !(m_iProperties & SCR_EServerEntryProperty.MODDED) || m_sPatchSize.IsEmpty())
392 return string.Empty;
393
394 string icon = string.Format("<image set='%1' name='%2' scale='%3'/>", UIConstants.ICONS_IMAGE_SET, m_sTooltipDownloadIcon, m_fTooltipDownloadIconScale.ToString());
395 return string.Format(" [%1%2 ]", icon, m_sPatchSize);
396 }
397
398 //------------------------------------------------------------------------------------------------
399 protected void OnServerDetailModsLoaded(Room room)
400 {
402 return;
403
404 array<ref SCR_WorkshopItem> toUpdateMods = m_ModsManager.GetRoomItemsToUpdate();
405 if (!toUpdateMods.IsEmpty())
406 m_sPatchSize = m_ModsManager.GetModListPatchSizeString(toUpdateMods);
407 else
408 m_sPatchSize = string.Empty;
409
412 }
413
414 //------------------------------------------------------------------------------------------------
416 {
418 return;
419
421 if (!content)
422 return;
423
424 string message = string.Format(content.GetDefaultMessage(), GetDownloadSizeMessage());
425 content.SetMessage(message);
426 }
427
428 //------------------------------------------------------------------------------------------------
429 // Public
430 //------------------------------------------------------------------------------------------------
431
432 //------------------------------------------------------------------------------------------------
435 void SetRoomInfo(Room room)
436 {
437 m_RoomInfo = room;
438
439 // Visualize as empty?
440 if (!m_RoomInfo)
441 return;
442
443 // Setup room properties
446
447 // Name
448 SetCellText("Name", m_RoomInfo.Name());
449
450 // Scenario
451 SetCellText("Scenario", m_RoomInfo.ScenarioName());
452
453 // Player count
454 SetCellText("Players", UIConstants.FormatValueOutOf(m_RoomInfo.PlayerCount(), m_RoomInfo.PlayerLimit()));
455
456 // Queue
457 DisplayQueue();
458
459 // Favorite
461 SetFavorite(m_RoomInfo.IsFavorite());
462
463 // Ping
464 DisplayPing(room.GetPing());
465 }
466
467 //------------------------------------------------------------------------------------------------
470 void EmptyVisuals(bool enable)
471 {
472 m_wHorizontalContent.SetVisible(!enable);
473 m_wLoading.SetVisible(enable);
474 }
475
476 //------------------------------------------------------------------------------------------------
479 {
480 m_ModsManager = modsManager;
481
482 if (m_ModsManager)
483 {
484 m_ModsManager.GetOnGetAllDependencies().Insert(OnServerDetailModsLoaded);
485 m_bIsPatchSizeLoaded = false;
486 }
487 }
488
489 //------------------------------------------------------------------------------------------------
492 {
493 return m_RoomInfo;
494 }
495
496 //------------------------------------------------------------------------------------------------
499 {
501 }
502
503 //------------------------------------------------------------------------------------------------
507 bool GetIsEnabled(out bool versionMismatch, out bool unjoinable)
508 {
509 versionMismatch = m_iProperties & SCR_EServerEntryProperty.VERSION_MISMATCH;
510 unjoinable = m_iProperties & SCR_EServerEntryProperty.UNJOINABLE;
511 return !versionMismatch && !unjoinable;
512 }
513}
514
516class ServerBrowserEntryProperty
517{
518 [Attribute("1", UIWidgets.ComboBox, "", category:"Selector", ParamEnumArray.FromEnum(SCR_EServerEntryProperty))]
519 SCR_EServerEntryProperty m_iPropertyState;
520
521 [Attribute("", UIWidgets.EditBox, desc: "Image name to load")]
522 string m_sImageName;
523
524 [Attribute("", UIWidgets.EditBox, desc: "String value of property")]
525 string m_sValue;
526
527 [Attribute("1 1 1 1", UIWidgets.ColorPicker)]
528 ref Color m_Color;
529}
532{
536 LAN = 1 << 3,
537 MODDED = 1 << 4,
538 UNJOINABLE = 1 << 5,
class RestAPIHelper< JsonApiStruct T > content
ArmaReforgerScripted GetGame()
Definition game.c:1398
ref Color m_Color
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
SCR_ServerBrowserEntryComponent SCR_BrowserListMenuEntryComponent BaseContainerProps()] class ServerBrowserEntryProperty
SCR_EServerEntryProperty
@ MODDED
@ UNJOINABLE
@ VERSION_MISMATCH
@ CROSS_PLATFORM
@ LAN
@ PASSWORD_PROTECTED
Definition Color.c:13
Definition Math.c:13
Definition Room.c:13
bool GetUgcPrivilege()
Returns immediate value of UserPrivilege.USER_GEN_CONTENT.
static SCR_AddonManager GetInstance()
ref SCR_ModularButtonComponent m_FavoriteButton
bool SetFavorite(bool favorite)
bool m_bUnavailable
SCR_ScriptedWidgetTooltip m_CurrentTooltip
ref ScriptInvokerString m_OnMouseInteractionButtonClicked
bool m_bFocused
ref array< ref SCR_HorizontalScrollAnimationComponent > m_aScrollAnimations
ref array< SCR_ModularButtonComponent > m_aMouseButtons
SCR_ScriptedWidgetTooltipContentBase GetContent()
This component handles server entry and visiualization of server data.
const string TOOLTIP_JOIN
string m_sPatchSize
Widget m_wImageModded
Widget m_wLoading
const string TOOLTIP_VERSION_MISMATCH
string GetDownloadSizeMessage()
Widget m_wPasswordButton
void UpdateTooltipJoinDownloadSizeMessage()
int m_iHighestPing
void DisplayPing(int ping)
Widget m_wHorizontalContent
bool GetIsModded()
const string BUTTON_PASSWORD
void DisplayQueue()
const string BUTTON_JOIN
Room m_RoomInfo
override bool OnFocusLost(Widget w, int x, int y)
string m_sTooltipDownloadIcon
ImageWidget m_wImgPing
const string FRAME_SCENARIO
Room GetRoomInfo()
void SetCellText(string cellName, string str, string widgetName="Content")
const string ICON_WARNING
override void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltip)
const string TEXT_WIDGET_QUEUE
const string LAYOUT_LOADING
const string LAYOUT_CONTENT
void OnServerDetailModsLoaded(Room room)
SCR_ModularButtonComponent m_JoinButton
SCR_ModularButtonComponent m_PasswordButton
SCR_RoomModsManager m_ModsManager
void EmptyVisuals(bool enable)
Widget m_wUnjoinableIcon
override void HandlerAttached(Widget w)
int m_iPingLimit
const string FRAME_NAME
float m_fTooltipDownloadIconScale
const string ICON_PING
const string ICON_UNJOINABLE
void DisplayServerProperties()
Create property images based on room setup.
bool m_bIsPatchSizeLoaded
TextWidget m_wQueue
void CheckRoomProperties()
Check properties and assign state of room.
bool GetIsEnabled(out bool versionMismatch, out bool unjoinable)
void OnJoinInteractionButtonClicked()
override bool OnFocus(Widget w, int x, int y)
const string ICON_MODDED
override void UpdateModularButtons()
Widget m_wVersionWarningIcon
SCR_EServerEntryProperty m_iProperties
void SetRoomInfo(Room room)
void SetModsManager(SCR_RoomModsManager modsManager)
Widget m_wJoinButton
ref array< ref ServerBrowserEntryProperty > m_aPingStates
static SCR_VersionMismatchTooltipComponent FindComponent(notnull Widget w)
SCR_FieldOfViewSettings Attribute