QingGangLongGu/Assets/_Scripts/Application/UI/ModeSelectionPanel.cs

77 lines
3.0 KiB
C#
Raw Normal View History

2025-03-11 15:30:07 +08:00
using UnityEngine;
using UnityEngine.UI;
using ZXKFramework;
public class ModeSelectionPanel : UIBase
{
public override string Name => "ModeSelectionPanel";
public override string GroupName => UIGroupLiao.Main.ToString();
GameModel gameModel;
Transform choicePanel;
public override void HandleEvent(string name, object data){}
public override void Init(IUIManager uictrl)
{
base.Init(uictrl);
gameModel = GetModel<GameModel>();
choicePanel = transform.FindFirst<Transform>("ChoicePanel");
}
public override void Show()
{
base.Show();
transform.FindFirst<Text>("TitleText").text = gameModel.mainData.GetModuleName(gameModel.GetId());
string[] md = gameModel.mainData.GetModeGroup(gameModel.GetId());
for (int i = 0; i < choicePanel.childCount; i++)
{
Button btn = choicePanel.GetChild(i).GetComponent<Button>();
btn.onClick.RemoveAllListeners();
switch (btn.name)
{
case "LYBtn":
if (!string.IsNullOrEmpty(md[0]))
{
btn.transform.FindFirst<Text>("Text").text = md[0];
btn.gameObject.SetActive(true);
btn.onClick.AddListener(() => {
gameModel.SetModeType(ModeType.LiuLan);
Game.Instance.fsm.ChangeState<MainState>();
});
}
else
{
btn.gameObject.SetActive(false);
}
break;
case "SXBtn":
if (!string.IsNullOrEmpty(md[1]))
{
btn.transform.FindFirst<Text>("Text").text = md[1];
btn.gameObject.SetActive(true);
btn.onClick.AddListener(() => {
gameModel.SetModeType(ModeType.ShiXun);
Game.Instance.fsm.ChangeState<MainState>();
});
}
else
{
btn.gameObject.SetActive(false);
}
break;
case "KHBtn":
if (!string.IsNullOrEmpty(md[2]))
{
btn.transform.FindFirst<Text>("Text").text = md[2];
btn.gameObject.SetActive(true);
btn.onClick.AddListener(() => {
gameModel.SetModeType(ModeType.KaoHe);
Game.Instance.fsm.ChangeState<MainState>();
});
}
else
{
btn.gameObject.SetActive(false);
}
break;
}
}
}
}