Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_MarkShapesEditorOnlyPlugin.c
Go to the documentation of this file.
1#ifdef WORKBENCH
2[WorkbenchPluginAttribute(name: "Mark shapes editor only", wbModules: { "WorldEditor"}, awesomeFontCode: 0xF023)]
3class SCR_MarkShapesEditorOnlyPlugin : WorkbenchPlugin
4{
5 [Attribute("false", UIWidgets.CheckBox)]
6 protected bool ActiveLayerOnly;
7
8 protected ref array<string> m_aEditorOnlyGenerators = {
9 "ForestGeneratorEntity",
10 "PrefabGeneratorEntity",
11 "RoadGeneratorEntity",
12 "SCR_PowerlineGeneratorEntity",
13 "WallGeneratorEntity"
14 };
15
16 //------------------------------------------------------------------------------------------------
17 [ButtonAttribute("OK")]
18 protected bool OkButton()
19 {
20 return true;
21 }
22
23 //------------------------------------------------------------------------------------------------
24 override void Run()
25 {
26 WorldEditor worldEditor = Workbench.GetModule(WorldEditor);
27 if (!worldEditor)
28 return;
29
30 WorldEditorAPI worldEditorAPI = worldEditor.GetApi();
31 if (!worldEditorAPI)
32 return;
33
34 BaseWorld world = worldEditorAPI.GetWorld();
35 if (!world)
36 return;
37
38 if (!Workbench.ScriptDialog("Configure editor only marking", "", this))
39 return;
40
41 if (!worldEditorAPI.BeginEntityAction())
42 return;
43
44 Print("--- Start marking shapes editor only", LogLevel.NORMAL);
45
46 // Progress dialog
47 int approximateCount = worldEditorAPI.GetEditorEntityCount();
48 WBProgressDialog progress = new WBProgressDialog("Marking", worldEditor);
49
50 worldEditorAPI.ToggleGeneratorEvents(false);
51
52 EditorEntityIterator iter = new EditorEntityIterator(worldEditorAPI);
53 IEntitySource src = iter.GetNext();
54 float prevProgress, currProgress;
55 while (src)
56 {
57 ProcessEntity(worldEditorAPI, src);
58 src = iter.GetNext();
59
60 currProgress = iter.GetCurrentIdx() / approximateCount;
61 if (currProgress - prevProgress >= 0.01) // min 1%
62 {
63 progress.SetProgress(currProgress); // expensive
64 prevProgress = currProgress;
65 }
66 }
67
68 worldEditorAPI.ToggleGeneratorEvents(true);
69 worldEditorAPI.EndEntityAction();
70
71 Print("--- Done marking shapes editor only", LogLevel.NORMAL);
72 }
73
74 //------------------------------------------------------------------------------------------------
75 protected void SetEditorOnly(WorldEditorAPI worldEditorAPI, IEntitySource src)
76 {
77 int flags;
78 src.Get("Flags", flags);
79 if ((flags & EntityFlags.EDITOR_ONLY) == 0)
80 {
81 flags |= EntityFlags.EDITOR_ONLY;
82 worldEditorAPI.SetVariableValue(src, null, "Flags", flags.ToString());
83 }
84 }
85
86 //------------------------------------------------------------------------------------------------
87 protected void ProcessEntity(WorldEditorAPI worldEditorAPI, IEntitySource src)
88 {
89 if (ActiveLayerOnly)
90 {
91 int activeLayer = worldEditorAPI.GetCurrentEntityLayerId();
92 if (src.GetLayerID() != activeLayer)
93 return;
94 }
95
96 int childCount = src.GetNumChildren();
97 string classname = src.GetClassName();
98
99 if (classname == "PolylineShapeEntity" || classname == "SplineShapeEntity")
100 {
101 // All shape entites are considered Editor Only by default
102 bool shapeEdOnly = true;
103
104 // All children must "support" editor only for the shape to be eligible
105 IEntitySource childSrc;
106 for (int i = 0; i < childCount; ++i)
107 {
108 // Check if given child falls into the "eligable" category
109 bool isEdOnlyGenerator = false;
110 childSrc = src.GetChild(i);
111 foreach (string editorOnlyGenerator : m_aEditorOnlyGenerators)
112 {
113 if (childSrc.GetClassName() == editorOnlyGenerator)
114 {
115 isEdOnlyGenerator = true;
116 // Even if the whole shape may not be editor only, the generator itself can
117 SetEditorOnly(worldEditorAPI, childSrc);
118 break;
119 }
120 }
121
122 // We have some entity which may need the shape in game, let's be conservative and don't mark it ed only
123 if (!isEdOnlyGenerator)
124 {
125 shapeEdOnly = false;
126 break;
127 }
128 }
129
130 if (shapeEdOnly)
131 SetEditorOnly(worldEditorAPI, src);
132 }
133 else
134 {
135 for (int i = 0; i < childCount; ++i)
136 {
137 ProcessEntity(worldEditorAPI, src.GetChild(i));
138 }
139 }
140 }
141}
142#endif // WORKBENCH
SCR_EAIThreatSectorFlags flags
GenerateFlowMaps WorkbenchPlugin WorkbenchPluginAttribute("Regenerate river flow-maps", "Generate and save/overwrite river flow-maps", "", "", {"WorldEditor"}, "", 0xf773)
Definition FlowmapTool.c:59
bool ProcessEntity(IEntity ent)
override void Run()
class WorkbenchDialog_AbortRetryIgnore ButtonAttribute("OK", true)
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
SCR_FieldOfViewSettings Attribute
EntityFlags
Various entity flags.
Definition EntityFlags.c:14