StoreChargeView.cs 4.6 KB

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