NoticeView.cs 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Notice;
  4. using System.Collections.Generic;
  5. using ET;
  6. namespace GFGGame
  7. {
  8. public class NoticeView : BaseWindow
  9. {
  10. private UI_NoticeUI _ui;
  11. private EffectUI _effectUI1;
  12. private EffectUI _effectUI2;
  13. private AdCfg[] activitydata;
  14. private List<AdCfg> showActivity = new List<AdCfg>();
  15. public override void Dispose()
  16. {
  17. EffectUIPool.Recycle(_effectUI1);
  18. _effectUI1 = null;
  19. EffectUIPool.Recycle(_effectUI2);
  20. _effectUI2 = null;
  21. if (_ui != null)
  22. {
  23. _ui.Dispose();
  24. _ui = null;
  25. }
  26. base.Dispose();
  27. }
  28. protected override void Init()
  29. {
  30. base.Init();
  31. packageName = UI_NoticeUI.PACKAGE_NAME;
  32. _ui = UI_NoticeUI.Create();
  33. this.viewCom = _ui.target;
  34. this.viewCom.Center();
  35. this.modal = true;
  36. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  37. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. _ui.m_listActivity.itemRenderer = ListActivityItemRender;
  42. //_ui.m_listActivity.onClick.Add(OnListActivityClick);
  43. _ui.m_listNotice.itemRenderer = ListNoticeItemRender;
  44. _ui.m_c1.onChanged.Add(OnCtrlChange);
  45. AddEffect();
  46. }
  47. protected override void AddEventListener()
  48. {
  49. base.AddEventListener();
  50. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  51. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. _ui.m_c1.selectedIndex = 1;
  57. _ui.m_listActivity.visible = true;
  58. _ui.m_listNotice.visible = true;
  59. _ui.m_buttonCom.visible = true;
  60. OnCtrlChange();
  61. }
  62. protected override void OnHide()
  63. {
  64. base.OnHide();
  65. }
  66. protected override void RemoveEventListener()
  67. {
  68. base.RemoveEventListener();
  69. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  70. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  71. }
  72. private void AddEffect()
  73. {
  74. //邊框左上角特效
  75. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up");
  76. //邊框右下角特效
  77. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down");
  78. }
  79. private void OnCtrlChange()
  80. {
  81. if (_ui.m_c1.selectedIndex == 0)
  82. {
  83. UpdateInfo();
  84. _ui.m_listActivity.numItems = showActivity.Count;
  85. _ui.m_txtTips.visible = _ui.m_listActivity.numItems == 0;
  86. }
  87. else if (_ui.m_c1.selectedIndex == 1)
  88. {
  89. _ui.m_listNotice.numItems = NoticeDataManager.Instance.NoticeInfos.Count;
  90. _ui.m_txtTips.visible = _ui.m_listNotice.numItems == 0;
  91. }
  92. }
  93. private void ListActivityItemRender(int index, GObject obj)
  94. {
  95. UI_ListActivityItem item = UI_ListActivityItem.Proxy(obj);
  96. item.m_loaShow.url = ResPathUtil.GetActivityPath("");
  97. item.m_txtName.text = showActivity[index].res;
  98. switch (showActivity[index].jumpId)
  99. {
  100. //后续添加其他活动
  101. case "LuckyBoxView":
  102. item.m_imgTips.visible = RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy) || RedDotDataManager.Instance.GetLuckyBoxFreeTimes();
  103. break;
  104. default:
  105. break;
  106. }
  107. long endTime = 0;
  108. long curTime = TimeHelper.ServerNow();
  109. if (showActivity[0] != null || showActivity != null)
  110. {
  111. endTime = TimeUtil.DateTimeToTimestamp(showActivity[0].endTime);
  112. }
  113. item.m_txtTime.text = string.Format("剩余时间:{0}", TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime));
  114. item.target.onClick.Add(OnListActivityClick);
  115. item.target.data = showActivity[index];
  116. UI_ListActivityItem.ProxyEnd();
  117. }
  118. private void OnListActivityClick(EventContext context)
  119. {
  120. AdCfg adCfg = (AdCfg)(context.sender as GObject).data;
  121. object[] param = null;
  122. int jumpIndex = 0;
  123. if (adCfg.jumpId == nameof(LimitChargeView))
  124. {
  125. param = new object[] { adCfg.activityId };
  126. }
  127. if (adCfg.jumpId == nameof(NewLimitChargeView))
  128. {
  129. param = new object[] { adCfg.activityId };
  130. }
  131. if (adCfg.jumpId == nameof(LuckyBoxView))
  132. {
  133. jumpIndex = adCfg.jumpParamArr[0];
  134. }
  135. if (jumpIndex != 0)
  136. {
  137. this.Hide();
  138. ViewManager.Show($"GFGGame.{adCfg.jumpId}", jumpIndex);
  139. }
  140. else
  141. {
  142. this.Hide();
  143. ViewManager.Show($"GFGGame.{adCfg.jumpId}", param);
  144. }
  145. }
  146. private void ListNoticeItemRender(int index, GObject obj)
  147. {
  148. NoticeInfo noticeInfo = NoticeDataManager.Instance.NoticeInfos[index];
  149. UI_ListNoticeItem item = UI_ListNoticeItem.Proxy(obj);
  150. item.m_txtTitle.text = noticeInfo.title;
  151. item.m_txtTime.text = TimeUtil.FormattingTimeTo_yyyMMdd0(noticeInfo.time);
  152. // item.m_imgTips.visible = !noticeInfo.readStatus;
  153. RedDotController.Instance.SetComRedDot(item.target, !noticeInfo.readStatus, "gg_gg_hdhdgth", -40, 32);
  154. if (item.m_btnGo.data == null)
  155. {
  156. item.m_btnGo.onClick.Add(OnListNoticeBtnGoClick);
  157. }
  158. item.m_btnGo.data = noticeInfo;
  159. UI_ListNoticeItem.ProxyEnd();
  160. }
  161. private async void OnListNoticeBtnGoClick(EventContext context)
  162. {
  163. _ui.m_listActivity.visible = false;
  164. _ui.m_listNotice.visible = false;
  165. _ui.m_buttonCom.visible = false;
  166. NoticeInfo noticeInfo = (context.sender as GObject).data as NoticeInfo;
  167. if (noticeInfo.content == "")
  168. {
  169. bool result = await NoticeSProxy.ReqSystemNotice(noticeInfo.noticeId);
  170. if (result)
  171. {
  172. ViewManager.Show<NoticeSystemShowView>(NoticeDataManager.Instance.GetNoticeInfoById(noticeInfo.noticeId));
  173. }
  174. }
  175. else
  176. {
  177. ViewManager.Show<NoticeSystemShowView>(noticeInfo);
  178. }
  179. }
  180. private void UpdateInfo()
  181. {
  182. if(activitydata == null)
  183. {
  184. activitydata = AdCfgArray.Instance.dataArray;
  185. }
  186. showActivity.Clear();
  187. for (int i = 0; i < activitydata.Length; i++)
  188. {
  189. AdCfg adCfg = activitydata[i];
  190. if (adCfg.activityId > 0)
  191. {
  192. if (ActivityGlobalDataManager.Instance.GetActivityInfo(adCfg.activityId) == null) continue;
  193. ActivityInfo activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(adCfg.activityId);
  194. if (TimeHelper.ServerNow() < activityInfo.StartTime || TimeHelper.ServerNow() > activityInfo.EndTime) continue;
  195. }
  196. if (adCfg.startTime != "" && adCfg.startTime != null)
  197. {
  198. long startTime = TimeUtil.DateTimeToTimestamp(adCfg.startTime);
  199. long endTime = TimeUtil.DateTimeToTimestamp(adCfg.endTime);
  200. if (TimeHelper.ServerNow() < startTime || TimeHelper.ServerNow() > endTime)
  201. {
  202. continue;
  203. }
  204. else
  205. {
  206. showActivity.Add(adCfg);
  207. }
  208. }
  209. }
  210. }
  211. }
  212. }