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. _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. }
  100. }
  101. private async void OnBtnGetClick(EventContext context)
  102. {
  103. GObject obj = context.sender as GObject;
  104. int goodsId = (int)obj.data;
  105. UI_GrowthFundItemUI item = UI_GrowthFundItemUI.Proxy(_ui.m_list.GetChildAt(goodsId - 1));
  106. if(item.m_rewardBtn.m_c1.selectedIndex != 1)
  107. {
  108. return;
  109. }
  110. UI_GrowthFundItemUI.ProxyEnd();
  111. bool result = await ShopSProxy.ReqGetGrowthFundReward(3002,goodsId);
  112. if (result)
  113. {
  114. _ui.m_list.numItems = GrowthFundCfgArray.Instance.dataArray.Length;
  115. }
  116. }
  117. private void ListItemRenderer(int index, GObject obj)
  118. {
  119. UI_GrowthFundItemUI item = UI_GrowthFundItemUI.Proxy(obj);
  120. int num = GrowthFundCfgArray.Instance.dataArray[index].level;
  121. item.m_rewardDesc.text = string.Format("等级达{0}级可领",num);
  122. item.m_rewardBtn.m_c1.selectedIndex = 1;
  123. if (GetGrowthFundBuy())
  124. {
  125. bool isRed = true;
  126. if(RoleDataManager.lvl >= num)
  127. {
  128. foreach (int i in ShopDataManager.Instance.GrowthFundRewardList)
  129. {
  130. if (i == GrowthFundCfgArray.Instance.dataArray[index].id)
  131. {
  132. item.m_rewardBtn.m_c1.selectedIndex = 2;
  133. isRed = false;
  134. break;
  135. }
  136. }
  137. }
  138. else
  139. {
  140. item.m_rewardBtn.m_c1.selectedIndex = 0;
  141. isRed = false;
  142. }
  143. RedDotController.Instance.SetComRedDot(item.m_rewardBtn.target, isRed);
  144. }
  145. else
  146. {
  147. item.m_rewardBtn.m_c1.selectedIndex = 0;
  148. RedDotController.Instance.SetComRedDot(item.m_rewardBtn.target, false);
  149. }
  150. ItemUtil.CreateItemView(GrowthFundCfgArray.Instance.dataArray[index].bonusArr[0], item.m_reward as GComponent);
  151. if (item.m_rewardBtn.target.data == null)
  152. {
  153. item.m_rewardBtn.target.onClick.Add(OnBtnGetClick);
  154. }
  155. if(item.m_rewardBtn.m_c1.selectedIndex == 1)
  156. {
  157. if(firstToIndex)
  158. {
  159. ScrollToViewIndex = index;
  160. firstToIndex = false;
  161. }
  162. }
  163. item.m_rewardBtn.target.data = index + 1;
  164. UI_GrowthFundItemUI.ProxyEnd();
  165. }
  166. private bool GetGrowthFundBuy()
  167. {
  168. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(ActivityOpenCfgArray.Instance.GetCfg(3002).paramsArr[0]);
  169. var remainBuyNum = shopCfg.maxBuyNum - ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  170. if (remainBuyNum == 0)
  171. {
  172. //已售完
  173. _ui.m_btnBuy.m_c1.selectedIndex = 1;
  174. return true;
  175. }
  176. else
  177. {
  178. //未售完
  179. _ui.m_btnBuy.m_c1.selectedIndex = 0;
  180. return false;
  181. }
  182. }
  183. private void UpdateRedDot()
  184. {
  185. }
  186. }
  187. }