166 lines
6.2 KiB
C#
166 lines
6.2 KiB
C#
using UnityEngine;
|
||
using UnityEngine.UI;
|
||
using XMLTool;
|
||
using TMPro;
|
||
using System.Collections.Generic;
|
||
using static OperationController;
|
||
namespace QFramework.Example
|
||
{
|
||
public class UIOperationListData : UIPanelData
|
||
{
|
||
}
|
||
public partial class UIOperationList : UIPanel
|
||
{
|
||
Operation op;
|
||
List<Button> btns = new List<Button>();
|
||
|
||
protected override void OnInit(IUIData uiData = null)
|
||
{
|
||
mData = uiData as UIOperationListData ?? new UIOperationListData();
|
||
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||
}
|
||
|
||
private void OnStepChanged(StepStatusOnChange change)
|
||
{
|
||
ResetBtnStatus(change.curIndex, change.status);
|
||
}
|
||
|
||
public void ResetBtnStatus(int index, OperationController.StepStatus status)
|
||
{
|
||
Button btn = btns[index];
|
||
bool isParent = btn.transform.Find("StepLabel") == null;
|
||
Color highColor = new Color(25f / 255f, 224f / 255f, 224f / 255f);
|
||
if (isParent)
|
||
{
|
||
var name = btn.transform.Find("Name").GetComponent<TextMeshProUGUI>();
|
||
var arrow = btn.transform.Find("Arrow").transform;
|
||
Image highIcon = btn.transform.Find("HighIcon").GetComponent<Image>();
|
||
switch (status)
|
||
{
|
||
case StepStatus.NoStart:
|
||
name.color = Color.white;
|
||
highIcon.color = Color.white;
|
||
arrow.eulerAngles = new Vector3(0, 0, 90);
|
||
break;
|
||
case StepStatus.Start:
|
||
case StepStatus.Finished:
|
||
name.color = highColor;
|
||
highIcon.color = highColor;
|
||
arrow.eulerAngles = Vector3.zero;
|
||
break;
|
||
}
|
||
}
|
||
else
|
||
{
|
||
var stepLabel = btn.transform.Find("StepLabel").GetComponent<TextMeshProUGUI>();
|
||
switch (status)
|
||
{
|
||
case StepStatus.NoStart:
|
||
stepLabel.color = Color.white;
|
||
break;
|
||
case StepStatus.Start:
|
||
stepLabel.color = highColor;
|
||
btn.transform.parent.gameObject.SetActive(true);
|
||
break;
|
||
case StepStatus.Finished:
|
||
// TODO<44><4F>ʵ<EFBFBD>ַ<EFBFBD>ʽ<EFBFBD><CABD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>Ż<EFBFBD>
|
||
if (Global.Instance.curModule.type == "Exam")
|
||
{
|
||
stepLabel.color = highColor;
|
||
}
|
||
else
|
||
{
|
||
stepLabel.color = Color.white;
|
||
}
|
||
break;
|
||
}
|
||
}
|
||
}
|
||
|
||
protected override void OnOpen(IUIData uiData = null)
|
||
{
|
||
TypeEventSystem.Global.Register<OnOperationChanged>((arg) => Refresh());
|
||
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(this);
|
||
|
||
}
|
||
|
||
public void Refresh()
|
||
{
|
||
btns.Clear();
|
||
op = OperationController.Instance.operation;
|
||
StepContent.RemoveAllChildren();
|
||
foreach (var item in op.Steps)
|
||
{
|
||
|
||
if (item.SubSteps != null && item.SubSteps.Count > 0)
|
||
{
|
||
GameObject obj = GameObject.Instantiate(Step.gameObject, StepContent);
|
||
Transform title = obj.transform.Find("Title");
|
||
var name = title.Find("Name").GetComponent<TextMeshProUGUI>();
|
||
name.text = item.Name;
|
||
Image highIcon = title.Find("HighIcon").GetComponent<Image>();
|
||
Color highColor = new Color(25f / 255f, 224f / 255f, 224f / 255f);
|
||
GameObject subContent = obj.transform.Find("SubContent").gameObject;
|
||
Button btn = title.GetComponent<Button>();
|
||
subContent.gameObject.SetActive(false);
|
||
btn.name = btns.Count.ToString();
|
||
btns.Add(btn);
|
||
btn.onClick.AddListener(() =>
|
||
{
|
||
subContent.SetActive(!subContent.activeSelf);
|
||
if (op.freeStep)
|
||
{
|
||
if (highIcon.color != highColor)
|
||
{
|
||
TypeEventSystem.Global.Send<StepExecute>(new StepExecute() { index = int.Parse(btn.name) });
|
||
}
|
||
}
|
||
});
|
||
foreach (var sub in item.SubSteps)
|
||
{
|
||
StepItemFactory(subContent.transform, sub.Name);
|
||
}
|
||
}
|
||
else
|
||
{
|
||
StepItemFactory(StepContent, item.Name);
|
||
}
|
||
}
|
||
}
|
||
|
||
|
||
public void StepItemFactory(Transform content, string txt)
|
||
{
|
||
GameObject subObj = GameObject.Instantiate(SubStep.gameObject, content.transform);
|
||
var stepLabel = subObj.transform.Find("StepLabel").GetComponent<TextMeshProUGUI>();
|
||
stepLabel.text = txt;
|
||
Button subBtn = subObj.GetComponent<Button>();
|
||
subBtn.name = btns.Count.ToString();
|
||
btns.Add(subBtn);
|
||
subBtn.onClick.AddListener(() =>
|
||
{
|
||
if (op.freeStep)
|
||
{
|
||
subBtn.transform.parent.gameObject.SetActive(true);
|
||
TypeEventSystem.Global.Send<StepExecute>(new StepExecute() { index = int.Parse(subBtn.name) });
|
||
}
|
||
});
|
||
}
|
||
|
||
protected override void OnShow()
|
||
{
|
||
Refresh();
|
||
}
|
||
protected override void OnClose()
|
||
{
|
||
TypeEventSystem.Global.UnRegister<OnOperationChanged>((arg) => Refresh());
|
||
}
|
||
|
||
public override void Hide()
|
||
{
|
||
base.Hide();
|
||
TypeEventSystem.Global.UnRegister<OnOperationChanged>((arg) => Refresh());
|
||
}
|
||
}
|
||
}
|