StoreView.cs 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. using UI.Store;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using ET;
  6. using UnityEngine;
  7. // using System.Diagnostics;
  8. namespace GFGGame
  9. {
  10. public class StoreView : BaseWindow
  11. {
  12. private UI_StoreUI _ui;
  13. // private ValueBarController _valueBarController;
  14. private List<List<string>> _arenaSubTab = new List<List<string>>();
  15. private List<string[]> _storeTabCfgs = new List<string[]>();
  16. private int _curTabIndex = 0;
  17. private int _curSubTabIndex = 0;
  18. private string _curViewName = "";
  19. public override void Dispose()
  20. {
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. }
  25. _arenaSubTab.Clear();
  26. _ui = null;
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_StoreUI.PACKAGE_NAME;
  33. _ui = UI_StoreUI.Create();
  34. this.viewCom = _ui.target;
  35. isfullScreen = true;
  36. isReturnView = true;
  37. this.bringToFontOnClick = false;
  38. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("bg_fhl");
  39. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  40. _ui.m_comTab.m_c1.onChanged.Add(OnTabChange);
  41. _ui.m_listSubTab.itemRenderer = RenderListSubTabItem;
  42. _ui.m_listSubTab.onClickItem.Add(OnListSubTabClick);
  43. }
  44. protected override void AddEventListener()
  45. {
  46. base.AddEventListener();
  47. EventAgent.AddEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  48. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateRedDot);
  49. EventAgent.AddEventListener(ConstMessage.NOTICE_BATCH_TASK_STATE_CHANGE, UpdateStoreMonthRedDot);
  50. EventAgent.AddEventListener(ConstMessage.STORE_BROCADE_WEAV_RECEIVE, UpdateStoreMonthRedDot);
  51. }
  52. protected override void OnShown()
  53. {
  54. base.OnShown();
  55. StoreTabCfg arenaTab = StoreTabCfgArray.Instance.GetCfgByfunctionId(ConstFunctionId.STORE_ARENA);
  56. _arenaSubTab.Clear();
  57. _arenaSubTab.Add(new List<string>() { arenaTab.subTabArr[0][0], arenaTab.subTabArr[0][1], arenaTab.subTabArr[0][2] });
  58. for (int i = ArenaDataManager.Instance.SeasonId; i > 0; i--)
  59. {
  60. _arenaSubTab.Add(new List<string>() { string.Format("第{0}赛季", i), i.ToString(), "StoreArenaView" });
  61. }
  62. _curTabIndex = this.viewData == null ? ConstStoreTabId.STORE_CHARGE : (int)(this.viewData as object[])[0];
  63. _ui.m_comTab.m_c1.selectedIndex = _curTabIndex;
  64. _ui.m_comTab.target.scrollPane.SetPercX((float)(_curTabIndex - 1) / (float)StoreTabCfgArray.Instance.dataArray.Length, false);
  65. _curSubTabIndex = this.viewData == null ? 0 : (int)(this.viewData as object[])[1];
  66. if (_curTabIndex == ConstStoreTabId.STORE_GIFT_BAG && _curSubTabIndex > 0 && !ShopDataManager.Instance.GetShopActivityIsShow()) {
  67. _curSubTabIndex -= 1;
  68. }
  69. if (_ui.m_listSubTab.numItems > _curSubTabIndex)
  70. {
  71. _ui.m_listSubTab.selectedIndex = _curSubTabIndex;
  72. _ui.m_listSubTab.ScrollToView(_curSubTabIndex);
  73. OnListSubTabChange(_curSubTabIndex);
  74. }
  75. UpdateRedDot();
  76. }
  77. protected override void OnHide()
  78. {
  79. base.OnHide();
  80. _ui.m_comTab.m_c1.selectedIndex = 0;
  81. _ui.m_listSubTab.selectedIndex = 0;
  82. }
  83. protected override void RemoveEventListener()
  84. {
  85. base.RemoveEventListener();
  86. EventAgent.RemoveEventListener(ConstMessage.NUMERIC_CHANGE, UpdateRedDot);
  87. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateRedDot);
  88. EventAgent.RemoveEventListener(ConstMessage.NOTICE_BATCH_TASK_STATE_CHANGE, UpdateStoreMonthRedDot);
  89. EventAgent.RemoveEventListener(ConstMessage.STORE_BROCADE_WEAV_RECEIVE, UpdateStoreMonthRedDot);
  90. }
  91. private void OnClickBtnBack()
  92. {
  93. ViewManager.Hide(_curViewName);
  94. this.Hide();
  95. //ViewManager.GoBackFrom(typeof(StoreView).FullName);
  96. }
  97. private void OnTabChange()
  98. {
  99. StoreTabCfg tabCfg = StoreTabCfgArray.Instance.GetCfg(_ui.m_comTab.m_c1.selectedIndex);
  100. if (tabCfg == null) return;
  101. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(tabCfg.functionId))
  102. {
  103. _ui.m_comTab.m_c1.selectedIndex = _ui.m_comTab.m_c1.previsousIndex;
  104. }
  105. _curTabIndex = _ui.m_comTab.m_c1.selectedIndex;
  106. if (tabCfg.functionId == ConstFunctionId.STORE_ARENA)
  107. {
  108. _ui.m_listSubTab.numItems = _arenaSubTab.Count;
  109. }
  110. else
  111. {
  112. _storeTabCfgs.Clear();
  113. if (tabCfg.index == ConstStoreTabId.STORE_GIFT_BAG)
  114. {
  115. for (int i = 0; i < tabCfg.subTabArr.Length; i++)
  116. {
  117. int menu2 = int.Parse(tabCfg.subTabArr[i][1]);
  118. if (menu2 == ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY)
  119. {
  120. if (!ShopDataManager.Instance.GetShopActivityIsShow()) continue;
  121. }
  122. _storeTabCfgs.Add(tabCfg.subTabArr[i]);
  123. }
  124. }
  125. else
  126. {
  127. _storeTabCfgs = new List<string[]>(tabCfg.subTabArr);
  128. }
  129. _ui.m_listSubTab.numItems = _storeTabCfgs.Count;
  130. }
  131. _ui.m_listSubTab.selectedIndex = 0;
  132. _curSubTabIndex = 0;
  133. OnListSubTabChange(_curSubTabIndex);
  134. UpdateRedDot();
  135. }
  136. private void RenderListSubTabItem(int index, GObject obj)
  137. {
  138. GButton item = obj.asButton;
  139. StoreTabCfg tabCfg = StoreTabCfgArray.Instance.GetCfg(_curTabIndex);
  140. int menu2 = 0;
  141. if (tabCfg.functionId == ConstFunctionId.STORE_ARENA)
  142. {
  143. item.title = _arenaSubTab[index][0];
  144. menu2 = int.Parse(_arenaSubTab[index][1]);
  145. }
  146. else
  147. {
  148. item.title = _storeTabCfgs[index][0];
  149. menu2 = int.Parse(_storeTabCfgs[index][1]);
  150. }
  151. item.data = index;
  152. }
  153. private void OnListSubTabClick(EventContext context)
  154. {
  155. GObject obj = context.data as GObject;
  156. int index = (int)obj.data;
  157. if (index < 0) return;
  158. OnListSubTabChange(index);
  159. }
  160. private void OnListSubTabChange(int index)
  161. {
  162. StoreTabCfg tabCfg = StoreTabCfgArray.Instance.GetCfg(_curTabIndex);
  163. string viewName = "";
  164. int menu2 = 0;
  165. if (tabCfg.functionId == ConstFunctionId.STORE_ARENA)
  166. {
  167. menu2 = int.Parse(_arenaSubTab[index][1]);
  168. viewName = _arenaSubTab[index][2];
  169. }
  170. else
  171. {
  172. menu2 = int.Parse(_storeTabCfgs[index][1]);
  173. viewName = _storeTabCfgs[index][2];
  174. }
  175. if (!FunctionOpenDataManager.Instance.CheckIsFunOpenById(viewName))
  176. {
  177. _ui.m_listSubTab.selectedIndex = _curSubTabIndex;
  178. return;
  179. }
  180. ViewManager.Hide(_curViewName);
  181. if (!string.IsNullOrEmpty(viewName) && viewName != "“”")
  182. {
  183. ViewManager.Show("GFGGame." + viewName, menu2);
  184. }
  185. _curSubTabIndex = index;
  186. _curViewName = "GFGGame." + viewName;
  187. }
  188. private void UpdateRedDot()
  189. {
  190. RedDotController.Instance.SetComRedDot(_ui.m_comTab.m_btn0.target, RedDotDataManager.Instance.GetChargeAddUpRewardRed());
  191. for (int i = 0; i < _ui.m_listSubTab.numItems; i++)
  192. {
  193. RedDotController.Instance.SetComRedDot(_ui.m_listSubTab.GetChildAt(i).asCom, false);
  194. }
  195. if (_ui.m_comTab.m_c1.selectedIndex == ConstStoreTabId.STORE_CHARGE)
  196. {
  197. RedDotController.Instance.SetComRedDot(_ui.m_listSubTab.GetChildAt(ConstStoreSubId.STORE_CHARGE_ADDUP).asCom, RedDotDataManager.Instance.GetChargeAddUpRewardRed());
  198. }
  199. UpdateStoreMonthRedDot();
  200. RedDotController.Instance.SetComRedDot(_ui.m_comTab.m_btn2.target, RedDotDataManager.Instance.GetGiftBagRewardRed());
  201. if (_ui.m_comTab.m_c1.selectedIndex == ConstStoreTabId.STORE_GIFT_BAG)
  202. {
  203. RedDotController.Instance.SetComRedDot(_ui.m_listSubTab.GetChildAt(ConstStoreSubId.STORE_GIFT_BAG_ACTIVITY).asCom, RedDotDataManager.Instance.GetGiftBagRewardRed());
  204. }
  205. }
  206. //月卡红点刷新
  207. private void UpdateStoreMonthRedDot()
  208. {
  209. RedDotController.Instance.SetComRedDot(_ui.m_comTab.m_btn1.target, RedDotDataManager.Instance.GetGoldCardRewardRed() || RedDotDataManager.Instance.GetBlackCardRewardRed() || RedDotDataManager.Instance.GetBlackCardClothingRed()
  210. || RedDotDataManager.Instance.GetStoreBrocadeWeavRewardRed());
  211. if (_ui.m_comTab.m_c1.selectedIndex == ConstStoreTabId.STORE_MONTH_CARD)
  212. {
  213. RedDotController.Instance.SetComRedDot(_ui.m_listSubTab.GetChildAt(ConstStoreSubId.STORE_MONTH_GOLD_CARD).asCom, RedDotDataManager.Instance.GetGoldCardRewardRed());
  214. RedDotController.Instance.SetComRedDot(_ui.m_listSubTab.GetChildAt(ConstStoreSubId.STORE_MONTH_BLACK_CARD).asCom, RedDotDataManager.Instance.GetBlackCardRewardRed() || RedDotDataManager.Instance.GetBlackCardClothingRed());
  215. RedDotController.Instance.SetComRedDot(_ui.m_listSubTab.GetChildAt(ConstStoreSubId.STORE_MONTH_BROCADE_WEAV).asCom, RedDotDataManager.Instance.GetStoreBrocadeWeavRewardRed());
  216. }
  217. }
  218. }
  219. }