少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-25 cdb0198fb8e85811ec1e06b15f36df9cbe0fdb9a
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
226
227
228
229
230
231
232
233
234
235
236
237
238
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Wednesday, September 13, 2017
//--------------------------------------------------------
 
using Snxxz.UI;
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
//装备捐献面板
namespace Snxxz.UI
{
 
    public class DonateEquipTipsWin : Window
    {
        [SerializeField] ScrollerController _GridlineCtrl;
        [SerializeField] Button _CloseBtn;
 
        ItemTipsModel _itemTipsModel;
        ItemTipsModel itemTipsModel { get { return _itemTipsModel ?? (_itemTipsModel = ModelCenter.Instance.GetModel<ItemTipsModel>()); } }
 
        PackModel _playerPack;
        PackModel playerPack { get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PackModel>()); } }
        PlayerFairyAuTreasureData m_PlayerFairyAuTreasureData;
        PlayerFairyAuTreasureData playerFairyAuTreasureData { get { return m_PlayerFairyAuTreasureData ?? (m_PlayerFairyAuTreasureData = ModelCenter.Instance.GetModel<PlayerFairyAuTreasureData>()); } }
        private int _BagIndex = 0;//标记背包物品下标
 
        private int MaxDonationAmount = 0;//最大捐献数量
        List<string> phagocytosisID = new List<string>();//存储可以捐献的物品
 
        #region Built-in
        protected override void BindController()
        {
            MaxDonationAmount = int.Parse(FuncConfigConfig.Get("FamilyStoreSpace").Numerical1)+1;
        }
 
        protected override void AddListeners()
        {
            _CloseBtn.onClick.AddListener(CloseButton);
        }
 
        protected override void OnPreOpen()
        {
            playerPack.refreshItemCountEvent += BackpackRefresh;//背包物品清理
            _GridlineCtrl.OnRefreshCell += OnRefreshGridCell;
            Backpacking();//背包物品读取和创建
 
            OnCreateGridLineCell(_GridlineCtrl);
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
 
        }
 
        protected override void OnAfterClose()
        {
            playerPack.refreshItemCountEvent -= BackpackRefresh;//背包物品清理
            _GridlineCtrl.OnRefreshCell -= OnRefreshGridCell;
 
        }
        #endregion
 
 
        void CloseButton()//关闭按钮
        {
            Close();
 
        }
 
        void Backpacking()//物品读取
        {
            Dictionary<int, ItemModel> backpack_dic = playerPack.GetSinglePack(PackType.Item).GetAllItems();
            Dictionary<int, ProductOrderJudgment> _ProductOrderJudgment = new Dictionary<int, ProductOrderJudgment>();
            phagocytosisID.Clear();
            _ProductOrderJudgment = AttributeJudgment();///属性判断
            if (backpack_dic.Count == 0)//得到背包的所有物品
                return;
 
 
            foreach (int item_id in backpack_dic.Keys)
            {
 
                ItemConfig _ChinItem = ItemConfig.Get((int)backpack_dic[item_id].itemId);
 
                if (backpack_dic[item_id].isBind == 1)
                    continue;
                foreach (int key in _ProductOrderJudgment.Keys)
                {
                    if (_ChinItem.EquipPlace == key && _ChinItem.LV >= _ProductOrderJudgment[key].Class && _ChinItem.StarLevel >= _ProductOrderJudgment[key].TheStar && _ChinItem.ItemColor >= _ProductOrderJudgment[key].Color)
                    {
 
                        string IDnumber = backpack_dic[item_id].itemId.ToString() + "|" + item_id.ToString();//添加ID和位置索引
 
                        phagocytosisID.Add(IDnumber);
 
                    }
                }
            }
        }
 
        class ProductOrderJudgment
        {
            public int Class;//阶级
            public int TheStar;//星级
            public int Color;//颜色
 
 
        }
 
        Dictionary<int, ProductOrderJudgment> AttributeJudgment()//属性判断
        {
            Dictionary<int, ProductOrderJudgment> _DicConditions = new Dictionary<int, ProductOrderJudgment>();//条件字典
            FuncConfigConfig Number1 = FuncConfigConfig.Get("FamilyStoreItemRule1");
            FuncConfigConfig Number2 = FuncConfigConfig.Get("FamilyStoreItemRule2");
            string[] strA = Number1.Numerical1.Split('|');
            string[] strA1 = Number1.Numerical2.Split('|');
            for (int i = 0; i < strA.Length; i++)
            {
                if (!_DicConditions.ContainsKey(int.Parse(strA[i])))
                {
                    ProductOrderJudgment _ProductOrder = new ProductOrderJudgment();
                    _ProductOrder.Class = int.Parse(strA1[0]);
                    _ProductOrder.TheStar = int.Parse(strA1[1]);
                    _ProductOrder.Color = int.Parse(strA1[2]);
                    _DicConditions.Add(int.Parse(strA[i]), _ProductOrder);
                }
            }
 
            string[] strB = Number2.Numerical1.Split('|');
            string[] strB1 = Number2.Numerical2.Split('|');
            for (int j = 0; j < strB.Length; j++)
            {
                if (!_DicConditions.ContainsKey(int.Parse(strB[j])))
                {
                    ProductOrderJudgment _ProductOrder = new ProductOrderJudgment();
                    _ProductOrder.Class = int.Parse(strB1[0]);
                    _ProductOrder.TheStar = int.Parse(strB1[1]);
                    _ProductOrder.Color = int.Parse(strB1[2]);
                    _DicConditions.Add(int.Parse(strB[j]), _ProductOrder);
                }
 
            }
            return _DicConditions;
        }
 
 
        void OnCreateGridLineCell(ScrollerController gridCtrl)//预制体创建
        {
            gridCtrl.Refresh();
            int Index = Mathf.CeilToInt((float)phagocytosisID.Count / 5);
            for (int i = 0; i < Index; i++)
            {
                gridCtrl.AddCell(ScrollerDataType.Header, i);
            }
 
            gridCtrl.Restart();
        }
 
        void OnRefreshGridCell(ScrollerDataType type, CellView cell)
        {
            int line = cell.index;
            for (int i = 0; i < 5; i++)
            {
 
                int index = line * 5 + i;
                GameObject obj = cell.transform.GetChild(i).gameObject;
                ItemCell _itemCell = obj.transform.Find("ItemCell").GetComponent<ItemCell>();
                Button _ItemBtn = _itemCell.GetComponent<Button>();
                if (index < phagocytosisID.Count)
                {
                    obj.SetActive(true);
 
                    string[] _ParseStr = phagocytosisID[index].Split('|');
                    int _ItemID = int.Parse(_ParseStr[0]);
                    int _index = int.Parse(_ParseStr[1]);
                    ItemConfig Item = ItemConfig.Get(_ItemID);
                    PetEatEquipConfig tagPet = PetEatEquipConfig.GetEquipColorAndEquipClass(Item.ItemColor, Item.LV);//装备积分兑换表
 
                    ItemModel model = playerPack.GetItemByIndex(PackType.Item, _index);
                    if (model != null)
                    {
                        _itemCell.Init(model,true);
                        _ItemBtn.RemoveAllListeners();
                        _ItemBtn.AddListener(() =>
                        {
                            _BagIndex = _index;
                            itemTipsModel.SetItemTipsModel(PackType.Item, model.guid, false, true, ItemTipChildType.UnionWarehouseDonation);
                            itemTipsModel.curAttrData.SetTipsFuncBtn(ItemOperateType.donate, Donation);
                            itemTipsModel.ShowUICtrl();
                        });
                    }
                }
                else
                {
                    obj.SetActive(false);
                }
            }
 
        }
 
 
        void Donation(ItemOperateType type, string s)//捐献
        {
            switch (type)
            {
                case ItemOperateType.donate:
                    ////像服务端捐献发包
                    if (playerFairyAuTreasureData._DicfamilyStoreItem.Count >= MaxDonationAmount)
                    {
                        ScrollTip.ShowTip(Language.Get("Z1802"));
                        return;
                    }
                    CA609_tagCMFamilyStoreDonate _tagCA609 = new CA609_tagCMFamilyStoreDonate();
                    _tagCA609.ItemIndex = (byte)_BagIndex;
                    GameNetSystem.Instance.SendInfo(_tagCA609);
                    KnapSackEventMgr.Instance.HideItemPopWin();
                    break;
            }
        }
 
 
 
        void BackpackRefresh(PackType type, int itemPlace, int id)//背包物品清理
        {
 
            Backpacking();//背包物品读取和创建
            OnCreateGridLineCell(_GridlineCtrl);
        }
    }
}