CTT/Unity/Assets/HotfixView/Event/UI/UpdateMainUISlotEvent.cs

79 lines
3.4 KiB
C#

using ET;
using FairyGUI;
using Cal.DataTable;
using System.Collections.Generic;
using ET.EventType;
namespace ET
{
public class UpdateMainUISlotEvent : AEvent<UpdateMainUISlot>
{
public override async ETTask Run(UpdateMainUISlot args)
{
FUI_MainUI ui = FUIComponent.Instance.Get(FUIPackage.Common_MainUI) as FUI_MainUI;
MainUISlotComponent mainuiSlotComponent = ui.GetComponent<MainUISlotComponent>();
if (!mainuiSlotComponent.isInit)
{
mainuiSlotComponent.isInit = true;
InitMainUISlot(ui, mainuiSlotComponent);
}
foreach (MainUISlotInfo mainUISlotInfo in args.list)
{
int index = mainUISlotInfo.Index;
GButton btn = ui.m_mainUISlotList.GetChildAt(index).asButton;
MainUISlot mainUISlot = MainUISlotComponent.Instance.Get(index);
FUI_ButtonMianUISlot fui = mainUISlot.FUI_Btn;
mainUISlot.slotState = MainUISlotComponent.SlotState.Common;
mainUISlot.MainUISlotId = mainUISlotInfo.Id;
mainUISlot.MainUIType = mainUISlotInfo.MainUIType;
mainUISlot.SkillLevel = mainUISlotInfo.Level;
mainUISlot.ItemCount = mainUISlotInfo.ItemCount;
switch (mainUISlotInfo.MainUIType)
{
case MainUIType.NoneSlot:
btn.icon = null;
btn.text = null;
fui.m_imgMask.fillAmount = 0;
break;
case MainUIType.SkillSlot:
int skillId = mainUISlotInfo.Id;
btn.icon = UIPackage.GetItemURL(FUIPackage.Skill, skillId.ToString());
fui.m_imgMask.fillAmount = 0;
break;
case MainUIType.ItemSlot:
GoodsBase goodsbase = DataTableHelper.Get<GoodsBase>(mainUISlot.MainUISlotId);
if (goodsbase == null)
{
Log.Error("goodsbase==null");
return;
}
btn.icon = UIPackage.GetItemURL(FUIPackage.Bag, goodsbase.IconName.ToString());
btn.text = mainUISlot.ItemCount.ToString();
fui.m_imgMask.fillAmount = 0;
break;
}
}
}
private void InitMainUISlot(FUI_MainUI ui, MainUISlotComponent mainuiSlotComponent)
{
for (int i = 0; i < ui.m_mainUISlotList.numChildren; i++)
{
GButton btn = ui.m_mainUISlotList.GetChildAt(i).asButton;
FUI_ButtonMianUISlot _fui = FUI_ButtonMianUISlot.GetFormPool(ui, btn);
MainUISlot mainUISlot = EntityFactory.CreateWithParent<MainUISlot, FUI_ButtonMianUISlot>(mainuiSlotComponent, _fui);
mainUISlot.slotState = MainUISlotComponent.SlotState.Common;
mainUISlot.FUI_Btn.m_imgMask.fillAmount = 0;
mainUISlot.MainUISlotId = 0;
mainUISlot.MainUIType = MainUIType.NoneSlot;
mainUISlot.SkillLevel = 0;
mainUISlot.ItemCount = 0;
mainuiSlotComponent.UpdateMainUISlot(i, mainUISlot);
}
}
}
}