Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
SCR_EditableEntityCore.c
Go to the documentation of this file.
1 void ScriptInvoker_EntityCoreBudgetUpdated(EEditableEntityBudget type, int originalBudgetValue, int budgetChange, int updatedBudgetValue, SCR_EditableEntityComponent entity);
3 typedef ScriptInvokerBase<ScriptInvoker_EntityCoreBudgetUpdated> ScriptInvoker_EntityCoreBudgetUpdatedEvent;
4 
6 
9 [BaseContainerProps(configRoot: true)]
10 class SCR_EditableEntityCore : SCR_GameCoreBase
11 {
12  [Attribute(desc: "Settings for every entity type.")]
13  private ref array<ref SCR_EditableEntityCoreTypeSetting> m_TypeSettings;
14 
15  [Attribute("1000", desc: "Draw distance override for player characters.")]
16  protected float m_fPlayerDrawDistance;
17 
18  [Attribute(defvalue: "0.01", desc: "The distance modifier for players in vehicles which will be used to determine player filter's visibility.")]
19  protected float m_fPlayerVehicleDistanceModifier;
20 
21  [Attribute(desc: "Budget settings for every entity type.")]
22  private ref array<ref SCR_EditableEntityCoreBudgetSetting> m_BudgetSettings;
23 
24  [Attribute(desc: "Label Groups which will have labels displayed in content browser. Groups are needed for certain functionality. If GROUPLESS group exist then all labels not defined in the EditableEntityCore config will be automatically added to the the groupless list but never displayed as a filter")]
25  private ref array<ref SCR_EditableEntityCoreLabelGroupSetting> m_LabelGroupSettings;
26 
27  [Attribute(desc: "Label configs")]
28  private ref array<ref SCR_EditableEntityCoreLabelSetting> m_EntityLabels;
29 
30  private ref map<EEditableEntityType, SCR_EditableEntityCoreTypeSetting> m_TypeSettingsMap = new map<EEditableEntityType, SCR_EditableEntityCoreTypeSetting>;
31 
32  private ref map<EEditableEntityLabelGroup, ref array<SCR_EditableEntityCoreLabelSetting>> m_LabelListMap = new map<EEditableEntityLabelGroup, ref array<SCR_EditableEntityCoreLabelSetting>>;
33  private ref map<EEditableEntityLabelGroup, SCR_EditableEntityCoreLabelGroupSetting> m_LabelGroupSettingsMap = new map<EEditableEntityLabelGroup, SCR_EditableEntityCoreLabelGroupSetting>;
34  private ref map<EEditableEntityLabel, SCR_EditableEntityCoreLabelSetting> m_LabelSettingsMap = new map<EEditableEntityLabel, SCR_EditableEntityCoreLabelSetting>;
35 
36  private ref set<SCR_EditableEntityComponent> m_Entities;
37  ref map<RplId, ref array<RplId>> m_OrphanEntityIds = new map<RplId, ref array<RplId>>();
38  private SCR_EditableEntityComponent m_CurrentLayer;
39 
41  ref ScriptInvoker Event_OnEntityRegistered = new ScriptInvoker;
42 
44  ref ScriptInvoker Event_OnEntityUnregistered = new ScriptInvoker;
45 
47  ref ScriptInvoker Event_OnEntityRefreshed = new ScriptInvoker;
48 
50  ref ScriptInvoker Event_OnParentEntityChanged = new ScriptInvoker;
51 
53  ref ScriptInvoker Event_OnEntityAccessKeyChanged = new ScriptInvoker;
54 
56  ref ScriptInvoker Event_OnEntityVisibilityChanged = new ScriptInvoker;
57 
59  ref ScriptInvoker Event_OnEntityTransformChanged = new ScriptInvoker;
60 
62  ref ScriptInvoker Event_OnEntityTransformChangedServer = new ScriptInvoker;
63 
66 
68  ref ScriptInvoker Event_OnEntityExtendedChange = new ScriptInvoker;
69 
70  //------------------------------------------------------------------------------------------------
73  void AddToRoot(SCR_EditableEntityComponent entity)
74  {
75  if (!m_Entities)
76  m_Entities = new set<SCR_EditableEntityComponent>();
77 
78  if (m_Entities.Find(entity) < 0)
79  m_Entities.Insert(entity);
80  }
81 
82  //------------------------------------------------------------------------------------------------
85  void RemoveFromRoot(SCR_EditableEntityComponent entity)
86  {
87  if (!m_Entities) return;
88 
89  int index = m_Entities.Find(entity);
90  if (index != -1) m_Entities.Remove(index);
91  }
92 
93  //------------------------------------------------------------------------------------------------
96  void RegisterEntity(SCR_EditableEntityComponent entity)
97  {
98  //--- Get settings for the entity based on its type
99  SCR_EditableEntityCoreTypeSetting setting = null;
100  if (m_TypeSettingsMap.Find(entity.GetEntityType(), setting))
101  {
102  //--- Set default max draw distance
103  if (entity.GetMaxDrawDistanceSq() <= 0)
104  entity.SetMaxDrawDistance(setting.GetMaxDrawDistance());
105  }
106  else
107  {
108  Print(string.Format("Default type settings not found for '%1'!", Type().EnumToString(EEditableEntityType, entity.GetEntityType())), LogLevel.ERROR);
109  }
110 
111  Event_OnEntityRegistered.Invoke(entity);
112 
113  //:| Player ownership isn't ready if we don't wait for a frame before calling UpdateBudgets.
114  //:| This results in Player ownership related checks to have an undefined behavior.
115  GetGame().GetCallqueue().CallLater(UpdateBudgets, 0, false, entity, true, entity.GetOwnerScripted());
116  }
117 
118  //------------------------------------------------------------------------------------------------
122  void UnRegisterEntity(SCR_EditableEntityComponent entity, IEntity owner = null)
123  {
124  UpdateBudgets(entity, false, owner);
125  Event_OnEntityUnregistered.Invoke(entity);
126  }
127 
128  //------------------------------------------------------------------------------------------------
134  void AddOrphan(RplId parentId, RplId orphanId)
135  {
136  array<RplId> orphanIds;
137  if (!m_OrphanEntityIds.Find(parentId, orphanIds))
138  orphanIds = {};
139 
140  orphanIds.Insert(orphanId);
141  m_OrphanEntityIds.Insert(parentId, orphanIds);
142  }
143 
144  //------------------------------------------------------------------------------------------------
149  int RemoveOrphans(RplId parentId, out notnull array<SCR_EditableEntityComponent> outOrphans)
150  {
151  if (!parentId.IsValid())
152  return 0;
153 
154  //--- Check if there are some orphans for given parent. If not, terminate
155  array<RplId> orphanIds = {};
156  if (!m_OrphanEntityIds.Find(parentId, orphanIds))
157  return 0;
158 
159  //--- Find all editable orphans
161  for (int i = orphanIds.Count() - 1; i >= 0; i--)
162  {
163  orphan = SCR_EditableEntityComponent.Cast(Replication.FindItem(orphanIds[i]));
164  if (orphan)
165  {
166  outOrphans.Insert(orphan);
167  orphanIds.Remove(i);
168  }
169  }
170 
171  //--- No orphans left, unregister the parent
172  if (orphanIds.IsEmpty())
173  m_OrphanEntityIds.Remove(parentId);
174 
175  return outOrphans.Count();
176  }
177 
178  //------------------------------------------------------------------------------------------------
183  void GetAllEntities(out notnull set<SCR_EditableEntityComponent> entities, bool onlyDirect = false, bool skipIgnored = false)
184  {
185  entities.Clear();
186  if (!m_Entities) return;
187  foreach (SCR_EditableEntityComponent entity: m_Entities)
188  {
189  entities.Insert(entity);
190  if (!onlyDirect) entity.GetChildren(entities, onlyDirect, skipIgnored);
191  }
192  }
193 
194  //------------------------------------------------------------------------------------------------
198  void GetAllEntities(out notnull set<SCR_EditableEntityComponent> entities, EEditableEntityAccessKey accessKey)
199  {
200  entities.Clear();
201  if (!m_Entities) return;
202  foreach (SCR_EditableEntityComponent entity: m_Entities)
203  {
204  if (!entity.HasAccessSelf(accessKey)) continue;
205 
206  entities.Insert(entity);
207 
208  if (entity.IsLayer())
209  {
210  set<SCR_EditableEntityComponent> subEntities = new set<SCR_EditableEntityComponent>;
211  entity.GetChildren(subEntities, false, accessKey);
212  foreach (SCR_EditableEntityComponent child: subEntities)
213  {
214  entities.Insert(child);
215  }
216  //entities.InsertAll(subEntities)
217  }
218  }
219  }
220 
221  //------------------------------------------------------------------------------------------------
228  SCR_EditableEntityComponent FindNearestEntity(vector pos, EEditableEntityType type, EEditableEntityFlag flags = 0, bool onlyDirect = true)
229  {
230  float nearestDis = float.MAX;
231  SCR_EditableEntityComponent nearestEntity;
232 
233  set<SCR_EditableEntityComponent> entities = new set<SCR_EditableEntityComponent>();
234  if (onlyDirect)
235  entities = m_Entities;
236  else
237  GetAllEntities(entities);
238 
239  foreach (SCR_EditableEntityComponent entity: m_Entities)
240  {
241  if (entity.GetEntityType() != type || !entity.HasEntityFlag(flags))
242  continue;
243 
244  vector entityPos;
245  if (!entity.GetPos(entityPos))
246  continue;
247 
248  float dis = vector.DistanceSq(entityPos, pos);
249  if (dis > nearestDis)
250  continue;
251 
252  nearestDis = dis;
253  nearestEntity = entity;
254  }
255  return nearestEntity;
256  }
257 
258  //------------------------------------------------------------------------------------------------
263  {
265  if (m_TypeSettingsMap.Find(type, setting))
266  return setting.GetInteraction();
267  else
268  return null;
269  }
270 
271  //------------------------------------------------------------------------------------------------
275  bool GetEntityCanBeControlled(EEditableEntityType type)
276  {
278  return m_TypeSettingsMap.Find(type, setting) && setting.GetCanBePlayer();
279  }
280 
281  //------------------------------------------------------------------------------------------------
285  EEditableEntityBudget GetBudgetForEntityType(EEditableEntityType entityType)
286  {
287  EEditableEntityBudget budget;
288  switch (entityType)
289  {
290  case EEditableEntityType.GENERIC:
291  case EEditableEntityType.ITEM:
292  budget = EEditableEntityBudget.PROPS;
293  break;
294  case EEditableEntityType.CHARACTER:
295  case EEditableEntityType.GROUP:
296  budget = EEditableEntityBudget.AI;
297  break;
298  case EEditableEntityType.VEHICLE:
299  budget = EEditableEntityBudget.VEHICLES;
300  break;
301  case EEditableEntityType.WAYPOINT:
302  case EEditableEntityType.COMMENT:
303  case EEditableEntityType.SYSTEM:
304  case EEditableEntityType.TASK:
305  budget = EEditableEntityBudget.SYSTEMS;
306  break;
307  default:
308  budget = EEditableEntityBudget.PROPS;
309  break;
310  }
311  return budget;
312  }
313 
314  //------------------------------------------------------------------------------------------------
317  void GetBudgets(out notnull array<ref SCR_EditableEntityCoreBudgetSetting> budgets)
318  {
319  foreach (SCR_EditableEntityCoreBudgetSetting budget : m_BudgetSettings)
320  {
321  budgets.Insert(budget);
322  }
323  }
324 
325  //------------------------------------------------------------------------------------------------
328  bool GetBudget(EEditableEntityBudget budgetType, out SCR_EditableEntityCoreBudgetSetting budgetSettings)
329  {
330  foreach (SCR_EditableEntityCoreBudgetSetting budget : m_BudgetSettings)
331  {
332  if (budget.GetBudgetType() == budgetType)
333  {
334  budgetSettings = budget;
335  return true;
336  }
337  }
338  return false;
339  }
340 
341  //------------------------------------------------------------------------------------------------
344  void GetLabelGroups(out notnull array<ref SCR_EditableEntityCoreLabelGroupSetting> labelGroups)
345  {
346  foreach ( SCR_EditableEntityCoreLabelGroupSetting labelGroup : m_LabelGroupSettings)
347  {
348  int index = labelGroups.Count();
349 
350  for (int i = 0; i < index; i++)
351  {
352  if (labelGroups[i].GetOrder() >= labelGroup.GetOrder())
353  {
354  index = i;
355  break;
356  }
357  }
358 
359  labelGroups.InsertAt(labelGroup, index);
360  }
361  }
362 
363  //------------------------------------------------------------------------------------------------
367  int GetLabelGroupOrder(EEditableEntityLabelGroup groupLabel)
368  {
369  foreach ( SCR_EditableEntityCoreLabelGroupSetting labelGroup : m_LabelGroupSettings)
370  {
371  if (labelGroup.GetLabelGroupType() == groupLabel)
372  return labelGroup.GetOrder();
373  }
374 
375  return -1;
376  }
377 
378  //------------------------------------------------------------------------------------------------
383  bool GetLabelGroupType(EEditableEntityLabel label, out EEditableEntityLabelGroup labelGroup)
384  {
386  if (!m_LabelSettingsMap.Find(label, labelSettings))
387  return false;
388 
389  labelGroup = labelSettings.GetLabelGroupType();
390  return labelGroup != EEditableEntityLabelGroup.NONE;
391  }
392 
393  //------------------------------------------------------------------------------------------------
398  bool GetLabelsOfGroup(EEditableEntityLabelGroup groupType, out notnull array<SCR_EditableEntityCoreLabelSetting> labels)
399  {
400  return m_LabelListMap.Find(groupType, labels);
401  }
402 
403  //------------------------------------------------------------------------------------------------
408  bool GetLabelUIInfo(EEditableEntityLabel entityLabel, out SCR_UIInfo uiInfo)
409  {
410  SCR_EditableEntityCoreLabelSetting labelSetting = m_LabelSettingsMap.Get(entityLabel);
411  if (labelSetting)
412  uiInfo = labelSetting.GetInfo();
413 
414  return uiInfo != null;
415  }
416 
417  //------------------------------------------------------------------------------------------------
423  bool GetLabelUIInfoIfValid(EEditableEntityLabel entityLabel, EEditorMode currentMode, out SCR_UIInfo uiInfo)
424  {
425  SCR_EditableEntityCoreLabelSetting labelSetting = m_LabelSettingsMap.Get(entityLabel);
426  if (labelSetting)
427  {
428  if (labelSetting.IsValid(currentMode))
429  uiInfo = labelSetting.GetInfo();
430  else
431  uiInfo = null;
432  }
433 
434  return uiInfo != null;
435  }
436 
437  //------------------------------------------------------------------------------------------------
443  {
444  SCR_EditableEntityCampaignBuildingLabelSetting buildModeLabelSetting = SCR_EditableEntityCampaignBuildingLabelSetting.Cast(m_LabelSettingsMap.Get(entityLabel));
445  if (!buildModeLabelSetting)
446  return null;
447 
448  SCR_UIInfo uiInfo = buildModeLabelSetting.GetInfo();
449  SCR_EServicePointType linkedConflictServicePoint = buildModeLabelSetting.GetLinkedConflictServicePoint();
450  if (!uiInfo && linkedConflictServicePoint < 0)
451  return null;
452 
453  return new SCR_EditableEntityCampaignBuildingModeLabelData(entityLabel, uiInfo, linkedConflictServicePoint);
454  }
455 
456  //------------------------------------------------------------------------------------------------
462  int GetCampaignBuildingModeLabelsData(notnull array<EEditableEntityLabel> entityLabels, notnull out array<ref SCR_EditableEntityCampaignBuildingModeLabelData> validBuildmodeLabelData)
463  {
464  validBuildmodeLabelData.Clear();
465 
467  SCR_UIInfo uiInfo;
468  SCR_EServicePointType linkedConflictServicePoint;
469 
470  foreach (EEditableEntityLabel entityLabel : entityLabels)
471  {
472  if (entityLabel == EEditableEntityLabel.TRAIT_SERVICE)
473  continue;
474 
475  buildModeLabelSetting = SCR_EditableEntityCampaignBuildingLabelSetting.Cast(m_LabelSettingsMap.Get(entityLabel));
476  if (!buildModeLabelSetting)
477  continue;
478 
479  uiInfo = buildModeLabelSetting.GetInfo();
480  linkedConflictServicePoint = buildModeLabelSetting.GetLinkedConflictServicePoint();
481 
482  if (!uiInfo && linkedConflictServicePoint < 0)
483  continue;
484 
485  validBuildmodeLabelData.Insert(new SCR_EditableEntityCampaignBuildingModeLabelData(entityLabel, uiInfo, linkedConflictServicePoint));
486  }
487 
488  return validBuildmodeLabelData.Count();
489  }
490 
491  //------------------------------------------------------------------------------------------------
495  SCR_UIInfo GetBuildModeLabelUIInfo(EEditableEntityLabel entityLabel)
496  {
497  SCR_EditableEntityCampaignBuildingLabelSetting buildModeLabelSetting = SCR_EditableEntityCampaignBuildingLabelSetting.Cast(m_LabelSettingsMap.Get(entityLabel));
498  if (!buildModeLabelSetting)
499  return null;
500 
501  return buildModeLabelSetting.GetInfo();
502  }
503 
504  //------------------------------------------------------------------------------------------------
508  SCR_EServicePointType GetBuildModeLabelLinkedConflictService(EEditableEntityLabel entityLabel)
509  {
510  SCR_EditableEntityCampaignBuildingLabelSetting buildModeLabelSetting = SCR_EditableEntityCampaignBuildingLabelSetting.Cast(m_LabelSettingsMap.Get(entityLabel));
511  if (!buildModeLabelSetting)
512  return -1;
513 
514  return buildModeLabelSetting.GetLinkedConflictServicePoint();
515  }
516 
517  //------------------------------------------------------------------------------------------------
520  int GetLabelOrder(EEditableEntityLabel entityLabel)
521  {
522  //~ Labels do not use order so get array index
523  array<SCR_EditableEntityCoreLabelSetting> labels = {};
524  EEditableEntityLabelGroup groupLabel;
525  GetLabelGroupType(entityLabel, groupLabel);
526 
527  if (!GetLabelsOfGroup(groupLabel, labels))
528  return -1;
529 
530  int count = labels.Count();
531 
532  for(int i = 0; i < count; i++)
533  {
534  if (labels[i].GetLabelType() == entityLabel)
535  return i;
536  }
537 
538  return -1;
539  }
540 
541  //------------------------------------------------------------------------------------------------
544  void OrderLabels(inout notnull array<EEditableEntityLabel> labels)
545  {
546  if (labels.IsEmpty())
547  return;
548 
549  array<EEditableEntityLabelGroup> orderedGroups = {};
550  map<EEditableEntityLabelGroup, ref array<EEditableEntityLabel>> groupsWithLabels = new map<EEditableEntityLabelGroup, ref array<EEditableEntityLabel>>();
551 
552  int groupLabelCount = 0;
553  bool groupAdded = false;
554  EEditableEntityLabelGroup groupLabel;
555 
556  //~ Get label groups of the given label and get order of the group
557  foreach (EEditableEntityLabel label: labels)
558  {
559  GetLabelGroupType(label, groupLabel);
560 
561  if (!groupsWithLabels.Contains(groupLabel))
562  groupsWithLabels.Insert(groupLabel, new array<EEditableEntityLabel>());
563 
564  groupsWithLabels[groupLabel].Insert(label);
565 
566  //~ New list so add it and continue
567  if (orderedGroups.IsEmpty())
568  {
569  orderedGroups.Insert(groupLabel);
570  groupLabelCount++;
571  continue;
572  }
573 
574  //~ Already in list so continue
575  if (orderedGroups.Contains(groupLabel))
576  continue;
577 
578  groupAdded = false;
579  //~ Check existing and place it in the correct order
580  for(int i = 0; i < groupLabelCount; i++)
581  {
582  //~ Group Label is higher order so add it to the list and break loop
583  if (GetLabelGroupOrder(groupLabel) <= GetLabelGroupOrder(orderedGroups[i]))
584  {
585  orderedGroups.InsertAt(groupLabel, i);
586  groupLabelCount++;
587  groupAdded = true;
588  break;
589  }
590  }
591 
592  if (groupAdded)
593  continue;
594 
595  orderedGroups.Insert(groupLabel);
596  groupLabelCount++;
597  }
598 
599  array<EEditableEntityLabel> orderedLabels = {};
600  int orderedLabelCount;
601  bool labelAdded = false;
602  array<EEditableEntityLabel> allOrderedLabels = {};
603 
604  array<EEditableEntityLabel> labelsTest = {};
605 
606  //~ For each ordered group get the labels and order those as well
607  foreach (EEditableEntityLabelGroup group: orderedGroups)
608  {
609  orderedLabelCount = 0;
610  orderedLabels.Clear();
611 
612  //~ Go over each label in the group and order them from highest to lowest
613  foreach (EEditableEntityLabel label: groupsWithLabels[group])
614  {
615  //~ New list so add it and continue
616  if (orderedLabels.IsEmpty())
617  {
618  orderedLabels.Insert(label);
619  orderedLabelCount++;
620  continue;
621  }
622 
623  labelAdded = false;
624  //~ Check existing and place it in the correct order
625  for(int i = 0; i < orderedLabelCount; i++)
626  {
627  //~ Label is higher order so add it to the list and break loop
628  if (GetLabelOrder(label) <= GetLabelOrder(orderedLabels[i]))
629  {
630  orderedLabels.InsertAt(label, i);
631  orderedLabelCount++;
632  labelAdded = true;
633  break;
634  }
635  }
636 
637  if (labelAdded)
638  continue;
639 
640  //~ Lowest order so add it there
641  orderedLabels.Insert(label);
642  orderedLabelCount++;
643  }
644 
645  //~ Add the ordered labels to the overal ordered list
646  allOrderedLabels.InsertAll(orderedLabels);
647  }
648 
649  //~ Set out labels to ordered labels
650  labels.Copy(allOrderedLabels);
651  }
652 
653  //------------------------------------------------------------------------------------------------
656  void LoadSettings(SCR_EditableEntityComponent entity)
657  {
658  if (!entity) return;
659 
660  //--- Get settings for the entity based on its type
661  SCR_EditableEntityCoreTypeSetting setting = null;
662  if (!m_TypeSettingsMap.Find(entity.GetEntityType(), setting))
663  {
664  Print(string.Format("Default type settings not found for '%1'!", Type().EnumToString(EEditableEntityType, entity.GetEntityType())), LogLevel.ERROR);
665  return;
666  }
667 
668  //--- Set default max draw distance
669  if (entity.GetMaxDrawDistanceSq() <= 0)
670  entity.SetMaxDrawDistance(setting.GetMaxDrawDistance());
671  }
672 
673  //------------------------------------------------------------------------------------------------
677  {
678  SCR_EditableEntityCoreTypeSetting setting = null;
679  if (entity && !m_TypeSettingsMap.Find(entity.GetEntityType(), setting))
680  return setting;
681 
682  return null;
683  }
684 
685  //------------------------------------------------------------------------------------------------
689  float GetPlayerDrawDistanceSq(bool isInVehicle)
690  {
691  float modifiedDrawDistance = m_fPlayerDrawDistance;
692  if (isInVehicle)
693  modifiedDrawDistance *= m_fPlayerVehicleDistanceModifier;
694 
695  return modifiedDrawDistance;
696  }
697 
698  //------------------------------------------------------------------------------------------------
700  void Log()
701  {
702  if (!m_Entities) return;
703  Print("--------------------------------------------------", LogLevel.DEBUG);
704  Print(string.Format("--- ALL (%1)", m_Entities.Count()), LogLevel.DEBUG);
705  foreach (SCR_EditableEntityComponent entity: m_Entities)
706  {
707  entity.Log();
708  }
709  Print("--------------------------------------------------", LogLevel.DEBUG);
710  }
711 
712  //------------------------------------------------------------------------------------------------
717  void UpdateBudgets(SCR_EditableEntityComponent entity, bool added, IEntity owner = null)
718  {
719  if (!entity)
720  return;
721 
722  EEditableEntityType entityType = entity.GetEntityType();
723  if (entity.HasEntityFlag(EEditableEntityFlag.LOCAL) || entity.HasEntityFlag(EEditableEntityFlag.NON_INTERACTIVE))
724  return;
725 
726  if (!owner)
727  owner = entity.GetOwner();
728 
729  if (added)
730  {
731  // Budget update is delayed by one frame since AI-control can not be determined directly on spawn
732  // Update is delayed for these and potentionally other entities
733  GetGame().GetCallqueue().CallLater(UpdateBudgetForEntity, 0, false, entity, added, owner);
734  }
735  else
736  {
737  UpdateBudgetForEntity(entity, added, owner);
738  }
739  }
740 
741  //------------------------------------------------------------------------------------------------
746  protected void UpdateBudgetForEntity(SCR_EditableEntityComponent entity, bool added, IEntity owner)
747  {
748  // Entity was deleted before delayed update could run, ignore entity.
749  // Will be ignored for both delayed Register and Unregister so shouldn't affect total budget
750  if (!entity)
751  return;
752 
753  array<ref SCR_EntityBudgetValue> entityBudgetCosts = {};
754  if (entity.GetEntityBudgetCost(entityBudgetCosts, owner))
755  {
756  if (entityBudgetCosts.IsEmpty())
757  {
758  SCR_EditableGroupComponent editableGroupComponent = SCR_EditableGroupComponent.Cast(entity);
759  if (editableGroupComponent)
760  editableGroupComponent.GetPrefabBudgetCost(entityBudgetCosts);
761  }
762 
763  foreach (SCR_EntityBudgetValue budgetCost : entityBudgetCosts)
764  {
765  UpdateBudget(budgetCost.GetBudgetType(), added, entity, budgetCost);
766  }
767  }
768  else
769  {
770  UpdateBudget(GetBudgetForEntityType(entity.GetEntityType(owner)), added, entity);
771  }
772  }
773 
774  //------------------------------------------------------------------------------------------------
780  protected void UpdateBudget(EEditableEntityBudget budgetType, bool added, SCR_EditableEntityComponent entity, SCR_EntityBudgetValue budgetCost = null)
781  {
783  if (!GetBudget(budgetType, budgetSettings))
784  return;
785 
786  int originalBudgetValue = budgetSettings.GetCurrentBudget();
787  int budgetChange = 0;
788  if (added)
789  {
790  budgetChange = budgetSettings.AddToBudget(budgetCost);
791  }
792  else
793  {
794  budgetChange = budgetSettings.SubtractFromBudget(budgetCost);
795  }
796 
797  int updatedBudgetValue = originalBudgetValue + budgetChange;
798 
799  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_BUDGET_CHANGES))
800  Print(string.Format("New budget for type %1: %2", budgetType, updatedBudgetValue), LogLevel.NORMAL);
801 
802  Event_OnEntityBudgetUpdated.Invoke(budgetType, originalBudgetValue, budgetChange, updatedBudgetValue, entity);
803  }
804 
805  //------------------------------------------------------------------------------------------------
806  override void OnUpdate(float timeSlice)
807  {
808  if (DiagMenu.GetBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ALL))
809  {
810  int type = DiagMenu.GetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_TYPE) - 1;
811  if (type == -1)
812  {
813  Log();
814  }
815  else
816  {
817  SCR_BaseEditableEntityFilter filter = SCR_BaseEditableEntityFilter.GetInstance(Math.Pow(2, type));
818  if (filter)
819  filter.Log();
820  }
821  DiagMenu.SetValue(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ALL, false);
822  }
823  }
824 
825  //------------------------------------------------------------------------------------------------
826  override void OnGameStart()
827  {
828  typename state = EEditableEntityState;
829  DiagMenu.RegisterMenu(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES, "Editable Entities", "Editor");
830  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ALL, "", "Log All", "Editable Entities");
831  DiagMenu.RegisterRange(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_TYPE, "", "Log Type", "Editable Entities", string.Format("-1 %1 -1 1", state.GetVariableCount() - 1));
832  DiagMenu.RegisterBool(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_DISABLE, "", "Disable entities", "Editable Entities");
833  }
834 
835  //------------------------------------------------------------------------------------------------
836  override void OnGameEnd()
837  {
838  m_Entities = null;
839  m_CurrentLayer = null;
840 
841  Event_OnEntityRegistered = new ScriptInvoker;
842  Event_OnEntityUnregistered = new ScriptInvoker;
843  Event_OnParentEntityChanged = new ScriptInvoker;
844  Event_OnEntityAccessKeyChanged = new ScriptInvoker;
845  Event_OnEntityVisibilityChanged = new ScriptInvoker;
846  Event_OnEntityExtendedChange = new ScriptInvoker;
847  Event_OnEntityBudgetUpdated = new ScriptInvoker_EntityCoreBudgetUpdatedEvent();
848 
849  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES);
850  DiagMenu.Unregister(SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ALL);
851  }
852 
853  //------------------------------------------------------------------------------------------------
854  // constructor
856  {
857  foreach (SCR_EditableEntityCoreTypeSetting setting: m_TypeSettings)
858  {
859  m_TypeSettingsMap.Insert(setting.GetType(), setting)
860  }
861 
862  foreach (SCR_EditableEntityCoreLabelSetting labelSetting : m_EntityLabels)
863  {
864  if (!labelSetting)
865  continue;
866 
867  m_LabelSettingsMap.Insert(labelSetting.GetLabelType(), labelSetting);
868  }
869 
870 
871  //~ Check if groupless label group exist and create a labelSetting for any label not defined in EntityCore with LabelGroup GROUPLESS
872  foreach (SCR_EditableEntityCoreLabelGroupSetting labelGroup : m_LabelGroupSettings)
873  {
874  //~ Make sure the groupless label group exists
875  if (labelGroup && labelGroup.GetLabelGroupType() == EEditableEntityLabelGroup.GROUPLESS)
876  {
877  //~ Get all labels that exist in the enum but are not defined in entity core. Add them to the label list under group: Groupless
878  array<int> allLabels = {};
879  int count = SCR_Enum.GetEnumValues(EEditableEntityLabel, allLabels);
881 
882  //~ Create new groupless labels
883  for (int i = 0; i < count; i++)
884  {
885  //~ Already in m_EntityLabels
886  if (m_LabelSettingsMap.Contains(allLabels[i]))
887  continue;
888 
889  labelSetting = SCR_EditableEntityCoreLabelSetting.CreateGrouplessLabel(allLabels[i]);
890  m_EntityLabels.Insert(labelSetting);
891  m_LabelSettingsMap.Insert(allLabels[i], labelSetting);
892  }
893 
894  break;
895  }
896  }
897 
898  foreach (SCR_EditableEntityCoreLabelGroupSetting labelGroup : m_LabelGroupSettings)
899  {
900  array<SCR_EditableEntityCoreLabelSetting> groupLabels = {};
901  EEditableEntityLabelGroup labelGroupType = labelGroup.GetLabelGroupType();
902  m_LabelGroupSettingsMap.Insert(labelGroupType, labelGroup);
903 
904  foreach (SCR_EditableEntityCoreLabelSetting entityLabel : m_EntityLabels)
905  {
906  if (!entityLabel)
907  continue;
908 
909  if (entityLabel.GetLabelGroupType() == labelGroupType)
910  {
911  groupLabels.Insert(entityLabel);
912  }
913  }
914 
915  m_LabelListMap.Insert(labelGroupType, groupLabels);
916  }
917 
918  //--- Square the value
920  }
921 }
EEditableEntityState
EEditableEntityState
Definition: EEditableEntityState.c:37
EEditableEntityLabel
EEditableEntityLabel
Definition: EEditableEntityLabel.c:1
EEditableEntityFlag
EEditableEntityFlag
Unique flags of the entity.
Definition: EEditableEntityFlag.c:5
SCR_EditableEntityCore
Definition: SCR_EditableEntityCore.c:10
SCR_Enum
Definition: SCR_Enum.c:1
SCR_EditableEntityCampaignBuildingLabelSetting
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:2
SCR_EditableEntityCoreBudgetSetting
Definition: SCR_EditableEntityCoreBudgetSetting.c:2
ScriptInvoker_EntityCoreBudgetUpdated
func ScriptInvoker_EntityCoreBudgetUpdated
Definition: SCR_EditableEntityCore.c:2
SCR_EditableEntityCampaignBuildingModeLabelData
void SCR_EditableEntityCampaignBuildingModeLabelData(EEditableEntityLabel label, SCR_UIInfo uiInfo, SCR_EServicePointType linkedServicePoint)
Definition: SCR_EditableEntityCampaignBuildingModeLabelSetting.c:39
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
desc
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition: SCR_RespawnBriefingComponent.c:17
SCR_EditableGroupComponent
void SCR_EditableGroupComponent(IEntityComponentSource src, IEntity ent, IEntity parent)
Definition: SCR_EditableGroupComponent.c:703
func
func
Definition: SCR_AIThreatSystem.c:5
EEditableEntityBudget
EEditableEntityBudget
Definition: EEditableEntityBudget.c:1
ScriptInvoker_EntityCoreBudgetUpdatedEvent
ScriptInvokerBase< ScriptInvoker_EntityCoreBudgetUpdated > ScriptInvoker_EntityCoreBudgetUpdatedEvent
Definition: SCR_EditableEntityCore.c:3
SCR_EditableEntityCoreLabelSetting
Definition: SCR_EditableEntityCoreLabelSetting.c:2
Attribute
typedef Attribute
Post-process effect of scripted camera.
EEditableEntityAccessKey
EEditableEntityAccessKey
Definition: EEditableEntityAccessKey.c:8
EEditableEntityLabelGroup
EEditableEntityLabelGroup
Definition: EEditableEntityLabel.c:200
EEditableEntityType
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
Definition: EEditableEntityType.c:5
m_Entities
protected ref SCR_SortedArray< SCR_EditableEntityComponent > m_Entities
Definition: SCR_EntitiesToolbarEditorUIComponent.c:31
SCR_EntityBudgetValue
Definition: SCR_EntityBudgetValue.c:2
m_fPlayerDrawDistance
protected float m_fPlayerDrawDistance
Definition: SCR_EditableCharacterComponent.c:22
SCR_EditableEntityCoreLabelGroupSetting
Definition: SCR_EditableEntityCoreLabelGroupSetting.c:2
SCR_EditableEntityCoreTypeSetting
Definition: SCR_EditableEntityCoreTypeSetting.c:2
SCR_BaseEditableEntityFilter
Definition: SCR_BaseEditableEntityFilter.c:13
SCR_UIInfo
Definition: SCR_UIInfo.c:7
SCR_EditableEntityComponent
Definition: SCR_EditableEntityComponent.c:13
EEditorMode
EEditorMode
Editor mode that defines overall functionality.
Definition: EEditorMode.c:5
index
SCR_DestructionSynchronizationComponentClass ScriptComponentClass int index
Definition: SCR_DestructionSynchronizationComponent.c:17
GetOrder
int GetOrder()
Definition: SCR_Faction.c:78
type
EDamageType type
Definition: SCR_DestructibleTreeV2.c:32
SCR_EditableEntityInteraction
Definition: SCR_EditableEntityInteraction.c:2
SCR_DebugMenuID
SCR_DebugMenuID
This enum contains all IDs for DiagMenu entries added in script.
Definition: DebugMenuID.c:3
SCR_EServicePointType
SCR_EServicePointType
Definition: SCR_ServicePointComponent.c:180
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