NoticeView.cs 9.2 KB

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