Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_ActionsToolbarEditorUIComponent.c
Go to the documentation of this file.
1 //#define TOOLBAR_DEBUG
4 {
5  [Attribute(SCR_Enum.GetDefault(EEditorActionType.ACTION), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditorActionType))]
6  EEditorActionType m_ActionType;
7 
8  [Attribute(params: "layout")]
9  ResourceName m_Layout;
10 }
11 
13 
14 class SCR_ActionsToolbarEditorUIComponent : SCR_BaseToolbarEditorUIComponent
15 {
16  [Attribute()]
17  protected ref array<ref SCR_ActionsToolbarItemEditorUIComponent> m_aItemLayouts;
18 
19  [Attribute(params: "layout")]
20  protected ResourceName m_SeparatorLayout;
21 
23  protected ref array<ref SCR_EditorActionData> m_aActionData = {};
25  protected int m_iActionFlags;
26  protected ref map<Widget, SCR_BaseEditorAction> m_Actions = new map<Widget, SCR_BaseEditorAction>();
27 
28  //------------------------------------------------------------------------------------------------
29  protected Widget CreateItem(SCR_EditorActionData actionData)
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 
150  SCR_BaseEditorAction action;
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  {
162  EditorMenuBase menu = EditorMenuBase.Cast(GetMenu());
163  if (menu)
164  menu.CloseSelf();
165  }
166 
167  return false;
168  }
169 
170  //------------------------------------------------------------------------------------------------
171  override void HandlerAttachedScripted(Widget w)
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_BaseEditorAction
Definition: SCR_BaseEditorAction.c:24
SCR_BaseGameMode
Definition: SCR_BaseGameMode.c:137
SCR_ActionsToolbarItemEditorUIComponent
Definition: SCR_ActionsToolbarEditorUIComponent.c:3
m_iActionFlags
protected int m_iActionFlags
Definition: SCR_ActionsToolbarEditorUIComponent.c:25
SCR_Enum
Definition: SCR_Enum.c:1
m_aActionData
protected ref array< ref SCR_EditorActionData > m_aActionData
Definition: SCR_ActionsToolbarEditorUIComponent.c:23
EEditorActionType
EEditorActionType
Definition: SCR_BaseEditorAction.c:1
OnGlobalNightModeEnabledChanged
protected void OnGlobalNightModeEnabledChanged(bool enabled)
Definition: SCR_ActionsToolbarEditorUIComponent.c:130
SCR_BaseContainerCustomTitleEnum
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
Definition: SCR_CampaignHintStorage.c:22
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
SCR_ToolbarActionsEditorComponent
Definition: SCR_ToolbarActionsEditorComponent.c:6
ShowEntries
override protected void ShowEntries(Widget contentWidget, int indexStart, int indexEnd)
Definition: SCR_ActionsToolbarEditorUIComponent.c:68
CreateItem
protected Widget CreateItem(SCR_EditorActionData actionData)
Definition: SCR_ActionsToolbarEditorUIComponent.c:29
m_Actions
protected ref map< Widget, SCR_BaseEditorAction > m_Actions
Definition: SCR_ActionsToolbarEditorUIComponent.c:26
SCR_EditorActionData
Definition: SCR_BaseEditorAction.c:280
OnClick
override bool OnClick(Widget w, int x, int y, int button)
Definition: SCR_ActionsToolbarEditorUIComponent.c:143
GetGameMode
SCR_BaseGameMode GetGameMode()
Definition: SCR_BaseGameModeComponent.c:15
HandlerDeattached
override void HandlerDeattached(Widget w)
Definition: SCR_ActionsToolbarEditorUIComponent.c:213
GetMenu
SCR_RadialMenu GetMenu()
Definition: SCR_RadialMenuGameModeComponent.c:41
SCR_EditorToolbarAction
Definition: SCR_EditorToolbarAction.c:3
EditorMenuBase
Definition: EditorMenuBase.c:7
m_EditorActionsComponent
protected SCR_ToolbarActionsEditorComponent m_EditorActionsComponent
Definition: SCR_ActionsToolbarEditorUIComponent.c:22
Attribute
class SCR_ActionsToolbarItemEditorUIComponent Attribute()] protected ref array< ref SCR_ActionsToolbarItemEditorUIComponent > m_aItemLayouts
Post-process effect of scripted camera.
Refresh
override protected void Refresh()
Definition: SCR_ActionsToolbarEditorUIComponent.c:92
EEditorActionGroup
EEditorActionGroup
Definition: SCR_BaseEditorAction.c:7
SCR_BaseToolbarItemEditorUIComponent
Definition: SCR_BaseToolbarItemEditorUIComponent.c:1
m_SeparatorLayout
protected ResourceName m_SeparatorLayout
Definition: SCR_ActionsToolbarEditorUIComponent.c:20
params
Configs ServerBrowser KickDialogs params
Definition: SCR_NotificationSenderComponent.c:24
OnRepeat
override void OnRepeat()
Definition: SCR_ActionsToolbarEditorUIComponent.c:136
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
SCR_PlacingEditorComponent
Definition: SCR_PlacingEditorComponent.c:118
SCR_ActionToolbarItemEditorUIComponent
Definition: SCR_ActionToolbarItemEditorUIComponent.c:1
HandlerAttachedScripted
override void HandlerAttachedScripted(Widget w)
Definition: SCR_ActionsToolbarEditorUIComponent.c:171
BaseContainerProps
SCR_AIGoalReaction_Follow BaseContainerProps
Handles insects that are supposed to be spawned around selected prefabs defined in prefab names array...
Definition: SCR_AIGoalReaction.c:468
SCR_BaseToolbarEditorUIComponent
Definition: SCR_BaseToolbarEditorUIComponent.c:5
m_RepeatAction
protected SCR_BaseEditorAction m_RepeatAction
Definition: SCR_ActionsToolbarEditorUIComponent.c:24
SCR_EditorManagerEntity
Definition: SCR_EditorManagerEntity.c:26