少年修仙传客户端代码仓库
hch
2025-06-12 204ef05a831c9484e2abc561d27ecbff7c797453
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
using System;
using System.Collections;
using System.Collections.Generic;
 
using UnityEngine;
using UnityEngine.UI;
 
namespace vnxbqy.UI
{
    public class OSGiftBehaviour : MonoBehaviour
    {
        [SerializeField] Text m_GiftName;
        [SerializeField] RareItem[] m_Items;
        [SerializeField] Text m_GiftDescription;
        [SerializeField] Image m_CostMoneyIcon;
        [SerializeField] Text m_CostValue;
        [SerializeField] Image m_OriginalMoneyIcon;
        [SerializeField] Text m_OriginalMoneyValue;
        [SerializeField] Button m_BuyBtn;
        [SerializeField] Image m_Complete;
        [SerializeField] Text m_OwnMoney;
 
        StoreModel m_StoreModel;
        StoreModel storeModel
        {
            get
            {
                return m_StoreModel ?? (m_StoreModel = ModelCenter.Instance.GetModel<StoreModel>());
            }
        }
 
        OSTimeLimitGiftModel m_TimeLimitGiftModel;
        OSTimeLimitGiftModel timeLimitGiftModel
        {
            get
            {
                return m_TimeLimitGiftModel ?? (m_TimeLimitGiftModel = ModelCenter.Instance.GetModel<OSTimeLimitGiftModel>());
            }
        }
 
        OSGiftModel giftModel { get { return ModelCenter.Instance.GetModel<OSGiftModel>(); } }
 
        private int storeId = 0;
 
        private void Awake()
        {
            m_BuyBtn.onClick.AddListener(OnBuyBtn);
            for (int i = 0; i < m_Items.Length; i++)
            {
                var _index = i;
                m_Items[i].button.onClick.AddListener(() =>
                {
                    OnItemClick(_index);
                });
            }
        }
 
        private void OnEnable()
        {
            storeModel.RefreshBuyShopLimitEvent += RefreshBuyShopLimitEvent;
            PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
        }
 
        private void OnDisable()
        {
            storeModel.RefreshBuyShopLimitEvent -= RefreshBuyShopLimitEvent;
            PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
        }
 
        private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
        {
            if (refreshType == PlayerDataType.Gold || refreshType == PlayerDataType.GoldPaper)
            {
                DisplayOwnMoney();
            }
        }
 
        private void RefreshBuyShopLimitEvent()
        {
            Display(storeId);
        }
 
        public void Display(int _id)
        {
            var _storeConfig = StoreConfig.Get(_id);
            if (_storeConfig == null)
            {
                return;
            }
            storeId = _id;
            List<ShopItemInfo> _shopItems;
            if (m_GiftName != null)
            {
                m_GiftName.text = Language.Get(StringUtility.Contact("OSGiftName_"), _storeConfig.MoneyNumber);
            }
            if (m_GiftDescription != null)
            {
                m_GiftDescription.text = Language.Get(StringUtility.Contact("OSGiftDesc_", _storeConfig.MoneyNumber));
            }
            if (storeModel.TryGetShopItemInfo((StoreFunc)_storeConfig.ShopType, _id, out _shopItems))
            {
                for (int i = 0; i < m_Items.Length; i++)
                {
                    if (i >= _shopItems.Count)
                    {
                        m_Items[i].SetActive(false);
                        continue;
                    }
                    m_Items[i].SetActive(true);
                    var _item = _shopItems[i];
                    var _itemModel = new ItemCellModel(_item.itemId, false, (ulong)_item.count);
                    m_Items[i].SetItemRare(_itemModel, _storeConfig.MainItemID == _item.itemId);
                }
            }
            m_CostMoneyIcon.SetIconWithMoneyType(_storeConfig.MoneyType);
            m_CostValue.text = _storeConfig.MoneyNumber.ToString();
 
            if (m_OriginalMoneyIcon != null)
            {
                m_OriginalMoneyIcon.SetIconWithMoneyType(_storeConfig.MoneyType);
            }
            if (m_OriginalMoneyValue != null)
            {
                m_OriginalMoneyValue.text = _storeConfig.MoneyOriginal.ToString();
            }
 
            DisplayOwnMoney();
 
            var _limit = storeModel.GetBuyShopLimit((uint)storeId);
            m_Complete.SetActive(_limit != null && _limit.BuyCnt >= _storeConfig.GoumaiNumber[0]);
            m_BuyBtn.SetActive(_limit == null || _limit.BuyCnt < _storeConfig.GoumaiNumber[0]);
        }
 
        private void DisplayOwnMoney()
        {
            if (m_OwnMoney != null)
            {
                var config = StoreConfig.Get(storeId);
                m_OwnMoney.text = UIHelper.GetMoneyCnt(config == null ? 1 : config.MoneyType).ToString();
            }
        }
 
        private void OnBuyBtn()
        {
            var _storeConfig = StoreConfig.Get(storeId);
            if (_storeConfig == null)
            {
                return;
            }
            switch ((StoreFunc)_storeConfig.ShopType)
            {
                case StoreFunc.OSTimeLimitGift:
                    if (timeLimitGiftModel.currentDay > timeLimitGiftModel.openDays)
                    {
                        SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
                        return;
                    }
                    ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                        Language.Get("OSTimeLimitGiftConfirm", _storeConfig.MoneyNumber), (bool isOk) =>
                    {
                        if (isOk)
                        {
                            storeModel.SendBuyShopItem(_storeConfig, 1);
                        }
                    });
                    return;
                case StoreFunc.OSGift:
                    {
                        if (!giftModel.IsGiftExist(_storeConfig.ID))
                        {
                            SysNotifyMgr.Instance.ShowTip("ActiveOutTime");
                            return;
                        }
                        ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"),
                        Language.Get("OSTimeLimitGiftConfirm", _storeConfig.MoneyNumber), (bool isOk) =>
                        {
                            if (isOk)
                            {
                                storeModel.SendBuyShopItem(_storeConfig, 1);
                            }
                        });
                    }
                    return;
            }
            storeModel.SendBuyShopItem(_storeConfig, 1);
        }
 
        private void OnItemClick(int _index)
        {
            var _storeConfig = StoreConfig.Get(storeId);
            if (_storeConfig == null)
            {
                return;
            }
            List<ShopItemInfo> _shopItems;
            if (storeModel.TryGetShopItemInfo((StoreFunc)_storeConfig.ShopType, storeId, out _shopItems))
            {
                if (_index < _shopItems.Count)
                {
                    var item = _shopItems[_index];
                    ItemTipUtility.Show(item.itemId);
                }
            }
        }
    }
}