|
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Diagnostics;
- using CIG;
- using CIG.Translation;
- using CIG3.ExtensionMethods;
- using CIGEnums;
- using SUISS.Core;
- using SUISSEngine;
- using UnityEngine;
-
- public sealed class CIGTutorialManager : SingletonMonobehaviour<CIGTutorialManager>
- {
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event CIGTutorialManager.TutorialFinishedEventHandler TutorialFinishedEvent;
-
- private void FireTutorialFinishedEvent()
- {
- if (this.TutorialFinishedEvent != null)
- {
- this.TutorialFinishedEvent();
- }
- }
-
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event CIGTutorialManager.HasDeserializedEventHandler HasDeserializedEvent;
-
- private void FireHasDeserializedEvent()
- {
- if (this.HasDeserializedEvent != null)
- {
- this.HasDeserializedEvent();
- }
- }
-
- public CIGTutorialState state
- {
- get
- {
- return this._state;
- }
- private set
- {
- if (this._state != value)
- {
- this._state = value;
- this._popupShown = false;
- this.serializing.Serialize();
- this._hudState.reference.CheckTutorialButton();
- }
- }
- }
-
- public bool IsFinished
- {
- get
- {
- return this._state > CIGTutorialState.Success;
- }
- }
-
- public bool HasDeserialized { get; private set; }
-
- protected override void Awake()
- {
- base.Awake();
- this._fsm = UnityEngine.Object.FindObjectOfType<FiniteStateMachine>();
- this._gameState = UnityEngine.Object.FindObjectOfType<CIGGameState>();
- this._running = false;
- }
-
- private void Start()
- {
- SingletonMonobehaviour<WorldMap>.Instance.VisibilityChangedEvent += this.OnWorldMapVisibilityChanged;
- this._tutorialRoutine = this.TutorialRoutine();
- }
-
- protected override void OnDestroy()
- {
- if (SingletonMonobehaviour<WorldMap>.IsAvailable)
- {
- SingletonMonobehaviour<WorldMap>.Instance.VisibilityChangedEvent -= this.OnWorldMapVisibilityChanged;
- }
- base.OnDestroy();
- }
-
- private void OnSerialize(Dictionary<string, object> values)
- {
- values["tutorialState"] = (int)this._state;
- values["cranePopupShown"] = this._cranePopupShown;
- }
-
- private void OnDeserialize(Dictionary<string, object> values)
- {
- this._state = CIGTutorialState.Welcome;
- if (values.ContainsKey("tutorialState"))
- {
- int num = (int)values["tutorialState"];
- if (num >= 0 && num < 10)
- {
- this._state = (CIGTutorialState)num;
- }
- }
- this._cranePopupShown = values.GetValue("cranePopupShown", false);
- }
-
- private void OnDeserialized()
- {
- this.HasDeserialized = true;
- this.FireHasDeserializedEvent();
- }
-
- public void QuitTutorial()
- {
- this._popupShown = true;
- this.state = CIGTutorialState.Finished;
- }
-
- public bool ShouldOverrideBuildingConstructionTime(CIGBuilding building)
- {
- return (this._state == CIGTutorialState.BuildHouse && building is CIGResidentialBuilding) || (this._state == CIGTutorialState.BuildFarm && building is CIGCommercialBuilding);
- }
-
- private void OnWorldMapVisibilityChanged(bool visible)
- {
- bool isVisiting = SingletonMonobehaviour<CIGIslandsManager>.Instance.IsVisiting;
- if (!visible && !isVisiting && this._state != CIGTutorialState.Finished && !this._running)
- {
- base.StartCoroutine(this._tutorialRoutine);
- }
- else if (visible || isVisiting)
- {
- base.StopCoroutine(this._tutorialRoutine);
- }
- }
-
- private IEnumerator TutorialRoutine()
- {
- yield return new WaitForSeconds(5f);
- for (;;)
- {
- this.CheckState();
- switch (this.state)
- {
- case CIGTutorialState.Initial:
- this.state = CIGTutorialState.Welcome;
- goto IL_23A;
- case CIGTutorialState.Welcome:
- this.ShowPopup(Localization.Key("tutorial_start"), Localization.Key("continue_message"), false, -1);
- goto IL_23A;
- case CIGTutorialState.BuildHouse:
- this.ShowTutorialDialog(Localization.Key("tutorial_build_house"), 0);
- goto IL_23A;
- case CIGTutorialState.SpeedupHouse:
- this.ShowTutorialDialog(Localization.Key("tutorial_speedup_house"), -1);
- goto IL_23A;
- case CIGTutorialState.Road:
- this.ShowTutorialDialog(Localization.Key("tutorial_build_road"), 2);
- goto IL_23A;
- case CIGTutorialState.BuildFarm:
- foreach (CIGCommercialBuilding cigbuilding in SingletonMonobehaviour<GameObjectManager>.Instance.Commercial)
- {
- if (!cigbuilding.island.IsValid() || cigbuilding.island == this._cityIsland.reference.island)
- {
- if (cigbuilding.IsUnlocked && !cigbuilding.activatable)
- {
- SpriteRenderer component = cigbuilding.GetComponent<SpriteRenderer>();
- if (component != null)
- {
- Sprite sprite = component.sprite;
- break;
- }
- }
- }
- }
- this.ShowTutorialDialog(Localization.Key("tutorial_build_commercial"), 0);
- goto IL_23A;
- case CIGTutorialState.CityAdvisor:
- this.ShowTutorialDialog(Localization.Key("tutorial_city_advisor"), 5);
- goto IL_23A;
- case CIGTutorialState.DeprecatedSocialPopup:
- goto IL_1F5;
- case CIGTutorialState.Success:
- goto IL_1F5;
- case CIGTutorialState.Finished:
- goto IL_21B;
- }
- break;
- IL_23A:
- yield return new WaitForSeconds(2f);
- continue;
- IL_1F5:
- this.ShowPopup(Localization.Key("tutorial_complete"), Localization.Key("thank_you"), true, -1);
- goto IL_23A;
- }
- UnityEngine.Debug.LogWarning("TutorialRoutine: Tutorial is in invalid state.");
- yield break;
- IL_21B:
- this.FireTutorialFinishedEvent();
- yield break;
- yield break;
- }
-
- private void CheckState()
- {
- if (!this._popupShown)
- {
- return;
- }
- CIGTutorialState state = this.state;
- CIGBuilding focusBuilding = this._focusBuilding;
- switch (this.state)
- {
- case CIGTutorialState.Initial:
- this.state = CIGTutorialState.Welcome;
- goto IL_158;
- case CIGTutorialState.Welcome:
- this.state = CIGTutorialState.BuildHouse;
- break;
- case CIGTutorialState.BuildHouse:
- break;
- case CIGTutorialState.SpeedupHouse:
- goto IL_A1;
- case CIGTutorialState.Road:
- goto IL_AD;
- case CIGTutorialState.BuildFarm:
- goto IL_D3;
- case CIGTutorialState.CityAdvisor:
- goto IL_106;
- case CIGTutorialState.DeprecatedSocialPopup:
- goto IL_132;
- case CIGTutorialState.Success:
- goto IL_132;
- case CIGTutorialState.Finished:
- goto IL_13F;
- default:
- UnityEngine.Debug.LogWarning("CheckState: Tutorial is in invalid state.");
- goto IL_158;
- }
- CIGBuilding cigbuilding = this.BuildingOfTypeBuilt<CIGResidentialBuilding>(false);
- if (cigbuilding == null)
- {
- goto IL_158;
- }
- this.state = CIGTutorialState.SpeedupHouse;
- IL_A1:
- this.state = CIGTutorialState.Road;
- IL_AD:
- CIGBuilding x = this.BuildingOfTypeHasRoad<CIGResidentialBuilding>();
- if (x == null)
- {
- goto IL_158;
- }
- this.state = CIGTutorialState.BuildFarm;
- IL_D3:
- CIGBuilding cigbuilding2 = this.BuildingOfTypeBuilt<CIGCommercialBuilding>(false);
- if (cigbuilding2 == null)
- {
- goto IL_158;
- }
- this.state = CIGTutorialState.CityAdvisor;
- IL_106:
- if (!this._gameState.GetValue<bool>("cityAdvisorOpened", false))
- {
- goto IL_158;
- }
- this.state = CIGTutorialState.Success;
- goto IL_158;
- IL_132:
- this.state = CIGTutorialState.Finished;
- IL_13F:
- IL_158:
- if (state != this.state && this._focusBuilding != focusBuilding && focusBuilding != null)
- {
- focusBuilding.HideMovingArrow();
- }
- if (state != this.state && this.state != CIGTutorialState.Finished)
- {
- }
- }
-
- public void NotifyBuildCount(CIGBuilderManager manager, int currentCount)
- {
- if (this._cranePopupShown || currentCount < manager.MaxBuildCount)
- {
- return;
- }
- if (this._state != CIGTutorialState.Finished)
- {
- return;
- }
- Action action = delegate()
- {
- this._cranePopupShown = true;
- this.serializing.Serialize();
- };
- SingletonMonobehaviour<PopupManager>.Instance.RequestGenericPopup(UISpriteType.Crane, Localization.Key("tutorial"), Localization.Format(Localization.Key("tutorial_touch_crane_popup"), new ILocalizedString[]
- {
- Localization.Integer(manager.MaxBuildCount)
- }), Localization.Key("continue_message"), null, action, action, action, true);
- HUDState hudstate = UnityEngine.Object.FindObjectOfType<HUDState>();
- if (hudstate != null)
- {
- hudstate.ShowArrowAboveButtonIndex(7, 10);
- }
- }
-
- private void PopupClosed()
- {
- this._textSkipCount = Math.Max(0, this._textSkipCount);
- this.TutorialMessageShown();
- }
-
- private void ShowTutorialDialog(ILocalizedString bodyText, int targetedButton)
- {
- if (bodyText != this._lastShownText || !this._tutorialDialogActive)
- {
- State currentState = this._fsm.CurrentState;
- if (currentState is HUDState)
- {
- ((HUDState)currentState).ShowTutorialDialog(bodyText, new Action(this.HideTutorialDialog));
- this._arrowIndex = targetedButton;
- this._lastShownText = bodyText;
- this._popupShown = true;
- this._tutorialDialogActive = true;
- SingletonMonobehaviour<CIGGameStats>.Instance.AddScreenViewed("tutorial_dialog");
- this.TutorialMessageShown();
- }
- }
- }
-
- private void HideTutorialDialog()
- {
- this._tutorialDialogActive = false;
- SingletonMonobehaviour<CIGGameStats>.Instance.AddScreenViewed("none");
- }
-
- private void TutorialMessageShown()
- {
- if (this._arrowIndex >= 0)
- {
- this.ShowArrow(this._arrowIndex);
- }
- if (this._focusBuilding != null && this._focusBuilding.state == BuildingState.Constructing)
- {
- this._focusBuilding.ShowMovingArrow();
- }
- }
-
- private void ShowPopup(ILocalizedString bodyText, ILocalizedString buttonText, bool showFlares, int targetedButton)
- {
- if (!this.PreShowPopupCheck(bodyText, targetedButton))
- {
- return;
- }
- SingletonMonobehaviour<PopupManager>.Instance.RequestFirstPopup<TutorialPopupState>(delegate(State state)
- {
- ((TutorialPopupState)state).UpdateInfo(bodyText, buttonText, showFlares, new Action(this.PopupClosed));
- });
- this.PostShowPopup(bodyText);
- }
-
- private bool PreShowPopupCheck(ILocalizedString bodyText, int targetedButton)
- {
- if (bodyText == this._lastShownText)
- {
- if (++this._textSkipCount < 10)
- {
- return false;
- }
- }
- else
- {
- this._popupShown = false;
- }
- if (!(this._fsm.CurrentState is HUDState) || !SingletonMonobehaviour<PopupManager>.Instance.PopupsMayOpen)
- {
- return false;
- }
- this._arrowIndex = targetedButton;
- return true;
- }
-
- private void PostShowPopup(ILocalizedString bodyText)
- {
- SingletonMonobehaviour<CIGGameStats>.Instance.AddScreenViewed("tutorial_dialog");
- this._lastShownText = bodyText;
- this._textSkipCount = -150;
- this._popupShown = true;
- }
-
- private void ShowArrow(int index)
- {
- State currentState = this._fsm.CurrentState;
- if (currentState is HUDState)
- {
- ((HUDState)currentState).ShowArrowAboveButtonIndex(index, 0);
- }
- }
-
- private CIGBuilding BuildingOfTypeBuilt<T>(bool checkFinished)
- {
- foreach (Building building in UnityEngine.Object.FindObjectsOfType<Building>())
- {
- if (building is CIGBuilding)
- {
- if (building.tile.status == GridTile.Status.Created)
- {
- CIGBuilding cigbuilding = (CIGBuilding)building;
- if (!cigbuilding.activatable || cigbuilding.Activated)
- {
- if (cigbuilding is T)
- {
- if (!checkFinished)
- {
- return cigbuilding;
- }
- if (cigbuilding.IsConstructed)
- {
- return cigbuilding;
- }
- }
- }
- }
- }
- }
- return null;
- }
-
- private CIGBuilding BuildingOfTypeHasRoad<T>()
- {
- foreach (Building building in UnityEngine.Object.FindObjectsOfType<Building>())
- {
- if (building is CIGBuilding)
- {
- if (building.tile.status == GridTile.Status.Created)
- {
- CIGBuilding cigbuilding = (CIGBuilding)building;
- if (!cigbuilding.activatable)
- {
- if (cigbuilding != null && cigbuilding is T && (!cigbuilding.checkForRoad || cigbuilding.CheckForRoad()))
- {
- return cigbuilding;
- }
- }
- }
- }
- }
- return null;
- }
-
- private bool HaveWaitingCommercialBuilding()
- {
- foreach (CIGCommercialBuilding cigcommercialBuilding in UnityEngine.Object.FindObjectsOfType<CIGCommercialBuilding>())
- {
- if (cigcommercialBuilding.state == BuildingState.Normal && (!cigcommercialBuilding.checkForRoad || cigcommercialBuilding.CheckForRoad()) && cigcommercialBuilding.Employees * 100 >= cigcommercialBuilding.MaxEmployees * 90 && cigcommercialBuilding.ProfitTimeLeft >= 300)
- {
- return true;
- }
- }
- return false;
- }
-
- [SerializeField]
- [SelfReference]
- private Serializing serializing;
-
- public const string CityAdvisorOpenedKey = "cityAdvisorOpened";
-
- private MagicalReference<CityIsland> _cityIsland = new MagicalReference<CityIsland>();
-
- private MagicalReference<HUDState> _hudState = new MagicalReference<HUDState>();
-
- private CIGGameState _gameState;
-
- private CIGTutorialState _state;
-
- private FiniteStateMachine _fsm;
-
- private ILocalizedString _lastShownText;
-
- private bool _popupShown;
-
- private int _textSkipCount;
-
- private int _arrowIndex = -1;
-
- private CIGBuilding _focusBuilding;
-
- private bool _running;
-
- private IEnumerator _tutorialRoutine;
-
- private bool _cranePopupShown;
-
- private bool _tutorialDialogActive;
-
- public delegate void TutorialFinishedEventHandler();
-
- public delegate void HasDeserializedEventHandler();
- }
|