111 lines
4.1 KiB
C#
111 lines
4.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using asap.core;
|
|
using GameCore;
|
|
using UnityEngine;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine.UI;
|
|
|
|
public class ChainPackPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] private TMP_Text textTimer;
|
|
[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 IChainPackData _data;
|
|
|
|
private const string ContentAnimationShiftKey = "item_change", ContentAnimationIdleKey = "item_normal";
|
|
|
|
public void Init(IChainPackData data)
|
|
{
|
|
btnClose.onClick.AddListener(OnClickClose);
|
|
_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<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);
|
|
contentAnimation.Play(ContentAnimationIdleKey);
|
|
}
|
|
|
|
/// <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());
|
|
RedPointManager.Instance.SetRedPointState(_data.RedPointKey, _data.DoNeedPackRedPoint);
|
|
}
|
|
|
|
[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....
|
|
{
|
|
// Debug.Log($"[EventBreak]Index: {IndexFromToSlotIndex[i]}");
|
|
slots[i].Init(IndexFromToSlotIndex[i], _data, _eventAggregator);
|
|
}
|
|
}
|
|
|
|
private void OnClickClose()
|
|
{
|
|
// RedPointManager.Instance.SetRedPointState(EventShootingRangeData.PackRedPointId, _data.DoNeedPackRedPoint);
|
|
UIManager.Instance.DestroyUI(gameObject.name);
|
|
}
|
|
}
|
|
public class EventChainPackClaimed
|
|
{
|
|
public readonly int SlotIdx;
|
|
public List<int> ProgressRewardGot;
|
|
|
|
public EventChainPackClaimed(int slotIdx)
|
|
{
|
|
SlotIdx = slotIdx;
|
|
}
|
|
} |