少年修仙传客户端代码仓库
client_linchunjie
2018-09-21 edfd535734a7adab6d0f24c863149ed63bcd37c8
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
//--------------------------------------------------------
//    [Author]:           第二世界
//    [  Date ]:           Thursday, May 10, 2018
//--------------------------------------------------------
 
using System;
using System.Collections;
using System.Collections.Generic;
using TableConfig;
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI {
 
    public class OpenServerGiftWin : Window
    {
        [SerializeField] RectTransform m_ContainerDisplay;
        [SerializeField] Button[] m_CloseBtns;
        [SerializeField] OSGiftBehaviour[] m_OSGifts;
        [SerializeField] RectTransform m_ContainerTime;
        [SerializeField] Text m_Overdue;
        [SerializeField] Text m_Timer;
        StoreModel m_Model;
        StoreModel model
        {
            get
            {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<StoreModel>());
            }
        }
 
        int currentSelectId = 0;
 
        OSGiftModel giftModel { get { return ModelCenter.Instance.GetModel<OSGiftModel>(); } }
        #region Built-in
        protected override void BindController()
        {
        }
 
        protected override void AddListeners()
        {
            for (int i = 0; i < m_CloseBtns.Length; i++)
            {
                m_CloseBtns[i].onClick.AddListener(OnCloseClick);
            }
        }
 
        protected override void OnPreOpen()
        {
            WindowCenter.Instance.windowAfterOpenEvent += WindowAfterOpenEvent;
            WindowCenter.Instance.windowAfterCloseEvent += windowAfterCloseEvent;
            model.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
            TimeUtility.OnServerOpenDayRefresh += OnServerOpenDayRefresh;
            GlobalTimeEvent.Instance.secondEvent += SecondEvent;
            giftModel.timeLimitUpdate += TimeLimitUpdate;
            giftModel.SetDayRemind();
            Display();
 
            m_ContainerDisplay.gameObject.SetActive(!WindowCenter.Instance.CheckOpen<OffLineOnHookWin>());
        }
 
        protected override void OnAfterOpen()
        {
        }
 
        protected override void OnPreClose()
        {
            WindowCenter.Instance.windowAfterOpenEvent -= WindowAfterOpenEvent;
            WindowCenter.Instance.windowAfterCloseEvent -= windowAfterCloseEvent;
            model.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
            TimeUtility.OnServerOpenDayRefresh -= OnServerOpenDayRefresh;
            GlobalTimeEvent.Instance.secondEvent -= SecondEvent;
            giftModel.timeLimitUpdate -= TimeLimitUpdate;
        }
 
        protected override void OnAfterClose()
        {
        }
        #endregion
 
        private void WindowAfterOpenEvent(Window _win)
        {
            if(_win is OffLineOnHookWin)
            {
                m_ContainerDisplay.gameObject.SetActive(false);
            }
        }
 
        private void windowAfterCloseEvent(Window _win)
        {
            if (_win is OffLineOnHookWin)
            {
                m_ContainerDisplay.gameObject.SetActive(true);
            }
        }
 
        private void RefreshBuyShopLimitEvent()
        {
            Display();
        }
 
        private void OnServerOpenDayRefresh()
        {
            Display();
        }
 
        private void SecondEvent()
        {
            DisplayTimer();
        }
 
        private void TimeLimitUpdate()
        {
            Display();
        }
 
        void DisplayTimer()
        {
            var seconds = (int)(giftModel.overDueTime - TimeUtility.ServerNow).TotalSeconds;
            if (giftModel.IsGiftOverdue(currentSelectId) || seconds <= 0)
            {
                m_ContainerTime.gameObject.SetActive(false);
                m_Overdue.gameObject.SetActive(true);
            }
            else
            {
                m_ContainerTime.gameObject.SetActive(true);
                m_Overdue.gameObject.SetActive(false);
                m_Timer.text = TimeUtility.SecondsToDHMSCHS(seconds);
                m_Timer.color = UIHelper.GetUIColor(TextColType.Green);
            }
        }
 
        private void Display()
        {
            List<StoreConfig> _list = null;
            StoreConfig.TryGetStoreConfigs((int)StoreFunc.OSGift, out _list);
            var _index = 0;
            for (int i = 0; i < _list.Count; i++)
            {
                if (!giftModel.IsGiftOverdue(_list[i].ID))
                {
                    var _storeConfig = Config.Instance.Get<StoreConfig>(_list[i].ID);
                    var _limit = model.GetBuyShopLimit((uint)_list[i].ID);
                    if (_limit == null || _limit.BuyCnt < _storeConfig.PurchaseNumber[0])
                    {
                        _index = i;
                        currentSelectId = _list[i].ID;
                        m_OSGifts[i].Display(_list[i].ID);
                        break;
                    }
                }
                _index = i;
            }
            for (int i = 0; i < m_OSGifts.Length; i++)
            {
                m_OSGifts[i].gameObject.SetActive(_index == i);
            }
            DisplayTimer();
        }
 
        private void OnCloseClick()
        {
            CloseImmediately();
        }
    }
 
}