ZGTHgiftTipsView.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  1. using ET;
  2. using FairyGUI;
  3. using UI.ActivityMain;
  4. using UI.CommonGame;
  5. using static GFGGame.ShopSProxy;
  6. namespace GFGGame
  7. {
  8. public class ZGTHgiftTipsView : BaseWindow
  9. {
  10. //直购648
  11. private UI_ZGTHgiftTipsUI _ui;
  12. private int giftItemId = 0;
  13. private ItemCfg itemcfg;
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_ZGTHgiftTipsUI.PACKAGE_NAME;
  27. _ui = UI_ZGTHgiftTipsUI.Create();
  28. this.viewCom = _ui.target;
  29. this.modal = true;
  30. this.viewCom.Center();
  31. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  32. _ui.m_Itemlist.itemRenderer = ListItemRender;
  33. _ui.m_btnBuy.onClick.Add(OnBtnGetClick);
  34. _ui.m_btnClose.onClick.Add(this.Hide);
  35. }
  36. protected override void AddEventListener()
  37. {
  38. base.AddEventListener();
  39. }
  40. protected override void RemoveEventListener()
  41. {
  42. base.RemoveEventListener();
  43. }
  44. protected override void OnShown()
  45. {
  46. base.OnShown();
  47. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(ActivityOpenCfgArray.Instance.GetCfg(6001).paramsArr[0]);
  48. giftItemId = shopCfg.itemId;
  49. itemcfg = ItemCfgArray.Instance.GetCfg(giftItemId);
  50. _ui.m_Itemlist.numItems = itemcfg.itemsArr.Length;
  51. int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  52. if (shopCfg.maxBuyNum == 0 || buyNum < shopCfg.maxBuyNum)
  53. {
  54. _ui.m_btnBuy.visible = true;
  55. }
  56. else
  57. {
  58. _ui.m_btnBuy.visible = false;
  59. }
  60. Timers.inst.Add(1, 0, UpdateTime);
  61. }
  62. protected override void OnHide()
  63. {
  64. Timers.inst.Remove(UpdateTime);
  65. base.OnHide();
  66. }
  67. private void OnBtnGetClick()
  68. {
  69. _ui.m_btnBuy.visible = false;
  70. ReqShopBuy(itemcfg.id).Coroutine();
  71. }
  72. private void UpdateBtn()
  73. {
  74. _ui.m_btnBuy.visible = false;
  75. }
  76. private void ListItemRender(int index, GObject obj)
  77. {
  78. UI_ZGTHRewardItem item = UI_ZGTHRewardItem.Proxy(obj);
  79. int id = itemcfg.itemsArr[index][0];
  80. int count = itemcfg.itemsArr[index][1];
  81. ItemData itemDate = ItemUtil.createItemData(id, count);
  82. ItemView itemView = new ItemView(item.m_item);
  83. itemView.SetData(itemDate);
  84. item.m_name.text = ItemCfgArray.Instance.GetCfg(itemcfg.id).name;
  85. UI_ZGTHRewardItem.ProxyEnd();
  86. }
  87. private void UpdateTime(object param)
  88. {
  89. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(6002);
  90. long endTime = 0;
  91. if (activityInfo != null)
  92. {
  93. endTime = activityInfo.EndTime;
  94. }
  95. var leftTime = endTime - TimeHelper.ServerNow();
  96. if (leftTime <= 0)
  97. {
  98. _ui.m_timeText.text = "";
  99. _ui.m_btnBuy.visible = false;
  100. Timers.inst.Remove(UpdateTime);
  101. return;
  102. }
  103. _ui.m_timeText.text = TimeUtil.FormattingTimeTo_DDHHmm((int)leftTime);
  104. }
  105. }
  106. }