| New file |
| | |
| | | using System;
|
| | | using System.Collections; |
| | | using System.Collections.Generic; |
| | | using UnityEngine; |
| | | using UnityEngine.UI;
|
| | |
|
| | | namespace Snxxz.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;
|
| | |
|
| | | 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;
|
| | | requireRemind = SatisfyRemindCondition() && model.RequireFairyLeagueRemind(1)
|
| | | && TryGetStartTime(out startTime);
|
| | | m_Container.gameObject.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;
|
| | | requireRemind = false;
|
| | | }
|
| | |
|
| | | private void OnPerSecond()
|
| | | {
|
| | | if (requireRemind)
|
| | | {
|
| | | DisplayTimer();
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnRefreshFairyInfo()
|
| | | {
|
| | | OnRefreshFairyLeagueEvent();
|
| | | }
|
| | |
|
| | | private void OnFuncStateChangeEvent(int id)
|
| | | {
|
| | | if (id == (int)FuncOpenEnum.FairyLeague)
|
| | | {
|
| | | OnRefreshFairyLeagueEvent();
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnFairyLeagueBattleEvent()
|
| | | {
|
| | | requireRemind = SatisfyRemindCondition() && model.RequireFairyLeagueRemind(1)
|
| | | && TryGetStartTime(out startTime);
|
| | | m_Container.gameObject.SetActive(requireRemind);
|
| | | if (requireRemind)
|
| | | {
|
| | | DisplayTimer();
|
| | | }
|
| | | }
|
| | |
|
| | | private void OnRefreshFairyLeagueEvent()
|
| | | {
|
| | | requireRemind = SatisfyRemindCondition() && model.RequireFairyLeagueRemind(1)
|
| | | && TryGetStartTime(out startTime);
|
| | | m_Container.gameObject.SetActive(requireRemind);
|
| | | if (requireRemind)
|
| | | {
|
| | | DisplayTimer();
|
| | | }
|
| | | }
|
| | |
|
| | | bool SatisfyRemindCondition()
|
| | | {
|
| | | var fairyLeagueStage = model.fairyLeagueStage;
|
| | | var session = model.fairyLeagueSession;
|
| | | return fairyLeagueStage == FairyLeagueStage.Grouping && session == 1;
|
| | | }
|
| | |
|
| | | 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);
|
| | | }
|
| | | }
|
| | | } |
| | | |