Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_CaptureAndHoldObjectiveDisplayObject.c
Go to the documentation of this file.
1
3{
5 protected Widget m_wRoot;
10
19
21
23 protected float m_fBlendScreenPosition;
25 protected const float COLOR_BLEND_SPEED = 5.5;
27 protected const float POSITION_BLEND_SPEED = 2.5;
28
29 // Initial values
30 protected float m_fOriginalXSize;
31 protected float m_fOriginalYSize;
32 protected float m_fOriginalTitleSize;
33 protected float m_fOriginalTextSize;
34
35 // Loaded texture indices
36 protected const int ATLAS_INDEX_NEUTRAL = 0;
37 protected const int ATLAS_INDEX_BLUFOR = 1;
38 protected const int ATLAS_INDEX_OPFOR = 2;
39
40
43
44 //------------------------------------------------------------------------------------------------
50
51 //------------------------------------------------------------------------------------------------
54 {
55 return m_wRoot;
56 }
57
58 //------------------------------------------------------------------------------------------------
61 {
62 m_wRoot = root;
63 m_AffiliatedArea = area;
64 m_wNameText = TextWidget.Cast(m_wRoot.FindAnyWidget("Name"));
66
67 m_wDistanceText = TextWidget.Cast(m_wRoot.FindAnyWidget("Distance"));
68 m_wIcon = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_Faction"));
69 m_wBackdropIcon = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_Backdrop"));
70
71 m_wUnderAttackIcon = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_UnderAttack"));
72 m_wLayout = VerticalLayoutWidget.Cast(m_wRoot.FindAnyWidget("VerticalLayout"));
75
76 m_wMajorIcon = ImageWidget.Cast(m_wRoot.FindAnyWidget("Icon_MajorMark"));
77
79 }
80
81 //------------------------------------------------------------------------------------------------
83 protected void UpdateImageState(Widget root, float timeSlice)
84 {
85 Faction owningFaction = m_AffiliatedArea.GetOwningFaction();
86
87 Color targetColor;
88 if (!owningFaction)
89 targetColor = Color.FromRGBA(249, 210, 103, 255);
90 else
91 targetColor = owningFaction.GetFactionColor();
92
93 int rootColor = m_wRoot.GetColor().PackToInt();
94 Color currentColor = Color.FromInt(rootColor);
95 if (currentColor != targetColor)
96 currentColor.Lerp(targetColor, timeSlice * COLOR_BLEND_SPEED);
97
98 // Only show major symbol when area is marked as one
99 m_wMajorIcon.SetVisible(m_AffiliatedArea.IsMajor());
100
101 // Imageset for Base state icon
102 const string AtlasImageset = "{225B7CAD5CEC4AE3}UI/Imagesets/CaptureAndHold/CaptureAndHoldAtlas.imageset";
103
104 // Area is completely neutral
105 if (!owningFaction)
106 {
107 m_wIcon.LoadImageFromSet(0,AtlasImageset, "CAH_NEUTRAL_LARGE");
108 m_wBackdropIcon.LoadImageFromSet(0,AtlasImageset, "CAH_NEUTRAL_BACKDROP");
109
110 m_wRoot.SetColor(currentColor);
111 // With no owning faction, there is no contesting faction
112 m_wUnderAttackIcon.SetVisible(false);
113 return;
114 }
115
116 // TODO: Improvement desirable
117 // This is far from ideal and is not sandbox enough.
118 FactionKey factionKey = owningFaction.GetFactionKey();
119 if (factionKey == "US" || factionKey == "FIA")
120 {
121 m_wIcon.LoadImageFromSet(0,AtlasImageset, "CAH_BLUFOR_LARGE");
122 m_wBackdropIcon.LoadImageFromSet(0,AtlasImageset, "CAH_BLUFOR_BACKDROP");
123
124 m_wUnderAttackIcon.SetRotation(0);
125 }
126 else if (factionKey == "USSR")
127 {
128 m_wIcon.LoadImageFromSet(0,AtlasImageset, "CAH_OPFOR_LARGE");
129 m_wBackdropIcon.LoadImageFromSet(0,AtlasImageset, "CAH_OPFOR_BACKDROP");
130
131 m_wUnderAttackIcon.SetRotation(45);
132 }
133
134 m_wRoot.SetColor(currentColor);
135
136 Faction contestingFaction = m_AffiliatedArea.GetContestingFaction();
137 if (contestingFaction)
138 {
139 m_wUnderAttackIcon.SetVisible(true);
140 // Pulsing animation
141 //Color col = new Color(1.0, 1.0, 1.0, 1.0);
142 Color col = Color.FromRGBA(249, 210, 103, 255);
143 float val01 = Math.Sin( m_AffiliatedArea.GetWorld().GetWorldTime() * 0.01 ) * 0.5 + 0.5;
144 col.Lerp(contestingFaction.GetFactionColor(), val01);
145 m_wUnderAttackIcon.SetColor(col);
146
147 //Color selfCol = new Color(1.0, 1.0, 1.0, 1.0);
148 Color selfCol = Color.FromRGBA(249, 210, 103, 255);
149 selfCol.Lerp(owningFaction.GetFactionColor(), val01);
150 m_wRoot.SetColor(selfCol);
151 }
152 else
153 {
154 m_wUnderAttackIcon.SetVisible(false);
155 }
156 }
157
158 //------------------------------------------------------------------------------------------------
160 void UpdateStatic(float timeSlice)
161 {
162 m_wDistanceText.SetVisible(false);
163 UpdateImageState(m_wRoot, timeSlice);
164 // Set objective symbol
165 m_wNameText.SetText(m_AffiliatedArea.GetAreaSymbol());
166 }
167
168 //------------------------------------------------------------------------------------------------
170 void UpdateDynamic(IEntity playerEntity, float timeSlice)
171 {
172 vector objectiveWorldPosition = m_AffiliatedArea.GetWorldObjectiveCenter();
173 vector projectedScreenPosition = m_wRoot.GetWorkspace().ProjWorldToScreen(objectiveWorldPosition, m_AffiliatedArea.GetWorld());
174
175 vector cameraMatrix[4];
176 m_AffiliatedArea.GetWorld().GetCurrentCamera(cameraMatrix);
177
178 float alpha = 1.0;
179 bool visible = true;
180
181 // This case should rarely happen as we do not expect spawn protection area
182 // to overlay a capture area, but regardless..
183 bool isPopupDrawn;
185 if (popupNotifications && popupNotifications.GetCurrentMsg())
186 isPopupDrawn = true;
187
188 // Center to screen and stay fixed
189 if (playerEntity && m_AffiliatedArea.IsCharacterInside(SCR_ChimeraCharacter.Cast(playerEntity)) && !isPopupDrawn)
190 {
191 // Update screen space blend
193 visible = true; // Always draw inside
194 }
195 else
196 {
197 // Worldprojection
198 vector dirToCamera = (objectiveWorldPosition - cameraMatrix[3]).Normalized();
199 float dot = vector.Dot(dirToCamera, cameraMatrix[2]);
200 if (dot < 0.6666 && m_fBlendScreenPosition <= 0) // Force animation
201 visible = false;
202
203 float alphaScale = Math.InverseLerp(0.667, 1.0, dot);
204 alphaScale = Math.Clamp(alphaScale, 0.0, 1.0);
205
206 if (m_fBlendScreenPosition <= 0.0)
207 alpha = Math.Lerp(0.5, 1.0, alphaScale);
208 else
209 alpha = 1.0;
210
211 // Blend the point out significantly in optics, because the projection is misaligned
212 if (ArmaReforgerScripted.IsScreenPointInPIPSights(projectedScreenPosition, ArmaReforgerScripted.GetCurrentPIPSights()))
213 alpha = Math.Min(alpha, 0.65);
214
216 }
217
218 // Clamp the blend so we don't overshoot
220
221 // If not visible, do not draw and that's it
222 if (!visible)
223 {
224 m_wRoot.SetVisible(false);
225 return;
226 }
227
228 // Otherwise update widget
229 m_wDistanceText.SetVisible(true);
230
231 // Distance text
232 float distance = vector.Distance(cameraMatrix[3], objectiveWorldPosition);
233 distance = Math.Round(distance);
234 m_wDistanceText.SetTextFormat("#AR-CAH-Objective_Distance", distance);
235
236 // Update image state
237 UpdateImageState(m_wRoot, timeSlice);
238
239 // Opacity
240 m_wRoot.SetOpacity(alpha);
241
242 float x, y;
243 float scale = 1.0;
244 float textScale = 1.0;
245 // Interpolate position
246 if (m_fBlendScreenPosition > 0.0)
247 {
248 WorkspaceWidget ww = m_wRoot.GetWorkspace();
249 int w = ww.GetWidth();
250 int h = ww.GetHeight();
251 float fixedX = ww.DPIUnscale(0.5 * w);
252 float fixedY = ww.DPIUnscale(0.15 * h);
253
254 SCR_EditorManagerEntity editorManager = SCR_EditorManagerEntity.GetInstance();
255 if (editorManager && editorManager.IsOpened())
256 fixedY += 40;
257
258 x = Math.Lerp(projectedScreenPosition[0], fixedX, m_fBlendScreenPosition);
259 y = Math.Lerp(projectedScreenPosition[1], fixedY, m_fBlendScreenPosition);
261 textScale = m_fBlendScreenPosition * 1.85;
262 }
263 else
264 {
265 x = projectedScreenPosition[0];
266 y = projectedScreenPosition[1];
267 }
268
269 float xScale = m_fOriginalXSize * scale;
270 float yScale = m_fOriginalYSize * scale;
271 // Apply
272 FrameSlot.SetPos(m_wRoot, x - 0.5 * xScale, y - 0.5 * yScale);
273
274 // Scale
275 FrameSlot.SetSize(m_wLayout, xScale, yScale);
276
277 m_wNameText.SetExactFontSize(m_fOriginalTitleSize * textScale);
278 m_wDistanceText.SetExactFontSize(m_fOriginalTextSize * textScale);
279
280 // Set objective symbol
281 m_wNameText.SetText(m_AffiliatedArea.GetAreaSymbol());
282
283 // And make widget visible
284 m_wRoot.SetVisible(true);
285 }
286}
vector scale
float distance
void SCR_EditorManagerEntity(IEntitySource src, IEntity parent)
Definition Color.c:13
Definition Math.c:13
void UpdateImageState(Widget root, float timeSlice)
Update image state according to provided area state.
void UpdateStatic(float timeSlice)
Update this widget as static UI element, ie. not reprojecting it automatically.
ImageWidget m_wUnderAttackIcon
The objective is under attack symbol image.
TextWidget m_wNameText
Text that displays name or symbol of the objective.
SCR_CaptureAndHoldArea GetArea()
Returns the area this element represents.
float m_fBlendScreenPosition
Blend progress of when within the area.
ImageWidget m_wBackdropIcon
The backdrop image of this element.
ImageWidget m_wMajorIcon
The major objective symbol image.
SCR_CaptureAndHoldArea m_AffiliatedArea
The area this object represents.
Widget GetRootWidget()
Returns root widget of this element.
TextWidget m_wDistanceText
Text that displays objective distance.
void SCR_CaptureAndHoldObjectiveDisplayObject(notnull Widget root, notnull SCR_CaptureAndHoldArea area)
Create new wrapper for objective display.
void UpdateDynamic(IEntity playerEntity, float timeSlice)
Update this widget as dynamic UI element projected to screen space.
Takes care of dynamic and static onscreen popups.
static SCR_PopUpNotification GetInstance()
SCR_PopupMessage GetCurrentMsg()