Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

156 linhas
4.5 KiB

  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using CIG;
  5. using CIG.Translation;
  6. using SUISS.Core;
  7. using Tweening;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. public class LevelUpPopupView : PopupBaseView
  11. {
  12. public override void Open()
  13. {
  14. base.Open();
  15. SingletonMonobehaviour<FPSLimiter>.Instance.PushUnlimitedFPSRequest(this);
  16. this._starTweener.Play();
  17. }
  18. public override void Close()
  19. {
  20. SingletonMonobehaviour<FPSLimiter>.Instance.PopUnlimitedFPSRequest(this);
  21. int count = this._buildingsPool.Count;
  22. for (int i = 0; i < count; i++)
  23. {
  24. UnityEngine.Object.Destroy(this._buildingsPool[i].gameObject);
  25. }
  26. this._buildingsPool.Clear();
  27. this._spawnedBuildings.Clear();
  28. this._buildingsBackgroundTweener.StopAndReset(false);
  29. this._starTweener.StopAndReset(false);
  30. this._buildingsContainerTransform.localPosition = Vector3.zero;
  31. base.Close();
  32. }
  33. public void ShowBuildings(int level, ILocalizedString title, ILocalizedString rewardAmount, List<CIGBuilding> unlockedBuildings)
  34. {
  35. this._instantiatedBuildings = false;
  36. this._levelLabel.LocalizedString = Localization.Integer(level);
  37. this._titleLabel.LocalizedString = title;
  38. this._currencyAmountLabel.LocalizedString = rewardAmount;
  39. this._unlockedBuildingsCanvasGroup.alpha = 1f;
  40. this._unlockedBuildings = unlockedBuildings;
  41. this._unlockLevel = level;
  42. this._buildingsBackgroundTweener.Play();
  43. this._delayedIntroRoutine = base.StartCoroutine(this.DelayedIntro());
  44. }
  45. public void ShowCurrency(int level, ILocalizedString title, ILocalizedString reward)
  46. {
  47. this._levelLabel.LocalizedString = Localization.Integer(level);
  48. this._titleLabel.LocalizedString = title;
  49. this._currencyAmountLabel.LocalizedString = reward;
  50. this._unlockedBuildingsCanvasGroup.alpha = 0f;
  51. }
  52. public void OnLevelUpOverlayClicked()
  53. {
  54. if (!this._instantiatedBuildings)
  55. {
  56. if (this._spawnBuildingsRoutine != null)
  57. {
  58. base.StopCoroutine(this._spawnBuildingsRoutine);
  59. this._spawnBuildingsRoutine = null;
  60. }
  61. if (this._delayedIntroRoutine != null)
  62. {
  63. base.StopCoroutine(this._delayedIntroRoutine);
  64. this._delayedIntroRoutine = null;
  65. }
  66. this._spawnBuildingsRoutine = base.StartCoroutine(this.SpawnBuildings(false));
  67. }
  68. }
  69. private IEnumerator DelayedIntro()
  70. {
  71. this._scrollRect.horizontal = false;
  72. this._greenButton.Interactable = false;
  73. yield return new WaitForSecondsRealtime(0.7f);
  74. this._spawnBuildingsRoutine = base.StartCoroutine(this.SpawnBuildings(true));
  75. yield break;
  76. }
  77. private IEnumerator SpawnBuildings(bool useDelay)
  78. {
  79. int count = this._unlockedBuildings.Count;
  80. for (int i = 0; i < count; i++)
  81. {
  82. CIGBuilding item = this._unlockedBuildings[i];
  83. if (!this._spawnedBuildings.Contains(item))
  84. {
  85. LevelUpBuildingItem levelUpBuilding = UnityEngine.Object.Instantiate<LevelUpBuildingItem>(this._levelUpBuildingPrefab, this._buildingsContainerTransform.transform);
  86. this._buildingsPool.Add(levelUpBuilding);
  87. this._spawnedBuildings.Add(item);
  88. levelUpBuilding.SetBuilding(this._unlockLevel, item);
  89. if (useDelay)
  90. {
  91. yield return new WaitForSecondsRealtime(0.5f);
  92. }
  93. levelUpBuilding.gameObject.SetActive(true);
  94. }
  95. }
  96. this._instantiatedBuildings = true;
  97. this._scrollRect.horizontal = true;
  98. this._greenButton.Interactable = true;
  99. yield break;
  100. }
  101. [SerializeField]
  102. private LocalizedText _levelLabel;
  103. [SerializeField]
  104. private LocalizedText _titleLabel;
  105. [SerializeField]
  106. private LocalizedText _currencyAmountLabel;
  107. [SerializeField]
  108. private CanvasGroup _unlockedBuildingsCanvasGroup;
  109. [SerializeField]
  110. private GameObject _buildingItemsContainer;
  111. [SerializeField]
  112. private LevelUpBuildingItem _levelUpBuildingPrefab;
  113. [SerializeField]
  114. private ScrollRect _scrollRect;
  115. [SerializeField]
  116. private RectTransform _buildingsContainerTransform;
  117. [SerializeField]
  118. private InteractableButton _greenButton;
  119. [SerializeField]
  120. private Tweener _buildingsBackgroundTweener;
  121. [SerializeField]
  122. private Tweener _starTweener;
  123. private List<LevelUpBuildingItem> _buildingsPool = new List<LevelUpBuildingItem>();
  124. private List<CIGBuilding> _unlockedBuildings = new List<CIGBuilding>();
  125. private List<CIGBuilding> _spawnedBuildings = new List<CIGBuilding>();
  126. private Coroutine _delayedIntroRoutine;
  127. private Coroutine _spawnBuildingsRoutine;
  128. private bool _instantiatedBuildings;
  129. private int _unlockLevel;
  130. }