using System; using System.Collections; using System.Collections.Generic; using CIG; using CIG.Translation; using SUISS.Core; using Tweening; using UnityEngine; using UnityEngine.UI; public class LevelUpPopupView : PopupBaseView { public override void Open() { base.Open(); SingletonMonobehaviour.Instance.PushUnlimitedFPSRequest(this); this._starTweener.Play(); } public override void Close() { SingletonMonobehaviour.Instance.PopUnlimitedFPSRequest(this); int count = this._buildingsPool.Count; for (int i = 0; i < count; i++) { UnityEngine.Object.Destroy(this._buildingsPool[i].gameObject); } this._buildingsPool.Clear(); this._spawnedBuildings.Clear(); this._buildingsBackgroundTweener.StopAndReset(false); this._starTweener.StopAndReset(false); this._buildingsContainerTransform.localPosition = Vector3.zero; base.Close(); } public void ShowBuildings(int level, ILocalizedString title, ILocalizedString rewardAmount, List unlockedBuildings) { this._instantiatedBuildings = false; this._levelLabel.LocalizedString = Localization.Integer(level); this._titleLabel.LocalizedString = title; this._currencyAmountLabel.LocalizedString = rewardAmount; this._unlockedBuildingsCanvasGroup.alpha = 1f; this._unlockedBuildings = unlockedBuildings; this._unlockLevel = level; this._buildingsBackgroundTweener.Play(); this._delayedIntroRoutine = base.StartCoroutine(this.DelayedIntro()); } public void ShowCurrency(int level, ILocalizedString title, ILocalizedString reward) { this._levelLabel.LocalizedString = Localization.Integer(level); this._titleLabel.LocalizedString = title; this._currencyAmountLabel.LocalizedString = reward; this._unlockedBuildingsCanvasGroup.alpha = 0f; } public void OnLevelUpOverlayClicked() { if (!this._instantiatedBuildings) { if (this._spawnBuildingsRoutine != null) { base.StopCoroutine(this._spawnBuildingsRoutine); this._spawnBuildingsRoutine = null; } if (this._delayedIntroRoutine != null) { base.StopCoroutine(this._delayedIntroRoutine); this._delayedIntroRoutine = null; } this._spawnBuildingsRoutine = base.StartCoroutine(this.SpawnBuildings(false)); } } private IEnumerator DelayedIntro() { this._scrollRect.horizontal = false; this._greenButton.Interactable = false; yield return new WaitForSecondsRealtime(0.7f); this._spawnBuildingsRoutine = base.StartCoroutine(this.SpawnBuildings(true)); yield break; } private IEnumerator SpawnBuildings(bool useDelay) { int count = this._unlockedBuildings.Count; for (int i = 0; i < count; i++) { CIGBuilding item = this._unlockedBuildings[i]; if (!this._spawnedBuildings.Contains(item)) { LevelUpBuildingItem levelUpBuilding = UnityEngine.Object.Instantiate(this._levelUpBuildingPrefab, this._buildingsContainerTransform.transform); this._buildingsPool.Add(levelUpBuilding); this._spawnedBuildings.Add(item); levelUpBuilding.SetBuilding(this._unlockLevel, item); if (useDelay) { yield return new WaitForSecondsRealtime(0.5f); } levelUpBuilding.gameObject.SetActive(true); } } this._instantiatedBuildings = true; this._scrollRect.horizontal = true; this._greenButton.Interactable = true; yield break; } [SerializeField] private LocalizedText _levelLabel; [SerializeField] private LocalizedText _titleLabel; [SerializeField] private LocalizedText _currencyAmountLabel; [SerializeField] private CanvasGroup _unlockedBuildingsCanvasGroup; [SerializeField] private GameObject _buildingItemsContainer; [SerializeField] private LevelUpBuildingItem _levelUpBuildingPrefab; [SerializeField] private ScrollRect _scrollRect; [SerializeField] private RectTransform _buildingsContainerTransform; [SerializeField] private InteractableButton _greenButton; [SerializeField] private Tweener _buildingsBackgroundTweener; [SerializeField] private Tweener _starTweener; private List _buildingsPool = new List(); private List _unlockedBuildings = new List(); private List _spawnedBuildings = new List(); private Coroutine _delayedIntroRoutine; private Coroutine _spawnBuildingsRoutine; private bool _instantiatedBuildings; private int _unlockLevel; }