using System; using UnityEngine; using UnityEngine.UI; namespace Snxxz.UI { public class CrossSeverOneVsOneBuyMatchTimesWin : Window { [SerializeField] Text m_TodayBuyTimes; [SerializeField] Text m_CostRemind; [SerializeField] Button m_BuyTimes; [SerializeField] Button m_Close; [SerializeField] RectTransform m_ContainerBuylimit; CrossServerOneVsOneModel crossServerModel { get { return ModelCenter.Instance.GetModel(); } } ulong price = 0; #region Built-in protected override void BindController() { } protected override void AddListeners() { m_Close.AddListener(CloseClick); m_BuyTimes.AddListener(ClickBuyTimes); } protected override void OnPreOpen() { CrossServerOneVsOnePlayerInfo.Instance.UpdatePlayerInfoEvent += SetDisplay; SetDisplay(); } protected override void OnAfterOpen() { } protected override void OnPreClose() { CrossServerOneVsOnePlayerInfo.Instance.UpdatePlayerInfoEvent -= SetDisplay; } protected override void OnAfterClose() { } #endregion private void SetDisplay() { int remainBuyTimes = CrossServerOneVsOnePlayerInfo.Instance.GetDayRemainBuyNum(); price = (ulong)CrossServerOneVsOnePlayerInfo.Instance.GetBuyMatchNumPrice(); m_CostRemind.text = Language.Get("TimesBuyLanguage3", price); m_ContainerBuylimit.gameObject.SetActive(remainBuyTimes <= 0); m_BuyTimes.gameObject.SetActive(remainBuyTimes > 0); if (remainBuyTimes > 0) { m_TodayBuyTimes.text = Language.Get("TimesBuyLanguage1", UIHelper.AppendColor(TextColType.Green, remainBuyTimes.ToString()), crossServerModel.buyMaxMatchNum); } else { m_TodayBuyTimes.text = Language.Get("TimesBuyLanguage1", UIHelper.AppendColor(TextColType.Red, remainBuyTimes.ToString()), crossServerModel.buyMaxMatchNum); } } private void ClickBuyTimes() { if (!crossServerModel.TryGetBuyMatchTimes("CrossMatching21")) return; ulong sumGold = UIHelper.GetMoneyCnt(1); if (sumGold >= price) { SendBuyTimes(); } else { WindowCenter.Instance.Open(); } } private void SendBuyTimes() { crossServerModel.SendBuyMatchCount(); } } }