244 lines
8.5 KiB
C#
244 lines
8.5 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class UICheckTest : UIBase
|
|
{
|
|
public Button close;
|
|
QuestionType questionType;
|
|
|
|
List<DataItem2> currentPeoplesQuestion;
|
|
|
|
public Transform content;
|
|
List<QuestionItem> allQuestionItem;
|
|
|
|
GameObject questionPrefab;
|
|
|
|
private void Awake()
|
|
{
|
|
close.onClick.AddListener(() => { UIManager.Instance.DestoryUI(UIType.UICheckTest); });
|
|
EventCenter.dispatcher.AddListener(MsgType.OnSubmitQuestion, OnSubmitQuestion);
|
|
questionPrefab = (GameObject)Resources.Load("UIPrefabs/Question");
|
|
|
|
EventCenter.dispatcher.AddListener(MsgType.OnGetPeopleQuetionList, RefreshData);
|
|
RefreshData();
|
|
}
|
|
|
|
public void RefreshData(Message evt = null)
|
|
{
|
|
if (content != null)
|
|
{
|
|
for (int i = 0; i < content.transform.childCount; i++)
|
|
{
|
|
var transform = content.transform.GetChild(i);
|
|
GameObject.Destroy(transform.gameObject);
|
|
}
|
|
}
|
|
var allQuestion = DataManager.Instance.currentPeoplesQuestion;
|
|
questionType = DataManager.Instance.currentQuesitionType;
|
|
allQuestionItem = new List<QuestionItem>();
|
|
currentPeoplesQuestion = new List<DataItem2>();
|
|
|
|
|
|
//如果是退出 显示所有答过的问题
|
|
if (questionType == QuestionType.EXIT_PROBLEM)
|
|
{
|
|
var datas = DataManager.Instance.currentAllDoneQuestion;
|
|
for (int i = 0; i < datas.Count; i++)
|
|
{
|
|
if (content != null)
|
|
{
|
|
var temp = datas[i];
|
|
var newUI = GameObject.Instantiate(questionPrefab, content);
|
|
QuestionItem currentItem = newUI.GetComponent<QuestionItem>();
|
|
bool isEnd = i == datas.Count - 1;
|
|
currentItem.Init(temp.question, isEnd, true);
|
|
allQuestionItem.Add(currentItem);
|
|
if (datas[i].type == 1)
|
|
{
|
|
currentItem.SetChooseSingle(temp.chooseOne);
|
|
}
|
|
else if (datas[i].type == 2)
|
|
{
|
|
currentItem.SetMoreChoose(temp.choose);
|
|
}
|
|
else
|
|
{
|
|
currentItem.SetStrAnswer(temp.hint);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
return;
|
|
}
|
|
}
|
|
}
|
|
//其余正常显示问题
|
|
switch (questionType)
|
|
{
|
|
case QuestionType.CLINICAL_PROBLEM:
|
|
for (int i = 0; i < allQuestion.Count; i++)
|
|
{
|
|
if (allQuestion[i].backgroundType == 1)
|
|
{
|
|
currentPeoplesQuestion.Add(allQuestion[i]);
|
|
}
|
|
}
|
|
break;
|
|
case QuestionType.DIAGNOSE_PROBLEM:
|
|
for (int i = 0; i < allQuestion.Count; i++)
|
|
{
|
|
if (allQuestion[i].backgroundType == 2)
|
|
{
|
|
currentPeoplesQuestion.Add(allQuestion[i]);
|
|
}
|
|
}
|
|
break;
|
|
case QuestionType.SUGGEST_PROBLEM:
|
|
for (int i = 0; i < allQuestion.Count; i++)
|
|
{
|
|
if (allQuestion[i].backgroundType == 3)
|
|
{
|
|
currentPeoplesQuestion.Add(allQuestion[i]);
|
|
}
|
|
}
|
|
break;
|
|
case QuestionType.TALK_OVER:
|
|
for (int i = 0; i < allQuestion.Count; i++)
|
|
{
|
|
if (allQuestion[i].backgroundType == 4)
|
|
{
|
|
currentPeoplesQuestion.Add(allQuestion[i]);
|
|
}
|
|
}
|
|
break;
|
|
case QuestionType.EXIT_PROBLEM:
|
|
//currentPeoplesQuestion = DataManager.Instance.currentAnswerQuestion;
|
|
break;
|
|
}
|
|
for (int i = 0; i < currentPeoplesQuestion.Count; i++)
|
|
{
|
|
if (content != null)
|
|
{
|
|
var temp = currentPeoplesQuestion[i];
|
|
var newUI = GameObject.Instantiate(questionPrefab, content);
|
|
QuestionItem currentItem = newUI.GetComponent<QuestionItem>();
|
|
bool isEnd = i == currentPeoplesQuestion.Count - 1;
|
|
currentItem.Init(temp, isEnd);
|
|
allQuestionItem.Add(currentItem);
|
|
}
|
|
}
|
|
if (content != null)
|
|
{
|
|
LayoutRebuilder.ForceRebuildLayoutImmediate(content.GetComponent<RectTransform>());
|
|
}
|
|
|
|
}
|
|
|
|
private void OnSubmitQuestion(Message evt)
|
|
{
|
|
bool isAllFinish = false;
|
|
for (int i = 0; i < allQuestionItem.Count; i++)
|
|
{
|
|
var item = allQuestionItem[i];
|
|
if (item.currentData.type == 3)
|
|
{
|
|
if (string.IsNullOrEmpty(item.GetStrAnswer()))
|
|
{
|
|
Debug.Log("InputField" + item.name + "No answer");
|
|
isAllFinish = false;
|
|
|
|
break;
|
|
}
|
|
}
|
|
if (item.GetTogSelect() == -1)
|
|
{
|
|
Debug.Log("Toggle" + item.name + "No answer");
|
|
isAllFinish = false;
|
|
|
|
break;
|
|
}
|
|
isAllFinish = true;
|
|
}
|
|
if (isAllFinish)
|
|
{
|
|
for (int i = 0; i < allQuestionItem.Count; i++)
|
|
{
|
|
var item = allQuestionItem[i];
|
|
//步骤
|
|
UITalkMain uitalkMain = (UITalkMain)UIManager.Instance.GetUIBase(UIType.UITalkMain);
|
|
var temp = DataManager.Instance.currentDisDistance;
|
|
int tempNum = uitalkMain.currentStep + 1;
|
|
if (temp.ContainsKey(tempNum))
|
|
{
|
|
if (!temp[tempNum])
|
|
{
|
|
uitalkMain.currentStep = tempNum;
|
|
temp[tempNum] = true;
|
|
uitalkMain.RefreshLeftBtnState(true);
|
|
}
|
|
}
|
|
//
|
|
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);
|
|
}
|
|
}
|
|
if (questionType == QuestionType.EXIT_PROBLEM)
|
|
{
|
|
var list = DataManager.Instance.peopleDisProgress;
|
|
var id = DataManager.Instance.currentSelectPeople.id;
|
|
var disID = DataManager.Instance.currentData.id;
|
|
if (list.ContainsKey(id))
|
|
{
|
|
var t1 = list[id];
|
|
var t2 = t1[t1.Count - 1];
|
|
int num = t2 + 1;
|
|
list[id].Add(num);
|
|
}
|
|
UIManager.Instance.DestoryUI(UIType.UITalkMain);
|
|
UIManager.Instance.ShowAllUI();
|
|
UIPeopleProgress ui = (UIPeopleProgress)UIManager.Instance.GetUIBase(UIType.UIPeopleProgress);
|
|
ui.RefreshProgressState();
|
|
}
|
|
|
|
UIManager.Instance.DestoryUI(UIType.UICheckTest);
|
|
}
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
EventCenter.dispatcher.RemoveListener(MsgType.OnSubmitQuestion, OnSubmitQuestion);
|
|
EventCenter.dispatcher.RemoveListener(MsgType.OnGetPeopleQuetionList, RefreshData);
|
|
|
|
}
|
|
}
|