You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

129 lines
4.0 KiB

  1. using System;
  2. using CIG.Extensions;
  3. using CIG.Translation;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using UnityEngine;
  7. public class DropChestHUDButton : MonoBehaviour
  8. {
  9. private void OnEnable()
  10. {
  11. this.UpdateButton();
  12. }
  13. private void OnDestroy()
  14. {
  15. if (this._manager != null)
  16. {
  17. this._manager.StateChangedEvent -= this.UpdateButton;
  18. this._manager = null;
  19. }
  20. this.CancelInvoke(new Action(this.UpdateDropTime));
  21. this.CancelInvoke(new Action(this.ShowOrUpdateTimerPopup));
  22. }
  23. public void Init(CIGDropChestManager manager)
  24. {
  25. if (this._manager != null)
  26. {
  27. this._manager.StateChangedEvent -= this.UpdateButton;
  28. }
  29. this._manager = manager;
  30. if (this._manager != null)
  31. {
  32. this._manager.StateChangedEvent += this.UpdateButton;
  33. }
  34. this.UpdateButton();
  35. }
  36. public void OnHUDButtonClick()
  37. {
  38. if (this._manager != null)
  39. {
  40. if (this._manager.State == CIGDropChestManager.ChestState.Ready)
  41. {
  42. SingletonMonobehaviour<PopupManager>.Instance.RequestPopup<GenericPopupState>(delegate(State state)
  43. {
  44. ((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);
  45. });
  46. }
  47. else if (this._manager.State == CIGDropChestManager.ChestState.Timer)
  48. {
  49. this.ShowOrUpdateTimerPopup();
  50. this.CancelInvoke(new Action(this.ShowOrUpdateTimerPopup));
  51. this.InvokeRepeating(new Action(this.ShowOrUpdateTimerPopup), 1f, 1f, true);
  52. }
  53. }
  54. }
  55. private void TimerPopupClosed()
  56. {
  57. this.CancelInvoke(new Action(this.ShowOrUpdateTimerPopup));
  58. }
  59. private void ShowOrUpdateTimerPopup()
  60. {
  61. if (this._manager != null)
  62. {
  63. SingletonMonobehaviour<PopupManager>.Instance.ShowOrUpdateGenericPopup(UISpriteType.ChestParachute, Localization.Key("chest_dropping"), Localization.Format(Localization.Key("available_in_x_time"), new ILocalizedString[]
  64. {
  65. Localization.TimeSpan(TimeSpan.FromSeconds((double)this._manager.RemainingTimeUntilDrop), false)
  66. }), Localization.Key("ok"), null, new Action(this.TimerPopupClosed), null, new Action(this.TimerPopupClosed), true);
  67. }
  68. else
  69. {
  70. bool suppressQueue = SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue;
  71. SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue = true;
  72. SingletonMonobehaviour<PopupManager>.Instance.CloseRecursive(true);
  73. this.TimerPopupClosed();
  74. SingletonMonobehaviour<PopupManager>.Instance.SuppressQueue = suppressQueue;
  75. }
  76. }
  77. private void UpdateButton()
  78. {
  79. this.CancelInvoke(new Action(this.UpdateDropTime));
  80. if (this._manager == null)
  81. {
  82. base.gameObject.SetActive(false);
  83. return;
  84. }
  85. switch (this._manager.State)
  86. {
  87. case CIGDropChestManager.ChestState.Disabled:
  88. case CIGDropChestManager.ChestState.Dropped:
  89. base.gameObject.SetActive(false);
  90. this.CancelInvoke(new Action(this.UpdateDropTime));
  91. break;
  92. case CIGDropChestManager.ChestState.Timer:
  93. case CIGDropChestManager.ChestState.Ready:
  94. base.gameObject.SetActive(true);
  95. this._dropChestCheck.SetActive(this._manager.State == CIGDropChestManager.ChestState.Ready);
  96. this._dropChestRemainingTimeLabel.gameObject.SetActive(this._manager.State == CIGDropChestManager.ChestState.Timer);
  97. if (base.gameObject.activeInHierarchy)
  98. {
  99. this.UpdateDropTime();
  100. if (this._manager.RemainingTimeUntilDrop > 0f)
  101. {
  102. this.InvokeRepeating(new Action(this.UpdateDropTime), 1f, 1f, true);
  103. }
  104. }
  105. break;
  106. }
  107. }
  108. private void UpdateDropTime()
  109. {
  110. this._dropChestRemainingTimeLabel.LocalizedString = Localization.TimeSpan(TimeSpan.FromSeconds((double)this._manager.RemainingTimeUntilDrop), false);
  111. }
  112. [SerializeField]
  113. private GameObject _dropChestCheck;
  114. [SerializeField]
  115. private LocalizedText _dropChestRemainingTimeLabel;
  116. private CIGDropChestManager _manager;
  117. }