您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

195 行
5.5 KiB

  1. using System;
  2. using CIG;
  3. using CIG.Translation;
  4. using CIGEnums;
  5. using SUISS.Core;
  6. using UnityEngine;
  7. public class ShopPopupView : PopupBaseView
  8. {
  9. private void OnDestroy()
  10. {
  11. if (this._tabView != null)
  12. {
  13. this._tabView.TabIndexChangedEvent -= this.OnTabIndexChanged;
  14. this._tabView = null;
  15. }
  16. if (this._buildingShopItemsView != null)
  17. {
  18. this._buildingShopItemsView.BuildingShopItemClickedEvent -= this.OnBuildingShopItemClicked;
  19. this._buildingShopItemsView.TutorialDialogSetEvent -= this.OnTutorialDialogSet;
  20. this._buildingShopItemsView.TutorialDialogClearedEvent -= this.OnTutorialDialogCleared;
  21. this._buildingShopItemsView = null;
  22. }
  23. if (this._iapShopItemsView != null)
  24. {
  25. this._iapShopItemsView.IAPShopItemClickedEvent -= this.OnIAPShopItemClicked;
  26. this._iapShopItemsView.CraneShopItemClickedEvent -= this.OnCraneShopItemClicked;
  27. this._iapShopItemsView = null;
  28. }
  29. }
  30. public override void Init()
  31. {
  32. base.Init();
  33. this._iapShopItemsView.Init();
  34. this._iapShopItemsView.IAPShopItemClickedEvent += this.OnIAPShopItemClicked;
  35. this._iapShopItemsView.CraneShopItemClickedEvent += this.OnCraneShopItemClicked;
  36. this._buildingShopItemsView.BuildingShopItemClickedEvent += this.OnBuildingShopItemClicked;
  37. this._buildingShopItemsView.TutorialDialogSetEvent += this.OnTutorialDialogSet;
  38. this._buildingShopItemsView.TutorialDialogClearedEvent += this.OnTutorialDialogCleared;
  39. this._tabView.TabIndexChangedEvent += this.OnTabIndexChanged;
  40. }
  41. public override void Open()
  42. {
  43. base.Open();
  44. SingletonMonobehaviour<FPSLimiter>.Instance.PushUnlimitedFPSRequest(this);
  45. this.UpdateCraneTab();
  46. }
  47. public void SwitchTab(ShopMenuTabs shopMenuTab, ShopType category)
  48. {
  49. this._tabView.ActiveTabIndex = (int)shopMenuTab;
  50. this.SwitchContent(shopMenuTab, category);
  51. }
  52. public void UpdateCraneTab()
  53. {
  54. this._craneTabObject.SetActive(SingletonMonobehaviour<CIGBuilderManager>.Instance.CanPurchaseCrane);
  55. }
  56. public void UpdateBadge(ShopMenuTabs tab, bool isActive)
  57. {
  58. this._tabView.UpdateBadge((int)tab, isActive);
  59. }
  60. public void UpdateBadge(ShopMenuTabs tab, int amount)
  61. {
  62. this._tabView.UpdateBadge((int)tab, amount);
  63. }
  64. public override void Close()
  65. {
  66. SingletonMonobehaviour<FPSLimiter>.Instance.PopUnlimitedFPSRequest(this);
  67. if (this._activeShopItemsView != null)
  68. {
  69. this._activeShopItemsView.Clear();
  70. this._activeShopItemsView.gameObject.SetActive(false);
  71. this._activeShopItemsView = null;
  72. }
  73. base.Close();
  74. }
  75. public override void OnCloseClicked()
  76. {
  77. if (this._activeShopItemsView != null)
  78. {
  79. this._activeShopItemsView.Close();
  80. }
  81. base.OnCloseClicked();
  82. }
  83. public void OnAddGoldClicked()
  84. {
  85. ((ShopPopupState)this.State).SwitchTab(ShopMenuTabs.Gold, false, false);
  86. }
  87. public void OnAddCashClicked()
  88. {
  89. ((ShopPopupState)this.State).SwitchTab(ShopMenuTabs.Cash, false, false);
  90. }
  91. public void OnAddCraneClicked()
  92. {
  93. if (SingletonMonobehaviour<CIGBuilderManager>.Instance.CanPurchaseCrane)
  94. {
  95. ((ShopPopupState)this.State).SwitchTab(ShopMenuTabs.Cranes, false, false);
  96. }
  97. }
  98. private void SwitchContent(ShopMenuTabs activeTab, ShopType category)
  99. {
  100. if (this._activeShopItemsView != null)
  101. {
  102. this._activeShopItemsView.Clear();
  103. this._activeShopItemsView.gameObject.SetActive(false);
  104. }
  105. switch (activeTab)
  106. {
  107. case ShopMenuTabs.Gold:
  108. case ShopMenuTabs.Cash:
  109. case ShopMenuTabs.Cranes:
  110. this._activeShopItemsView = this._iapShopItemsView;
  111. break;
  112. case ShopMenuTabs.Residential:
  113. case ShopMenuTabs.Commercial:
  114. case ShopMenuTabs.Community:
  115. case ShopMenuTabs.Decorations:
  116. this._activeShopItemsView = this._buildingShopItemsView;
  117. break;
  118. default:
  119. UnityEngine.Debug.LogWarning("[ShopPopupView] No content for tab " + activeTab + ", redirecting to Gold tab");
  120. ((ShopPopupState)this.State).SwitchTab(ShopMenuTabs.Gold, true, false);
  121. return;
  122. }
  123. this._titleLabel.LocalizedString = this._tabView.GetLocalizedTitle((int)activeTab);
  124. this._activeShopItemsView.gameObject.SetActive(true);
  125. this._activeShopItemsView.ShowItems(category);
  126. }
  127. private void OnTabIndexChanged(int oldIndex, int newIndex)
  128. {
  129. ((ShopPopupState)this.State).SwitchTab((ShopMenuTabs)newIndex, false, false);
  130. }
  131. private void OnBuildingShopItemClicked(CIGBuilding building)
  132. {
  133. ((ShopPopupState)this.State).OnBuildingShopItemClicked(building);
  134. }
  135. private void OnIAPShopItemClicked(CIG3StoreProduct product)
  136. {
  137. ((ShopPopupState)this.State).OnIAPShopItemClicked(product);
  138. }
  139. private void OnCraneShopItemClicked(decimal goldCost)
  140. {
  141. ((ShopPopupState)this.State).OnCraneShopItemClicked(goldCost);
  142. }
  143. private void OnTutorialDialogSet(ILocalizedString tutorialDialogLocalizedString)
  144. {
  145. this._tutorialDialogLabel.LocalizedString = tutorialDialogLocalizedString;
  146. this._tutorialDialogContainer.SetActive(true);
  147. }
  148. private void OnTutorialDialogCleared()
  149. {
  150. this._tutorialDialogContainer.SetActive(false);
  151. }
  152. [SerializeField]
  153. private TabView _tabView;
  154. [SerializeField]
  155. private BuildingShopItemsView _buildingShopItemsView;
  156. [SerializeField]
  157. private IAPShopItemsView _iapShopItemsView;
  158. [SerializeField]
  159. private GameObject _craneTabObject;
  160. [SerializeField]
  161. private LocalizedText _titleLabel;
  162. [SerializeField]
  163. private GameObject _tutorialDialogContainer;
  164. [SerializeField]
  165. private LocalizedText _tutorialDialogLabel;
  166. private ShopItemsView _activeShopItemsView;
  167. }