131 lines
3.3 KiB
C#
131 lines
3.3 KiB
C#
using asap.core;
|
|
using cfg;
|
|
using GameCore;
|
|
using System;
|
|
using TMPro;
|
|
using UniRx;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class HomeBtnComeBack : MonoBehaviour
|
|
{
|
|
EventWelcomeBackManager manager;
|
|
Tables tables;
|
|
TMP_Text text_time;
|
|
Button btn;
|
|
Timer timer;
|
|
public GameObject redPoint;
|
|
public GameObject redpoint_big;
|
|
public TMP_Text text_redpoint_big;
|
|
IDisposable disposable;
|
|
private void Awake()
|
|
{
|
|
manager = new EventWelcomeBackManager();
|
|
tables = GContext.container.Resolve<Tables>();
|
|
|
|
text_time = transform.Find("text_time").GetComponent<TMP_Text>();
|
|
btn = GetComponent<Button>();
|
|
disposable = GContext.OnEvent<ClaimComeBack>().Subscribe(OnClaimComeBack);
|
|
}
|
|
void Start()
|
|
{
|
|
bool isWelcomeBack = manager.CheckWelcomeBack();
|
|
gameObject.SetActive(isWelcomeBack);
|
|
if (!isWelcomeBack)
|
|
{
|
|
return;
|
|
}
|
|
btn.onClick.AddListener(OnClick);
|
|
SetEndTime();
|
|
SetRedPointState();
|
|
}
|
|
|
|
void SetEndTime()
|
|
{
|
|
DateTime endTime = manager.GetCurrentRoundEndTime();
|
|
TimeSpan now = endTime - ZZTimeHelper.UtcNow();
|
|
double seconds = now.TotalSeconds;
|
|
if (seconds <= 0)
|
|
{
|
|
TimeEnd();
|
|
return;
|
|
}
|
|
timer?.Cancel();
|
|
timer = null;
|
|
timer = this.AttachTimer((float)seconds, TimeEnd,
|
|
(elapsed) =>
|
|
{
|
|
now = endTime - ZZTimeHelper.UtcNow();
|
|
text_time.text = ConvertTools.ConvertTime2(now.Days, now.Hours, now.Minutes, now.Seconds);
|
|
}, useRealTime: true);
|
|
}
|
|
void OnClaimComeBack(ClaimComeBack claimComeBack)
|
|
{
|
|
var welcomeBackData = manager.LoadData();
|
|
if (welcomeBackData.received >= tables.TbEventWelcomeBackTimeReward.DataList.Count)
|
|
{
|
|
TimeEnd();
|
|
return;
|
|
}
|
|
if (claimComeBack.state == 2)
|
|
{
|
|
SetEndTime();
|
|
}
|
|
SetRedPointState();
|
|
}
|
|
void TimeEnd()
|
|
{
|
|
timer?.Cancel();
|
|
timer = null;
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
public void SetRedPointState()
|
|
{
|
|
int count = manager.CheckRedPoint();
|
|
|
|
bool state = count > 0;
|
|
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);
|
|
}
|
|
}
|
|
|
|
void OnClick()
|
|
{
|
|
UIManager.Instance.ShowUINotLoading(new UIType("ComebackChainsPopupPanel"));
|
|
}
|
|
private void OnDestroy()
|
|
{
|
|
disposable?.Dispose();
|
|
disposable = null;
|
|
}
|
|
}
|