MailContentView.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. using ET;
  2. using UI.Mail;
  3. using FairyGUI;
  4. using UI.CommonGame;
  5. namespace GFGGame
  6. {
  7. public class MailContentView : BaseWindow
  8. {
  9. private UI_MailContentUI _ui;
  10. private int _childIndex;
  11. private MailInfo mailInfo;
  12. public override void Dispose()
  13. {
  14. if (_ui != null)
  15. {
  16. _ui.Dispose();
  17. _ui = null;
  18. }
  19. base.Dispose();
  20. }
  21. protected override void OnInit()
  22. {
  23. base.OnInit();
  24. _ui = UI_MailContentUI.Create();
  25. this.viewCom = _ui.target;
  26. this.viewCom.Center();
  27. this.modal = true;
  28. viewAnimationType = EnumViewAnimationType.ZOOM_CENTER;
  29. _ui.m_listReward.itemRenderer = RenderListRewardItem;
  30. _ui.m_btnGet.onClick.Add(OnClickBtnGet);
  31. _ui.m_btnDelete.onClick.Add(OnClickBtnDelete);
  32. }
  33. protected override void AddEventListener()
  34. {
  35. base.AddEventListener();
  36. EventAgent.AddEventListener(ConstMessage.MAIL_REWARD, UpdateNormal);
  37. }
  38. protected override void RemoveEventListener()
  39. {
  40. base.RemoveEventListener();
  41. EventAgent.RemoveEventListener(ConstMessage.MAIL_REWARD, UpdateNormal);
  42. }
  43. protected override void OnShown()
  44. {
  45. base.OnShown();
  46. // EventAgent.AddEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
  47. long mailId = (long)this.viewData;
  48. mailInfo = MailDataManager.Instance.GetMailInfoById(mailId);
  49. _ui.m_c1.selectedIndex = mailInfo.rewards.Count == 0 ? 0 : 1;
  50. _ui.m_txtTitle.text = mailInfo.title;
  51. _ui.m_ComContent.target.scrollPane.ScrollTop();
  52. _ui.m_ComContent.m_txtContent.text = mailInfo.content;
  53. UpdateNormal();
  54. }
  55. private void UpdateNormal()
  56. {
  57. _ui.m_btnGet.visible = (ConstMailStatus)mailInfo.state == ConstMailStatus.ReadedButNotGet ? true : false;
  58. _ui.m_btnDelete.visible = _ui.m_btnGet.visible == true ? false : true;
  59. _ui.m_listReward.numItems = mailInfo.rewards.Count;
  60. }
  61. private void RenderListRewardItem(int index, GObject obj)
  62. {
  63. ItemData reward = mailInfo.rewards[index];
  64. if (obj.data == null)
  65. {
  66. obj.data = new ItemView(obj as GComponent);
  67. }
  68. (obj.data as ItemView).SetData(reward);
  69. (obj.data as ItemView).GrpGotVisible = (ConstMailStatus)mailInfo.state == ConstMailStatus.ReadedAndGot ? true : false;
  70. }
  71. private async void OnClickBtnGet()
  72. {
  73. bool result = await MailSProxy.ReqMailReward(mailInfo.mailId);
  74. if (result)
  75. {
  76. mailInfo = MailDataManager.Instance.GetMailInfoById(mailInfo.mailId);
  77. UpdateNormal();
  78. }
  79. }
  80. private async void OnClickBtnDelete()
  81. {
  82. bool result = await MailSProxy.ReqDeleteMail(mailInfo.mailId);
  83. if (result)
  84. {
  85. this.Hide();
  86. }
  87. }
  88. // protected override void OnHide()
  89. // {
  90. // base.OnHide();
  91. // // EventAgent.RemoveEventListener(ConstMessage.MAIL_CHANGE, UpdateNormal);
  92. // }
  93. }
  94. }