VirtualFramework/Assets/Scripts/UI/UIOperationList.cs
2024-12-20 10:31:29 +08:00

143 lines
5.3 KiB
C#

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);
}
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:
stepLabel.color = highColor;
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()
{
}
}
}