22 private ref array<ref SCR_EditableEntityCoreTypeSetting> m_TypeSettings;
24 [
Attribute(
"1000",
desc:
"Draw distance override for player characters.")]
27 [
Attribute(defvalue:
"0.01",
desc:
"The distance modifier for players in vehicles which will be used to determine player filter's visibility.")]
31 private ref array<ref SCR_EditableEntityCoreBudgetSetting> m_BudgetSettings;
35 [
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")]
36 private ref array<ref SCR_EditableEntityCoreLabelGroupSetting> m_LabelGroupSettings;
39 private ref array<ref SCR_EditableEntityCoreLabelSetting> m_EntityLabels;
47 private ref set<SCR_EditableEntityComponent> m_Entities;
86 bool budgetChangesAccumulated =
false;
102 m_Entities =
new set<SCR_EditableEntityComponent>();
104 if (m_Entities.Find(entity) < 0)
105 m_Entities.Insert(entity);
113 if (!m_Entities)
return;
115 int index = m_Entities.Find(entity);
137 Event_OnEntityRegistered.Invoke(entity);
150 UpdateBudgets(entity,
false, owner);
151 Event_OnEntityUnregistered.Invoke(entity);
162 array<RplId> orphanIds;
163 if (!m_OrphanEntityIds.Find(parentId, orphanIds))
166 orphanIds.Insert(orphanId);
167 m_OrphanEntityIds.Insert(parentId, orphanIds);
177 if (!parentId.IsValid())
181 array<RplId> orphanIds = {};
182 if (!m_OrphanEntityIds.Find(parentId, orphanIds))
187 for (
int i = orphanIds.Count() - 1; i >= 0; i--)
192 outOrphans.Insert(orphan);
198 if (orphanIds.IsEmpty())
199 m_OrphanEntityIds.Remove(parentId);
201 return outOrphans.Count();
209 void GetAllEntities(out notnull set<SCR_EditableEntityComponent> entities,
bool onlyDirect =
false,
bool skipIgnored =
false)
212 if (!m_Entities)
return;
215 entities.Insert(entity);
216 if (!onlyDirect) entity.GetChildren(entities, onlyDirect, skipIgnored);
227 if (!m_Entities)
return;
230 if (!entity.HasAccessSelf(accessKey))
continue;
232 entities.Insert(entity);
234 if (entity.IsLayer())
236 set<SCR_EditableEntityComponent> subEntities =
new set<SCR_EditableEntityComponent>;
237 entity.GetChildren(subEntities,
false, accessKey);
240 entities.Insert(child);
259 string authorUID = entity.GetAuthorUID();
260 if (authorUID.IsEmpty() || authorUID != playerUID)
263 entities.Insert(entity);
265 if (entity.IsLayer())
267 set<SCR_EditableEntityComponent> subEntities =
new set<SCR_EditableEntityComponent>;
268 entity.GetChildren(subEntities);
271 if (authorUID.IsEmpty() || authorUID != playerUID)
274 entities.Insert(child);
279 return entities.Count();
307 int authorID = entity.GetAuthorPlayerID();
308 if (playerID != authorID)
311 entities.Insert(entity);
313 if (entity.IsLayer())
315 set<SCR_EditableEntityComponent> subEntities =
new set<SCR_EditableEntityComponent>;
316 entity.GetChildren(subEntities);
319 if (playerID != authorID)
322 entities.Insert(child);
327 return entities.Count();
352 float nearestDis =
float.MAX;
355 set<SCR_EditableEntityComponent> entities =
new set<SCR_EditableEntityComponent>();
357 entities = m_Entities;
363 if (entity.GetEntityType() !=
type || !entity.HasEntityFlag(
flags))
367 if (!entity.GetPos(entityPos))
370 float dis =
vector.DistanceSq(entityPos, pos);
371 if (dis > nearestDis)
375 nearestEntity = entity;
377 return nearestEntity;
387 if (m_TypeSettingsMap.Find(
type, setting))
388 return setting.GetInteraction();
400 return m_TypeSettingsMap.Find(
type, setting) && setting.GetCanBePlayer();
441 void GetBudgets(out notnull array<ref SCR_EditableEntityCoreBudgetSetting> budgets)
443 foreach (SCR_EditableEntityCoreBudgetSetting budget : m_BudgetSettings)
445 budgets.Insert(budget);
454 budgetSettings = m_BudgetSettingsInternal.Get(budgetType);
456 bool result = budgetSettings;
458 #ifdef BUDGET_OPTIMIZATION_CHECKS
459 if (result && !budgetSettings)
461 Print(
"GetBudget: Budget type wasn't defined!",
LogLevel.ERROR);
462 return GetBudget_Old(budgetType, budgetSettings);
472 private bool GetBudget_Old(
EEditableEntityBudget budgetType, out SCR_EditableEntityCoreBudgetSetting budgetSettings)
475 foreach (SCR_EditableEntityCoreBudgetSetting budget : m_BudgetSettings)
477 if (budget.GetBudgetType() == budgetType)
479 budgetSettings = budget;
489 void GetLabelGroups(out notnull array<ref SCR_EditableEntityCoreLabelGroupSetting> labelGroups)
491 foreach (SCR_EditableEntityCoreLabelGroupSetting labelGroup : m_LabelGroupSettings)
493 int index = labelGroups.Count();
495 for (
int i = 0; i <
index; i++)
497 if (labelGroups[i].
GetOrder() >= labelGroup.GetOrder())
504 labelGroups.InsertAt(labelGroup,
index);
514 foreach (SCR_EditableEntityCoreLabelGroupSetting labelGroup : m_LabelGroupSettings)
516 if (labelGroup.GetLabelGroupType() == groupLabel)
517 return labelGroup.GetOrder();
530 SCR_EditableEntityCoreLabelSetting labelSettings;
531 if (!m_LabelSettingsMap.Find(label, labelSettings))
534 labelGroup = labelSettings.GetLabelGroupType();
545 return m_LabelListMap.Find(groupType, labels);
555 SCR_EditableEntityCoreLabelSetting labelSetting = m_LabelSettingsMap.Get(entityLabel);
557 uiInfo = labelSetting.GetInfo();
559 return uiInfo != null;
570 SCR_EditableEntityCoreLabelSetting labelSetting = m_LabelSettingsMap.Get(entityLabel);
573 if (labelSetting.IsValid(currentMode))
574 uiInfo = labelSetting.GetInfo();
579 return uiInfo != null;
589 SCR_EditableEntityCampaignBuildingLabelSetting buildModeLabelSetting = SCR_EditableEntityCampaignBuildingLabelSetting.Cast(m_LabelSettingsMap.Get(entityLabel));
590 if (!buildModeLabelSetting)
593 SCR_UIInfo uiInfo = buildModeLabelSetting.GetInfo();
595 if (!uiInfo && linkedConflictServicePoint < 0)
607 int GetCampaignBuildingModeLabelsData(notnull array<EEditableEntityLabel> entityLabels, notnull out array<ref SCR_EditableEntityCampaignBuildingModeLabelData> validBuildmodeLabelData)
609 validBuildmodeLabelData.Clear();
611 SCR_EditableEntityCampaignBuildingLabelSetting buildModeLabelSetting;
620 buildModeLabelSetting = SCR_EditableEntityCampaignBuildingLabelSetting.Cast(m_LabelSettingsMap.Get(entityLabel));
621 if (!buildModeLabelSetting)
624 uiInfo = buildModeLabelSetting.GetInfo();
627 if (!uiInfo && linkedConflictServicePoint < 0)
633 return validBuildmodeLabelData.Count();
642 SCR_EditableEntityCampaignBuildingLabelSetting buildModeLabelSetting = SCR_EditableEntityCampaignBuildingLabelSetting.Cast(m_LabelSettingsMap.Get(entityLabel));
643 if (!buildModeLabelSetting)
646 return buildModeLabelSetting.GetInfo();
655 SCR_EditableEntityCampaignBuildingLabelSetting buildModeLabelSetting = SCR_EditableEntityCampaignBuildingLabelSetting.Cast(m_LabelSettingsMap.Get(entityLabel));
656 if (!buildModeLabelSetting)
668 array<SCR_EditableEntityCoreLabelSetting> labels = {};
670 GetLabelGroupType(entityLabel, groupLabel);
672 if (!GetLabelsOfGroup(groupLabel, labels))
675 int count = labels.Count();
677 for (
int i = 0; i < count; i++)
679 if (labels[i].GetLabelType() == entityLabel)
689 void OrderLabels(inout notnull array<EEditableEntityLabel> labels)
691 if (labels.IsEmpty())
694 array<EEditableEntityLabelGroup> orderedGroups = {};
695 map<EEditableEntityLabelGroup, ref array<EEditableEntityLabel>> groupsWithLabels =
new map<EEditableEntityLabelGroup, ref array<EEditableEntityLabel>>();
697 int groupLabelCount = 0;
698 bool groupAdded =
false;
704 GetLabelGroupType(label, groupLabel);
706 if (!groupsWithLabels.Contains(groupLabel))
707 groupsWithLabels.Insert(groupLabel,
new array<EEditableEntityLabel>());
709 groupsWithLabels[groupLabel].Insert(label);
712 if (orderedGroups.IsEmpty())
714 orderedGroups.Insert(groupLabel);
720 if (orderedGroups.Contains(groupLabel))
725 for (
int i = 0; i < groupLabelCount; i++)
728 if (GetLabelGroupOrder(groupLabel) <= GetLabelGroupOrder(orderedGroups[i]))
730 orderedGroups.InsertAt(groupLabel, i);
740 orderedGroups.Insert(groupLabel);
744 array<EEditableEntityLabel> orderedLabels = {};
745 int orderedLabelCount;
746 bool labelAdded =
false;
747 array<EEditableEntityLabel> allOrderedLabels = {};
749 array<EEditableEntityLabel> labelsTest = {};
754 orderedLabelCount = 0;
755 orderedLabels.Clear();
761 if (orderedLabels.IsEmpty())
763 orderedLabels.Insert(label);
770 for (
int i = 0; i < orderedLabelCount; i++)
773 if (GetLabelOrder(label) <= GetLabelOrder(orderedLabels[i]))
775 orderedLabels.InsertAt(label, i);
786 orderedLabels.Insert(label);
791 allOrderedLabels.InsertAll(orderedLabels);
795 labels.Copy(allOrderedLabels);
806 SCR_EditableEntityCoreTypeSetting setting = null;
807 if (!m_TypeSettingsMap.Find(entity.
GetEntityType(), setting))
821 SCR_EditableEntityCoreTypeSetting GetSettings(SCR_EditableEntityComponent entity)
823 SCR_EditableEntityCoreTypeSetting setting = null;
824 if (entity && !m_TypeSettingsMap.Find(entity.
GetEntityType(), setting))
834 float GetPlayerDrawDistanceSq(
bool isInVehicle)
840 return modifiedDrawDistance;
847 if (!m_Entities)
return;
848 Print(
"--------------------------------------------------",
LogLevel.DEBUG);
849 Print(
string.Format(
"--- ALL (%1)", m_Entities.Count()),
LogLevel.DEBUG);
850 foreach (SCR_EditableEntityComponent entity : m_Entities)
854 Print(
"--------------------------------------------------",
LogLevel.DEBUG);
862 void UpdateBudgets(SCR_EditableEntityComponent entity,
bool added,
IEntity owner = null)
872 owner = entity.GetOwner();
898 array<ref SCR_EntityBudgetValue> entityBudgetCosts = {};
901 if (entityBudgetCosts.IsEmpty())
904 if (editableGroupComponent)
905 editableGroupComponent.GetPrefabBudgetCost(entityBudgetCosts);
921 SCR_EditableEntityCoreBudgetSetting budgetSettings;
922 if (!
GetBudget(budgetType, budgetSettings))
925 const int originalBudgetValue = budgetSettings.GetCurrentBudget();
926 int budgetChange = budgetSettings.GetMinBudgetCost();
930 budgetChange =
Math.Max(budgetChange, budgetCost.GetBudgetValue());
937 const int adjustedCurrentBudget = budgetSettings.GetCurrentBudget() + m_accumulatedBudgetChanges[budgetType];
938 const int updatedBudgetValue = adjustedCurrentBudget + budgetChange;
941 m_accumulatedBudgetChanges[budgetType] = m_accumulatedBudgetChanges[budgetType] + budgetChange;
943 Event_OnEntityBudgetUpdatedPerEntity.Invoke(budgetType, adjustedCurrentBudget, budgetChange, updatedBudgetValue, entity);
945 if (!budgetChangesAccumulated)
948 budgetChangesAccumulated =
true;
954 SCR_EditableEntityCoreBudgetSetting budgetSettings = null;
955 int budgetChange = 0;
956 int originalBudgetValue = 0;
960 MapIterator it = m_accumulatedBudgetChanges.Begin();
961 const MapIterator end = m_accumulatedBudgetChanges.End();
968 budgetChange = m_accumulatedBudgetChanges.GetIteratorElement(it);
969 if (budgetChange == 0)
972 it = m_accumulatedBudgetChanges.Next(it);
976 budgetType = m_accumulatedBudgetChanges.GetIteratorKey(it);
977 budgetSettings = m_BudgetSettingsInternal[budgetType];
979 originalBudgetValue = budgetSettings.GetCurrentBudget();
982 if (budgetChange > 0)
983 budgetChange = budgetSettings.AddToBudget(budgetChange);
985 budgetChange = budgetSettings.SubtractFromBudget(-budgetChange);
987 const int updatedBudgetValue = budgetSettings.GetCurrentBudget();
990 Print(
string.Format(
"New budget for type %1: %2", budgetType, updatedBudgetValue),
LogLevel.NORMAL);
992 Event_OnEntityBudgetUpdated.Invoke(budgetType, originalBudgetValue, budgetChange, updatedBudgetValue);
995 m_accumulatedBudgetChanges[budgetType] = 0;
998 it = m_accumulatedBudgetChanges.Next(it);
1001 budgetChangesAccumulated =
false;
1011 SCR_EditableEntityCoreBudgetSetting budgetSettings;
1012 if (!
GetBudget(budgetType, budgetSettings))
1015 int originalBudgetValue = budgetSettings.GetCurrentBudget();
1016 int budgetChange = 0;
1019 budgetChange = budgetSettings.AddToBudget(budgetCost);
1023 budgetChange = budgetSettings.SubtractFromBudget(budgetCost);
1026 int updatedBudgetValue = originalBudgetValue + budgetChange;
1029 Print(
string.Format(
"New budget for type %1: %2", budgetType, updatedBudgetValue),
LogLevel.NORMAL);
1031 Event_OnEntityBudgetUpdated.Invoke(budgetType, originalBudgetValue, budgetChange, updatedBudgetValue, entity);
1037 set<SCR_EditableEntityComponent> entitiesToCheck =
new set<SCR_EditableEntityComponent>;
1038 array<SCR_EditableEntityComponent> entitiesToDelete = {};
1043 if (!component.EntityHasBudgetOfType(budgetToFree))
1046 entitiesToCheck.Clear();
1049 entitiesToCheck.Insert(component);
1050 component.GetChildren(entitiesToCheck);
1054 array<ref SCR_EntityBudgetValue> entityBudgetCosts = {};
1057 if (!entityToCheck.EntityHasBudgetOfType(budgetToFree))
1060 entitiesToDelete.Insert(entityToCheck);
1066 component.Delete(
true);
1078 if (!m_mAuthors.Contains(newAuthor.m_sAuthorUID))
1080 newAuthor.m_iEntityCount++;
1081 m_mAuthors.Insert(newAuthor.m_sAuthorUID, newAuthor);
1082 Print(
"SCR_EditableEntityCore::RegisterAuthorServer - Author Added",
LogLevel.VERBOSE);
1086 m_mAuthors[newAuthor.m_sAuthorUID].m_iEntityCount++;
1087 Print(
"SCR_EditableEntityCore::RegisterAuthorServer - Author Updated",
LogLevel.VERBOSE);
1097 if (!m_mAuthors.Contains(newAuthor.m_sAuthorUID))
1099 Print(
"SCR_EditableEntityCore::AuthorEntityRemovedServer - This should not happen, author has to be registered if entity is being removed",
LogLevel.ERROR);
1103 m_mAuthors[newAuthor.m_sAuthorUID].m_iEntityCount--;
1105 if (m_mAuthors[newAuthor.m_sAuthorUID].m_iEntityCount <= 0)
1106 m_mAuthors.Remove(newAuthor.m_sAuthorUID);
1114 return new set<SCR_EditableEntityAuthor>();
1116 set<SCR_EditableEntityAuthor> authors =
new set<SCR_EditableEntityAuthor>();
1118 foreach (SCR_EditableEntityAuthor author : m_mAuthors)
1120 authors.Insert(author);
1140 manager.RequestAllAuthors();
1148 if (m_mAuthors.IsEmpty())
1149 m_mAuthors.Insert(newAuthor.m_sAuthorUID, newAuthor);
1151 foreach (SCR_EditableEntityAuthor author : m_mAuthors)
1153 if (author.m_sAuthorUID == newAuthor.m_sAuthorUID)
1156 PrintFormat(
"SCR_EditableEntityCore::AddAuthorOnRequest - %1 Updated", newAuthor.m_sAuthorUID, level:
LogLevel.VERBOSE);
1161 m_mAuthors.Insert(newAuthor.m_sAuthorUID, newAuthor);
1163 PrintFormat(
"SCR_EditableEntityCore::AddAuthorOnRequest - %1", newAuthor.m_sAuthorUID, level:
LogLevel.VERBOSE);
1171 set<SCR_EditableEntityAuthor> authors =
new set<SCR_EditableEntityAuthor>();
1172 foreach (SCR_EditableEntityAuthor author : m_mAuthors)
1174 authors.Insert(author);
1183 return m_mAuthors[authorIdentity];
1192 author.m_iAuthorID = playerId;
1221 DiagMenu.RegisterRange(
SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_LOG_TYPE,
"",
"Log Type",
"Editable Entities",
string.Format(
"-1 %1 -1 1", state.GetVariableCount() - 1));
1222 DiagMenu.RegisterBool(
SCR_DebugMenuID.DEBUGUI_EDITOR_ENTITIES_DISABLE,
"",
"Disable entities",
"Editable Entities");
1237 m_CurrentLayer = null;
1264 m_CurrentLayer = null;
1267 m_CurrentLayer = null;
1270 budgetChangesAccumulated =
false;
1280 foreach (SCR_EditableEntityCoreBudgetSetting setting : m_BudgetSettings)
1282 setting.SetCurrentBudget(0);
1283 setting.UnreserveBudget(setting.GetReservedBudget());
1292 m_TypeSettingsMap.Insert(setting.GetType(), setting)
1300 m_LabelSettingsMap.Insert(labelSetting.GetLabelType(), labelSetting);
1311 array<int> allLabels = {};
1316 for (
int i = 0; i < count; i++)
1319 if (m_LabelSettingsMap.Contains(allLabels[i]))
1323 m_EntityLabels.Insert(labelSetting);
1324 m_LabelSettingsMap.Insert(allLabels[i], labelSetting);
1333 array<SCR_EditableEntityCoreLabelSetting> groupLabels = {};
1335 m_LabelGroupSettingsMap.Insert(labelGroupType, labelGroup);
1342 if (entityLabel.GetLabelGroupType() == labelGroupType)
1344 groupLabels.Insert(entityLabel);
1348 m_LabelListMap.Insert(labelGroupType, groupLabels);
1352 foreach (SCR_EditableEntityCoreBudgetSetting budgetSetting : m_BudgetSettings)
1354 m_BudgetSettingsInternal.Insert(budgetSetting.GetBudgetType(), budgetSetting);