少年修仙传客户端代码仓库
client_Wu Xijin
2018-08-22 c322d95d20fd83762c4afd0d50a1d9b37deaba1c
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
//--------------------------------------------------------
//    [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;
 
        StoreModel m_Model;
        StoreModel model
        {
            get
            {
                return m_Model ?? (m_Model = ModelCenter.Instance.GetModel<StoreModel>());
            }
        }
        #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;
            ModelCenter.Instance.GetModel<OSGiftModel>().giftGetNotify = false;
            model.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
 
            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;
        }
 
        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 Display()
        {
            List<StoreConfig> _list = null;
            StoreConfig.TryGetStoreConfigs((int)StoreFunc.OSGift, out _list);
            var _index = 0;
            for (int i = 0; i < _list.Count; i++)
            {
                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;
                    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);
            }
        }
 
        private void OnCloseClick()
        {
            CloseImmediately();
            if (!WindowCenter.Instance.CheckOpen<MainInterfaceWin>())
            {
                WindowCenter.Instance.Open<MainInterfaceWin>();
            }
        }
    }
 
}