NoticeView.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266
  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. ViewManager.Show($"GFGGame.{adCfg.jumpId}", jumpIndex, false, false);
  146. //Hide();
  147. }
  148. else
  149. {
  150. ViewManager.Show($"GFGGame.{adCfg.jumpId}", param, false, false);
  151. //Hide();
  152. }
  153. }
  154. public override void Refresh()
  155. {
  156. base.Refresh();
  157. Debug.LogError(1);
  158. }
  159. /// <summary>
  160. /// 系统公告 1
  161. /// </summary>
  162. /// <param name="index"></param>
  163. /// <param name="obj"></param>
  164. private void ListNoticeItemRender(int index, GObject obj)
  165. {
  166. NoticeInfo noticeInfo = NoticeDataManager.Instance.NoticeInfos[index];
  167. UI_ListNoticeItem item = UI_ListNoticeItem.Proxy(obj);
  168. item.m_txtTitle.text = noticeInfo.title;
  169. item.m_txtTime.text = TimeUtil.FormattingTimeTo_yyyMMdd0(noticeInfo.time);
  170. // item.m_imgTips.visible = !noticeInfo.readStatus;
  171. RedDotController.Instance.SetComRedDot(item.target, !noticeInfo.readStatus, "gg_gg_hdhdgth", -40, 32);
  172. if (item.m_btnGo.data == null)
  173. {
  174. item.m_btnGo.onClick.Add(OnListNoticeBtnGoClick);
  175. }
  176. item.m_btnGo.data = noticeInfo;
  177. UI_ListNoticeItem.ProxyEnd();
  178. }
  179. private async void OnListNoticeBtnGoClick(EventContext context)
  180. {
  181. _ui.m_listActivity.visible = false;
  182. _ui.m_listNotice.visible = false;
  183. _ui.m_buttonCom.visible = false;
  184. NoticeInfo noticeInfo = (context.sender as GObject).data as NoticeInfo;
  185. if (noticeInfo.content == "")
  186. {
  187. bool result = await NoticeSProxy.ReqSystemNotice(noticeInfo.noticeId);
  188. if (result)
  189. {
  190. ViewManager.Show<NoticeSystemShowView>(NoticeDataManager.Instance.GetNoticeInfoById(noticeInfo.noticeId), false, false);
  191. }
  192. }
  193. else
  194. {
  195. ViewManager.Show<NoticeSystemShowView>(noticeInfo, false, false);
  196. }
  197. }
  198. private void UpdateInfo()
  199. {
  200. showActivity = NoticeDataManager.Instance.UpdateShowActivity();
  201. }
  202. private void UpdateTitleRedDot()
  203. {
  204. RedDotController.Instance.SetComRedDot(_ui.m_btnActivity, false);
  205. RedDotController.Instance.SetComRedDot(_ui.m_btnNotice, false);
  206. // 活动公告
  207. for (int i = 0; i < showActivity.Count; i++)
  208. {
  209. if (NoticeDataManager.Instance.GetRedDotState(showActivity[i].jumpId, showActivity[i].activityId))
  210. {
  211. RedDotController.Instance.SetComRedDot(_ui.m_btnActivity, true, "", -25);
  212. break;
  213. }
  214. }
  215. // 系统公告
  216. for (int i = 0; i < NoticeDataManager.Instance.NoticeInfos.Count; i++)
  217. {
  218. if (!NoticeDataManager.Instance.NoticeInfos[i].readStatus)
  219. {
  220. RedDotController.Instance.SetComRedDot(_ui.m_btnNotice, true, "", -25);
  221. break;
  222. }
  223. }
  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. }
  235. }