Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_LoadoutGallery.c
Go to the documentation of this file.
2 {
3  [Attribute("{39D815C843414C76}UI/layouts/Menus/DeployMenu/LoadoutButton.layout")]
4  protected ResourceName m_sLoadoutButton;
5  protected ref set<SCR_LoadoutButton> m_aLoadoutButtons = new set<SCR_LoadoutButton>();
6 
7  protected ref ScriptInvoker<SCR_LoadoutButton> m_OnLoadoutClicked;
8  protected ref ScriptInvoker<SCR_BasePlayerLoadout> m_OnLoadoutHovered;
9  protected ref ScriptInvokerBool m_OnFocusChange = new ScriptInvokerBool();
10  protected bool m_bFocused;
11 
12  override void HandlerAttached(Widget w)
13  {
14  super.HandlerAttached(w);
15  EnablePagingInputListeners(false);
16  }
17 
18  ScriptInvokerBool GetOnFocusChange()
19  {
20  return m_OnFocusChange;
21  }
22 
23  void SetGalleryFocused(bool focused)
24  {
25  Widget focusedWidget = GetGame().GetWorkspace().GetFocusedWidget();
26  if (m_bFocused && (focusedWidget && focusedWidget.IsInherited(SCR_LoadoutButton)))
27  return;
28 
29  m_bFocused = focused;
30  m_OnFocusChange.Invoke(m_bFocused);
31  }
32 
33  override bool OnFocus(Widget w, int x, int y)
34  {
35  super.OnFocus(w, x, y);
36  SetGalleryFocused(true);
37 
38  return false;
39  }
40 
41  override bool OnFocusLost(Widget w, int x, int y)
42  {
43  super.OnFocusLost(w, x, y);
44  SetGalleryFocused(false);
45 
46  return false;
47  }
48 
49  bool GetFocused()
50  {
51  return m_bFocused;
52  }
53 
54  void EnablePagingInputListeners(bool enable)
55  {
56  GetGame().GetInputManager().RemoveActionListener(m_sActionLeft, EActionTrigger.DOWN, OnCustomLeft);
57  GetGame().GetInputManager().RemoveActionListener(m_sActionRight, EActionTrigger.DOWN, OnCustomRight);
58 
59  if (!enable)
60  return;
61 
62  GetGame().GetInputManager().AddActionListener(m_sActionLeft, EActionTrigger.DOWN, OnCustomLeft);
63  GetGame().GetInputManager().AddActionListener(m_sActionRight, EActionTrigger.DOWN, OnCustomRight);
64  }
65 
66  int AddItem(SCR_BasePlayerLoadout loadout, bool enabled = true)
67  {
68  Widget loadoutEntry = GetGame().GetWorkspace().CreateWidgets(m_sLoadoutButton);
69  SCR_LoadoutButton loadoutBtn = SCR_LoadoutButton.Cast(loadoutEntry.FindHandler(SCR_LoadoutButton));
70  if (loadoutBtn)
71  {
72  loadoutBtn.SetLoadout(loadout);
73  loadoutBtn.SetEnabled(enabled);
74 
75  loadoutBtn.m_OnClicked.Insert(OnLoadoutClicked);
76  loadoutBtn.m_OnFocus.Insert(OnLoadoutHovered);
77  loadoutBtn.m_OnMouseEnter.Insert(OnLoadoutHovered);
78 
79  m_aLoadoutButtons.Insert(loadoutBtn);
80  }
81 
82  int itm = AddItem(loadoutEntry);
83  ShowPagingButtons(); // hack to go around hajkovinas
84 
85  return itm;
86  }
87 
88  override void ShowPagingButtons(bool animate = true)
89  {
90  bool show = (m_aWidgets.Count() > m_iCountShownItems);
91  if (m_PagingLeft)
92  m_PagingLeft.SetVisible(show, false);
93 
94  if (m_PagingRight)
95  m_PagingRight.SetVisible(show, false);
96  }
97 
98  protected void OnLoadoutClicked(notnull SCR_LoadoutButton loadoutBtn)
99  {
100  GetOnLoadoutClicked().Invoke(loadoutBtn);
101  }
102 
103  protected void OnLoadoutHovered(Widget btn)
104  {
105  SCR_LoadoutButton loadoutBtn = SCR_LoadoutButton.Cast(btn.FindHandler(SCR_LoadoutButton));
106  if (loadoutBtn)
107  GetOnLoadoutHovered().Invoke(loadoutBtn.GetLoadout());
108  }
109 
110  Widget GetContentRoot()
111  {
112  return m_wContentRoot;
113  }
114 
115  void SetSelected(SCR_BasePlayerLoadout loadout)
116  {
117  foreach (SCR_LoadoutButton loadoutBtn : m_aLoadoutButtons)
118  {
119  loadoutBtn.SetSelected(loadoutBtn.GetLoadout() == loadout)
120  }
121  }
122 
123  override void ClearAll()
124  {
125  super.ClearAll();
126  m_aLoadoutButtons.Clear();
127  }
128 
129  SCR_LoadoutButton GetButtonForLoadout(SCR_BasePlayerLoadout loadout)
130  {
131  foreach (SCR_LoadoutButton btn : m_aLoadoutButtons)
132  {
133  if (btn.GetLoadout() == loadout)
134  return btn;
135  }
136 
137  return null;
138  }
139 
140  ScriptInvoker GetOnLoadoutClicked()
141  {
142  if (!m_OnLoadoutClicked)
143  m_OnLoadoutClicked = new ScriptInvoker();
144 
145  return m_OnLoadoutClicked;
146  }
147 
148  ScriptInvoker GetOnLoadoutHovered()
149  {
150  if (!m_OnLoadoutHovered)
151  m_OnLoadoutHovered = new ScriptInvoker();
152 
153  return m_OnLoadoutHovered;
154  }
155 };
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
loadout
string loadout
Definition: SCR_ArsenalManagerComponent.c:2
SCR_LoadoutButton
Definition: SCR_LoadoutRequestUIComponent.c:487
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_PagingRight
protected SCR_PagingButtonComponent m_PagingRight
Definition: SCR_TabViewComponent.c:61
ScriptInvokerBool
ScriptInvokerBase< ScriptInvokerBoolMethod > ScriptInvokerBool
Definition: SCR_ScriptInvokerHelper.c:41
m_sActionLeft
string m_sActionLeft
Definition: SCR_TabViewComponent.c:40
m_aWidgets
ref array< Widget > m_aWidgets
Definition: SCR_UITaskManagerComponent.c:25
m_PagingLeft
protected SCR_PagingButtonComponent m_PagingLeft
Definition: SCR_TabViewComponent.c:60
SCR_BasePlayerLoadout
Definition: SCR_BasePlayerLoadout.c:2
m_sActionRight
string m_sActionRight
Definition: SCR_TabViewComponent.c:43