|
- 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<CIGWebService>.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<CIGWebService>.IsAvailable)
- {
- SingletonMonobehaviour<CIGWebService>.Instance.PullRequestCompleted -= this.OnPullRequestCompleted;
- this._pullRequestHandlerRegistered = false;
- }
- }
-
- public void OpenYouPopup()
- {
- CIGSparkSocServices instanceIfAvailable = SingletonMonobehaviour<CIGSparkSocServices>.InstanceIfAvailable;
- if (instanceIfAvailable != null)
- {
- if (instanceIfAvailable.IsLogedInAndLinked())
- {
- base.SafeSwitchState<GenericPopupState>().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<SparkSocLoginPopupState>();
- }
- }
- }
-
- public void OpenGiftsPopup()
- {
- base.SafeSwitchState<GiftsPopupState>();
- }
-
- public void OpenOtherGamesPopup()
- {
- base.SafeSwitchState<OtherGamesPopupState>();
- }
-
- public void OpenNewsletterPopup()
- {
- base.SafeSwitchState<SparkSocNewsletterPopupState>().SetCallbacks(delegate
- {
- SingletonMonobehaviour<CIGNewsletterRequester>.Instance.Subscribed = true;
- }, null);
- }
-
- protected void OnPullRequestCompleted()
- {
- CIGWebService instanceIfAvailable = SingletonMonobehaviour<CIGWebService>.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;
- }
|