Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ScenarioTileComponent.c
Go to the documentation of this file.
1 //------------------------------------------------------------------------------------------------
3 {
4 
5  MissionWorkshopItem m_Scenario = null;
6  SCR_MissionHeader m_Header = null;
7  protected bool m_bIsLocal = true;
8  protected ImageWidget m_ScenarioImage;
9  protected TextWidget m_ScenarioName;
10 
11  protected TextWidget m_ScenarioSumary;
12  protected TextWidget m_ScenarioGameMode;
13 
14  protected Widget m_ScenarioMod;
15  protected SCR_ButtonComponent m_ModParentComp;
16  protected Widget m_wPlayableButtom;
17  protected Widget m_wWhiteFrame;
18 
19  protected SCR_InputButtonComponent m_PlayButtonComponent;
20  protected SCR_InputButtonComponent m_HostButtonComponent;
21  protected SCR_InputButtonComponent m_JoinButtonComponent;
22 
23  protected SCR_ButtonComponent m_LinkComp;
24  protected Widget m_wGamepadModNameButton;
25  protected SCR_ButtonComponent m_GamepadModNameButtonController
26  protected Widget m_ScenarioModButton;
27  protected Widget m_wFavouriteOverlay;
28  SCR_SelectableTileButtonComponent m_FavComponent;
29  private string m_sFavouriteOverlay = "FavouriteOverlayButton";
30 
31  private InputManager m_InputManager;
32 
33  ContentBrowserUI m_ParentContentBrowserMenu;
34 
35  ref ScriptInvoker m_OnPlayClicked = new ScriptInvoker();
36  ref ScriptInvoker m_OnHostClicked = new ScriptInvoker();
37  ref ScriptInvoker m_OnJoinClicked = new ScriptInvoker();
38 
39  //------------------------------------------------------------------------------------------------
40  override void HandlerAttached(Widget w)
41  {
42  super.HandlerAttached(w);
43 
44  m_InputManager = GetGame().GetInputManager();
45  m_ScenarioGameMode = TextWidget.Cast(m_wRoot.FindAnyWidget("ScenarioGameMode"));
46  m_ScenarioImage = ImageWidget.Cast(m_wRoot.FindAnyWidget("ScenarioImage"));
47  m_ScenarioName = TextWidget.Cast(m_wRoot.FindAnyWidget("ScenarioName"));
48  m_ScenarioMod = m_wRoot.FindAnyWidget("ScenarioMod");
49  m_ScenarioModButton = m_wRoot.FindAnyWidget("ScenarioModButton");
50  m_ScenarioSumary = TextWidget.Cast(m_wRoot.FindAnyWidget("ScenarioSumary"));
51  m_wPlayableButtom = m_wRoot.FindAnyWidget("PlayablePC");
52  m_wWhiteFrame = m_wRoot.FindAnyWidget("WhiteFrameOverlay");
53 
54 
55  m_PlayButtonComponent = SCR_InputButtonComponent.GetInputButtonComponent("PlayButton", m_wRoot);
56  if (m_PlayButtonComponent)
57  m_PlayButtonComponent.m_OnActivated.Insert(OnPlay);
58 
59  m_HostButtonComponent = SCR_InputButtonComponent.GetInputButtonComponent("HostButton", m_wRoot);
60  if (m_HostButtonComponent)
61  m_HostButtonComponent.m_OnActivated.Insert(OnHost);
62 
63  m_JoinButtonComponent = SCR_InputButtonComponent.GetInputButtonComponent("JoinButton", m_wRoot);
64  if (m_JoinButtonComponent)
65  m_JoinButtonComponent.m_OnActivated.Insert(OnJoin);
66 
67  if (m_ScenarioModButton)
68  {
69  m_ModParentComp = SCR_ButtonComponent.Cast(m_ScenarioModButton.FindHandler(SCR_ButtonComponent));
70  if (m_ModParentComp)
71  {
72  m_ModParentComp.m_OnClicked.Insert(OpenParentMod);
73  }
74  }
75 
76  m_wFavouriteOverlay = w.FindAnyWidget(m_sFavouriteOverlay);
77  if (m_wFavouriteOverlay)
78  {
79  m_FavComponent = SCR_SelectableTileButtonComponent.Cast(m_wFavouriteOverlay.FindHandler(SCR_SelectableTileButtonComponent));
80  if (m_FavComponent)
81  {
82  m_FavComponent.m_OnChanged.Insert(OnFavouriteClicked);
83  }
84  }
85 
86  m_wGamepadModNameButton = m_wRoot.FindAnyWidget("ModNavButton");
87  GetGame().OnInputDeviceIsGamepadInvoker().Remove(OnInputDeviceIsGamepad);
88  GetGame().OnInputDeviceIsGamepadInvoker().Insert(OnInputDeviceIsGamepad);
89 
90  AnimateWidget.Opacity(m_wPlayableButtom, 0, m_fAnimationRate);
91  OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
92  }
93 
94  //------------------------------------------------------------------------------------------------
95  MissionWorkshopItem GetMission()
96  {
97  return m_Scenario;
98  }
99 
100  //------------------------------------------------------------------------------------------------
101  SCR_MissionHeader GetHeader()
102  {
103  return m_Header;
104  }
105 
106  //------------------------------------------------------------------------------------------------
107  void OpenParentModGamepad()
108  {
109  if (!m_ScenarioMod.IsVisible())
110  return;
111  if (m_wRoot == GetGame().GetWorkspace().GetFocusedWidget())
112  OpenParentMod();
113  }
114 
115  //------------------------------------------------------------------------------------------------
116  void OpenParentMod()
117  {
118  if (!m_Scenario)
119  return;
120  WorkshopItem owner = m_Scenario.GetOwner();
121  if (!owner)
122  return;
123  ContentBrowserDetailsMenu baseMenu = ContentBrowserDetailsMenu.Cast(GetGame().GetMenuManager().OpenMenu(ChimeraMenuPreset.ContentBrowserDetailsMenu, 0, true, false));
124 
125  if (baseMenu)
126  {
127  // todo
128  //if (m_ParentContentBrowserMenu)
129  // baseMenu.SetParentMenu(m_ParentContentBrowserMenu);
130  // baseMenu.SetWorkshopItem(owner, null, null);
131  }
132  }
133 
134  //------------------------------------------------------------------------------------------------
135  void SetParentMenu(ContentBrowserUI menu)
136  {
137  m_ParentContentBrowserMenu = menu;
138  }
139 
140  //------------------------------------------------------------------------------------------------
141  void SetScenarioHeader(SCR_MissionHeader header)
142  {
143  m_Header = header;
144  if (m_ScenarioImage)
145  {
146  if (header.m_sIcon)
147  {
148  m_ScenarioImage.LoadImageTexture(0, header.m_sIcon, false, true);
149  m_ScenarioImage.SetImage(0);
150  }
151 
152  }
153 
154  if (m_ScenarioName)
155  {
156  if (header.m_sName)
157  m_ScenarioName.SetText(header.m_sName);
158  }
159 
160  if (m_ScenarioSumary)
161  {
162  if (header.m_sDescription)
163  m_ScenarioSumary.SetText(header.m_sDescription);
164  }
165 
166  if (m_ScenarioGameMode)
167  {
168  if (m_ScenarioGameMode)
169  m_ScenarioGameMode.SetText(header.m_sGameMode);
170  }
171 
172  if (header.IsMultiplayer())
173  {
174  m_HostButtonComponent.GetRootWidget().SetVisible(true);
175  m_JoinButtonComponent.GetRootWidget().SetVisible(true);
176  }
177  else
178  {
179  m_HostButtonComponent.GetRootWidget().SetVisible(false);
180  m_JoinButtonComponent.GetRootWidget().SetVisible(false);
181  }
182  }
183 
184  //------------------------------------------------------------------------------------------------
185  void SetScenario(MissionWorkshopItem scenario, bool bShowOwner = true, bool bShowFavourite = true)
186  {
187  m_Scenario = scenario;
188  SCR_MissionHeader header = SCR_MissionHeader.Cast(scenario.GetHeader());
189 
190  if (bShowFavourite)
191  {
192  m_wFavouriteOverlay.SetVisible(true);
193  if (scenario.IsFavorite())
194  AnimateWidget.Opacity(m_wPlayableButtom, 1, UIConstants.FADE_RATE_DEFAULT);
195  m_FavComponent.SetSelected(scenario.IsFavorite(), false);
196  }
197 
198  if (header)
199  SetScenarioHeader(header);
200  else
201  {
202  if (m_ScenarioImage)
203  {
204  ImageScale img = scenario.Thumbnail().GetLocalScale(0); //take any scale
205  if (img)
206  {
207  m_ScenarioImage.LoadImageTexture(0, img.Path(), false, true);
208  m_ScenarioImage.SetImage(0);
209  }
210 
211  }
212 
213  if (m_ScenarioName)
214  {
215  if (scenario.Name())
216  m_ScenarioName.SetText(scenario.Name());
217  }
218 
219  if (m_ScenarioSumary)
220  {
221  if (scenario.Description())
222  m_ScenarioSumary.SetText(scenario.Description());
223  }
224 
225  }
226 
227  m_FavComponent.SetSelected(m_Scenario.IsFavorite(), false);
228 
229 
230  WorkshopItem owner = scenario.GetOwner();
231  if (owner)
232  {
233 
234  if (bShowOwner)
235  {
236  if (m_ScenarioMod)
237  {
238 
239  m_ScenarioMod.SetVisible(true);
240  m_ModParentComp.SetContent(owner.Name());
241  }
242  else
243  m_ScenarioName.SetColor(Color.FromInt(UIColors.CONTRAST_COLOR.PackToInt()));
244 
245  }
246  else
247  {
248  if (m_ScenarioMod)
249  m_ScenarioMod.SetVisible(false);
250  }
251  int flags = owner.GetStateFlags();
252  if (!(flags & EWorkshopItemState.EWSTATE_OFFLINE) || !owner.IsLoaded())
253  {
254  m_bIsLocal = false;
255  m_wPlayableButtom.SetVisible(false);
256  }
257  }
258 
259 
260  }
261 
262 
263  //------------------------------------------------------------------------------------------------
264  MissionWorkshopItem GetScenario()
265  {
266  return m_Scenario;
267  }
268 
269 
270  //------------------------------------------------------------------------------------------------
271  bool IsFocused()
272  {
273  return GetGame().GetWorkspace().GetFocusedWidget() == this.m_wRoot;
274  }
275 
276  //------------------------------------------------------------------------------------------------
277  void OnPlay()
278  {
279  if (!this.IsFocused())
280  return;
281 
282  m_OnPlayClicked.Invoke(this);
283  }
284 
285  //------------------------------------------------------------------------------------------------
286  void OnHost()
287  {
288  if (!this.IsFocused())
289  return;
290 
291  m_OnHostClicked.Invoke(this);
292  }
293 
294  //------------------------------------------------------------------------------------------------
295  void OnJoin()
296  {
297  if (!this.IsFocused())
298  return;
299 
300  m_OnJoinClicked.Invoke(this);
301  }
302 
303  //------------------------------------------------------------------------------------------------
304  override void OnMenuSelect()
305  {
306  return;
307  }
308 
309  //------------------------------------------------------------------------------------------------
310  override bool OnMouseButtonDown(Widget w, int x, int y, int button)
311  {
312 
313  return false;
314  }
315 
316  //------------------------------------------------------------------------------------------------
317  override bool OnMouseButtonUp(Widget w, int x, int y, int button)
318  {
319 
320  return false;
321  }
322 
323  //------------------------------------------------------------------------------------------------
324  override bool OnFocus(Widget w, int x, int y)
325  {
326  //if (w != m_wRoot)
327  //return false;
328  m_OnFocus.Invoke(w);
329 
330  m_FavComponent.ShowButton();
331  AnimateWidget.Opacity(m_wPlayableButtom, 1, m_fAnimationRate);
332  AnimateWidget.Color(m_wWhiteFrame, m_BackgroundSelected, m_fAnimationRate);
333  //AnimateWidget.Opacity(m_wGamepadModNameButton, 1, m_fAnimationRate);
334 
335  if (GetGame().GetInputManager().IsUsingMouseAndKeyboard())
336  {
337  m_wGamepadModNameButton.SetOpacity(0);
338  }
339  else
340  {
341  m_InputManager.AddActionListener("MenuRefresh", EActionTrigger.PRESSED, OpenParentModGamepad);
342  m_wGamepadModNameButton.SetOpacity(1);
343  }
344 
345  return super.OnFocus( w, x, y);;
346  }
347 
348  //------------------------------------------------------------------------------------------------
349  override bool OnFocusLost(Widget w, int x, int y)
350  {
351  /*if (GetWidgetUnderCursor() == w)
352  AnimateWidget.Color(m_wWhiteFrame, COLOR_BACKGROUND_HOVERED, m_fAnimationRate);
353  else
354  {*/
355  AnimateWidget.Color(m_wWhiteFrame, Color.FromInt(UIColors.TRANSPARENT.PackToInt()), m_fAnimationRate);
356  AnimateWidget.Opacity(m_wPlayableButtom, 0, m_fAnimationRate);
357  AnimateWidget.Opacity(m_wGamepadModNameButton, 0, m_fAnimationRate);
358  //}
359  m_InputManager.RemoveActionListener("MenuRefresh", EActionTrigger.PRESSED, OpenParentModGamepad);
360  m_wGamepadModNameButton.SetOpacity(0);
361  m_FavComponent.HideButton();
362  return super.OnFocusLost( w, x, y);;
363  }
364 
365  //------------------------------------------------------------------------------------------------
366  void OnButtonHovered()
367  {
368  OnMouseEnter(m_wRoot, 0, 0);
369  }
370 
371  //------------------------------------------------------------------------------------------------
372  void OnInputDeviceIsGamepad(bool isGamepad)
373  {
374 
375  }
376 
377  //------------------------------------------------------------------------------------------------
378  void OnFavouriteClicked()
379  {
380  m_Scenario.SetFavorite(m_FavComponent.IsSelected());
381  }
382 
383 };
OnMouseEnter
override bool OnMouseEnter(Widget w, int x, int y)
Definition: SCR_EntitiesEditorUIComponent.c:99
m_InputManager
protected InputManager m_InputManager
Definition: SCR_BaseManualCameraComponent.c:15
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
ContentBrowserDetailsMenu
Definition: ContentBrowserDetailsMenu.c:2
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_ButtonBaseComponent
Base class for any button, regardless its own content.
Definition: SCR_ButtonBaseComponent.c:3
GetInputManager
protected InputManager GetInputManager()
Definition: SCR_BaseManualCameraComponent.c:65
ChimeraMenuPreset
ChimeraMenuPreset
Menu presets.
Definition: ChimeraMenuBase.c:3
m_OnFocus
ref ScriptInvoker m_OnFocus
Definition: SCR_ModularButtonComponent.c:63
SCR_SelectableTileButtonComponent
Definition: SCR_SelectableTileButtonComponent.c:2
SCR_ScenarioTileComponent
Definition: SCR_ScenarioTileComponent.c:2
SCR_MissionHeader
Definition: SCR_MissionHeader.c:1
SCR_InputButtonComponent
Definition: SCR_InputButtonComponent.c:1
m_Scenario
SCR_ExitGameWhileDownloadingDialog m_Scenario