StoreChargeView.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using UI.Store;
  2. using UI.CommonGame;
  3. using FairyGUI;
  4. using System.Collections.Generic;
  5. using ET;
  6. namespace GFGGame
  7. {
  8. public class StoreChargeView : BaseWindow
  9. {
  10. private UI_StoreChargeUI _ui;
  11. private ValueBarController _valueBarController;
  12. private List<ShopCfg> _shopCfgs;
  13. private List<EffectUI> _effectUIs = new List<EffectUI>();
  14. public override void Dispose()
  15. {
  16. if (_valueBarController != null)
  17. {
  18. _valueBarController.Dispose();
  19. _valueBarController = null;
  20. }
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. }
  25. _ui = null;
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI_StoreChargeUI.PACKAGE_NAME;
  32. _ui = UI_StoreChargeUI.Create();
  33. this.viewCom = _ui.target;
  34. isfullScreen = true;
  35. this.clickBlankToClose = false;
  36. this.bringToFontOnClick = false;
  37. _ui.m_list.itemRenderer = ListItemRenderer;
  38. _valueBarController = new ValueBarController(_ui.m_valueBar);
  39. }
  40. protected override void AddEventListener()
  41. {
  42. base.AddEventListener();
  43. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. _shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE);
  49. _valueBarController.OnShown();
  50. _ui.m_comVipLv.m_loaIcon.url = ResPathUtil.GetIconPath("tb_hyjf", "png");
  51. UpdateView();
  52. }
  53. private void DestroyEffect()
  54. {
  55. for (int i = 0; i < _effectUIs.Count; i++)
  56. {
  57. EffectUIPool.Recycle(_effectUIs[i]);
  58. _effectUIs[i] = null;
  59. }
  60. _effectUIs.Clear();
  61. }
  62. private void UpdateView()
  63. {
  64. DestroyEffect();
  65. _ui.m_list.numItems = _shopCfgs.Count;
  66. ShopViewManager.Instance.UpdateVipProgressCom(_ui.m_comVipLv.target);
  67. }
  68. protected override void OnHide()
  69. {
  70. base.OnHide();
  71. DestroyEffect();
  72. _valueBarController.OnHide();
  73. }
  74. protected override void RemoveEventListener()
  75. {
  76. base.RemoveEventListener();
  77. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView);
  78. }
  79. private void ListItemRenderer(int index, GObject obj)
  80. {
  81. ShopCfg shopCfg = _shopCfgs[index];
  82. UI_ListChargeItem item = UI_ListChargeItem.Proxy(obj);
  83. item.m_btnBuy.m_c1.selectedIndex = 1;
  84. item.m_btnBuy.m_txtTitle.text = shopCfg.price.ToString();
  85. if (item.target.data == null)
  86. {
  87. item.target.onClick.Add(OnClickBtnBuy);
  88. }
  89. item.target.data = index;
  90. ItemCfg doubleItem = ItemCfgArray.Instance.GetCfg(shopCfg.doubleItemId);
  91. item.m_txtName.text = string.Format("{0}{1}", shopCfg.itemNum, doubleItem.name);
  92. item.m_txtDesc.text = string.Format("首充赠送+{0}{1}", shopCfg.itemNum, doubleItem.name);
  93. bool isDouble = ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id) < shopCfg.doubleTimes;
  94. item.m_grpDouble.visible = isDouble;
  95. item.m_txtDesc.visible = isDouble;
  96. item.m_icon.url = "ui://Store/sc_zizhuan_" + (index + 1);
  97. if (isDouble) {
  98. EffectUI _effectUI = EffectUIPool.CreateEffectUI(item.m_holderfEff, "ui_Small_parts", "store_FirstCharge_Double");
  99. _effectUIs.Add(_effectUI);
  100. }
  101. UI_ListChargeItem.ProxyEnd();
  102. }
  103. private void OnClickBtnBuy(EventContext context)
  104. {
  105. GObject obj = context.sender as GObject;
  106. int index = (int)obj.data;
  107. ShopCfg itemData = _shopCfgs[index];
  108. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.price))
  109. {
  110. ShopSProxy.ReqShopBuy(itemData.id, 1).Coroutine();
  111. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  112. }
  113. }
  114. }
  115. }