using System;
|
using System.Collections;
|
using System.Collections.Generic;
|
using UnityEngine;
|
using UnityEngine.UI;
|
|
namespace vnxbqy.UI
|
{
|
public class FairyLeagueRemindBehaviour : MonoBehaviour
|
{
|
[SerializeField] RectTransform m_Container;
|
[SerializeField] Text m_Timer;
|
[SerializeField] Button m_Goto;
|
|
FairyLeagueModel model
|
{
|
get { return ModelCenter.Instance.GetModel<FairyLeagueModel>(); }
|
}
|
|
bool requireRemind = false;
|
DateTime startTime = DateTime.Now;
|
|
float lastRequestTime = 0;
|
|
private void Awake()
|
{
|
m_Goto.AddListener(Goto);
|
}
|
|
public void Init()
|
{
|
GlobalTimeEvent.Instance.secondEvent += OnPerSecond;
|
model.OnRefreshFairyLeagueEvent += OnRefreshFairyLeagueEvent;
|
model.onFairyLeagueBattleEvent += OnFairyLeagueBattleEvent;
|
FuncOpen.Instance.OnFuncStateChangeEvent += OnFuncStateChangeEvent;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo += OnRefreshFairyInfo;
|
PlayerDatas.Instance.playerDataRefreshEvent += PlayerDataRefreshInfoEvent;
|
requireRemind = SatisfyRemindCondition() && model.RequireFairyLeagueRemind(1)
|
&& TryGetStartTime(out startTime) && !InCrossServer();
|
m_Container.SetActive(requireRemind);
|
if (requireRemind)
|
{
|
DisplayTimer();
|
}
|
}
|
|
public void UnInit()
|
{
|
GlobalTimeEvent.Instance.secondEvent -= OnPerSecond;
|
model.OnRefreshFairyLeagueEvent -= OnRefreshFairyLeagueEvent;
|
model.onFairyLeagueBattleEvent -= OnFairyLeagueBattleEvent;
|
FuncOpen.Instance.OnFuncStateChangeEvent -= OnFuncStateChangeEvent;
|
PlayerDatas.Instance.fairyData.OnRefreshFairyInfo -= OnRefreshFairyInfo;
|
PlayerDatas.Instance.playerDataRefreshEvent -= PlayerDataRefreshInfoEvent;
|
requireRemind = false;
|
}
|
|
private void OnPerSecond()
|
{
|
if (requireRemind)
|
{
|
DisplayTimer();
|
}
|
else
|
{
|
if (Time.time - lastRequestTime < 5)
|
{
|
return;
|
}
|
lastRequestTime = Time.time;
|
var fairyLeagueTime = model.currentWeekTime;
|
if (fairyLeagueTime == null || fairyLeagueTime.fairyLeagueStage != FairyLeagueStage.Grouping)
|
{
|
return;
|
}
|
var ring = fairyLeagueTime.rings[fairyLeagueTime.currentRing];
|
if (ring == null)
|
{
|
return;
|
}
|
var session = ring.sessions[ring.sessions.Count - 1];
|
if (session == null)
|
{
|
return;
|
}
|
var stage = session.stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Grouping;
|
});
|
if (stage != null)
|
{
|
if (TimeUtility.Hour == stage.startHour
|
&& TimeUtility.Minute == stage.startMinute)
|
{
|
CA001_tagViewUniversalGameRec _pak = new CA001_tagViewUniversalGameRec();
|
_pak.ViewType = (byte)FairyLeagueModel.FAIRY_LEAGUE_BATTLE;
|
GameNetSystem.Instance.SendInfo(_pak);
|
}
|
}
|
}
|
}
|
|
private void OnRefreshFairyInfo()
|
{
|
OnRefreshFairyLeagueEvent();
|
}
|
|
private void OnFuncStateChangeEvent(int id)
|
{
|
if (id == (int)FuncOpenEnum.FairyLeague)
|
{
|
OnRefreshFairyLeagueEvent();
|
}
|
}
|
|
private void PlayerDataRefreshInfoEvent(PlayerDataType refreshType)
|
{
|
if (refreshType == PlayerDataType.ExAttr5)
|
{
|
OnRefreshFairyLeagueEvent();
|
}
|
}
|
|
private void OnFairyLeagueBattleEvent()
|
{
|
requireRemind = SatisfyRemindCondition() && model.RequireFairyLeagueRemind(1)
|
&& TryGetStartTime(out startTime) && !InCrossServer();
|
m_Container.SetActive(requireRemind);
|
if (requireRemind)
|
{
|
DisplayTimer();
|
}
|
}
|
|
private void OnRefreshFairyLeagueEvent()
|
{
|
requireRemind = SatisfyRemindCondition() && model.RequireFairyLeagueRemind(1)
|
&& TryGetStartTime(out startTime) && !InCrossServer();
|
m_Container.SetActive(requireRemind);
|
if (requireRemind)
|
{
|
DisplayTimer();
|
}
|
}
|
|
bool SatisfyRemindCondition()
|
{
|
var fairyLeagueStage = model.fairyLeagueStage;
|
var session = model.fairyLeagueSession;
|
return fairyLeagueStage == FairyLeagueStage.Grouping && session == 1;
|
}
|
|
bool InCrossServer()
|
{
|
return CrossServerUtility.IsCrossServer();
|
}
|
|
bool TryGetStartTime(out DateTime time)
|
{
|
time = DateTime.Now;
|
var fairyLeagueTime = model.currentWeekTime;
|
if (fairyLeagueTime == null)
|
{
|
return false;
|
}
|
var ring = fairyLeagueTime.rings[fairyLeagueTime.currentRing];
|
var session = ring.sessions[ring.sessions.Count - 1];
|
var stage = session.stages.Find((x) =>
|
{
|
return x.stage == FairyLeagueStage.Fight;
|
});
|
time = new DateTime(TimeUtility.ServerNow.Year, TimeUtility.ServerNow.Month, TimeUtility.Day,
|
stage.startHour, stage.startMinute, 0);
|
return true;
|
}
|
|
private void DisplayTimer()
|
{
|
var seconds = (int)(startTime - TimeUtility.ServerNow).TotalSeconds;
|
seconds = Mathf.Max(0, seconds);
|
m_Timer.text = TimeUtility.SecondsToMS(seconds);
|
}
|
|
private void Goto()
|
{
|
WindowJumpMgr.Instance.WindowJumpTo(JumpUIType.UnionFunc4);
|
}
|
}
|
}
|
|