StoreGrowthFundView.cs 6.6 KB

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