NoticeView.cs 9.3 KB

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