Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_SelectionMenuDisplay.c
Go to the documentation of this file.
1 
5 //------------------------------------------------------------------------------------------------
7 class SCR_SelectionMenuDisplay : SCR_InfoDisplayExtended
8 {
9  protected const float FADE_IN_SPEED = UIConstants.FADE_RATE_SUPER_FAST;
10 
11  [Attribute("", ".layout", desc: "Base layout that should be used for all entries that doesn't need custom layout.")]
12  protected ResourceName m_sEntryLayout;
13 
14  // Widget name refs
15  [Attribute("")]
16  protected string m_sEntriesParent;
17 
18  // Menu and entries
19  protected ref SCR_SelectionMenu m_Menu;
20 
21  protected ref array<SCR_SelectionMenuEntry> m_aEntries = {};
22  protected ref array<ref Widget> m_aEntryWidgets = {};
23 
24  protected SCR_SelectionMenuEntry m_LastSelectedEntry;
25  protected int m_iLastSelectedId = -1;
26 
27  // Widgets
28  protected Widget m_wEntriesParent;
29 
30  //------------------------------------------------------------------------------------------------
31  // Override
32  //------------------------------------------------------------------------------------------------
33 
34  //------------------------------------------------------------------------------------------------
37  void SetupMenu(SCR_SelectionMenu menu)
38  {
39  // Clear callbacks for previous menu
40  if (m_Menu)
41  {
42  m_Menu.GetOnOpen().Remove(OnMenuOpen);
43  m_Menu.GetOnClose().Remove(OnMenuClose);
44  m_Menu.GetOnUpdateEntries().Remove(OnMenuEntriesUpdate);
45  m_Menu.GetOnSelect().Remove(OnMenuEntrySelected);
46  m_Menu.GetOnPerform().Remove(OnMenuEntryPerform);
47  }
48 
49  // Register to new menu
50  m_Menu = menu;
51 
52  if (!m_Menu)
53  {
54  DebugPrint("DisplayInit", "No menu was found!");
55  return;
56  }
57 
58  // Listen to menu
59  m_Menu.GetOnOpen().Insert(OnMenuOpen);
60  m_Menu.GetOnClose().Insert(OnMenuClose);
61  m_Menu.GetOnUpdateEntries().Insert(OnMenuEntriesUpdate);
62  m_Menu.GetOnSelect().Insert(OnMenuEntrySelected);
63  m_Menu.GetOnPerform().Insert(OnMenuEntryPerform);
64  }
65 
66  //------------------------------------------------------------------------------------------------
68  override void DisplayStartDraw(IEntity owner)
69  {
70  super.DisplayStartDraw(owner);
71 
72  // Find widgets
73  m_wEntriesParent = GetRootWidget().FindAnyWidget(m_sEntriesParent);
74  }
75 
76  //------------------------------------------------------------------------------------------------
77  override void DisplayOnSuspended()
78  {
79  super.DisplayOnSuspended();
80 
81  if (m_Menu)
82  m_Menu.Close();
83  }
84 
85  //------------------------------------------------------------------------------------------------
86  // Custom
87  //------------------------------------------------------------------------------------------------
88 
89  //------------------------------------------------------------------------------------------------
91  protected void FindMenu() {}
92 
93  //------------------------------------------------------------------------------------------------
95  protected void CreateEntryWidgets()
96  {
97  if (!m_wEntriesParent)
98  {
99  DebugPrint("CreateEntryWidgets", "Can't create entries due to missing parent!");
100  return;
101  }
102 
103  if (!m_aEntries)
104  {
105  DebugPrint("CreateEntryWidgets", "Entries is null!");
106  return;
107  }
108 
109  for (int i = 0, count = m_aEntries.Count(); i < count; i++)
110  {
111  // Pick custom resource
112  ResourceName entryLayout = m_aEntries[i].GetCustomLayout();
113  if (entryLayout.IsEmpty())
114  entryLayout = m_sEntryLayout;
115 
116  // Create and setup
117  Widget entry = GetGame().GetWorkspace().CreateWidgets(entryLayout, m_wEntriesParent);
118  m_aEntryWidgets.Insert(entry);
119  SetupEntryWidget(m_aEntries[i], entry, i);
120 
121  // Setup component
123  entry.FindHandler(SCR_SelectionMenuEntryComponent));
124 
125  m_aEntries[i].SetEntryComponent(entryComponent);
126  }
127  }
128 
129  //------------------------------------------------------------------------------------------------
130  protected void CreateNewEntry(int i)
131  {
132  // Pick custom resource
133  ResourceName entryLayout = m_aEntries[i].GetCustomLayout();
134  if (entryLayout.IsEmpty())
135  entryLayout = m_sEntryLayout;
136 
137  // Create and setup
138  Widget entry = GetGame().GetWorkspace().CreateWidgets(m_sEntryLayout, m_wEntriesParent);
139  m_aEntryWidgets.Insert(entry);
140  //SetupEntryWidget(m_aEntries[i], entry, i);
141 
142  // Setup component
144  entry.FindHandler(SCR_SelectionMenuEntryComponent));
145 
146  m_aEntries[i].SetEntryComponent(entryComponent);
147  }
148 
149  //------------------------------------------------------------------------------------------------
150  protected void RemoveEntry(Widget entry, int id)
151  {
152  m_aEntryWidgets[id].RemoveFromHierarchy();
153  m_aEntryWidgets.RemoveItem(entry);
154  }
155 
156  //------------------------------------------------------------------------------------------------
160  protected void SetupEntryWidget(notnull SCR_SelectionMenuEntry entry, notnull Widget widget, int id){}
161 
162  //------------------------------------------------------------------------------------------------
164  protected void ClearEntryWidgets()
165  {
166  for (int i = 0, count = m_aEntryWidgets.Count(); i < count; i++)
167  {
168  m_aEntryWidgets[i].RemoveFromHierarchy();
169  }
170 
171  m_aEntryWidgets.Clear();
172  }
173 
174  //------------------------------------------------------------------------------------------------
176  protected bool EntriesChanged(array<ref SCR_SelectionMenuEntry> entries)
177  {
178  int prevCount = m_aEntries.Count();
179 
180  // Check entries count
181  if (prevCount == 0 || prevCount != entries.Count())
182  {
183  m_aEntries.Clear();
184  for (int i = 0, count = entries.Count(); i < count; i++)
185  {
186  m_aEntries.Insert(entries[i]);
187  }
188 
189  return true;
190  }
191 
192  // Fill up entries
193  array<SCR_SelectionMenuEntry> previousEntries = {};
194 
195  for (int i = 0; i < prevCount; i++)
196  {
197  previousEntries.Insert(m_aEntries[i]);
198  }
199 
200  m_aEntries.Clear();
201 
202  for (int i = 0, count = entries.Count(); i < count; i++)
203  {
204  m_aEntries.Insert(entries[i]);
205  }
206 
207  // Check if data is different
208  for (int i = 0, count = m_aEntries.Count(); i < count; i++)
209  {
210  if (previousEntries.IsEmpty() || !previousEntries.IsIndexValid(i))
211  return true;
212 
213  if (previousEntries[i] != m_aEntries[i])
214  return true;
215  }
216 
217  return false;
218  }
219 
220  //------------------------------------------------------------------------------------------------
221  // Callbacks
222  //------------------------------------------------------------------------------------------------
223 
224  //------------------------------------------------------------------------------------------------
225  protected void OnMenuOpen()
226  {
227  Show(true, FADE_IN_SPEED);
228 
229  ClearEntryWidgets();
230  CreateEntryWidgets();
231  }
232 
233  //------------------------------------------------------------------------------------------------
234  protected void OnMenuClose()
235  {
236  Show(false, UIConstants.FADE_RATE_FAST);
237  }
238 
239  //------------------------------------------------------------------------------------------------
240  protected void OnMenuEntriesUpdate(SCR_SelectionMenu menu, array<ref SCR_SelectionMenuEntry> entries)
241  {
242  // Update entries
243  if (EntriesChanged(entries))
244  {
245  ClearEntryWidgets();
246  CreateEntryWidgets();
247  }
248  }
249 
250  //------------------------------------------------------------------------------------------------
252  protected void OnMenuEntrySelected(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry, int id) {}
253 
254  //------------------------------------------------------------------------------------------------
256  protected void OnMenuEntryPerform(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry) {}
257 
258  //------------------------------------------------------------------------------------------------
259  // API
260  //------------------------------------------------------------------------------------------------
261 
262  //------------------------------------------------------------------------------------------------
263  SCR_SelectionMenu GetMenu()
264  {
265  return m_Menu;
266  }
267 
268  //------------------------------------------------------------------------------------------------
269  // Debug
270  //------------------------------------------------------------------------------------------------
271 
272  //------------------------------------------------------------------------------------------------
273  protected void DebugPrint(string method, string msg)
274  {
275  Print(string.Format("[SCR_SelectionMenuDisplay] - %1() - '%2'", method, msg), LogLevel.DEBUG);
276  }
277 };
UIConstants
Definition: Constants.c:130
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
GetRootWidget
Widget GetRootWidget()
Definition: SCR_UITaskManagerComponent.c:160
Show
override void Show(WorkspaceWidget pWorkspace, Widget pToolTipWidget, float desiredPosX, float desiredPosY)
Definition: SCR_ScriptedWidgetTooltip.c:55
SCR_SelectionMenu
Definition: SCR_SelectionMenu.c:6
m_aEntries
protected ref array< ref SCR_TextsTaskManagerEntry > m_aEntries
Definition: SCR_TextsTaskManagerComponent.c:3
Attribute
typedef Attribute
Post-process effect of scripted camera.
SCR_SelectionMenuEntryComponent
Definition: SCR_SelectionMenuEntryComponent.c:6
SCR_SelectionMenuDisplay
Definition: SCR_SelectionMenuDisplay.c:7
SCR_SelectionMenuEntry
Definition: SCR_SelectionMenuEntry.c:7
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468