Tanoda
ResultCanvas.cs
Go to the documentation of this file.
1using System.Collections.Generic;
2using System.Linq;
3using UnityEngine;
4using UnityEngine.UI;
5
6public class ResultCanvas : MonoBehaviour
7{
8 public GameObject newRow, newColumn;
9 public Transform parent;
10 public static ResultCanvas Instance { get; private set; }
11 public List <ResultCanvasHelper> rowList = new List <ResultCanvasHelper>();
12 // Start is called before the first frame update
13 void Start()
14 {
15 Instance = this;
16 }
17
18 // Update is called once per frame
19 void Update()
20 {
21
22 }
23
24
25 public void ShowResultCanvas(UserManager.Training lastTraining)
26 {
27 //var resultCanvasHelper = FindObjectOfType<ResultCanvasHelper>(true);
28 //resultCanvasHelper.canvas.SetActive(true);
29 //var resultRow = FindObjectOfType<ResultCanvasHelper>(true);
30 var currentUserValue = UserManager.instance.GetUserByName(SavedUser.instance.currentUser.Value.Username);
31 var currentTrainingName = SavedUser.instance.levelName;
32 List<UserManager.Training> currentTrainings = new List<UserManager.Training>();
33 var allTraining = currentUserValue.trainings;
34 //var lastTraining = currentTrainings[currentTrainings.Count - 1];
35 var actions = lastTraining.Actions.OrderByDescending(x => x.timeSpent).ToList();
36 int counter = 0;
37 GameObject addColumn = new GameObject();
39 foreach (var action in actions)
40 {
41 if (!Blacklisted(action.actionType))
42 {
43
44 var actionObject = Controller.Instance.GetActionById(action.actionName);
45
46 HoldToolAction HTA = null;
47 RealToolAction RTA = null;
48 if (actionObject is HoldToolAction) HTA = (HoldToolAction)actionObject;
49 if (actionObject is RealToolAction) RTA = (RealToolAction)actionObject;
50
51 var connections = Controller.Instance.GetConnectionsByEndPointId(actionObject.outPuts[0].name);
52 bool outputIsWaiter = false;
53 foreach (var c in connections)
54 {
55 var outputAction = Controller.Instance.GetActionByInOut(c.toId);
56 if (outputAction.action.Contains("Waiter")) outputIsWaiter = true;
57 }
58
59 if (!outputIsWaiter && actionObject.taktTime > 0)
60 {
61
62 if (counter % 2 == 0 || counter == 0)
63 {
64 addColumn = Instantiate(newColumn, parent);
65
66 }
67 sh = addColumn.GetComponent<StatisticHelper>();
68 var addRow = Instantiate(sh.newRow, sh.newRow.transform.parent);
69 addRow.gameObject.SetActive(true);
70 counter++;
71 var row = addRow.GetComponentInChildren<ResultCanvasHelper>();
72 rowList.Add(row);
73 row.gameObject.SetActive(true);
74 if (actionObject.comment != null) row.actionName.text = actionObject.comment;
75 else row.actionName.text = actionObject.action;
76
77 for (int i = 0; i < lastTraining.Actions.Count; i++)
78 {
79 if (lastTraining.Actions[i].actionName == actionObject.name)
80 {
81 row.takt.text = Mathf.FloorToInt(actionObject.taktTime / 60).ToString("D2") + ":" + (actionObject.taktTime % 60).ToString("00.00").Replace(',', '.');
82 row.timeSpent.text = Mathf.FloorToInt(actionObject.spentTimeOnAction / 60).ToString("D2") + ":" + (actionObject.spentTimeOnAction % 60).ToString("00.00").Replace(',', '.');
83 if (actionObject.timeInUse > 0) row.useful.text = Mathf.FloorToInt(actionObject.timeInUse / 60).ToString("D2") + ":" + (actionObject.timeInUse % 60).ToString("00.00").Replace(',', '.');
84 else row.useful.text = "-";
85
86 if (HTA != null)
87 {
88 if (LanguageSelector.Instance.selectedLang == 0)
89 {
90 if (HTA.low) row.progress.text = "ALACSONY";
91 else if (HTA.high) row.progress.text = "MAGAS";
92 else row.progress.text = "OK";
93 }
94 else
95 {
96 if (HTA.low) row.progress.text = "LOW";
97 else if (HTA.high) row.progress.text = "HIGH";
98 else row.progress.text = "OK";
99 }
100
101 }
102 if (RTA != null)
103 {
104 if (LanguageSelector.Instance.selectedLang == 0)
105 {
106 if (RTA.low) row.progress.text = "ALACSONY";
107 else if (RTA.high) row.progress.text = "MAGAS";
108 else row.progress.text = "OK";
109 }
110 else
111 {
112 if (RTA.low) row.progress.text = "LOW";
113 else if (RTA.high) row.progress.text = "HIGH";
114 else row.progress.text = "OK";
115 }
116
117 }
118 if (!HTA && !RTA)
119 {
120 row.progress.text = "-";
121 }
122
123 }
124 }
125
126 if (actionObject.spentTimeOnAction > actionObject.taktTime || HTA && HTA.isPenalty || RTA && RTA.isPenalty)
127 {
128 if (LanguageSelector.Instance.selectedLang == 0)
129 {
130 row.succes.text = "SIKERTELEN";
131 }
132 else
133 {
134 row.succes.text = "FAILED";
135 }
136
137 row.GetComponent<Image>().color = Color.red;
138 }
139 else
140 {
141 if (LanguageSelector.Instance.selectedLang == 0)
142 {
143 row.succes.text = "SIKERES";
144 }
145 else
146 {
147 row.succes.text = "SUCCES";
148 }
149
150 row.GetComponent<Image>().color = Color.green;
151 }
152
153 }
154
155 }
156
157 }
158 //if (taktTimeHelper.transform.parent.childCount < 4)
159 //{
160 // var children = taktTimeHelper.transform.parent.GetComponentsInChildren<OptimizationHelper>(true);
161 // foreach (var child in children)
162 // {
163 // child.actionName.color = Color.red;
164 // child.time.color = Color.red;
165 // }
166 //}
167 //else
168 //{
169 // var children = taktTimeHelper.transform.parent.GetComponentsInChildren<OptimizationHelper>(true);
170 //}
171 }
172
173 public void ClearRows()
174 {
175 foreach (var item in rowList)
176 {
177 if (item && item.gameObject)
178 {
179 Destroy(item.gameObject);
180 }
181
182 }
183 }
184 private bool Blacklisted(string action)
185 {
186 return action.Contains("Countdown") || action.Contains("GameObject") || action.Contains("Weld") ||
187 action.Contains("Led") || action.Contains("Start") || action.Contains("Sound") ||
188 action.Contains("Move") || action.Contains("Belt") || action.Contains("ShowHide") || action.Contains("Deactivate") ||
189 action.Contains("Script") || action.Contains("Voice") || action.Contains("Collector") || action.Contains("Finish") || action.Contains("Trigger");
190 }
191}
System.Drawing.Image Image
Definition: TestScript.cs:37
UnityEngine.Color Color
Definition: TestScript.cs:32
Connection[] GetConnectionsByEndPointId(string id)
Definition: Controller.cs:862
ActionObject GetActionByInOut(string id)
Definition: Controller.cs:925
ActionObject GetActionById(string id)
Definition: Controller.cs:950
static Controller Instance
Definition: Controller.cs:16
static LanguageSelector Instance
GameObject newColumn
Definition: ResultCanvas.cs:8
void ClearRows()
void ShowResultCanvas(UserManager.Training lastTraining)
Definition: ResultCanvas.cs:25
GameObject newRow
Definition: ResultCanvas.cs:8
List< ResultCanvasHelper > rowList
Definition: ResultCanvas.cs:11
static ResultCanvas Instance
Definition: ResultCanvas.cs:10
Transform parent
Definition: ResultCanvas.cs:9
List< VRAction > Actions
Definition: UserManager.cs:854