9 protected const float FADE_IN_SPEED =
UIConstants.FADE_RATE_SUPER_FAST;
11 [
Attribute(
"",
".layout",
desc:
"Base layout that should be used for all entries that doesn't need custom layout.")]
12 protected ResourceName m_sEntryLayout;
16 protected string m_sEntriesParent;
21 protected ref array<SCR_SelectionMenuEntry> m_aEntries = {};
22 protected ref array<ref Widget> m_aEntryWidgets = {};
25 protected int m_iLastSelectedId = -1;
28 protected Widget m_wEntriesParent;
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);
54 DebugPrint(
"DisplayInit",
"No menu was found!");
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);
68 override void DisplayStartDraw(IEntity owner)
70 super.DisplayStartDraw(owner);
73 m_wEntriesParent =
GetRootWidget().FindAnyWidget(m_sEntriesParent);
77 override void DisplayOnSuspended()
79 super.DisplayOnSuspended();
91 protected void FindMenu() {}
95 protected void CreateEntryWidgets()
97 if (!m_wEntriesParent)
99 DebugPrint(
"CreateEntryWidgets",
"Can't create entries due to missing parent!");
105 DebugPrint(
"CreateEntryWidgets",
"Entries is null!");
109 for (
int i = 0, count =
m_aEntries.Count(); i < count; i++)
112 ResourceName entryLayout =
m_aEntries[i].GetCustomLayout();
113 if (entryLayout.IsEmpty())
114 entryLayout = m_sEntryLayout;
117 Widget entry =
GetGame().GetWorkspace().CreateWidgets(entryLayout, m_wEntriesParent);
118 m_aEntryWidgets.Insert(entry);
125 m_aEntries[i].SetEntryComponent(entryComponent);
130 protected void CreateNewEntry(
int i)
133 ResourceName entryLayout =
m_aEntries[i].GetCustomLayout();
134 if (entryLayout.IsEmpty())
135 entryLayout = m_sEntryLayout;
138 Widget entry =
GetGame().GetWorkspace().CreateWidgets(m_sEntryLayout, m_wEntriesParent);
139 m_aEntryWidgets.Insert(entry);
146 m_aEntries[i].SetEntryComponent(entryComponent);
150 protected void RemoveEntry(Widget entry,
int id)
152 m_aEntryWidgets[id].RemoveFromHierarchy();
153 m_aEntryWidgets.RemoveItem(entry);
164 protected void ClearEntryWidgets()
166 for (
int i = 0, count = m_aEntryWidgets.Count(); i < count; i++)
168 m_aEntryWidgets[i].RemoveFromHierarchy();
171 m_aEntryWidgets.Clear();
176 protected bool EntriesChanged(array<ref SCR_SelectionMenuEntry> entries)
181 if (prevCount == 0 || prevCount != entries.Count())
184 for (
int i = 0, count = entries.Count(); i < count; i++)
193 array<SCR_SelectionMenuEntry> previousEntries = {};
195 for (
int i = 0; i < prevCount; i++)
202 for (
int i = 0, count = entries.Count(); i < count; i++)
208 for (
int i = 0, count =
m_aEntries.Count(); i < count; i++)
210 if (previousEntries.IsEmpty() || !previousEntries.IsIndexValid(i))
225 protected void OnMenuOpen()
227 Show(
true, FADE_IN_SPEED);
230 CreateEntryWidgets();
234 protected void OnMenuClose()
240 protected void OnMenuEntriesUpdate(
SCR_SelectionMenu menu, array<ref SCR_SelectionMenuEntry> entries)
243 if (EntriesChanged(entries))
246 CreateEntryWidgets();
273 protected void DebugPrint(
string method,
string msg)
275 Print(
string.Format(
"[SCR_SelectionMenuDisplay] - %1() - '%2'", method, msg), LogLevel.DEBUG);