VirtualFramework/Assets/Scripts/UI/UIOperationList.cs
2025-01-09 09:43:15 +08:00

152 lines
5.7 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

using UnityEngine;
using UnityEngine.UI;
using QFramework;
using XMLTool;
using UnityEditor.Rendering;
using TMPro;
using System.Collections.Generic;
using static OperationController;
using System;
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<StepStatusOnChange>(OnStepChanged);
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)
{
op = OperationController.Instance.operation;
StepContent.RemoveAllChildren();
foreach (var item in op.Steps)
{
GameObject obj = GameObject.Instantiate(Step.gameObject, StepContent);
Transform title = obj.transform.Find("Title");
var name = title.Find("Name").GetComponent<TextMeshProUGUI>();
name.text = item.Name;
var arrow = title.Find("Arrow").transform;
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) });
}
}
});
if (item.SubSteps != null)
{
foreach (var sub in item.SubSteps)
{
GameObject subObj = GameObject.Instantiate(SubStep.gameObject, subContent.transform);
var stepLabel = subObj.transform.Find("StepLabel").GetComponent<TextMeshProUGUI>();
stepLabel.text = sub.Name;
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()
{
}
protected override void OnHide()
{
}
protected override void OnClose()
{
}
}
}