forked from Maxouwell/CS_EmploymentDetailsExtender
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathUIChartPanel.cs
More file actions
112 lines (89 loc) · 3.66 KB
/
UIChartPanel.cs
File metadata and controls
112 lines (89 loc) · 3.66 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
using ColossalFramework.UI;
using System;
using System.Collections.Generic;
using UnityEngine;
namespace DemographicsMod
{
class UIChartPanel : UIPanel
{
private UIRadialChart[] m_RadialChart = new UIRadialChart[4];
private UIGraph m_graph;
private static readonly Vector2 chartSize = new Vector2(64, 64);
private static readonly int chartPadding = 5;
private static readonly int chartSeparator = 10;
private static readonly float[] _chartLine = new float[]
{
1,4,3,8,6,12,14,21,18,13,29
};
public string RadialChartPrefix { get; set; }
public static readonly Vector2 panelSize = new Vector2(chartPadding * 2 + chartSeparator + chartSize.x * 2, chartPadding * 2 + chartSeparator + chartSize.y * 2);
public override void Start()
{
base.Start();
//backgroundSprite = "InfoviewPanel"; //White Bakground
isVisible = true;
canFocus = true;
isInteractive = true;
width = panelSize.x;
height = panelSize.y;
for (int i = 0; i < m_RadialChart.Length; i++)
{
m_RadialChart[i] = CreateRadialChart(i);
}
//CreateGraph();
}
private void CreateGraph()
{
m_graph = AddUIComponent<UIGraph>();
m_graph.enabled = true;
m_graph.isVisible = true;
m_graph.name = "EmploymentGraph";
m_graph.size = new Vector2(250, 120);
m_graph.relativePosition = new Vector2(chartPadding, 200);
m_graph.color = new Color32(200, 200, 200,255);
m_graph.AddCurve("TestData", "EN-US", _chartLine, 2, new Color32(132, 55, 55, 255));
}
private UIRadialChart CreateRadialChart(int level)
{
UIRadialChart rc = AddUIComponent<UIRadialChart>();
rc.isEnabled = true;
rc.isVisible = true;
rc.name = RadialChartPrefix + "EmploymentChartLevel" + level;
rc.size = chartSize;
rc.relativePosition = new Vector2(chartPadding + (level % 2 * (rc.size.x + chartSeparator)), chartPadding + (level / 2 * (rc.size.y + chartSeparator)));
rc.zOrder = 2;
rc.spriteName = "PieChartWhiteBg";
rc.AddSlice();
UIRadialChart.SliceSettings slice0 = rc.GetSlice(0);
Color32 color = JobsUtils.educationLevelColors[level];
slice0.outterColor = color;
slice0.innerColor = color;
rc.AddSlice();
UIRadialChart.SliceSettings slice1 = rc.GetSlice(1);
Color32 color2 = new Color32(132, 110, 110, 255);
slice1.outterColor = color2;
slice1.innerColor = color2;
return rc;
}
public override void Update()
{
if (isVisible && isEnabled)
{
for (int i = 0; i < m_RadialChart.Length; i++)
{
float percent;
switch (RadialChartPrefix)
{
case "workplaces":
percent = BuildingsInfoManager.GetPercent(i);
break;
default:
percent = JobsUtils.GetPercentEmployedF(i);
break;
}
m_RadialChart[i].SetValues(new float[] { percent, 1f - percent });
}
}
}
}
}