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.
 
 
 

230 regels
6.9 KiB

  1. using System;
  2. using System.Collections;
  3. using CIG.Translation;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using SUISSEngine;
  7. using UnityEngine;
  8. using UnityEngine.SceneManagement;
  9. public class SettingsPopupState : PopupBaseState
  10. {
  11. private void OnDestroy()
  12. {
  13. if (SingletonMonobehaviour<CIGGameState>.IsAvailable)
  14. {
  15. SingletonMonobehaviour<CIGGameState>.Instance.LevelledUp -= this.OnLevelledUp;
  16. }
  17. }
  18. public override void Init()
  19. {
  20. base.Init();
  21. if (StorageController.CloudStorage.CloudStorageAvailable)
  22. {
  23. SingletonMonobehaviour<CIGGameState>.Instance.LevelledUp += this.OnLevelledUp;
  24. if (SingletonMonobehaviour<CIGGameState>.Instance.Level >= 20 && Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Unknown)
  25. {
  26. this._fsm.GetState<HUDState>().PushSettingsExclamationRequest(this);
  27. }
  28. }
  29. }
  30. public override void Enter(State oldState, bool openView)
  31. {
  32. base.Enter(oldState, openView);
  33. SettingsPopupView settingsPopupView = (SettingsPopupView)this.View;
  34. settingsPopupView.UpdateGameInfo();
  35. this.CheckMusicButton();
  36. this.CheckSoundEffectsButton();
  37. this.CheckNotificationsButton();
  38. this.CheckCloudSaveButton();
  39. settingsPopupView.SetLanguageVisible(Localization.AvailableCultures.Count > 1);
  40. settingsPopupView.SetLanguage(Localization.CurrentCulture);
  41. CIGDLCDownloader cigdlcdownloader = UnityEngine.Object.FindObjectOfType<CIGDLCDownloader>();
  42. settingsPopupView.SetDownloadVisible(cigdlcdownloader != null && !cigdlcdownloader.IsDone);
  43. if (StorageController.CloudStorage.CloudStorageAvailable)
  44. {
  45. if (SingletonMonobehaviour<CIGGameState>.Instance.Level >= 20 && Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Unknown)
  46. {
  47. this._cloudStorageReminderRoutine = base.StartCoroutine(this.OpenCloudStorageReminderAfterAnimation());
  48. }
  49. }
  50. else
  51. {
  52. settingsPopupView.DisableCloudSaveButton();
  53. }
  54. }
  55. public override void ClosePopup(Action callback, bool animate, bool synchronous)
  56. {
  57. if (this._cloudStorageReminderRoutine != null)
  58. {
  59. base.StopCoroutine(this._cloudStorageReminderRoutine);
  60. }
  61. base.ClosePopup(callback, animate, synchronous);
  62. }
  63. public void ToggleMusic()
  64. {
  65. Singleton<CIGSettings>.Instance.MusicEnabled = !Singleton<CIGSettings>.Instance.MusicEnabled;
  66. this.CheckMusicButton();
  67. }
  68. public void ToggleSoundEffects()
  69. {
  70. Singleton<CIGSettings>.Instance.SoundEffectsEnabled = !Singleton<CIGSettings>.Instance.SoundEffectsEnabled;
  71. this.CheckSoundEffectsButton();
  72. }
  73. public void ToggleNotifications()
  74. {
  75. Singleton<CIGSettings>.Instance.NotificationsEnabled = !Singleton<CIGSettings>.Instance.NotificationsEnabled;
  76. this.CheckNotificationsButton();
  77. }
  78. public void ToggleCloudSaving()
  79. {
  80. if (Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Activated)
  81. {
  82. Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Deactivated;
  83. this.CheckCloudSaveButton();
  84. }
  85. else
  86. {
  87. this.OpenCloudStorageReminder();
  88. }
  89. }
  90. public void OpenLanguages()
  91. {
  92. this._fsm.SwitchState<LanguagePopupState>();
  93. }
  94. private void NewGameConfirmed()
  95. {
  96. CIGLoadingScreen.MarkNewGame();
  97. SceneManager.LoadScene("LoadingScreen");
  98. }
  99. public void NewGame()
  100. {
  101. base.ClosePopup(delegate()
  102. {
  103. SingletonMonobehaviour<PopupManager>.Instance.RequestFirstGenericPopup(UISpriteType.DemolishIcon, Localization.Key("option_start_new_game"), Localization.Key("option_start_new_game_confirm"), Localization.Key("ok"), Localization.Key("cancel"), new Action(this.NewGameConfirmed), null, null, true);
  104. });
  105. }
  106. public void OpenOtherGames()
  107. {
  108. this._fsm.SwitchState<OtherGamesPopupState>();
  109. }
  110. public void OpenRateUs()
  111. {
  112. }
  113. public void OpenDownloadPopup()
  114. {
  115. CIGDLCDownloader cigdlcdownloader = UnityEngine.Object.FindObjectOfType<CIGDLCDownloader>();
  116. if (cigdlcdownloader != null)
  117. {
  118. cigdlcdownloader.ShowPopup();
  119. }
  120. else
  121. {
  122. UnityEngine.Debug.LogError("No downloader");
  123. }
  124. base.ClosePopup();
  125. }
  126. public void OpenTermsOfService()
  127. {
  128. }
  129. public void OpenPrivacyPolicy()
  130. {
  131. }
  132. private void OnLevelledUp(int level)
  133. {
  134. if (Singleton<CIGSettings>.Instance.CloudStorageState != CloudStorageState.Activated && level >= 20 && (level - 20) % 10 == 0)
  135. {
  136. Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Unknown;
  137. if (base.Closed)
  138. {
  139. this._fsm.GetState<HUDState>().PushSettingsExclamationRequest(this);
  140. }
  141. else
  142. {
  143. this.OpenCloudStorageReminder();
  144. }
  145. }
  146. }
  147. private void OpenCloudStorageReminder()
  148. {
  149. this._fsm.SwitchState<GenericPopupState>().UpdateInfo(UISpriteType.CloudSaveIcon, Localization.Key("cloud_storage_reminder_title"), Localization.Key("cloud_storage_reminder_body"), Localization.Key("timewarp_confirm"), Localization.Key("timewarp_cancel"), new Action(this.OnActivateCloudStorage), new Action(this.OnDeactivateCloudStorage), null, false);
  150. }
  151. private void OnActivateCloudStorage()
  152. {
  153. if (StorageController.HasLoadedCloudSave)
  154. {
  155. this.OnEnableCloudStorage();
  156. }
  157. else
  158. {
  159. this._fsm.SwitchState<GenericPopupState>().UpdateInfo(UISpriteType.CloudSaveIcon, Localization.Key("cloud_storage_permissions_title"), Localization.Key("cloud_storage_permissions_body"), Localization.Key("ok"), null, new Action(this.OnEnableCloudStorage), null, null, false);
  160. }
  161. }
  162. private void OnDeactivateCloudStorage()
  163. {
  164. this._fsm.GetState<HUDState>().PopSettingsExclamationRequest(this);
  165. Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Deactivated;
  166. this.CheckCloudSaveButton();
  167. }
  168. private void OnEnableCloudStorage()
  169. {
  170. this._fsm.GetState<HUDState>().PopSettingsExclamationRequest(this);
  171. Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Activated;
  172. this.CheckCloudSaveButton();
  173. }
  174. private void CheckMusicButton()
  175. {
  176. ((SettingsPopupView)this.View).UpdateMusicButton(Singleton<CIGSettings>.Instance.MusicEnabled);
  177. }
  178. private void CheckSoundEffectsButton()
  179. {
  180. ((SettingsPopupView)this.View).UpdateSFXButton(Singleton<CIGSettings>.Instance.SoundEffectsEnabled);
  181. }
  182. private void CheckNotificationsButton()
  183. {
  184. ((SettingsPopupView)this.View).UpdateNotificationsButton(Singleton<CIGSettings>.Instance.NotificationsEnabled);
  185. }
  186. private void CheckCloudSaveButton()
  187. {
  188. ((SettingsPopupView)this.View).UpdateCloudSaveButton(Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Activated);
  189. }
  190. private IEnumerator OpenCloudStorageReminderAfterAnimation()
  191. {
  192. yield return new WaitForSeconds(((SettingsPopupView)this.View).TweenTime);
  193. this.OpenCloudStorageReminder();
  194. this._cloudStorageReminderRoutine = null;
  195. yield break;
  196. }
  197. private const int MinimumCloudStorageReminderLevel = 20;
  198. private const int CloudStorageReminderLevelInterval = 10;
  199. private Coroutine _cloudStorageReminderRoutine;
  200. }