77 lines
2.5 KiB
C#
77 lines
2.5 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using ZXKFramework;
|
|
using UnityEngine.UI;
|
|
public class ModulePanel : UIBase
|
|
{
|
|
public override string Name => "ModulePanel";
|
|
public override string GroupName => UIGroupLiao.Main.ToString();
|
|
private Dictionary<string, int> dic = new();
|
|
private GameModel gameModel;
|
|
public override void HandleEvent(string name, object data){}
|
|
public override void Init(IUIManager uictrl)
|
|
{
|
|
base.Init(uictrl);
|
|
gameModel = GetModel<GameModel>();
|
|
}
|
|
public override void ShowData(params object[] obj)
|
|
{
|
|
base.ShowData(obj);
|
|
foreach (var loData in gameModel.mainData.GetMainDataList())
|
|
{
|
|
{
|
|
if (!dic.ContainsKey(loData.ModuleName))
|
|
{
|
|
dic.Add(loData.ModuleName, loData.id);
|
|
}
|
|
else
|
|
{
|
|
if (dic[loData.ModuleName] > loData.id)
|
|
{
|
|
dic[loData.ModuleName] = loData.id;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
//TestToString();
|
|
}
|
|
public override void Show()
|
|
{
|
|
base.Show();
|
|
transform.FindFirst<Text>("TitleText").text = LanguageTools.Get(1);
|
|
Transform loBenParent = transform.FindFirst<Transform>("ChoicePanel");
|
|
Game.Instance.objectPool.Unspawn("ModuleBtnBase");
|
|
foreach (var item in dic)
|
|
{
|
|
Game.Instance.objectPool.Spawn("ModuleBtnBase", loBenParent, m =>
|
|
{
|
|
m.transform.localScale = Vector3.one;
|
|
m.FindFirst<Text>("Text").text = item.Key;
|
|
Game.Instance.res.Load<Texture2D>(gameModel.mainData.GetModuleImagePath(item.Value), t => {
|
|
m.FindFirst<Image>("Image").sprite = UnityTools.ToSprite(t);
|
|
});
|
|
Button loBtn = m.GetComponent<Button>();
|
|
loBtn.onClick.RemoveAllListeners();
|
|
loBtn.onClick.AddListener(() =>
|
|
{
|
|
gameModel.SetId(item.Value);
|
|
Game.Instance.fsm.ChangeState<ModeSelectionState>();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
public override void Hide()
|
|
{
|
|
base.Hide();
|
|
dic.Clear();
|
|
}
|
|
void TestToString()
|
|
{
|
|
foreach (var item in dic)
|
|
{
|
|
Debug.Log(item.Key + "==" + item.Value);
|
|
}
|
|
}
|
|
}
|