少年修仙传客户端代码仓库
lcy
2024-12-16 a39c35fc6449430cd02bccb681c4a0a880e46cd9
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
using UnityEngine;
using UnityEngine.UI;
 
using System;
 
namespace vnxbqy.UI
{
    public class ComposeMatCell : MonoBehaviour
    {
        [SerializeField] Button selectBtn;
        [SerializeField] public ItemCell itemCell;
        [SerializeField] GameObject lockObj;
        [SerializeField] Text desText;
 
        NeedMatType matType = NeedMatType.Nothing;
        int itemId = 0;
        string matDes = string.Empty;
        public ItemModel itemModel { get; private set;}
        ItemCompoundConfig itemCompound;
        PackModel playerPack { get { return ModelCenter.Instance.GetModel<PackModel>(); } }
        
        SelectEquipModel selectModel {get { return ModelCenter.Instance.GetModel<SelectEquipModel>(); }}
        ComposeWinModel composeModel { get { return ModelCenter.Instance.GetModel<ComposeWinModel>(); } }
 
        private void OnEnable()
        {
            playerPack.itemCntReduceEvent += UpdateItemCount;
        }
 
        private void OnDisable()
        {
            playerPack.itemCntReduceEvent -= UpdateItemCount;
        }
 
        public void SetDisplay(ItemCompoundConfig _itemCompound,NeedMatType _matType,bool isLock,string des = "", int _itemId = 0,int _itemIndex = -1)
        {
            this.itemCompound = _itemCompound;
            var packType = composeModel.GetPackTypeByMakerId(itemCompound.makeID);
            this.itemModel = playerPack.GetItemByIndex(packType, _itemIndex);
            this.matType = _matType;
            this.itemId = _itemId;
            matDes = des;
            desText.SetActive(des != "" && !string.IsNullOrEmpty(des));
            desText.text = des;
            lockObj.SetActive(isLock);
            UpdateItemCell();
            UpdateMatCount();
            selectBtn.RemoveAllListeners();
            if(!isLock)
            {
                switch (matType)
                {
                    case NeedMatType.unfixedItem:
                    case NeedMatType.addItem:
                        selectBtn.AddListener(ClickSelect);
                        break;
                }
            }
        }
 
        private void UpdateItemCell()
        {
            bool isShowMat = itemId != 0 || itemModel != null ? true : false;
            itemCell.SetActive(isShowMat);
            if (isShowMat)
            {
                if (itemModel != null)
                {
                    itemCell.Init(itemModel);
                    itemCell.button.SetListener(ClickItemCell);
                }
                else
                {
 
                    ItemCellModel cellModel = new ItemCellModel(itemId);
                    itemCell.Init(cellModel);
                    itemCell.button.SetListener(ClickItemCell);
                }
 
                switch(matType)
                {
                    case NeedMatType.unfixedItem:
                    case NeedMatType.addItem:
                        itemCell.reducebtn.SetActive(true);
                        itemCell.reducebtn.SetListener(ClickReduce);
                        break;
                }
            }
        }
 
        private void UpdateMatCount()
        {
            switch (matType)
            {
                case NeedMatType.IncreaseItem:
                case NeedMatType.fixedItem:
                    int needCount = 0;
                    TryGetCountById(out needCount);
                    var packType = composeModel.GetPackTypeByMakerId(itemCompound.makeID);
                    int haveCount = playerPack.GetItemCountByID(packType, itemId);
                    itemCell.countText.SetActive(true);
                    if (haveCount >= needCount)
                    {
                        itemCell.countText.text = StringUtility.Contact(UIHelper.AppendColor(TextColType.Green, haveCount.ToString()),
                            "/", needCount);
                    }
                    else
                    {
                        itemCell.countText.text = StringUtility.Contact(UIHelper.AppendColor(TextColType.Red, haveCount.ToString()),
                            "/", needCount);
                    }
                    break;
                case NeedMatType.unfixedItem:
                case NeedMatType.Nothing:
                case NeedMatType.MakeItem:
                case NeedMatType.addItem:
                    itemCell.countText.SetActive(false);
                    break;
            }
        }
        
        private bool TryGetCountById(out int itemCount)
        {
            itemCount = 0;
            if (itemCompound == null) return false;
 
            switch (matType)
            {
                case NeedMatType.IncreaseItem:
                    int[] increases = itemCompound.successRateIncrease;
                    if(increases != null && increases.Length >= 3)
                    {
                        itemCount = increases[1];
                        return true;
                    }
                    break;
                case NeedMatType.fixedItem:
                    int[] fixedIds = itemCompound.itemID;
                    int[] fixedCounts = itemCompound.itemCount;
                    if (fixedIds != null)
                    {
                        for(int i = 0; i < fixedIds.Length; i++)
                        {
                            if(fixedIds[i] == itemId)
                            {
                                itemCount = fixedCounts[i];
                                return true;
                            }
                        }
                    }
                    break;
            }
            return false;
        }
 
        private void ClickItemCell()
        {
            ItemConfig itemConfig = ItemConfig.Get(itemId);
            switch (matType)
            {
                case NeedMatType.IncreaseItem:
                case NeedMatType.fixedItem:
                    if (itemConfig.GetWay != null && itemConfig.GetWay.Length > 0)
                    {
                        ItemTipUtility.Show(itemId);
                        return;
                    }
                    break;
 
            }
 
            if (itemModel == null)
            {
                ItemTipUtility.Show(itemId);
            }
            else
            {
                ItemTipUtility.Show(itemModel.guid);
            }
        }
 
        private void ClickSelect()
        {
            selectModel.SetSelectMatCell(this);
            switch (matType)
            {
                case NeedMatType.unfixedItem:
                    selectModel.selectItem = SelectItemType.unfixed;
                    break;
                case NeedMatType.addItem:
                    selectModel.selectItem = SelectItemType.addons;
                    break;
            }
            WindowCenter.Instance.Open<SelectItemWin>();
        }
 
        private void UpdateItemCount(PackType type, int index, int id)
        {
            if (itemModel == null) return;
            
            if(itemModel.packType == type 
                && itemModel.gridIndex == index
                && itemModel.itemId == id)
            {
                ClickReduce();
            }
        }
 
        private void ClickReduce()
        {
            if (itemModel == null) return;
 
            switch (matType)
            {
                case NeedMatType.unfixedItem:
                    selectModel.RemoveHaveUnfixedSelectItem(itemModel.gridIndex);
                    break;
                case NeedMatType.addItem:
                    selectModel.RemoveHaveAddSelectItem(itemModel.gridIndex);
                    break;
            }
            composeModel.UpdateReduce(this,matType);
        }
    }
}