Tz2/Assets/Zion/Scripts/配送/不良行为处理/Delivery_BadBehavior.cs

207 lines
5.6 KiB
C#

using System;
using DefaultNamespace.ProcessMode;
using Newtonsoft.Json;
using System.Collections.Generic;
using System.Linq;
using DefaultNamespace;
using MotionFramework;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static InterfaceManager;
/// <summary>
/// 不良行为处理
/// </summary>
public class Delivery_BadBehavior : MonoBehaviour
{
/// <summary>
/// 确定按钮
/// </summary>
private Button confirmBtn;
/// <summary>
/// 清单按钮
/// </summary>
private Button inventoryBtn;
/// <summary>
/// 清单图片
/// </summary>
private Image inventoryImg;
/// <summary>
/// 选项组
/// </summary>
private ToggleGroup options;
/// <summary>
/// 问题提示
/// </summary>
private TextMeshProUGUI questionStem;
/// <summary>
/// 问题类型
/// </summary>
private TextMeshProUGUI questionTypes;
/// <summary>
/// 选项
/// </summary>
private List<Toggle> toggles;
/// <summary>
/// 不良行为数据
/// </summary>
private List<BadBehaviorData> badBehaviorDatas;
/// <summary>
/// 当前题号
/// </summary>
public int step;
public bool isGuiding = false;
public bool isGuiding2 = false;
public static Delivery_BadBehavior Instance;
private void Awake()
{
Instance = this;
}
private void Start()
{
Init();
}
public void Init()
{
//FindObjectByName<RectTransform>("不良行为清单Canvas").gameObject.SetActive(true);
badBehaviorDatas = MyJsonManager.LoadListData<BadBehaviorData>("DeliveryData/不良行为处理");
questionTypes = FindObjectByName<TextMeshProUGUI>("questionTypes");
questionStem = FindObjectByName<TextMeshProUGUI>("questionStem");
inventoryBtn = FindObjectByName<Button>("BtnInventory");
inventoryBtn.gameObject.SetActive(true);
confirmBtn = FindObjectByName<Button>("btn_BadBehavior");
inventoryImg = FindObjectByName<Image>("供应商不良行为清单");
options = GetComponentInChildren<ToggleGroup>(true);
toggles = options.GetComponentsInChildren<Toggle>(true).ToList();
for (int i = 0; i < toggles.Count; i++)
{
toggles[i].onValueChanged.AddListener((bool value) =>
{
if (value)
{
LoadTriggerNextGuide();
}
});
}
inventoryImg.GetComponentInChildren<Button>().onClick.AddListener(() =>
{
if (isGuiding)
{
if (!isGuiding2)
{
transform.GetChild(0).gameObject.SetActive(true);
LoadTriggerNextGuide();
isGuiding2 = true;
}
}
inventoryImg.gameObject.SetActive(false);
});
inventoryBtn.onClick.AddListener(async () =>
{
if (MotionEngine.GetModule<GlobalDataStorage>().ExamName != "不良行为处理")
return;
inventoryImg.gameObject.SetActive(true);
inventoryImg.rectTransform.anchoredPosition = Vector3.zero;
if (!isGuiding)
{
if (await LoadTriggerNextGuide(inventoryBtn.name))
{
isGuiding = true;
}
}
});
confirmBtn.onClick.AddListener(() =>
{
List<string> selectedAnswers = new List<string>();
foreach (Toggle toggle in toggles.FindAll(t => t.isOn))
{
TextMeshProUGUI textMeshProUGUI = toggle.GetComponentInChildren<TextMeshProUGUI>();
if (textMeshProUGUI != null && !selectedAnswers.Contains(textMeshProUGUI.text))
{
selectedAnswers.Add(textMeshProUGUI.text);
}
}
if (selectedAnswers.Count > 0)
{
MotionFramework.MotionEngine.GetModule<ProcessManager>().HandleClick(selectedAnswers);
SetQuestionData();
LoadTriggerNextGuide();
}
});
SetQuestionData();
}
/// <summary>
/// 加载触发下一步
/// </summary>
private void SetQuestionData()
{
if (step >= badBehaviorDatas.Count)
{
if (step == badBehaviorDatas.Count) transform.GetChild(0).gameObject.SetActive(false);
return;
}
questionStem.text = badBehaviorDatas[step].Question;
for (int i = 0; i < toggles.Count; i++)
{
toggles[i].isOn = false;
toggles[i].GetComponentInChildren<TextMeshProUGUI>().text = badBehaviorDatas[step].Options[i];
}
options.enabled = badBehaviorDatas[step].QuestionTypes.Equals(0) ? true : false;
questionTypes.text = badBehaviorDatas[step].QuestionTypes.Equals(0) ? "单选题" : "多选题";
step++;
}
}
/// <summary>
/// 不良行为数据
/// </summary>
public class BadBehaviorData
{
/// <summary>
/// 附件文件
/// </summary>
[JsonProperty("document")] public string Document;
/// <summary>
/// 题目类型
/// </summary>
[JsonProperty("questionTypes")] // 0 单选 1 多选
public int QuestionTypes;
/// <summary>
/// 题目
/// </summary>
[JsonProperty("question")] public string Question;
/// <summary>
/// 选项
/// </summary>
[JsonProperty("options")] public List<string> Options;
}