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