Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_PlayMenuComponent.c
Go to the documentation of this file.
1 class SCR_PlayMenuComponent : ScriptedWidgetComponent
2 {
3  [Attribute("3")]
4  protected int m_iColumns;
5  [Attribute("1")]
6  protected int m_iRows;
7 
8  protected int m_iItems;
9  protected int m_iSelectedItem;
10 
11  [Attribute("2")]
12  protected int m_iPaddingHorizontal;
13  [Attribute("2")]
14  protected int m_iPaddingVertical;
15 
16  [Attribute("{4FFBD0D5E9A5ED50}UI/layouts/Menus/PlayMenu/PlayMenuTile_Recent.layout", UIWidgets.ResourceNamePicker, "", "layout")]
17  protected ResourceName m_sItemLayout;
18 
19  [Attribute("0.2")]
20  protected float m_fAnimationTime;
21 
22  protected ref array<Widget> m_aWidgets = {};
23  protected GridLayoutWidget m_wContentRoot;
24  protected Widget m_wRoot;
25  protected float m_fAnimationRate = SCR_WLibComponentBase.START_ANIMATION_RATE;
26 
27  //------------------------------------------------------------------------------------------------
28  override void HandlerAttached(Widget w)
29  {
30  m_wRoot = w;
31  m_wContentRoot = GridLayoutWidget.Cast(w.FindAnyWidget("Content"));
32 
33  if (!m_wContentRoot)
34  return;
35 
36  m_iItems = m_iColumns * m_iRows;
37 
38  if (m_iItems == 0)
39  return;
40 
41  // Convert time to animation speed
42  GetGame().GetCallqueue().CallLater(SetAnimationRate, SCR_WLibComponentBase.START_ANIMATION_PERIOD);
43 
44  CreateWidgets(m_iColumns, m_iRows);
45 
46  m_iSelectedItem = 0;
47  SetFocusedItem(m_iSelectedItem);
48  }
49 
50  //------------------------------------------------------------------------------------------------
51  protected void CreateWidgets(int columns, int rows)
52  {
53  if (!m_wContentRoot)
54  return;
55 
56  // Delete old widgets
57  foreach (Widget w: m_aWidgets)
58  {
59  if (w)
60  w.RemoveFromHierarchy();
61  }
62  m_aWidgets.Clear();
63 
64  // Create new grid tile widgets
65  for (int r = 0; r < rows; r++)
66  {
67  for (int c = 0; c < columns; c++)
68  {
69  CreateWidget(c, r);
70  }
71  }
72  }
73 
74  //------------------------------------------------------------------------------------------------
75  protected Widget CreateWidget(int column, int row)
76  {
77  if (!m_wContentRoot)
78  return null;
79 
80  Widget w = GetGame().GetWorkspace().CreateWidgets(m_sItemLayout, m_wContentRoot);
81  if (!w)
82  return null;
83 
84  GridSlot.SetColumn(w, column);
85  GridSlot.SetRow(w, row);
86  m_wContentRoot.SetRowFillWeight(row, 1);
87  m_wContentRoot.SetColumnFillWeight(column, 1);
88 
89  // Listen on focus event
91  if (!comp)
92  {
93  comp = new SCR_EventHandlerComponent();
94  w.AddHandler(comp);
95  }
96  comp.GetOnFocus().Insert(OnItemFocused);
97 
98  // Check if root is actually a button
99  ButtonWidget button = ButtonWidget.Cast(w);
100 
101  if (!button)
102  Print("Gallery element root has to be a button, otherwise interactivity will not work", LogLevel.WARNING);
103 
104  // Apply spacing
105  int left, top, right, bottom;
106 
107  if (column > 0)
108  left = m_iPaddingHorizontal;
109 
110  if (column < m_iColumns - 1)
111  right = m_iPaddingHorizontal;
112 
113  if (row > 0)
114  top = m_iPaddingVertical;
115 
116  if (row < m_iRows - 1)
117  bottom = m_iPaddingVertical;
118 
119  AlignableSlot.SetPadding(w, left, top, right, bottom);
120 
121  m_aWidgets.Insert(w);
122 
123  return w;
124  }
125 
126  //------------------------------------------------------------------------------------------------
127  protected void SetAnimationRate()
128  {
129  if (m_fAnimationTime <= 0)
130  m_fAnimationRate = 1000;
131  else
132  m_fAnimationRate = 1 / m_fAnimationTime;
133  }
134 
135  //------------------------------------------------------------------------------------------------
136  void OnItemFocused(Widget w)
137  {
138  m_iSelectedItem = m_aWidgets.Find(w);
139  }
140 
141  //------------------------------------------------------------------------------------------------
142  void SetFocusedItem(int index)
143  {
144  if (!m_aWidgets.IsIndexValid(index))
145  return;
146 
147  Widget w = m_aWidgets[index];
148 
149  if (!w.IsEnabled())
150  return;
151 
152  GetGame().GetWorkspace().SetFocusedWidget(w);
153  m_iSelectedItem = index;
154  }
155 
156  //------------------------------------------------------------------------------------------------
157  array<Widget> GetWidgets()
158  {
159  return m_aWidgets;
160  }
161 
162  //------------------------------------------------------------------------------------------------
165  static SCR_PlayMenuComponent GetComponent(string name, Widget parent, bool searchAllChildren = true)
166  {
167  if (!parent || name == string.Empty)
168  return null;
169 
170  Widget w;
171  if (searchAllChildren)
172  w = parent.FindAnyWidget(name);
173  else
174  w = parent.FindWidget(name);
175 
176  if (!w)
177  return null;
178 
179  return SCR_PlayMenuComponent.Cast(w.FindHandler(SCR_PlayMenuComponent));
180  }
181 };
m_wRoot
protected Widget m_wRoot
Definition: SCR_ScenarioFrameworkLayerTaskDefend.c:59
SCR_WLibComponentBase
Base class for all final Reforger interactive elements.
Definition: SCR_WLibComponentBase.c:4
SCR_PlayMenuComponent
Definition: SCR_PlayMenuComponent.c:1
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_EventHandlerComponent
Definition: SCR_EventHandlerComponent.c:5
m_aWidgets
ref array< Widget > m_aWidgets
Definition: SCR_UITaskManagerComponent.c:25
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17