|
- using System;
- using System.Collections.Generic;
- using CIG.Translation;
- using CIGEnums;
- using SUISS.Core;
- using SUISS.Storage;
-
- public sealed class CIGNewsletterRequester : SingletonMonobehaviour<CIGNewsletterRequester>
- {
- protected override void Awake()
- {
- base.Awake();
- if (this._isValidNewInstance)
- {
- this._gameStorage = Storage.Get(StorageLifecycle.Game).GetDictionary("CIGNewsletterRequesterGame");
- this._foreverStorage = Storage.Get(StorageLifecycle.Forever).GetDictionary("CIGNewsletterRequesterForever");
- }
- }
-
- private void Start()
- {
- this.TryShowRequest();
- }
-
- protected override void OnDestroy()
- {
- if (SingletonMonobehaviour<WorldMap>.IsAvailable)
- {
- SingletonMonobehaviour<WorldMap>.Instance.VisibilityChangedEvent -= this.OnWorldMapVisibilityChanged;
- }
- base.OnDestroy();
- }
-
- public bool Subscribed
- {
- get
- {
- return this._foreverStorage.GetBoolean("SubscribedToNewsletter", false);
- }
- set
- {
- this._foreverStorage["SubscribedToNewsletter"] = value;
- }
- }
-
- private int NextShowPopupLevel
- {
- get
- {
- return this._gameStorage.GetInt("ShowPopupAtLevel", 15);
- }
- set
- {
- this._gameStorage["ShowPopupAtLevel"] = value;
- }
- }
-
- private void TryShowRequest()
- {
- if (this.Subscribed || SingletonMonobehaviour<CIGGameState>.Instance.Level < this.NextShowPopupLevel)
- {
- return;
- }
- WorldMap instance = SingletonMonobehaviour<WorldMap>.Instance;
- if (!instance.IsVisible)
- {
- SingletonMonobehaviour<PopupManager>.Instance.RequestGenericPopup(UISpriteType.NewsletterIcon, Localization.Key("SSP_MENU_NEWSLETTER"), Localization.Format(Localization.Key("newsletter_subscribe_request"), new ILocalizedString[]
- {
- Localization.Key("gold")
- }), Localization.Key("rating_yes"), Localization.Key("confirmspend.no_thanks"), delegate()
- {
- SingletonMonobehaviour<PopupManager>.Instance.RequestFirstPopup<SparkSocNewsletterPopupState>(delegate(State state)
- {
- ((SparkSocNewsletterPopupState)state).SetCallbacks(delegate
- {
- this.Subscribed = true;
- }, new Action(this.UpdateNextRequest));
- });
- }, new Action(this.UpdateNextRequest), new Action(this.UpdateNextRequest), true);
- }
- else
- {
- instance.VisibilityChangedEvent += this.OnWorldMapVisibilityChanged;
- }
- }
-
- private void OnWorldMapVisibilityChanged(bool visible)
- {
- if (visible)
- {
- return;
- }
- SingletonMonobehaviour<WorldMap>.Instance.VisibilityChangedEvent -= this.OnWorldMapVisibilityChanged;
- this.TryShowRequest();
- }
-
- private void UpdateNextRequest()
- {
- int level = SingletonMonobehaviour<CIGGameState>.Instance.Level;
- do
- {
- this.NextShowPopupLevel += 10;
- }
- while (this.NextShowPopupLevel < level);
- }
-
- private const string GameStorageKey = "CIGNewsletterRequesterGame";
-
- private const string ForeverStorageKey = "CIGNewsletterRequesterForever";
-
- private const string ShowPopupAtLevelKey = "ShowPopupAtLevel";
-
- private const string SubscribedKey = "SubscribedToNewsletter";
-
- private const int MinLevelToShowPopup = 15;
-
- private const int IncreaseAmountNextShowLevel = 10;
-
- private Dictionary<string, object> _gameStorage;
-
- private Dictionary<string, object> _foreverStorage;
- }
|