using System; using System.Collections.Generic; using CIG.Translation; using CIGEnums; using SUISS.Core; using SUISS.Storage; public sealed class CIGNewsletterRequester : SingletonMonobehaviour { 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.IsAvailable) { SingletonMonobehaviour.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.Instance.Level < this.NextShowPopupLevel) { return; } WorldMap instance = SingletonMonobehaviour.Instance; if (!instance.IsVisible) { SingletonMonobehaviour.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.Instance.RequestFirstPopup(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.Instance.VisibilityChangedEvent -= this.OnWorldMapVisibilityChanged; this.TryShowRequest(); } private void UpdateNextRequest() { int level = SingletonMonobehaviour.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 _gameStorage; private Dictionary _foreverStorage; }