using System; using CIG; using CIG.Translation; using CIGEnums; using SUISS.Core; using UnityEngine; public class ShopPopupView : PopupBaseView { private void OnDestroy() { if (this._tabView != null) { this._tabView.TabIndexChangedEvent -= this.OnTabIndexChanged; this._tabView = null; } if (this._buildingShopItemsView != null) { this._buildingShopItemsView.BuildingShopItemClickedEvent -= this.OnBuildingShopItemClicked; this._buildingShopItemsView.TutorialDialogSetEvent -= this.OnTutorialDialogSet; this._buildingShopItemsView.TutorialDialogClearedEvent -= this.OnTutorialDialogCleared; this._buildingShopItemsView = null; } if (this._iapShopItemsView != null) { this._iapShopItemsView.IAPShopItemClickedEvent -= this.OnIAPShopItemClicked; this._iapShopItemsView.CraneShopItemClickedEvent -= this.OnCraneShopItemClicked; this._iapShopItemsView = null; } } public override void Init() { base.Init(); this._iapShopItemsView.Init(); this._iapShopItemsView.IAPShopItemClickedEvent += this.OnIAPShopItemClicked; this._iapShopItemsView.CraneShopItemClickedEvent += this.OnCraneShopItemClicked; this._buildingShopItemsView.BuildingShopItemClickedEvent += this.OnBuildingShopItemClicked; this._buildingShopItemsView.TutorialDialogSetEvent += this.OnTutorialDialogSet; this._buildingShopItemsView.TutorialDialogClearedEvent += this.OnTutorialDialogCleared; this._tabView.TabIndexChangedEvent += this.OnTabIndexChanged; } public override void Open() { base.Open(); SingletonMonobehaviour.Instance.PushUnlimitedFPSRequest(this); this.UpdateCraneTab(); } public void SwitchTab(ShopMenuTabs shopMenuTab, ShopType category) { this._tabView.ActiveTabIndex = (int)shopMenuTab; this.SwitchContent(shopMenuTab, category); } public void UpdateCraneTab() { this._craneTabObject.SetActive(SingletonMonobehaviour.Instance.CanPurchaseCrane); } public void UpdateBadge(ShopMenuTabs tab, bool isActive) { this._tabView.UpdateBadge((int)tab, isActive); } public void UpdateBadge(ShopMenuTabs tab, int amount) { this._tabView.UpdateBadge((int)tab, amount); } public override void Close() { SingletonMonobehaviour.Instance.PopUnlimitedFPSRequest(this); if (this._activeShopItemsView != null) { this._activeShopItemsView.Clear(); this._activeShopItemsView.gameObject.SetActive(false); this._activeShopItemsView = null; } base.Close(); } public override void OnCloseClicked() { if (this._activeShopItemsView != null) { this._activeShopItemsView.Close(); } base.OnCloseClicked(); } public void OnAddGoldClicked() { ((ShopPopupState)this.State).SwitchTab(ShopMenuTabs.Gold, false, false); } public void OnAddCashClicked() { ((ShopPopupState)this.State).SwitchTab(ShopMenuTabs.Cash, false, false); } public void OnAddCraneClicked() { if (SingletonMonobehaviour.Instance.CanPurchaseCrane) { ((ShopPopupState)this.State).SwitchTab(ShopMenuTabs.Cranes, false, false); } } private void SwitchContent(ShopMenuTabs activeTab, ShopType category) { if (this._activeShopItemsView != null) { this._activeShopItemsView.Clear(); this._activeShopItemsView.gameObject.SetActive(false); } switch (activeTab) { case ShopMenuTabs.Gold: case ShopMenuTabs.Cash: case ShopMenuTabs.Cranes: this._activeShopItemsView = this._iapShopItemsView; break; case ShopMenuTabs.Residential: case ShopMenuTabs.Commercial: case ShopMenuTabs.Community: case ShopMenuTabs.Decorations: this._activeShopItemsView = this._buildingShopItemsView; break; default: UnityEngine.Debug.LogWarning("[ShopPopupView] No content for tab " + activeTab + ", redirecting to Gold tab"); ((ShopPopupState)this.State).SwitchTab(ShopMenuTabs.Gold, true, false); return; } this._titleLabel.LocalizedString = this._tabView.GetLocalizedTitle((int)activeTab); this._activeShopItemsView.gameObject.SetActive(true); this._activeShopItemsView.ShowItems(category); } private void OnTabIndexChanged(int oldIndex, int newIndex) { ((ShopPopupState)this.State).SwitchTab((ShopMenuTabs)newIndex, false, false); } private void OnBuildingShopItemClicked(CIGBuilding building) { ((ShopPopupState)this.State).OnBuildingShopItemClicked(building); } private void OnIAPShopItemClicked(CIG3StoreProduct product) { ((ShopPopupState)this.State).OnIAPShopItemClicked(product); } private void OnCraneShopItemClicked(decimal goldCost) { ((ShopPopupState)this.State).OnCraneShopItemClicked(goldCost); } private void OnTutorialDialogSet(ILocalizedString tutorialDialogLocalizedString) { this._tutorialDialogLabel.LocalizedString = tutorialDialogLocalizedString; this._tutorialDialogContainer.SetActive(true); } private void OnTutorialDialogCleared() { this._tutorialDialogContainer.SetActive(false); } [SerializeField] private TabView _tabView; [SerializeField] private BuildingShopItemsView _buildingShopItemsView; [SerializeField] private IAPShopItemsView _iapShopItemsView; [SerializeField] private GameObject _craneTabObject; [SerializeField] private LocalizedText _titleLabel; [SerializeField] private GameObject _tutorialDialogContainer; [SerializeField] private LocalizedText _tutorialDialogLabel; private ShopItemsView _activeShopItemsView; }