321 lines
10 KiB
C#
321 lines
10 KiB
C#
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using ZXKFramework;
|
|||
|
|
|
|||
|
|
public class Question_ChoicePanel : UIBase
|
|||
|
|
{
|
|||
|
|
public override string GroupName => UIGroupLiao.Question.ToString();
|
|||
|
|
public override string Name => "Question_ChoicePanel";
|
|||
|
|
public Dictionary<string, string> optionsDic = new Dictionary<string, string>();
|
|||
|
|
public string analysis;
|
|||
|
|
int groupId;
|
|||
|
|
Text question_Text;
|
|||
|
|
Button button_QuestionSumbit;
|
|||
|
|
RectTransform optionsParent;
|
|||
|
|
Text analysis_Text;
|
|||
|
|
RectTransform analysis_Panel;
|
|||
|
|
Button button_AnalysisClose;
|
|||
|
|
Button button_AnalysisShow;
|
|||
|
|
Button button_QuestionClose;
|
|||
|
|
Button button_QuestionNext;
|
|||
|
|
ToggleGroup toggleGroup;
|
|||
|
|
Dictionary<Toggle, string> toggleDic = new Dictionary<Toggle, string>();
|
|||
|
|
List<int> quesitonIds = new List<int>();
|
|||
|
|
int index_Question = 0;
|
|||
|
|
GameModel gameModel;
|
|||
|
|
List<string> rightAnswersList = new List<string>();
|
|||
|
|
Transform rightIcon;
|
|||
|
|
Transform falseIcon;
|
|||
|
|
bool single;
|
|||
|
|
bool ifRight = false;
|
|||
|
|
public override void Init(IUIManager uictrl)
|
|||
|
|
{
|
|||
|
|
base.Init(uictrl);
|
|||
|
|
gameModel = GetModel<GameModel>();
|
|||
|
|
question_Text = transform.FindFirst<Text>("question_Text");
|
|||
|
|
optionsParent = transform.FindFirst<RectTransform>("Options");
|
|||
|
|
analysis_Text = transform.FindFirst<Text>("Text_Analysis");
|
|||
|
|
analysis_Panel = transform.FindFirst<RectTransform>("Panel_Analysis");
|
|||
|
|
toggleGroup = transform.FindFirst<ToggleGroup>("Options");
|
|||
|
|
|
|||
|
|
button_QuestionSumbit = transform.FindFirst<Button>("Button_QuestionSumbit");
|
|||
|
|
button_AnalysisClose = transform.FindFirst<Button>("Button_AnalysisConfirm");
|
|||
|
|
button_AnalysisShow = transform.FindFirst<Button>("Button_TurnToAnalysis");
|
|||
|
|
button_QuestionNext = transform.FindFirst<Button>("Button_NextQuestion");
|
|||
|
|
button_QuestionClose = transform.FindFirst<Button>("Button_CloseQuestion");
|
|||
|
|
|
|||
|
|
rightIcon = transform.FindFirst<Transform>("Right");
|
|||
|
|
falseIcon = transform.FindFirst<Transform>("False");
|
|||
|
|
|
|||
|
|
button_QuestionSumbit.onClick.AddListener(Submit);
|
|||
|
|
button_AnalysisClose.onClick.AddListener(ConfirmAnalysis);
|
|||
|
|
button_AnalysisShow.onClick.AddListener(ShowAnalysis);
|
|||
|
|
button_QuestionNext.onClick.AddListener(ShowNextQustion);
|
|||
|
|
button_QuestionClose.onClick.AddListener(() => {
|
|||
|
|
SetActive(false);
|
|||
|
|
Game.Instance.eventManager.Raise(new CloseQuestionEvent());
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
public override void ShowData(params object[] obj)
|
|||
|
|
{
|
|||
|
|
base.ShowData(obj);
|
|||
|
|
//<2F><>ȡid
|
|||
|
|
groupId = (int)obj[0];
|
|||
|
|
quesitonIds = gameModel.questionChoiceData.GetQuestionIDsByGroup(groupId);
|
|||
|
|
//<2F><>ʼ<EFBFBD><CABC>
|
|||
|
|
index_Question = 0;
|
|||
|
|
rightAnswersList.Clear();
|
|||
|
|
optionsDic.Clear();
|
|||
|
|
//<2F><>ʾϰ<CABE><CFB0>
|
|||
|
|
ShowContent(index_Question);
|
|||
|
|
}
|
|||
|
|
//<2F><>ʾϰ<CABE><CFB0>
|
|||
|
|
public void ShowContent(int value)
|
|||
|
|
{
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
|
SetQuestion(gameModel.questionChoiceData.GetQuestionByID(quesitonIds[value]));
|
|||
|
|
SetSingleOrMultiple(gameModel.questionChoiceData.GetType(quesitonIds[value]));
|
|||
|
|
SetOptions(gameModel.questionChoiceData.GetOptionsByID(quesitonIds[value]));
|
|||
|
|
SetAnswers(gameModel.questionChoiceData.GetAnswersByID(quesitonIds[value]));
|
|||
|
|
SetAnalysis(gameModel.questionChoiceData.GetAnalysisByID(quesitonIds[value]));
|
|||
|
|
//<2F><>ʾ
|
|||
|
|
analysis_Panel.gameObject.SetActive(false);
|
|||
|
|
button_AnalysisShow.gameObject.SetActive(false);
|
|||
|
|
button_QuestionClose.gameObject.SetActive(false);
|
|||
|
|
button_QuestionNext.gameObject.SetActive(false);
|
|||
|
|
button_QuestionSumbit.gameObject.SetActive(true);
|
|||
|
|
rightIcon.gameObject.SetActive(false);
|
|||
|
|
falseIcon.gameObject.SetActive(false);
|
|||
|
|
if (gameModel.GetModeType() == ModeType.KaoHe)
|
|||
|
|
{
|
|||
|
|
Game.Instance.eventManager.Raise(new StepRecordEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.questionChoiceData.GetName(quesitonIds[index_Question]),
|
|||
|
|
answer = gameModel.questionChoiceData.GetAnswerByID(quesitonIds[value]),
|
|||
|
|
stepType = gameModel.mainData.GetMessageType(gameModel.GetId()),
|
|||
|
|
start = true
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
void SetQuestion(string value)
|
|||
|
|
{
|
|||
|
|
question_Text.text = value;
|
|||
|
|
}
|
|||
|
|
void SetSingleOrMultiple(string value)
|
|||
|
|
{
|
|||
|
|
switch (value)
|
|||
|
|
{
|
|||
|
|
case "S":
|
|||
|
|
single = true;
|
|||
|
|
break;
|
|||
|
|
case "M":
|
|||
|
|
single = false;
|
|||
|
|
break;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
void SetOptions(Dictionary<string, string> optionsDic)
|
|||
|
|
{
|
|||
|
|
toggleDic.Clear();
|
|||
|
|
rightAnswersList.Clear();
|
|||
|
|
Game.Instance.objectPool.Unspawn("Toggle_Template");
|
|||
|
|
foreach (var item in optionsDic.Keys)
|
|||
|
|
{
|
|||
|
|
Game.Instance.objectPool.Spawn("Toggle_Template", optionsParent, m =>
|
|||
|
|
{
|
|||
|
|
Toggle tempToggle = m.GetComponent<Toggle>();
|
|||
|
|
tempToggle.isOn = false;
|
|||
|
|
if (single)
|
|||
|
|
{
|
|||
|
|
tempToggle.group = toggleGroup;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
tempToggle.group = null;
|
|||
|
|
}
|
|||
|
|
tempToggle.GetComponentInChildren<Text>().text = item + "<22><>" + optionsDic[item];
|
|||
|
|
tempToggle.name = item;
|
|||
|
|
toggleDic.Add(tempToggle, item);
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
ResetAllToggle();
|
|||
|
|
}
|
|||
|
|
void SetAnswers(List<string> answers)
|
|||
|
|
{
|
|||
|
|
rightAnswersList = answers;
|
|||
|
|
}
|
|||
|
|
void SetAnalysis(string value)
|
|||
|
|
{
|
|||
|
|
analysis_Text.text = value;
|
|||
|
|
}
|
|||
|
|
public override void Destroy()
|
|||
|
|
{
|
|||
|
|
button_QuestionSumbit.onClick.RemoveAllListeners();
|
|||
|
|
button_AnalysisShow.onClick.RemoveAllListeners();
|
|||
|
|
button_AnalysisClose.onClick.RemoveAllListeners();
|
|||
|
|
button_QuestionNext.onClick.RemoveAllListeners();
|
|||
|
|
button_QuestionClose.onClick.RemoveAllListeners();
|
|||
|
|
}
|
|||
|
|
void ResetAllToggle()
|
|||
|
|
{
|
|||
|
|
SetAllToggleInteractive();
|
|||
|
|
SetAllToggleUnSelected();
|
|||
|
|
ResetAllColor();
|
|||
|
|
}
|
|||
|
|
void SetAllToggleInteractive()
|
|||
|
|
{
|
|||
|
|
foreach (var item in toggleDic.Keys)
|
|||
|
|
{
|
|||
|
|
item.interactable = true;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
void SetAllToggleUnSelected()
|
|||
|
|
{
|
|||
|
|
foreach (var item in toggleDic.Keys)
|
|||
|
|
{
|
|||
|
|
item.isOn = false;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20>ύ
|
|||
|
|
/// </summary>
|
|||
|
|
void Submit()
|
|||
|
|
{
|
|||
|
|
if (GetToggleOnCount() == 0) return;
|
|||
|
|
//<2F>ж<EFBFBD><D0B6><EFBFBD>
|
|||
|
|
if (GetToggleOnCount() == rightAnswersList.Count)
|
|||
|
|
{
|
|||
|
|
ifRight = true;
|
|||
|
|
foreach (var item in toggleDic.Keys)
|
|||
|
|
{
|
|||
|
|
if (item.isOn && !rightAnswersList.Contains(toggleDic[item]))
|
|||
|
|
{
|
|||
|
|
ifRight = false;
|
|||
|
|
SetWrongColor(item);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
ifRight = false;
|
|||
|
|
foreach (var item in toggleDic.Keys)
|
|||
|
|
{
|
|||
|
|
if (item.isOn && !rightAnswersList.Contains(toggleDic[item]))
|
|||
|
|
{
|
|||
|
|
SetWrongColor(item);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
string yourAnswer = "";
|
|||
|
|
foreach (var item in toggleDic.Keys)
|
|||
|
|
{
|
|||
|
|
if (item.isOn)
|
|||
|
|
{
|
|||
|
|
yourAnswer += item.name;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
foreach (var item in toggleDic.Keys)
|
|||
|
|
{
|
|||
|
|
item.interactable = false;
|
|||
|
|
if (rightAnswersList.Contains(toggleDic[item]))
|
|||
|
|
{
|
|||
|
|
SetRightColor(item);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
//<2F>Ƿ<EFBFBD><C7B7><EFBFBD>ʾ<EFBFBD><CABE>һ<EFBFBD>ⰴť
|
|||
|
|
if (index_Question < quesitonIds.Count - 1)
|
|||
|
|
{
|
|||
|
|
button_QuestionNext.gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
button_QuestionClose.gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
//<2F>ر<EFBFBD>
|
|||
|
|
button_AnalysisShow.gameObject.SetActive(true);
|
|||
|
|
button_QuestionSumbit.gameObject.SetActive(false);
|
|||
|
|
if (ifRight)
|
|||
|
|
{
|
|||
|
|
rightIcon.gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
falseIcon.gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
//<2F>ɼ<EFBFBD>
|
|||
|
|
if (gameModel.GetModeType() == ModeType.KaoHe)
|
|||
|
|
{
|
|||
|
|
Game.Instance.eventManager.Raise(new ScoreRecordEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.questionChoiceData.GetName(quesitonIds[index_Question]),
|
|||
|
|
right = ifRight
|
|||
|
|
});
|
|||
|
|
Game.Instance.eventManager.Raise(new StepRecordEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.questionChoiceData.GetName(quesitonIds[index_Question]),
|
|||
|
|
yourAnswer = yourAnswer,
|
|||
|
|
start = false
|
|||
|
|
});
|
|||
|
|
Game.Instance.eventManager.Raise(new ProcessEvent()
|
|||
|
|
{
|
|||
|
|
subModule = gameModel.mainData.GetSubModuleName(gameModel.GetId()),
|
|||
|
|
task = gameModel.questionChoiceData.GetName(quesitonIds[index_Question])
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// <20><>һ<EFBFBD><D2BB>
|
|||
|
|
/// </summary>
|
|||
|
|
void ShowNextQustion()
|
|||
|
|
{
|
|||
|
|
index_Question++;
|
|||
|
|
ShowContent(index_Question);
|
|||
|
|
}
|
|||
|
|
void ShowAnalysis()
|
|||
|
|
{
|
|||
|
|
analysis_Panel.gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
void ConfirmAnalysis()
|
|||
|
|
{
|
|||
|
|
analysis_Panel.gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
private void SetRightColor(Toggle toggle)
|
|||
|
|
{
|
|||
|
|
toggle.targetGraphic.color = Color.green;
|
|||
|
|
}
|
|||
|
|
void SetWrongColor(Toggle toggle)
|
|||
|
|
{
|
|||
|
|
toggle.targetGraphic.color = Color.red;
|
|||
|
|
}
|
|||
|
|
void SetNormalColor(Toggle toggle)
|
|||
|
|
{
|
|||
|
|
toggle.targetGraphic.color = Color.white;
|
|||
|
|
}
|
|||
|
|
void ResetAllColor()
|
|||
|
|
{
|
|||
|
|
foreach (var item in toggleDic.Keys)
|
|||
|
|
{
|
|||
|
|
SetNormalColor(item);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
int GetToggleOnCount()
|
|||
|
|
{
|
|||
|
|
int temp = 0;
|
|||
|
|
foreach (var item in toggleDic.Keys)
|
|||
|
|
{
|
|||
|
|
if (item.isOn)
|
|||
|
|
{
|
|||
|
|
temp++;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
return temp;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public override void HandleEvent(string name, object data)
|
|||
|
|
{
|
|||
|
|
}
|
|||
|
|
}
|