Tanoda
WaitingRoomManager.cs
Go to the documentation of this file.
1using NaughtyAttributes;
2using System.Collections.Generic;
3using System.IO;
4using System.Linq;
5using UnityEngine;
6
7public class WaitingRoomManager : MonoBehaviour
8{
9 public GameObject[] pageswitchers;
11 public UnityEngine.UI.Text[] buttonTexts;
12
13 private int pageIndex = 0;
14 private int maxPages = 0;
15 private int selected = -1;
16
17 [Button]
18 public void Start()
19 {
20 var hasMoreThenThree = false;
21 var user = SavedUser.instance.currentUser;
22 if (user.HasValue && user.Value.addedTrainings != null)
23 {
24 buttonTexts[1].text = "";
25 buttonTexts[2].text = "";
26 for (int i = 0; i < user.Value.addedTrainings.Count; i++)
27 {
28 if (i > 2) break;
29 UserManager.AddedTrainings course = user.Value.addedTrainings[i];
30 buttonTexts[i].text = course.TrainingName;
31 }
32 hasMoreThenThree = user.Value.addedTrainings.Count > 3;
33 maxPages = user.Value.addedTrainings.Count / 3 + 1;
34 pageNumber.text = $"1/{maxPages}";
35 }
36 foreach (var item in pageswitchers)
37 {
38 item.gameObject.SetActive(hasMoreThenThree);
39 }
40 }
41
42 public void StartSelected()
43 {
44 if (selected == -1) return;
45 var jsonPath = GetFilesFullPath(new [] {buttonTexts[selected].text});
46 Debug.Log("jsonPath: " + jsonPath.FirstOrDefault());
47 var mls = FindObjectOfType<MenuLoadScene>();
48 mls.Open(jsonPath[0]);
49
50 }
51
52 public void SelectCourse(int index)
53 {
54 Debug.Log("SELECTED: " + index);
55 selected = index;
56 }
57
58 public void OnPreviousPage()
59 {
60 pageIndex--;
61 if (pageIndex < 0)
62 {
63 pageIndex++;
64 return;
65 }
66 selected = -1;
67 pageNumber.text = $"{pageIndex + 1}/{maxPages}";
68
69 var user = SavedUser.instance.currentUser;
70 var trainings = user.Value.addedTrainings;
71 var j = 0;
72 for (int i = pageIndex * 3; i < trainings.Count; i++)
73 {
74 if (j > 2) break;
75 UserManager.AddedTrainings course = trainings[i];
76 buttonTexts[j].text = course.TrainingName;
77 j++;
78 }
79 }
80 public void OnNextPage()
81 {
82 pageIndex++;
83 if (pageIndex > maxPages - 1)
84 {
85 pageIndex--;
86 return;
87 }
88 selected = -1;
89 pageNumber.text = $"{pageIndex + 1}/{maxPages}";
90
91 var user = SavedUser.instance.currentUser;
92 var trainings = user.Value.addedTrainings;
93 var j = 0;
94 for (int i = pageIndex * 3; i < trainings.Count; i++)
95 {
96 if (j > 2) break;
97 UserManager.AddedTrainings course = trainings[i];
98 buttonTexts[j].text = course.TrainingName;
99 j++;
100 }
101 if (j == 1)
102 {
103 buttonTexts[1].text = "";
104 buttonTexts[2].text = "";
105 }
106 if (j == 2)
107 {
108 buttonTexts[2].text = "";
109 }
110 }
111
112
113 private List<string> GetFilesFullPath(string[] files,
114 SearchOption searchOption = SearchOption.AllDirectories)
115 {
116#if UNITY_EDITOR
117 string fileName = Path.Combine(Application.streamingAssetsPath, "..", "..");
118#else
119 string fileName = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName;
120#endif
121 Debug.Log("fileName: " + fileName);
122 Debug.Log("filePath: " + Path.GetDirectoryName(fileName));
123 var allfiles = Directory.EnumerateFiles(Path.GetDirectoryName(fileName), "*", searchOption).ToList();
124 var retval = new List<string>();
125 foreach (var filepath in allfiles)
126 {
127 foreach (var file in files)
128 {
129 if (filepath.EndsWith(file))
130 {
131 retval.Add(filepath);
132 break;
133 }
134 }
135 }
136 return retval;
137 }
138}
UnityEngine.UI.Button Button
Definition: Pointer.cs:7
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
UnityEngine.UI.Text pageNumber
GameObject[] pageswitchers
void SelectCourse(int index)
UnityEngine.UI.Text[] buttonTexts