StoreChargeView.cs 3.5 KB

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