//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, November 01, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using TableConfig; namespace Snxxz.UI { public class DungeonBuyTimesWin : Window { [SerializeField] Button m_Close; [SerializeField] Text m_DungeonName; [SerializeField] Text m_TodayBuyTimes; [SerializeField] Text m_CostRemind; [SerializeField] RectTransform m_ContainerVipUp; [SerializeField] Text m_VipUpRemind; [SerializeField] RectTransform m_ContainerBuylimit; [SerializeField] Button m_BuyTimes; [SerializeField] Button m_GotoRecharge; DungeonRecord dungeonRecord; string costFormula = string.Empty; DungeonModel model { get { return ModelCenter.Instance.GetModel(); } } VipModel vipModel { get { return ModelCenter.Instance.GetModel(); } } protected override void BindController() { } protected override void AddListeners() { m_Close.onClick.AddListener(CloseClick); m_BuyTimes.onClick.AddListener(BuyTimes); m_GotoRecharge.onClick.AddListener(GotoRecharge); } protected override void OnPreOpen() { PlayerDatas.Instance.PlayerDataRefreshInfoEvent += PlayerDataRefreshInfoEvent; vipModel.OnVipTimeEvent += OnVipTimeEvent; model.updateDungeonBuyCnt += UpdateDungeonBuyCnt; if (model.TryGetRecord(model.currentDungeon.mapId, out dungeonRecord)) { Display(); } else { CloseImmediately(); } } protected override void OnAfterOpen() { } protected override void OnPreClose() { PlayerDatas.Instance.PlayerDataRefreshInfoEvent -= PlayerDataRefreshInfoEvent; vipModel.OnVipTimeEvent -= OnVipTimeEvent; model.updateDungeonBuyCnt -= UpdateDungeonBuyCnt; } protected override void OnAfterClose() { } private void OnVipTimeEvent() { Display(); } private void PlayerDataRefreshInfoEvent(PlayerDataRefresh refreshType) { if (refreshType == PlayerDataRefresh.VIPLv) { Display(); } } private void UpdateDungeonBuyCnt() { Display(); } void Display() { var openTimeConfig = Config.Instance.Get(model.currentDungeon.mapId); var dungeonConfig = Config.Instance.Get(model.GetDungeonId(model.currentDungeon.mapId, model.currentDungeon.lineId)); m_DungeonName.text = dungeonConfig.FBName; int defaultTimes = VipPrivilegeConfig.GetVipPrivilegeData((VipPrivilegeType)openTimeConfig.BuyTimesID, 0); int vipBuyTimes = vipModel.GetVipPrivilegeCnt((VipPrivilegeType)openTimeConfig.BuyTimesID) - defaultTimes; var totalTimes = defaultTimes + vipBuyTimes; var surplusTimes = totalTimes - dungeonRecord.buyTimes; var canBuyTimes = defaultTimes > dungeonRecord.buyTimes || surplusTimes > 0; var surplusTimeDisplay = UIHelper.GetTextColorByItemColor(surplusTimes > 0 ? TextColType.Green : TextColType.Red, surplusTimes.ToString(), true); m_TodayBuyTimes.text = Language.Get("TimesBuyLanguage1", surplusTimeDisplay, totalTimes); int nextVipLv = vipModel.GetPrivilegeVipLv((VipPrivilegeType)openTimeConfig.BuyTimesID, totalTimes); var currentVipLv = PlayerDatas.Instance.baseData.VIPLv; int vipHasTimesLv = vipModel.GetPrivilegeVipLv((VipPrivilegeType)openTimeConfig.BuyTimesID, defaultTimes); bool displayUp = (currentVipLv >= vipHasTimesLv && nextVipLv != -1) || (currentVipLv < vipHasTimesLv && surplusTimes == 0 && nextVipLv != -1); m_ContainerVipUp.gameObject.SetActive(displayUp); m_GotoRecharge.gameObject.SetActive(nextVipLv != -1 && !canBuyTimes); if (displayUp) { var _buyTimes = VipPrivilegeConfig.GetVipPrivilegeData((VipPrivilegeType)openTimeConfig.BuyTimesID, nextVipLv); var upTimes = _buyTimes - totalTimes; m_VipUpRemind.text = Language.Get("TimesBuyLanguage2", nextVipLv, upTimes); } if (model.TryGetBuyCountCost(model.currentDungeon.mapId, out costFormula)) { Equation.Instance.Clear(); Equation.Instance.AddKeyValue("hasBuyCnt", dungeonRecord.buyTimes); int _cost = Equation.Instance.Eval(costFormula); m_CostRemind.text = Language.Get("TimesBuyLanguage3", _cost); } m_BuyTimes.gameObject.SetActive(canBuyTimes); m_GotoRecharge.gameObject.SetActive(!canBuyTimes && nextVipLv != -1); m_ContainerBuylimit.gameObject.SetActive(!canBuyTimes && nextVipLv == -1); } private void BuyTimes() { if (!CheckSpecialDungeon()) { return; } Equation.Instance.Clear(); Equation.Instance.AddKeyValue("hasBuyCnt", dungeonRecord.buyTimes); model.TryGetBuyCountCost(model.currentDungeon.mapId, out costFormula); int _cost = Equation.Instance.Eval(costFormula); if (PlayerDatas.Instance.baseData.GoldPaper + PlayerDatas.Instance.baseData.Gold >= _cost) { if (PlayerDatas.Instance.baseData.GoldPaper < _cost) { ConfirmCancel.ShowPopConfirm(Language.Get("Mail101"), Language.Get("FairyLand_Func13", PlayerDatas.Instance.baseData.GoldPaper, _cost, _cost - PlayerDatas.Instance.baseData.GoldPaper), (bool isOk) => { if (isOk) { model.RequestBuyEnterCount(model.currentDungeon.mapId); } }); return; } else { model.RequestBuyEnterCount(model.currentDungeon.mapId); } } else { if (VersionConfig.Get().isBanShu) { SysNotifyMgr.Instance.ShowTip("GoldErr"); return; } WindowCenter.Instance.Open(); } //CloseImmediately(); } private bool CheckSpecialDungeon() { if (DemonJarModel.DEMONJAR_MAPID == model.currentDungeon.mapId) { var _totalTimes = model.GetTotalTimes(DemonJarModel.DEMONJAR_MAPID); var _enterTimes = model.GetEnterTimes(DemonJarModel.DEMONJAR_MAPID); if ((_totalTimes - _enterTimes) >= DemonJarModel.TOTALTIME_LIMIT) { MessageWin.Inst.ShowFixedTip(Language.Get("DemonJar18")); return false; } } return true; } private void GotoRecharge() { WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.VipRechargeFunc1); } } }