4 protected CanvasWidget m_wCanvasWidget;
6 protected vector m_vCenter;
7 protected float m_fRadius;
8 protected const float m_fLegendOffsetAsRadius = 0.2;
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;
14 protected ImageWidget m_wbackgroundImage;
16 protected ref array<ref Widget> m_aLegends;
18 protected Widget m_wSpiderNetFrame;
22 protected int m_iNumberOfPoints;
23 protected ref array<float> m_aSpPoints, m_aOldSpPoints;
25 [
Attribute(defvalue:
"0.761 0.386 0.08 0.059",
desc:
"Outline Graph Color")]
26 protected ref Color m_iPolygonColor;
28 [
Attribute(defvalue:
"0.761 0.386 0.08 1",
desc:
"Outline Graph Color")]
29 protected ref Color m_iOutlineColor;
31 [
Attribute(defvalue:
"0.761 0.571 0.347 0.059",
desc:
"Outline Graph Color for OLD stats")]
32 protected ref Color m_iOldStatsPolygonColor;
34 [
Attribute(defvalue:
"0.761 0.484 0.199 1",
desc:
"Outline Graph Color for OLD stats")]
35 protected ref Color m_iOldStatsOutlineColor;
37 [
Attribute(
"0.03",
"auto",
"Value to display when progress is 0")]
38 protected float m_fMinRepresentativeValue;
41 protected ResourceName m_LegendLayout;
44 protected override void HandlerAttached(Widget w)
46 m_wCanvasWidget = CanvasWidget.Cast(w.FindAnyWidget(
"Canvas"));
47 m_wbackgroundImage = ImageWidget.Cast(w.FindAnyWidget(
"Background"));
48 m_wSpiderNetFrame = w.FindAnyWidget(
"SpiderNetFrame");
53 m_CareerSpecializationsHandler = instance;
56 void SetSpPoints(array<float> specializations,
bool newStats =
true)
62 for (
int i = 0, count = specializations.Count(); i < count; i++)
63 m_aSpPoints.Insert(specializations[i] / 1000000);
70 for (
int i = 0, count = specializations.Count(); i < count; i++)
71 m_aOldSpPoints.Insert(specializations[i] / 1000000);
77 if (!m_aSpPoints || m_aSpPoints.IsEmpty() || !m_wbackgroundImage || !m_wCanvasWidget)
81 m_wbackgroundImage.GetScreenSize(x, y);
84 GetGame().GetCallqueue().CallLater(DrawSpiderNet,10);
93 CalculateVertices(m_aSpPoints, m_aOldSpPoints);
96 if (m_CareerSpecializationsHandler)
97 m_CareerSpecializationsHandler.UpdateSpecialization(0);
101 override bool OnUpdate(Widget w)
113 protected void CalculateVertices(array<float> points, array<float> oldPoints)
117 m_aLegendPositions = {};
118 m_iNumberOfPoints = points.Count();
120 float angle, lengthToPoint, lengthToOldPoint, lengthToLegend;
122 for (
int i=0; i<m_iNumberOfPoints;i++)
125 angle = ( ( (2 * Math.PI) / m_iNumberOfPoints) *i) + (Math.PI / 2);
128 if (points[i] < m_fMinRepresentativeValue)
129 points[i] = m_fMinRepresentativeValue;
131 if (oldPoints && oldPoints[i] < m_fMinRepresentativeValue)
132 oldPoints[i] = m_fMinRepresentativeValue;
138 lengthToOldPoint =
m_fRadius * oldPoints[i];
141 lengthToLegend = lengthToPoint +
m_fRadius * m_fLegendOffsetAsRadius;
144 m_aVertices.Insert(m_vCenter[0] + lengthToPoint * Math.Cos(angle));
145 m_aVertices.Insert(m_vCenter[1] - lengthToPoint * Math.Sin(angle));
149 m_aOldVertices.Insert(m_vCenter[0] + lengthToOldPoint * Math.Cos(angle));
150 m_aOldVertices.Insert(m_vCenter[1] - lengthToOldPoint * Math.Sin(angle));
154 m_aLegendPositions.Insert(m_vCenter[0] + lengthToLegend * Math.Cos(angle));
155 m_aLegendPositions.Insert(m_vCenter[1] - lengthToLegend * Math.Sin(angle));
161 protected void DrawVertices()
163 m_aCanvasCommands = {};
165 m_aCanvasCommands.Insert(InnerArea());
166 m_aCanvasCommands.Insert(OuterArea());
167 m_aCanvasCommands.Insert(OldOuterArea());
168 m_aCanvasCommands.Insert(OldInnerArea());
170 m_wCanvasWidget.SetDrawCommands(m_aCanvasCommands);
174 protected CanvasWidgetCommand InnerArea()
176 PolygonDrawCommand polygon =
new PolygonDrawCommand();
178 polygon.m_iColor = m_iPolygonColor.PackToInt();
179 polygon.m_Vertices = m_aVertices;
185 protected CanvasWidgetCommand OldInnerArea()
187 PolygonDrawCommand polygon =
new PolygonDrawCommand();
189 polygon.m_iColor = m_iOldStatsPolygonColor.PackToInt();
190 polygon.m_Vertices = m_aOldVertices;
196 protected CanvasWidgetCommand OuterArea()
198 LineDrawCommand surface =
new LineDrawCommand();
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;
210 protected CanvasWidgetCommand OldOuterArea()
212 LineDrawCommand surface =
new LineDrawCommand();
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;
224 protected void DrawLegends()
230 for (
int i = 0; i < m_iNumberOfPoints; i++)
234 case 0: name =
"1";
break;
235 case 1: name =
"2";
break;
236 case 2: name =
"3";
break;
237 default: name =
"Undefined ID";
break;
240 CreateLegend(m_aLegendPositions[i * 2], m_aLegendPositions[i * 2 + 1], name, i);
245 protected void CreateLegend(
float positionX,
float positionY,
string title,
int id)
247 WorkspaceWidget workspace =
GetGame().GetWorkspace();
251 Widget legendWidget = Widget.Cast(workspace.CreateWidgets(m_LegendLayout, m_wSpiderNetFrame));
255 ButtonWidget buttonWidget = ButtonWidget.Cast(legendWidget.FindAnyWidget(
"LegendButton"));
265 handler.GetOnClicked().Insert(OnButtonClick);
266 handler.GetOnMouseEnter().Insert(OnMouseEnterButton);
267 handler.GetOnMouseLeave().Insert(OnMouseLeaveButton);
268 handler.SetButtonId(
id);
269 handler.SetText(title);
271 if (m_CareerSpecializationsHandler)
272 m_CareerSpecializationsHandler.AddLegendButtonHandler(handler);
274 AdjustLegend(legendWidget, handler, positionX, positionY);
275 m_aLegends.Insert(legendWidget);
281 ImageWidget image = handler.GetCoreImageWidget();
286 image.GetScreenSize(x, y);
287 if (x == 0 && y == 0)
289 GetGame().GetCallqueue().CallLater(AdjustLegend, 10,
false, legendWidget, handler, positionX, positionY);
293 WorkspaceWidget workspace =
GetGame().GetWorkspace();
297 positionX = workspace.DPIUnscale(positionX - x/2);
298 positionY = workspace.DPIUnscale(positionY - y/2);
300 FrameSlot.SetPos(legendWidget, positionX, positionY);
312 if (!buttonHandler || !m_CareerSpecializationsHandler)
315 int newSelection = buttonHandler.GetButtonId();
316 m_CareerSpecializationsHandler.UpdateSpecialization(newSelection);
323 if (!buttonHandler || !m_CareerSpecializationsHandler)
326 int hoveredButton = buttonHandler.GetButtonId();
327 m_CareerSpecializationsHandler.UpdateHoveredSpecialization(hoveredButton,
true);
334 if (!buttonHandler || !m_CareerSpecializationsHandler)
337 int hoveredButton = buttonHandler.GetButtonId();
338 m_CareerSpecializationsHandler.UpdateHoveredSpecialization(hoveredButton,
false);