NoticeView.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. using UnityEngine;
  2. using FairyGUI;
  3. using UI.Notice;
  4. namespace GFGGame
  5. {
  6. public class NoticeView : BaseWindow
  7. {
  8. private UI_NoticeUI _ui;
  9. public override void Dispose()
  10. {
  11. if (_ui != null)
  12. {
  13. _ui.Dispose();
  14. _ui = null;
  15. }
  16. base.Dispose();
  17. }
  18. protected override void Init()
  19. {
  20. base.Init();
  21. packageName = UI_NoticeUI.PACKAGE_NAME;
  22. _ui = UI_NoticeUI.Create();
  23. this.viewCom = _ui.target;
  24. this.viewCom.Center();
  25. this.modal = true;
  26. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  27. }
  28. protected override void OnInit()
  29. {
  30. base.OnInit();
  31. _ui.m_listActivity.itemRenderer = ListActivityItemRender;
  32. _ui.m_listActivity.onClick.Add(OnListActivityClick);
  33. _ui.m_listNotice.itemRenderer = ListNoticeItemRender;
  34. _ui.m_c1.onChanged.Add(OnCtrlChange);
  35. }
  36. protected override void AddEventListener()
  37. {
  38. base.AddEventListener();
  39. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  40. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  41. }
  42. protected override void OnShown()
  43. {
  44. base.OnShown();
  45. _ui.m_c1.selectedIndex = 1;
  46. _ui.m_listActivity.visible = true;
  47. _ui.m_listNotice.visible = true;
  48. OnCtrlChange();
  49. }
  50. protected override void OnHide()
  51. {
  52. base.OnHide();
  53. }
  54. protected override void RemoveEventListener()
  55. {
  56. base.RemoveEventListener();
  57. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  58. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  59. }
  60. private void OnCtrlChange()
  61. {
  62. if (_ui.m_c1.selectedIndex == 0)
  63. {
  64. _ui.m_listActivity.numItems = 0;
  65. _ui.m_txtTips.visible = _ui.m_listActivity.numItems == 0;
  66. }
  67. else if (_ui.m_c1.selectedIndex == 1)
  68. {
  69. _ui.m_listNotice.numItems = NoticeDataManager.Instance.NoticeInfos.Count;
  70. _ui.m_txtTips.visible = _ui.m_listNotice.numItems == 0;
  71. }
  72. }
  73. private void ListActivityItemRender(int index, GObject obj)
  74. {
  75. UI_ListActivityItem item = UI_ListActivityItem.Proxy(obj);
  76. item.m_loaShow.url = ResPathUtil.GetActivityPath("");
  77. item.target.data = index;
  78. UI_ListActivityItem.ProxyEnd();
  79. }
  80. private void OnListActivityClick(EventContext context)
  81. {
  82. // _ui.m_listActivity.visible = false;
  83. // _ui.m_listNotice.visible = false;
  84. // int noticeId = (int)(context.data as GObject).data;
  85. // ViewManager.Show<NoticeActivityShowView>(null, new object[] { typeof(NoticeView).Name, this.viewData });
  86. }
  87. private void ListNoticeItemRender(int index, GObject obj)
  88. {
  89. NoticeInfo noticeInfo = NoticeDataManager.Instance.NoticeInfos[index];
  90. UI_ListNoticeItem item = UI_ListNoticeItem.Proxy(obj);
  91. item.m_txtTitle.text = noticeInfo.title;
  92. item.m_txtTime.text = TimeUtil.FormattingTimeTo_yyyMMdd0(noticeInfo.time);
  93. // item.m_imgTips.visible = !noticeInfo.readStatus;
  94. RedDotController.Instance.SetComRedDot(item.target, !noticeInfo.readStatus, "gg_gg_hdhdgth", -13, 12);
  95. if (item.m_btnGo.data == null)
  96. {
  97. item.m_btnGo.onClick.Add(OnListNoticeBtnGoClick);
  98. }
  99. item.m_btnGo.data = noticeInfo;
  100. UI_ListNoticeItem.ProxyEnd();
  101. }
  102. private async void OnListNoticeBtnGoClick(EventContext context)
  103. {
  104. _ui.m_listActivity.visible = false;
  105. _ui.m_listNotice.visible = false;
  106. NoticeInfo noticeInfo = (context.sender as GObject).data as NoticeInfo;
  107. if (noticeInfo.content == "")
  108. {
  109. bool result = await NoticeSProxy.ReqSystemNotice(noticeInfo.noticeId);
  110. if (result)
  111. {
  112. ViewManager.Show<NoticeSystemShowView>(NoticeDataManager.Instance.GetNoticeInfoById(noticeInfo.noticeId), new object[] { typeof(NoticeView).Name, this.viewData });
  113. }
  114. }
  115. else
  116. {
  117. ViewManager.Show<NoticeSystemShowView>(noticeInfo, new object[] { typeof(NoticeView).Name, this.viewData });
  118. }
  119. }
  120. }
  121. }