NoticeView.cs 4.5 KB

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