NoticeView.cs 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. }
  38. protected override void OnInit()
  39. {
  40. base.OnInit();
  41. _ui.m_listActivity.itemRenderer = ListActivityItemRender;
  42. //_ui.m_listActivity.onClick.Add(OnListActivityClick);
  43. _ui.m_listNotice.itemRenderer = ListNoticeItemRender;
  44. _ui.m_c1.onChanged.Add(OnCtrlChange);
  45. AddEffect();
  46. }
  47. protected override void AddEventListener()
  48. {
  49. base.AddEventListener();
  50. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  51. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  52. }
  53. protected override void OnShown()
  54. {
  55. base.OnShown();
  56. _ui.m_c1.selectedIndex = 1;
  57. _ui.m_listActivity.visible = true;
  58. _ui.m_listNotice.visible = true;
  59. _ui.m_buttonCom.visible = true;
  60. OnCtrlChange();
  61. }
  62. protected override void OnHide()
  63. {
  64. base.OnHide();
  65. }
  66. protected override void RemoveEventListener()
  67. {
  68. base.RemoveEventListener();
  69. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  70. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  71. }
  72. private void AddEffect()
  73. {
  74. //邊框左上角特效
  75. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_holderLeftTop, "ui_Activity", "Com_window_L_up");
  76. //邊框右下角特效
  77. _effectUI2 = EffectUIPool.CreateEffectUI(_ui.m_holderRightDowm, "ui_Activity", "Com_window_R_Down");
  78. }
  79. private void OnCtrlChange()
  80. {
  81. if (_ui.m_c1.selectedIndex == 0)
  82. {
  83. UpdateInfo();
  84. _ui.m_listActivity.numItems = showActivity.Count;
  85. _ui.m_txtTips.visible = _ui.m_listActivity.numItems == 0;
  86. }
  87. else if (_ui.m_c1.selectedIndex == 1)
  88. {
  89. _ui.m_listNotice.numItems = NoticeDataManager.Instance.NoticeInfos.Count;
  90. _ui.m_txtTips.visible = _ui.m_listNotice.numItems == 0;
  91. }
  92. }
  93. private void ListActivityItemRender(int index, GObject obj)
  94. {
  95. UI_ListActivityItem item = UI_ListActivityItem.Proxy(obj);
  96. item.m_loaShow.url = ResPathUtil.GetActivityPath(showActivity[index].NoticeTips);
  97. item.m_txtName.text = showActivity[index].res;
  98. switch (showActivity[index].jumpId)
  99. {
  100. //后续添加其他活动
  101. case "LuckyBoxView":
  102. item.m_imgTips.visible = RedDotDataManager.Instance.GetActLuckyBoxRewardRed(ConstLimitTimeActivityType.ActLimitTsy) || RedDotDataManager.Instance.GetLuckyBoxFreeTimes();
  103. break;
  104. default:
  105. break;
  106. }
  107. long endTime = 0;
  108. long curTime = TimeHelper.ServerNow();
  109. if (showActivity.Count > 0)
  110. {
  111. if (showActivity[index].endTime != "" && showActivity[index].endTime != null)
  112. {
  113. endTime = TimeUtil.DateTimeToTimestamp(showActivity[0].endTime);
  114. }
  115. else
  116. {
  117. ActivityInfo activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(showActivity[index].activityId);
  118. endTime = activityInfo.EndTime;
  119. }
  120. }
  121. item.m_txtTime.text = string.Format("剩余时间:{0}", TimeUtil.FormattingTimeTo_DDHHmm(endTime - curTime));
  122. item.target.onClick.Add(OnListActivityClick);
  123. item.target.data = showActivity[index];
  124. UI_ListActivityItem.ProxyEnd();
  125. }
  126. private void OnListActivityClick(EventContext context)
  127. {
  128. AdCfg adCfg = (AdCfg)(context.sender as GObject).data;
  129. object[] param = null;
  130. int jumpIndex = 0;
  131. if (adCfg.jumpId == nameof(LimitChargeView))
  132. {
  133. param = new object[] { adCfg.activityId };
  134. }
  135. if (adCfg.jumpId == nameof(NewLimitChargeView))
  136. {
  137. param = new object[] { adCfg.activityId };
  138. }
  139. if (adCfg.jumpId == nameof(LuckyBoxView))
  140. {
  141. jumpIndex = adCfg.jumpParamArr[0];
  142. }
  143. if (jumpIndex != 0)
  144. {
  145. this.Hide();
  146. ViewManager.Show($"GFGGame.{adCfg.jumpId}", jumpIndex);
  147. }
  148. else
  149. {
  150. this.Hide();
  151. ViewManager.Show($"GFGGame.{adCfg.jumpId}", param);
  152. }
  153. }
  154. private void ListNoticeItemRender(int index, GObject obj)
  155. {
  156. NoticeInfo noticeInfo = NoticeDataManager.Instance.NoticeInfos[index];
  157. UI_ListNoticeItem item = UI_ListNoticeItem.Proxy(obj);
  158. item.m_txtTitle.text = noticeInfo.title;
  159. item.m_txtTime.text = TimeUtil.FormattingTimeTo_yyyMMdd0(noticeInfo.time);
  160. // item.m_imgTips.visible = !noticeInfo.readStatus;
  161. RedDotController.Instance.SetComRedDot(item.target, !noticeInfo.readStatus, "gg_gg_hdhdgth", -40, 32);
  162. if (item.m_btnGo.data == null)
  163. {
  164. item.m_btnGo.onClick.Add(OnListNoticeBtnGoClick);
  165. }
  166. item.m_btnGo.data = noticeInfo;
  167. UI_ListNoticeItem.ProxyEnd();
  168. }
  169. private async void OnListNoticeBtnGoClick(EventContext context)
  170. {
  171. _ui.m_listActivity.visible = false;
  172. _ui.m_listNotice.visible = false;
  173. _ui.m_buttonCom.visible = false;
  174. NoticeInfo noticeInfo = (context.sender as GObject).data as NoticeInfo;
  175. if (noticeInfo.content == "")
  176. {
  177. bool result = await NoticeSProxy.ReqSystemNotice(noticeInfo.noticeId);
  178. if (result)
  179. {
  180. ViewManager.Show<NoticeSystemShowView>(NoticeDataManager.Instance.GetNoticeInfoById(noticeInfo.noticeId));
  181. }
  182. }
  183. else
  184. {
  185. ViewManager.Show<NoticeSystemShowView>(noticeInfo);
  186. }
  187. }
  188. private void UpdateInfo()
  189. {
  190. if(activitydata == null)
  191. {
  192. activitydata = AdCfgArray.Instance.dataArray;
  193. }
  194. showActivity.Clear();
  195. for (int i = 0; i < activitydata.Length; i++)
  196. {
  197. AdCfg adCfg = activitydata[i];
  198. if (adCfg.activityId > 0)
  199. {
  200. if (ActivityGlobalDataManager.Instance.GetActivityInfo(adCfg.activityId) == null) continue;
  201. ActivityInfo activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(adCfg.activityId);
  202. if (TimeHelper.ServerNow() < activityInfo.StartTime || TimeHelper.ServerNow() > activityInfo.EndTime) continue;
  203. }
  204. if (adCfg.ActivityNotice != null && adCfg.ActivityNotice != "")
  205. {
  206. if (adCfg.activityId != 0)
  207. {
  208. ActivityInfo activityInfo = ActivityGlobalDataManager.Instance.GetActivityInfo(adCfg.activityId);
  209. if (TimeHelper.ServerNow() < activityInfo.StartTime || TimeHelper.ServerNow() > activityInfo.EndTime)
  210. {
  211. }
  212. else
  213. {
  214. showActivity.Add(adCfg);
  215. continue;
  216. }
  217. }
  218. if (adCfg.startTime != "" && adCfg.startTime != null)
  219. {
  220. long startTime = TimeUtil.DateTimeToTimestamp(adCfg.startTime);
  221. long endTime = TimeUtil.DateTimeToTimestamp(adCfg.endTime);
  222. if (TimeHelper.ServerNow() < startTime || TimeHelper.ServerNow() > endTime)
  223. {
  224. continue;
  225. }
  226. else
  227. {
  228. showActivity.Add(adCfg);
  229. }
  230. }
  231. }
  232. }
  233. }
  234. }
  235. }