13 private ref array<ref SCR_EditableEntityCoreTypeSetting> m_TypeSettings;
15 [
Attribute(
"1000",
desc:
"Draw distance override for player characters.")]
16 protected float m_fPlayerDrawDistance;
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;
22 private ref array<ref SCR_EditableEntityCoreBudgetSetting> m_BudgetSettings;
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;
28 private ref array<ref SCR_EditableEntityCoreLabelSetting> m_EntityLabels;
30 private ref map<EEditableEntityType, SCR_EditableEntityCoreTypeSetting> m_TypeSettingsMap =
new map<EEditableEntityType, SCR_EditableEntityCoreTypeSetting>;
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>;
36 private ref set<SCR_EditableEntityComponent> m_Entities;
37 ref map<RplId, ref array<RplId>> m_OrphanEntityIds =
new map<RplId, ref array<RplId>>();
41 ref ScriptInvoker Event_OnEntityRegistered =
new ScriptInvoker;
44 ref ScriptInvoker Event_OnEntityUnregistered =
new ScriptInvoker;
47 ref ScriptInvoker Event_OnEntityRefreshed =
new ScriptInvoker;
50 ref ScriptInvoker Event_OnParentEntityChanged =
new ScriptInvoker;
53 ref ScriptInvoker Event_OnEntityAccessKeyChanged =
new ScriptInvoker;
56 ref ScriptInvoker Event_OnEntityVisibilityChanged =
new ScriptInvoker;
59 ref ScriptInvoker Event_OnEntityTransformChanged =
new ScriptInvoker;
62 ref ScriptInvoker Event_OnEntityTransformChangedServer =
new ScriptInvoker;
68 ref ScriptInvoker Event_OnEntityExtendedChange =
new ScriptInvoker;
76 m_Entities =
new set<SCR_EditableEntityComponent>();
100 if (m_TypeSettingsMap.Find(entity.GetEntityType(), setting))
103 if (entity.GetMaxDrawDistanceSq() <= 0)
104 entity.SetMaxDrawDistance(setting.GetMaxDrawDistance());
108 Print(
string.Format(
"Default type settings not found for '%1'!", Type().EnumToString(
EEditableEntityType, entity.GetEntityType())), LogLevel.ERROR);
111 Event_OnEntityRegistered.Invoke(entity);
115 GetGame().GetCallqueue().CallLater(UpdateBudgets, 0,
false, entity,
true, entity.GetOwnerScripted());
124 UpdateBudgets(entity,
false, owner);
125 Event_OnEntityUnregistered.Invoke(entity);
134 void AddOrphan(RplId parentId, RplId orphanId)
136 array<RplId> orphanIds;
137 if (!m_OrphanEntityIds.Find(parentId, orphanIds))
140 orphanIds.Insert(orphanId);
141 m_OrphanEntityIds.Insert(parentId, orphanIds);
149 int RemoveOrphans(RplId parentId, out notnull array<SCR_EditableEntityComponent> outOrphans)
151 if (!parentId.IsValid())
155 array<RplId> orphanIds = {};
156 if (!m_OrphanEntityIds.Find(parentId, orphanIds))
161 for (
int i = orphanIds.Count() - 1; i >= 0; i--)
166 outOrphans.Insert(orphan);
172 if (orphanIds.IsEmpty())
173 m_OrphanEntityIds.Remove(parentId);
175 return outOrphans.Count();
183 void GetAllEntities(out notnull set<SCR_EditableEntityComponent> entities,
bool onlyDirect =
false,
bool skipIgnored =
false)
189 entities.Insert(entity);
190 if (!onlyDirect) entity.GetChildren(entities, onlyDirect, skipIgnored);
204 if (!entity.HasAccessSelf(accessKey))
continue;
206 entities.Insert(entity);
208 if (entity.IsLayer())
210 set<SCR_EditableEntityComponent> subEntities =
new set<SCR_EditableEntityComponent>;
211 entity.GetChildren(subEntities,
false, accessKey);
214 entities.Insert(child);
230 float nearestDis =
float.MAX;
233 set<SCR_EditableEntityComponent> entities =
new set<SCR_EditableEntityComponent>();
237 GetAllEntities(entities);
241 if (entity.GetEntityType() !=
type || !entity.HasEntityFlag(flags))
245 if (!entity.GetPos(entityPos))
248 float dis = vector.DistanceSq(entityPos, pos);
249 if (dis > nearestDis)
253 nearestEntity = entity;
255 return nearestEntity;
265 if (m_TypeSettingsMap.Find(
type, setting))
266 return setting.GetInteraction();
278 return m_TypeSettingsMap.Find(
type, setting) && setting.GetCanBePlayer();
317 void GetBudgets(out notnull array<ref SCR_EditableEntityCoreBudgetSetting> budgets)
321 budgets.Insert(budget);
332 if (budget.GetBudgetType() == budgetType)
334 budgetSettings = budget;
344 void GetLabelGroups(out notnull array<ref SCR_EditableEntityCoreLabelGroupSetting> labelGroups)
348 int index = labelGroups.Count();
350 for (
int i = 0; i <
index; i++)
352 if (labelGroups[i].
GetOrder() >= labelGroup.GetOrder())
359 labelGroups.InsertAt(labelGroup,
index);
371 if (labelGroup.GetLabelGroupType() == groupLabel)
372 return labelGroup.GetOrder();
386 if (!m_LabelSettingsMap.Find(label, labelSettings))
389 labelGroup = labelSettings.GetLabelGroupType();
400 return m_LabelListMap.Find(groupType, labels);
412 uiInfo = labelSetting.GetInfo();
414 return uiInfo !=
null;
428 if (labelSetting.IsValid(currentMode))
429 uiInfo = labelSetting.GetInfo();
434 return uiInfo !=
null;
445 if (!buildModeLabelSetting)
448 SCR_UIInfo uiInfo = buildModeLabelSetting.GetInfo();
449 SCR_EServicePointType linkedConflictServicePoint = buildModeLabelSetting.GetLinkedConflictServicePoint();
450 if (!uiInfo && linkedConflictServicePoint < 0)
462 int GetCampaignBuildingModeLabelsData(notnull array<EEditableEntityLabel> entityLabels, notnull out array<ref SCR_EditableEntityCampaignBuildingModeLabelData> validBuildmodeLabelData)
464 validBuildmodeLabelData.Clear();
476 if (!buildModeLabelSetting)
479 uiInfo = buildModeLabelSetting.GetInfo();
480 linkedConflictServicePoint = buildModeLabelSetting.GetLinkedConflictServicePoint();
482 if (!uiInfo && linkedConflictServicePoint < 0)
488 return validBuildmodeLabelData.Count();
498 if (!buildModeLabelSetting)
501 return buildModeLabelSetting.GetInfo();
511 if (!buildModeLabelSetting)
514 return buildModeLabelSetting.GetLinkedConflictServicePoint();
523 array<SCR_EditableEntityCoreLabelSetting> labels = {};
525 GetLabelGroupType(entityLabel, groupLabel);
527 if (!GetLabelsOfGroup(groupLabel, labels))
530 int count = labels.Count();
532 for(
int i = 0; i < count; i++)
534 if (labels[i].GetLabelType() == entityLabel)
544 void OrderLabels(inout notnull array<EEditableEntityLabel> labels)
546 if (labels.IsEmpty())
549 array<EEditableEntityLabelGroup> orderedGroups = {};
550 map<EEditableEntityLabelGroup, ref array<EEditableEntityLabel>> groupsWithLabels =
new map<EEditableEntityLabelGroup, ref array<EEditableEntityLabel>>();
552 int groupLabelCount = 0;
553 bool groupAdded =
false;
559 GetLabelGroupType(label, groupLabel);
561 if (!groupsWithLabels.Contains(groupLabel))
562 groupsWithLabels.Insert(groupLabel,
new array<EEditableEntityLabel>());
564 groupsWithLabels[groupLabel].Insert(label);
567 if (orderedGroups.IsEmpty())
569 orderedGroups.Insert(groupLabel);
575 if (orderedGroups.Contains(groupLabel))
580 for(
int i = 0; i < groupLabelCount; i++)
583 if (GetLabelGroupOrder(groupLabel) <= GetLabelGroupOrder(orderedGroups[i]))
585 orderedGroups.InsertAt(groupLabel, i);
595 orderedGroups.Insert(groupLabel);
599 array<EEditableEntityLabel> orderedLabels = {};
600 int orderedLabelCount;
601 bool labelAdded =
false;
602 array<EEditableEntityLabel> allOrderedLabels = {};
604 array<EEditableEntityLabel> labelsTest = {};
609 orderedLabelCount = 0;
610 orderedLabels.Clear();
616 if (orderedLabels.IsEmpty())
618 orderedLabels.Insert(label);
625 for(
int i = 0; i < orderedLabelCount; i++)
628 if (GetLabelOrder(label) <= GetLabelOrder(orderedLabels[i]))
630 orderedLabels.InsertAt(label, i);
641 orderedLabels.Insert(label);
646 allOrderedLabels.InsertAll(orderedLabels);
650 labels.Copy(allOrderedLabels);
662 if (!m_TypeSettingsMap.Find(entity.GetEntityType(), setting))
664 Print(
string.Format(
"Default type settings not found for '%1'!", Type().EnumToString(
EEditableEntityType, entity.GetEntityType())), LogLevel.ERROR);
669 if (entity.GetMaxDrawDistanceSq() <= 0)
670 entity.SetMaxDrawDistance(setting.GetMaxDrawDistance());
679 if (entity && !m_TypeSettingsMap.Find(entity.GetEntityType(), setting))
689 float GetPlayerDrawDistanceSq(
bool isInVehicle)
693 modifiedDrawDistance *= m_fPlayerVehicleDistanceModifier;
695 return modifiedDrawDistance;
703 Print(
"--------------------------------------------------", LogLevel.DEBUG);
704 Print(
string.Format(
"--- ALL (%1)",
m_Entities.Count()), LogLevel.DEBUG);
709 Print(
"--------------------------------------------------", LogLevel.DEBUG);
727 owner = entity.GetOwner();
733 GetGame().GetCallqueue().CallLater(UpdateBudgetForEntity, 0,
false, entity, added, owner);
737 UpdateBudgetForEntity(entity, added, owner);
753 array<ref SCR_EntityBudgetValue> entityBudgetCosts = {};
754 if (entity.GetEntityBudgetCost(entityBudgetCosts, owner))
756 if (entityBudgetCosts.IsEmpty())
759 if (editableGroupComponent)
760 editableGroupComponent.GetPrefabBudgetCost(entityBudgetCosts);
765 UpdateBudget(budgetCost.GetBudgetType(), added, entity, budgetCost);
770 UpdateBudget(GetBudgetForEntityType(entity.GetEntityType(owner)), added, entity);
783 if (!GetBudget(budgetType, budgetSettings))
786 int originalBudgetValue = budgetSettings.GetCurrentBudget();
787 int budgetChange = 0;
790 budgetChange = budgetSettings.AddToBudget(budgetCost);
794 budgetChange = budgetSettings.SubtractFromBudget(budgetCost);
797 int updatedBudgetValue = originalBudgetValue + budgetChange;
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);
802 Event_OnEntityBudgetUpdated.Invoke(budgetType, originalBudgetValue, budgetChange, updatedBudgetValue, entity);
806 override void OnUpdate(
float timeSlice)
821 DiagMenu.SetValue(
SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_ALL,
false);
826 override void OnGameStart()
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");
836 override void OnGameEnd()
839 m_CurrentLayer =
null;
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;
859 m_TypeSettingsMap.Insert(setting.GetType(), setting)
867 m_LabelSettingsMap.Insert(labelSetting.GetLabelType(), labelSetting);
878 array<int> allLabels = {};
883 for (
int i = 0; i < count; i++)
886 if (m_LabelSettingsMap.Contains(allLabels[i]))
890 m_EntityLabels.Insert(labelSetting);
891 m_LabelSettingsMap.Insert(allLabels[i], labelSetting);
900 array<SCR_EditableEntityCoreLabelSetting> groupLabels = {};
902 m_LabelGroupSettingsMap.Insert(labelGroupType, labelGroup);
909 if (entityLabel.GetLabelGroupType() == labelGroupType)
911 groupLabels.Insert(entityLabel);
915 m_LabelListMap.Insert(labelGroupType, groupLabels);