StoreGrowthFundView.cs 6.8 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. using cfg.GfgCfg;
  8. namespace GFGGame
  9. {
  10. public class StoreGrowthFundView : BaseWindow
  11. {
  12. private UI_StoreGrowthFundUI _ui;
  13. private ValueBarController _valueBarController;
  14. private int menu2;
  15. private EffectUI _effectUI1;
  16. private int ScrollToViewIndex = 0;
  17. private bool firstToIndex;
  18. public override void Dispose()
  19. {
  20. EffectUIPool.Recycle(_effectUI1);
  21. _effectUI1 = null;
  22. if (_valueBarController != null)
  23. {
  24. _valueBarController.Dispose();
  25. _valueBarController = null;
  26. }
  27. if (_ui != null)
  28. {
  29. _ui.Dispose();
  30. }
  31. _ui = null;
  32. base.Dispose();
  33. }
  34. protected override void OnInit()
  35. {
  36. base.OnInit();
  37. packageName = UI_StoreGrowthFundUI.PACKAGE_NAME;
  38. _ui = UI_StoreGrowthFundUI.Create();
  39. this.viewCom = _ui.target;
  40. isfullScreen = true;
  41. this.clickBlankToClose = false;
  42. this.bringToFontOnClick = false;
  43. _valueBarController = new ValueBarController(_ui.m_valueBar);
  44. _ui.m_list.itemRenderer = ListItemRenderer;
  45. _ui.m_btnBuy.target.onClick.Add(OnBtnBuyClick);
  46. }
  47. protected override void AddEventListener()
  48. {
  49. base.AddEventListener();
  50. EventAgent.AddEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  51. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. _valueBarController.OnShown();
  57. _ui.m_txtDailyMoneyCount.text = "4800";
  58. UpdateView();
  59. UpdateRedDot();
  60. }
  61. protected override void OnHide()
  62. {
  63. base.OnHide();
  64. _valueBarController.OnHide();
  65. }
  66. protected override void RemoveEventListener()
  67. {
  68. base.RemoveEventListener();
  69. EventAgent.RemoveEventListener(ConstMessage.RED_CHANGE, UpdateRedDot);
  70. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView);
  71. }
  72. private void OnBtnBlackRewardClick()
  73. {
  74. ViewManager.Show<StoreBlackCardRewardView>();
  75. }
  76. private void UpdateView()
  77. {
  78. GetGrowthFundBuy();
  79. ScrollToViewIndex = 0;
  80. firstToIndex = true;
  81. int count = 0;
  82. for(int i = 0;i < CommonDataManager.Tables.TblGrowthFundCfg.DataList.Count ;i++)
  83. {
  84. if(RoleDataManager.lvl >= CommonDataManager.Tables.TblGrowthFundCfg.DataList[i].Level)
  85. {
  86. count += CommonDataManager.Tables.TblGrowthFundCfg.DataList[i].Bonus[0].Count;
  87. }
  88. }
  89. _ui.m_txtGiftBag.text = count.ToString();
  90. _ui.m_list.numItems = CommonDataManager.Tables.TblGrowthFundCfg.DataList.Count;
  91. _ui.m_list.ScrollToView(ScrollToViewIndex,false,true);
  92. }
  93. private void OnBtnBuyClick()
  94. {
  95. //是否购买
  96. if (!GetGrowthFundBuy())
  97. {
  98. int id = CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(3002).Params1[0];
  99. ShopSProxy.ReqShopBuy(id).Coroutine();
  100. ShopSProxy.ReqGetGrowthFundInfo().Coroutine();
  101. }
  102. }
  103. private async void OnBtnGetClick(EventContext context)
  104. {
  105. GObject obj = context.sender as GObject;
  106. int goodsId = (int)obj.data;
  107. UI_GrowthFundItemUI item = UI_GrowthFundItemUI.Proxy(_ui.m_list.GetChildAt(goodsId - 1));
  108. if(item.m_rewardBtn.m_c1.selectedIndex != 1)
  109. {
  110. return;
  111. }
  112. UI_GrowthFundItemUI.ProxyEnd();
  113. bool result = await ShopSProxy.ReqGetGrowthFundReward(3002,goodsId);
  114. _ui.m_list.numItems = CommonDataManager.Tables.TblGrowthFundCfg.DataList.Count;
  115. }
  116. private void ListItemRenderer(int index, GObject obj)
  117. {
  118. UI_GrowthFundItemUI item = UI_GrowthFundItemUI.Proxy(obj);
  119. int num = CommonDataManager.Tables.TblGrowthFundCfg.DataList[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 == CommonDataManager.Tables.TblGrowthFundCfg.DataList[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(CommonDataManager.Tables.TblGrowthFundCfg.DataList[index].Bonus[0].ToGfgGameItemParam(), 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 = CommonDataManager.Tables.TblShopCfg.GetOrDefault( CommonDataManager.Tables.TblActivityOpenCfg.GetOrDefault(3002).Params1[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. }