少年修仙传客户端代码仓库
client_linchunjie
2018-09-14 a0ede150686a218c92b901b1f20aef12a9913890
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
using System;
using UnityEngine;
using UnityEngine.UI;
using System.Collections.Generic;
 
namespace Snxxz.UI
{
    public class PrayforDrugWin : Window
    {
        [SerializeField] ScrollerController ctrl;
        [SerializeField] Button prayBtn;
        [SerializeField] Image prayBtnImg;
        [SerializeField] Text costText;
        [SerializeField] Button closeBtn;
        [Header("最大格子数")]
        [SerializeField] int gridCount = 100;
        [Header("每行数量")]
        [SerializeField] int columnCout = 5;
 
        PrayForDurgModel PrayModel { get { return ModelCenter.Instance.GetModel<PrayForDurgModel>(); } }
        List<int> praylist;
 
        protected override void BindController()
        {
            ctrl.OnRefreshCell += RefreshPrayDrug;
        }
 
        protected override void AddListeners()
        {
            closeBtn.AddListener(CloseClick);
          
        }
 
        protected override void OnPreOpen()
        {
            praylist = PrayModel.GetPrayDruglist();
            PrayModel.RefreshPrayEvent += UpdatePrayBtn;
            UpdatePrayPack();
            SetDisplayUI();
        }
 
        protected override void OnAfterOpen()
        {
 
        }
 
        protected override void OnPreClose()
        {
            PrayModel.RefreshPrayEvent -= UpdatePrayBtn;
        }
 
        protected override void OnAfterClose()
        {
 
        }
 
        private void SetDisplayUI()
        {
            costText.text = PrayModel.costMoney.ToString();
            UpdatePrayBtn();
        }
 
        private void UpdatePrayBtn()
        {
            prayBtn.RemoveAllListeners();
            if (PrayModel.alreadyPrayNum >= PrayModel.everyDayNum)
            {
                prayBtnImg.material = MaterialUtility.GetDefaultSpriteGrayMaterial();
            }
            else
            {
                prayBtn.AddListener(ClickPrayBtn);
                prayBtnImg.material = MaterialUtility.GetUIDefaultGraphicMaterial();
            }
        }
 
        private void ClickPrayBtn()
        {
            if(PrayModel.alreadyPrayNum >= PrayModel.everyDayNum)
            {
                return;
            }
 
            if(UIHelper.GetMoneyCnt(1) >= (ulong)PrayModel.costMoney)
            {
                PrayModel.SendPrayElixir();
            }
            else
            {
                WindowCenter.Instance.Open<RechargeTipWin>();
            }
        }
 
        private void UpdatePrayPack()
        {
            if (ctrl.GetNumberOfCells(ctrl.m_Scorller) == 0)
            {
                ctrl.Refresh();
                var _line = gridCount / columnCout;
                for (int i = 0; i < _line; i++)
                {
                    ctrl.AddCell(ScrollerDataType.Header, i);
                }
                ctrl.Restart();
            }
            else
            {
                ctrl.m_Scorller.RefreshActiveCellViews();
            }
            ctrl.JumpIndex(0);
        }
 
        private void RefreshPrayDrug(ScrollerDataType type, CellView cell)
        {
            var _line = cell.index;
            int length = cell.transform.childCount;
            for (int i = 0; i < length; i++)
            {
                var _index = _line * length + i;
                PrayDrugCell prayCell = cell.transform.GetChild(i).GetComponent<PrayDrugCell>();
                if(_index < praylist.Count)
                {
                    prayCell.SetDisplayModel(praylist[_index]);
                }
                else
                {
                    prayCell.SetDisplayModel(0);
                }
               
            }
        }
    }
}