Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
EditorCommentEntity.c
Go to the documentation of this file.
1[EntityEditorProps(category: "GameLib/Scripted", description: "Editor comment, for leaving notes in the editor", sizeMin: "-1 -1 -1", sizeMax: "1 1 1", visible: false, dynamicBox: true)]
2class EditorCommentEntityClass : GenericEntityClass
3{
4};
5
6class EditorCommentEntity : GenericEntity
7{
8 [Attribute("New comment", UIWidgets.EditBoxMultiline, "Write any comment you wish")]
9 string m_Comment;
10
11 [Attribute("0.2", UIWidgets.EditBox, "Text size in meters")]
12 float m_Size;
13
14 [Attribute("1 1 1", UIWidgets.ColorPicker, "Text color")]
15 ref Color m_Color;
16
17 [Attribute("0", UIWidgets.Slider, "Text transparency", "0 1 0.05")]
18 float m_Transparency;
19
20 [Attribute("0", UIWidgets.CheckBox, "If true, text is scaled by distance from camera")]
21 bool m_ScaleByDistance;
22
23 [Attribute("0", UIWidgets.CheckBox, "If true, text will face the camera")]
24 bool m_FaceCamera;
25
26 [Attribute("0", UIWidgets.CheckBox, "If true, text will be visible over everything")]
27 bool m_VisibleOverall;
28
29 [Attribute("0", UIWidgets.CheckBox, "If true, text will be visible even ingame")]
30 bool m_VisibleIngame;
31
32 [Attribute("0", UIWidgets.CheckBox, "If true, text will have a darkened background plane for easier visibility")]
33 bool m_TextBackground;
34
35 [Attribute("0 0 0", UIWidgets.ColorPicker, "Background color")]
36 ref Color m_BackgroundColor;
37
38 [Attribute("0.5", UIWidgets.Slider, "Background transparency", "0 1 0.05")]
39 float m_BackgroundTransparency;
40
41 //------------------------------------------------------------------------------------------------
42 private void DrawComment()
43 {
44 const float textWidthScale = 0.7;
45
46 vector textMat[4];
47 GetWorld().GetCurrentCamera(textMat);
48
49 if (!m_FaceCamera)
50 {
51 textMat[0] = GetTransformAxis(0);
52 textMat[1] = GetTransformAxis(1);
53 textMat[2] = GetTransformAxis(2);
54 }
55
56 float distScale = 1;
57 if (m_ScaleByDistance)
58 {
59 distScale = vector.Distance(textMat[3], GetOrigin()) * 0.1;
60 distScale = Math.Clamp(distScale, 0.5, 10);
61 }
62
63 float textEndSize = (m_Size * distScale) / vector.Distance(textMat[3], GetOrigin());
64 if (textEndSize < 0.005)
65 return;
66
67 textMat[3] = GetOrigin() - textMat[1] * m_Size * distScale * 0.5;
68 ShapeFlags flags = ShapeFlags.ONCE | ShapeFlags.TRANSP;
69 if (m_VisibleOverall)
70 flags |= ShapeFlags.NOZBUFFER;
71 if (m_Transparency > 0)
72 flags |= ShapeFlags.TRANSP;
73
74#ifdef WORKBENCH
75 m_fWB_Width = m_Comment.Length() * m_Size * distScale * textWidthScale;
76 m_fWB_Height = m_Size * distScale;
77#endif
78
79 //CreateSimpleText(m_Comment, textMat, m_Size * distScale, ARGBF(1 - m_Transparency, m_Color[0], m_Color[1], m_Color[2]), flags, null, textWidthScale, m_TextBackground, ARGBF(1 - m_BackgroundTransparency, m_BackgroundColor[0], m_BackgroundColor[1], m_BackgroundColor[2]));
80 int dtFlags = DebugTextFlags.CENTER | DebugTextFlags.ONCE;
81 if (m_FaceCamera)
82 dtFlags |= DebugTextFlags.FACE_CAMERA;
83 vector mat[4];
85 float size = m_Size;
86 if (m_ScaleByDistance)
87 size *= 10; // To keep the sizes similar for now
88
89 int bgColor;
90 if (m_TextBackground)
91 bgColor = ARGBF(1 - m_BackgroundTransparency, m_BackgroundColor.R(), m_BackgroundColor.G(), m_BackgroundColor.B());
92 else
93 bgColor = ARGBF(0, 0, 0, 0);
94 DebugTextWorldSpace.CreateInWorld(GetWorld(), m_Comment, dtFlags, mat, size, ARGBF(1 - m_Transparency, m_Color.R(), m_Color.G(), m_Color.B()), bgColor);
95 }
96
97#ifdef WORKBENCH
98 float m_fWB_Width = 1;
99 float m_fWB_Height = 1;
100 //------------------------------------------------------------------------------------------------
101 override void _WB_GetBoundBox(inout vector min, inout vector max, IEntitySource src)
102 {
103 if (m_FaceCamera)
104 {
105 min = Vector(m_fWB_Width * -0.5, m_fWB_Height * -0.5, m_fWB_Width * -0.5);
106 max = Vector(m_fWB_Width * 0.5, m_fWB_Height * 0.5, m_fWB_Width * 0.5);
107 }
108 else
109 {
110 min = Vector(m_fWB_Width * -0.5, m_fWB_Height * -0.5, m_fWB_Height * 0.25 * -0.5);
111 max = Vector(m_fWB_Width * 0.5, m_fWB_Height * 0.5, m_fWB_Height * 0.25 * 0.5);
112 }
113 }
114
115 //------------------------------------------------------------------------------------------------
117 {
118 return EEntityFrameUpdateSpecs.CALL_WHEN_ENTITY_VISIBLE;
119 }
120
121 //------------------------------------------------------------------------------------------------
122 override void _WB_AfterWorldUpdate(float timeSlice)
123 {
125 if (!api)
126 return;
127
128 IEntitySource src = api.EntityToSource(this);
129 if (!src)
130 return;
131
132 if (api.IsEntityLayerVisible(src.GetSubScene(), src.GetLayerID()))
133 DrawComment();
134 }
135#endif
136
137 //------------------------------------------------------------------------------------------------
138 override void EOnFrame(IEntity owner, float timeSlice)
139 {
140 DrawComment();
141 }
142
143 //------------------------------------------------------------------------------------------------
144 void EditorCommentEntity(IEntitySource src, IEntity parent)
145 {
146 if (m_VisibleIngame && RplSession.Mode() != RplMode.Dedicated)
147 {
149 }
150 }
151
152};
SCR_EAIThreatSectorFlags flags
int size
RplMode
Mode of replication.
Definition RplMode.c:9
enum SCR_ECompassType EntityEditorProps(category:"GameScripted/Gadgets", description:"Compass", color:"0 0 255 255")
Prefab data class for compass component.
Definition Color.c:13
event void _WB_GetBoundBox(inout vector min, inout vector max, IEntitySource src)
Editor needs to know a bound box of entity (For ray-casting, visualizers etc.). You can return any cu...
event void _WB_AfterWorldUpdate(float timeSlice)
Called after updating world in Workbench. The entity must be visible in frustum, selected or named....
proto external WorldEditorAPI _WB_GetEditorAPI()
This returns world editor API, which is safe to use from editor events bellow.
event int _WB_GetAfterWorldUpdateSpecs(IEntitySource src)
Called after _WB_OnInit or also later when editor needs to know whether _WB_AfterWorldUpdate needs to...
void IEntity(IEntitySource src, IEntity parent)
protected script Constructor
proto external EntityEvent SetEventMask(EntityEvent e)
proto external vector GetOrigin()
proto external void GetWorldTransform(out vector mat[])
See IEntity::GetTransform.
proto external BaseWorld GetWorld()
proto external vector GetTransformAxis(int axis)
See IEntity::GetTransformAxis.
Definition Math.c:13
DebugTextFlags
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
EntityEvent
Various entity events.
Definition EntityEvent.c:14
proto native vector Vector(float x, float y, float z)
proto int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.