NoticeView.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  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. private GameObject _gameObject1;
  10. private GameObject _gameObject2;
  11. private GoWrapper _wrapper1;
  12. private GoWrapper _wrapper2;
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void Init()
  23. {
  24. base.Init();
  25. packageName = UI_NoticeUI.PACKAGE_NAME;
  26. _ui = UI_NoticeUI.Create();
  27. this.viewCom = _ui.target;
  28. this.viewCom.Center();
  29. this.modal = true;
  30. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  31. }
  32. protected override void OnInit()
  33. {
  34. base.OnInit();
  35. _ui.m_listActivity.itemRenderer = ListActivityItemRender;
  36. _ui.m_listActivity.onClick.Add(OnListActivityClick);
  37. _ui.m_listNotice.itemRenderer = ListNoticeItemRender;
  38. _ui.m_c1.onChanged.Add(OnCtrlChange);
  39. }
  40. protected override void AddEventListener()
  41. {
  42. base.AddEventListener();
  43. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  44. EventAgent.AddEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  45. }
  46. protected override void OnShown()
  47. {
  48. base.OnShown();
  49. _ui.m_c1.selectedIndex = 1;
  50. _ui.m_listActivity.visible = true;
  51. _ui.m_listNotice.visible = true;
  52. _ui.m_buttonCom.visible = true;
  53. OnCtrlChange();
  54. AddEffect();
  55. }
  56. protected override void OnHide()
  57. {
  58. SceneController.DestroyObjectFromView(_gameObject1, _wrapper1);
  59. SceneController.DestroyObjectFromView(_gameObject2, _wrapper2);
  60. base.OnHide();
  61. }
  62. protected override void RemoveEventListener()
  63. {
  64. base.RemoveEventListener();
  65. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_ADD, OnCtrlChange);
  66. EventAgent.RemoveEventListener(ConstMessage.NOTICE_SYSTOM_REMOVE, OnCtrlChange);
  67. }
  68. private void AddEffect()
  69. {
  70. //邊框左上角特效
  71. string resPath1 = ResPathUtil.GetViewEffectPath("ui_Activity", "Com_window_L_up");
  72. SceneController.AddObjectToView(null, null, _ui.m_holderLeftTop, resPath1,
  73. out _gameObject1, out _wrapper1);
  74. //邊框右下角特效
  75. string resPath2 = ResPathUtil.GetViewEffectPath("ui_Activity", "Com_window_R_Down");
  76. SceneController.AddObjectToView(null, null, _ui.m_holderRightDowm, resPath2,
  77. out _gameObject2, out _wrapper2);
  78. }
  79. private void OnCtrlChange()
  80. {
  81. if (_ui.m_c1.selectedIndex == 0)
  82. {
  83. _ui.m_listActivity.numItems = 0;
  84. _ui.m_txtTips.visible = _ui.m_listActivity.numItems == 0;
  85. }
  86. else if (_ui.m_c1.selectedIndex == 1)
  87. {
  88. _ui.m_listNotice.numItems = NoticeDataManager.Instance.NoticeInfos.Count;
  89. _ui.m_txtTips.visible = _ui.m_listNotice.numItems == 0;
  90. }
  91. }
  92. private void ListActivityItemRender(int index, GObject obj)
  93. {
  94. UI_ListActivityItem item = UI_ListActivityItem.Proxy(obj);
  95. item.m_loaShow.url = ResPathUtil.GetActivityPath("");
  96. item.target.data = index;
  97. UI_ListActivityItem.ProxyEnd();
  98. }
  99. private void OnListActivityClick(EventContext context)
  100. {
  101. // _ui.m_listActivity.visible = false;
  102. // _ui.m_listNotice.visible = false;
  103. // int noticeId = (int)(context.data as GObject).data;
  104. // ViewManager.Show<NoticeActivityShowView>(null, new object[] { typeof(NoticeView).Name, this.viewData });
  105. }
  106. private void ListNoticeItemRender(int index, GObject obj)
  107. {
  108. NoticeInfo noticeInfo = NoticeDataManager.Instance.NoticeInfos[index];
  109. UI_ListNoticeItem item = UI_ListNoticeItem.Proxy(obj);
  110. item.m_txtTitle.text = noticeInfo.title;
  111. item.m_txtTime.text = TimeUtil.FormattingTimeTo_yyyMMdd0(noticeInfo.time);
  112. // item.m_imgTips.visible = !noticeInfo.readStatus;
  113. RedDotController.Instance.SetComRedDot(item.target, !noticeInfo.readStatus, "gg_gg_hdhdgth", -13, 12);
  114. if (item.m_btnGo.data == null)
  115. {
  116. item.m_btnGo.onClick.Add(OnListNoticeBtnGoClick);
  117. }
  118. item.m_btnGo.data = noticeInfo;
  119. UI_ListNoticeItem.ProxyEnd();
  120. }
  121. private async void OnListNoticeBtnGoClick(EventContext context)
  122. {
  123. _ui.m_listActivity.visible = false;
  124. _ui.m_listNotice.visible = false;
  125. _ui.m_buttonCom.visible = false;
  126. NoticeInfo noticeInfo = (context.sender as GObject).data as NoticeInfo;
  127. if (noticeInfo.content == "")
  128. {
  129. bool result = await NoticeSProxy.ReqSystemNotice(noticeInfo.noticeId);
  130. if (result)
  131. {
  132. ViewManager.Show<NoticeSystemShowView>(NoticeDataManager.Instance.GetNoticeInfoById(noticeInfo.noticeId), new object[] { typeof(NoticeView).Name, this.viewData });
  133. }
  134. }
  135. else
  136. {
  137. ViewManager.Show<NoticeSystemShowView>(noticeInfo, new object[] { typeof(NoticeView).Name, this.viewData });
  138. }
  139. }
  140. }
  141. }