using System; using CIG.Translation; using CIGEnums; using SUISS.Core; using UnityEngine; public class SparkSocMenuPopupState : PopupBaseState { public override void Enter(State oldState) { base.Enter(oldState); CIGWebService instanceIfAvailable = SingletonMonobehaviour.InstanceIfAvailable; if (instanceIfAvailable != null) { string userKey = instanceIfAvailable.UserKey; ((SparkSocMenuPopupView)this.View).SetFriendCode(userKey); if (string.IsNullOrEmpty(userKey) && !this._pullRequestHandlerRegistered) { instanceIfAvailable.PullRequestCompleted += this.OnPullRequestCompleted; this._pullRequestHandlerRegistered = true; } } } public override void Leave(State newState) { base.Leave(newState); if (this._pullRequestHandlerRegistered && SingletonMonobehaviour.IsAvailable) { SingletonMonobehaviour.Instance.PullRequestCompleted -= this.OnPullRequestCompleted; this._pullRequestHandlerRegistered = false; } } public void OpenYouPopup() { CIGSparkSocServices instanceIfAvailable = SingletonMonobehaviour.InstanceIfAvailable; if (instanceIfAvailable != null) { if (instanceIfAvailable.IsLogedInAndLinked()) { base.SafeSwitchState().UpdateInfo(UISpriteType.SparklingIcon, Localization.Key("SSP_MENU_YOU"), Localization.Format("{0}: {1}", new ILocalizedString[] { Localization.Key("settings_sparksoc"), Localization.Literal(instanceIfAvailable.GetPlayerName()) }), Localization.Key("back"), Localization.Key("settings_logout"), null, new Action(instanceIfAvailable.LogoutSparkSocPlayer), null, true); } else { base.SafeSwitchState(); } } } public void OpenGiftsPopup() { base.SafeSwitchState(); } public void OpenOtherGamesPopup() { base.SafeSwitchState(); } public void OpenNewsletterPopup() { base.SafeSwitchState().SetCallbacks(delegate { SingletonMonobehaviour.Instance.Subscribed = true; }, null); } protected void OnPullRequestCompleted() { CIGWebService instanceIfAvailable = SingletonMonobehaviour.InstanceIfAvailable; if (instanceIfAvailable != null && !string.IsNullOrEmpty(instanceIfAvailable.UserKey)) { ((SparkSocMenuPopupView)this.View).SetFriendCode(instanceIfAvailable.UserKey); if (this._pullRequestHandlerRegistered) { instanceIfAvailable.PullRequestCompleted -= this.OnPullRequestCompleted; this._pullRequestHandlerRegistered = false; } else { UnityEngine.Debug.LogError("Pull request handler called, but not registered."); } } } protected bool _pullRequestHandlerRegistered; }