Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_WaypointDisplay.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
4class SCR_WaypointDisplay : SCR_InfoDisplayExtended
5{
6 //TODO: ATTRIBUTE
7 protected static string DISTANCE_STRING_UNIT = "#AR-Tutorial_WaypointUnits_meters";
8 protected static float WAYPOINT_FADE_THRESHOLD = 20;
9 protected static float WAYPOINT_MINIMUM_OPACITY = 0.2;
10 protected static float WAYPOINT_DISTANCE_INDICATOR_FADE_START = 100;
11 protected static float WAYPOINT_DISTANCE_INDICATOR_FADE_END = 50;
12 protected static float WAYPOINT_FADE_IN_DISTANCE = 3;
13
14 //TODO: ATTRIBUTE
15 protected ResourceName m_sWaypointLayout = "{825C6D728AC3E02A}UI/layouts/Waypoint/Waypoint.layout";
16 protected ref array<ref SCR_Waypoint> m_aWaypoints;
17
18 //------------------------------------------------------------------------------------------------
20 {
21 if (!m_aWaypoints)
22 return null;
23
24 IEntity attachedEntity;
25 foreach(SCR_Waypoint waypoint : m_aWaypoints)
26 {
27 attachedEntity = waypoint.GetAttachedEntity();
28 if (!attachedEntity || (attachedEntity != entity))
29 continue;
30
31 return waypoint;
32 }
33
34 return null;
35 }
36
37 //------------------------------------------------------------------------------------------------
38 void GetWaypoints(out array<ref SCR_Waypoint> waypoints)
39 {
40 waypoints = m_aWaypoints;
41 }
42
43 //------------------------------------------------------------------------------------------------
45 {
46 if (m_aWaypoints)
47 m_aWaypoints.RemoveItem(waypoint);
48 }
49
50 //------------------------------------------------------------------------------------------------
52 {
54 if (!waypoint)
55 return null;
56
58
59 if (!m_aWaypoints)
60 m_aWaypoints = {};
61
62 m_aWaypoints.Insert(waypoint);
63
64 return waypoint;
65 }
66
67 //------------------------------------------------------------------------------------------------
69 {
71 if (!waypoint)
72 return null;
73
74 waypoint.AttachToEntity(entity);
75
76 if (!m_aWaypoints)
77 m_aWaypoints = {};
78
79 m_aWaypoints.Insert(waypoint);
80
81 return waypoint;
82 }
83
84 //------------------------------------------------------------------------------------------------
85 protected bool HandleWidgetOpacities(notnull SCR_Waypoint waypoint, notnull IEntity player)
86 {
87 float distance = vector.Distance(player.GetOrigin(), waypoint.GetPosition());
88
89 if ((waypoint.m_iMinimumDrawDistance > distance) || ((waypoint.m_iMaximumDrawDistance != -1) && (waypoint.m_iMaximumDrawDistance < distance)))
90 {
91 waypoint.SetVisible(false);
92 return false;
93 }
94 else
95 {
96 waypoint.SetVisible(true);
97 }
98
99 RichTextWidget distanceWidget = waypoint.m_wDistance;
100 int shownDistance;
101 float distanceOpacity;
102
103 if (distanceWidget)
104 {
105 // Rounding
106 int roundedDistance = Math.Round(distance);
107
108 if (distance > 1000)
109 shownDistance = roundedDistance - (roundedDistance % 1000);
110 else if (distance > 100)
111 shownDistance = Math.Round(distance / 100) * 100;
112 else if (distance > 50)
113 shownDistance = roundedDistance - (roundedDistance % 50);
114
115 distanceWidget.SetTextFormat(DISTANCE_STRING_UNIT, shownDistance);
116
117 //Distance opacity
119 distanceOpacity = 1;
121 distanceOpacity = 0;
122 else
124
125 distanceWidget.SetOpacity(distanceOpacity);
126 }
127
128 Widget iconWidget = waypoint.m_wIcon;
129 float iconsOpacity;
130
131 if (iconWidget)
132 {
133 //Icon Opacity
134 if (waypoint.FadingEnabled())
135 {
136 if (waypoint.m_iMaximumDrawDistance != -1 && distance > (waypoint.m_iMaximumDrawDistance - WAYPOINT_FADE_IN_DISTANCE)) // Player is reaching the max drawing distance
137 iconsOpacity = Math.Lerp(0, 1, (waypoint.m_iMaximumDrawDistance - distance) / WAYPOINT_FADE_IN_DISTANCE);
138 else if (waypoint.m_iMinimumDrawDistance != 0 && distance < (waypoint.m_iMinimumDrawDistance + WAYPOINT_FADE_IN_DISTANCE)) // Player is reaching the min drawing distance
139 iconsOpacity = Math.Lerp(1, 0, (distance - waypoint.m_iMinimumDrawDistance) / WAYPOINT_FADE_IN_DISTANCE);
140 else if (distance < WAYPOINT_FADE_THRESHOLD) // Player is within fade distance
142 else
143 iconsOpacity = 1;
144 }
145 else
146 {
147 iconsOpacity = 1;
148 }
149
150 if (iconWidget)
151 iconWidget.SetOpacity(iconsOpacity);
152
153 if (distanceWidget && distanceOpacity > iconsOpacity)
154 distanceWidget.SetOpacity(iconsOpacity);
155 }
156
157 RichTextWidget titleWidget = waypoint.m_wTitle;
158
159 if (titleWidget)
160 titleWidget.SetOpacity(iconsOpacity);
161
162 return true;
163 }
164
165 //------------------------------------------------------------------------------------------------
166 // Overrides
167 //------------------------------------------------------------------------------------------------
168 override void DisplayUpdate(IEntity owner, float timeSlice)
169 {
170 if (!m_wRoot || !m_aWaypoints || m_aWaypoints.IsEmpty())
171 return;
172
173 IEntity player = m_PlayerController.GetControlledEntity();
174 if (!player)
175 return;
176
177 WorkspaceWidget workspace = m_wRoot.GetWorkspace();
178 if (!workspace)
179 return;
180
181 int screenHeight = workspace.GetHeight();
182 int screenWidth = workspace.GetWidth();
183 int widgetPosX, widgetPosY;
184
185 BaseWorld world = GetGame().GetWorld();
186 vector position2D;
187
188 foreach (SCR_Waypoint waypoint : m_aWaypoints)
189 {
190 //Don't update waypoints, that are not enabled
191 if (!waypoint.IsEnabled())
192 continue;
193
194 if (!HandleWidgetOpacities(waypoint, player))
195 continue;
196
197 //positioning widget
198 position2D = workspace.ProjWorldToScreen(waypoint.GetPosition(), world);
199 widgetPosX = workspace.DPIScale(position2D[0]);
200 widgetPosY = workspace.DPIScale(position2D[1]);
201
202 if (widgetPosX < 0)
203 position2D[0] = 0;
204 else if (widgetPosX > screenWidth)
205 position2D[0] = workspace.DPIUnscale(screenWidth);
206
207 if (widgetPosY < 0)
208 position2D[1] = 0;
209 else if (widgetPosY > screenHeight || position2D[2] < 0)
210 position2D[1] = workspace.DPIUnscale(screenHeight);
211
212 FrameSlot.SetPos(waypoint.GetWidget(), position2D[0], position2D[1]);
213 }
214 }
215}
ArmaReforgerScripted GetGame()
Definition game.c:1398
float distance
vector position
SCR_FastTravelComponentClass m_PlayerController
Widget m_wRoot
Definition Math.c:13
void DeleteWaypoint(SCR_Waypoint waypoint)
bool HandleWidgetOpacities(notnull SCR_Waypoint waypoint, notnull IEntity player)
static float WAYPOINT_FADE_IN_DISTANCE
override void DisplayUpdate(IEntity owner, float timeSlice)
static float WAYPOINT_DISTANCE_INDICATOR_FADE_START
ref array< ref SCR_Waypoint > m_aWaypoints
SCR_Waypoint FindWaypointByEntity(IEntity entity)
static float WAYPOINT_FADE_THRESHOLD
SCR_Waypoint CreateWaypoint(vector position)
static float WAYPOINT_MINIMUM_OPACITY
void GetWaypoints(out array< ref SCR_Waypoint > waypoints)
SCR_Waypoint CreateWaypoint(IEntity entity)
static float WAYPOINT_DISTANCE_INDICATOR_FADE_END
static string DISTANCE_STRING_UNIT
void SetPositionStatic(vector pos)
Set only static position, not attached to entity.
void AttachToEntity(IEntity entity)
Attach waypoint to entity, copying its position.