Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CommandToolbarEditorUIComponent.c
Go to the documentation of this file.
1
2
4{
5 [Attribute("", uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditorActionGroup))]
6 protected ref array<EEditorActionGroup> m_ActionGroups;
7
8 [Attribute(params: "layout")]
10
13 protected ref array<ref SCR_EditorActionData> m_aActionData = {};
14 protected ref array<ref SCR_BaseEditorAction> m_aShortcuts = {};
16
17 bool m_queuedRefresh = false;
18 //------------------------------------------------------------------------------------------------
19 protected void CreateItem(SCR_EditorActionData actionData, int shortcutIndex)
20 {
21 Widget itemWidget;
23 if (!CreateItem(itemWidget, item))
24 return;
25
26 SCR_BaseEditorAction action = actionData.GetAction();
27 if (!action)
28 return;
29
31 if (actionItem)
32 actionItem.SetAction(action, itemWidget);
33
34 //--- Set shortcut reference - shown in GUI, but otherwise has no effect
35 action.SetShortcutRef(string.Format("EditorQuickCommand%1", shortcutIndex + 1));
36 m_aShortcuts.InsertAt(action, shortcutIndex);
37
38 m_Actions.Insert(itemWidget, action);
39 }
40
41 //------------------------------------------------------------------------------------------------
42 protected void OnEditorQuickCommand(int index)
43 {
44 if (m_aShortcuts.Count() >= index)
46 }
57 //protected void OnEditorQuickCommand11() { OnEditorQuickCommand(11); }
58 //protected void OnEditorQuickCommand12() { OnEditorQuickCommand(12); }
59
60 //------------------------------------------------------------------------------------------------
61 override protected void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
62 {
63 if (!GetGame().GetInputManager().IsUsingMouseAndKeyboard())
64 return;
65
66 int shortcutIndex;
67 indexEnd = Math.Min(indexEnd, m_aActionData.Count());
68 for (int i = indexStart; i < indexEnd; i++)
69 {
70 if (m_aActionData[i])
71 {
72 CreateItem(m_aActionData[i], shortcutIndex);
73 shortcutIndex++;
74 }
75 else if (i > indexStart && i < indexEnd - 1)
76 {
77 //--- Separator (not as first or last item)
78 GetGame().GetWorkspace().CreateWidgets(m_SeparatorLayout, m_ItemsWidget);
79 }
80 }
81 }
82
83 //Many actions can request a refresh for the GM toolbar, but we should only refresh it once per frame.
84 protected void QueueRefresh()
85 {
87 return;
88
89 GetGame().GetCallqueue().CallLater(Refresh);
90 m_queuedRefresh = true;
91 }
92 //------------------------------------------------------------------------------------------------
93 override protected void Refresh()
94 {
95 int actionFlags;
96 m_EditorActionsComponent.ValidateSelection(false);
97 int count = m_EditorActionsComponent.GetAndEvaluateActions(vector.Zero, m_aActionData, actionFlags);
98 m_aShortcuts.Clear();
99
100 //--- Filter by action group
101 for (int i = count - 1; i >= 0; i--)
102 {
103 if (!m_ActionGroups.Contains(m_aActionData[i].GetAction().GetActionGroup()))
104 {
105 m_aActionData.Remove(i);
106 count--;
107 }
108 }
109
110 //--- Add separators
112 {
113 EEditorActionGroup group, prevGroup;
114 for (int i = count - 1; i >= 0; i--)
115 {
116 group = m_aActionData[i].GetAction().GetActionGroup();
117 if (group != prevGroup)
118 {
119 m_aActionData.InsertAt(null, i + 1);
120 prevGroup = group;
121 if (i != count - 1)
122 count++;
123 }
124 }
125 }
126
127#ifdef WORKBENCH
128 int debugCount = DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_GUI_TOOLBAR_FILL);
129 if (count > 0 && debugCount > 0)
130 {
131 for (int i; i < debugCount; i++)
132 {
133 if (m_EditorActionsComponent.ActionCanBeShown(m_aActionData[i].GetAction(), vector.Zero, actionFlags))
134 m_aActionData.Insert(m_aActionData[i % count]);
135 }
136 count += debugCount;
137 }
138#endif
139
140 if (m_Pagination)
141 m_Pagination.SetEntryCount(count);
142
143 super.Refresh();
144
145 m_queuedRefresh = false;
146 }
147
148 //------------------------------------------------------------------------------------------------
152 protected void OnFilterChange(EEditableEntityState state, set<SCR_EditableEntityComponent> entitiesInsert, set<SCR_EditableEntityComponent> entitiesRemove)
153 {
154 QueueRefresh();
155 }
156
157 //------------------------------------------------------------------------------------------------
158 override bool IsUnique()
159 {
160 return false;
161 }
162
163 //------------------------------------------------------------------------------------------------
164 override void OnInputDeviceIsGamepad(bool isGamepad)
165 {
166 if (!isGamepad)
167 {
168 m_Filter.GetOnChanged().Insert(OnFilterChange);
169 QueueRefresh();
170 }
171 else
172 {
173 m_Filter.GetOnChanged().Remove(OnFilterChange);
175 }
176
177 super.OnInputDeviceIsGamepad(isGamepad);
178 }
179
180 //------------------------------------------------------------------------------------------------
181 override bool OnClick(Widget w, int x, int y, int button)
182 {
183 if (button != 0)
184 return false;
185
187 if (m_Actions.Find(w, action))
188 {
189 m_EditorActionsComponent.StartPlacing(action);
190 }
191 return false;
192 }
193
194 //------------------------------------------------------------------------------------------------
196 {
199 return;
200
201 m_Filter = SCR_BaseEditableEntityFilter.GetInstance(EEditableEntityState.COMMANDED, true); //--- ToDo: Don't hardcode
202 if (!m_Filter)
203 return;
204
205 //--- Assign quick commands (cannot be parametrized, the function would not know which input action called it)
206 InputManager inputManager = GetGame().GetInputManager();
207 inputManager.AddActionListener("EditorQuickCommand1", EActionTrigger.DOWN, OnEditorQuickCommand1);
208 inputManager.AddActionListener("EditorQuickCommand2", EActionTrigger.DOWN, OnEditorQuickCommand2);
209 inputManager.AddActionListener("EditorQuickCommand3", EActionTrigger.DOWN, OnEditorQuickCommand3);
210 inputManager.AddActionListener("EditorQuickCommand4", EActionTrigger.DOWN, OnEditorQuickCommand4);
211 inputManager.AddActionListener("EditorQuickCommand5", EActionTrigger.DOWN, OnEditorQuickCommand5);
212 inputManager.AddActionListener("EditorQuickCommand6", EActionTrigger.DOWN, OnEditorQuickCommand6);
213 inputManager.AddActionListener("EditorQuickCommand7", EActionTrigger.DOWN, OnEditorQuickCommand7);
214 inputManager.AddActionListener("EditorQuickCommand8", EActionTrigger.DOWN, OnEditorQuickCommand8);
215 inputManager.AddActionListener("EditorQuickCommand9", EActionTrigger.DOWN, OnEditorQuickCommand9);
216 inputManager.AddActionListener("EditorQuickCommand10", EActionTrigger.DOWN, OnEditorQuickCommand10);
217 //inputManager.AddActionListener("EditorQuickCommand11", EActionTrigger.DOWN, OnEditorQuickCommand11);
218 //inputManager.AddActionListener("EditorQuickCommand12", EActionTrigger.DOWN, OnEditorQuickCommand12);
219
220 OnInputDeviceIsGamepad(!GetGame().GetInputManager().IsUsingMouseAndKeyboard());
221
222 super.HandlerAttachedScripted(w);
223 }
224
225 //------------------------------------------------------------------------------------------------
226 override void HandlerDeattached(Widget w)
227 {
228 if (m_Filter)
229 m_Filter.GetOnChanged().Remove(OnFilterChange);
230
231 super.HandlerDeattached(w);
232 }
233}
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition DebugMenuID.c:4
ArmaReforgerScripted GetGame()
Definition game.c:1398
EEditorActionGroup
InputManager GetInputManager()
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Diagnostic and developer menu system.
Definition DiagMenu.c:18
Input management system for user interactions.
Definition Math.c:13
void SetAction(SCR_BaseEditorAction action, Widget widget)
static SCR_BaseEditableEntityFilter GetInstance(EEditableEntityState state, bool showError=false)
void SetShortcutRef(string shortcutRef)
SCR_ExternalPaginationUIComponent m_Pagination
ref map< Widget, SCR_BaseEditorAction > m_Actions
void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
void OnFilterChange(EEditableEntityState state, set< SCR_EditableEntityComponent > entitiesInsert, set< SCR_EditableEntityComponent > entitiesRemove)
ref array< ref SCR_BaseEditorAction > m_aShortcuts
void CreateItem(SCR_EditorActionData actionData, int shortcutIndex)
ref array< ref SCR_EditorActionData > m_aActionData
override bool OnClick(Widget w, int x, int y, int button)
SCR_CommandActionsEditorComponent m_EditorActionsComponent
Definition Types.c:486
EEditableEntityState
SCR_FieldOfViewSettings Attribute
EActionTrigger