NoticeView.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  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[index].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. public override void Refresh()
  158. {
  159. base.Refresh();
  160. Debug.LogError(1);
  161. }
  162. /// <summary>
  163. /// 系统公告 1
  164. /// </summary>
  165. /// <param name="index"></param>
  166. /// <param name="obj"></param>
  167. private void ListNoticeItemRender(int index, GObject obj)
  168. {
  169. NoticeInfo noticeInfo = NoticeDataManager.Instance.NoticeInfos[index];
  170. UI_ListNoticeItem item = UI_ListNoticeItem.Proxy(obj);
  171. item.m_txtTitle.text = noticeInfo.title;
  172. item.m_txtTime.text = TimeUtil.FormattingTimeTo_yyyMMdd0(noticeInfo.time);
  173. // item.m_imgTips.visible = !noticeInfo.readStatus;
  174. RedDotController.Instance.SetComRedDot(item.target, !noticeInfo.readStatus, "gg_gg_hdhdgth", -40, 32);
  175. if (item.m_btnGo.data == null)
  176. {
  177. item.m_btnGo.onClick.Add(OnListNoticeBtnGoClick);
  178. }
  179. item.m_btnGo.data = noticeInfo;
  180. UI_ListNoticeItem.ProxyEnd();
  181. }
  182. private async void OnListNoticeBtnGoClick(EventContext context)
  183. {
  184. _ui.m_listActivity.visible = false;
  185. _ui.m_listNotice.visible = false;
  186. _ui.m_buttonCom.visible = false;
  187. NoticeInfo noticeInfo = (context.sender as GObject).data as NoticeInfo;
  188. if (noticeInfo.content == "")
  189. {
  190. bool result = await NoticeSProxy.ReqSystemNotice(noticeInfo.noticeId);
  191. if (result)
  192. {
  193. ViewManager.Show<NoticeSystemShowView>(NoticeDataManager.Instance.GetNoticeInfoById(noticeInfo.noticeId), false, false);
  194. }
  195. }
  196. else
  197. {
  198. ViewManager.Show<NoticeSystemShowView>(noticeInfo, false, false);
  199. }
  200. }
  201. private void UpdateInfo()
  202. {
  203. showActivity = NoticeDataManager.Instance.UpdateShowActivity();
  204. }
  205. private void UpdateTitleRedDot()
  206. {
  207. bool btnActivityFlag = false;
  208. bool btnNoticeFlag = false;
  209. // 活动公告
  210. for (int i = 0; i < showActivity.Count; i++)
  211. {
  212. if (NoticeDataManager.Instance.GetRedDotState(showActivity[i].jumpId, showActivity[i].activityId))
  213. {
  214. btnActivityFlag = true;
  215. break;
  216. }
  217. }
  218. // 系统公告
  219. for (int i = 0; i < NoticeDataManager.Instance.NoticeInfos.Count; i++)
  220. {
  221. if (!NoticeDataManager.Instance.NoticeInfos[i].readStatus)
  222. {
  223. btnNoticeFlag = true;
  224. break;
  225. }
  226. }
  227. RedDotController.Instance.SetComRedDot(_ui.m_btnActivity, btnActivityFlag, "", -25);
  228. RedDotController.Instance.SetComRedDot(_ui.m_btnNotice, btnNoticeFlag, "", -25);
  229. }
  230. private void UpdateView()
  231. {
  232. _ui.m_listActivity.visible = true;
  233. _ui.m_listNotice.visible = true;
  234. _ui.m_buttonCom.visible = true;
  235. OnCtrlChange();
  236. UpdateInfo();
  237. UpdateTitleRedDot();
  238. }
  239. private void UpdateRedDot()
  240. {
  241. if(_ui.m_c1.selectedIndex == 0)
  242. {
  243. OnCtrlChange();
  244. UpdateInfo();
  245. UpdateTitleRedDot();
  246. }
  247. }
  248. }
  249. }