StoreChargeView.cs 4.5 KB

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