Arma Reforger Explorer  1.1.0.42
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
CommentEntity.c
Go to the documentation of this file.
1 [EntityEditorProps(category: "GameScripted/Utility", description: "Editor comment, for leaving notes in the editor", sizeMin: "-1 -1 -1", sizeMax: "1 1 1", visible: false, dynamicBox: true)]
2 class CommentEntityClass : GenericEntityClass
3 {
4 };
5 
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  vector 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  vector 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  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];
84  GetWorldTransform(mat);
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[0], m_BackgroundColor[1], m_BackgroundColor[2]);
92  else
93  bgColor = ARGBF(0, 0, 0, 0);
94  DebugTextWorldSpace.CreateInWorld(GetWorld(), m_Comment, dtFlags, mat, size, ARGBF(1 - m_Transparency, m_Color[0], m_Color[1], m_Color[2]), 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  //------------------------------------------------------------------------------------------------
116  override void _WB_AfterWorldUpdate(float timeSlice)
117  {
118  WorldEditorAPI api = _WB_GetEditorAPI();
119  if (!api)
120  return;
121 
122  IEntitySource src = api.EntityToSource(this);
123  if (!src)
124  return;
125 
126  if (api.IsEntityLayerVisible(src.GetSubScene(), src.GetLayerID()))
127  DrawComment();
128  }
129 #endif
130 
131  //------------------------------------------------------------------------------------------------
132  override void EOnFrame(IEntity owner, float timeSlice)
133  {
134  DrawComment();
135  }
136 
137  //------------------------------------------------------------------------------------------------
138  void CommentEntity(IEntitySource src, IEntity parent)
139  {
140  if (m_VisibleIngame && RplSession.Mode() != RplMode.Dedicated)
141  {
142  SetEventMask(EntityEvent.FRAME);
143  }
144 
145  ChimeraWorld world = GetGame().GetWorld();
146  if (world)
147  world.RegisterEntityToBeUpdatedWhileGameIsPaused(this);
148  }
149 
150  //------------------------------------------------------------------------------------------------
151  void ~CommentEntity()
152  {
153  ChimeraWorld world = GetGame().GetWorld();
154  if (world)
155  world.UnregisterEntityToBeUpdatedWhileGameIsPaused(this);
156  }
157 };
ChimeraWorld
Definition: ChimeraWorld.c:12
EntityEditorProps
enum EQueryType EntityEditorProps(category:"GameScripted/Sound", description:"THIS IS THE SCRIPT DESCRIPTION.", color:"0 0 255 255")
Definition: SCR_AmbientSoundsComponent.c:12
CommentEntity
Definition: CommentEntity.c:6
CommentEntityClass
Definition: CommentEntity.c:2
GetGame
ArmaReforgerScripted GetGame()
Definition: game.c:1424
GenericEntity
SCR_GenericBoxEntityClass GenericEntity
GetOrigin
vector GetOrigin()
Definition: SCR_AIUtilityComponent.c:279
Attribute
typedef Attribute
Post-process effect of scripted camera.
m_Color
ref Color m_Color
Definition: SCR_GeneratorBaseEntity.c:3
category
params category
Definition: SCR_VehicleDamageManagerComponent.c:180