少年修仙传客户端代码仓库
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
using System;
using System.Collections.Generic;
 
 
namespace vnxbqy.UI
{
    //充值自选功能
    public class CustomizedRechargeModel : Model
    {
        public const int MaxGridCount = 4;      //最多4个可选格子
 
        //用户选择面板
        public int chooseWinIndex = 0;              //用户选择面板 当前选中的格子(自选位索引)
        public int chooseCTGID = 0;                 //用户选择面板 当前选中的礼包id
        public Dictionary<int, int> chooseIndexDict = new Dictionary<int, int>();  //用户在选择面板中已选中物品栏中的索引
 
        public Action UpdateWin;
        VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
 
        public override void Init()
        {
        }
 
 
        public override void UnInit()
        {
        }
 
 
        //自选礼包 物品信息
        //count为固定的数量,sumCount包含自选格子总数量不管是否已选
        public bool TryGetRechargeItemEx(int ctgId, out List<Item> items, out int count, out int sumCount)
        {
            count = 0;
            sumCount = 0;
            items = new List<Item>();
            List<Item> awards = new List<Item>();
            if (!vipModel.TryGetRechargeItem(ctgId, out awards))
                return false;
 
            VipModel.RechargeCount rechargeCount;
            if (!vipModel.TryGetRechargeCount(ctgId, out rechargeCount))
            {
                return false;
            }
 
            count = awards.Count;
            for (int i = 0; i < awards.Count; i++)
            {
                items.Add(awards[i]);
            }
            var selectItemInfo = CTGConfig.Get(ctgId).SelectItemInfo;
            if (selectItemInfo != null && selectItemInfo.Length != 0)
            {
                sumCount = selectItemInfo.Length + items.Count;
 
                var selectedItemIndexs = ModelCenter.Instance.GetModel<CustomizedRechargeModel>().GetSelectedItems(rechargeCount.selectItemValue);
                //自选
                for (int j = 0; j < selectedItemIndexs.Count; j++)
                {
                    int selectID = selectItemInfo[j][selectedItemIndexs[j] - 1];
 
                    items.Add(new Item(CTGSelectItemConfig.Get(selectID).ItemID, CTGSelectItemConfig.Get(selectID).ItemCount));
                }
            }
            else
            {
                sumCount = count;
            }
 
            return true;
        }
 
        //约定最多4个可选, 只有全选和未选两种状态
        public List<int> GetSelectedItems(int SelectItemValue)
        {
            if (SelectItemValue <= 0)
                return new List<int>();
            var list = new List<int>();
 
            for (int i = 0; i < MaxGridCount; i++)
            {
                int itemIndex = (int)(SelectItemValue % 100);
                if (itemIndex == 0)
                    break;
                SelectItemValue /= 100;
                list.Add(itemIndex);
            }
 
            return list;
        }
 
        public uint GetSelectedItemValue()
        {
            uint SelectItemValue = 0;
 
            for (int i = 0; i < MaxGridCount; i++)
            {
                if (chooseIndexDict.ContainsKey(i))
                {
                    SelectItemValue += (uint)(chooseIndexDict[i] * Math.Pow(100, i));
                }
            }
 
            return SelectItemValue;
        }
 
 
 
        public void InitChoose()
        {
            VipModel.RechargeCount rechargeCount;
            vipModel.TryGetRechargeCount(chooseCTGID, out rechargeCount);
 
            var selectedItemIndexs = ModelCenter.Instance.GetModel<CustomizedRechargeModel>().GetSelectedItems(rechargeCount.selectItemValue);
 
            if (selectedItemIndexs.Count == 0)
            {
                chooseIndexDict.Clear();
                return;
            }
 
            for (int i = 0; i < selectedItemIndexs.Count; i++)
            {
                chooseIndexDict[i] = selectedItemIndexs[i];
            }
        }
 
        //0 未选中,从1开始
        public int GetChooseSubIndex(int index)
        {
            if (chooseIndexDict.ContainsKey(index))
                return chooseIndexDict[index];
            return 0;
        }
 
        public void ShowUIItems(List<CustomizedItemCell> itemCells, int ctgID)
        {
            int goodsCount; //固定商品种类数量
            int goodsSumCount; //商品总数量
            List<Item> awards = new List<Item>();
            TryGetRechargeItemEx(ctgID, out awards, out goodsCount, out goodsSumCount);
            VipModel.RechargeCount rechargeCount;
            vipModel.TryGetRechargeCount(ctgID, out rechargeCount);
            for (int i = 0; i < itemCells.Count; i++)
            {
                if (i < goodsSumCount)
                {
                    itemCells[i].SetActive(true);
                    int index = i;
                    if (i < awards.Count)
                    {
                        var award = awards[i];
                        var itemData = new ItemCellModel(award.id, false, (ulong)award.count);
                        itemCells[i].Init(itemData);
                        itemCells[i].button.SetListener(() =>
                        {
                            if (index < goodsCount)
                                ItemTipUtility.Show(award.id);
                            else
                            {
                                //可自选
                                chooseWinIndex = index - goodsCount;
                                chooseCTGID = ctgID;
                                WindowCenter.Instance.Open<CustomizedGiftChooseWin>();
                            }
 
                        });
                    }
                    else
                    {
                        itemCells[i].Init(null);
                        itemCells[i].button.SetListener(() =>
                        {
                            chooseWinIndex = index - goodsCount;
                            chooseCTGID = ctgID;
                            WindowCenter.Instance.Open<CustomizedGiftChooseWin>();
                        });
                    }
                }
                else
                {
                    itemCells[i].SetActive(false);
                }
            }
        }
    }
}