142 lines
4.8 KiB
C#
142 lines
4.8 KiB
C#
using asap.core;
|
|
using GameCore;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UniRx;
|
|
using UnityEngine.UI;
|
|
using game;
|
|
|
|
public class EventOfferJourneyPanel : MonoBehaviour
|
|
{
|
|
[SerializeField] private AEventOfferJourneyScroller scroller;
|
|
[SerializeField] private int jumpToProgress;
|
|
[SerializeField] private RewardItemNew[] grandPrizeView;
|
|
[SerializeField] private TMP_Text textTicketCount;
|
|
[SerializeField] private Button btnTip, btnInfo;
|
|
[SerializeField] private EventOfferJourneyTipView goTip;
|
|
[SerializeField] private BingoTimer timer;
|
|
[SerializeField] private CloseSelfPanel closeSelfReference;
|
|
[SerializeField] private float initialScrollDuration = 0.8f;
|
|
private int _progress;
|
|
private string PlayerPreferenceKey => "EventOfferJourneyPop" + GContext.container.Resolve<IUserService>().UserId;
|
|
|
|
private void Start()
|
|
{
|
|
var data = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
var rewardList = data.GetRewardList();
|
|
rewardList.Reverse();
|
|
var grandPrize = rewardList[0];
|
|
var grandRewardItems = GContext.container.Resolve<PlayerItemData>()
|
|
.GetItemDataByDropIdLureInflation(null, grandPrize.DropId);
|
|
for (int i = 0; i < grandPrizeView.Length; i++)
|
|
{
|
|
if (i >= grandRewardItems.Count)
|
|
grandPrizeView[i].gameObject.SetActive(false);
|
|
else
|
|
{
|
|
grandPrizeView[i].gameObject.SetActive(true);
|
|
grandPrizeView[i].SetData(grandRewardItems[i]);
|
|
}
|
|
}
|
|
scroller.Init(rewardList, data.GetStartPosParam());
|
|
UpdataTicketCount();
|
|
GContext.OnEvent<EventTicketUpdate>().Subscribe(_ => UpdataTicketCount()).AddTo(this);
|
|
GContext.OnEvent<EventOfferJourneyDisplayEnd>().Subscribe(_ => RefreshPanel()).AddTo(this);
|
|
GContext.OnEvent<EventOfferJourneyClosePanel>().Subscribe(OnRequestClose).AddTo(this);
|
|
_progress = data.Progress;
|
|
btnInfo.onClick.AddListener(OnClickInfo);
|
|
btnTip.onClick.AddListener(OnClickTip);
|
|
goTip.gameObject.SetActive(false);
|
|
timer.Init(data.ToTimerData(closeSelfReference.OnClickClose));
|
|
InitSequence();
|
|
// if (data is EventOfferJourneyData journeyData)
|
|
// Debug.Log($"[EventOfferJourneyPanel] On Open, Recorded vipLvl:{journeyData.VipLvlOnTrigger}, actual vipLvl:{GContext.container.Resolve<PlayerData>().PriceLv}");
|
|
}
|
|
|
|
private void UpdataTicketCount()
|
|
{
|
|
var data = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
var count = data.TicketCount;
|
|
count = count > 999 ? 999 : count;
|
|
textTicketCount.text = count.ToString();
|
|
}
|
|
|
|
private void RefreshPanel()
|
|
{
|
|
try
|
|
{
|
|
var data = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
if (_progress == data.Progress)
|
|
return;
|
|
_progress = data.Progress;
|
|
scroller.JumpTo(_progress);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (Input.GetKeyDown(KeyCode.J))
|
|
{
|
|
scroller.JumpTo(jumpToProgress);
|
|
}
|
|
}
|
|
|
|
private async void OnClickInfo()
|
|
{
|
|
try
|
|
{
|
|
await UIManager.Instance.ShowUINotLoading(UITypes.EventOfferJourneyInfoPanel);
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.Log($"[EventOfferJourney]{e.Message}\n{e.StackTrace}");
|
|
}
|
|
}
|
|
|
|
private void OnClickTip()
|
|
{
|
|
if (goTip == null)
|
|
return;
|
|
goTip.gameObject.SetActive(true);
|
|
}
|
|
|
|
private async void InitSequence()
|
|
{
|
|
try
|
|
{
|
|
var data = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
var ppEventId = PlayerPrefs.GetInt(PlayerPreferenceKey);
|
|
var maxProgress = data.GetRewardList().Count - 1;
|
|
scroller.JumpTo(_progress, 0.001f);
|
|
if (ppEventId == data.EventId)
|
|
{
|
|
return;
|
|
}
|
|
PlayerPrefs.SetInt(PlayerPreferenceKey, data.EventId);
|
|
PlayerPrefs.Save();
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(0.001f));
|
|
scroller.JumpTo(maxProgress, initialScrollDuration);
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(initialScrollDuration));
|
|
OnClickTip();
|
|
}
|
|
catch (System.Exception e)
|
|
{
|
|
Debug.LogError(e);
|
|
}
|
|
}
|
|
|
|
private async void OnRequestClose(EventOfferJourneyClosePanel _)
|
|
{
|
|
await System.Threading.Tasks.Task.Delay(System.TimeSpan.FromSeconds(0.3f));
|
|
closeSelfReference.OnClickClose();
|
|
}
|
|
}
|
|
|
|
public class EventOfferJourneyDisplayEnd { }
|
|
public class EventOfferJourneyClosePanel { }
|
|
public class EventOfferJourneyHideEntrance { }
|