Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

101 строка
2.5 KiB

  1. using System;
  2. using System.Collections;
  3. using CIG.Translation;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using SUISSEngine;
  7. using UnityEngine;
  8. public class SparkSocNewsletterPopupState : PopupBaseState
  9. {
  10. public void Submit(string name, string emailAddress)
  11. {
  12. if (!this._isBusy)
  13. {
  14. if (!string.IsNullOrEmpty(name))
  15. {
  16. if (this.IsValidEmail(emailAddress))
  17. {
  18. base.StartCoroutine(this.DoSubmitEmailAddress(emailAddress));
  19. }
  20. else
  21. {
  22. this.ShowErrorPopup(Localization.Key("register_enter_emailaddress"));
  23. }
  24. }
  25. else
  26. {
  27. this.ShowErrorPopup(Localization.Key("register_enter_name"));
  28. }
  29. }
  30. }
  31. public override void ClosePopup(Action callback, bool animate, bool synchronous)
  32. {
  33. if (!this._isBusy)
  34. {
  35. base.ClosePopup(callback, animate, synchronous);
  36. }
  37. }
  38. public void SetCallbacks(Action greenAction, Action redAction)
  39. {
  40. this._greenAction = greenAction;
  41. this._redAction = redAction;
  42. }
  43. public void CloseClicked()
  44. {
  45. if (this._redAction != null)
  46. {
  47. this._redAction();
  48. }
  49. }
  50. private IEnumerator DoSubmitEmailAddress(string emailAddress)
  51. {
  52. this._isBusy = true;
  53. ((SparkSocNewsletterPopupView)this.View).UpdateSubmitButton(true);
  54. WWW www = SingletonMonobehaviour<CIGWebService>.Instance.RegisterNewsLetter(emailAddress);
  55. yield return www;
  56. this._isBusy = false;
  57. ((SparkSocNewsletterPopupView)this.View).UpdateSubmitButton(false);
  58. if (!string.IsNullOrEmpty(www.text) && www.text == "SUCCESS")
  59. {
  60. this._fsm.SwitchState<GenericPopupState>().UpdateInfo(UISpriteType.NewsletterIcon, Localization.Key("thank_you"), Localization.Format(Localization.Key("register_success_confirmation"), new ILocalizedString[]
  61. {
  62. Localization.Literal(emailAddress)
  63. }), Localization.Key("ok"), null, delegate()
  64. {
  65. if (this._greenAction != null)
  66. {
  67. this._greenAction();
  68. }
  69. base.ClosePopup();
  70. }, null, this._greenAction, true);
  71. }
  72. else
  73. {
  74. this.ShowErrorPopup(Localization.Key("SSP_ERROR"));
  75. UnityEngine.Debug.LogError(www.text);
  76. }
  77. yield break;
  78. }
  79. private bool IsValidEmail(string emailAddress)
  80. {
  81. return emailAddress.Contains("@");
  82. }
  83. private void ShowErrorPopup(ILocalizedString text)
  84. {
  85. this._fsm.SwitchState<GenericPopupState>().UpdateInfo(null, Localization.Key("oops_something_went_wrong"), text, Localization.Key("ok"), null, null, null, null, true);
  86. }
  87. private bool _isBusy;
  88. private Action _greenAction;
  89. private Action _redAction;
  90. }