Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

123 rindas
3.2 KiB

  1. using System;
  2. using System.Collections.Generic;
  3. using CIG.Translation;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using SUISS.Storage;
  7. public sealed class CIGNewsletterRequester : SingletonMonobehaviour<CIGNewsletterRequester>
  8. {
  9. protected override void Awake()
  10. {
  11. base.Awake();
  12. if (this._isValidNewInstance)
  13. {
  14. this._gameStorage = Storage.Get(StorageLifecycle.Game).GetDictionary("CIGNewsletterRequesterGame");
  15. this._foreverStorage = Storage.Get(StorageLifecycle.Forever).GetDictionary("CIGNewsletterRequesterForever");
  16. }
  17. }
  18. private void Start()
  19. {
  20. this.TryShowRequest();
  21. }
  22. protected override void OnDestroy()
  23. {
  24. if (SingletonMonobehaviour<WorldMap>.IsAvailable)
  25. {
  26. SingletonMonobehaviour<WorldMap>.Instance.VisibilityChangedEvent -= this.OnWorldMapVisibilityChanged;
  27. }
  28. base.OnDestroy();
  29. }
  30. public bool Subscribed
  31. {
  32. get
  33. {
  34. return this._foreverStorage.GetBoolean("SubscribedToNewsletter", false);
  35. }
  36. set
  37. {
  38. this._foreverStorage["SubscribedToNewsletter"] = value;
  39. }
  40. }
  41. private int NextShowPopupLevel
  42. {
  43. get
  44. {
  45. return this._gameStorage.GetInt("ShowPopupAtLevel", 15);
  46. }
  47. set
  48. {
  49. this._gameStorage["ShowPopupAtLevel"] = value;
  50. }
  51. }
  52. private void TryShowRequest()
  53. {
  54. if (this.Subscribed || SingletonMonobehaviour<CIGGameState>.Instance.Level < this.NextShowPopupLevel)
  55. {
  56. return;
  57. }
  58. WorldMap instance = SingletonMonobehaviour<WorldMap>.Instance;
  59. if (!instance.IsVisible)
  60. {
  61. SingletonMonobehaviour<PopupManager>.Instance.RequestGenericPopup(UISpriteType.NewsletterIcon, Localization.Key("SSP_MENU_NEWSLETTER"), Localization.Format(Localization.Key("newsletter_subscribe_request"), new ILocalizedString[]
  62. {
  63. Localization.Key("gold")
  64. }), Localization.Key("rating_yes"), Localization.Key("confirmspend.no_thanks"), delegate()
  65. {
  66. SingletonMonobehaviour<PopupManager>.Instance.RequestFirstPopup<SparkSocNewsletterPopupState>(delegate(State state)
  67. {
  68. ((SparkSocNewsletterPopupState)state).SetCallbacks(delegate
  69. {
  70. this.Subscribed = true;
  71. }, new Action(this.UpdateNextRequest));
  72. });
  73. }, new Action(this.UpdateNextRequest), new Action(this.UpdateNextRequest), true);
  74. }
  75. else
  76. {
  77. instance.VisibilityChangedEvent += this.OnWorldMapVisibilityChanged;
  78. }
  79. }
  80. private void OnWorldMapVisibilityChanged(bool visible)
  81. {
  82. if (visible)
  83. {
  84. return;
  85. }
  86. SingletonMonobehaviour<WorldMap>.Instance.VisibilityChangedEvent -= this.OnWorldMapVisibilityChanged;
  87. this.TryShowRequest();
  88. }
  89. private void UpdateNextRequest()
  90. {
  91. int level = SingletonMonobehaviour<CIGGameState>.Instance.Level;
  92. do
  93. {
  94. this.NextShowPopupLevel += 10;
  95. }
  96. while (this.NextShowPopupLevel < level);
  97. }
  98. private const string GameStorageKey = "CIGNewsletterRequesterGame";
  99. private const string ForeverStorageKey = "CIGNewsletterRequesterForever";
  100. private const string ShowPopupAtLevelKey = "ShowPopupAtLevel";
  101. private const string SubscribedKey = "SubscribedToNewsletter";
  102. private const int MinLevelToShowPopup = 15;
  103. private const int IncreaseAmountNextShowLevel = 10;
  104. private Dictionary<string, object> _gameStorage;
  105. private Dictionary<string, object> _foreverStorage;
  106. }