少年修仙传客户端代码仓库
client_linchunjie
2019-04-17 11997ece0dc4980eba3dd8889d37adb8376e14cb
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace Snxxz.UI
{
    [XLua.Hotfix]
    public class SuperValueGiftBehaviour : MonoBehaviour
    {
        [SerializeField] Text m_Cost;
        [SerializeField] RareItem[] m_Items;
        [SerializeField] Button m_Buy;
        [SerializeField] Image m_AreadyBuySign;
 
        OSGiftModel model
        {
            get { return ModelCenter.Instance.GetModel<OSGiftModel>(); }
        }
 
        VipModel vipModel
        {
            get { return ModelCenter.Instance.GetModel<VipModel>(); }
        }
 
        int rechargeId = 0;
 
        private void Awake()
        {
            m_Buy.onClick.AddListener(Buy);
            for (int i = 0; i < m_Items.Length; i++)
            {
                var _index = i;
                m_Items[i].button.onClick.AddListener(() =>
                {
                    OnItemClick(_index);
                });
            }
        }
 
        private void OnEnable()
        {
            vipModel.rechargeCountEvent += RechargeCountEvent;
        }
 
        private void OnDisable()
        {
            vipModel.rechargeCountEvent -= RechargeCountEvent;
        }
 
        private void RechargeCountEvent(int id)
        {
            if (id == rechargeId)
            {
                Display(rechargeId);
            }
        }
 
        private void OnItemClick(int index)
        {
            if (rechargeId != 0)
            {
                List<Item> items;
                if (vipModel.TryGetRechargeItem(rechargeId, out items))
                {
                    if (index < items.Count)
                    {
                        var item = items[index];
                        ItemAttrData attrData = new ItemAttrData(item.id, false, (ulong)item.count);
                        ModelCenter.Instance.GetModel<ItemTipsModel>().SetItemTipsModel(attrData);
                    }
                }
            }
        }
 
        private void Buy()
        {
            if (rechargeId != 0)
            {
                VipModel.RechargeCount rechargeCount;
                if (vipModel.TryGetRechargeCount(rechargeId, out rechargeCount))
                {
                    if (rechargeCount.totalCount >= 1)
                    {
                        return;
                    }
                }
                vipModel.CTG(rechargeId);
            }
        }
 
        public void Display(int id)
        {
            rechargeId = id;
            List<Item> items;
            bool hasItem = vipModel.TryGetRechargeItem(id, out items);
            for (int i = 0; i < m_Items.Length; i++)
            {
                if (hasItem && i < items.Count)
                {
                    m_Items[i].gameObject.SetActive(true);
                    var _item = items[i];
                    var _itemModel = new ItemCellModel(_item.id, false, (ulong)_item.count);
                    m_Items[i].SetItemRare(_itemModel, i == 0);
                }
                else
                {
                    m_Items[i].gameObject.SetActive(false);
                }
            }
 
            var config = CTGConfig.Get(id);
            if (config != null)
            {
                OrderInfoConfig orderInfoConfig;
                if (vipModel.TryGetOrderInfo(id, out orderInfoConfig))
                {
                    m_Cost.text = Language.Get("SuperValueGiftCost", orderInfoConfig.PayRMBNum);
                }
            }
 
            VipModel.RechargeCount rechargeCount;
            bool alreadyBuy = false;
            if (vipModel.TryGetRechargeCount(id, out rechargeCount))
            {
                alreadyBuy = rechargeCount.totalCount >= 1;
            }
            m_Buy.gameObject.SetActive(!alreadyBuy);
            m_AreadyBuySign.gameObject.SetActive(alreadyBuy);
        }
    }
}