少年修仙传客户端代码仓库
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
using System;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
 
    public class CustomizedGiftChooseWin : Window
    {
        [SerializeField] ScrollerController m_Controller;
        [SerializeField] Text txtTitle;
        [SerializeField] RichText txtInfo;
        [SerializeField] List<CustomizedItemCell> itemCellList;
        [SerializeField] List<ImageEx> imageList;
        [SerializeField] Button closeBtn;
        [SerializeField] Button closeBtn2;
        [SerializeField] Button okBtn;
        CustomizedRechargeModel model { get { return ModelCenter.Instance.GetModel<CustomizedRechargeModel>(); } }
        VipModel vipModel { get { return ModelCenter.Instance.GetModel<VipModel>(); } }
        int index;
        int actCtgIndex;
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            closeBtn.SetListener(CloseClick);
 
            closeBtn2.SetListener(CloseClick);
 
            okBtn.SetListener(ChooseItem);
        }
 
 
        protected override void OnPreOpen()
        {
            model.InitChoose();
            m_Controller.OnRefreshCell += OnRefreshCell;
            model.UpdateWin += OnUpdateWin;
            vipModel.rechargeCountEvent += VipModel_rechargeCountEvent;
            Display();
        }
        void VipModel_rechargeCountEvent(int obj)
        {
            if (model.chooseCTGID == obj)
            {
                CloseClick();
            }
        }
 
        protected override void OnAfterOpen()
        {
            DisplayScroll();
        }
 
        protected override void OnPreClose()
        {
            m_Controller.OnRefreshCell -= OnRefreshCell;
            model.UpdateWin -= OnUpdateWin;
            vipModel.rechargeCountEvent -= VipModel_rechargeCountEvent;
        }
 
        void OnUpdateWin()
        {
            Display();
            m_Controller.m_Scorller.RefreshActiveCellViews();
        }
 
        protected override void OnAfterClose()
        {
 
        }
        #endregion
 
        private void OnRefreshCell(ScrollerDataType type, CellView cell)
        {
            var _cell = cell as CustomizedGiftChooseCell;
            _cell.Display(_cell.index);
        }
 
        void DisplayScroll()
        {
            m_Controller.Refresh();
            var ctgConfig = CTGConfig.Get(model.chooseCTGID);
            var selectItemInfo = ctgConfig.SelectItemInfo[model.chooseWinIndex];
            int count = selectItemInfo.Length;
            int lineCount = (int)Math.Ceiling((double)count / 7);
            for (int i = 0; i < lineCount; i++)
            {
                m_Controller.AddCell(ScrollerDataType.Header, i);
            }
            m_Controller.Restart();
        }
 
        void Display()
        {
            for (int i = 0; i < imageList.Count; i++)
            {
                imageList[i].SetActive(false);
            }
 
            var ctgConfig = CTGConfig.Get(model.chooseCTGID);
            var selectItemInfo = ctgConfig.SelectItemInfo[model.chooseWinIndex];
 
            int selectItemID = 0;
            int selectIemCount = 0;
            for (int i = 0; i < itemCellList.Count; i++)
            {
                if (i < ctgConfig.SelectItemInfo.Length)
                {
                    itemCellList[i].SetActive(true);
                    int chooseIndex = model.GetChooseSubIndex(i);
                    if (chooseIndex != 0)
                    {
                        int selectID = ctgConfig.SelectItemInfo[i][chooseIndex - 1];
                        var itemData = new ItemCellModel(CTGSelectItemConfig.Get(selectID).ItemID, false, (ulong)CTGSelectItemConfig.Get(selectID).ItemCount);
                        itemCellList[i].Init(itemData);
                        if (i == model.chooseWinIndex)
                        {
                            selectItemID = CTGSelectItemConfig.Get(selectID).ItemID;
                            selectIemCount = CTGSelectItemConfig.Get(selectID).ItemCount;
                        }
                    }
                    else
                    {
                        itemCellList[i].Init(null);
                    }
 
                    int index = i;
                    itemCellList[i].button.SetListener(() =>
                    {
                        if (model.chooseWinIndex != index)
                        {
                            model.chooseWinIndex = index;
                            Display();
                            DisplayScroll();
                        }
                    });
 
                    imageList[i].SetActive(i == model.chooseWinIndex);
 
                }
                else
                {
                    itemCellList[i].SetActive(false);
                }
            }
 
            if (selectItemID > 0)
            {
                txtTitle.SetActive(true);
                txtInfo.SetActive(true);
                txtTitle.text = StringUtility.Contact(ItemConfig.Get(selectItemID).ItemName, " x", selectIemCount);
                txtInfo.text = ItemConfig.Get(selectItemID).Description;
            }
            else
            {
                txtTitle.SetActive(false);
                txtInfo.SetActive(false);
            }
        }
 
        void ChooseItem()
        {
            var ctgConfig = CTGConfig.Get(model.chooseCTGID);
            if (ctgConfig.SelectItemInfo.Length != model.chooseIndexDict.Count)
            {
                SysNotifyMgr.Instance.ShowTip("CustomizedGift01");
                return;
            }
            
            CA126_tagCMSelectCTGItem pack = new CA126_tagCMSelectCTGItem();
            pack.RecordID = (ushort)model.chooseCTGID;
            pack.SelectItemValue = model.GetSelectedItemValue();
            GameNetSystem.Instance.SendInfo(pack);
        }
    }
}