Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_AIMessageVisualization.c
Go to the documentation of this file.
1class SCR_AIMessageVisualization
2{
3 private const float RANGE_SQR = 500 * 500;
4 IEntity m_TargetEntity;
5 private string m_sMessage;
6 private float m_fTimeout;
7 private int m_Color;
8 private float m_fSize;
9
10 static const bool DRAW_TRANSPARENCY = false;
11 static const float HEIGHT = 2;
12 static const ref Color COLOR_BACKGROUND = Color.FromSRGBA(0, 0, 0, 64); //UIColors.TRANSPARENT;
13
14 //------------------------------------------------------------------------------------------------
15 void SCR_AIMessageVisualization(IEntity entity, string message, float showTime = 10, Color color = Color.White, float fontSize = 16)
16 {
17 m_TargetEntity = entity;
18 m_sMessage = message;
19 m_fTimeout = showTime;
20 m_Color = color.PackToInt();
21 m_fSize = fontSize;
22 }
23
24 // @TODO: Optimize: No need to get camera transform multiple times, that can be done just once
25 //------------------------------------------------------------------------------------------------
26 bool Draw(float timeSlice)
27 {
28 if (m_fTimeout <= 0 || m_sMessage == string.Empty || !m_TargetEntity)
29 return true;
30
31 m_fTimeout -= timeSlice;
32
33 // Do not draw if camera is not looking at the owner
34 vector mat[4];
35 BaseWorld world = m_TargetEntity.GetWorld();
36 world.GetCurrentCamera(mat);
37 vector targetPos = m_TargetEntity.GetOrigin();
38 float dot = vector.Dot(mat[2], (targetPos - mat[3]).Normalized());
39 float distanceSqr = vector.DistanceSq(mat[3], targetPos);
40 if (dot < 0 || distanceSqr > RANGE_SQR) // More than 90 deg to right/left
41 return false;
42
43 ShapeFlags flags = ShapeFlags.ONCE | ShapeFlags.TRANSP;
44 if (DRAW_TRANSPARENCY)
45 flags |= ShapeFlags.TRANSP;
46
47 int dtFlags = DebugTextFlags.CENTER | DebugTextFlags.ONCE;
48 vector origin = m_TargetEntity.GetOrigin();
49 origin[1] = origin[1] + HEIGHT;
50 vector pos = GetGame().GetWorkspace().ProjWorldToScreenNative(origin, world);
51
52 DebugTextScreenSpace.Create(m_TargetEntity.GetWorld(), m_sMessage, dtFlags, pos[0], pos[1], m_fSize, m_Color, COLOR_BACKGROUND.PackToInt());
53 return false;
54 }
55};
SCR_EAIThreatSectorFlags flags
ArmaReforgerScripted GetGame()
Definition game.c:1398
Definition Color.c:13
DebugTextFlags
ShapeFlags
Definition ShapeFlags.c:13