177 lines
5.1 KiB
C#
177 lines
5.1 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using game;
|
|
using GameCore;
|
|
using System;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class HomeBtnMatch : EventButtonResource
|
|
{
|
|
private TMP_Text textTimer;
|
|
Button btn;
|
|
Image icon;
|
|
public GameObject redPoint;
|
|
public GameObject redpoint_big;
|
|
public TMP_Text text_redpoint_big;
|
|
string iconUrl;
|
|
private DateTime endDateTime;
|
|
Tables tables;
|
|
EventMatchGameManager matchGameManager;
|
|
FishingEvent fishingEvent;
|
|
protected CompositeDisposable disposables = new CompositeDisposable();
|
|
EventMatchInit eventMatchInit;
|
|
private void Awake()
|
|
{
|
|
matchGameManager = new EventMatchGameManager();
|
|
textTimer = transform.Find("text_time").GetComponent<TMP_Text>();
|
|
btn = GetComponent<Button>();
|
|
icon = transform.Find("icon").GetComponent<Image>();
|
|
}
|
|
private void Start()
|
|
{
|
|
if (!matchGameManager.CheckOpen())
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
MatchGameData matchGameData = matchGameManager.GetEventData();
|
|
GContext.OnEvent<RewardPanelClose>().Subscribe(RewardPanelClose).AddTo(disposables);
|
|
int fishingEventID = matchGameData.eventID;
|
|
//GContext.container.Resolve<IFaceUIService>().AddGiftFaceUI(fishingEventID, new UIType(EventRechargeBenefitsPanel));
|
|
tables = GContext.container.Resolve<Tables>();
|
|
fishingEvent = tables.TbFishingEvent[fishingEventID];
|
|
eventMatchInit = matchGameManager.GetMatchInitRedirectID(fishingEvent.RedirectID);
|
|
if (eventMatchInit == null)
|
|
{
|
|
gameObject.SetActive(false);
|
|
return;
|
|
}
|
|
endDateTime = DateTime.Parse((fishingEvent.TimeDefinition as LimitedTime).EndTime);
|
|
iconUrl = eventMatchInit.Icon;
|
|
TimeSpan all = GetRemainingTime(endDateTime);
|
|
textTimer.text = ConvertTools.ConvertTime2(all);
|
|
CheckResource(new List<string>
|
|
{
|
|
"MatchGameAct",
|
|
iconUrl,
|
|
eventMatchInit.UIPanel,
|
|
});
|
|
GetRed();
|
|
btn.onClick.AddListener(OnBtnEnter);
|
|
}
|
|
private void OnBtnEnter()
|
|
{
|
|
StartEnterMatchAct();
|
|
StopCountDown();
|
|
}
|
|
void StopCountDown()
|
|
{
|
|
disposables?.Dispose();
|
|
disposables = null;
|
|
}
|
|
private async void StartEnterMatchAct()
|
|
{
|
|
var loadResourceService = GContext.container.Resolve<ILoadResourceService>();
|
|
var isCanEnter = await loadResourceService.Loads(new List<string>
|
|
{
|
|
"MatchGameAct",
|
|
eventMatchInit.UIPanel,
|
|
});
|
|
|
|
if (isCanEnter)
|
|
{
|
|
EnterMatchAct();
|
|
}
|
|
else
|
|
{
|
|
var panel = await UIManager.Instance.ShowUI(UITypes.CloudTransitionPanel);
|
|
panel.GetComponent<CloudTransitionPanel>().SetBtn(true, EnterMatchAct);
|
|
}
|
|
|
|
}
|
|
private void EnterMatchAct()
|
|
{
|
|
GContext.Publish(new UnloadActToNextAct("MatchGameAct"));
|
|
}
|
|
protected override void OnLoadEventResource()
|
|
{
|
|
if (!matchGameManager.CheckOpen())
|
|
{
|
|
return;
|
|
}
|
|
UpdateTimer();
|
|
gameObject.SetActive(true);
|
|
Observable.Interval(TimeSpan.FromSeconds(1f)).Subscribe(UpdateTimer).AddTo(disposables);
|
|
_ = GContext.container.Resolve<IUIService>().SetImageSprite(icon, iconUrl);
|
|
}
|
|
private void UpdateTimer(long _ = 0L)
|
|
{
|
|
TimeSpan tmpAll = GetRemainingTime(endDateTime);
|
|
textTimer.text = ConvertTools.ConvertTime2(tmpAll);
|
|
if (tmpAll.TotalSeconds <= 0)
|
|
{
|
|
gameObject.SetActive(false);
|
|
disposables?.Dispose();
|
|
disposables = null;
|
|
}
|
|
}
|
|
void RewardPanelClose(RewardPanelClose rewardPanelClose)
|
|
{
|
|
GetRed();
|
|
}
|
|
void GetRed()
|
|
{
|
|
int count = matchGameManager.GetTokenCount(fishingEvent.ID);
|
|
SetRedPointState(count);
|
|
}
|
|
void SetRedPointState(int count)
|
|
{
|
|
bool state = count > 1;
|
|
if (redpoint_big != null && text_redpoint_big != null)
|
|
{
|
|
if (!state)
|
|
{
|
|
redpoint_big.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
if (count > 1)
|
|
{
|
|
redpoint_big.SetActive(true);
|
|
if (count > 99)
|
|
{
|
|
text_redpoint_big.text = "99+";
|
|
}
|
|
else
|
|
{
|
|
text_redpoint_big.text = count.ToString();
|
|
}
|
|
state = false;
|
|
}
|
|
else
|
|
{
|
|
redpoint_big.SetActive(false);
|
|
}
|
|
}
|
|
}
|
|
if (redPoint != null)
|
|
{
|
|
redPoint.SetActive(state);
|
|
}
|
|
}
|
|
private TimeSpan GetRemainingTime(DateTime endDateTime)
|
|
{
|
|
return endDateTime - ZZTimeHelper.UtcNow();
|
|
}
|
|
protected override void OnDestroy()
|
|
{
|
|
base.OnDestroy();
|
|
disposables?.Dispose();
|
|
disposables = null;
|
|
}
|
|
}
|