少年修仙传客户端代码仓库
hch
2023-06-14 f23c81d21c9cc4c9f06e8bed3ebb7ddbe7e15ac3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
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);
            }
        }
    }
}