Files
ft/Client/Assets/Scripts/UI/OfferStoryChain/OfferStoryChainMainPanel.cs
2026-06-29 21:18:33 +08:00

130 lines
4.1 KiB
C#

using GameCore;
using UnityEngine;
using UnityEngine.UI;
using OfferStoryChain;
using asap.core;
using UniRx;
using game;
using System.Threading.Tasks;
using System;
public class OfferStoryChainMainPanel : MonoBehaviour
{
[SerializeField] private Button btnClose;
[SerializeField] private OfferStoryChainScrollerView scrollerView;
[SerializeField] private OfferStoryChainTaskView taskView;
[SerializeField] private OfferStoryChainAnimationCtrl spineCtrl;
[SerializeField] private BingoTimer timer;
[SerializeField] private GameObject fxFinal;
[SerializeField] private float jiandaFxDelay = 2.5f;
private int _idx;
private void Start()
{
var manager = GContext.container.Resolve<Manager>();
btnClose.onClick.AddListener(OnClickClose);
manager.EventAggregator.GetEvent<OfferStoryChainPurchaseContext>()
.Subscribe(AfterPurchase)
.AddTo(this);
GContext.OnEvent<FishingTurnTableContinueMultiDraw>()
.Subscribe(_ => AfterRewardCollection())
.AddTo(this);
Init(manager.GetMainPanelData());
fxFinal.SetActive(false);
}
public void Init(MainPanelData data)
{
var manager = GContext.container.Resolve<Manager>();
scrollerView.Init(data.ScrollerItemViewDataList);
taskView.SetIcons(data.Progress);
taskView.SetReward(data.Reward);
spineCtrl.Init(data.SpineBaseName);
spineCtrl.PlayIdleAnimation(data.Progress);
var timerCtx = manager.GetTimerData();
timerCtx.OnExpire = OnClickClose;
timer.Init(timerCtx);
}
private void OnClickClose()
{
var manager = GContext.container.Resolve<Manager>();
manager.EventAggregator.Publish(new OfferStoryChainCloseEvent());
RedPointManager.Instance.SetRedPointState(Manager.RedPointKey, manager.DoNeedRedPoint);
UIManager.Instance.DestroyUI(UITypes.OfferStoryChainPanel);
}
private async void AfterPurchase(OfferStoryChainPurchaseContext ctx)
{
try
{
Debug.Log($"[OfferStoryChain] idx main{_idx}");
_idx = ctx.Index;
await scrollerView.TickBtnBuy(ctx.Index);
GContext.Publish(new ShowData());
}
catch (System.Exception e)
{
Debug.LogError(e);
}
}
private bool _toBeClosed = false;
private async void AfterRewardCollection()
{
var manager = GContext.container.Resolve<Manager>();
RedPointManager.Instance.SetRedPointState(Manager.RedPointKey, manager.DoNeedRedPoint);
if (_toBeClosed)
{
OnClickClose();
return;
}
try
{
var PlayerItemData = GContext.container.Resolve<PlayerItemData>();
await taskView.PlayItemFly(scrollerView.GetItemStartPoint(_idx), _idx);
taskView.SetIcons(_idx + 1);
await spineCtrl.PlayUpdateAnimation(_idx + 1);
if (_idx >= manager.GetMaxProgressInRound() - 1)
{
await PlayFinishFx();
var dropId = manager.GetFinalRewardDropId(manager.RoundCount);
var finalReward = new ShowData(PlayerItemData.GetItemDataByDropIdAndTypeLureInflation(null, dropId));
GContext.Publish(finalReward);
GContext.Publish(new ShowData());
_toBeClosed = true;
}
else
{
scrollerView.JumpTo(_idx + 1);
await scrollerView.PlayUnlockAnimation(_idx + 1);
}
}
catch (System.Exception e)
{
Debug.LogError(e);
}
}
private async Task PlayFinishFx()
{
fxFinal.SetActive(false);
fxFinal.SetActive(true);
await Task.Delay(TimeSpan.FromSeconds(jiandaFxDelay));
}
// #region Test
// [Header("Test")]
// [SerializeField] private int idx;
// private void Update()
// {
// if (Input.GetKeyDown(KeyCode.Space))
// {
// scrollerView.JumpTo(idx);
// }
// }
// #endregion
}