5 name:
"Entity Flags Manager",
6 description:
"Reset all/selected entities' desired flags to Prefab's default",
7 shortcut:
"Ctrl+Shift+F",
8 wbModules: {
"WorldEditor" })]
9class SCR_EntityFlagsManagerPlugin : WorldEditorPlugin
16 protected bool m_bResetTraceableFlag;
19 protected bool m_bResetVisibleFlag;
22 protected bool m_bResetStaticFlag;
25 protected bool m_bResetFeatureFlag;
28 protected bool m_bResetNoLinkFlag;
31 protected bool m_bResetProxyFlag;
34 protected bool m_bResetEditorOnlyFlag;
37 protected bool m_bResetDisabledFlag;
40 protected bool m_bResetRelativeYFlag;
43 protected bool m_bResetOnFilteredNavmeshFlag;
50 protected bool m_bProcessEverythingSelected;
56 protected bool m_bProcessRocks;
59 protected bool m_bProcessTrees;
62 protected bool m_bProcessBushes;
65 protected bool m_bProcessBuildings;
74 [
Attribute(defvalue:
"0",
desc:
"[COSTY] Process child entities - may be problematic with e.g forest generators",
category:
"Options")]
75 protected bool m_bUpdateChildEntities;
77 [
Attribute(defvalue:
"0",
desc:
"Force flags cleaning - slower but sure to remove unneeded flags",
category:
"Options")]
78 protected bool m_bForceCleaning;
80 protected static const int PROGRESSBAR_TIMEOUT = 3000;
81 protected static const int PROGRESSBAR_REFRESH = 1000;
82 protected static const string COORDS =
"coords";
83 protected static const string FLAGS =
"Flags";
84 protected static const ResourceName ROCK_BASE =
"{B94DDC61F0B7F9D7}Prefabs/Rocks/Rock_Base.et";
85 protected static const ResourceName TREE_BASE =
"{388AE316D09D0680}Prefabs/Vegetation/Core/Tree_Base.et";
86 protected static const ResourceName BUSH_BASE =
"{D7163D1B571F4C0C}Prefabs/Vegetation/Core/Bush_Base.et";
87 protected static const ResourceName BUILDING_BASE =
"{A43A100E3C377DB2}Prefabs/Structures/Core/Building_Base.et";
92 WorldEditorAPI worldEditorAPI = SCR_WorldEditorToolHelper.GetWorldEditorAPI();
99 int selectedCount = worldEditorAPI.GetSelectedEntitiesCount();
100 string message =
"Entities currently selected: " + selectedCount;
102 if (selectedCount < 1)
104 m_bProcessEverythingSelected =
false;
105 message +=
"\n\n[ WARNING: you are about to process ALL TERRAIN ENTITIES ]";
109 if (!Workbench.ScriptDialog(
"Entity Flags Manager", message,
this))
113 m_bResetTraceableFlag ||
114 m_bResetVisibleFlag ||
115 m_bResetStaticFlag ||
116 m_bResetFeatureFlag ||
117 m_bResetNoLinkFlag ||
119 m_bResetEditorOnlyFlag ||
120 m_bResetDisabledFlag ||
121 m_bResetRelativeYFlag ||
122 m_bResetOnFilteredNavmeshFlag
125 Print(
"No Flags were selected for reset; leaving",
LogLevel.WARNING);
130 array<ResourceName> validTopMostAncestors = {};
131 if (!m_bProcessEverythingSelected)
134 validTopMostAncestors.Insert(ROCK_BASE);
137 validTopMostAncestors.Insert(TREE_BASE);
139 if (m_bProcessBushes)
140 validTopMostAncestors.Insert(BUSH_BASE);
142 if (m_bProcessBuildings)
143 validTopMostAncestors.Insert(BUILDING_BASE);
145 if (validTopMostAncestors.IsEmpty())
147 Print(
"No Entity Types have been selected; leaving",
LogLevel.WARNING);
153 array<IEntitySource> entitySources = GetEntitySources(validTopMostAncestors);
155 int entitySourcesCount = entitySources.Count();
156 if (entitySourcesCount < 1)
163 ProcessEntitySources(entitySources);
169 protected void ProcessEntitySources(array<IEntitySource> entitySources)
171 int entitySourcesCount = entitySources.Count();
173 int lastRefresh =
System.GetTickCount();
174 WBProgressDialog progress;
177 int clearedFlags, editedFlags, fixed;
179 WorldEditorAPI worldEditorAPI = SCR_WorldEditorToolHelper.GetWorldEditorAPI();
181 Debug.BeginTimeMeasure();
182 worldEditorAPI.BeginEntityAction();
186 if (!entitySource.GetAncestor())
190 if (!entitySource.Get(
FLAGS, oldFlags))
192 Print(
"Could not get flags from entitySource",
LogLevel.WARNING);
197 if (!entitySource.GetAncestor().Get(
FLAGS, prefabFlags))
205 bool useEditSequence = m_bResetRelativeYFlag;
207 worldEditorAPI.BeginEditSequence(entitySource);
213 if (m_bResetTraceableFlag)
221 if (m_bResetVisibleFlag)
229 if (m_bResetStaticFlag)
237 if (m_bResetFeatureFlag)
245 if (m_bResetNoLinkFlag)
253 if (m_bResetProxyFlag)
261 if (m_bResetEditorOnlyFlag)
269 if (m_bResetDisabledFlag)
277 if (m_bResetRelativeYFlag)
290 entitySource.Get(COORDS, entityPos);
291 if (worldEditorAPI.TryGetTerrainSurfaceY(entityPos[0], entityPos[2], y))
292 entityPos[1] = entityPos[1] + y;
294 Print(
"Entity " + worldEditorAPI.SourceToEntity(entitySource).
GetID() +
" position cannot be changed (ATL to World)",
LogLevel.WARNING);
307 entitySource.Get(COORDS, entityPos);
308 if (worldEditorAPI.TryGetTerrainSurfaceY(entityPos[0], entityPos[2], y))
309 entityPos[1] = entityPos[1] - y;
311 Print(
"Entity " + worldEditorAPI.SourceToEntity(entitySource).
GetID() +
" position cannot be changed (World to ATL)",
LogLevel.WARNING);
320 if (m_bResetOnFilteredNavmeshFlag)
333 if (!m_bForceCleaning && oldFlags == newFlags && newFlags == prefabFlags)
336 if (newFlags == prefabFlags)
338 worldEditorAPI.ClearVariableValue(entitySource, null,
FLAGS);
342 if (newFlags != oldFlags)
344 worldEditorAPI.SetVariableValue(entitySource, null,
FLAGS, newFlags.ToString());
349 if (m_bResetRelativeYFlag && entityPos !=
vector.Zero)
350 worldEditorAPI.SetVariableValue(entitySource, null, COORDS, entityPos.ToString(
false));
352 if (oldFlags != newFlags)
356 worldEditorAPI.EndEditSequence(entitySource);
358 int timeDiff =
System.GetTickCount() - lastRefresh;
361 if (timeDiff > PROGRESSBAR_TIMEOUT)
363 progress =
new WBProgressDialog(
"Processing " + entitySourcesCount +
" entities...", Workbench.GetModule(WorldEditor));
364 progress.SetProgress(i / entitySourcesCount);
368 if (timeDiff > PROGRESSBAR_REFRESH)
370 progress.SetProgress(i / entitySourcesCount);
371 lastRefresh =
System.GetTickCount();
375 worldEditorAPI.EndEntityAction();
376 Debug.EndTimeMeasure(
"Entity flag fixing");
378 Print(
"Fixed " + fixed +
"/" + entitySourcesCount +
" entities (edited: " + editedFlags +
" / cleared " + clearedFlags +
")",
LogLevel.NORMAL);
386 protected array<IEntitySource> GetEntitySources(array<ResourceName> validAncestors)
389 array<IEntitySource> result = {};
390 WorldEditorAPI worldEditorAPI = SCR_WorldEditorToolHelper.GetWorldEditorAPI();
391 int selectedCount = worldEditorAPI.GetSelectedEntitiesCount();
393 Debug.BeginTimeMeasure();
394 if (selectedCount > 0)
397 originalCount = selectedCount;
398 result.Reserve(selectedCount);
399 for (
int i = 0; i < selectedCount; i++)
401 entitySource = worldEditorAPI.GetSelectedEntity(i);
406 if (!m_bUpdateChildEntities && entitySource.GetParent())
409 if (m_bProcessEverythingSelected || validAncestors.Contains(
SCR_BaseContainerTools.GetTopMostAncestor(entitySource).GetResourceName()))
410 result.Insert(entitySource);
415 int entitiesCount = worldEditorAPI.GetEditorEntityCount();
416 originalCount = entitiesCount;
417 result.Reserve(entitiesCount);
419 for (
int i = 0; i < entitiesCount; i++)
421 entitySource = worldEditorAPI.GetEditorEntity(i);
425 if (!m_bUpdateChildEntities && entitySource.GetParent())
430 result.Insert(entitySource);
433 Debug.EndTimeMeasure(
"Filtering " + result.Count() +
"/" + originalCount +
" entities");
440 protected bool BtnOK()
447 protected bool BtnCancel()
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
proto external EntityID GetID()
proto void Print(void var, LogLevel level=LogLevel.NORMAL)
Prints content of variable to console/log.
LogLevel
Enum with severity of the logging message.
SCR_FieldOfViewSettings Attribute
EntityFlags
Various entity flags.