StoreGrowthFundView.cs 6.6 KB

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