Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
MeasureTool.c
Go to the documentation of this file.
1[WorkbenchToolAttribute(
2 "Measure Tool",
3 "Measure length along a 3D line\n" +
4 "Line segment length is rendered at the center of segment.\nTotal length rendered next to the cursor.\n\n" +
5 "LMB - Start measuring\nESC - Cancel measuring",
6 awesomeFontCode: 0xF545)]
7class MeasureTool : WorldEditorTool
8{
9 [Attribute(desc: "Measure against objects", category: "General")]
11
14 protected ref array<ref DebugTextWorldSpace> m_aSegmentLengths;
15 protected ref Shape m_Polyline;
16
19 protected float m_fDistancePrevious;
20 protected float m_fDistanceCurrent;
21 protected vector m_aLinePoints[1000];
22 protected int m_iLinePointsCount;
23 protected float m_fLastX;
24 protected float m_fLastY;
25 protected bool m_bActivated = false;
26
27 //------------------------------------------------------------------------------------------------
28 override void OnMouseMoveEvent(float x, float y)
29 {
30 vector traceStart;
31 vector traceEnd;
32 vector traceDir;
33
34 m_Crosshair.SetPosition(x, y);
35 m_Crosshair.SetText("+");
36 m_Text.SetPosition(x, y);
37
38 TraceFlags traceFlags = TraceFlags.WORLD;
40 traceFlags = TraceFlags.ENTS | TraceFlags.WORLD;
41
42 if (m_API.TraceWorldPos(x, y, traceFlags, traceStart, traceEnd, traceDir))
43 {
44 m_vCurrent3DPoint = traceEnd;
45
46 if (m_iLinePointsCount >= 1)
47 {
49 m_Text.SetText(" " + (m_fDistanceCurrent + m_fDistancePrevious).ToString() + " m");
51 m_Polyline = Shape.CreateLines(ARGB(255, 255, 255, 255), ShapeFlags.NOZBUFFER | ShapeFlags.TRANSP, m_aLinePoints, m_iLinePointsCount + 1);
52 m_fLastX = x;
53 m_fLastY = y;
54 }
55 }
56 else
57 {
58 // line is being drawn and cursor is out of terrain bounds, stick cursor and length info to terrain's edge
59 if (m_iLinePointsCount >= 1)
60 {
61 m_Crosshair.SetPosition(m_fLastX, m_fLastY);
62 m_Text.SetPosition(m_fLastX, m_fLastY);
63 }
64 else
65 // line is not being drawn and cursor is out of terrain bounds
66 {
67 m_Crosshair.SetText("");
68 }
69 }
70 }
71
72 //------------------------------------------------------------------------------------------------
73 override void OnMousePressEvent(float x, float y, WETMouseButtonFlag buttons)
74 {
75 vector traceStart;
76 vector traceEnd;
77 vector traceDir;
78 vector text_position;
79
80 if (m_iLinePointsCount == 0)
81 {
83 }
84
85 TraceFlags traceFlags = TraceFlags.WORLD;
87 traceFlags = TraceFlags.ENTS | TraceFlags.WORLD;
88
89 if (m_API.TraceWorldPos(x, y, traceFlags, traceStart, traceEnd, traceDir))
90 {
91 m_vCurrent3DPoint = traceEnd;
93
94 //Render line segments length
95 if (m_iLinePointsCount != 0)
96 {
97 text_position = m_vPrevious3DPoint + ((m_vCurrent3DPoint - m_vPrevious3DPoint).Normalized() * (m_vPrevious3DPoint - m_vCurrent3DPoint).Length() * 0.5);
98 m_aSegmentLengths.Insert(
100 m_API.GetWorld(),
101 (m_vPrevious3DPoint - m_vCurrent3DPoint).Length().ToString() + " m",
102 0,
103 text_position[0],
104 text_position[1],
105 text_position[2],
106 15,
107 ARGBF(1, 1, 1, 1),
108 0x00000000));
109 }
110
112 // Print(linePts[m_iLinePointsCount]);
114 // Print(m_iLinePointsCount);
116 }
117 }
118
119 //------------------------------------------------------------------------------------------------
120 override void OnKeyPressEvent(KeyCode key, bool isAutoRepeat)
121 {
122 //Cancel measuring
123 if (key == KeyCode.KC_ESCAPE && isAutoRepeat == false)
124 {
125 m_Text.SetText("");
126 m_aSegmentLengths.Clear();
128 m_fDistanceCurrent = 0.0;
129 m_vPrevious3DPoint = "0 0 0";
131 m_Polyline = Shape.CreateLines(ARGB(255, 255, 0, 0), ShapeFlags.NOZBUFFER | ShapeFlags.TRANSP, m_aLinePoints, m_iLinePointsCount + 1);
132 }
133 }
134
135 //------------------------------------------------------------------------------------------------
136 void Init()
137 {
139 m_API.GetWorld(), "",
140 DebugTextFlags.DONT_SCALE_POS,
141 100, 100, 14, ARGBF(1, 1, 1, 1), 0x00000000
142 );
144 m_API.GetWorld(), "",
145 DebugTextFlags.DONT_SCALE_POS | DebugTextFlags.CENTER,
146 0, 0, 30, ARGBF(1, 1, 1, 1), 0x00000000
147 );
150 }
151
152 //------------------------------------------------------------------------------------------------
153 void Deinit()
154 {
155 m_Text = null;
156 m_Crosshair = null;
157 m_aSegmentLengths.Clear();
159 m_fDistanceCurrent = 0.0;
160 m_vPrevious3DPoint = "0 0 0";
162 m_Polyline = null;
163 }
164
165 //------------------------------------------------------------------------------------------------
166 override void OnActivate()
167 {
168 Init();
169 m_bActivated = true;
170 }
171
172
173 override void OnDeActivate()
174 {
175 Deinit();
176 m_bActivated = false;
177 }
178
179 override void OnAfterLoadWorld()
180 {
181 if (m_bActivated)
182 {
183 // Loaded a world while the tool was activated
184 // => everything was deinitialized in OnBeforeUnloadWorld
185 // => reinit
186 Init();
187 }
188 }
189 override void OnBeforeUnloadWorld()
190 {
191 if (m_bActivated)
192 {
193 // Everything is invalid => deinitialize
194 Deinit();
195 }
196 }
197
198};
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
int m_iLinePointsCount
Definition MeasureTool.c:22
override void OnMousePressEvent(float x, float y, WETMouseButtonFlag buttons)
Definition MeasureTool.c:73
override void OnKeyPressEvent(KeyCode key, bool isAutoRepeat)
float m_fLastX
Definition MeasureTool.c:23
vector m_vPrevious3DPoint
Definition MeasureTool.c:17
ref DebugTextScreenSpace m_Text
Definition MeasureTool.c:12
ref array< ref DebugTextWorldSpace > m_aSegmentLengths
Definition MeasureTool.c:14
float m_fLastY
Definition MeasureTool.c:24
override void OnMouseMoveEvent(float x, float y)
Definition MeasureTool.c:28
void Deinit()
override void OnDeActivate()
override void OnActivate()
vector m_aLinePoints[1000]
Definition MeasureTool.c:21
bool m_bActivated
Definition MeasureTool.c:25
bool m_bCheckAgainstEntities
Definition MeasureTool.c:10
override void OnBeforeUnloadWorld()
vector m_vCurrent3DPoint
Definition MeasureTool.c:18
ref Shape m_Polyline
Definition MeasureTool.c:15
ref DebugTextScreenSpace m_Crosshair
Definition MeasureTool.c:13
float m_fDistanceCurrent
Definition MeasureTool.c:20
override void OnAfterLoadWorld()
float m_fDistancePrevious
Definition MeasureTool.c:19
Instance of created debug visualizer.
Definition Shape.c:14
DebugTextFlags
ShapeFlags
Definition ShapeFlags.c:13
SCR_FieldOfViewSettings Attribute
KeyCode
Definition KeyCode.c:13
proto external string ToString()
Plain C++ pointer, no weak pointers, no memory management.
TraceFlags
Definition TraceFlags.c:13
proto int ARGBF(float fa, float fr, float fg, float fb)
Converts <0.0, 1.0> ARGB into color.
proto int ARGB(int a, int r, int g, int b)