using System;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
|
namespace Snxxz.UI
|
{
|
public class XBGridCell : MonoBehaviour
|
{
|
[SerializeField] ItemCell itemCell;
|
PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
|
HappyXBModel XBModel { get { return ModelCenter.Instance.GetModel<HappyXBModel>(); } }
|
int index = 0;
|
public void OnEnable()
|
{
|
playerPack.refreshItemCountEvent += RefreshItemCount;
|
}
|
|
public void OnDisable()
|
{
|
playerPack.refreshItemCountEvent -= RefreshItemCount;
|
}
|
|
public void SetModel(string guid,int index)
|
{
|
this.index = index;
|
ItemModel itemModel = playerPack.GetItemByGuid(guid);
|
if(itemModel != null)
|
{
|
itemCell.SetActive(true);
|
itemCell.Init(itemModel);
|
itemCell.button.RemoveAllListeners();
|
itemCell.button.AddListener(() => { ClickItemCell(itemModel); });
|
}
|
else
|
{
|
itemCell.SetActive(false);
|
}
|
}
|
|
private void ClickItemCell(ItemModel itemModel)
|
{
|
if(itemModel.config.Type == 30 || itemModel.config.Type == 31)
|
{
|
if (XBModel.CheckIsEmptyGrid(PackType.RunePack))
|
{
|
XBModel.SendPutOutXBItem(PackType.Treasure, PackType.RunePack, itemModel.gridIndex, 0);
|
}
|
}
|
else
|
{
|
if (XBModel.CheckIsEmptyGrid(PackType.Item))
|
{
|
XBModel.SendPutOutXBItem(PackType.Treasure, PackType.Item, itemModel.gridIndex, 0);
|
}
|
}
|
}
|
|
private void RefreshItemCount(PackType type, int index, int id)
|
{
|
if (type != PackType.Treasure || this.index != index) return;
|
|
ItemModel itemModel = playerPack.GetItemByIndex(type,index);
|
if(itemModel != null)
|
{
|
SetModel(itemModel.guid,index);
|
}
|
else
|
{
|
SetModel("",index);
|
}
|
}
|
}
|
}
|