Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_PlacedCommandInfoDisplay.c
Go to the documentation of this file.
1class SCR_PlacedCommandInfoDisplay : SCR_InfoDisplayExtended
2{
3 [Attribute("1000", desc: "Max distance to command position in meters.")]
4 protected float m_fCommandVisualRange;
5
6 [Attribute("0 1 0.5 0", UIWidgets.CurveDialog, params: "1 0.6 0 0.2")]
7 protected ref Curve m_aScaleCurve;
8
9 [Attribute("Frame")]
10 protected string m_sCommandFrameWidgetName;
11
12 [Attribute("Icon")]
13 protected string m_sCommandIconWidgetName;
14
15 [Attribute("Glow")]
16 protected string m_sCommandGlowWidgetName;
17
18 [Attribute("Pulse")]
19 protected string m_sCommandPulseWidgetName;
20
21 [Attribute("PulsePreview")]
23
24 [Attribute("26", desc: "Default Image size of Command Icon Widget.")]
25 protected float m_fCommandIconWidgetSize;
26
27 [Attribute("48", desc: "Default Image size of Command Glow Widget.")]
28 protected float m_fCommandGlowWidgetSize;
29
30 [Attribute("64", desc: "Default Image size of Command Pulse Preview Widget.")]
32
33 protected bool m_bCanUpdate;
34 protected bool m_bCanUpdatePosition;
35 protected bool m_bIsPreview;
36
37 protected float m_fDistance;
38
41
47
49
51
52 protected ref TraceParam m_TraceParam;
53
54 protected static const int PULSE_WIDGET_MAX_SIZE = 70;
55
56 protected static const float BASE_FOV = 100;
57 protected static const float LINE_OF_SIGHT_THRESHOLD = 0.25;
58
59 //------------------------------------------------------------------------------------------------
79
80 //------------------------------------------------------------------------------------------------
86
87 //------------------------------------------------------------------------------------------------
88 override void DisplayUpdate(IEntity owner, float timeSlice)
89 {
91 return;
92
95
96 if (m_vCommandPosition == vector.Zero)
97 return;
98
99 int screenW = m_wWorkspace.GetWidth();
100 int screenH = m_wWorkspace.GetHeight();
101 screenW = m_wWorkspace.DPIUnscale(screenW);
102 screenH = m_wWorkspace.DPIUnscale(screenH);
103
104 float posX, posY;
105 GetWorldToScreenPosition(GetGame().GetWorld(), m_vCommandPosition, posX, posY);
106
107 BaseWorld world = GetGame().GetWorld();
108 int cameraIndex = world.GetCurrentCameraId();
109 vector transform[4];
110 world.GetCamera(cameraIndex, transform);
111
112 if (posX < 0 || posX > screenW || posY < 0 || posY > screenH || !IsInLineOfSight(m_vCommandPosition, transform))
113 {
114 m_wCommandFrameWidget.SetVisible(false);
115 return;
116 }
117 else
118 {
119 m_wCommandFrameWidget.SetVisible(true);
120 }
121
122 FrameSlot.SetPos(m_wCommandFrameWidget, posX, posY);
123
124 float zoom = 1; // world.GetCameraVerticalFOV(cameraIndex) - missing crucial getter
125 CameraManager cameraManager = GetGame().GetCameraManager();
126 if (cameraManager)
127 {
128 CameraBase camera = cameraManager.CurrentCamera();
129 if (camera && camera.GetProjType() != CameraType.NONE)
130 zoom = BASE_FOV / Math.Max(camera.GetVerticalFOV(), 1);
131 }
132
133 vector referencePos = transform[3];
134 float distanceLimit = m_fCommandVisualRange * zoom;
135
137 {
138 float distanceSq = vector.DistanceSq(m_vCommandPosition, referencePos);
139 m_fDistance = Math.Sqrt(distanceSq);
140 }
141
142 float sizeScale = 1;
143 // Calculate the distance from the camera to the world position on a range from 0-1
144 if (distanceLimit != 0)
145 sizeScale = Math.Clamp(distanceLimit - m_fDistance, 0.2, distanceLimit) / distanceLimit;
146
147 // Get the current Y value (size multiplier) based on the current distance from the curve
148 sizeScale = LegacyCurve.Curve(ECurveType.CurveProperty2D, sizeScale, m_aScaleCurve)[1];
149
150 float iconSize;
152 {
154 m_wCommandIconWidget.SetSize(iconSize, iconSize);
155 }
156
158 {
160 m_wCommandGlowWidget.SetSize(iconSize, iconSize);
161 }
162
164 {
166 m_wCommandPulsePreviewWidget.SetSize(iconSize, iconSize);
167 }
168 }
169
170 //------------------------------------------------------------------------------------------------
171 protected void UpdatePosition()
172 {
173 if (m_PhysicsHelper)
174 return;
175
176 PlayerController controller = GetGame().GetPlayerController();
177 PlayerCamera camera = PlayerCamera.Cast(GetGame().GetCameraManager().CurrentCamera());
178 if (!camera)
179 return;
180
181 IEntity controlledEntity = controller.GetControlledEntity();
182
183 vector mat[4];
184 camera.GetTransform(mat);
185 vector end = mat[3] + mat[2] * m_fCommandVisualRange;
186
187 //ToDO:@Kuceramar check / optimize trace performance
188 if (!m_TraceParam)
189 {
190 m_TraceParam = new TraceParam();
191 m_TraceParam.Flags = TraceFlags.ENTS | TraceFlags.WORLD | TraceFlags.ANY_CONTACT;
192 m_TraceParam.LayerMask = EPhysicsLayerDefs.Projectile;
193 }
194
195 array<IEntity> excludeArray = {};
196 excludeArray.Insert(controlledEntity);
197
198 ChimeraCharacter playerCharacter = ChimeraCharacter.Cast(controlledEntity);
199 if (playerCharacter && playerCharacter.IsInVehicle())
200 {
201 CompartmentAccessComponent compartmentComp = playerCharacter.GetCompartmentAccessComponent();
202 if (compartmentComp)
203 {
204 IEntity vehicleIn = compartmentComp.GetVehicleIn(playerCharacter);
205 if (vehicleIn)
206 excludeArray.Insert(vehicleIn);
207 }
208 }
209
210 m_TraceParam.Start = mat[3];
211 m_TraceParam.End = end;
212 m_TraceParam.ExcludeArray = excludeArray;
213 m_TraceParam.TraceEnt = null;
214
215 float traceResult = GetGame().GetWorld().TraceMove(m_TraceParam, null);
216
217 if (m_TraceParam.TraceEnt || traceResult == 1)
218 m_vCommandPosition = m_TraceParam.Start + (end - mat[3]) * (m_TraceParam.End - m_TraceParam.Start).Length() * traceResult;
219
220 m_fDistance = traceResult * (m_TraceParam.End - m_TraceParam.Start).Length();
221 }
222
223 //------------------------------------------------------------------------------------------------
227 protected bool IsInLineOfSight(vector point, vector transform[4])
228 {
229 vector direction = point - transform[3];
230 direction.Normalize();
231
232 return vector.Dot(direction, transform[2]) > LINE_OF_SIGHT_THRESHOLD;
233 }
234
235 //------------------------------------------------------------------------------------------------
237 {
238 anim.GetOnCompleted().Remove(FadeOutPulse);
239
240 //Delay the animation by 1 frame, so the previous animation gets deleted first
241 GetGame().GetCallqueue().Call(FadeOutPulseDelayed);
242 }
243
244 //------------------------------------------------------------------------------------------------
246 {
247 AnimateWidget.Opacity(m_wCommandPulseWidget, 0, UIConstants.FADE_RATE_DEFAULT, true);
248 }
249
250 //------------------------------------------------------------------------------------------------
251 protected void DeleteWidget(WidgetAnimationOpacity anim = null)
252 {
253 if (anim)
254 anim.GetOnCompleted().Remove(DeleteWidget);
255
256 m_bCanUpdate = false;
257 m_HUDManager.StopDrawing(this);
258 }
259
260 //------------------------------------------------------------------------------------------------
261 protected void HideWidget(bool deleteWidget = false)
262 {
265
266 if (deleteWidget && anim)
267 anim.GetOnCompleted().Insert(DeleteWidget);
268 }
269
270 //------------------------------------------------------------------------------------------------
272 {
273 // Hide the widget after its definied show time in seconds
275 GetGame().GetCallqueue().CallLater(HideWidget, SCR_ECommandVisualizationDuration.BRIEF * 1000, param1: true);
276 }
277
278 //------------------------------------------------------------------------------------------------
285 protected bool GetWorldToScreenPosition(BaseWorld world, vector worldPosition, out float posX, out float posY, int cameraIndex = -1)
286 {
287 vector screenPosition = GetGame().GetWorkspace().ProjWorldToScreen(worldPosition, world, cameraIndex);
288 posX = screenPosition[0];
289 posY = screenPosition[1];
290
291 return false;
292 }
293
294 //------------------------------------------------------------------------------------------------
298 void VisualizeCommand(vector targetPosition, SCR_BaseGroupCommand command)
299 {
300 if (!command)
301 return;
302
303 string imageSet = command.GetIconImageset();
304 string icon = command.GetIconName();
305
306 if (imageSet == string.Empty)
307 m_wCommandIconWidget.LoadImageTexture(0, icon);
308 else
309 m_wCommandIconWidget.LoadImageFromSet(0, imageSet, icon);
310
313
314 m_vCommandPosition = targetPosition;
315
316 m_bCanUpdate = true;
317
318 m_wCommandPulsePreviewWidget.SetVisible(false);
319 m_wCommandFrameWidget.SetVisible(true);
322
324 {
325 m_wCommandPulsePreviewWidget.SetVisible(true);
326 return;
327 }
328
330 return;
331
332 float sizePulse[2] = {PULSE_WIDGET_MAX_SIZE, PULSE_WIDGET_MAX_SIZE};
333 m_wCommandPulseWidget.SetVisible(true);
335 AnimateWidget.Size(m_wCommandPulseWidget, sizePulse, UIConstants.FADE_RATE_DEFAULT * 0.5);
336 anim.GetOnCompleted().Insert(FadeOutPulse);
337 }
338
339 //------------------------------------------------------------------------------------------------
340 void SetCanUpdatePosition(bool canUpdate)
341 {
342 m_bCanUpdatePosition = canUpdate;
343 }
344
345 //------------------------------------------------------------------------------------------------
346 void SetIsPreview(bool isPreview)
347 {
348 m_bIsPreview = isPreview
349 }
350}
ArmaReforgerScripted GetGame()
Definition game.c:1398
SCR_HUDManagerComponent m_HUDManager
Definition game.c:39
vector direction
Widget m_wRoot
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
static bool StopAnimation(Widget w, typename typeName)
static WidgetAnimationFrameSize Size(Widget widget, float size[2], float speed)
static WidgetAnimationOpacity Opacity(Widget widget, float targetValue, float speed, bool toggleVisibility=false)
static void StopAllAnimations(Widget w)
Definition Math.c:22
Definition Math.c:13
SCR_ECommandVisualizationDuration GetVisualizationDuration()
override void DisplayStartDraw(IEntity owner)
void HideWidget(bool deleteWidget=false)
bool IsInLineOfSight(vector point, vector transform[4])
void DeleteWidget(WidgetAnimationOpacity anim=null)
override void DisplayUpdate(IEntity owner, float timeSlice)
override void DisplayStopDraw(IEntity owner)
void VisualizeCommand(vector targetPosition, SCR_BaseGroupCommand command)
bool GetWorldToScreenPosition(BaseWorld world, vector worldPosition, out float posX, out float posY, int cameraIndex=-1)
SCR_ECommandVisualizationDuration m_eCommandVisualizationDuration
void FadeOutPulse(WidgetAnimationOpacity anim)
CameraManagerClass GenericEntityClass CurrentCamera()
Returns the current camera.
SCR_FieldOfViewSettings Attribute
ECurveType
Definition ECurveType.c:13
Tuple param1
TraceFlags
Definition TraceFlags.c:13
CameraType
Definition CameraType.c:14