StoreGrowthFundView.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. using UI.Store;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using ET;
  6. using System;
  7. namespace GFGGame
  8. {
  9. public class StoreGrowthFundView : BaseWindow
  10. {
  11. private UI_StoreGrowthFundUI _ui;
  12. private ValueBarController _valueBarController;
  13. private int menu2;
  14. private EffectUI _effectUI1;
  15. public override void Dispose()
  16. {
  17. EffectUIPool.Recycle(_effectUI1);
  18. _effectUI1 = null;
  19. if (_valueBarController != null)
  20. {
  21. _valueBarController.Dispose();
  22. _valueBarController = null;
  23. }
  24. if (_ui != null)
  25. {
  26. _ui.Dispose();
  27. }
  28. _ui = null;
  29. base.Dispose();
  30. }
  31. protected override void OnInit()
  32. {
  33. base.OnInit();
  34. packageName = UI_StoreGrowthFundUI.PACKAGE_NAME;
  35. _ui = UI_StoreGrowthFundUI.Create();
  36. this.viewCom = _ui.target;
  37. isfullScreen = true;
  38. this.clickBlankToClose = false;
  39. this.bringToFontOnClick = false;
  40. _valueBarController = new ValueBarController(_ui.m_valueBar);
  41. _ui.m_list.itemRenderer = ListItemRenderer;
  42. _ui.m_btnBuy.target.onClick.Add(OnBtnBuyClick);
  43. }
  44. protected override void AddEventListener()
  45. {
  46. base.AddEventListener();
  47. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  48. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  49. }
  50. protected override void OnShown()
  51. {
  52. base.OnShown();
  53. _valueBarController.OnShown();
  54. UpdateView();
  55. UpdateRedDot();
  56. }
  57. protected override void OnHide()
  58. {
  59. base.OnHide();
  60. _valueBarController.OnHide();
  61. }
  62. protected override void RemoveEventListener()
  63. {
  64. base.RemoveEventListener();
  65. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  66. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateView);
  67. }
  68. private void OnBtnBlackRewardClick()
  69. {
  70. ViewManager.Show<StoreBlackCardRewardView>();
  71. }
  72. private void UpdateView()
  73. {
  74. GetGrowthFundBuy();
  75. int count = 0;
  76. for(int i = 0;i < GrowthFundCfgArray.Instance.dataArray.Length;i++)
  77. {
  78. if(RoleDataManager.lvl >= GrowthFundCfgArray.Instance.dataArray[i].level)
  79. {
  80. count += GrowthFundCfgArray.Instance.dataArray[i].bonusArr[0][1];
  81. }
  82. }
  83. _ui.m_txtGiftBag.text = count.ToString();
  84. _ui.m_list.numItems = GrowthFundCfgArray.Instance.dataArray.Length;
  85. }
  86. private void OnBtnBuyClick()
  87. {
  88. //是否购买
  89. if (!GetGrowthFundBuy())
  90. {
  91. int id = ActivityOpenCfgArray.Instance.GetCfg(3002).paramsArr[0];
  92. ShopSProxy.ReqShopBuy(id).Coroutine();
  93. }
  94. }
  95. private async void OnBtnGetClick(EventContext context)
  96. {
  97. GObject obj = context.sender as GObject;
  98. int goodsId = (int)obj.data;
  99. UI_GrowthFundItemUI item = UI_GrowthFundItemUI.Proxy(_ui.m_list.GetChildAt(goodsId - 1));
  100. if(item.m_rewardBtn.m_c1.selectedIndex != 1)
  101. {
  102. return;
  103. }
  104. UI_GrowthFundItemUI.ProxyEnd();
  105. bool result = await ShopSProxy.ReqGetGrowthFundReward(3002,goodsId);
  106. if (result)
  107. {
  108. _ui.m_list.numItems = GrowthFundCfgArray.Instance.dataArray.Length;
  109. }
  110. }
  111. private void ListItemRenderer(int index, GObject obj)
  112. {
  113. UI_GrowthFundItemUI item = UI_GrowthFundItemUI.Proxy(obj);
  114. int num = GrowthFundCfgArray.Instance.dataArray[index].level;
  115. item.m_rewardDesc.text = string.Format("等级达{0}级可领",num);
  116. item.m_rewardBtn.m_c1.selectedIndex = 1;
  117. if (GetGrowthFundBuy())
  118. {
  119. bool isRed = true;
  120. if(RoleDataManager.lvl >= num)
  121. {
  122. foreach (int i in ShopDataManager.Instance.GrowthFundRewardList)
  123. {
  124. if (i == GrowthFundCfgArray.Instance.dataArray[index].id)
  125. {
  126. item.m_rewardBtn.m_c1.selectedIndex = 2;
  127. isRed = false;
  128. break;
  129. }
  130. }
  131. }
  132. else
  133. {
  134. item.m_rewardBtn.m_c1.selectedIndex = 0;
  135. isRed = false;
  136. }
  137. RedDotController.Instance.SetComRedDot(item.m_rewardBtn.target, isRed);
  138. }
  139. else
  140. {
  141. item.m_rewardBtn.m_c1.selectedIndex = 0;
  142. RedDotController.Instance.SetComRedDot(item.m_rewardBtn.target, false);
  143. }
  144. ItemUtil.CreateItemView(GrowthFundCfgArray.Instance.dataArray[index].bonusArr[0], item.m_reward as GComponent);
  145. if (item.m_rewardBtn.target.data == null)
  146. {
  147. item.m_rewardBtn.target.onClick.Add(OnBtnGetClick);
  148. }
  149. item.m_rewardBtn.target.data = index + 1;
  150. UI_GrowthFundItemUI.ProxyEnd();
  151. }
  152. private bool GetGrowthFundBuy()
  153. {
  154. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(ActivityOpenCfgArray.Instance.GetCfg(3002).paramsArr[0]);
  155. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  156. if (remainBuyNum == 0)
  157. {
  158. //已售完
  159. _ui.m_btnBuy.m_c1.selectedIndex = 1;
  160. return true;
  161. }
  162. else
  163. {
  164. //未售完
  165. _ui.m_btnBuy.m_c1.selectedIndex = 0;
  166. return false;
  167. }
  168. }
  169. private void UpdateRedDot()
  170. {
  171. }
  172. }
  173. }