ZGTHgiftTipsView.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. private int shopId = 0;
  15. public override void Dispose()
  16. {
  17. if (_ui != null)
  18. {
  19. _ui.Dispose();
  20. _ui = null;
  21. }
  22. base.Dispose();
  23. }
  24. protected override void OnInit()
  25. {
  26. base.OnInit();
  27. packageName = UI_ZGTHgiftTipsUI.PACKAGE_NAME;
  28. _ui = UI_ZGTHgiftTipsUI.Create();
  29. this.viewCom = _ui.target;
  30. this.modal = true;
  31. this.viewCom.Center();
  32. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  33. _ui.m_Itemlist.itemRenderer = ListItemRender;
  34. _ui.m_btnBuy.onClick.Add(OnBtnGetClick);
  35. _ui.m_btnClose.onClick.Add(this.Hide);
  36. _ui.m_notTips.onClick.Add(OnClickTips);
  37. }
  38. protected override void AddEventListener()
  39. {
  40. base.AddEventListener();
  41. }
  42. protected override void RemoveEventListener()
  43. {
  44. base.RemoveEventListener();
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. ShopCfg shopCfg = ShopCfgArray.Instance.GetCfg(ActivityOpenCfgArray.Instance.GetCfg(6002).paramsArr[0]);
  50. giftItemId = shopCfg.itemId;
  51. shopId = shopCfg.id;
  52. itemcfg = ItemCfgArray.Instance.GetCfg(giftItemId);
  53. _ui.m_Itemlist.numItems = itemcfg.itemsArr.Length;
  54. int buyNum = ShopDataManager.Instance.GetGoodsBuyNumById(shopCfg.id);
  55. if (shopCfg.maxBuyNum == 0 || buyNum < shopCfg.maxBuyNum)
  56. {
  57. _ui.m_btnBuy.visible = true;
  58. }
  59. else
  60. {
  61. _ui.m_btnBuy.visible = false;
  62. }
  63. _ui.m_btnBuy.GetChild("title").text = string.Format("{0}元/购买", shopCfg.configPrice.ToString());
  64. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(6002);
  65. long endTime = 0;
  66. if (activityInfo != null)
  67. {
  68. endTime = activityInfo.EndTime;
  69. }
  70. var leftTime = endTime - TimeHelper.ServerNow();
  71. if (leftTime <= 0)
  72. {
  73. _ui.m_timeText.text = "";
  74. _ui.m_btnBuy.visible = false;
  75. Timers.inst.Remove(UpdateTime);
  76. return;
  77. }
  78. _ui.m_timeText.text = TimeUtil.FormattingTimeTo_DDHHmm((int)leftTime);
  79. Timers.inst.Add(1, 0, UpdateTime);
  80. }
  81. protected async override void OnHide()
  82. {
  83. if(_ui.m_TipImg.visible)
  84. {
  85. await ActivitySProxy.SetTipsStatus(6002, 1, 1);
  86. }
  87. else
  88. {
  89. await ActivitySProxy.SetTipsStatus(6000, 0, 1);
  90. }
  91. Timers.inst.Remove(UpdateTime);
  92. base.OnHide();
  93. }
  94. private void OnBtnGetClick()
  95. {
  96. _ui.m_btnBuy.visible = false;
  97. ReqShopBuy(shopId).Coroutine();
  98. }
  99. private void UpdateBtn()
  100. {
  101. _ui.m_btnBuy.visible = false;
  102. }
  103. private void OnClickTips()
  104. {
  105. if (_ui.m_TipImg.visible == false)
  106. {
  107. _ui.m_TipImg.visible = true;
  108. }
  109. else
  110. {
  111. _ui.m_TipImg.visible = false;
  112. }
  113. }
  114. private void ListItemRender(int index, GObject obj)
  115. {
  116. UI_ZGTHRewardItem item = UI_ZGTHRewardItem.Proxy(obj);
  117. int id = itemcfg.itemsArr[index][0];
  118. int count = itemcfg.itemsArr[index][1];
  119. ItemData itemDate = ItemUtil.createItemData(id, count);
  120. ItemView itemView = new ItemView(item.m_item);
  121. itemView.SetData(itemDate);
  122. item.m_name.text = ItemCfgArray.Instance.GetCfg(itemcfg.itemsArr[index][0]).name;
  123. UI_ZGTHRewardItem.ProxyEnd();
  124. }
  125. private void UpdateTime(object param)
  126. {
  127. var activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(6002);
  128. long endTime = 0;
  129. if (activityInfo != null)
  130. {
  131. endTime = activityInfo.EndTime;
  132. }
  133. var leftTime = endTime - TimeHelper.ServerNow();
  134. if (leftTime <= 0)
  135. {
  136. _ui.m_timeText.text = "";
  137. _ui.m_btnBuy.visible = false;
  138. Timers.inst.Remove(UpdateTime);
  139. return;
  140. }
  141. _ui.m_timeText.text = TimeUtil.FormattingTimeTo_DDHHmm((int)leftTime);
  142. }
  143. }
  144. }