51 lines
1.9 KiB
C#
51 lines
1.9 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using asap.core;
|
|
using DG.Tweening;
|
|
using GameCore;
|
|
|
|
public class EventBingoTaskView : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image progressBar;
|
|
[SerializeField] private RewardItemNew reward, finalReward;
|
|
[SerializeField] private TMP_Text textProgress;
|
|
private int _taskId;
|
|
private float _progressGrowthDuration = 0.3f;
|
|
private ItemData _reward;
|
|
private const float RewardFlyDuration = 1.2f;
|
|
public int TaskId => _taskId;
|
|
|
|
public void Init(EventBingoProgressTaskData taskData)
|
|
{
|
|
progressBar.fillAmount = taskData.Progress / (float)taskData.TargetProgress;
|
|
reward.SetData(taskData.Reward);
|
|
textProgress.text = taskData.Progress + "/" + taskData.TargetProgress;
|
|
_taskId = taskData.TaskId;
|
|
_reward = taskData.Reward;
|
|
var bingoModel = GContext.container.Resolve<EventBingoModel>();
|
|
var fr = bingoModel.Ctx.GetProgressTaskFinalReward();
|
|
finalReward.SetData(fr);
|
|
}
|
|
|
|
public async System.Threading.Tasks.Task UpdateProgress()
|
|
{
|
|
var newData = GContext.container.Resolve<EventBingoModel>().TaskData;
|
|
if (newData.TaskId == _taskId)
|
|
{
|
|
var newProgress = newData.Progress / (float)newData.TargetProgress;
|
|
progressBar.DOFillAmount(newProgress, _progressGrowthDuration);
|
|
textProgress.text = newData.Progress + "/" + newData.TargetProgress;
|
|
}
|
|
else
|
|
{
|
|
var s = textProgress.text;
|
|
var tokens = s.Split('/');
|
|
textProgress.text = tokens[1] + "/" + tokens[1];
|
|
await progressBar.DOFillAmount(1, _progressGrowthDuration).AsyncWaitForCompletion();
|
|
GContext.Publish(new EventRewardFlyStashRequest(_reward, reward.icon.GetComponent<RectTransform>()));
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(RewardFlyDuration));
|
|
Init(newData);
|
|
}
|
|
}
|
|
} |