using System; using System.Collections; using System.Collections.Generic; using TableConfig; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class RechargeWin : Window { [SerializeField] RechargeBehaviour[] m_Recharges; [SerializeField] Text m_GoldValue; [SerializeField] Text m_GoldPaperValue; [SerializeField] Button m_SpecialRechargeBtn; VipModel m_Model; VipModel model { get { return m_Model ?? (m_Model = ModelCenter.Instance.GetModel()); } } protected override void BindController() { } protected override void AddListeners() { m_SpecialRechargeBtn.onClick.AddListener(SpecialRecharge); } protected override void OnPreClose() { PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent; model.rechargeCountEvent -= RechargeCountEvent; if (model.rechargeGiftRedpoint.state == RedPointState.Simple) { model.SetViewedRechargeGift(); } } protected override void OnPreOpen() { Display(); UpdateGoldValue(); PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent; model.rechargeCountEvent += RechargeCountEvent; } protected override void OnAfterClose() { } protected override void OnAfterOpen() { } private void PlayerDataRefreshInfoEvent(PlayerDataRefresh _type) { switch (_type) { case PlayerDataRefresh.Gold: case PlayerDataRefresh.GoldPaper: UpdateGoldValue(); break; } } void Display() { var _list = model.GetCTGConfigs(VersionConfig.Get().appId); var _index = 0; for (int i = 0; i < _list.Count; i++) { var config = Config.Instance.Get(_list[i]); if (config == null || (config.PayType != 1 && config.PayType != 2)) { continue; } m_Recharges[_index].Display(_list[i]); _index++; } var _specialIndex = _list.FindIndex((x) => { var config = Config.Instance.Get(x); return config != null && config.PayType == 3; }); m_SpecialRechargeBtn.gameObject.SetActive(_specialIndex != -1 && PlayerDatas.Instance.baseData.VIPLv >= GeneralConfig.Instance.supremeRechargeVipLv); } private void SpecialRecharge() { var _list = model.GetCTGConfigs(VersionConfig.Get().appId); var _specialIndex = _list.FindIndex((x) => { var config = Config.Instance.Get(x); return config != null && config.PayType == 3; }); if (_specialIndex != -1) { WindowCenter.Instance.Open(); } } void UpdateGoldValue() { m_GoldValue.text = UIHelper.ReplaceLargeNum(PlayerDatas.Instance.baseData.Gold); m_GoldPaperValue.text = UIHelper.ReplaceLargeNum(PlayerDatas.Instance.baseData.GoldPaper); } private void RechargeCountEvent(int _id) { var config = Config.Instance.Get(_id); if (config == null || (config.PayType != 1 && config.PayType != 2)) { return; } for (int i = 0; i < m_Recharges.Length; i++) { if (m_Recharges[i].chargeId == _id) { m_Recharges[i].Display(_id); break; } } } } }