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