Arma Reforger Explorer 1.7.0.54
Arma Reforger Code Explorer by Zeroy - Thanks to MisterOutofTime
Loading...
Searching...
No Matches
SCR_SpiderNet.c
Go to the documentation of this file.
1//------------------------------------------------------------------------------------------------
3{
5
6 protected vector m_vCenter;
7 protected float m_fRadius;
8 protected const float m_fLegendOffsetAsRadius = 0.2;
9
10 protected ref array<ref CanvasWidgetCommand> m_aCanvasCommands;
11 protected ref array<float> m_aVertices;
12 protected ref array<float> m_aOldVertices;
13 protected ref array<float> m_aLegendPositions;
15
16 protected ref array<ref Widget> m_aLegends;
17
19
21
22 protected int m_iNumberOfPoints;
23 protected ref array<float> m_aSpPoints, m_aOldSpPoints;
24
25 [Attribute(defvalue: "0.761 0.386 0.08 0.059", desc: "Outline Graph Color")]
26 protected ref Color m_iPolygonColor;
27
28 [Attribute(defvalue: "0.761 0.386 0.08 1", desc: "Outline Graph Color")]
29 protected ref Color m_iOutlineColor;
30
31 [Attribute(defvalue: "0.761 0.571 0.347 0.059", desc: "Outline Graph Color for OLD stats")]
33
34 [Attribute(defvalue: "0.761 0.484 0.199 1", desc: "Outline Graph Color for OLD stats")]
36
37 [Attribute("0.03", "auto", "Value to display when progress is 0")]
39
40 [Attribute(params: "Legend layout")]
42
43 //------------------------------------------------------------------------------------------------
44 protected override void HandlerAttached(Widget w)
45 {
46 m_wCanvasWidget = CanvasWidget.Cast(w.FindAnyWidget("Canvas"));
47 m_wbackgroundImage = ImageWidget.Cast(w.FindAnyWidget("Background"));
48 m_wSpiderNetFrame = w.FindAnyWidget("SpiderNetFrame");
49 }
50
55
56 void SetSpPoints(array<float> specializations, bool newStats = true)
57 {
58 if (newStats)
59 {
60 m_aSpPoints = {};
61
62 for (int i = 0, count = specializations.Count(); i < count; i++)
63 m_aSpPoints.Insert(specializations[i] / 1000000);
64
65 return;
66 }
67
68 m_aOldSpPoints = {};
69
70 for (int i = 0, count = specializations.Count(); i < count; i++)
71 m_aOldSpPoints.Insert(specializations[i] / 1000000);
72 }
73
74 //------------------------------------------------------------------------------------------------
76 {
78 return;
79
80 float x, y;
81 m_wbackgroundImage.GetScreenSize(x, y);
82 if (x <= 0 && y <= 0) //If the layout and widgets have not been initialized yet, do nothing
83 {
84 GetGame().GetCallqueue().CallLater(DrawSpiderNet,10);
85 return;
86 }
87
88 m_fRadius = x/2;
89 m_vCenter = {};
90 m_vCenter[0] = x/2; //center: x
91 m_vCenter[1] = y/2; //center: y
92
97 m_CareerSpecializationsHandler.UpdateSpecialization(0);
98 }
99
100 //------------------------------------------------------------------------------------------------
101 override bool OnUpdate(Widget w)
102 {
103 return true;
104 }
105
106 //------------------------------------------------------------------------------------------------
113 protected void CalculateVertices(array<float> points, array<float> oldPoints)
114 {
115 m_aVertices = {};
116 m_aOldVertices = {};
118 m_iNumberOfPoints = points.Count();
119
120 float angle, lengthToPoint, lengthToOldPoint, lengthToLegend;
121
122 for (int i=0; i<m_iNumberOfPoints;i++)
123 {
124 //Distribute the 2*PI angles equidistantly for all specializations
125 angle = ( ( (2 * Math.PI) / m_iNumberOfPoints) *i) + (Math.PI / 2);
126
127 //m_iMinRepresentativeValue of offset so 0 doesn't look like nothing at all
128 if (points[i] < m_fMinRepresentativeValue)
129 points[i] = m_fMinRepresentativeValue;
130
131 if (oldPoints && oldPoints[i] < m_fMinRepresentativeValue)
132 oldPoints[i] = m_fMinRepresentativeValue;
133
134 //Length of the line = % of points on this Specialization.
135 lengthToPoint = m_fRadius * points[i];
136
137 if (oldPoints)
138 lengthToOldPoint = m_fRadius * oldPoints[i];
139
140 //Distance to Legend from Center
141 lengthToLegend = lengthToPoint + m_fRadius * m_fLegendOffsetAsRadius;
142
143 //Vertices so we know where to draw.
144 m_aVertices.Insert(m_vCenter[0] + lengthToPoint * Math.Cos(angle)); //x
145 m_aVertices.Insert(m_vCenter[1] - lengthToPoint * Math.Sin(angle)); //y
146
147 if (oldPoints)
148 {
149 m_aOldVertices.Insert(m_vCenter[0] + lengthToOldPoint * Math.Cos(angle)); //x
150 m_aOldVertices.Insert(m_vCenter[1] - lengthToOldPoint * Math.Sin(angle)); //y
151 }
152
153 //Legend position so we know where to put the legend
154 m_aLegendPositions.Insert(m_vCenter[0] + lengthToLegend * Math.Cos(angle)); //x
155 m_aLegendPositions.Insert(m_vCenter[1] - lengthToLegend * Math.Sin(angle)); //y
156 }
157 }
158
159 //------------------------------------------------------------------------------------------------
161 protected void DrawVertices()
162 {
164
169
170 m_wCanvasWidget.SetDrawCommands(m_aCanvasCommands);
171 }
172
173 //------------------------------------------------------------------------------------------------
174 protected CanvasWidgetCommand InnerArea()
175 {
176 PolygonDrawCommand polygon = new PolygonDrawCommand();
177
178 polygon.m_iColor = m_iPolygonColor.PackToInt();
179 polygon.m_Vertices = m_aVertices;
180
181 return polygon;
182 }
183
184 //------------------------------------------------------------------------------------------------
185 protected CanvasWidgetCommand OldInnerArea()
186 {
187 PolygonDrawCommand polygon = new PolygonDrawCommand();
188
189 polygon.m_iColor = m_iOldStatsPolygonColor.PackToInt();
190 polygon.m_Vertices = m_aOldVertices;
191
192 return polygon;
193 }
194
195 //------------------------------------------------------------------------------------------------
196 protected CanvasWidgetCommand OuterArea()
197 {
198 LineDrawCommand surface = new LineDrawCommand();
199
200 surface.m_Vertices = m_aVertices;
201 surface.m_fWidth = 4;
202 surface.m_fOutlineWidth = 6;
203 surface.m_iOutlineColor = m_iOutlineColor.PackToInt();
204 surface.m_bShouldEnclose = true;
205
206 return surface;
207 }
208
209 //------------------------------------------------------------------------------------------------
210 protected CanvasWidgetCommand OldOuterArea()
211 {
212 LineDrawCommand surface = new LineDrawCommand();
213
214 surface.m_Vertices = m_aOldVertices;
215 surface.m_fWidth = 4;
216 surface.m_fOutlineWidth = 6;
217 surface.m_iOutlineColor = m_iOldStatsOutlineColor.PackToInt();
218 surface.m_bShouldEnclose = true;
219
220 return surface;
221 }
222
223 //------------------------------------------------------------------------------------------------
224 protected void DrawLegends()
225 {
226 m_aLegends = {};
227
228 string name;
229
230 for (int i = 0; i < m_iNumberOfPoints; i++)
231 {
232 switch (i)
233 {
234 case 0: name = "1"; break;
235 case 1: name = "2"; break;
236 case 2: name = "3"; break;
237 default: name = "Undefined ID"; break;
238 }
239
240 CreateLegend(m_aLegendPositions[i * 2], m_aLegendPositions[i * 2 + 1], name, i);
241 }
242 }
243
244 //------------------------------------------------------------------------------------------------
245 protected void CreateLegend(float positionX, float positionY, string title, int id)
246 {
247 WorkspaceWidget workspace = GetGame().GetWorkspace();
248 if (!workspace)
249 return;
250
251 Widget legendWidget = workspace.CreateWidgets(m_LegendLayout, m_wSpiderNetFrame);
252 if (!legendWidget)
253 return;
254
255 ButtonWidget buttonWidget = ButtonWidget.Cast(legendWidget.FindAnyWidget("LegendButton"));
256 if (!buttonWidget)
257 return;
258
259 SCR_ButtonLegendComponent handler = SCR_ButtonLegendComponent.Cast(buttonWidget.FindHandler(SCR_ButtonLegendComponent));
260 if (!handler)
261 return;
262
263 handler.Hide();
264
265 handler.GetOnClicked().Insert(OnButtonClick);
266 handler.GetOnMouseEnter().Insert(OnMouseEnterButton);
267 handler.GetOnMouseLeave().Insert(OnMouseLeaveButton);
268 handler.SetButtonId(id);
269 handler.SetText(title);
270
272 m_CareerSpecializationsHandler.AddLegendButtonHandler(handler);
273
274 AdjustLegend(legendWidget, handler, positionX, positionY);
275 m_aLegends.Insert(legendWidget);
276 }
277
278 //------------------------------------------------------------------------------------------------
279 protected void AdjustLegend(Widget legendWidget, SCR_ButtonLegendComponent handler, float positionX, float positionY)
280 {
281 ImageWidget image = handler.GetCoreImageWidget();
282 if (!image)
283 return;
284
285 float x, y;
286 image.GetScreenSize(x, y);
287 if (x == 0 && y == 0)
288 {
289 GetGame().GetCallqueue().CallLater(AdjustLegend, 10, false, legendWidget, handler, positionX, positionY);
290 return;
291 }
292
293 WorkspaceWidget workspace = GetGame().GetWorkspace();
294 if (!workspace)
295 return;
296
297 positionX = workspace.DPIUnscale(positionX - x/2);
298 positionY = workspace.DPIUnscale(positionY - y/2);
299
300 FrameSlot.SetPos(legendWidget, positionX, positionY);
301
302 handler.Unhide();
303
304 //if (handler.GetButtonId() == 0)
305 // handler.SetFocus();
306 }
307
308 //When a legend is selected, deselect other legends
309 //------------------------------------------------------------------------------------------------
311 {
312 if (!buttonHandler || !m_CareerSpecializationsHandler)
313 return;
314
315 int newSelection = buttonHandler.GetButtonId();
316 m_CareerSpecializationsHandler.UpdateSpecialization(newSelection);
317 }
318
319 //When a legend is on hover
320 //------------------------------------------------------------------------------------------------
322 {
323 if (!buttonHandler || !m_CareerSpecializationsHandler)
324 return;
325
326 int hoveredButton = buttonHandler.GetButtonId();
327 m_CareerSpecializationsHandler.UpdateHoveredSpecialization(hoveredButton, true);
328 }
329
330 //When a legend is not hover anymore
331 //------------------------------------------------------------------------------------------------
333 {
334 if (!buttonHandler || !m_CareerSpecializationsHandler)
335 return;
336
337 int hoveredButton = buttonHandler.GetButtonId();
338 m_CareerSpecializationsHandler.UpdateHoveredSpecialization(hoveredButton, false);
339 }
340
341 /*
342 //------------------------------------------------------------------------------------------------
343 protected void CreateLegend(float positionX, float positionY, float horizontalAlignment, float verticalAlignment, string title, int id)
344 {
345 WorkspaceWidget workspace = GetGame().GetWorkspace();
346 if (!workspace)
347 return;
348
349 Widget legendWidget = Widget.Cast(workspace.CreateWidgets(m_LegendLayout, m_wSpiderNetFrame));
350 if (!legendWidget)
351 return;
352
353 ButtonWidget buttonWidget = ButtonWidget.Cast(legendWidget.FindAnyWidget("LegendButton"));
354 if (!buttonWidget)
355 return;
356
357 SCR_ButtonLegendComponent handler = SCR_ButtonLegendComponent.Cast(buttonWidget.FindHandler(SCR_ButtonLegendComponent));
358 if (!handler)
359 return;
360
361 handler.GetOnClicked().Insert(OnButtonClick);
362 handler.SetButtonId(id);
363 handler.SetText(title);
364
365 if (m_CareerSpecializationsHandler)
366 m_CareerSpecializationsHandler.AddLegendButtonHandler(handler);
367
368 positionX = m_workspace.DPIUnscale(positionX);
369 positionY = m_workspace.DPIUnscale(positionY);
370
371 FrameSlot.SetPos(legendWidget, positionX, positionY);
372
373 TextWidget wText = handler.GetTextWidget();
374 ImageWidget wImage = handler.GetImageWidget();
375
376 if ((wText && wImage))
377 {
378 FrameSlot.SetAlignment(legendWidget, horizontalAlignment, verticalAlignment);
379 if (horizontalAlignment < 0.6)
380 {
381 //Image left, Text right
382 AlignableSlot.SetHorizontalAlign(wImage, LayoutHorizontalAlign.Left);
383 wText.SetFlags(WidgetFlags.RALIGN);
384 }
385 else
386 {
387 //Image right, Text left which's set as default on editor rn
388 AlignableSlot.SetHorizontalAlign(wImage, LayoutHorizontalAlign.Right);
389 }
390 }
391
392 m_aLegends.Insert(legendWidget);
393 }
394 */
395};
ArmaReforgerScripted GetGame()
Definition game.c:1398
UI Textures DeployMenu Briefing conflict_HintBanner_1_UI desc
Definition Color.c:13
Definition Math.c:13
CanvasWidgetCommand OldInnerArea()
void OnButtonClick(SCR_ButtonLegendComponent buttonHandler)
void CalculateVertices(array< float > points, array< float > oldPoints)
void AdjustLegend(Widget legendWidget, SCR_ButtonLegendComponent handler, float positionX, float positionY)
ref Color m_iPolygonColor
ref array< float > m_aSpPoints
override bool OnUpdate(Widget w)
CanvasWidget m_wCanvasWidget
ImageWidget m_wbackgroundImage
ref array< float > m_aLegendPositions
void RegisterCareerProfileHandler(SCR_CareerSpecializationsUI instance)
ResourceName m_LegendLayout
void DrawSpiderNet()
Widget m_wSpiderNetFrame
ref array< float > m_aOldSpPoints
ref Color m_iOldStatsOutlineColor
CanvasWidgetCommand OuterArea()
CanvasWidgetCommand InnerArea()
float m_fMinRepresentativeValue
void OnMouseLeaveButton(SCR_ButtonLegendComponent buttonHandler)
ref Color m_iOutlineColor
override void HandlerAttached(Widget w)
CanvasWidgetCommand OldOuterArea()
ref array< ref CanvasWidgetCommand > m_aCanvasCommands
ref Color m_iOldStatsPolygonColor
ref array< float > m_aOldVertices
ref array< ref Widget > m_aLegends
ref array< float > m_aVertices
void SetSpPoints(array< float > specializations, bool newStats=true)
SCR_CareerSpecializationsUI m_CareerSpecializationsHandler
const float m_fLegendOffsetAsRadius
void OnMouseEnterButton(SCR_ButtonLegendComponent buttonHandler)
void CreateLegend(float positionX, float positionY, string title, int id)
void DrawVertices()
Create inner polygon.
SCR_FieldOfViewSettings Attribute