Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SelectionMenuDisplay.c
Go to the documentation of this file.
1
4
5//------------------------------------------------------------------------------------------------
7class 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.")]
13
14 // Widget name refs
15 [Attribute("")]
16 protected string m_sEntriesParent;
17
18 // Menu and entries
20
21 protected ref array<SCR_SelectionMenuEntry> m_aEntries = {};
22 protected ref array<ref Widget> m_aEntryWidgets = {};
23
25 protected int m_iLastSelectedId = -1;
26
27 // Widgets
29
30 //------------------------------------------------------------------------------------------------
31 // Override
32 //------------------------------------------------------------------------------------------------
33
34 //------------------------------------------------------------------------------------------------
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
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 {
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
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 {
247 }
248 }
249
250 //------------------------------------------------------------------------------------------------
252 protected void OnMenuEntrySelected(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry, int id) {}
253
254 //------------------------------------------------------------------------------------------------
257
258 //------------------------------------------------------------------------------------------------
259 // API
260 //------------------------------------------------------------------------------------------------
261
262 //------------------------------------------------------------------------------------------------
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};
AddonBuildInfoTool id
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
Widget GetRootWidget()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
void DebugPrint(string method, string msg)
void RemoveEntry(Widget entry, int id)
ref array< SCR_SelectionMenuEntry > m_aEntries
override void DisplayStartDraw(IEntity owner)
Setup menu.
void ClearEntryWidgets()
Remove all entries from HUD layout.
void SetupMenu(SCR_SelectionMenu menu)
void OnMenuEntrySelected(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry, int id)
React on selected entry change.
void OnMenuEntryPerform(SCR_SelectionMenu menu, SCR_SelectionMenuEntry entry)
React on selected entry change.
SCR_SelectionMenuEntry m_LastSelectedEntry
void FindMenu()
Method ready for override to find menu at custom place.
void OnMenuEntriesUpdate(SCR_SelectionMenu menu, array< ref SCR_SelectionMenuEntry > entries)
ref array< ref Widget > m_aEntryWidgets
void CreateEntryWidgets()
Will create entries in HUD layout.
void SetupEntryWidget(notnull SCR_SelectionMenuEntry entry, notnull Widget widget, int id)
bool EntriesChanged(array< ref SCR_SelectionMenuEntry > entries)
Check if used data are still same.
override void Show()
Definition gameLib.c:262
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
SCR_FieldOfViewSettings Attribute