MailContentView.cs 2.8 KB

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