using System; using System.Collections; using CIG.Translation; using CIGEnums; using SUISS.Core; using SUISSEngine; using UnityEngine; public class SparkSocNewsletterPopupState : PopupBaseState { public void Submit(string name, string emailAddress) { if (!this._isBusy) { if (!string.IsNullOrEmpty(name)) { if (this.IsValidEmail(emailAddress)) { base.StartCoroutine(this.DoSubmitEmailAddress(emailAddress)); } else { this.ShowErrorPopup(Localization.Key("register_enter_emailaddress")); } } else { this.ShowErrorPopup(Localization.Key("register_enter_name")); } } } public override void ClosePopup(Action callback, bool animate, bool synchronous) { if (!this._isBusy) { base.ClosePopup(callback, animate, synchronous); } } public void SetCallbacks(Action greenAction, Action redAction) { this._greenAction = greenAction; this._redAction = redAction; } public void CloseClicked() { if (this._redAction != null) { this._redAction(); } } private IEnumerator DoSubmitEmailAddress(string emailAddress) { this._isBusy = true; ((SparkSocNewsletterPopupView)this.View).UpdateSubmitButton(true); WWW www = SingletonMonobehaviour.Instance.RegisterNewsLetter(emailAddress); yield return www; this._isBusy = false; ((SparkSocNewsletterPopupView)this.View).UpdateSubmitButton(false); if (!string.IsNullOrEmpty(www.text) && www.text == "SUCCESS") { this._fsm.SwitchState().UpdateInfo(UISpriteType.NewsletterIcon, Localization.Key("thank_you"), Localization.Format(Localization.Key("register_success_confirmation"), new ILocalizedString[] { Localization.Literal(emailAddress) }), Localization.Key("ok"), null, delegate() { if (this._greenAction != null) { this._greenAction(); } base.ClosePopup(); }, null, this._greenAction, true); } else { this.ShowErrorPopup(Localization.Key("SSP_ERROR")); UnityEngine.Debug.LogError(www.text); } yield break; } private bool IsValidEmail(string emailAddress) { return emailAddress.Contains("@"); } private void ShowErrorPopup(ILocalizedString text) { this._fsm.SwitchState().UpdateInfo(null, Localization.Key("oops_something_went_wrong"), text, Localization.Key("ok"), null, null, null, null, true); } private bool _isBusy; private Action _greenAction; private Action _redAction; }