Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_BaseActionsEditorComponent.c
Go to the documentation of this file.
3{
4 [Attribute(SCR_Enum.GetDefault(EEditorActionGroup.NONE), uiwidget: UIWidgets.ComboBox, enums: ParamEnumArray.FromEnum(EEditorActionGroup))]
5 EEditorActionGroup m_ActionGroup;
6
7 [Attribute()]
8 int m_iOrder;
9
10 ref SCR_SortedArray<SCR_BaseEditorAction> m_aActions;
11}
12
13[BaseContainerProps(configRoot: true)]
14class SCR_EditorActionList
16 [Attribute(desc: "Editor actions")]
17 ref array<ref SCR_BaseEditorAction> m_Actions;
19
21{
22 [Attribute(desc: "Editor actions", category: "Editor Actions")]
23 protected ref array<ref SCR_EditorActionList> m_ActionsLists;
24
25 [Attribute(desc: "Editor action groups", category: "Editor Actions")]
26 protected ref array<ref SCR_EditorActionGroup> m_ActionGroups;
27
28 protected ref array<SCR_BaseEditorAction> m_ActionsSorted = {};
29
30 //------------------------------------------------------------------------------------------------
34 int GetActions(out notnull array<SCR_BaseEditorAction> outActions)
35 {
36 return outActions.Copy(m_ActionsSorted);
37 }
38
39 //------------------------------------------------------------------------------------------------
44 {
45 if (!m_ActionsSorted.IsIndexValid(index))
46 return null;
47
48 return m_ActionsSorted[index];
49 }
50
51 //------------------------------------------------------------------------------------------------
56 {
57 return m_ActionsSorted.Find(action);
58 }
59
60 //------------------------------------------------------------------------------------------------
63 void SetShortcuts(SCR_BaseActionsEditorComponent manager, bool toAdd)
64 {
65 if (toAdd)
66 {
67 foreach (SCR_BaseEditorAction action : m_ActionsSorted)
68 {
69 action.AddShortcut(manager);
70 }
71 }
72 else
73 {
74 foreach (SCR_BaseEditorAction action : m_ActionsSorted)
75 {
76 action.RemoveShortcut();
77 }
78 }
79 }
80
81 //---- REFACTOR NOTE START: Sorting might be done simpler and easir to read?
82
83 //------------------------------------------------------------------------------------------------
84 // constructor
87 {
88 if (!m_ActionGroups || m_ActionGroups.IsEmpty())
89 {
90 //--- No action groups defined
92 SCR_SortedArray<SCR_BaseEditorAction> actionsSorted = new SCR_SortedArray<SCR_BaseEditorAction>();
93 foreach (SCR_EditorActionList list: m_ActionsLists)
94 {
95 for (int i = 0, count = list.m_Actions.Count(); i < count; i++)
96 {
97 action = list.m_Actions[i];
98 if (action.IsEnabled())
99 actionsSorted.Insert(action.GetOrder(), action);
100 }
101 }
102 actionsSorted.ToArray(m_ActionsSorted);
103 }
104 else
105 {
106 //--- Action groups defined, use them for sorting
107 SCR_EditorActionGroup actionGroup;
108 SCR_SortedArray<SCR_EditorActionGroup> actionGroupsSorted = new SCR_SortedArray<SCR_EditorActionGroup>();
110 int actionGroupCount = m_ActionGroups.Count();
111 for (int g = 0; g < actionGroupCount; g++)
112 {
113 actionGroup = m_ActionGroups[g];
114 actionGroup.m_aActions = new SCR_SortedArray<SCR_BaseEditorAction>();
115 actionGroupsSorted.Insert(actionGroup.m_iOrder, actionGroup);
116 actionGroupsMap.Insert(actionGroup.m_ActionGroup, actionGroup);
117 }
118
119 //--- Put actions to their groups
121 foreach (SCR_EditorActionList list: m_ActionsLists)
122 {
123 for (int a = 0, count = list.m_Actions.Count(); a < count; a++)
124 {
125 action = list.m_Actions[a];
126 if (action.IsEnabled())
127 {
128 if (actionGroupsMap.Find(action.GetActionGroup(), actionGroup))
129 actionGroup.m_aActions.Insert(action.GetOrder(), action);
130 else
131 Debug.Error2("SCR_BaseActionsEditorComponentClass.SCR_BaseActionsEditorComponentClass()", string.Format("Cannot register action %1, its group %2 is not configured!", Type(), typename.EnumToString(EEditorActionGroup, action.GetActionGroup())));
132 }
133 }
134 }
135
136 //--- Create array sorted by groups and order indexes
137 for (int g; g < actionGroupCount; g++)
138 {
139 actionGroup = actionGroupsSorted[g];
140 for (int a, actionCount = actionGroup.m_aActions.Count(); a < actionCount; a++)
141 {
142 m_ActionsSorted.Insert(actionGroup.m_aActions[a]);
143 }
144 }
145 }
146 m_ActionGroups = null;
147 }
148
149 //---- REFACTOR NOTE END ----
150}
151
152class SCR_BaseActionsEditorComponent : SCR_BaseEditorComponent
153{
157
159 protected ref set<SCR_EditableEntityComponent> m_SelectedEntities = new set<SCR_EditableEntityComponent>();
160
161 //------------------------------------------------------------------------------------------------
167
168 //------------------------------------------------------------------------------------------------
172 int GetActions(out notnull array<SCR_BaseEditorAction> actions)
173 {
174 SCR_BaseActionsEditorComponentClass prefabData = SCR_BaseActionsEditorComponentClass.Cast(GetEditorComponentData());
175 if (prefabData)
176 return prefabData.GetActions(actions);
177 else
178 return 0;
179 }
180
181 //------------------------------------------------------------------------------------------------
188 void EvaluateActions(notnull array<SCR_BaseEditorAction> actions, vector cursorWorldPosition, out notnull array<ref SCR_EditorActionData> filteredActions, out int flags = 0)
189 {
190 filteredActions.Clear();
191
192 flags |= ValidateSelection(false);
193
194 foreach (SCR_BaseEditorAction action : actions)
195 {
196 if (!ActionCanBeShown(action, cursorWorldPosition, flags))
197 continue;
198
199 bool canBePerformed = ActionCanBePerformed(action, cursorWorldPosition, flags);
200
201 filteredActions.Insert(new SCR_EditorActionData(action, canBePerformed));
202 }
203 }
204
205 //------------------------------------------------------------------------------------------------
211 int GetAndEvaluateActions(vector cursorWorldPosition, out notnull array<ref SCR_EditorActionData> filteredActions, out int flags = 0)
212 {
213 array<SCR_BaseEditorAction> actions = {};
214 GetActions(actions);
215 EvaluateActions(actions, cursorWorldPosition, filteredActions, flags);
216 return filteredActions.Count();
217 }
218
219 //------------------------------------------------------------------------------------------------
224 protected int ValidateSelection(bool isInstant)
225 {
226 return 0;
227 }
228
229 //------------------------------------------------------------------------------------------------
235 bool ActionCanBeShown(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags)
236 {
237 return false;
238 }
239
240 //------------------------------------------------------------------------------------------------
246 bool ActionCanBePerformed(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags)
247 {
248 return true;
249 }
250
251 //------------------------------------------------------------------------------------------------
256 {
257 flags |= ValidateSelection(true);
258
259 vector cursorWorldPosition;
261 m_MenuLayoutManager.GetCursorWorldPos(cursorWorldPosition, GetInstantActionTraceFlags()); //--- ToDo: Handle in UI scripts?
262
263 if (ActionCanBePerformed(action, cursorWorldPosition, flags))
264 ActionPerformInstantlyNoDialog(action, cursorWorldPosition, flags);
265 }
266
267 //------------------------------------------------------------------------------------------------
268 protected void ActionPerformInstantlyNoDialog(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags = 0)
269 {
270 //--- Editor closed while waiting, terminate the loop
271 if (!SCR_EditorManagerEntity.IsOpenedInstance())
272 return;
273
274 //--- Keep waiting until no dialog is open
275 if (GetGame().GetMenuManager().IsAnyDialogOpen())
276 GetGame().GetCallqueue().CallLater(ActionPerformInstantlyNoDialog, 1, false, action, cursorWorldPosition, flags);
277 else
278 ActionPerform(action, cursorWorldPosition, flags);
279 }
280
281 //------------------------------------------------------------------------------------------------
283 {
284 return -1;
285 }
286
287 //------------------------------------------------------------------------------------------------
292 void ActionPerform(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags)
293 {
294 int param = action.GetParam();
295
296 //~ Check if on cooldown and set cooldown if any. Always checked locally
297 if (action.CheckAndSetCooldown())
298 return;
299
300 // If action requires execution on server and role is proxy/client, send action to server
301 if (action.IsServer() && m_RplComponent.Role() == RplRole.Proxy)
302 {
303 ActionPerformRpc(action, cursorWorldPosition, flags, param);
304 }
305 else
306 {
307 ActionPerform(action, m_HoveredEntity, m_SelectedEntities, cursorWorldPosition, flags, param);
308 ActionPerformLocal(action, m_HoveredEntity, m_SelectedEntities, cursorWorldPosition, flags, param);
309 }
310 }
311
312 //------------------------------------------------------------------------------------------------
313 protected void ActionPerformRpc(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags, int param = -1)
314 {
315 SCR_BaseActionsEditorComponentClass prefabData = SCR_BaseActionsEditorComponentClass.Cast(GetEditorComponentData());
316 if (!prefabData)
317 return;
318
319 int actionIndex = prefabData.FindAction(action);
320 if (actionIndex == -1)
321 return;
322
323 RplId hoveredEntityID = -1;
324 array<RplId> selectedEntityIds = {};
325 SerializeEntities(hoveredEntityID, selectedEntityIds);
326
327 Rpc(ActionPerformServer, actionIndex, hoveredEntityID, selectedEntityIds, cursorWorldPosition, flags, param);
328 }
329
330 //------------------------------------------------------------------------------------------------
331 protected void ActionPerform(SCR_BaseEditorAction action, SCR_EditableEntityComponent hoveredEntityComponent, set<SCR_EditableEntityComponent> selectedEntityComponents, vector cursorWorldPosition, int flags, int param)
332 {
333 action.Perform(hoveredEntityComponent, selectedEntityComponents, cursorWorldPosition, flags, param);
334 }
335
336 //------------------------------------------------------------------------------------------------
337 protected void ActionPerformLocal(SCR_BaseEditorAction action, SCR_EditableEntityComponent hoveredEntityComponent, set<SCR_EditableEntityComponent> selectedEntityComponents, vector cursorWorldPosition, int flags, int param)
338 {
339 action.PerformOwner(m_HoveredEntity, m_SelectedEntities, cursorWorldPosition, flags, param);
340
341 SCR_BaseEditorEffect.Activate(action.GetEffects(), this, cursorWorldPosition, selectedEntityComponents);
342 }
343
344 //------------------------------------------------------------------------------------------------
352 [RplRpc(RplChannel.Reliable, RplRcver.Server)]
353 protected void ActionPerformServer(int actionIndex, RplId hoveredEntityID, array<RplId> selectedEntityIds, vector cursorWorldPosition, int flags, int param)
354 {
355 SCR_BaseActionsEditorComponentClass prefabData = SCR_BaseActionsEditorComponentClass.Cast(GetEditorComponentData());
356 if (!prefabData)
357 return;
358
359 SCR_BaseEditorAction action = prefabData.GetAction(actionIndex);
360 if (!action)
361 {
362 Print("Action with index: " + actionIndex + " not found on server", LogLevel.ERROR);
363 return;
364 }
365
366 SCR_EditableEntityComponent hoveredEntityComponent;
367 set<SCR_EditableEntityComponent> selectedEntityComponents = new set<SCR_EditableEntityComponent>;
368 DeSerializeEntities(hoveredEntityID, selectedEntityIds, hoveredEntityComponent, selectedEntityComponents);
369
370 if (!action.CanBeShown(hoveredEntityComponent, selectedEntityComponents, cursorWorldPosition, flags))
371 return;
372
373 if (!action.CanBePerformed(hoveredEntityComponent, selectedEntityComponents, cursorWorldPosition, flags))
374 return;
375
376 ActionPerform(action, hoveredEntityComponent, selectedEntityComponents, cursorWorldPosition, flags, param);
377
378 Rpc(ActionPerformOwner, actionIndex, cursorWorldPosition, flags, param);
379 }
380
381 //------------------------------------------------------------------------------------------------
383 [RplRpc(RplChannel.Reliable, RplRcver.Owner)]
384 protected void ActionPerformOwner(int actionIndex, vector cursorWorldPosition, int flags, int param)
385 {
386 SCR_BaseActionsEditorComponentClass prefabData = SCR_BaseActionsEditorComponentClass.Cast(GetEditorComponentData());
387 if (!prefabData)
388 return;
389
390 SCR_BaseEditorAction action = prefabData.GetAction(actionIndex);
391 if (!action)
392 {
393 Print("Action with index: " + actionIndex + " returned from server, not found on client", LogLevel.ERROR);
394 return;
395 }
396 ActionPerformLocal(action, m_HoveredEntity, m_SelectedEntities, cursorWorldPosition, flags, param);
397 }
398
399 //------------------------------------------------------------------------------------------------
400 private void SerializeEntities(out RplId hoveredEntityId, out array<RplId> selectedEntityIds)
401 {
402 // Serialize hovered entity to RplId int
403 if (m_HoveredEntity)
404 {
405 if (!GetRplIdFromEditableEntity(m_HoveredEntity, hoveredEntityId))
406 {
407 Print("Entity " + m_HoveredEntity.GetDisplayName() + " does not have replication component or is not registered for replication", LogLevel.WARNING);
408 }
409 }
410
411 // Serialize selected entities to RplId int array
412 foreach (SCR_EditableEntityComponent selectedEntity : m_SelectedEntities)
413 {
414 if (!selectedEntity)
415 {
416 continue;
417 }
418 RplId selectedEntityId;
419 if (!GetRplIdFromEditableEntity(selectedEntity, selectedEntityId))
420 {
421 Print("Entity " + selectedEntity.GetDisplayName() + " does not have replication component or is not registered for replication", LogLevel.WARNING);
422 continue;
423 }
424 selectedEntityIds.Insert(selectedEntityId);
425 }
426 }
427
428 //------------------------------------------------------------------------------------------------
429 private bool GetRplIdFromEditableEntity(SCR_EditableEntityComponent entity, out RplId entityRplId)
430 {
431 entityRplId = Replication.FindItemId(entity);
432 return entityRplId != -1;
433 }
434
435 //------------------------------------------------------------------------------------------------
436 private void DeSerializeEntities(RplId hoveredEntityId, array<RplId> selectedEntityIds, out SCR_EditableEntityComponent hoveredEntityComponent, out set<SCR_EditableEntityComponent> selectedEntityComponents)
437 {
438 // Deserialize hovered entity RplId
439 if (hoveredEntityId != -1)
440 {
441 if (!GetEditableEntityFromRplId(hoveredEntityId, hoveredEntityComponent))
442 Print(string.Format("Hovered entity with RplID: %1 not found on server", hoveredEntityId), LogLevel.NORMAL);
443 }
444
445 // Deserialize selected entity RplIds
446 foreach (RplId selectedEntityRplId : selectedEntityIds)
447 {
448 SCR_EditableEntityComponent selectedEntityComponent;
449 if (!GetEditableEntityFromRplId(selectedEntityRplId, selectedEntityComponent))
450 {
451 Print(string.Format("Selected entity with RplID: %1 not found on server", selectedEntityRplId), LogLevel.NORMAL );
452 continue;
453 }
454 selectedEntityComponents.Insert(selectedEntityComponent);
455 }
456 }
457
458 //------------------------------------------------------------------------------------------------
459 private bool GetEditableEntityFromRplId(RplId entityRplId, out SCR_EditableEntityComponent editableEntityComponent)
460 {
461 Managed entityComponent = Replication.FindItem(entityRplId);
462 if (!entityComponent)
463 {
464 Print(string.Format("Entity with RplID: %1 not found on server", entityRplId), LogLevel.NORMAL);
465 return false;
466 }
467
468 editableEntityComponent = SCR_EditableEntityComponent.Cast(entityComponent);
469 return editableEntityComponent != null;
470 }
471
472 //------------------------------------------------------------------------------------------------
473 override void EOnEditorActivate()
474 {
475 SCR_BaseActionsEditorComponentClass prefabData = SCR_BaseActionsEditorComponentClass.Cast(GetEditorComponentData());
476 if (!prefabData)
477 return;
478
479 SCR_EntitiesManagerEditorComponent entitiesManager = SCR_EntitiesManagerEditorComponent.Cast(SCR_EntitiesManagerEditorComponent.GetInstance(SCR_EntitiesManagerEditorComponent));
480 if (entitiesManager)
481 {
482 m_HoverManager = entitiesManager.GetFilter(EEditableEntityState.HOVER);
483 m_SelectedManager = entitiesManager.GetFilter(EEditableEntityState.SELECTED);
484 }
485
486 m_MenuLayoutManager = SCR_MenuLayoutEditorComponent.Cast(SCR_MenuLayoutEditorComponent.GetInstance(SCR_MenuLayoutEditorComponent));
487
488 prefabData.SetShortcuts(this, true);
489 }
490
491 //------------------------------------------------------------------------------------------------
492 override void EOnEditorDeactivate()
493 {
494 SCR_BaseActionsEditorComponentClass prefabData = SCR_BaseActionsEditorComponentClass.Cast(GetEditorComponentData());
495 if (!prefabData)
496 return;
497
498 prefabData.SetShortcuts(this, false);
499 }
500}
SCR_EAIThreatSectorFlags flags
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
void EOnEditorActivate()
ref map< Widget, SCR_BaseEditorAction > m_Actions
override void EOnEditorDeactivate()
SCR_BaseActionsEditorComponentClass m_HoverManager
bool ActionCanBePerformed(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags)
void ActionPerformInstantlyNoDialog(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags=0)
SCR_EditableEntityComponent m_HoveredEntity
void ActionPerformInstantly(SCR_BaseEditorAction action, int flags=0)
SCR_MenuLayoutEditorComponent m_MenuLayoutManager
void ActionPerformRpc(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags, int param=-1)
int ValidateSelection(bool isInstant)
void ActionPerformServer(int actionIndex, RplId hoveredEntityID, array< RplId > selectedEntityIds, vector cursorWorldPosition, int flags, int param)
bool ActionCanBeShown(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags)
SCR_BaseEditableEntityFilter m_SelectedManager
void ActionPerform(SCR_BaseEditorAction action, vector cursorWorldPosition, int flags)
SCR_EditableEntityComponent GetHoveredEntity()
void ActionPerformLocal(SCR_BaseEditorAction action, SCR_EditableEntityComponent hoveredEntityComponent, set< SCR_EditableEntityComponent > selectedEntityComponents, vector cursorWorldPosition, int flags, int param)
void ActionPerformOwner(int actionIndex, vector cursorWorldPosition, int flags, int param)
Server callback for when action is executed succesfully, calls PerformOwner function on action for e....
int GetAndEvaluateActions(vector cursorWorldPosition, out notnull array< ref SCR_EditorActionData > filteredActions, out int flags=0)
ref set< SCR_EditableEntityComponent > m_SelectedEntities
TraceFlags GetInstantActionTraceFlags()
EEditorActionGroup
RplComponent m_RplComponent
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
array< ref SCR_MenuActionPreset > GetActions()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
int Type
Definition Debug.c:13
Replication item identifier.
Definition RplId.c:14
int GetActions(out notnull array< SCR_BaseEditorAction > outActions)
void SCR_BaseActionsEditorComponentClass(IEntityComponentSource componentSource, IEntitySource parentSource, IEntitySource prefabSource)
ref array< ref SCR_EditorActionGroup > m_ActionGroups
ref array< SCR_BaseEditorAction > m_ActionsSorted
void SetShortcuts(SCR_BaseActionsEditorComponent manager, bool toAdd)
ref array< ref SCR_EditorActionList > m_ActionsLists
bool CanBeShown(SCR_EditableEntityComponent hoveredEntity, notnull set< SCR_EditableEntityComponent > selectedEntities, vector cursorWorldPosition, int flags)
void PerformOwner(SCR_EditableEntityComponent hoveredEntity, notnull set< SCR_EditableEntityComponent > selectedEntities, vector cursorWorldPosition, int flags, int param=-1)
void Perform(SCR_EditableEntityComponent hoveredEntity, notnull set< SCR_EditableEntityComponent > selectedEntities, vector cursorWorldPosition, int flags, int param=-1)
bool CanBePerformed(SCR_EditableEntityComponent hoveredEntity, notnull set< SCR_EditableEntityComponent > selectedEntities, vector cursorWorldPosition, int flags)
array< ref SCR_BaseEditorEffect > GetEffects()
EEditorActionGroup GetActionGroup()
SCR_BaseEditableEntityFilter GetFilter(EEditableEntityState state, bool showError=false)
Definition Types.c:486
AIBaseUtilityComponentClass AIComponentClass EvaluateActions()
Evaluate all actions and return the highest evaluated action which is not suspended....
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
Definition LogLevel.c:14
EEditableEntityState
SCR_FieldOfViewSettings Attribute
RplRole
Role of replicated node (and all items in it) within the replication system.
Definition RplRole.c:14
void RplRpc(RplChannel channel, RplRcver rcver, RplCondition condition=RplCondition.None, string customConditionName="")
Definition EnNetwork.c:95
RplRcver
Definition RplRcver.c:59
RplChannel
Communication channel. Reliable is guaranteed to be delivered. Unreliable not.
Definition RplChannel.c:14
int RplId
Definition EnNetwork.c:33
TraceFlags
Definition TraceFlags.c:13