166 lines
5.9 KiB
C#
166 lines
5.9 KiB
C#
using Newtonsoft.Json;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using static LYTWebGLHelper;
|
|
|
|
namespace QFramework.Example
|
|
{
|
|
public class UIScoreData : UIPanelData
|
|
{
|
|
/// <summary>
|
|
/// 只显示当前模块的评分
|
|
/// </summary>
|
|
public bool onlyCurModule = false;
|
|
}
|
|
public partial class UIScore : UIPanel
|
|
{
|
|
protected override void OnInit(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UIScoreData ?? new UIScoreData();
|
|
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
|
DownLoad.onClick.AddListener(() =>
|
|
{
|
|
if (string.IsNullOrEmpty(InputName.text) || string.IsNullOrEmpty(InputId.text))
|
|
{
|
|
UITipWindowData data = new UITipWindowData();
|
|
data.txt = "姓名或者学号为空";
|
|
data.btns.Add(new UITipWindowData.ItemData() { txt = "确定" });
|
|
UIKit.OpenPanelAsync<UITipWindow>(canvasLevel: UILevel.PopUI, uiData: data).ToAction().Start(this);
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
#if UNITY_WEBGL&&!UNITY_EDITOR
|
|
ResLoader loader = ResLoader.Allocate();
|
|
loader.Add2Load(Global.reportDemoPath.ToLocalBytesResName(), (success, res) =>
|
|
{
|
|
if (success)
|
|
{
|
|
byte[] bytes = res.As<LocalBytesRes>().bytes;
|
|
WebGLDownLoadFile.Instance.DownloadDocx(bytes, GetScoreDataJson());
|
|
|
|
}
|
|
});
|
|
loader.LoadAsync();
|
|
#elif UNITY_STANDALONE_WIN||UNITY_EDITOR
|
|
DownLoad.interactable = false;
|
|
AsposeHelper.Writer(GetScoreDataJson(), () =>
|
|
{
|
|
DownLoad.interactable = true;
|
|
});
|
|
#endif
|
|
|
|
|
|
});
|
|
Confirm.onClick.AddListener(Hide);
|
|
}
|
|
|
|
public string GetScoreDataJson()
|
|
{
|
|
return ScoreController.Instance.GetModuleDictJson(InputName.text, InputId.text, this.Sum.text);
|
|
}
|
|
|
|
|
|
protected override void OnOpen(IUIData uiData = null)
|
|
{
|
|
mData = uiData as UIScoreData ?? new UIScoreData();
|
|
|
|
Content.RemoveAllChildren();
|
|
|
|
float sum = 0;
|
|
float score = 0;
|
|
|
|
bool onlyCur = false;
|
|
if (uiData == null)
|
|
{
|
|
if (bool.TryParse(Global.Instance.curModule.OnlyCurScore, out onlyCur) == false)
|
|
{
|
|
onlyCur = false;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
onlyCur = mData.onlyCurModule;
|
|
}
|
|
|
|
|
|
List<Expstepvtwolist> datas = new List<Expstepvtwolist>();
|
|
int seq = 1;
|
|
if (onlyCur)
|
|
{
|
|
foreach (var item in ScoreController.Instance.GetCurScoreData())
|
|
{
|
|
GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content);
|
|
obj.transform.Find("Step").GetComponent<TextMeshProUGUI>().text = item.Value.step;
|
|
obj.transform.Find("Name").GetComponent<TextMeshProUGUI>().text = item.Value.name;
|
|
obj.transform.Find("Sum").GetComponent<TextMeshProUGUI>().text = item.Value.sum;
|
|
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
|
|
sum += float.Parse(item.Value.sum);
|
|
score += item.Value.value;
|
|
datas.Add(new Expstepvtwolist()
|
|
{
|
|
ExpStepName = item.Value.step + item.Value.name,
|
|
maxScore = int.Parse(item.Value.sum),
|
|
score = (int)item.Value.value,
|
|
startTime = item.Value.time,
|
|
endTime = item.Value.time,
|
|
seq = seq,
|
|
StepState = (int)item.Value.value == float.Parse(item.Value.sum) ? "全部正确" : "有错误"
|
|
});
|
|
seq++;
|
|
}
|
|
}
|
|
else
|
|
{
|
|
foreach (var moduleDict in ScoreController.Instance.moduleDict)
|
|
{
|
|
foreach (var item in moduleDict.Value.scoreDict)
|
|
{
|
|
GameObject obj = GameObject.Instantiate(ItemPrefab.gameObject, Content);
|
|
obj.transform.Find("Step").GetComponent<TextMeshProUGUI>().text = item.Value.step;
|
|
obj.transform.Find("Name").GetComponent<TextMeshProUGUI>().text = item.Value.name;
|
|
obj.transform.Find("Sum").GetComponent<TextMeshProUGUI>().text = item.Value.sum;
|
|
obj.transform.Find("Score").GetComponent<TextMeshProUGUI>().text = item.Value.value.ToString();
|
|
sum += float.Parse(item.Value.sum);
|
|
score += item.Value.value;
|
|
datas.Add(new Expstepvtwolist()
|
|
{
|
|
ExpStepName = item.Value.step + item.Value.name,
|
|
maxScore = int.Parse(item.Value.sum),
|
|
score = (int)item.Value.value,
|
|
startTime = item.Value.time,
|
|
endTime = item.Value.time,
|
|
seq = seq
|
|
});
|
|
seq++;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
this.Score.text = score.ToString();
|
|
this.Sum.text = sum.ToString();
|
|
|
|
#if UNITY_WEBGL
|
|
|
|
LYTWebGLHelper.Instance.UpLoadData((int)score, datas.ToArray());
|
|
#endif
|
|
}
|
|
|
|
protected override void OnShow()
|
|
{
|
|
}
|
|
|
|
protected override void OnHide()
|
|
{
|
|
}
|
|
|
|
protected override void OnClose()
|
|
{
|
|
}
|
|
}
|
|
}
|