NoticeView.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260
  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. //isReturnView = true;
  38. }
  39. protected override void OnInit()
  40. {
  41. base.OnInit();
  42. _ui.m_listActivity.itemRenderer = ListActivityItemRender;
  43. //_ui.m_listActivity.onClick.Add(OnListActivityClick);
  44. _ui.m_listNotice.itemRenderer = ListNoticeItemRender;
  45. _ui.m_c1.onChanged.Add(OnCtrlChange);
  46. AddEffect();
  47. }
  48. protected override void AddEventListener()
  49. {
  50. base.AddEventListener();
  51. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  52. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  53. EventAgent.AddEventListener(ConstMessage.SHOW_SYSTEM_NOTICE, UpdateView);
  54. }
  55. protected override void OnShown()
  56. {
  57. base.OnShown();
  58. if (backRefresh)
  59. {
  60. _ui.m_c1.selectedIndex = 0;
  61. }
  62. UpdateView();
  63. }
  64. protected override void OnHide()
  65. {
  66. base.OnHide();
  67. }
  68. protected override void RemoveEventListener()
  69. {
  70. base.RemoveEventListener();
  71. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  72. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  73. EventAgent.RemoveEventListener(ConstMessage.SHOW_SYSTEM_NOTICE, UpdateView);
  74. }
  75. private void AddEffect()
  76. {
  77. //邊框左上角特效
  78. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up");
  79. //邊框右下角特效
  80. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down");
  81. }
  82. private void OnCtrlChange()
  83. {
  84. if (_ui.m_c1.selectedIndex == 0)
  85. {
  86. UpdateInfo();
  87. _ui.m_listActivity.numItems = showActivity.Count;
  88. _ui.m_txtTips.visible = _ui.m_listActivity.numItems == 0;
  89. }
  90. else if (_ui.m_c1.selectedIndex == 1)
  91. {
  92. _ui.m_listNotice.numItems = NoticeDataManager.Instance.NoticeInfos.Count;
  93. _ui.m_txtTips.visible = _ui.m_listNotice.numItems == 0;
  94. }
  95. }
  96. /// <summary>
  97. /// 活动公告 0
  98. /// </summary>
  99. /// <param name="index"></param>
  100. /// <param name="obj"></param>
  101. private void ListActivityItemRender(int index, GObject obj)
  102. {
  103. UI_ListActivityItem item = UI_ListActivityItem.Proxy(obj);
  104. item.m_loaShow.url = ResPathUtil.GetActivityPath(showActivity[index].NoticeTips, "png");
  105. item.m_txtName.text = "";
  106. long endTime = 0;
  107. long curTime = TimeHelper.ServerNow();
  108. if (showActivity.Count > 0)
  109. {
  110. if (showActivity[index].endTime != "" && showActivity[index].endTime != null)
  111. {
  112. endTime = TimeUtil.DateTimeToTimestamp(showActivity[0].endTime);
  113. }
  114. else
  115. {
  116. ActivityInfo activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(showActivity[index].activityId);
  117. endTime = activityInfo.EndTime;
  118. }
  119. }
  120. item.m_txtTime.text = string.Format("剩余时间:{0}", TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime));
  121. item.target.onClick.Add(OnListActivityClick);
  122. item.target.data = showActivity[index];
  123. item.m_imgTips.visible = NoticeDataManager.Instance.GetRedDotState(showActivity[index].jumpId, showActivity[index].activityId);
  124. UI_ListActivityItem.ProxyEnd();
  125. }
  126. private void OnListActivityClick(EventContext context)
  127. {
  128. AdCfg adCfg = (AdCfg)(context.sender as GObject).data;
  129. object[] param = null;
  130. int jumpIndex = 0;
  131. if (adCfg.jumpId == nameof(LimitChargeView))
  132. {
  133. param = new object[] { adCfg.activityId };
  134. }
  135. if (adCfg.jumpId == nameof(NewLimitChargeView))
  136. {
  137. param = new object[] { adCfg.activityId };
  138. }
  139. if (adCfg.jumpId == nameof(LuckyBoxView))
  140. {
  141. jumpIndex = adCfg.jumpParamArr[0];
  142. }
  143. if (jumpIndex != 0)
  144. {
  145. //Hide();
  146. ViewManager.Show($"GFGGame.{adCfg.jumpId}", jumpIndex, false, false);
  147. }
  148. else
  149. {
  150. //Hide();
  151. ViewManager.Show($"GFGGame.{adCfg.jumpId}", param, false, false);
  152. }
  153. }
  154. /// <summary>
  155. /// 系统公告 1
  156. /// </summary>
  157. /// <param name="index"></param>
  158. /// <param name="obj"></param>
  159. private void ListNoticeItemRender(int index, GObject obj)
  160. {
  161. NoticeInfo noticeInfo = NoticeDataManager.Instance.NoticeInfos[index];
  162. UI_ListNoticeItem item = UI_ListNoticeItem.Proxy(obj);
  163. item.m_txtTitle.text = noticeInfo.title;
  164. item.m_txtTime.text = TimeUtil.FormattingTimeTo_yyyMMdd0(noticeInfo.time);
  165. // item.m_imgTips.visible = !noticeInfo.readStatus;
  166. RedDotController.Instance.SetComRedDot(item.target, !noticeInfo.readStatus, "gg_gg_hdhdgth", -40, 32);
  167. if (item.m_btnGo.data == null)
  168. {
  169. item.m_btnGo.onClick.Add(OnListNoticeBtnGoClick);
  170. }
  171. item.m_btnGo.data = noticeInfo;
  172. UI_ListNoticeItem.ProxyEnd();
  173. }
  174. private async void OnListNoticeBtnGoClick(EventContext context)
  175. {
  176. _ui.m_listActivity.visible = false;
  177. _ui.m_listNotice.visible = false;
  178. _ui.m_buttonCom.visible = false;
  179. NoticeInfo noticeInfo = (context.sender as GObject).data as NoticeInfo;
  180. if (noticeInfo.content == "")
  181. {
  182. bool result = await NoticeSProxy.ReqSystemNotice(noticeInfo.noticeId);
  183. if (result)
  184. {
  185. ViewManager.Show<NoticeSystemShowView>(NoticeDataManager.Instance.GetNoticeInfoById(noticeInfo.noticeId), false, false);
  186. }
  187. }
  188. else
  189. {
  190. ViewManager.Show<NoticeSystemShowView>(noticeInfo, false, false);
  191. }
  192. }
  193. private void UpdateInfo()
  194. {
  195. showActivity = NoticeDataManager.Instance.UpdateShowActivity();
  196. }
  197. private void UpdateTitleRedDot()
  198. {
  199. RedDotController.Instance.SetComRedDot(_ui.m_btnActivity, false);
  200. RedDotController.Instance.SetComRedDot(_ui.m_btnNotice, false);
  201. // 活动公告
  202. for (int i = 0; i < showActivity.Count; i++)
  203. {
  204. if (NoticeDataManager.Instance.GetRedDotState(showActivity[i].jumpId, showActivity[i].activityId))
  205. {
  206. RedDotController.Instance.SetComRedDot(_ui.m_btnActivity, true, "", -25);
  207. break;
  208. }
  209. }
  210. // 系统公告
  211. for (int i = 0; i < NoticeDataManager.Instance.NoticeInfos.Count; i++)
  212. {
  213. if (!NoticeDataManager.Instance.NoticeInfos[i].readStatus)
  214. {
  215. RedDotController.Instance.SetComRedDot(_ui.m_btnNotice, true, "", -25);
  216. break;
  217. }
  218. }
  219. }
  220. private void UpdateView()
  221. {
  222. _ui.m_listActivity.visible = true;
  223. _ui.m_listNotice.visible = true;
  224. _ui.m_buttonCom.visible = true;
  225. OnCtrlChange();
  226. UpdateInfo();
  227. UpdateTitleRedDot();
  228. }
  229. }
  230. }