Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayMenuTileComponent.c
Go to the documentation of this file.
2 {
3  [Attribute("0", UIWidgets.CheckBox, "Is this a big vertical tile? E.g. will use hi-res thumb picture..")]
4  protected bool m_bBigTile;
5 
6  [Attribute("480", UIWidgets.Slider, "Estimated width of grid thumb picture, in a reference resolution.", "320 1920 1")]
7  protected float m_fThumbnailWidth;
8 
9  MissionWorkshopItem m_Item;
10  ref SCR_MissionHeader m_Header;
11  string m_sScenarioPath;
12 
13  Widget m_wContentGroup;
14  Widget m_wFeatured;
15  TextWidget m_wName;
16  TextWidget m_wDescription;
17  Widget m_wRecentlyPlayed;
18  TextWidget m_wRecentlyPlayedText;
19 
20  // Mouse interact buttons
21  Widget m_wMouseInteractButtons;
22  Widget m_wPlay;
23  Widget m_wContinue;
24  Widget m_wRestart;
25  Widget m_wHost;
26  Widget m_wFindServer;
27 
28  bool m_bIsMouseInteraction;
29 
30  protected ref array<SCR_ModularButtonComponent> m_aMouseButtonsError = {};
31 
32  bool m_bFocused;
33 
34  // Button components
35  SCR_ModularButtonComponent m_Play;
36  SCR_ModularButtonComponent m_Continue;
37  SCR_ModularButtonComponent m_FindServer;
38  SCR_ModularButtonComponent m_Host;
39  SCR_ModularButtonComponent m_Restart;
40 
41  // Warning
42  SCR_SimpleWarningOverlayComponent m_WarningOverlay;
43 
44  // Tooltip
45  protected SCR_ScriptedWidgetTooltip m_CurrentTooltip;
46 
47  // Script invokers for the mouse interact buttons
48  protected ref ScriptInvokerString m_OnMouseInteractionButtonClicked;
49 
50  //------------------------------------------------------------------------------------------------
51  override void HandlerAttached(Widget w)
52  {
53  super.HandlerAttached(w);
54 
55  SCR_ServicesStatusHelper.RefreshPing();
56  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Insert(OnCommStatusCheckFinished);
57 
58  m_wName = TextWidget.Cast(w.FindAnyWidget("Name"));
59  m_wDescription = TextWidget.Cast(w.FindAnyWidget("Description"));
60  m_wFeatured = w.FindAnyWidget("Featured");
61  m_wContentGroup = w.FindAnyWidget("ContentGroup");
62 
63  m_wRecentlyPlayed = w.FindAnyWidget("RecentlyPlayed");
64  m_wRecentlyPlayedText = TextWidget.Cast(m_wRecentlyPlayed.FindAnyWidget("Label"));
65 
66  m_wMouseInteractButtons = w.FindAnyWidget("MouseInteractButtons");
67  m_wPlay = w.FindAnyWidget(SCR_ScenarioEntryHelper.BUTTON_PLAY);
68  m_wContinue = w.FindAnyWidget(SCR_ScenarioEntryHelper.BUTTON_CONTINUE);
69  m_wRestart = w.FindAnyWidget(SCR_ScenarioEntryHelper.BUTTON_RESTART);
70  m_wHost = w.FindAnyWidget(SCR_ScenarioEntryHelper.BUTTON_HOST);
71  m_wFindServer = w.FindAnyWidget(SCR_ScenarioEntryHelper.BUTTON_FIND_SERVERS);
72 
73  m_Play = SCR_ModularButtonComponent.FindComponent(m_wPlay);
74  if (m_Play)
75  m_Play.m_OnClicked.Insert(OnPlay);
76 
77  m_Continue = SCR_ModularButtonComponent.FindComponent(m_wContinue);
78  if (m_Continue)
79  m_Continue.m_OnClicked.Insert(OnContinue);
80 
81  m_Restart = SCR_ModularButtonComponent.FindComponent(m_wRestart);
82  if (m_Restart)
83  m_Restart.m_OnClicked.Insert(OnRestart);
84 
85  m_Host = SCR_ModularButtonComponent.FindComponent(m_wHost);
86  if (m_Host)
87  {
88  m_aMouseButtonsError.Insert(m_Host);
89  m_Host.m_OnClicked.Insert(OnHost);
90  }
91 
92  m_FindServer = SCR_ModularButtonComponent.FindComponent(m_wFindServer);
93  if (m_FindServer)
94  {
95  m_aMouseButtonsError.Insert(m_FindServer);
96  m_FindServer.m_OnClicked.Insert(OnFindServers);
97  }
98 
99  if (GetGame().InPlayMode())
100  Enable(false);
101 
102  InputManager inputManager = GetGame().GetInputManager();
103 
104  if (inputManager)
105  m_bIsMouseInteraction = (inputManager.GetLastUsedInputDevice() == EInputDeviceType.MOUSE);
106 
107  GetGame().OnInputDeviceUserChangedInvoker().Insert(OnInputDeviceUserChanged);
108 
110  }
111 
112  //------------------------------------------------------------------------------------------------
113  override void HandlerDeattached(Widget w)
114  {
115  super.HandlerDeattached(w);
116  SCR_ServicesStatusHelper.GetOnCommStatusCheckFinished().Remove(OnCommStatusCheckFinished);
117  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnTooltipShow);
118  }
119 
120  //------------------------------------------------------------------------------------------------
121  override bool OnFocus(Widget w, int x, int y)
122  {
123  super.OnFocus(w, x, y);
124 
125  m_bFocused = true;
126  UpdateModularButtons();
127 
128  // Tooltips
129  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Insert(OnTooltipShow);
130 
131  return false;
132  }
133 
134  //------------------------------------------------------------------------------------------------
135  override bool OnFocusLost(Widget w, int x, int y)
136  {
137  super.OnFocusLost(w, x, y);
138 
139  m_bFocused = false;
140  UpdateModularButtons();
141 
142  // Tooltips
143  SCR_ScriptedWidgetTooltip.GetOnTooltipShow().Remove(OnTooltipShow);
144 
145  return false;
146  }
147 
148  //------------------------------------------------------------------------------------------------
151  void Setup(notnull MissionWorkshopItem item, EPlayMenuContentType contentType)
152  {
153  m_Item = item;
154 
155  // Init header only if scenario is NOT coming from an addon
156  if (!item.GetOwner())
157  m_Header = SCR_MissionHeader.GetMissionHeader(item);
158 
159  m_wName.SetText(item.Name());
160  m_wDescription.SetText(item.Description());
161 
162  bool canContinue = m_Header && SCR_ScenarioEntryHelper.HasSave(item);
163  bool mp = SCR_ScenarioEntryHelper.IsMultiplayer(item);
164 
165  m_wPlay.SetVisible(!canContinue);
166  m_wContinue.SetVisible(canContinue);
167  m_wRestart.SetVisible(canContinue);
168  m_wHost.SetVisible(mp && !GetGame().IsPlatformGameConsole());
169  m_wFindServer.SetVisible(mp);
170 
171  UpdateModularButtons();
172  UpdateWarning();
173 
174  // Set image through SCR_ButtonImageComponent
176  if (comp)
177  {
178  ResourceName texture = GetTexture();
179 
180  //PrintFormat("%1 | texture: %2", item.Name(), texture);
181 
182  if (!texture.IsEmpty())
183  comp.SetImage(texture, item.GetOwner() != null);
184  }
185 
186  //DEBUG
187 // string savefile_item = SCR_SaveLoadComponent.GetSaveFileName(item);
188 // Print(savefile_item, LogLevel.NORMAL);
189 // string savefile_header = SCR_SaveLoadComponent.GetSaveFileName(m_Header);
190 // Print(savefile_header, LogLevel.NORMAL);
191 
192  m_wFeatured.SetVisible(contentType == EPlayMenuContentType.FEATURED);
193  m_wRecentlyPlayed.SetVisible(contentType == EPlayMenuContentType.RECENT);
194 
195  if (contentType == EPlayMenuContentType.RECENT)
196  {
197  int timeSinceLastPlayedSeconds = m_Item.GetTimeSinceLastPlay();
198  string sLastPlayed = SCR_FormatHelper.GetTimeSinceEventImprecise(timeSinceLastPlayedSeconds);
199 
200  m_wRecentlyPlayedText.SetText(sLastPlayed);
201  }
202 
203  if (m_wMouseInteractButtons)
204  m_wMouseInteractButtons.SetVisible(false);
205 
206  Enable();
207  }
208 
209  //------------------------------------------------------------------------------------------------
210  protected void Enable(bool enable = true)
211  {
212  m_wRoot.SetEnabled(enable);
213  m_wContentGroup.SetVisible(enable);
214  }
215 
216  //------------------------------------------------------------------------------------------------
218  ResourceName GetTexture()
219  {
220  if (m_bBigTile && m_Header && !m_Header.m_sPreviewImage.IsEmpty())
221  return m_Header.m_sPreviewImage;
222 
223  if (m_Header)
224  return m_Header.m_sLoadingScreen;
225 
226  if (m_Item)
227  {
228  BackendImage image = m_Item.Thumbnail();
229 
230  // DEBUG problems with scenario addon thumbs
231 // array<ImageScale> scales = {};
232 // int i = image.GetScales(scales);
233 
234  // Get optimal width for the thumb
235  float width = g_Game.GetWorkspace().DPIScale(m_fThumbnailWidth);
236  ImageScale scale = image.GetLocalScale((int)width);
237  if (scale)
238  return scale.Path();
239  }
240 
241  return string.Empty;
242  }
243 
244  // React on switching between input methods
245  //------------------------------------------------------------------------------------------------
246  protected void OnInputDeviceUserChanged(EInputDeviceType oldDevice, EInputDeviceType newDevice)
247  {
248  //PrintFormat("OnInputDeviceUserChanged | %1 -> %2", oldDevice, newDevice);
249 
250  if (newDevice == EInputDeviceType.TRACK_IR || newDevice == EInputDeviceType.JOYSTICK)
251  return;
252 
253  m_bIsMouseInteraction = (newDevice == EInputDeviceType.MOUSE);
254  }
255 
256  //------------------------------------------------------------------------------------------------
257  protected void OnPlay()
258  {
259  if (m_OnMouseInteractionButtonClicked)
260  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_PLAY);
261  }
262 
263  //------------------------------------------------------------------------------------------------
264  protected void OnContinue()
265  {
266  if (m_OnMouseInteractionButtonClicked)
267  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_CONTINUE);
268  }
269 
270  //------------------------------------------------------------------------------------------------
271  protected void OnRestart()
272  {
273  if (m_OnMouseInteractionButtonClicked)
274  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_RESTART);
275  }
276 
277  //------------------------------------------------------------------------------------------------
278  protected void OnHost()
279  {
280  if (SCR_ScenarioEntryHelper.IsInErrorState(m_Item))
281  return;
282 
283  if (m_OnMouseInteractionButtonClicked)
284  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_HOST);
285  }
286 
287  //------------------------------------------------------------------------------------------------
288  protected void OnFindServers()
289  {
290  if (SCR_ScenarioEntryHelper.IsInErrorState(m_Item))
291  return;
292 
293  if (m_OnMouseInteractionButtonClicked)
294  m_OnMouseInteractionButtonClicked.Invoke(SCR_ScenarioEntryHelper.BUTTON_FIND_SERVERS);
295  }
296 
297  //------------------------------------------------------------------------------------------------
298  protected void OnCommStatusCheckFinished(SCR_ECommStatus status, float responseTime, float lastSuccessTime, float lastFailTime)
299  {
300  UpdateModularButtons();
301  }
302 
303  //------------------------------------------------------------------------------------------------
304  protected void OnTooltipShow(SCR_ScriptedWidgetTooltip tooltipClass, Widget tooltipWidget, Widget hoverWidget, SCR_ScriptedWidgetTooltipPreset preset, string tag)
305  {
306  m_CurrentTooltip = tooltipClass;
307  SCR_ScenarioEntryHelper.UpdateErrorMouseButtonsTooltip(tooltipClass, m_Item);
308  }
309 
310  //------------------------------------------------------------------------------------------------
311  protected void UpdateModularButtons()
312  {
313  SCR_ScenarioEntryHelper.UpdateErrorMouseButtonsTooltip(m_CurrentTooltip, m_Item);
314 
315  if (m_wMouseInteractButtons)
316  m_wMouseInteractButtons.SetVisible(m_bFocused);
317 
318  array<SCR_ModularButtonComponent> mouseButtons = {};
319  if (m_Restart)
320  mouseButtons.Insert(m_Restart);
321 
322  SCR_ScenarioEntryHelper.UpdateMouseButtons(mouseButtons, m_aMouseButtonsError, m_Item, m_bFocused);
323  }
324 
325  //------------------------------------------------------------------------------------------------
326  protected void UpdateWarning()
327  {
328  if (!m_WarningOverlay)
329  return;
330 
331  m_bIsInErrorState = SCR_ScenarioEntryHelper.IsModInErrorState(m_Item);
332 
333  m_WarningOverlay.SetWarningVisible(m_bIsInErrorState, false);
334  m_WarningOverlay.SetWarning(SCR_ScenarioEntryHelper.GetErrorMessage(m_Item), SCR_ScenarioEntryHelper.GetErrorTexture(m_Item));
335  }
336 
337  //------------------------------------------------------------------------------------------------
339  ScriptInvokerString GetOnMouseInteractionButtonClicked()
340  {
341  if (!m_OnMouseInteractionButtonClicked)
342  m_OnMouseInteractionButtonClicked = new ScriptInvokerString();
343 
344  return m_OnMouseInteractionButtonClicked;
345  }
346 }
SCR_ECommStatus
SCR_ECommStatus
This class may become obsolete on BackendAPI update.
Definition: SCR_ServicesStatusHelper.c:2
m_wName
TextWidget m_wName
Definition: SCR_PlayerListMenu.c:20
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
m_WarningOverlay
protected SCR_SimpleWarningOverlayComponent m_WarningOverlay
Definition: SCR_ContentDetailsPanelBase.c:21
SCR_FormatHelper
Definition: SCR_FormatHelper.c:1
SCR_TileBaseComponent
Definition: SCR_TileBaseComponent.c:1
m_Item
NewsFeedItem m_Item
Definition: SCR_NewsSubMenu.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_PlayMenuTileComponent
Definition: SCR_PlayMenuTileComponent.c:1
EPlayMenuContentType
EPlayMenuContentType
Definition: SCR_PlayMenu.c:1
IsPlatformGameConsole
bool IsPlatformGameConsole()
Definition: game.c:1393
m_Host
protected SCR_InputButtonComponent m_Host
Definition: SCR_ScenarioDialogs.c:35
SCR_SimpleWarningOverlayComponent
Definition: SCR_SimpleWarningOverlayComponent.c:6
Attribute
typedef Attribute
Post-process effect of scripted camera.
ScriptInvokerString
ScriptInvokerBase< ScriptInvokerStringMethod > ScriptInvokerString
Definition: SCR_ScriptInvokerHelper.c:75
SCR_ServicesStatusHelper
Definition: SCR_ServicesStatusHelper.c:15
SCR_ScriptedWidgetTooltip
Definition: SCR_ScriptedWidgetTooltip.c:15
SCR_ButtonImageComponent
Definition: SCR_ButtonImageComponent.c:2
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1