146 lines
5.2 KiB
C#
146 lines
5.2 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using Unity.VisualScripting;
|
|
using UnityEngine;
|
|
using UnityEngine.Networking;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Video;
|
|
|
|
public class UIFile : UIBase
|
|
{
|
|
public Button close;
|
|
public Button submitBtn;
|
|
public Transform content;
|
|
public VerticalLayoutGroup layoutGroup;
|
|
|
|
List<GameObject> files;
|
|
private void Awake()
|
|
{
|
|
EventCenter.dispatcher.AddListener(MsgType.OnSubmitQuestion, OnSubmitQuestion);
|
|
close.onClick.AddListener(() => { UIManager.Instance.DestoryUI(UIType.UIFile); });
|
|
files = new List<GameObject>();
|
|
}
|
|
|
|
private void OnSubmitQuestion(Message evt)
|
|
{
|
|
//for (int i = 0; i < allQuestionItem.Count; i++)
|
|
//{
|
|
// var item = allQuestionItem[i];
|
|
// AnswerQuestionData questionData = new AnswerQuestionData();
|
|
// questionData.question = item.currentData;
|
|
// questionData.questionID = item.currentData.id;
|
|
// questionData.type = item.currentData.type;
|
|
// if (item.currentData.type == 1)
|
|
// {
|
|
// questionData.chooseOne = item.GetTogSelect();
|
|
// }
|
|
// else if (item.currentData.type == 2)
|
|
// {
|
|
// questionData.choose = item.GetAllSelect();
|
|
// }
|
|
// else
|
|
// {
|
|
// questionData.hint = item.GetStrAnswer();
|
|
// }
|
|
// bool ishave = false;
|
|
// var temp2 = DataManager.Instance.currentAllDoneQuestion;
|
|
// for (int j = 0; j < temp2.Count; j++)
|
|
// {
|
|
// if (temp2[j].questionID == questionData.questionID)
|
|
// {
|
|
// temp2[j] = questionData;
|
|
// ishave = true;
|
|
// }
|
|
// }
|
|
// if (!ishave)
|
|
// {
|
|
// DataManager.Instance.currentAllDoneQuestion.Add(questionData);
|
|
// }
|
|
//}
|
|
}
|
|
|
|
public void Init(List<FileInfoData> list)
|
|
{
|
|
if (list != null)
|
|
{
|
|
GameObject fileItem = (GameObject)Resources.Load("UIPrefabs/FileItem");
|
|
GameObject questionPrefab = (GameObject)Resources.Load("UIPrefabs/Question");
|
|
for (int i = 0; i < list.Count; i++)
|
|
{
|
|
GameObject newUI;
|
|
if (list[i].type == FileType.question)
|
|
{
|
|
newUI = GameObject.Instantiate(questionPrefab, content);
|
|
QuestionItem currentItem = newUI.GetComponent<QuestionItem>();
|
|
currentItem.Init(list[i].question, false, false);
|
|
}
|
|
else
|
|
{
|
|
newUI = GameObject.Instantiate(fileItem, content);
|
|
FileItem item = newUI.GetComponent<FileItem>();
|
|
item.Init(list[i]);
|
|
}
|
|
files.Add(newUI);
|
|
}
|
|
var submit = GameObject.Instantiate(submitBtn, content);
|
|
submit.gameObject.SetActive(true);
|
|
submit.onClick.AddListener(() =>
|
|
{
|
|
for (int i = 0; i < files.Count; i++)
|
|
{
|
|
var temp = files[i];
|
|
QuestionItem item = temp.GetComponent<QuestionItem>();
|
|
if(item != null)
|
|
{
|
|
AnswerQuestionData questionData = new AnswerQuestionData();
|
|
questionData.question = item.currentData;
|
|
questionData.questionID = item.currentData.id;
|
|
questionData.type = item.currentData.type;
|
|
if (item.currentData.type == 1)
|
|
{
|
|
questionData.chooseOne = item.GetTogSelect();
|
|
}
|
|
else if (item.currentData.type == 2)
|
|
{
|
|
questionData.choose = item.GetAllSelect();
|
|
}
|
|
else
|
|
{
|
|
questionData.hint = item.GetStrAnswer();
|
|
}
|
|
bool ishave = false;
|
|
var temp2 = DataManager.Instance.currentAllDoneQuestion;
|
|
for (int j = 0; j < temp2.Count; j++)
|
|
{
|
|
if (temp2[j].questionID == questionData.questionID)
|
|
{
|
|
temp2[j] = questionData;
|
|
ishave = true;
|
|
}
|
|
}
|
|
if (!ishave)
|
|
{
|
|
DataManager.Instance.currentAllDoneQuestion.Add(questionData);
|
|
}
|
|
}
|
|
}
|
|
UIManager.Instance.DestoryUI(UIType.UIFile);
|
|
});
|
|
}
|
|
}
|
|
|
|
public void Refrush()
|
|
{
|
|
//layoutGroup.padding = new RectOffset(0, 0, 10, 10);
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(layoutGroup.GetComponent<RectTransform>());
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventCenter.dispatcher.RemoveListener(MsgType.OnSubmitQuestion, OnSubmitQuestion);
|
|
|
|
}
|
|
}
|