278 lines
11 KiB
C#
278 lines
11 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using ZXK.Framework;
|
|
using ZXK.UTility;
|
|
using DG.Tweening;
|
|
/*******************************************************************************
|
|
*Create By CG
|
|
*Function 训练模式UI上所有数据显示
|
|
*******************************************************************************/
|
|
namespace ZXK.ZPS
|
|
{
|
|
public class DataUICtrl : MonoBehaviour
|
|
{
|
|
[SerializeField]
|
|
private Transform _firstContainerTran = null;
|
|
[SerializeField]
|
|
private GameObject _firstItemPrefab = null;
|
|
[SerializeField]
|
|
private UISecondPanelCtrl _secondPanelCtrl = null;
|
|
[SerializeField]
|
|
private UIToolPanelCtrl _toolPanelCtrl = null;
|
|
//[SerializeField]
|
|
//private Button _saveBtn = null;
|
|
[SerializeField]
|
|
private Button _submintBtn = null;
|
|
[SerializeField]
|
|
private Text _timeCountTxt = null;
|
|
|
|
private const int _timeCount = 3600;//倒计时60分钟
|
|
|
|
private void Awake()
|
|
{
|
|
GameRoot.Instance._DataUICtrl = this;
|
|
}
|
|
private void Start()
|
|
{
|
|
switch (GameRoot.Instance._CurType)
|
|
{
|
|
case UTility.EnumCtrl.Type.None:
|
|
break;
|
|
case UTility.EnumCtrl.Type.WQB:
|
|
InitTrainData(GameRoot.Instance.DataWQBArray);
|
|
break;
|
|
case UTility.EnumCtrl.Type.DHB:
|
|
InitTrainData(GameRoot.Instance.DataDHBArray);
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
AllowToolSubmin(false);
|
|
if (GameRoot.Instance._CurModel == EnumCtrl.Model.Exam)
|
|
{
|
|
//_saveBtn.gameObject.SetActive(true);
|
|
//_saveBtn.onClick.AddListener(() =>
|
|
//{
|
|
// PopUpMng.PopConBox("提示", $"提交{GameRoot.Instance._CurFirstProcess}的成绩", "确定", ()=> {
|
|
|
|
// GameRoot.Instance._ExamMng.SaveFirstProExamData();
|
|
// foreach (Transform item in _firstContainerTran)
|
|
// {
|
|
// if (item.name.Equals(GameRoot.Instance._CurFirstProcess))
|
|
// {
|
|
// item.GetComponent<Toggle>().interactable = false;
|
|
// //item.gameObject.SetActive(false);
|
|
// }
|
|
// }
|
|
// });
|
|
//});
|
|
_submintBtn.gameObject.SetActive(true);
|
|
_submintBtn.onClick.AddListener(() =>
|
|
{
|
|
//string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, ConstCtrl.DATA_ExamResult_PATH);
|
|
//string examReslutStr = TxtFileHandle.ReadAllTxt(filePath);
|
|
//string examReslutStr = TxtFileHandle.ReadAllTxtByResource(ConstCtrl.DATA_ExamResult_PATH);
|
|
string examReslutStr = TxtFileHandle.ReadAllTxtByPrefs(ConstCtrl.DATA_ExamResult_Key);
|
|
if (string.IsNullOrEmpty(examReslutStr))
|
|
{
|
|
PopUpMng.PopToast("提示", "没有考试数据,无效提交", "确定", null);
|
|
}
|
|
else
|
|
{
|
|
PopUpMng.PopConBox("提示", "是否查看成绩报告", "确定", () => {
|
|
GameRoot.Instance._ExamMng.SaveAllExamData();
|
|
Debug.Log("成绩报告");
|
|
});
|
|
}
|
|
});
|
|
|
|
_timeCountTxt.transform.parent.gameObject.SetActive(true);
|
|
int curTime = _timeCount;
|
|
DOTween.To(() => curTime, x => curTime = x, _timeCount - 1, 1).SetLoops(-1, LoopType.Incremental)
|
|
.OnStepComplete(() =>
|
|
{
|
|
//Debug.Log("c:" + curTime);
|
|
_timeCountTxt.text = $"{curTime / 60}:{curTime % 60}";
|
|
}).OnComplete(() =>
|
|
{
|
|
SaveLookData();
|
|
});
|
|
|
|
}
|
|
else
|
|
{
|
|
//_saveBtn.gameObject.SetActive(false);
|
|
_submintBtn.gameObject.SetActive(false);
|
|
_timeCountTxt.transform.parent.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
//private void Update()
|
|
//{
|
|
// if (string.IsNullOrEmpty(GameRoot.Instance._CurFirstProcess))
|
|
// {
|
|
// _saveBtn.interactable = false;
|
|
// }
|
|
// else
|
|
// {
|
|
// _saveBtn.interactable = true;
|
|
// }
|
|
//}
|
|
public void SaveLookData()
|
|
{
|
|
//string filePath = System.IO.Path.Combine(Application.streamingAssetsPath, ConstCtrl.DATA_ExamResult_PATH);
|
|
//string examReslutStr = TxtFileHandle.ReadAllTxt(filePath);
|
|
//string examReslutStr = TxtFileHandle.ReadAllTxtByResource(ConstCtrl.DATA_ExamResult_PATH);
|
|
string examReslutStr = TxtFileHandle.ReadAllTxtByPrefs(ConstCtrl.DATA_ExamResult_Key);
|
|
if (string.IsNullOrEmpty(examReslutStr))
|
|
{
|
|
PopUpMng.PopToast("提示", "没有考试数据,请退出", "退出", null);
|
|
}
|
|
else
|
|
{
|
|
//PopUpMng.PopConBox("提示", $"提交{GameRoot.Instance._CurFirstProcess}的成绩", "确定", () => {
|
|
|
|
GameRoot.Instance._ExamMng.SaveFirstProExamData();
|
|
PopUpMng.PopConBox("提示", "是否查看成绩报告", "确定", () => {
|
|
GameRoot.Instance._ExamMng.SaveAllExamData();
|
|
Debug.Log("成绩报告");
|
|
});
|
|
//});
|
|
}
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// 初始化训练数据
|
|
/// </summary>
|
|
/// <param name="firstProcessInfo">对应种类的工序数据</param>
|
|
private void InitTrainData(Dictionary<string, Dictionary<string, DataItemModel>> firstProcessInfo)
|
|
{
|
|
List<string> tools = new List<string>();
|
|
foreach (string firstItem in firstProcessInfo.Keys)
|
|
{
|
|
GameObject firstItemGeo = Instantiate(_firstItemPrefab, _firstContainerTran);
|
|
UIFirstItemCtrl firstItemCtrl = firstItemGeo.GetComponent<UIFirstItemCtrl>();
|
|
firstItemGeo.GetComponent<Toggle>().group = _firstContainerTran.GetComponent<ToggleGroup>();
|
|
firstItemCtrl.InitFirstItem(firstItem, firstProcessInfo[firstItem], _secondPanelCtrl);
|
|
|
|
//获取所有工具
|
|
if (!firstItem.Equals(ConstCtrl.DATA_NOGETTOOL_NAME1) &&
|
|
!firstItem.Equals(ConstCtrl.DATA_NOGETTOOL_NAME2))
|
|
{
|
|
foreach (string secondItem in firstProcessInfo[firstItem].Keys)
|
|
{
|
|
string[] secondUseTools = firstProcessInfo[firstItem][secondItem].Tools;
|
|
for (int i = 0; i < secondUseTools.Length; i++)
|
|
{
|
|
if (!tools.Contains(secondUseTools[i])&&!string.IsNullOrEmpty(secondUseTools[i]))
|
|
{
|
|
tools.Add(secondUseTools[i]);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
_toolPanelCtrl.CreateToolItem(tools);
|
|
}
|
|
|
|
public void OpenTool(string[] tools = null)
|
|
{
|
|
_toolPanelCtrl.OpenTool(tools);
|
|
}
|
|
public void AllowToolSubmin(bool allow)
|
|
{
|
|
_toolPanelCtrl.AllowSubminTool(allow);
|
|
}
|
|
|
|
public List<string> GetSelectTools()
|
|
{
|
|
return _toolPanelCtrl.GetSelectTool();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 获取二级工序顺序
|
|
/// </summary>
|
|
public List<string> GetSecondProcessOrder()
|
|
{
|
|
return _secondPanelCtrl.GetItemOrder();
|
|
}
|
|
//public void CloseTool()
|
|
//{
|
|
// _toolPanelCtrl.CloseTool();
|
|
//}
|
|
public void NextProcess()
|
|
{
|
|
int secondIndex = int.Parse(GameRoot.Instance._TrainMng._CurTrainInfo.ID.Split('-')[2]);
|
|
string firstName = GameRoot.Instance._CurFirstProcess;
|
|
Dictionary<string, Dictionary<string, DataItemModel>> curTypeDic = new Dictionary<string, Dictionary<string, DataItemModel>>();
|
|
|
|
switch (GameRoot.Instance._CurType)
|
|
{
|
|
case UTility.EnumCtrl.Type.None:
|
|
break;
|
|
case UTility.EnumCtrl.Type.WQB:
|
|
if (GameRoot.Instance.DataWQBArray.ContainsKey(firstName))
|
|
{
|
|
curTypeDic = GameRoot.Instance.DataWQBArray;
|
|
}
|
|
break;
|
|
case UTility.EnumCtrl.Type.DHB:
|
|
if (GameRoot.Instance.DataDHBArray.ContainsKey(firstName))
|
|
{
|
|
curTypeDic = GameRoot.Instance.DataDHBArray;
|
|
}
|
|
break;
|
|
}
|
|
|
|
if (curTypeDic[firstName].Count == (secondIndex + 1))
|
|
{
|
|
//跳转到下一个一级工序
|
|
int index = 0;
|
|
foreach (var item in curTypeDic)
|
|
{
|
|
if (item.Key.Equals(GameRoot.Instance._CurFirstProcess))
|
|
{
|
|
index++;
|
|
continue;
|
|
}
|
|
if (index == 1)
|
|
{
|
|
GameRoot.Instance._CurFirstProcess = item.Key;
|
|
index = 0;
|
|
break;
|
|
}
|
|
}
|
|
foreach (Transform item in _firstContainerTran)
|
|
{
|
|
if (item.name.Equals(GameRoot.Instance._CurFirstProcess))
|
|
{
|
|
item.GetComponent<UIFirstItemCtrl>().SetToggerShow();
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
//跳转到下一个二级工序
|
|
int index = 0;
|
|
foreach (var item in curTypeDic[firstName])
|
|
{
|
|
if (item.Key.Equals(GameRoot.Instance._CurSecondProcess))
|
|
{
|
|
index++;
|
|
continue;
|
|
}
|
|
if (index == 1)
|
|
{
|
|
GameRoot.Instance._NextSecondProcess = item.Key;
|
|
index = 0;
|
|
break;
|
|
}
|
|
}
|
|
_secondPanelCtrl.SetNextSecondProcess();
|
|
}
|
|
}
|
|
}
|
|
} |