NoticeView.cs 4.5 KB

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