StoreChargeView.cs 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. public override void Dispose()
  14. {
  15. if (_valueBarController != null)
  16. {
  17. _valueBarController.Dispose();
  18. _valueBarController = null;
  19. }
  20. if (_ui != null)
  21. {
  22. _ui.Dispose();
  23. }
  24. _ui = null;
  25. base.Dispose();
  26. }
  27. protected override void OnInit()
  28. {
  29. base.OnInit();
  30. packageName = UI_StoreChargeUI.PACKAGE_NAME;
  31. _ui = UI_StoreChargeUI.Create();
  32. this.viewCom = _ui.target;
  33. isfullScreen = true;
  34. this.clickBlankToClose = false;
  35. this.bringToFontOnClick = false;
  36. _ui.m_list.itemRenderer = ListItemRenderer;
  37. _valueBarController = new ValueBarController(_ui.m_valueBar);
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. EventAgent.AddEventListener(ConstMessage.SHOP_BUY, UpdateView);
  43. }
  44. protected override void OnShown()
  45. {
  46. base.OnShown();
  47. _shopCfgs = ShopCfgArray.Instance.GetCfgsBymenu1Andmenu2(ConstStoreTabId.STORE_CHARGE, ConstStoreSubId.STORE_CHARGE);
  48. _valueBarController.OnShown();
  49. UpdateView();
  50. }
  51. private void UpdateView()
  52. {
  53. _ui.m_list.numItems = _shopCfgs.Count;
  54. ShopViewManager.Instance.UpdateVipProgressCom(_ui.m_comVipLv.target);
  55. }
  56. protected override void OnHide()
  57. {
  58. base.OnHide();
  59. _valueBarController.OnHide();
  60. }
  61. protected override void RemoveEventListener()
  62. {
  63. base.RemoveEventListener();
  64. EventAgent.RemoveEventListener(ConstMessage.SHOP_BUY, UpdateView);
  65. }
  66. private void ListItemRenderer(int index, GObject obj)
  67. {
  68. ShopCfg shopCfg = _shopCfgs[index];
  69. UI_ListChargeItem item = UI_ListChargeItem.Proxy(obj);
  70. item.m_btnBuy.m_c1.selectedIndex = 1;
  71. item.m_btnBuy.m_txtTitle.text = shopCfg.price.ToString();
  72. if (item.target.data == null)
  73. {
  74. item.target.onClick.Add(OnClickBtnBuy);
  75. }
  76. item.target.data = index;
  77. item.m_txtName.text = string.Format("{0}{1}", shopCfg.itemNum, shopCfg.itemName);
  78. item.m_txtDesc.text = string.Format("首充赠送+{0}{1}", shopCfg.itemNum, shopCfg.itemName);
  79. bool isDouble = ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id) < shopCfg.doubleTimes;
  80. item.m_grpDouble.visible = isDouble;
  81. item.m_txtDesc.visible = isDouble;
  82. item.m_icon.url = "ui://Store/sc_zizhuan_" + (index + 1);
  83. UI_ListChargeItem.ProxyEnd();
  84. }
  85. private void OnClickBtnBuy(EventContext context)
  86. {
  87. GObject obj = context.sender as GObject;
  88. int index = (int)obj.data;
  89. ShopCfg itemData = _shopCfgs[index];
  90. if (!AntiAddictionController.CheckAntiAddictionRecharge(itemData.price))
  91. {
  92. ShopSProxy.ReqShopBuy(itemData.id, 1).Coroutine();
  93. LogServerHelper.SendPlayParticipationLog((int)PlayParticipationEnum.SHANG_CHENG, 2);
  94. }
  95. }
  96. }
  97. }