少年修仙传客户端代码仓库
client_Wu Xijin
2019-02-25 1e8c7d6350e5d69823b0c01fc9d8c50980e86e54
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Friday, September 22, 2017
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
 
using UnityEngine.EventSystems;
using Snxxz.UI;
 
namespace Snxxz.UI
{
 
    public class OneKeySellWin : Window
    {
        #region 成员变量
        [SerializeField] Button _closeBtn;
        [SerializeField] Button _sureSellBtn;
        [SerializeField] Button _setAutoSellBtn;
        [SerializeField] Text _canSellMoneyText;
        [SerializeField] ScrollerController _cellCtrl;
        [SerializeField] ScrollRect _sliderRect;
        #endregion
 
        private int sumLine = 0;
        private int sellMoney = 0;
        private FuncConfigConfig _funcOneKeySellModel;
        private Dictionary<int,ItemModel> _singlePackDict;
        private List<ItemModel> _oneKeySelllist = new List<ItemModel>();
        private ItemConfig _chinModel;
 
        PlayerPackModel _playerPack;
        PlayerPackModel playerPack
        {
            get { return _playerPack ?? (_playerPack = ModelCenter.Instance.GetModel<PlayerPackModel>()); }
        }
 
        #region Built-in
        protected override void BindController()
        {
            _cellCtrl.OnRefreshCell += OnRefreshGridCell;
            _cellCtrl.vertical = true;
        }
 
        protected override void AddListeners()
        {
 
        }
 
        protected override void OnPreOpen()
        {
            DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent += OneKeySellSuccess;
            _closeBtn.onClick.AddListener(OnClickCloseBtn);
            _sureSellBtn.onClick.AddListener(()=> { OnClickSellBtn(_oneKeySelllist); } );
            _setAutoSellBtn.onClick.AddListener(OnClickSetAutoSellBtn);
            _funcOneKeySellModel = FuncConfigConfig.Get("OneKeySellGridCount");
            sumLine = int.Parse(_funcOneKeySellModel.Numerical1) / 6;
            InitModel();
          
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            DTC0721_tagMakeItemAnswer.MakeItemAnswerEvent -= OneKeySellSuccess;
        }
 
        protected override void OnAfterClose()
        {
            _closeBtn.onClick.RemoveAllListeners();
            _sureSellBtn.onClick.RemoveAllListeners();
            _setAutoSellBtn.onClick.RemoveAllListeners();
        }
        #endregion
 
        private void InitModel()
        {
            _oneKeySelllist.Clear();
            _oneKeySelllist = ItemLogicUtility.Instance.GetSellItemList();
            OnCreateGridLineCell();
            _cellCtrl.JumpIndex(0);
        }
 
        public  void OnCreateGridLineCell()
        {
            if (_cellCtrl.GetNumberOfCells(_cellCtrl.m_Scorller) > 0)
            {
                _cellCtrl.m_Scorller.RefreshActiveCellViews();
            }
            else
            {
                _cellCtrl.Refresh();
                int code = 0;
                for (code = 0; code < sumLine; code++)
                {
                    _cellCtrl.AddCell(ScrollerDataType.Header, code);
                }
                _cellCtrl.Restart();
            }
 
            RefreshSellPrice();
        }
 
        private void OnRefreshGridCell(ScrollerDataType type, CellView cell)
        {
            int gridlineIndex = cell.index;
            int childCode = 0;
 
            if (_oneKeySelllist.Count < 1)
            {
                for (childCode = 0; childCode < cell.transform.childCount; childCode++)
                {
                    GameObject itemCell = cell.transform.GetChild(childCode).Find("ItemCell").gameObject;
                    GameObject gridLock = cell.transform.GetChild(childCode).Find("GridLock").gameObject;
                    itemCell.SetActive(false);
                    gridLock.SetActive(false);
                }
                return;
            }
 
 
            for (childCode = 0; childCode < cell.transform.childCount; childCode++)
            {
                ItemCell itemCell = cell.transform.GetChild(childCode).Find("ItemCell").GetComponent<ItemCell>();
                GameObject gridLock = cell.transform.GetChild(childCode).Find("GridLock").gameObject;
                int cellCount = (cell.transform.childCount) * gridlineIndex + (childCode + 1);
                itemCell.gameObject.SetActive(false);
                gridLock.SetActive(false);
                if(_oneKeySelllist.Count >= cellCount)
                {
                    itemCell.gameObject.SetActive(true);
                    ItemModel itemModel = _oneKeySelllist[cellCount - 1];
                    itemCell.Init(itemModel,true);
                    itemCell.cellBtn.onClick.RemoveAllListeners();
                    itemCell.cellBtn.onClick.AddListener(()=> { OnSingleClickItemCell(itemModel,itemCell.gameObject); });
                }
           
            }
 
 
        }
 
        private void RefreshSellPrice()
        {
            sellMoney = 0;
            int i = 0;
            for(i = 0; i < _oneKeySelllist.Count; i++)
            {
                _chinModel = ItemConfig.Get((int)_oneKeySelllist[i].itemId);
                if(_chinModel != null)
                {
                    sellMoney += _chinModel.SilverPrice;
                }
            }
            _canSellMoneyText.text = sellMoney.ToString();
        }
 
        #region 点击事件
 
        private void OnSingleClickItemCell(ItemModel model,GameObject go)
        {
           if(_oneKeySelllist.Contains(model))
            {
                _oneKeySelllist.Remove(model);
                go.SetActive(false);
                RefreshSellPrice();
            }
        }
 
        private void OnClickSetAutoSellBtn()
        {
            WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.SystemSettingFunc1);
            //SysNotifyMgr.Instance.ShowTip("UnopenedFunction");
        }
 
        private void OnClickSellBtn(List<ItemModel> _oneKeySelllist)
        {
            ItemLogicUtility.Instance.SendOneKeySellQuest(_oneKeySelllist);
            if(_oneKeySelllist.Count < 1)
            {
                OnClickCloseBtn();
            }
        }
 
        private void OneKeySellSuccess(H0721_tagMakeItemAnswer obj)
        {
            if (obj.MakeType != (byte)MakeType.Def_mitKeySell)
                return;
 
            if(obj.Result == 1)
            {
                ItemLogicUtility.Instance.SendPackResetQuest(PackType.Item);
            }
 
            OnClickCloseBtn();
        }
 
        private void OnClickCloseBtn()
        {
            Close();
        }
      
        #endregion
 
    }
}