Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ServerScenarioDetailsPanelComponent.c
Go to the documentation of this file.
1 /*
2 Scenaraio panel with additional mods data.
3 Used mainly in server browser for displaying server(room) scenario and it's mods data
4 */
5 
7 {
8  [Attribute("", UIWidgets.ResourceNamePicker, "Layout", "edds")]
9  protected string m_sDefaultScenarioImg;
10 
11  // Widget Names
12  protected const string WIDGET_MODS_COUNT = "ModsCount";
13  protected const string WIDGET_MODS_LOADING = "LoadingMods";
14  protected const string WIDGET_MODS_ICON = "ModsSizeIcon";
15  protected const string WIDGET_MODS_SIZE = "ModsSizeText";
16  protected const string WIDGET_MODS_LOCKED_ICON = "ModsLockedIcon";
17 
18  // Localized strings
19  protected const string STR_VERSION_MISMATCH = "#AR-ServerBrowser_JoinModVersionMissmatch";
20  protected const string STR_UNJOINABLE = "#AR-ServerBrowser_NoneServers";
21 
22  protected const string STR_DEFAULT_VERSION = "v0.0.0.0";
23 
24  // Mods Widgets
25  protected ImageWidget m_wImgModsIcon;
26  protected ImageWidget m_wImgModsLocked;
27  protected TextWidget m_wTxtModsCount;
28  protected TextWidget m_wModsSizeText;
29  protected Widget m_wImageCrossplay;
30 
31  protected SCR_LoadingOverlay m_ModsLoading;
32 
33  // Server additional data
34  protected Room m_Room;
35  protected SCR_RoomModsManager m_ModsManager;
36  protected bool m_bHideScenarioImg;
37 
38  //------------------------------------------------------------------------------------------------
39  // Override functions
40  //------------------------------------------------------------------------------------------------
41 
42  //------------------------------------------------------------------------------------------------
43  override void HandlerAttached(Widget w)
44  {
45  super.HandlerAttached(w);
46 
47  // Get additional
48  m_wTxtModsCount = TextWidget.Cast(w.FindAnyWidget(WIDGET_MODS_COUNT));
49  m_wModsSizeText = TextWidget.Cast(w.FindAnyWidget(WIDGET_MODS_SIZE));
50  m_wImgModsIcon = ImageWidget.Cast(w.FindAnyWidget(WIDGET_MODS_ICON));
51  m_wImgModsLocked = ImageWidget.Cast(w.FindAnyWidget(WIDGET_MODS_LOCKED_ICON));
52 
53  Widget wModsLoading = w.FindAnyWidget(WIDGET_MODS_LOADING);
54  if (wModsLoading)
55  m_ModsLoading = SCR_LoadingOverlay.Cast(wModsLoading.FindHandler(SCR_LoadingOverlay));
56 
57  m_wImageCrossplay = AddTypeDisplay("platform-crossplay", UIConstants.ICONS_IMAGE_SET, UIConstants.ICONS_GLOW_IMAGE_SET);
58 
59  if (!GetGame().InPlayMode())
60  return;
61 
62  // Setup widgets
63  SetDefaultScenario("");
64  HideModsWidgets();
65  }
66 
67  //------------------------------------------------------------------------------------------------
68  override void SetScenario(MissionWorkshopItem scenario)
69  {
70  m_BackendImageComponent.GetEventOnImageSelected().Clear();
71  m_BackendImageComponent.GetEventOnImageSelected().Insert(OnScenarioBackendImageSelected);
72 
73  DisplayRoomDataScenario(m_Room);
74 
75  // Update scenario
76  m_Scenario = scenario;
77  if (scenario)
78  {
79  SCR_MissionHeader header = SCR_MissionHeader.Cast(scenario.GetHeader());
80  m_Header = header;
81  }
82  else
83  m_Header = null;
84 
85  UpdateAllWidgets();
86 
87  // Set room version
88  string strVersion = STR_DEFAULT_VERSION;
89 
90  if (!m_Room.Joinable())
91  strVersion = STR_UNJOINABLE + "!";
92 
93  else if (m_Room.GameVersion())
94  {
95  strVersion = "v" + m_Room.GameVersion();
96 
97  if (m_Room.GameVersion() != GetGame().GetBuildVersion())
98  strVersion += " - " + STR_VERSION_MISMATCH + "!";
99  }
100 
101  m_CommonWidgets.m_wAuthorNameText.SetText(strVersion);
102 
103  m_CommonWidgets.m_wNameImg.SetVisible(false);
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  protected void OnScenarioBackendImageSelected()
108  {
109  if (m_BackendImageComponent)
110  m_BackendImageComponent.GetEventOnImageSelected().Remove(OnScenarioBackendImageSelected);
111 
112  m_CommonWidgets.m_wLoadingOverlay.SetVisible(false);
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  void SetHideScenarioImg(bool hideContent) { m_bHideScenarioImg = hideContent; }
117 
118  //------------------------------------------------------------------------------------------------
120  override protected void UpdateAllWidgets()
121  {
122  super.UpdateAllWidgets();
123 
124  if (m_bHideScenarioImg)
125  m_CommonWidgets.m_wImage.LoadImageTexture(0, m_sDefaultScenarioImg, false, true);
126  }
127 
128  //------------------------------------------------------------------------------------------------
129  // public functions
130  //------------------------------------------------------------------------------------------------
131 
132  //------------------------------------------------------------------------------------------------
135  void SetDefaultScenario(string contentTag)
136  {
137  // Get content
138  DetailsPanelContentPreset content = FallbackContentByTag(contentTag);
139  if (!content)
140  {
141  #ifdef SB_DEBUG
142  Print("[SCR_ServerScenarioDeatilsPanelComponent] No fallback content was found!");
143  #endif
144  return;
145  }
146 
147  // Set fallback image
148  if (!content.m_sImage.IsEmpty())
149  m_CommonWidgets.m_wImage.LoadImageTexture(0, content.m_sImage);
150  else
151  {
152  if (m_FallbackContent && m_FallbackContent.m_DefaultContent)
153  {
154  if (!m_FallbackContent.m_DefaultContent.m_sImage.IsEmpty())
155  m_CommonWidgets.m_wImage.LoadImageTexture(0, m_FallbackContent.m_DefaultContent.m_sImage);
156  }
157  }
158 
159  // Correct image size
160  int sx, sy;
161  m_CommonWidgets.m_wImage.GetImageSize(0, sx, sy);
162  m_CommonWidgets.m_wImage.SetSize(sx, sy);
163  m_CommonWidgets.m_wLoadingOverlay.SetVisible(false);
164 
165  // Title
166  string title = content.m_sTitle;
167 
168  m_CommonWidgets.m_wNameText.SetText(title);
169  if (!content.m_sTitleImageName.IsEmpty())
170  {
171  m_CommonWidgets.m_wNameImg.SetVisible(true);
172  m_CommonWidgets.m_wNameImg.LoadImageFromSet(0, UIConstants.ICONS_IMAGE_SET, content.m_sTitleImageName);
173  m_CommonWidgets.m_wNameImg.SetColor(content.m_sTitleImageColor);
174  }
175 
176  // Description
177  m_CommonWidgets.m_wDescriptionText.SetText(content.m_sDescription);
178 
179  // Show default description
180  m_CommonWidgets.m_wImage.SetVisible(true);
181  m_CommonWidgets.m_wNameText.SetVisible(true);
182  m_CommonWidgets.m_wDescriptionText.SetVisible(true);
183 
184  m_CommonWidgets.m_wAuthorNameText.SetVisible(false);
185 
186  if(m_wImageCrossplay)
187  m_wImageCrossplay.SetVisible(false);
188 
189  HideModsWidgets();
190  }
191 
192  //------------------------------------------------------------------------------------------------
193  void DisplayRoomData(Room room, bool showMods = true)
194  {
195  DisplayRoomDataScenario(room);
196  m_CommonWidgets.m_wTopSize.SetOpacity(1);
197 
198  // Display mods loading
199  HideModsWidgets();
200 
201  bool show = room.IsModded() && showMods;
202 
203  m_ModsLoading.SetShown(show);
204  m_wImgModsLocked.SetVisible(false);
205 
206  if (!room.IsModded())
207  return;
208 
209  // Loading for public modded server
210  if (!room.PasswordProtected())
211  {
212  m_ModsLoading.SetShown(show);
213  }
214  else
215  {
216  // Warning for protected modded server
217  if (!room.IsAuthorized())
218  {
219  m_ModsLoading.SetShown(false);
220 
221  m_wImgModsIcon.SetVisible(true);
222  m_wImgModsLocked.SetVisible(true);
223  }
224  }
225  }
226 
227  //-----------------------------------------------------------------------------------
228  protected void DisplayRoomDataScenario(Room room)
229  {
230  m_Room = room;
231 
232  // Check room
233  if (!m_Room)
234  return;
235 
236  m_CommonWidgets.m_wNameText.SetVisible(true);
237  m_CommonWidgets.m_wAuthorNameText.SetVisible(true);
238 
239  // Set room version
240  string strVersion = STR_DEFAULT_VERSION;
241  if (room.GameVersion())
242  strVersion = "v" + room.GameVersion();
243 
244  // Scenario
245  string scenarioDescription = "";
246  if (m_Scenario)
247  scenarioDescription = m_Scenario.Description();
248 
249  // Set content
250  string title = room.ScenarioName();
251  //title.ToUpper();
252  m_CommonWidgets.m_wNameText.SetText(title);
253  m_CommonWidgets.m_wDescriptionText.SetText(scenarioDescription);
254  m_CommonWidgets.m_wAuthorNameText.SetText(strVersion);
255 
256  // Version match
257  if (room.GameVersion() == GetGame().GetBuildVersion() && room.Joinable())
258  {
259  m_CommonWidgets.m_wAuthorNameText.SetColor(UIColors.SUB_HEADER);
260  }
261  else
262  {
263  m_CommonWidgets.m_wAuthorNameText.SetColor(UIColors.WARNING);
264 
265  string text = m_CommonWidgets.m_wAuthorNameText.GetText();
266  if(room.Joinable())
267  text += " - " + STR_VERSION_MISMATCH + "!";
268 
269  m_CommonWidgets.m_wAuthorNameText.SetText(text);
270  }
271 
272  m_CommonWidgets.m_wLoadingOverlay.SetVisible(true);
273 
274  if (m_wImageCrossplay)
275  m_wImageCrossplay.SetVisible(m_Room.IsCrossPlatform());
276  }
277 
278  //-----------------------------------------------------------------------------------
279  void DisplayDefaultScenarioImage()
280  {
281  if (m_BackendImageComponent)
282  m_BackendImageComponent.SetScenarioAndImage(null, null);
283 
284  m_CommonWidgets.m_wLoadingOverlay.SetVisible(false);
285  }
286 
287  //-----------------------------------------------------------------------------------
290  protected void HideModsWidgets()
291  {
292  m_wTxtModsCount.SetVisible(false);
293  m_wImgModsIcon.SetVisible(false);
294  m_wModsSizeText.SetVisible(false);
295 
296  m_ModsLoading.SetShown(false);
297  }
298 
299  //-----------------------------------------------------------------------------------
301  void DisplayMods()
302  {
303  //m_aMods = mods;
304 
305  // Check widgets
306  if (!m_wTxtModsCount)
307  return;
308 
309  // Get values
310  array<ref SCR_WorkshopItem> allMods = m_ModsManager.GetRoomItemsScripted();
311 
312  int count = allMods.Count();
313  m_ModsLoading.SetShown(false);
314 
315  // Show UGC restricted message
316  if (count > 0 && !SCR_AddonManager.GetInstance().GetUgcPrivilege())
317  {
318  m_wModsSizeText.SetVisible(true);
319  m_wModsSizeText.SetText("#AR-ServerBrowser_ContentNotAllowed");
320  m_wModsSizeText.SetColor(UIColors.WARNING);
321  return;
322  }
323 
324  // Hide mods widget if no mods
325  bool show = (count != 0);
326 
327  m_wImgModsIcon.SetVisible(show);
328  m_wTxtModsCount.SetVisible(show);
329  m_wModsSizeText.SetVisible(show);
330  m_wModsSizeText.SetColor(UIColors.NEUTRAL_ACTIVE_STANDBY);
331 
332  if (!show)
333  return;
334 
335  string totalSize = m_ModsManager.GetModListSizeString(allMods);
336 
337  // Set Text
338  m_wTxtModsCount.SetText(count.ToString());
339  m_wModsSizeText.SetText(totalSize);
340 
341  // Check mods to update size
342  array<ref SCR_WorkshopItem> toUpdateMods = m_ModsManager.GetRoomItemsToUpdate();
343 
344  // Check to update mods count
345  if (toUpdateMods.IsEmpty())
346  return;
347  }
348 
349  //-----------------------------------------------------------------------------------
351  void DisplayModsCount(int count)
352  {
353  // Show if modded
354  bool show = (count != 0);
355 
356  // Set widgets
357  m_wTxtModsCount.SetVisible(true);
358  m_wImgModsIcon.SetVisible(true);
359  m_wModsSizeText.SetVisible(false);
360 
361  m_wTxtModsCount.SetText(count.ToString());
362  }
363 
364  //-----------------------------------------------------------------------------------
365  void SetModsManager(SCR_RoomModsManager manager)
366  {
367  m_ModsManager = manager;
368  }
369 }
m_FallbackContent
protected ref DetailsPanelContentPresetConfig m_FallbackContent
Definition: SCR_ContentDetailsPanelBase.c:5
SCR_ScenarioDetailsPanelComponent
Definition: SCR_ScenarioDetailsPanelComponent.c:6
UIConstants
Definition: Constants.c:130
FallbackContentByTag
protected DetailsPanelContentPreset FallbackContentByTag(string contentTag)
Get fallback content by tag.
Definition: SCR_ContentDetailsPanelBase.c:59
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_LoadingOverlay
Definition: SCR_LoadingOverlay.c:49
SCR_ServerScenarioDetailsPanelComponent
Definition: SCR_ServerScenarioDetailsPanelComponent.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
UIColors
Definition: Constants.c:16
m_ModsManager
protected SCR_RoomModsManager m_ModsManager
Definition: SCR_ServerBrowserEntryComponent.c:52
DetailsPanelContentPreset
Definition: SCR_ContentDetailsPanelBase.c:129
SCR_RoomModsManager
Definition: SCR_RoomModsManager.c:27
SCR_AddonManager
Definition: SCR_AddonManager.c:72
m_Room
protected Room m_Room
Definition: ServerBrowserMenuCallbacks.c:2
m_CommonWidgets
protected ref SCR_ContentDetailsPanelBaseWidgets m_CommonWidgets
Definition: SCR_ContentDetailsPanelBase.c:2
AddTypeDisplay
protected Widget AddTypeDisplay(string image, ResourceName imageset, ResourceName glowImageset)
Definition: SCR_ContentDetailsPanelBase.c:85
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
m_Scenario
SCR_ExitGameWhileDownloadingDialog m_Scenario