NoticeView.cs 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  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. }
  54. protected override void OnShown()
  55. {
  56. base.OnShown();
  57. if (backRefresh)
  58. {
  59. _ui.m_c1.selectedIndex = 0;
  60. _ui.m_listActivity.visible = true;
  61. _ui.m_listNotice.visible = true;
  62. _ui.m_buttonCom.visible = true;
  63. }
  64. OnCtrlChange();
  65. UpdateInfo();
  66. UpdateTitleRedDot();
  67. }
  68. protected override void OnHide()
  69. {
  70. base.OnHide();
  71. }
  72. protected override void RemoveEventListener()
  73. {
  74. base.RemoveEventListener();
  75. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  76. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  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. //Hide();
  149. ViewManager.Show($"GFGGame.{adCfg.jumpId}", jumpIndex, false, false);
  150. }
  151. else
  152. {
  153. //Hide();
  154. ViewManager.Show($"GFGGame.{adCfg.jumpId}", param, false, false);
  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));
  189. }
  190. }
  191. else
  192. {
  193. ViewManager.Show<NoticeSystemShowView>(noticeInfo);
  194. }
  195. }
  196. private void UpdateInfo()
  197. {
  198. showActivity = NoticeDataManager.Instance.UpdateShowActivity();
  199. }
  200. private void UpdateTitleRedDot()
  201. {
  202. RedDotController.Instance.SetComRedDot(_ui.m_btnActivity, false);
  203. RedDotController.Instance.SetComRedDot(_ui.m_btnNotice, 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. RedDotController.Instance.SetComRedDot(_ui.m_btnActivity, true, "", -25);
  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. RedDotController.Instance.SetComRedDot(_ui.m_btnNotice, true, "", -25);
  219. break;
  220. }
  221. }
  222. }
  223. }
  224. }