备份CatanBuilding瘦身独立工程
This commit is contained in:
217
Assets/Scripts/EventBingo/ProgressChainPackPanel.cs
Normal file
217
Assets/Scripts/EventBingo/ProgressChainPackPanel.cs
Normal file
@@ -0,0 +1,217 @@
|
||||
// Modified from ThanksGivingPackPanel. All Rights Reserved...?
|
||||
using System;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using asap.core;
|
||||
using DG.Tweening;
|
||||
using game;
|
||||
using GameCore;
|
||||
using UniRx;
|
||||
|
||||
public class ProgressChainPackPanel : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TMP_Text textTimer, textProgress, textComplete;
|
||||
[SerializeField] private Image barProgress;
|
||||
[SerializeField] private RewardItemNew tokenIcon, rewardProgress;
|
||||
[SerializeField] private ThanksGivingChainSlot[] slots;
|
||||
[SerializeField] private ThanksGivingChainSlot slot6;
|
||||
[SerializeField] private Button btnClose;
|
||||
[SerializeField] private Animation targetAnimation, contentAnimation;
|
||||
[SerializeField] private float jiandaProgressBarIncreaseTime;
|
||||
private readonly IEventAggregator _eventAggregator = new EventAggregator();
|
||||
private static readonly int[] IndexFromToSlotIndex = { 0, 1, 3, 2, 4, 5 };
|
||||
private IProgressChainPackData _data;
|
||||
private int _visualProgress;
|
||||
|
||||
private const string ContentAnimationShiftKey = "item_change",
|
||||
ContentAnimationIdleKey = "item_normal";
|
||||
|
||||
private void Start()
|
||||
{
|
||||
btnClose.onClick.AddListener(OnClickClose);
|
||||
}
|
||||
|
||||
public void Init(IProgressChainPackData data)
|
||||
{
|
||||
_data = data;
|
||||
for (int i = 0; i < IndexFromToSlotIndex.Length; i++) // The idx here is a little confusing....
|
||||
slots[i].Init(IndexFromToSlotIndex[i], _data, _eventAggregator);
|
||||
_eventAggregator.GetEvent<EventThanksGivingSlotClaimed>().Subscribe(OnClaim).AddTo(this);
|
||||
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
|
||||
Observable.Interval(TimeSpan.FromSeconds(1.0f)).Subscribe(_ =>
|
||||
{
|
||||
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
|
||||
if (_data.RemainingTime.TotalSeconds <= 0) OnClickClose();
|
||||
}).AddTo(this);
|
||||
_visualProgress = _data.TokenProgress;
|
||||
InitTargetProgress();
|
||||
contentAnimation.Play(ContentAnimationIdleKey);
|
||||
}
|
||||
|
||||
private const string BubbleKey = "bubble_task";
|
||||
|
||||
/// <summary>
|
||||
/// Triggered when player click the claim button on the reward panel. Important.
|
||||
/// </summary>
|
||||
/// <param name="e">Contains the index of the slot that is being called.</param>
|
||||
private void OnClaim(EventThanksGivingSlotClaimed e)
|
||||
{
|
||||
StopAllCoroutines();
|
||||
StartCoroutine(PlayButtonChange(e));
|
||||
StartCoroutine(PlayProgressBar(e));
|
||||
StartCoroutine(ShiftSlots());
|
||||
}
|
||||
|
||||
[SerializeField] private float jiandaParticleDelay;
|
||||
|
||||
private IEnumerator PlayParticle(EventThanksGivingSlotClaimed e)
|
||||
{
|
||||
yield return new WaitForSeconds(jiandaParticleDelay);
|
||||
var slot = slots[IndexFromToSlotIndex[e.SlotIdx]];
|
||||
slot.RewardPanelCallbackSubscription?.Dispose();
|
||||
slot.PlayParticle();
|
||||
}
|
||||
|
||||
[SerializeField] private float jiandaButtonChangeDelay;
|
||||
|
||||
private IEnumerator PlayButtonChange(EventThanksGivingSlotClaimed e)
|
||||
{
|
||||
yield return new WaitForSeconds(jiandaButtonChangeDelay);
|
||||
var slot = slots[IndexFromToSlotIndex[e.SlotIdx]];
|
||||
slot.RewardPanelCallbackSubscription?.Dispose();
|
||||
slot.PlayButtonAnimation();
|
||||
slot.PlayCanvasGroupEffect(false);
|
||||
slot.SetToken(false);
|
||||
if (e.SlotIdx + 1 < IndexFromToSlotIndex.Length)
|
||||
{
|
||||
slots[IndexFromToSlotIndex[e.SlotIdx + 1]].SetLock(false);
|
||||
slots[IndexFromToSlotIndex[e.SlotIdx + 1]].PlayCanvasGroupEffect(true);
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private float jiandaProgressBarDelay;
|
||||
|
||||
private IEnumerator PlayProgressBar(EventThanksGivingSlotClaimed e)
|
||||
{
|
||||
yield return new WaitForSeconds(jiandaProgressBarDelay);
|
||||
_data.GetTokenProgressTargetByProgress(_visualProgress, out var targetDisplay,
|
||||
out var scoreDisplay);
|
||||
var midtermTarget = targetDisplay - scoreDisplay + _visualProgress;
|
||||
int rewardDropId;
|
||||
if (_data.IsChainPackDepleted)
|
||||
{
|
||||
yield return DOTween.To(() => _visualProgress, p => _visualProgress = p, midtermTarget,
|
||||
jiandaProgressBarIncreaseTime).OnUpdate(() =>
|
||||
{
|
||||
_data.GetTokenProgressTargetByProgress(_visualProgress, out targetDisplay,
|
||||
out scoreDisplay);
|
||||
textProgress.text = $"{scoreDisplay}/{targetDisplay}";
|
||||
barProgress.fillAmount = (float)scoreDisplay / targetDisplay;
|
||||
}).WaitForCompletion();
|
||||
targetAnimation.Play(BubbleKey);
|
||||
barProgress.fillAmount = 1;
|
||||
textProgress.gameObject.SetActive(false);
|
||||
textComplete.gameObject.SetActive(true);
|
||||
rewardProgress.SetReceived(true);
|
||||
GContext.Publish(new ShowData(GContext.container.Resolve<PlayerItemData>()
|
||||
.GetItemDataByDropId(e.ProgressRewardGot[0], afterAdding: true)));
|
||||
GContext.Publish(new ShowData());
|
||||
yield break;
|
||||
}
|
||||
|
||||
if (e.ProgressRewardGot.Count > 0)
|
||||
{
|
||||
yield return DOTween.To(() => _visualProgress, p => _visualProgress = p, midtermTarget,
|
||||
jiandaProgressBarIncreaseTime)
|
||||
.OnUpdate(() =>
|
||||
{
|
||||
_data.GetTokenProgressTargetByProgress(_visualProgress, out targetDisplay,
|
||||
out scoreDisplay);
|
||||
// Debug.Log($"<color=#f18c0a>{_visualProgress}: {scoreDisplay}/{targetDisplay}</color>");
|
||||
textProgress.text = $"{scoreDisplay}/{targetDisplay}";
|
||||
barProgress.fillAmount = (float)scoreDisplay / targetDisplay;
|
||||
}).WaitForCompletion();
|
||||
targetAnimation.Play(BubbleKey);
|
||||
barProgress.fillAmount = 0;
|
||||
textProgress.text = $"0/{targetDisplay}";
|
||||
yield return new WaitForSeconds(35f / 60);
|
||||
}
|
||||
|
||||
rewardDropId = _data.GetRewardDropByChainProgress(_visualProgress);
|
||||
rewardProgress.SetData(GContext.container.Resolve<PlayerItemData>()
|
||||
.GetItemDataByDropId(rewardDropId)[0]);
|
||||
yield return DOTween.To(() => _visualProgress, p => _visualProgress = p,
|
||||
_data.TokenProgress,
|
||||
jiandaProgressBarIncreaseTime)
|
||||
.OnUpdate(() =>
|
||||
{
|
||||
_data.GetTokenProgressTargetByProgress(_visualProgress, out targetDisplay,
|
||||
out scoreDisplay);
|
||||
textProgress.text = $"{scoreDisplay}/{targetDisplay}";
|
||||
barProgress.fillAmount = (float)scoreDisplay / targetDisplay;
|
||||
}).WaitForCompletion();
|
||||
if (e.ProgressRewardGot.Count > 0)
|
||||
{
|
||||
GContext.Publish(
|
||||
new ShowData(GContext.container.Resolve<PlayerItemData>()
|
||||
.GetItemDataByDropId(e.ProgressRewardGot[0], afterAdding: true)));
|
||||
GContext.Publish(new ShowData());
|
||||
}
|
||||
}
|
||||
|
||||
[SerializeField] private float jiandaSlotShiftDelay;
|
||||
|
||||
private IEnumerator ShiftSlots()
|
||||
{
|
||||
yield return new WaitForSeconds(jiandaSlotShiftDelay);
|
||||
if (!_data.IsEndGame)
|
||||
{
|
||||
slot6.Init(6, _data, _eventAggregator);
|
||||
contentAnimation.Play(ContentAnimationShiftKey);
|
||||
yield return new WaitForSeconds(35f / 60);
|
||||
contentAnimation.Play(ContentAnimationIdleKey);
|
||||
}
|
||||
|
||||
for (int i = 0;
|
||||
i < IndexFromToSlotIndex.Length;
|
||||
i++) // The idx here is a little confusing....
|
||||
{
|
||||
slots[i].Init(IndexFromToSlotIndex[i], _data, _eventAggregator);
|
||||
}
|
||||
}
|
||||
|
||||
private void OnClickClose()
|
||||
{
|
||||
RedPointManager.Instance.SetRedPointState(_data.RedPointKey, _data.DoNeedPackRedPoint);
|
||||
UIManager.Instance.DestroyUI(gameObject.name);
|
||||
}
|
||||
|
||||
private void InitTargetProgress()
|
||||
{
|
||||
if (_data.IsChainPackDepleted)
|
||||
{
|
||||
barProgress.fillAmount = 1;
|
||||
textProgress.gameObject.SetActive(false);
|
||||
textComplete.gameObject.SetActive(true);
|
||||
var rewardDropId = _data.GetRewardDropByChainProgress(_visualProgress);
|
||||
rewardProgress.SetData(GContext.container.Resolve<PlayerItemData>()
|
||||
.GetItemDataByDropId(rewardDropId)[0]);
|
||||
rewardProgress.SetReceived(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
_data.GetTokenProgressTargetByProgress(_visualProgress, out var targetDisplay,
|
||||
out var scoreDisplay);
|
||||
// Debug.Log($"<color=#f18c0a>Start {_visualProgress}-{targetDisplay} - {scoreDisplay}</color>");
|
||||
barProgress.fillAmount = scoreDisplay / (float)targetDisplay;
|
||||
textProgress.text = $"{scoreDisplay}/{targetDisplay}";
|
||||
textComplete.gameObject.SetActive(false);
|
||||
tokenIcon.SetIcon(_data.TokenIconUrl);
|
||||
var rewardDropId = _data.GetRewardDropByChainProgress(_visualProgress);
|
||||
rewardProgress.SetData(GContext.container.Resolve<PlayerItemData>()
|
||||
.GetItemDataByDropId(rewardDropId)[0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user