Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_ActionsToolbarEditorUIComponent.c
Go to the documentation of this file.
1//#define TOOLBAR_DEBUG
5 [Attribute(SCR_Enum.GetDefault(EEditorActionType.ACTION), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditorActionType))]
7
8 [Attribute(params: "layout")]
10}
11
13
14class SCR_ActionsToolbarEditorUIComponent : SCR_BaseToolbarEditorUIComponent
15{
16 [Attribute()]
17 protected ref array<ref SCR_ActionsToolbarItemEditorUIComponent> m_aItemLayouts;
18
19 [Attribute(params: "layout")]
21
23 protected ref array<ref SCR_EditorActionData> m_aActionData = {};
25 protected int m_iActionFlags;
27
28 //------------------------------------------------------------------------------------------------
30 {
31 SCR_BaseEditorAction action = actionData.GetAction();
32 if (!action)
33 return null;
34
35 int itemLayoutCount = m_aItemLayouts.Count();
36 if (itemLayoutCount == 0)
37 return null;
38
39 //--- Use first configured layout as default
40 m_ItemLayout = m_aItemLayouts[0].m_Layout;
41
42 //--- Find actual layout
43 for (int i; i < itemLayoutCount; i++)
44 {
45 if (action.GetActionType() == m_aItemLayouts[i].m_ActionType)
46 {
47 m_ItemLayout = m_aItemLayouts[i].m_Layout;
48 break;
49 }
50 }
51
52 //--- Create layout
53 Widget itemWidget;
55 if (!CreateItem(itemWidget, item))
56 return null;
57
59 if (actionItem)
60 actionItem.SetAction(action, itemWidget);
61
62 itemWidget.SetName(action.Type().ToString());
63 m_Actions.Insert(itemWidget, action);
64 return itemWidget;
65 }
66
67 //------------------------------------------------------------------------------------------------
68 override protected void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
69 {
70 indexEnd = Math.Min(indexEnd, m_aActionData.Count());
71 for (int i = indexStart; i < indexEnd; i++)
72 {
73 if (m_aActionData[i])
74 {
75 //--- Action
76 if (m_EditorActionsComponent.ActionCanBeShown(m_aActionData[i].GetAction(), vector.Zero, m_iActionFlags))
77 {
78 Widget itemWidget = CreateItem(m_aActionData[i]);
79 if (itemWidget)
80 itemWidget.SetEnabled(m_EditorActionsComponent.ActionCanBePerformed(m_aActionData[i].GetAction(), vector.Zero, m_iActionFlags));
81 }
82 }
83 else if (i > indexStart && i < indexEnd - 1)
84 {
85 //--- Separator (not as first or last item)
86 GetGame().GetWorkspace().CreateWidgets(m_SeparatorLayout, m_ItemsWidget);
87 }
88 }
89 }
90
91 //------------------------------------------------------------------------------------------------
92 override protected void Refresh()
93 {
94 int count = m_EditorActionsComponent.GetAndEvaluateActions(vector.Zero, m_aActionData, m_iActionFlags);
95
96 //--- Add separators
97 EEditorActionGroup group, prevGroup;
98 for (int i = count - 1; i >= 0; i--)
99 {
100 group = m_aActionData[i].GetAction().GetActionGroup();
101 if (group != prevGroup)
102 {
103 m_aActionData.InsertAt(null, i + 1);
104 prevGroup = group;
105 if (i != count - 1)
106 count++;
107 }
108 }
109
110 #ifdef WORKBENCH
111 int debugCount = DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_GUI_TOOLBAR_FILL);
112 if (count > 0 && debugCount > 0)
113 {
114 for (int i; i < debugCount; i++)
115 {
116 m_aActionData.Insert(m_aActionData[i % count]);
117 }
118 count += debugCount;
119 }
120 #endif
121
122 if (m_Pagination)
123 m_Pagination.SetEntryCount(count);
124
125 super.Refresh();
126 }
127
128 //------------------------------------------------------------------------------------------------
129 //~ Called when nightmode enabled changed to make sure the nightmode action is hidden if global night mode is enabled
130 protected void OnGlobalNightModeEnabledChanged(bool enabled)
131 {
132 Refresh();
133 }
134
135 //------------------------------------------------------------------------------------------------
136 override void OnRepeat()
137 {
138 if (m_RepeatAction)
139 m_EditorActionsComponent.ActionPerformInstantly(m_RepeatAction);
140 }
141
142 //------------------------------------------------------------------------------------------------
143 override bool OnClick(Widget w, int x, int y, int button)
144 {
145 super.OnClick(w, x, y, button);
146
147 if (button != 0)
148 return false;
149
151 if (m_Actions.Find(w, action))
152 {
153 m_EditorActionsComponent.ActionPerformInstantly(action);
154
155 SCR_ActionsToolbarEditorUIComponent linkedComponent = SCR_ActionsToolbarEditorUIComponent.Cast(m_LinkedComponent);
156 if (linkedComponent)
157 linkedComponent.m_RepeatAction = action;
158 }
159
160 if (m_bIsInDialog)
161 {
163 if (menu)
164 menu.CloseSelf();
165 }
166
167 return false;
168 }
169
170 //------------------------------------------------------------------------------------------------
172 {
175 return;
176
177 //--- Initialize all actions
178 array<SCR_BaseEditorAction> actions = {};
179 SCR_EditorToolbarAction toolbarAction;
180 for (int i = 0, count = m_EditorActionsComponent.GetActions(actions); i < count; i++)
181 {
182 toolbarAction = SCR_EditorToolbarAction.Cast(actions[i]);
183 if (toolbarAction)
184 toolbarAction.OnInit(this);
185 }
186
187 //--- ToDo: Don't hardcode, but allow each action to set its refresh event
189 if (placingManager)
190 placingManager.GetOnSelectedPrefabChange().Insert(Refresh);
191
192 SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
193 if (editorManager)
194 {
195 editorManager.GetOnCanEndGameChanged().Insert(Refresh);
196 editorManager.GetOnLimitedChange().Insert(Refresh);
197 }
198
200 if (gameMode)
201 {
202 gameMode.GetOnGameModeEnd().Insert(Refresh);
203
204 SCR_NightModeGameModeComponent nightModeComponent = SCR_NightModeGameModeComponent.Cast(gameMode.FindComponent(SCR_NightModeGameModeComponent));
205 if (nightModeComponent)
206 nightModeComponent.GetOnGlobalNightModeEnabledChanged().Insert(OnGlobalNightModeEnabledChanged);
207 }
208
209 super.HandlerAttachedScripted(w);
210 }
211
212 //------------------------------------------------------------------------------------------------
213 override void HandlerDeattached(Widget w)
214 {
215 super.HandlerDeattached(w);
216
217 //--- Terminate all actions
219 {
220 array<SCR_BaseEditorAction> actions = {};
221 SCR_EditorToolbarAction toolbarAction;
222 for (int i = 0, count = m_EditorActionsComponent.GetActions(actions); i < count; i++)
223 {
224 toolbarAction = SCR_EditorToolbarAction.Cast(actions[i]);
225 if (toolbarAction)
226 toolbarAction.OnExit(this);
227 }
228 }
229
231 if (placingManager)
232 placingManager.GetOnSelectedPrefabChange().Remove(Refresh);
233
234 SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
235 if (editorManager)
236 {
237 editorManager.GetOnCanEndGameChanged().Remove(Refresh);
238 editorManager.GetOnLimitedChange().Remove(Refresh);
239 }
240
242 if (gameMode)
243 {
244 gameMode.GetOnGameModeEnd().Remove(Refresh);
245
246 SCR_NightModeGameModeComponent nightModeComponent = SCR_NightModeGameModeComponent.Cast(gameMode.FindComponent(SCR_NightModeGameModeComponent));
247 if (nightModeComponent)
248 nightModeComponent.GetOnGlobalNightModeEnabledChanged().Remove(OnGlobalNightModeEnabledChanged);
249 }
250 }
251}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
void OnGlobalNightModeEnabledChanged(bool enabled)
ref map< Widget, SCR_BaseEditorAction > m_Actions
SCR_ToolbarActionsEditorComponent m_EditorActionsComponent
ResourceName m_Layout
EEditorActionType m_ActionType
ref array< ref SCR_EditorActionData > m_aActionData
ResourceName m_SeparatorLayout
SCR_BaseEditorAction m_RepeatAction
EEditorActionType
EEditorActionGroup
SCR_BaseGameMode GetGameMode()
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
override void HandlerAttachedScripted(Widget w)
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
bool Refresh()
void OnClick()
On click callback.
SCR_RadialMenu GetMenu()
override void HandlerDeattached(Widget w)
Diagnostic and developer menu system.
Definition DiagMenu.c:18
Definition Math.c:13
void SetAction(SCR_BaseEditorAction action, Widget widget)
EEditorActionType GetActionType()
ScriptInvoker GetOnGameModeEnd()
bool CreateItem(out Widget itemWidget, out SCR_BaseToolbarItemEditorUIComponent toolbarItem)
void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
Definition Types.c:486
SCR_FieldOfViewSettings Attribute
class SCR_ActionsToolbarItemEditorUIComponent Attribute()] protected ref array< ref SCR_ActionsToolbarItemEditorUIComponent > m_aItemLayouts