|
- using System;
- using CIG.Extensions;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using UnityEngine;
-
- public class DropChestHUDButton : MonoBehaviour
- {
- private void OnEnable()
- {
- this.UpdateButton();
- }
-
- private void OnDestroy()
- {
- if (this._manager != null)
- {
- this._manager.StateChangedEvent -= this.UpdateButton;
- this._manager = null;
- }
- this.CancelInvoke(new Action(this.UpdateDropTime));
- this.CancelInvoke(new Action(this.ShowOrUpdateTimerPopup));
- }
-
- public void Init(CIGDropChestManager manager)
- {
- if (this._manager != null)
- {
- this._manager.StateChangedEvent -= this.UpdateButton;
- }
- this._manager = manager;
- if (this._manager != null)
- {
- this._manager.StateChangedEvent += this.UpdateButton;
- }
- this.UpdateButton();
- }
-
- public void OnHUDButtonClick()
- {
- if (this._manager != null)
- {
- if (this._manager.State == CIGDropChestManager.ChestState.Ready)
- {
- SingletonMonobehaviour<PopupManager>.Instance.RequestPopup<GenericPopupState>(delegate(State state)
- {
- ((GenericPopupState)state).UpdateInfo(UISpriteType.ChestParachute, Localization.Key("chest_dropping"), Localization.Key("chest_dropping_message"), Localization.Key("great"), null, new Action(this._manager.DropChest), new Action(this._manager.DropChest), new Action(this._manager.DropChest), true);
- });
- }
- else if (this._manager.State == CIGDropChestManager.ChestState.Timer)
- {
- this.ShowOrUpdateTimerPopup();
- this.CancelInvoke(new Action(this.ShowOrUpdateTimerPopup));
- this.InvokeRepeating(new Action(this.ShowOrUpdateTimerPopup), 1f, 1f, true);
- }
- }
- }
-
- private void TimerPopupClosed()
- {
- this.CancelInvoke(new Action(this.ShowOrUpdateTimerPopup));
- }
-
- private void ShowOrUpdateTimerPopup()
- {
- if (this._manager != null)
- {
- SingletonMonobehaviour<PopupManager>.Instance.ShowOrUpdateGenericPopup(UISpriteType.ChestParachute, Localization.Key("chest_dropping"), Localization.Format(Localization.Key("available_in_x_time"), new ILocalizedString[]
- {
- Localization.TimeSpan(TimeSpan.FromSeconds((double)this._manager.RemainingTimeUntilDrop), false)
- }), Localization.Key("ok"), null, new Action(this.TimerPopupClosed), null, new Action(this.TimerPopupClosed), true);
- }
- else
- {
- bool suppressQueue = SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue;
- SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue = true;
- SingletonMonobehaviour<PopupManager>.Instance.CloseRecursive(true);
- this.TimerPopupClosed();
- SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue = suppressQueue;
- }
- }
-
- private void UpdateButton()
- {
- this.CancelInvoke(new Action(this.UpdateDropTime));
- if (this._manager == null)
- {
- base.gameObject.SetActive(false);
- return;
- }
- switch (this._manager.State)
- {
- case CIGDropChestManager.ChestState.Disabled:
- case CIGDropChestManager.ChestState.Dropped:
- base.gameObject.SetActive(false);
- this.CancelInvoke(new Action(this.UpdateDropTime));
- break;
- case CIGDropChestManager.ChestState.Timer:
- case CIGDropChestManager.ChestState.Ready:
- base.gameObject.SetActive(true);
- this._dropChestCheck.SetActive(this._manager.State == CIGDropChestManager.ChestState.Ready);
- this._dropChestRemainingTimeLabel.gameObject.SetActive(this._manager.State == CIGDropChestManager.ChestState.Timer);
- if (base.gameObject.activeInHierarchy)
- {
- this.UpdateDropTime();
- if (this._manager.RemainingTimeUntilDrop > 0f)
- {
- this.InvokeRepeating(new Action(this.UpdateDropTime), 1f, 1f, true);
- }
- }
- break;
- }
- }
-
- private void UpdateDropTime()
- {
- this._dropChestRemainingTimeLabel.LocalizedString = Localization.TimeSpan(TimeSpan.FromSeconds((double)this._manager.RemainingTimeUntilDrop), false);
- }
-
- [SerializeField]
- private GameObject _dropChestCheck;
-
- [SerializeField]
- private LocalizedText _dropChestRemainingTimeLabel;
-
- private CIGDropChestManager _manager;
- }
|