319 lines
9.3 KiB
C#
319 lines
9.3 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.SceneManagement;
|
|
using System.IO;
|
|
|
|
public class MenuController : MonoBehaviour
|
|
{
|
|
|
|
public static MenuController instance;
|
|
public static Sprite loadsprite;
|
|
|
|
#region Colors
|
|
[System.Serializable]
|
|
public class ColorGroup
|
|
{
|
|
public Color clara, escura, contrastColor;
|
|
}
|
|
|
|
public List<ColorGroup> colorsGroup;
|
|
public int indexColor;
|
|
|
|
public ColorGroup GetColor()
|
|
{
|
|
ColorGroup colorReturn = colorsGroup[indexColor];
|
|
indexColor++;
|
|
|
|
if (indexColor >= colorsGroup.Count)
|
|
{
|
|
indexColor = 0;
|
|
}
|
|
|
|
return colorReturn;
|
|
}
|
|
#endregion
|
|
|
|
private void Awake()
|
|
{
|
|
instance = this;
|
|
loadsprite = Resources.Load<Sprite>("Load");
|
|
}
|
|
|
|
Animator canvasAnime;
|
|
bool canChange = true;
|
|
|
|
public int nbrsClasses;
|
|
public GameObject prefabClass; APIMenu apiMenu;
|
|
|
|
public List<APIMenu.Classes> classes = new List<APIMenu.Classes>();
|
|
[SerializeField]
|
|
public List<GlobalClasses.ClassInfo> classInfos = new List<GlobalClasses.ClassInfo>();
|
|
|
|
public List<string> allowedCourses = new List<string>();
|
|
public List<string> coursesName = new List<string>();
|
|
public List<int> allowedClasses = new List<int>();
|
|
public Text nomeCurso; int actualCourse;
|
|
GameObject scrollObj;
|
|
|
|
Transform alligner;
|
|
List<GameObject> classPrefabObjs = new List<GameObject>();
|
|
|
|
public bool listedCourses = false;
|
|
bool cancelLoad = false;
|
|
Coroutine routineLoading = null;
|
|
bool changingCourse = false;
|
|
|
|
List<int> QuantidadeAulas = new List<int>();
|
|
|
|
private void Start()
|
|
{
|
|
nomeCurso = GameObject.Find("txtClass").GetComponent<Text>();
|
|
canvasAnime = GameObject.Find("ControlAnime").GetComponent<Animator>();
|
|
apiMenu = GetComponent<APIMenu>();
|
|
alligner = GameObject.Find("Content Aulas").transform;
|
|
|
|
StartCoroutine(CheckNDeleteFiles());
|
|
|
|
StartCoroutine(secondStart());
|
|
}
|
|
|
|
IEnumerator CheckNDeleteFiles()
|
|
{
|
|
foreach (string file in Directory.GetFiles(Application.persistentDataPath))
|
|
{
|
|
File.Delete(file);
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
yield break;
|
|
}
|
|
|
|
IEnumerator secondStart()
|
|
{
|
|
GameObject objleft = GameObject.Find("Left");
|
|
GameObject objRight = GameObject.Find("Right");
|
|
|
|
objleft.SetActive(false);
|
|
objRight.SetActive(false);
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
while (!ReadingFile.instance.canGo)
|
|
{
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
|
|
//Pega um token com o usuário do aluno
|
|
yield return StartCoroutine(apiMenu.LogarAluno());
|
|
|
|
//Lista os cursos disponíveis daquele aluno
|
|
yield return StartCoroutine(apiMenu.listCourses(ReadingFile.idmatricula, ReadingFile.banco));
|
|
|
|
while (!listedCourses)
|
|
{
|
|
yield return new WaitForFixedUpdate();
|
|
}
|
|
|
|
//Para cada curso, lista as aulas liberadas nele
|
|
for (int i = 0; i < allowedCourses.Count; i++)
|
|
{
|
|
if (allowedCourses[i] == "41" || allowedCourses[i] == "42")
|
|
{
|
|
Debug.Log("ID Curso :" + allowedCourses[i]);
|
|
yield return StartCoroutine(apiMenu.listClasses(allowedCourses[i], "99"));
|
|
}
|
|
else
|
|
{
|
|
yield return StartCoroutine(apiMenu.listClasses(allowedCourses[i], allowedClasses[i].ToString()));
|
|
}
|
|
apiMenu.FinishedLoading();
|
|
}
|
|
|
|
//Passa as informações de cada aula de cada curso para uma classe adequada
|
|
for (int o = 0; o < allowedCourses.Count; o++)
|
|
{
|
|
GlobalClasses.ClassInfo courseClass = new GlobalClasses.ClassInfo();
|
|
courseClass.idCurso = allowedCourses[o];
|
|
courseClass.nomeCurso = coursesName[o];
|
|
courseClass.infos = new List<GlobalClasses.ClassDetailedInfo>();
|
|
for (int i2 = 0; i2 < ((classes.Count > o) ? classes[o].response.Count : 0); i2++)
|
|
{
|
|
if (courseClass.idCurso == classes[o].response[i2].idcourses.ToString())
|
|
{
|
|
GlobalClasses.ClassDetailedInfo info = new GlobalClasses.ClassDetailedInfo();
|
|
info.description = classes[o].response[i2].description;
|
|
info.disabled = classes[o].response[i2].disabled;
|
|
info.idclasses = classes[o].response[i2].idclasses;
|
|
info.idcourses = classes[o].response[i2].idcourses;
|
|
info.name = classes[o].response[i2].name;
|
|
info.ordem = classes[o].response[i2].ordem;
|
|
info.viewed = classes[o].response[i2].viewed;
|
|
info.sprites = classes[o].response[i2].sprites;
|
|
info.demo = classes[o].response[i2].demo;
|
|
|
|
courseClass.infos.Add(info);
|
|
}
|
|
}
|
|
classInfos.Add(courseClass);
|
|
QuantidadeAulas.Add(classInfos[o].infos.Count);
|
|
yield return new WaitForEndOfFrame();
|
|
}
|
|
classes = null;
|
|
Debug.Log(classInfos[classInfos.Count - 1].idCurso);
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
if (allowedCourses.Count == 0)
|
|
{
|
|
nomeCurso.text = "No courses available!";
|
|
|
|
foreach (GameObject item in classPrefabObjs)
|
|
{
|
|
Destroy(item);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
StartCoroutine(PreencherCursos(0));
|
|
|
|
nomeCurso.text = classInfos[0].nomeCurso;
|
|
actualCourse = 0;
|
|
coursesName = null;
|
|
|
|
scrollObj = GameObject.Find("Scroll");
|
|
}
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
if (allowedCourses.Count > 1)
|
|
{
|
|
objleft.SetActive(true);
|
|
objRight.SetActive(true);
|
|
}
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
canvasAnime.SetBool("start", true);
|
|
Debug.Log(classInfos[0].infos.Count);
|
|
}
|
|
|
|
IEnumerator waitToClickAgain()
|
|
{
|
|
canChange = false;
|
|
yield return new WaitForSecondsRealtime(.1f);
|
|
canChange = true;
|
|
}
|
|
|
|
public void EnterClass(GlobalClasses.ClassDetailedInfo ClassTogo)
|
|
{
|
|
PlayerPrefs.SetString("NomeAula", ClassTogo.name);
|
|
PlayerPrefs.SetString("Desc", ClassTogo.description);
|
|
|
|
PlayerPrefs.SetInt("idClass", ClassTogo.idclasses);
|
|
SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);
|
|
|
|
//StartCoroutine(ExcludeExistingVideos(ClassTogo.idclasses));
|
|
}
|
|
|
|
IEnumerator ExcludeExistingVideos(int idClass)
|
|
{
|
|
string Path = Application.persistentDataPath + "/";
|
|
|
|
DirectoryInfo dir = new DirectoryInfo(Path);
|
|
FileInfo[] info = dir.GetFiles("*.*");
|
|
foreach (FileInfo f in info)
|
|
{
|
|
File.Delete(f.FullName);
|
|
}
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
PlayerPrefs.SetInt("idClass", idClass);
|
|
SceneManager.LoadSceneAsync(1, LoadSceneMode.Single);
|
|
}
|
|
|
|
public void Scroll()
|
|
{
|
|
if (canChange)
|
|
{
|
|
bool active = canvasAnime.GetBool("downScroll");
|
|
canvasAnime.SetBool("downScroll", !active);
|
|
|
|
StartCoroutine(waitToClickAgain());
|
|
}
|
|
}
|
|
|
|
public void ChangeCourse(int add)
|
|
{
|
|
StartCoroutine(changeCourse(add));
|
|
}
|
|
|
|
IEnumerator changeCourse(int add)
|
|
{
|
|
if (!changingCourse)
|
|
{
|
|
changingCourse = true;
|
|
|
|
int newcourse = actualCourse + add;
|
|
if (newcourse <= (classInfos.Count - 1) && newcourse >= 0)
|
|
{
|
|
nomeCurso.text = classInfos[newcourse].nomeCurso;
|
|
}
|
|
else
|
|
{
|
|
if (newcourse < 0)
|
|
{
|
|
newcourse = classInfos.Count - 1;
|
|
nomeCurso.text = classInfos[newcourse].nomeCurso;
|
|
}
|
|
else
|
|
{
|
|
newcourse = 0;
|
|
nomeCurso.text = classInfos[newcourse].nomeCurso;
|
|
}
|
|
}
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
foreach (GameObject item in classPrefabObjs)
|
|
{
|
|
Destroy(item);
|
|
}
|
|
|
|
classPrefabObjs.Clear();
|
|
if (routineLoading != null)
|
|
{
|
|
StopCoroutine(routineLoading);
|
|
}
|
|
yield return routineLoading = StartCoroutine(PreencherCursos(newcourse));
|
|
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
actualCourse = newcourse;
|
|
changingCourse = false;
|
|
}
|
|
}
|
|
|
|
public IEnumerator PreencherCursos(int ICurso)
|
|
{
|
|
int quant = QuantidadeAulas[ICurso] < 20 ? 20 : QuantidadeAulas[ICurso];
|
|
for (int i = 0; i < quant; i++)
|
|
{
|
|
classPrefabObjs.Add(Instantiate(prefabClass, alligner));
|
|
classPrefabObjs[classPrefabObjs.Count - 1].GetComponent<ClassControl>().SetInformation(classInfos[ICurso], i);
|
|
|
|
//yield return new WaitForSeconds(.2f);
|
|
}
|
|
routineLoading = null;
|
|
yield return new WaitForEndOfFrame();
|
|
|
|
|
|
}
|
|
|
|
public void ExitApplication()
|
|
{
|
|
Debug.Log("Sair");
|
|
Application.Quit();
|
|
}
|
|
}
|