|
- using System;
- using System.Collections;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using SUISSEngine;
- using UnityEngine;
- using UnityEngine.SceneManagement;
-
- public class SettingsPopupState : PopupBaseState
- {
- private void OnDestroy()
- {
- if (SingletonMonobehaviour<CIGGameState>.IsAvailable)
- {
- SingletonMonobehaviour<CIGGameState>.Instance.LevelledUp -= this.OnLevelledUp;
- }
- }
-
- public override void Init()
- {
- base.Init();
- if (StorageController.CloudStorage.CloudStorageAvailable)
- {
- SingletonMonobehaviour<CIGGameState>.Instance.LevelledUp += this.OnLevelledUp;
- if (SingletonMonobehaviour<CIGGameState>.Instance.Level >= 20 && Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Unknown)
- {
- this._fsm.GetState<HUDState>().PushSettingsExclamationRequest(this);
- }
- }
- }
-
- public override void Enter(State oldState, bool openView)
- {
- base.Enter(oldState, openView);
- SettingsPopupView settingsPopupView = (SettingsPopupView)this.View;
- settingsPopupView.UpdateGameInfo();
- this.CheckMusicButton();
- this.CheckSoundEffectsButton();
- this.CheckNotificationsButton();
- this.CheckCloudSaveButton();
- settingsPopupView.SetLanguageVisible(Localization.AvailableCultures.Count > 1);
- settingsPopupView.SetLanguage(Localization.CurrentCulture);
- CIGDLCDownloader cigdlcdownloader = UnityEngine.Object.FindObjectOfType<CIGDLCDownloader>();
- settingsPopupView.SetDownloadVisible(cigdlcdownloader != null && !cigdlcdownloader.IsDone);
- if (StorageController.CloudStorage.CloudStorageAvailable)
- {
- if (SingletonMonobehaviour<CIGGameState>.Instance.Level >= 20 && Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Unknown)
- {
- this._cloudStorageReminderRoutine = base.StartCoroutine(this.OpenCloudStorageReminderAfterAnimation());
- }
- }
- else
- {
- settingsPopupView.DisableCloudSaveButton();
- }
- }
-
- public override void ClosePopup(Action callback, bool animate, bool synchronous)
- {
- if (this._cloudStorageReminderRoutine != null)
- {
- base.StopCoroutine(this._cloudStorageReminderRoutine);
- }
- base.ClosePopup(callback, animate, synchronous);
- }
-
- public void ToggleMusic()
- {
- Singleton<CIGSettings>.Instance.MusicEnabled = !Singleton<CIGSettings>.Instance.MusicEnabled;
- this.CheckMusicButton();
- }
-
- public void ToggleSoundEffects()
- {
- Singleton<CIGSettings>.Instance.SoundEffectsEnabled = !Singleton<CIGSettings>.Instance.SoundEffectsEnabled;
- this.CheckSoundEffectsButton();
- }
-
- public void ToggleNotifications()
- {
- Singleton<CIGSettings>.Instance.NotificationsEnabled = !Singleton<CIGSettings>.Instance.NotificationsEnabled;
- this.CheckNotificationsButton();
- }
-
- public void ToggleCloudSaving()
- {
- if (Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Activated)
- {
- Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Deactivated;
- this.CheckCloudSaveButton();
- }
- else
- {
- this.OpenCloudStorageReminder();
- }
- }
-
- public void OpenLanguages()
- {
- this._fsm.SwitchState<LanguagePopupState>();
- }
-
- private void NewGameConfirmed()
- {
- CIGLoadingScreen.MarkNewGame();
- SceneManager.LoadScene("LoadingScreen");
- }
-
- public void NewGame()
- {
- base.ClosePopup(delegate()
- {
- 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);
- });
- }
-
- public void OpenOtherGames()
- {
- this._fsm.SwitchState<OtherGamesPopupState>();
- }
-
- public void OpenRateUs()
- {
- }
-
- public void OpenDownloadPopup()
- {
- CIGDLCDownloader cigdlcdownloader = UnityEngine.Object.FindObjectOfType<CIGDLCDownloader>();
- if (cigdlcdownloader != null)
- {
- cigdlcdownloader.ShowPopup();
- }
- else
- {
- UnityEngine.Debug.LogError("No downloader");
- }
- base.ClosePopup();
- }
-
- public void OpenTermsOfService()
- {
- }
-
- public void OpenPrivacyPolicy()
- {
- }
-
- private void OnLevelledUp(int level)
- {
- if (Singleton<CIGSettings>.Instance.CloudStorageState != CloudStorageState.Activated && level >= 20 && (level - 20) % 10 == 0)
- {
- Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Unknown;
- if (base.Closed)
- {
- this._fsm.GetState<HUDState>().PushSettingsExclamationRequest(this);
- }
- else
- {
- this.OpenCloudStorageReminder();
- }
- }
- }
-
- private void OpenCloudStorageReminder()
- {
- 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);
- }
-
- private void OnActivateCloudStorage()
- {
- if (StorageController.HasLoadedCloudSave)
- {
- this.OnEnableCloudStorage();
- }
- else
- {
- 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);
- }
- }
-
- private void OnDeactivateCloudStorage()
- {
- this._fsm.GetState<HUDState>().PopSettingsExclamationRequest(this);
- Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Deactivated;
- this.CheckCloudSaveButton();
- }
-
- private void OnEnableCloudStorage()
- {
- this._fsm.GetState<HUDState>().PopSettingsExclamationRequest(this);
- Singleton<CIGSettings>.Instance.CloudStorageState = CloudStorageState.Activated;
- this.CheckCloudSaveButton();
- }
-
- private void CheckMusicButton()
- {
- ((SettingsPopupView)this.View).UpdateMusicButton(Singleton<CIGSettings>.Instance.MusicEnabled);
- }
-
- private void CheckSoundEffectsButton()
- {
- ((SettingsPopupView)this.View).UpdateSFXButton(Singleton<CIGSettings>.Instance.SoundEffectsEnabled);
- }
-
- private void CheckNotificationsButton()
- {
- ((SettingsPopupView)this.View).UpdateNotificationsButton(Singleton<CIGSettings>.Instance.NotificationsEnabled);
- }
-
- private void CheckCloudSaveButton()
- {
- ((SettingsPopupView)this.View).UpdateCloudSaveButton(Singleton<CIGSettings>.Instance.CloudStorageState == CloudStorageState.Activated);
- }
-
- private IEnumerator OpenCloudStorageReminderAfterAnimation()
- {
- yield return new WaitForSeconds(((SettingsPopupView)this.View).TweenTime);
- this.OpenCloudStorageReminder();
- this._cloudStorageReminderRoutine = null;
- yield break;
- }
-
- private const int MinimumCloudStorageReminderLevel = 20;
-
- private const int CloudStorageReminderLevelInterval = 10;
-
- private Coroutine _cloudStorageReminderRoutine;
- }
|