Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

177 rindas
4.1 KiB

  1. using System;
  2. using CIG.Extensions;
  3. using CIG3.ExtensionMethods;
  4. using Inno.DLC;
  5. using SUISS.Core;
  6. using SUISS.Scheduling;
  7. using SUISS.Storage;
  8. using SUISSEngine;
  9. using UnityEngine;
  10. public class CIGDLCDownloader : MonoBehaviour
  11. {
  12. public static double AllowedToAskTimestamp
  13. {
  14. get
  15. {
  16. return Storage.Get(StorageLifecycle.Player).Root.GetValue("AskDLCTimestamp", 0.0);
  17. }
  18. set
  19. {
  20. Storage.Get(StorageLifecycle.Player).Root["AskDLCTimestamp"] = value;
  21. }
  22. }
  23. public bool IsDone
  24. {
  25. get
  26. {
  27. return this._done;
  28. }
  29. }
  30. public void ShowPopup()
  31. {
  32. this.CancelInvoke(new Action(this.TryShow));
  33. if (this._group != null)
  34. {
  35. DLCGroup group = this._group;
  36. this._popupRequest = SingletonMonobehaviour<PopupManager>.Instance.RequestFirstPopup<DownloadChoicePopupState>(delegate(State state)
  37. {
  38. if (this != null)
  39. {
  40. PopupRequest? popupRequest = this._popupRequest;
  41. if (popupRequest != null)
  42. {
  43. this._popupRequest = null;
  44. }
  45. }
  46. DownloadChoicePopupState downloadChoicePopupState = state as DownloadChoicePopupState;
  47. if (downloadChoicePopupState != null)
  48. {
  49. downloadChoicePopupState.Setup(group);
  50. }
  51. else
  52. {
  53. UnityEngine.Debug.LogError("Wrong type for popup state");
  54. }
  55. });
  56. }
  57. else
  58. {
  59. UnityEngine.Debug.LogError("Group is null");
  60. }
  61. }
  62. public void Check()
  63. {
  64. if (this.cityIsland != null)
  65. {
  66. string text = this.cityIsland.island.ToString();
  67. DLCManager dlcmanager = ServiceLocator.Find<DLCManager>();
  68. if (dlcmanager != null && dlcmanager.IsEnabled)
  69. {
  70. this._group = dlcmanager.GetGroup(text);
  71. if (this._group != null)
  72. {
  73. long remainingDownloadSize = this._group.RemainingDownloadSize;
  74. this._done = (remainingDownloadSize == 0L);
  75. }
  76. else
  77. {
  78. UnityEngine.Debug.LogError(string.Format("Group {0} not found.", text));
  79. }
  80. }
  81. else
  82. {
  83. UnityEngine.Debug.LogWarning("No DLC manager found");
  84. }
  85. }
  86. else
  87. {
  88. UnityEngine.Debug.LogError("No CityIsland linked");
  89. }
  90. if (this._done)
  91. {
  92. if (this._requestedSettingsExclamation)
  93. {
  94. SingletonMonobehaviour<PopupManager>.Instance.fsm.GetState<HUDState>().PopSettingsExclamationRequest(this);
  95. this._requestedSettingsExclamation = false;
  96. }
  97. this._group = null;
  98. }
  99. else if (!this._requestedSettingsExclamation)
  100. {
  101. SingletonMonobehaviour<PopupManager>.Instance.fsm.GetState<HUDState>().PushSettingsExclamationRequest(this);
  102. this._requestedSettingsExclamation = true;
  103. }
  104. }
  105. private void Start()
  106. {
  107. this.Check();
  108. if (!this._done)
  109. {
  110. if (Timing.UtcNow > CIGDLCDownloader.AllowedToAskTimestamp)
  111. {
  112. this.InvokeRepeating(new Action(this.TryShow), 2f, 1f, false);
  113. }
  114. else
  115. {
  116. UnityEngine.Debug.Log(string.Format("Will ask in {0} days", (CIGDLCDownloader.AllowedToAskTimestamp - Timing.UtcNow) / 86400.0));
  117. }
  118. }
  119. }
  120. private void OnDestroy()
  121. {
  122. if (SingletonMonobehaviour<PopupManager>.IsAvailable)
  123. {
  124. PopupRequest? popupRequest = this._popupRequest;
  125. if (popupRequest != null)
  126. {
  127. PopupManager instance = SingletonMonobehaviour<PopupManager>.Instance;
  128. PopupRequest? popupRequest2 = this._popupRequest;
  129. instance.RemovePopupRequest(popupRequest2.Value);
  130. }
  131. if (this._requestedSettingsExclamation)
  132. {
  133. SingletonMonobehaviour<PopupManager>.Instance.fsm.GetState<HUDState>().PopSettingsExclamationRequest(this);
  134. this._requestedSettingsExclamation = false;
  135. }
  136. }
  137. }
  138. private void TryShow()
  139. {
  140. if (SingletonMonobehaviour<WorldMap>.Instance.IsVisible)
  141. {
  142. return;
  143. }
  144. if (this._group == null)
  145. {
  146. this.Check();
  147. if (this._done)
  148. {
  149. this.CancelInvoke(new Action(this.TryShow));
  150. }
  151. return;
  152. }
  153. this.ShowPopup();
  154. }
  155. [SerializeField]
  156. [SelfReference]
  157. private CityIsland cityIsland;
  158. private bool _requestedSettingsExclamation;
  159. private const string TimestampKey = "AskDLCTimestamp";
  160. private bool _done;
  161. private DLCGroup _group;
  162. private PopupRequest? _popupRequest;
  163. }