|
- 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<FPSLimiter>.Instance.PushUnlimitedFPSRequest(this);
- this._starTweener.Play();
- }
-
- public override void Close()
- {
- SingletonMonobehaviour<FPSLimiter>.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<CIGBuilding> 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<LevelUpBuildingItem>(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<LevelUpBuildingItem> _buildingsPool = new List<LevelUpBuildingItem>();
-
- private List<CIGBuilding> _unlockedBuildings = new List<CIGBuilding>();
-
- private List<CIGBuilding> _spawnedBuildings = new List<CIGBuilding>();
-
- private Coroutine _delayedIntroRoutine;
-
- private Coroutine _spawnBuildingsRoutine;
-
- private bool _instantiatedBuildings;
-
- private int _unlockLevel;
- }
|