NoticeView.cs 9.7 KB

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