using GameCore; using TMPro; using UnityEngine; using UnityEngine.UI; using DG.Tweening; using asap.core; public class EventBingoTaskView : MonoBehaviour { [SerializeField] private Image progressBar; [SerializeField] private TMP_Text textProgress, textLevel, textProgressMax; [SerializeField] private Button btnBattlePass; [SerializeField] private Animation ani; private float _progressGrowthDuration = 0.3f; private const float RewardFlyDuration = 1.2f; private int _currentLevel, _currentExp, _currentMaxExp; private void Start() { btnBattlePass.onClick.AddListener(OnClickBattlePass); } public void Init(MiniBattlePassProgressInfo info) { progressBar.fillAmount = info.FillAmount; if (info.IsAtMaxLevel) { textProgress.gameObject.SetActive(false); textProgressMax.gameObject.SetActive(true); } else { textProgress.text = info.MaxExpForNextLevel.ToString(); textProgress.gameObject.SetActive(true); textProgressMax.gameObject.SetActive(false); } textProgress.text = info.CurrentExp + "/" + info.MaxExpForNextLevel; _currentLevel = info.CurrentLevel; _currentExp = info.CurrentExp; _currentMaxExp = info.MaxExpForNextLevel; textLevel.text = GetLevel(info).ToString(); } public async System.Threading.Tasks.Task UpdateProgress() { var bpData = GContext.container.Resolve().GetModel(MiniBattlePassType.Bingo); var info = bpData.GetUiProgressInfo(); int _previousMaxExp; while (_currentLevel < info.CurrentLevel) { _previousMaxExp = _currentLevel < 0 ? 0 : bpData.ProgressList[_currentLevel]; _currentMaxExp = bpData.ProgressList[_currentLevel + 1] - _previousMaxExp; Debug.Log($"[EventBingo] Progress: {_currentLevel}"); progressBar.DOFillAmount(1.0f, _progressGrowthDuration); await DOTween.To(() => _currentExp, x => _currentExp = x, _currentMaxExp, _progressGrowthDuration) .OnUpdate(() => { textProgress.text = $"{_currentExp}/{_currentMaxExp}"; }) .AsyncWaitForCompletion(); _currentLevel++; _currentExp = 0; if (!info.IsAtMaxLevel) progressBar.fillAmount = 0; _currentMaxExp = bpData.ProgressList[_currentLevel] - (_currentLevel < 1 ? 0 : bpData.ProgressList[_currentLevel - 1]); textLevel.text = GetLevel(info).ToString(); ani.Play(); await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(45f / 60)); } if (info.IsAtMaxLevel) { textProgress.gameObject.SetActive(false); textProgressMax.gameObject.SetActive(true); progressBar.DOFillAmount(1.0f, _progressGrowthDuration); } else { _currentMaxExp = info.MaxExpForNextLevel; _previousMaxExp = _currentLevel <= 0 ? 0 : bpData.ProgressList[_currentLevel - 1]; progressBar.DOFillAmount((float)info.CurrentExp / _currentMaxExp, _progressGrowthDuration); await DOTween.To(() => _currentExp, x => _currentExp = x, info.CurrentExp, _progressGrowthDuration) .OnUpdate(() => { textProgress.text = $"{_currentExp}/{_currentMaxExp}"; }) .AsyncWaitForCompletion(); } } private async void OnClickBattlePass() { try { await UIManager.Instance.ShowUINotLoading(UITypes.EventBingoBattlePassPanel); } catch (System.Exception e) { Debug.Log($"[EventBingoTaskView]{e.Message}\n{e.StackTrace}"); } } private int GetLevel(MiniBattlePassProgressInfo info) { return info.CurrentLevel + 2 >= info.MaxLevelCount ? info.MaxLevelCount : info.CurrentLevel + 2; } }