102 lines
3.5 KiB
C#
102 lines
3.5 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
using ZXKFramework;
|
|||
|
|
public class WorkBtn : UIBase
|
|||
|
|
{
|
|||
|
|
public override string Name => "WorkBtn";
|
|||
|
|
public override string GroupName => UIGroupLiao.WorkBtn.ToString();
|
|||
|
|
Dictionary<string, int> dic = new();
|
|||
|
|
GameModel gameModel;
|
|||
|
|
public List<Transform> btnList = new();
|
|||
|
|
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 (loData.ModuleName == gameModel.mainData.GetModuleName(gameModel.GetId()))
|
|||
|
|
{
|
|||
|
|
if (!string.IsNullOrEmpty(loData.SubModuleName))
|
|||
|
|
{
|
|||
|
|
if (!dic.ContainsKey(loData.SubModuleName))
|
|||
|
|
{
|
|||
|
|
dic.Add(loData.SubModuleName, loData.id);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
if(dic[loData.SubModuleName] > loData.id)
|
|||
|
|
{
|
|||
|
|
dic[loData.SubModuleName] = loData.id;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public override void Show()
|
|||
|
|
{
|
|||
|
|
base.Show();
|
|||
|
|
Transform loBenParent = transform.FindFirst<Transform>("WorkBtnData");
|
|||
|
|
Game.Instance.objectPool.Unspawn("SubModuleBtnBase");
|
|||
|
|
foreach (var item in dic)
|
|||
|
|
{
|
|||
|
|
Game.Instance.objectPool.Spawn("SubModuleBtnBase", loBenParent, m =>
|
|||
|
|
{
|
|||
|
|
btnList.Add(m.transform);
|
|||
|
|
m.transform.localScale = Vector3.one;
|
|||
|
|
m.FindFirst<Text>("Text").text = item.Key;
|
|||
|
|
Button loBtn = m.GetComponent<Button>();
|
|||
|
|
loBtn.onClick.RemoveAllListeners();
|
|||
|
|
loBtn.onClick.AddListener(() =>
|
|||
|
|
{
|
|||
|
|
//ȫ<><C8AB>id<69><64><EFBFBD><EFBFBD>
|
|||
|
|
gameModel.SetId(item.Value);
|
|||
|
|
//<2F>رո<D8B1><D5B8><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ
|
|||
|
|
uiManager.GetUI<ToolPanel>().CloseAllHighLightBtn();
|
|||
|
|
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģ<EFBFBD>鰴ť
|
|||
|
|
HighLightBtn(gameModel.mainData.GetSubModuleName(item.Value));
|
|||
|
|
Game.Instance.eventManager.Raise(new WorkBtnClipEvent() {
|
|||
|
|
id = item.Value,
|
|||
|
|
type = (EventType)System.Enum.Parse(typeof(EventType), gameModel.mainData.GetMessageType(item.Value)),
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
});
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void HighLightBtn(string value)
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < btnList.Count; i++)
|
|||
|
|
{
|
|||
|
|
if(value == btnList[i].FindFirst<Text>("Text").text)
|
|||
|
|
{
|
|||
|
|
btnList[i].FindFirst<Transform>("Select").gameObject.SetActive(true);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
btnList[i].FindFirst<Transform>("Select").gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public void CloseAllHighLightBtn()
|
|||
|
|
{
|
|||
|
|
for (int i = 0; i < btnList.Count; i++)
|
|||
|
|
{
|
|||
|
|
btnList[i].FindFirst<Transform>("Select").gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
public override void Hide()
|
|||
|
|
{
|
|||
|
|
base.Hide();
|
|||
|
|
dic.Clear();
|
|||
|
|
CloseAllHighLightBtn();
|
|||
|
|
btnList.Clear();
|
|||
|
|
}
|
|||
|
|
}
|