123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316 |
- /// #pkgName FGUI包名
- /// #panelName UIPanel名字
- /// #UIName = $"{#pkgName}{#panelName}" UIKey名字
- /// 该脚本由模板创建
- /// created by cb 2024
- using FairyGUI;
- using FL.Data;
- using System.Collections.Generic;
- using System;
- using XGame.Database;
- using XGame.Framework.Time;
- using XGame.Framework.UI;
- using UnityEngine;
- namespace FL.FGUI
- {
- /// <summary>
- /// UI逻辑处理类
- /// </summary>
- /// <typeparam name=""></typeparam>
- public partial class TreasureChestUpgradePanelCtrl : UIController<TreasureChestUpgradePanelVM>
- {
- private ITimer _upLvTimer; // 宝箱升级倒计时定时器
- private const int GoldId = 1; // 升级消耗金币(道具id)
- private const int AccelerationId = 1000; // 加速卡道具id
- private treasureTable _curTreasure;
- private treasureTable _nextTreasure;
- protected override void OnEnable(object intent)
- {
- AddUIListenres();
- AddEventLister();
- InitUI();
- ShowUI();
- }
- protected override void OnDisable()
- {
- RemoveUIListenres();
- RemoveEventLister();
- ClearStepTimer();
- VM.GoldResItem.Disable();
- VM.AccelerationResItem.Disable();
- VM.CostAccelerationResItem.Disable();
- }
- #region UI事件
- private void AddUIListenres()
- {
- VM.ProbabilityBtn.onClick.Add(OnClickProbabilityBtn);
- VM.IncomeBtn.onClick.Add(OnClickIncomeBtn);
- VM.UpgradeBtn.onClick.Add(OnClickUpgradeBtn);
- VM.AssistBtn.onClick.Add(OnClickAssistBtn);
- VM.ReduceTimeBtn.onClick.Add(OnClickReduceTimeBtn);
- VM.AccelerationTimeBtn.onClick.Add(OnClickAccelerationTimeBtn);
- }
- private void RemoveUIListenres()
- {
- VM.ProbabilityBtn.onClick.Remove(OnClickProbabilityBtn);
- VM.IncomeBtn.onClick.Remove(OnClickIncomeBtn);
- VM.UpgradeBtn.onClick.Remove(OnClickUpgradeBtn);
- VM.AssistBtn.onClick.Remove(OnClickAssistBtn);
- VM.ReduceTimeBtn.onClick.Remove(OnClickReduceTimeBtn);
- VM.AccelerationTimeBtn.onClick.Remove(OnClickAccelerationTimeBtn);
- }
- private void OnClickProbabilityBtn(EventContext context)
- {
- ShowPageUI(0);
- }
- private void OnClickIncomeBtn(EventContext context)
- {
- ShowPageUI(1);
- }
- /// <summary>
- /// 升级按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickUpgradeBtn(EventContext context)
- {
- DragonEggService.Instance.SendToUpgrade();
- }
- //协助按钮
- private void OnClickAssistBtn(EventContext context)
- {
- Context.ShowTips("发送援助到公会聊天频道");
- }
- /// <summary>
- /// 免费观看广告获取减少时间
- /// </summary>
- /// <param name="context"></param>
- private void OnClickReduceTimeBtn(EventContext context)
- {
- DragonEggService.Instance.SendToAcceleration(2, 0);
- }
- /// <summary>
- /// 加速按钮
- /// </summary>
- /// <param name="context"></param>
- private void OnClickAccelerationTimeBtn(EventContext context)
- {
- Context.UI.OpenAsync(UIKeys.TreasureChestReduceTimePanel,AccelerationId);
- }
- #endregion
- private void AddEventLister()
- {
- Context.AddListener(EventDefine.RefreshUpgradeTime, RefreshUpgradeTime);
- Context.AddListener(EventDefine.ShowEquipQualityProbability, ShowEquipQualityProbability);
- Context.AddListener(EventDefine.RefreshWatchAd, RefreshWatchAd);
- Context.AddListener(EventDefine.RefreshTreasureChestUI, RefreshTreasureChestUI);
- }
- private void RemoveEventLister()
- {
- Context.RemoveListener(EventDefine.RefreshUpgradeTime, RefreshUpgradeTime);
- Context.RemoveListener(EventDefine.ShowEquipQualityProbability, ShowEquipQualityProbability);
- Context.RemoveListener(EventDefine.RefreshWatchAd, RefreshWatchAd);
- Context.RemoveListener(EventDefine.RefreshTreasureChestUI, RefreshTreasureChestUI);
- }
- private void ShowUI()
- {
- _curTreasure = treasureTableRepo.Get(DragonEggData.Instance.Level);
- _nextTreasure = treasureTableRepo.Get(DragonEggData.Instance.Level + 1);
- bool bMaxLv = _nextTreasure == null;
- ShowBoxLv(DragonEggData.Instance.Level, bMaxLv);
- ShowExpUI(_curTreasure, bMaxLv);
- ShowPageUI(VM.PageCtrl.selectedIndex);
- }
- private void ShowPageUI(int index)
- {
- VM.PageCtrl.selectedIndex = index;
- if (index == 0)
- {
- ShowEquipProbability(_curTreasure, _nextTreasure);
- }
- else
- {
- ShowIncome(_curTreasure, _nextTreasure);
- }
- }
- private void ShowBoxLv(int curLv, bool bMaxLv)
- {
- VM.MaxLvCtrl.selectedIndex = bMaxLv ? 1 : 0;
- if (!bMaxLv)
- {
- VM.NextLvLabel.text = (curLv + 1).ToString();
- }
- VM.CurLvLabel.text = curLv.ToString();
- }
- private void ShowExpUI(treasureTable curTreasure, bool bMaxLv)
- {
- if (!bMaxLv && curTreasure?.Expend != null)
- {
- if (DragonEggData.Instance.UpLvTime > Context.Time.GetNowTime())
- {
- ShowUpgradeTimeUI();
- return;
- }
- VM.BoxLvExpBar.max = curTreasure.Expend;
- VM.BoxLvExpBar.value = DragonEggData.Instance.Exp;
- var needExp = curTreasure.Expend > DragonEggData.Instance.Exp ? curTreasure.Expend - DragonEggData.Instance.Exp : 0;
- VM.NeedExpLabel.text = string.Format(StringDefine.upgradeDragonEggBoxExp, needExp);
- VM.UpgradeBtn.enabled = DragonEggData.Instance.Exp >= curTreasure.Expend;
- }
- }
- /// <summary>
- /// 升级倒计时状态中
- /// </summary>
- private void ShowUpgradeTimeUI()
- {
- ShowUpgradeState(1);
- ClearStepTimer();
- if (_upLvTimer == null)
- {
- _upLvTimer = Context.Time.AddLooperTimer(500, (int dt) =>
- {
- ShowLeftStepTime();
- });
- }
- ShowLeftStepTime();
- }
- /// <summary>
- /// 龙蛋升阶倒计时
- /// </summary>
- private void ShowLeftStepTime()
- {
- long leftTime = DragonEggData.Instance.UpLvTime - Context.Time.GetNowTime();
- if (leftTime > 0)
- {
- TimeSpan timeData = TimeSpan.FromMilliseconds(leftTime);
- VM.EndTimeLabel.text = timeData.ToString(@"hh\:mm\:ss");
- }
- else
- {
- ClearStepTimer();
- ShowUpgradeState(0);
- }
- }
- private void ShowUpgradeState(int index)
- {
- VM.UpgradeCtrl.selectedIndex = index;
- if (index == 1)
- {
- ShowWatchAdUI();
- }
- }
- private void RefreshWatchAd(int eventId, object args)
- {
- if (VM.UpgradeCtrl.selectedIndex == 1)
- {
- ShowWatchAdUI();
- }
- }
- private void ShowWatchAdUI()
- {
- // 处于观看广告按钮CD状态中
- VM.CdTimeCtrl.selectedIndex = DragonEggData.Instance.WatchADCount < KeyValue.boxUpBillNum ? 0 : 1;
- VM.AdNumLabel.text = string.Format(StringDefine.treasureChestWatchADCount, DragonEggData.Instance.WatchADCount, KeyValue.boxUpBillNum);
- }
- private void ClearStepTimer()
- {
- if (_upLvTimer != null)
- {
- _upLvTimer.Cancel();
- _upLvTimer = null;
- }
- }
- /// <summary>
- /// 刷新宝箱等级界面UI
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void RefreshTreasureChestUI(int eventId, object args)
- {
- ShowUI();
- }
- /// <summary>
- /// 刷新升级倒计时
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void RefreshUpgradeTime(int eventId, object args)
- {
- ShowUpgradeTimeUI();
- }
- /// <summary>
- /// 收益页签查看装备品质产出几率按钮事件监听
- /// </summary>
- /// <param name="eventId"></param>
- /// <param name="args"></param>
- private void ShowEquipQualityProbability(int eventId, object args)
- {
- ShowPageUI(0);
- }
- private void InitUI()
- {
- VM.GoldResItem.Ctrl.ShowUI(GoldId, ItemData.Instance.GetItemNum(GoldId));
- VM.AccelerationResItem.Ctrl.ShowUI(AccelerationId, ItemData.Instance.GetItemNum(AccelerationId));
- VM.CostAccelerationResItem.Ctrl.ShowUI(AccelerationId, 1);
- VM.CdTimeLabel.text = string.Format(StringDefine.treasureChestADTime, Mathf.FloorToInt(KeyValue.boxUpBillTime / 60));
- }
- /// <summary>
- /// 装备概率UI
- /// </summary>
- private void ShowEquipProbability(treasureTable curTreasure, treasureTable nextTreasure)
- {
- var probabilityDataList = new List<ProbabilityParam>();
- bool bMaxLv = nextTreasure == null;
- for (int i = 0; i < curTreasure.EquipmentProbability.Length; i += 2)
- {
- probabilityDataList.Add(new ProbabilityParam()
- {
- quality = curTreasure.EquipmentProbability[i],
- curValue = curTreasure.EquipmentProbability[i + 1],
- nextValue = bMaxLv ? 0 : nextTreasure.EquipmentProbability[i + 1],
- bMaxLv = bMaxLv,
- });
- }
- VM.ProbabilityList.BindDatas(probabilityDataList);
- }
- /// <summary>
- /// 宝箱收益UI
- /// </summary>
- private void ShowIncome(treasureTable curTreasure, treasureTable nextTreasure)
- {
- var dropDataList = new List<TreasureChestIncome>()
- {
- new TreasureChestIncome(){dropId=curTreasure.WoodenChestDrop[0],nextLvDropId=nextTreasure == null ? 0 : nextTreasure.WoodenChestDrop[0] },
- new TreasureChestIncome(){dropId=curTreasure.BlackIronChestDrop[0],nextLvDropId=nextTreasure == null ? 0 : nextTreasure.BlackIronChestDrop[0] },
- new TreasureChestIncome(){dropId=curTreasure.PlatinumChestDrop[0],nextLvDropId=nextTreasure == null ? 0 : nextTreasure.PlatinumChestDrop[0] },
- new TreasureChestIncome(){dropId=curTreasure.ChemistryChestDrop[0],nextLvDropId=nextTreasure == null ? 0 : nextTreasure.ChemistryChestDrop[0] },
- new TreasureChestIncome(){dropId=curTreasure.PearlsChestDrop[0],nextLvDropId=nextTreasure == null ? 0 : nextTreasure.PearlsChestDrop[0] },
- };
- VM.IncomeList.BindDatas(dropDataList);
- }
- }
- }
|