NewYearRedEnvelopeView.cs 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. using FairyGUI;
  2. using ET;
  3. using UI.NewYearRedEnvelope;
  4. using UI.CommonGame;
  5. using UnityEngine;
  6. using System;
  7. using System.Collections.Generic;
  8. namespace GFGGame
  9. {
  10. public class NewYearRedEnvelopeView : BaseWindow
  11. {
  12. private UI_NewYearRedEnvelopeUI _ui;
  13. private List<EffectUI> _effectUIList = new List<EffectUI>();
  14. public override void Dispose()
  15. {
  16. for (int i = 0; i < _effectUIList.Count; i++)
  17. {
  18. EffectUIPool.Recycle(_effectUIList[i]);
  19. }
  20. _effectUIList.Clear();
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. packageName = UI_NewYearRedEnvelopeUI.PACKAGE_NAME;
  32. _ui = UI_NewYearRedEnvelopeUI.Create();
  33. this.viewCom = _ui.target;
  34. this.viewCom.Center();
  35. this.modal = true;
  36. //viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  37. _ui.m_btnOpen.onClick.Add(OnClickBtnOpen);
  38. _ui.m_btnDoubleGet.target.onClick.Add(OnClickBtnDoubleGet);
  39. }
  40. protected override void OnShown()
  41. {
  42. base.OnShown();
  43. if (NewYearRedEnvelopeDataManager.Status == RedPacketStatus.None)
  44. {
  45. _ui.m_openType.selectedIndex = 0;
  46. _ui.m_titleImgType.selectedIndex = 0;
  47. RedDotController.Instance.SetComRedDot(_ui.m_btnOpen, true, "", -50, 100);
  48. RefreshTime();
  49. }
  50. else
  51. {
  52. RefreshOpenView();
  53. RefreshViewInfo();
  54. }
  55. AddEffect();
  56. Timers.inst.Add(1, 0, UpdateTime);
  57. }
  58. private void AddEffect()
  59. {
  60. _effectUIList.Add(EffectUIPool.CreateEffectUI(_ui.m_holderTitle, "ui_Activity", "RedPack_Top_Quad"));
  61. _effectUIList.Add(EffectUIPool.CreateEffectUI(_ui.m_holderAFu, "ui_Activity", "RedPack_AF_Anmation"));
  62. _effectUIList.Add(EffectUIPool.CreateEffectUI(_ui.m_holderOpenBtn, "ui_Activity", "RedPack_ONE_cirle"));
  63. _effectUIList.Add(EffectUIPool.CreateEffectUI(_ui.m_holderdoubao1, "ui_Activity", "RedPack_doubao_Loop"));
  64. _effectUIList.Add(EffectUIPool.CreateEffectUI(_ui.m_holderdoubao2, "ui_Activity", "RedPack_doubao_Loop_R"));
  65. }
  66. protected override void AddEventListener()
  67. {
  68. base.AddEventListener();
  69. EventAgent.AddEventListener(ConstMessage.NEW_YEAR_RED_ENVELOPE_INFO, RefreshViewInfo);
  70. }
  71. protected override void RemoveEventListener()
  72. {
  73. base.RemoveEventListener();
  74. EventAgent.RemoveEventListener(ConstMessage.NEW_YEAR_RED_ENVELOPE_INFO, RefreshViewInfo);
  75. }
  76. private void RefreshViewInfo()
  77. {
  78. _ui.m_btnDoubleGet.target.visible = NewYearRedEnvelopeDataManager.Status != RedPacketStatus.Double;
  79. }
  80. private void RefreshOpenView()
  81. {
  82. _ui.m_openType.selectedIndex = 2;
  83. var titleIndex = PlayerPrefs.GetString("NewYearRedEnvelopeRamdomInt");
  84. _ui.m_titleImgType.selectedIndex = Convert.ToInt32(titleIndex);
  85. UI_ComItem item = UI_ComItem.Proxy(_ui.m_itemReward);
  86. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(NewYearRedEnvelopeDataManager.ItemId);
  87. RarityIconController.UpdateRarityIcon(item.m_loaRarity, itemCfg.id, false);
  88. item.target.data = itemCfg;
  89. item.m_QualityType.selectedIndex = itemCfg.rarity - 1;
  90. item.m_loaIcon.url = ResPathUtil.GetIconPath(itemCfg);
  91. item.m_txtCount.text = NewYearRedEnvelopeDataManager.ItemNum.ToString();
  92. UI_ComItem.ProxyEnd();
  93. _ui.m_textGetNum.text = NewYearRedEnvelopeDataManager.ItemNum.ToString();
  94. }
  95. private void UpdateTime(object param)
  96. {
  97. RefreshTime();
  98. }
  99. private void RefreshTime()
  100. {
  101. int actLimitId = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.NewYearRedPacket);
  102. ActivityOpenCfg activityOpenCfg = ActivityOpenCfgArray.Instance.GetCfg(actLimitId);
  103. long time = TimeUtil.DateTimeToTimestamp(activityOpenCfg.endTime) - TimeHelper.ServerNow();
  104. string strTime = TimeUtil.FormattingTimeTo_DDHHmm(time);
  105. _ui.m_txtTime.text = "µÚÒ»Ì죺" + strTime;
  106. UI_Button1 btn = UI_Button1.Proxy(_ui.m_btnDoubleGet.target);
  107. btn.m_txtTime.text = strTime;
  108. UI_Button1.ProxyEnd();
  109. }
  110. private void OnClickBtnDoubleGet(EventContext context)
  111. {
  112. BuyDoubleRedPacket();
  113. }
  114. private async void BuyDoubleRedPacket()
  115. {
  116. int actRedPacketId = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.NewYearRedPacket);
  117. bool result = await NewYearRedEnvelopeSProxy.ReqDoubleRedPacket(actRedPacketId);
  118. if (result)
  119. {
  120. RefreshOpenView();
  121. RefreshViewInfo();
  122. }
  123. }
  124. private void OnClickBtnOpen(EventContext context)
  125. {
  126. _ui.m_imgTitle.visible = false;
  127. ReqLeagueList();
  128. }
  129. private async void ReqLeagueList()
  130. {
  131. int actRedPacketId = ActivityDataManager.Instance.GetCurOpenActiveByType(ActivityType.NewYearRedPacket);
  132. bool result = await NewYearRedEnvelopeSProxy.ReqOpenRedPacket(actRedPacketId);
  133. if (result)
  134. {
  135. _ui.m_openType.selectedIndex = 1;
  136. _effectUIList.Add(EffectUIPool.CreateEffectUI(_ui.m_holderAllBg, "ui_Activity", "RedPack_ALL_tx"));
  137. Timers.inst.Add(0.7f, 0, UpdateOpenTime);
  138. }
  139. }
  140. private void UpdateOpenTime(object param)
  141. {
  142. _ui.m_imgTitle.visible = true;
  143. RefreshOpenView();
  144. }
  145. protected override void OnHide()
  146. {
  147. base.OnHide();
  148. Timers.inst.Remove(UpdateTime);
  149. Timers.inst.Remove(UpdateOpenTime);
  150. }
  151. }
  152. }