119 lines
4.3 KiB
C#
119 lines
4.3 KiB
C#
using System;
|
|
using System.Collections;
|
|
using asap.core;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine.UI;
|
|
|
|
public class ShootingChainPackPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text textTimer /*,textProgress, textComplete*/;
|
|
[SerializeField] private ShootingChainSlot[] slots;
|
|
[SerializeField] private ShootingChainSlot slot6;
|
|
[SerializeField] private Button btnClose;
|
|
[SerializeField] private Animation /*targetAnimation,*/ contentAnimation;
|
|
private readonly IEventAggregator _eventAggregator = new EventAggregator();
|
|
private static readonly int[] IndexFromToSlotIndex = { 0, 1, 3, 2, 4, 5 };
|
|
private EventShootingRangeData _data;
|
|
|
|
private const string /*RedPointKey = "home.thanks_giving",*/
|
|
ContentAnimationShiftKey = "item_change",
|
|
ContentAnimationIdleKey = "item_normal";
|
|
|
|
private void Start()
|
|
{
|
|
btnClose.onClick.AddListener(OnClickClose);
|
|
_data = GContext.container.Resolve<EventShootingRangeData>();
|
|
for (int i = 0; i < IndexFromToSlotIndex.Length; i++) // The idx here is a little confusing....
|
|
{
|
|
slots[i].Init(IndexFromToSlotIndex[i], _data, _eventAggregator);
|
|
}
|
|
|
|
_eventAggregator.GetEvent<EventChainPackClaimed>().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(EventChainPackClaimed e)
|
|
{
|
|
StopAllCoroutines();
|
|
StartCoroutine(PlayParticle(e));
|
|
StartCoroutine(PlayButtonChange(e));
|
|
StartCoroutine(ShiftSlots());
|
|
}
|
|
|
|
[SerializeField] private float jiandaParticleDelay;
|
|
|
|
private IEnumerator PlayParticle(EventChainPackClaimed e)
|
|
{
|
|
yield return new WaitForSeconds(jiandaParticleDelay);
|
|
var slot = slots[IndexFromToSlotIndex[e.SlotIdx]];
|
|
slot.RewardPanelCallbackSubscription?.Dispose();
|
|
}
|
|
|
|
[SerializeField] private float jiandaButtonChangeDelay;
|
|
|
|
private IEnumerator PlayButtonChange(EventChainPackClaimed e)
|
|
{
|
|
yield return new WaitForSeconds(jiandaButtonChangeDelay);
|
|
var slot = slots[IndexFromToSlotIndex[e.SlotIdx]];
|
|
slot.RewardPanelCallbackSubscription?.Dispose();
|
|
slot.PlayButtonAnimation();
|
|
slot.PlayCanvasGroupEffect(false);
|
|
if (e.SlotIdx + 1 < IndexFromToSlotIndex.Length)
|
|
{
|
|
slots[IndexFromToSlotIndex[e.SlotIdx + 1]].SetLock(false);
|
|
slots[IndexFromToSlotIndex[e.SlotIdx + 1]].PlayCanvasGroupEffect(true);
|
|
}
|
|
}
|
|
|
|
[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(EventShootingRangeData.PackRedPointId, _data.DoNeedPackRedPoint);
|
|
UIManager.Instance.DestroyUI(UITypes.ShootingChainPackPanel);
|
|
}
|
|
|
|
// public class EventShootingRangeChainPackClaimed
|
|
// {
|
|
// public readonly int SlotIdx;
|
|
// public List<int> ProgressRewardGot;
|
|
|
|
// public EventShootingRangeChainPackClaimed(int slotIdx)
|
|
// {
|
|
// SlotIdx = slotIdx;
|
|
// }
|
|
// }
|
|
} |