|
- using System;
- using System.Collections.Generic;
- using System.Diagnostics;
- using CIG;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using SUISSEngine;
- using UnityEngine;
-
- public sealed class PopupManager : SingletonMonobehaviour<PopupManager>
- {
- //[DebuggerBrowsable(DebuggerBrowsableState.Never)]
- public event PopupManager.StatesInitializedEventHandler StatesInitializedEvent;
-
- private void FireStatesInitializedEvent()
- {
- if (this.StatesInitializedEvent != null)
- {
- this.StatesInitializedEvent();
- }
- }
-
- public bool PopupsMayOpen
- {
- get
- {
- return this._popupsMayOpen;
- }
- set
- {
- this._popupsMayOpen = value;
- if (value)
- {
- this.OpenNextPopup();
- }
- }
- }
-
- public bool SuppressQueue
- {
- get
- {
- return this._popupsAreSuppressed;
- }
- set
- {
- this._popupsAreSuppressed = value;
- if (value)
- {
- this.OpenNextPopup();
- }
- }
- }
-
- private int SuppressedPopups { get; set; }
-
- protected override void Awake()
- {
- base.Awake();
- if (!this._isValidNewInstance)
- {
- return;
- }
- this._popupsMayOpen = true;
- this.fsm.StatesInitializedEvent += this.FireStatesInitializedEvent;
- }
-
- protected override void OnDestroy()
- {
- this.fsm.StatesInitializedEvent -= this.FireStatesInitializedEvent;
- base.OnDestroy();
- }
-
- public void ShowOverlay()
- {
- this.overlay.SetActive(true);
- }
-
- public void HideOverlay()
- {
- this.overlay.SetActive(false);
- }
-
- public PopupRequest? RequestPopup<T>(PopupManager.PopupOpened callback) where T : State
- {
- PopupRequest popupRequest = new PopupRequest(this.fsm.GetState<T>(), callback);
- if (this.PopupsMayOpen)
- {
- this.OpenPopupNow(popupRequest);
- return null;
- }
- this.scheduledRequests.AddLast(popupRequest);
- return new PopupRequest?(popupRequest);
- }
-
- public PopupRequest? RequestFirstPopup<T>(PopupManager.PopupOpened callback) where T : State
- {
- PopupRequest popupRequest = new PopupRequest(this.fsm.GetState<T>(), callback);
- if (this.PopupsMayOpen)
- {
- this.OpenPopupNow(popupRequest);
- return null;
- }
- this.scheduledRequests.AddFirst(popupRequest);
- return new PopupRequest?(popupRequest);
- }
-
- public void RemovePopupRequest(PopupRequest request)
- {
- this.scheduledRequests.Remove(request);
- }
-
- private void OpenPopupNow(PopupRequest request)
- {
- State requestedState = request.requestedState;
- if (this.fsm.CurrentState == requestedState)
- {
- return;
- }
- this.fsm.SwitchState(requestedState);
- if (this.fsm.CurrentState == requestedState)
- {
- if (request.callback != null)
- {
- request.callback(requestedState);
- }
- }
- else
- {
- UnityEngine.Debug.LogWarning("State change unsuccessfull! PopupManager may have become corrupted");
- }
- }
-
- private void OpenNextPopup()
- {
- if (this.scheduledRequests.Count == 0)
- {
- return;
- }
- if (this.SuppressQueue)
- {
- if (++this.SuppressedPopups > 2)
- {
- UnityEngine.Debug.LogWarning("Are you quite sure you intended to suppress the popup queue for so long? Maybe you forgot to revert the suppress functionality?");
- }
- return;
- }
- this.SuppressedPopups = 0;
- PopupRequest value = this.scheduledRequests.First.Value;
- this.scheduledRequests.RemoveFirst();
- this.OpenPopupNow(value);
- }
-
- public void OpenShopMenu(ShopMenuTabs shopMenuTab)
- {
- this.RequestFirstPopup<ShopPopupState>(delegate(State state)
- {
- ((ShopPopupState)state).OpenPopup(shopMenuTab, false);
- });
- }
-
- [Obsolete("Use CloseRecursive instead", false)]
- public void CloseAll()
- {
- GUIView[] array = UnityEngine.Object.FindObjectsOfType<GUIView>();
- foreach (GUIView guiview in array)
- {
- if (guiview is PopupBaseView)
- {
- ((PopupBaseState)guiview.State).ClosePopup();
- }
- }
- }
-
- public void CloseRecursive(bool animated = true)
- {
- while (this.PopupIsOpen())
- {
- ((PopupBaseState)this.fsm.CurrentState).ClosePopup(null, animated, true);
- }
- }
-
- public bool PopupIsOpen()
- {
- return !(this.fsm.CurrentState is HUDState) && this.fsm.CurrentState is PopupBaseState;
- }
-
- public void OpenRoadMenu()
- {
- this.RequestFirstPopup<RoadSelectionPopupState>(null);
- }
-
- public void OpenYouNeedMore(Currencies purchasePrice, bool enableGoldAsAlternativeForCash, Action<bool, Currencies> purchaseCallback)
- {
- if (enableGoldAsAlternativeForCash)
- {
- }
- else
- {
- }
- SingletonMonobehaviour<CIGGameStats>.Instance.AddScreenViewed();
- this.RequestFirstPopup<MoreCashGoldPopupState>(delegate(State State)
- {
- ((MoreCashGoldPopupState)State).UpdateInfo(purchasePrice, enableGoldAsAlternativeForCash, purchaseCallback);
- });
- }
-
- public void ShowOkPopup(ILocalizedString title, ILocalizedString body, Action okButtonAction, bool dismissable = true)
- {
- this.RequestFirstGenericPopup(null, title, body, Localization.Key("ok"), null, okButtonAction, null, null, dismissable);
- }
-
- public void ShowOkCancelPopup(ILocalizedString title, ILocalizedString body, Action okButtonAction, Action cancelButtonAction)
- {
- this.RequestFirstGenericPopup(null, title, body, Localization.Key("ok"), Localization.Key("cancel"), okButtonAction, cancelButtonAction, cancelButtonAction, true);
- }
-
- public void ShowOkCancelPopup(UISpriteType spriteType, ILocalizedString title, ILocalizedString body, Action okButtonAction, Action cancelButtonAction)
- {
- this.RequestFirstGenericPopup(spriteType, title, body, Localization.Key("ok"), Localization.Key("cancel"), okButtonAction, cancelButtonAction, cancelButtonAction, true);
- }
-
- public void ShowInfoPopup(ILocalizedString title, ILocalizedString body)
- {
- this.RequestFirstGenericPopup(null, title, body, Localization.Key("ok"), null, null, null, null, true);
- }
-
- public void RequestGenericPopup(Sprite sprite, ILocalizedString title, ILocalizedString body, ILocalizedString greenText, ILocalizedString redText, Action greenButtonAction, Action redButtonAction, Action closeAction, bool dismissable = true)
- {
- this.RequestPopup<GenericPopupState>(delegate(State state)
- {
- ((GenericPopupState)state).UpdateInfo(sprite, title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, dismissable);
- });
- }
-
- public void RequestGenericPopup(UISpriteType spriteType, ILocalizedString title, ILocalizedString body, ILocalizedString greenText, ILocalizedString redText, Action greenButtonAction, Action redButtonAction, Action closeAction, bool dismissable = true)
- {
- this.RequestGenericPopup(SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(spriteType), title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, dismissable);
- }
-
- public void RequestFirstGenericPopup(Sprite sprite, ILocalizedString title, ILocalizedString body, ILocalizedString greenText, ILocalizedString redText, Action greenButtonAction, Action redButtonAction, Action closeAction, bool dismissable = true)
- {
- this.RequestFirstPopup<GenericPopupState>(delegate(State state)
- {
- ((GenericPopupState)state).UpdateInfo(sprite, title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, dismissable);
- });
- }
-
- public void RequestFirstGenericPopup(UISpriteType spriteType, ILocalizedString title, ILocalizedString body, ILocalizedString greenText, ILocalizedString redText, Action greenButtonAction, Action redButtonAction, Action closeAction, bool dismissable = true)
- {
- this.RequestFirstGenericPopup(SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(spriteType), title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, dismissable);
- }
-
- public void RequestFirstAdvicePopup(Sprite sprite, ILocalizedString title, ILocalizedString body, ILocalizedString greenText, ILocalizedString redText, Action greenButtonAction, Action redButtonAction, Action closeAction, Building building, bool dismissable = true)
- {
- this.RequestFirstPopup<GenericPopupState>(delegate(State state)
- {
- ((GenericPopupState)state).UpdateInfo(sprite, title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, dismissable);
- if (building != null)
- {
- SpriteRenderer bottomRenderer = building.GetComponent<GridTile>().bottomRenderer;
- if (bottomRenderer != null)
- {
- ((GenericPopupState)state).SetBottomSprite(bottomRenderer);
- }
- }
- });
- }
-
- public void RequestFirstAdvicePopup(UISpriteType spriteType, ILocalizedString title, ILocalizedString body, ILocalizedString greenText, ILocalizedString redText, Action greenButtonAction, Action redButtonAction, Action closeAction, Building building, bool dismissable = true)
- {
- this.RequestFirstAdvicePopup(SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(spriteType), title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, building, dismissable);
- }
-
- public GenericPopupState ShowOrUpdateGenericPopup(Sprite sprite, ILocalizedString title, ILocalizedString body, ILocalizedString greenText, ILocalizedString redText, Action greenButtonAction, Action redButtonAction, Action closeAction, bool dismissable = true)
- {
- GenericPopupState genericPopupState;
- if (this.fsm.CurrentState is GenericPopupState)
- {
- genericPopupState = (GenericPopupState)this.fsm.CurrentState;
- genericPopupState.UpdateInfo(sprite, title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, dismissable);
- }
- else
- {
- genericPopupState = this.fsm.SwitchState<GenericPopupState>();
- genericPopupState.UpdateInfo(sprite, title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, dismissable);
- }
- return genericPopupState;
- }
-
- public GenericPopupState ShowOrUpdateGenericPopup(UISpriteType spriteType, ILocalizedString title, ILocalizedString body, ILocalizedString greenText, ILocalizedString redText, Action greenButtonAction, Action redButtonAction, Action closeAction, bool dismissable = true)
- {
- return this.ShowOrUpdateGenericPopup(SingletonMonobehaviour<UISpriteAssetCollection>.Instance.GetAsset(spriteType), title, body, greenText, redText, greenButtonAction, redButtonAction, closeAction, dismissable);
- }
-
- public void ShowReceiveRewardPopup(Currencies reward)
- {
- this.fsm.SwitchState<ReceiveRewardPopupState>().SetCurrencyReward(reward);
- SingletonMonobehaviour<CIGGameStats>.Instance.AddScreenViewed("receive_currencies");
- SingletonMonobehaviour<CIGAudioManager>.Instance.PlayClip(Clip.Applause);
- }
-
- public void ShowTooMuchParallelBuildsPopup(Action succesAction, Action cancelAction, Currencies extraCost)
- {
- this.RequestPopup<TooMuchParallelBuildsPopupState>(delegate(State state)
- {
- ((TooMuchParallelBuildsPopupState)state).UpdateInfo(succesAction, cancelAction, extraCost);
- });
- }
-
- public void ShowDailyQuestPopup()
- {
- this.RequestFirstPopup<QuestsPopupState>(delegate(State state)
- {
- ((QuestsPopupState)state).Init(QuestsMenuTabs.DailyQuests);
- });
- }
-
- public void ShowBuildDemolishPopup(BuildDemolishTabs buildDemolishTab = BuildDemolishTabs.Build)
- {
- this.RequestFirstPopup<BuildDemolishPopupState>(delegate(State state)
- {
- ((BuildDemolishPopupState)state).SwitchTab(buildDemolishTab);
- });
- }
-
- public bool AreStatesInitialized
- {
- get
- {
- return this.fsm.AreStatesInitialized;
- }
- }
-
- public FiniteStateMachine fsm;
-
- public GameObject overlay;
-
- private LinkedList<PopupRequest> scheduledRequests = new LinkedList<PopupRequest>();
-
- private bool _popupsMayOpen;
-
- private bool _popupsAreSuppressed;
-
- public delegate void PopupOpened(State state);
-
- public delegate void StatesInitializedEventHandler();
- }
|