170 lines
5.8 KiB
C#
170 lines
5.8 KiB
C#
using asap.core;
|
|
using DG.Tweening;
|
|
using GameCore;
|
|
using System;
|
|
using System.Threading;
|
|
using System.Threading.Tasks;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class BPBanner : MonoBehaviour
|
|
{
|
|
#region Banner
|
|
[SerializeField]
|
|
TMP_Text txt_exp, txt_level;
|
|
|
|
[SerializeField]
|
|
Image img_expBar;
|
|
|
|
[SerializeField]
|
|
Animation anim_levelCoin;
|
|
[SerializeField]
|
|
RewardItemNew _tokenItem;
|
|
#endregion
|
|
|
|
BattlePassDataProvider _dataProvider;
|
|
|
|
public async void RefreshLevelBanner()
|
|
{
|
|
_dataProvider = GContext.container.Resolve<BattlePassDataProvider>();
|
|
|
|
_tokenItem.SetData(new ItemData { id = _dataProvider.curPassMain.ExpItem, count = 0 });
|
|
_tokenItem.transform.Find("text_num").gameObject.SetActive(false);
|
|
var nextLevel = _dataProvider.GetBPNextLevel;
|
|
var maxLevel = _dataProvider.BPMaxLevel;
|
|
|
|
txt_level.text = nextLevel.ToString();
|
|
|
|
var curExp = _dataProvider.GetBPCurExp();
|
|
|
|
var levelUpExp = _dataProvider.GetTotalExpFromLevelRange(nextLevel - 1, nextLevel);
|
|
//满级了
|
|
if (_dataProvider.GetBPCurLevel == maxLevel)
|
|
{
|
|
txt_exp.text = LocalizationMgr.GetText("UI_FishingRodPanel_Advanced_18");
|
|
img_expBar.fillAmount = 1;
|
|
return;
|
|
}
|
|
txt_exp.text = $"{curExp}/{levelUpExp}";
|
|
img_expBar.fillAmount = (float)curExp / (float)levelUpExp;
|
|
|
|
|
|
if (_dataProvider.CheckIfPopBuyVipPanel())
|
|
{
|
|
await UIManager.Instance.ShowUI(UITypes.BattlePassBuyNoticePopupPanel);
|
|
_dataProvider.UpdateVipToastLevel();
|
|
}
|
|
}
|
|
|
|
public async void ResAnimation(CancellationToken token, float _fillTime, float _levelUpWaitTime)
|
|
{
|
|
var curNextLevel = int.Parse(txt_level.text);
|
|
var newNextLevel = _dataProvider.GetBPNextLevel;
|
|
var maxLevel = _dataProvider.BPMaxLevel;
|
|
if (curNextLevel == maxLevel)
|
|
{
|
|
return;
|
|
}
|
|
try
|
|
{
|
|
do
|
|
{
|
|
var levelUpExp = _dataProvider.GetTotalExpFromLevelRange(curNextLevel - 1, curNextLevel);
|
|
var addation = 0;
|
|
|
|
if (_dataProvider.GetBPCurLevel == maxLevel)
|
|
{
|
|
addation = 1;
|
|
}
|
|
var curExp = (addation + img_expBar.fillAmount) * levelUpExp + addation;
|
|
|
|
|
|
if (curNextLevel < newNextLevel)
|
|
{
|
|
|
|
img_expBar.DOFillAmount(1f, _fillTime).OnUpdate(
|
|
() =>
|
|
{
|
|
var curExp = img_expBar.fillAmount * levelUpExp;
|
|
txt_exp.text = $"{(int)curExp}/{levelUpExp}";
|
|
}
|
|
).OnComplete(() => anim_levelCoin.Play()).SetId("BPFill1");
|
|
await Task.Delay((int)((_fillTime + _levelUpWaitTime) * 1000), token);
|
|
if (this == null)
|
|
{
|
|
return;
|
|
}
|
|
curNextLevel++;
|
|
txt_level.text = (curNextLevel).ToString();
|
|
img_expBar.fillAmount = 0f;
|
|
curExp = 0;
|
|
levelUpExp = _dataProvider.GetTotalExpFromLevelRange(curNextLevel - 1, curNextLevel);
|
|
txt_exp.text = $"{(int)curExp}/{levelUpExp}";
|
|
}
|
|
else
|
|
{
|
|
var targetExp = _dataProvider.Data.BattlePassRecord.Exp;
|
|
//满级了
|
|
if (_dataProvider.GetBPCurLevel == maxLevel)
|
|
{
|
|
|
|
levelUpExp = _dataProvider.GetTotalExpFromLevelRange(_dataProvider.BPMaxLevel - 1, _dataProvider.BPMaxLevel);
|
|
targetExp += levelUpExp;
|
|
}
|
|
var curRate = 0f;
|
|
var txts = txt_exp.text.Split('/');
|
|
var curFillAmount = (float)int.Parse(txts[0]) / (float)int.Parse(txts[1]);
|
|
DOTween.To(
|
|
() => curFillAmount,
|
|
(value) => curRate = value,
|
|
(float)targetExp / (float)levelUpExp,
|
|
_fillTime
|
|
).OnUpdate(
|
|
|
|
() =>
|
|
{
|
|
img_expBar.fillAmount = curRate;
|
|
var curExp = curRate * levelUpExp;
|
|
|
|
txt_exp.text = $"{(int)curExp}/{levelUpExp}";
|
|
}
|
|
);
|
|
|
|
await Task.Delay((int)(_fillTime * 1000), token);
|
|
if (this == null)
|
|
{
|
|
return;
|
|
}
|
|
break;
|
|
}
|
|
|
|
} while (curNextLevel <= newNextLevel && curNextLevel <= maxLevel);
|
|
}
|
|
catch (OperationCanceledException)
|
|
{
|
|
DOTween.Kill("BPFill1");
|
|
DOTween.Kill("BPFill2");
|
|
return;
|
|
}
|
|
finally
|
|
{
|
|
}
|
|
txt_level.text = $"{newNextLevel}";
|
|
if (_dataProvider.GetBPCurLevel == maxLevel)
|
|
{
|
|
txt_exp.text = LocalizationMgr.GetText("UI_FishingRodPanel_Advanced_18");
|
|
return;
|
|
}
|
|
txt_exp.text = $"{(int)(_dataProvider.Data.BattlePassRecord.Exp + (_dataProvider.GetBPCurLevel == maxLevel ? 1000 : 0))}/{_dataProvider.GetTotalExpFromLevelRange(_dataProvider.GetBPNextLevel - 1, _dataProvider.GetBPNextLevel)}";
|
|
// txt_level.text = newLevel.ToString();
|
|
|
|
if (_dataProvider.CheckIfPopBuyVipPanel())
|
|
{
|
|
await UIManager.Instance.ShowUI(UITypes.BattlePassBuyNoticePopupPanel);
|
|
_dataProvider.UpdateVipToastLevel();
|
|
}
|
|
}
|
|
|
|
}
|