Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
EditablePrefabsLabel_Size.c
Go to the documentation of this file.
3{
4 [Attribute()]
5 protected float sizeXS;
6
7 [Attribute()]
8 protected float sizeS;
9
10 [Attribute()]
11 protected float sizeM;
12
13 [Attribute()]
14 protected float sizeL;
15
16 [Attribute()]
17 protected float sizeXL;
18
19 [Attribute()]
20 protected bool m_IgnoreY;
21
22 [Attribute()]
23 protected bool m_DebugPrintSize;
24
25 //------------------------------------------------------------------------------------------------
26 override bool GetLabelValid(WorldEditorAPI api, IEntitySource entitySource, IEntityComponentSource componentSource, string targetPath, EEditableEntityType entityType, notnull array<EEditableEntityLabel> authoredLabels, out EEditableEntityLabel label)
27 {
28 // Skip groups & authored compositions (SLOTSIZE label)
29 if (entityType == EEditableEntityType.GROUP || ContainsSlotSizeLabel(authoredLabels))
30 return false;
31
32 ResourceName prefab = entitySource.GetResourceName();
33
34 vector prefabBoundsMin = vector.One * float.MAX;
35 vector prefabBoundsMax = vector.One * -float.MAX;
36
37 GetEntitySourceBounds(api, entitySource, prefabBoundsMin, prefabBoundsMax);
38
39 if (m_IgnoreY)
40 {
41 prefabBoundsMin[1] = 0;
42 prefabBoundsMax[1] = 0;
43 }
44
45 vector prefabBounds = prefabBoundsMax - prefabBoundsMin;
46
47 float prefabSize = prefabBounds.Length();
48
50 Print(string.Format("%1", prefabSize), LogLevel.DEBUG);
51
52 if (prefabSize == 0)
53 {
54 Print("Calculated editable entity size is 0", LogLevel.NORMAL);
55 return false;
56 }
57
58 if (prefabSize >= sizeXL)
59 label = EEditableEntityLabel.SIZE_XL;
60 else if (prefabSize >= sizeL)
61 label = EEditableEntityLabel.SIZE_L;
62 else if (prefabSize >= sizeM)
63 label = EEditableEntityLabel.SIZE_M;
64 else if (prefabSize >= sizeS)
65 label = EEditableEntityLabel.SIZE_S;
66 else
67 label = EEditableEntityLabel.SIZE_XS;
68
69 if (ContainsSizeLabel(authoredLabels))
70 {
71 // Authored labels contains size label and differs from calculated label, show warning
72 if (!authoredLabels.Contains(label))
73 Print("Calculated size " + typename.EnumToString(EEditableEntityLabel, label) + " differs from authored size label", LogLevel.WARNING);
74
75 // Dont add calculated label if authored size label exists.
76 return false;
77 }
78
79 return true;
80 }
81
82 //------------------------------------------------------------------------------------------------
83 protected bool ContainsSlotSizeLabel(notnull array<EEditableEntityLabel> authoredLabels, EEditableEntityLabel optSizeLabelCheck = EEditableEntityLabel.NONE)
84 {
85 // AuthoredLabels contains any SlotSize label
86 return authoredLabels.Contains(EEditableEntityLabel.SLOT_FLAT_SMALL) ||
87 authoredLabels.Contains(EEditableEntityLabel.SLOT_FLAT_MEDIUM) ||
88 authoredLabels.Contains(EEditableEntityLabel.SLOT_FLAT_LARGE) ||
89 authoredLabels.Contains(EEditableEntityLabel.SLOT_ROAD_SMALL) ||
90 authoredLabels.Contains(EEditableEntityLabel.SLOT_ROAD_MEDIUM) ||
91 authoredLabels.Contains(EEditableEntityLabel.SLOT_ROAD_LARGE);
92 }
93
94 //------------------------------------------------------------------------------------------------
95 protected bool ContainsSizeLabel(notnull array<EEditableEntityLabel> authoredLabels, EEditableEntityLabel optSizeLabelCheck = EEditableEntityLabel.NONE)
96 {
97 // AuthoredLabels contains any size label
98 return authoredLabels.Contains(EEditableEntityLabel.SIZE_XL) ||
99 authoredLabels.Contains(EEditableEntityLabel.SIZE_L) ||
100 authoredLabels.Contains(EEditableEntityLabel.SIZE_M) ||
101 authoredLabels.Contains(EEditableEntityLabel.SIZE_S) ||
102 authoredLabels.Contains(EEditableEntityLabel.SIZE_XS);
103 }
104
105 //------------------------------------------------------------------------------------------------
106 protected string GetFileName(ResourceName prefab)
107 {
108 string name = FilePath.StripPath(prefab);
109 return FilePath.StripExtension(name);
110 }
111
112 //------------------------------------------------------------------------------------------------
113 protected void GetEntitySourceBounds(WorldEditorAPI api, IEntitySource source, out vector boundsMin, out vector boundsMax)
114 {
115 IEntity entity = api.SourceToEntity(source);
116 if (!entity)
117 return;
118
119 VObject object = entity.GetVObject();
120 if (object)
121 {
122 string ext;
123 FilePath.StripExtension(object.GetResourceName(), ext);
124 if (ext == "xob")
125 {
126 vector entityMin, entityMax;
127 //Print("EntityPos check: " + entity.GetWorldTransformAxis(3));
128 entity.GetWorldBounds(entityMin, entityMax);
129 //entityMin = entity.CoordToParent(entityMin);
130 //entityMax = entity.CoordToParent(entityMax);
131
132 boundsMin[0] = Math.Min(boundsMin[0], entityMin[0]);
133 boundsMin[1] = Math.Min(boundsMin[1], entityMin[1]);
134 boundsMin[2] = Math.Min(boundsMin[2], entityMin[2]);
135
136 boundsMax[0] = Math.Max(boundsMax[0], entityMax[0]);
137 boundsMax[1] = Math.Max(boundsMax[1], entityMax[1]);
138 boundsMax[2] = Math.Max(boundsMax[2], entityMax[2]);
139 }
140 }
141
142 //Print(string.Format("BoundsMin: %1, BoundsMax: %2", boundsMin, boundsMax), LogLevel.NORMAL);
143
144 int childrenCount = source.GetNumChildren();
145 for (int i = 0; i < childrenCount; i++)
146 {
147 GetEntitySourceBounds(api, source.GetChild(i), boundsMin, boundsMax);
148 }
149 }
150}
EEditableEntityLabel
SCR_AIAnimation_Loitering BaseContainerProps
Commanding menu commanding element class.
class SCR_CampaignHintStorage SCR_BaseContainerCustomTitleEnum(EHint, "m_eHintId")
override bool GetLabelValid(WorldEditorAPI api, IEntitySource entitySource, IEntityComponentSource componentSource, string targetPath, EEditableEntityType entityType, notnull array< EEditableEntityLabel > authoredLabels, out EEditableEntityLabel label)
string GetFileName(ResourceName prefab)
bool ContainsSizeLabel(notnull array< EEditableEntityLabel > authoredLabels, EEditableEntityLabel optSizeLabelCheck=EEditableEntityLabel.NONE)
bool ContainsSlotSizeLabel(notnull array< EEditableEntityLabel > authoredLabels, EEditableEntityLabel optSizeLabelCheck=EEditableEntityLabel.NONE)
void GetEntitySourceBounds(WorldEditorAPI api, IEntitySource source, out vector boundsMin, out vector boundsMax)
proto external void GetWorldBounds(out vector mins, out vector maxs)
proto external VObject GetVObject()
Returns visual object set to this Entity. No reference is added.
Definition Math.c:13
Visual object.
Definition VObject.c:14
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
EEditableEntityType
Defines type of SCR_EditableEntityComponent. Assigned automatically based on IEntity inheritance.
SCR_FieldOfViewSettings Attribute