105 lines
3.5 KiB
C#
105 lines
3.5 KiB
C#
using UnityEngine;
|
|
using TMPro;
|
|
using UnityEngine.UI;
|
|
using asap.core;
|
|
using GameCore;
|
|
using UniRx;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
|
|
public class EventOfferJourneyEntranceBtn : EventButtonResource
|
|
{
|
|
[SerializeField] private TMP_Text textTimer;
|
|
[SerializeField] private Button button;
|
|
[SerializeField] private Image icon;
|
|
private ILoadResourceService _loadResourceService;
|
|
private EventOfferJourneyEntranceData _data;
|
|
|
|
private void Awake()
|
|
{
|
|
// CheckForLevelTriggerPack();
|
|
var model = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
if (model == null)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
_data = model.ToEntranceData();
|
|
if (!_data.IsActive)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
UpdateTimer();
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(this);
|
|
_loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
button.onClick.AddListener(OpenPanel);
|
|
RedPointManager.Instance.SetRedPointState(model.RedPointKey, _data.DoNeedRedPoint);
|
|
CheckResource(new List<string>() { UITypes.EventOfferJourneyPanel.Path, _data.IconUrl });
|
|
GContext.OnEvent<EventOfferJourneyHideEntrance>().Subscribe(_ => { gameObject.SetActive(false); }).AddTo(this);
|
|
}
|
|
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
textTimer.text = ConvertTools.ConvertTime2(_data.RemainingTime);
|
|
if (!_data.IsActive && gameObject.activeSelf)
|
|
{
|
|
// Debug.Log("[EventLuckMagic] Time's up in entrance!");
|
|
// var _model = GContext.container.Resolve<EventLuckMagicModel>();
|
|
// _model?.DisposeLuckyTaskSubscription();
|
|
// GContext.container.Unregister<EventLuckMagicModel>();
|
|
gameObject.SetActive(false);
|
|
}
|
|
}
|
|
|
|
private async void OpenPanel()
|
|
{
|
|
try
|
|
{
|
|
bool isReady = await _loadResourceService.Loads(
|
|
new List<string>() { UITypes.EventOfferJourneyPanel.Path });
|
|
if (isReady)
|
|
{
|
|
await UIManager.Instance.ShowUINotLoading(UITypes.EventOfferJourneyPanel);
|
|
}
|
|
else
|
|
{
|
|
//TODO: Maybe some minor loading UI?
|
|
}
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
Debug.Log($"<color=#22a6f2>[EventOfferJourney] OpenPanelError: {e.Message}\n{e.StackTrace}</color>");
|
|
throw;
|
|
}
|
|
}
|
|
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
if (_data.IsActive)
|
|
{
|
|
GContext.container.Resolve<IUIService>().SetImageSprite(icon, _data.IconUrl);
|
|
gameObject.SetActive(true);
|
|
}
|
|
}
|
|
|
|
private void CheckForLevelTriggerPack()
|
|
{
|
|
var ctx = new EventOfferJourneyLvlTriggerTableContext();
|
|
if (!ctx.IsEventActive)
|
|
return;
|
|
var pfData = EventOfferJourneyLvlTriggerPlayfabData.Load();
|
|
if (pfData != null && pfData.RoundCount >= ctx.MaxRoundCount)
|
|
return;
|
|
GContext.container.Register<IEventOfferJourneyData, EventOfferJourneyLvlTriggerData>().AsSingleton();
|
|
var model = GContext.container.Resolve<IEventOfferJourneyData>();
|
|
if (!model.LoadDataFromPlayfab())
|
|
{
|
|
(model as EventOfferJourneyLvlTriggerData).Init();
|
|
}
|
|
var uiData = model.GetUiData();
|
|
UITypes.EventOfferJourneyPanel.SetType(uiData.PanelUrl);
|
|
UITypes.EventPartnerInfoPopupPanel.SetType(uiData.InfoPanelUrl);
|
|
}
|
|
}
|