NoticeView.cs 8.8 KB

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