//-------------------------------------------------------- // [Author]: 第二世界 // [ Date ]: Wednesday, November 01, 2017 //-------------------------------------------------------- using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; namespace vnxbqy.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.playerDataRefreshEvent += 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.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent; vipModel.OnVipTimeEvent -= OnVipTimeEvent; model.updateDungeonBuyCnt -= UpdateDungeonBuyCnt; } protected override void OnAfterClose() { } private void OnVipTimeEvent() { Display(); } private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType) { if (refreshType == PlayerDataType.VIPLv) { Display(); } } private void UpdateDungeonBuyCnt() { Display(); } void Display() { var openTimeConfig = DungeonOpenTimeConfig.Get(model.currentDungeon.mapId); m_DungeonName.text = openTimeConfig.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.AppendColor(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.SetActive(displayUp); m_GotoRecharge.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.SetActive(canBuyTimes); m_GotoRecharge.SetActive(!canBuyTimes && nextVipLv != -1); m_ContainerBuylimit.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.diamond >= _cost) { model.RequestBuyEnterCount(model.currentDungeon.mapId); } else { if (VersionConfig.Get().isBanShu) { SysNotifyMgr.Instance.ShowTip("GoldErr"); return; } WindowCenter.Instance.Open(); } } private bool CheckSpecialDungeon() { if (DemonJarModel.DATA_MAPID == model.currentDungeon.mapId) { var _totalTimes = model.GetTotalTimes(DemonJarModel.DATA_MAPID); var _enterTimes = model.GetEnterTimes(DemonJarModel.DATA_MAPID); if ((_totalTimes - _enterTimes) >= DemonJarModel.TOTALTIME_LIMIT) { ServerTipDetails.DisplayNormalTip(Language.Get("DemonJar18")); return false; } } else if (JadeDynastyBossModel.JADEDYNASTY_MAP == model.currentDungeon.mapId) { var _totalTimes = model.GetTotalTimes(JadeDynastyBossModel.JADEDYNASTY_MAP); var _enterTimes = model.GetEnterTimes(JadeDynastyBossModel.JADEDYNASTY_MAP); var jadeDynastyBossModel = ModelCenter.Instance.GetModel(); if ((_totalTimes - _enterTimes) >= jadeDynastyBossModel.challengeLimitCount) { ServerTipDetails.DisplayNormalTip(Language.Get("DemonJar18")); return false; } var mapId = PlayerDatas.Instance.baseData.MapID; var dataMapId = model.GetDataMapIdByMapId(mapId); if (dataMapId == JadeDynastyBossModel.JADEDYNASTY_MAP) { SysNotifyMgr.Instance.ShowTip("JadeDynastyBossBuyTimesError"); return false; } } return true; } private void GotoRecharge() { WindowCenter.Instance.Close(); WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.VipRechargeFunc1); } } }