PoemGalleryPreviewView.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using ET;
  2. using FairyGUI;
  3. using UI.Poem;
  4. using UnityEngine;
  5. namespace GFGGame
  6. {
  7. public class PoemGalleryPreviewView : BaseWindow
  8. {
  9. private UI_PoemGalleryPreviewUI _ui;
  10. private int _sortType = 0;//由 GallerySortType 定义
  11. private PoemGalleryData _galleryData;
  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. packageName = UI_PoemGalleryPreviewUI.PACKAGE_NAME;
  25. _ui = UI_PoemGalleryPreviewUI.Create();
  26. this.viewCom = _ui.target;
  27. isfullScreen = true;
  28. // _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("gzs_bjbj");
  29. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  30. _ui.m_btnCollect.onClick.Add(OnBtnCollectClick);
  31. _ui.m_btnVote.onClick.Add(OnBtnVoteClick);
  32. _ui.m_btnAddFriend.onClick.Add(OnBtnAddFriendClick);
  33. _ui.m_btnDelete.onClick.Add(OnBtnDeleteClick);
  34. }
  35. protected override void AddEventListener()
  36. {
  37. base.AddEventListener();
  38. }
  39. protected override void OnShown()
  40. {
  41. base.OnShown();
  42. _sortType = (int)(this.viewData as object[])[0];
  43. long workId = (int)(this.viewData as object[])[1];
  44. _galleryData = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  45. }
  46. private void UpdateView()
  47. {
  48. _ui.m_c1.selectedIndex = _sortType;
  49. _ui.m_txtName.text = _galleryData.AuthorName;
  50. string themeTime = PoemGalleryDataManager.Instance.GetThemeTime();
  51. GalleryThemeCfg themeCfg = GalleryThemeCfgArray.Instance.GetCfg((int)PoemGalleryDataManager.Instance.ThemeId);
  52. string themeName = themeCfg.theme;
  53. _ui.m_txtTheme.text = string.Format("{0} {1}", themeTime, themeName);// PoemGalleryDataManager.Instance.GetThemeTime();
  54. _ui.m_btnCollect.selected = _galleryData.CollectOrNot;
  55. _ui.m_btnCollect.title = _galleryData.CollectCount.ToString();
  56. _ui.m_btnVote.selected = _galleryData.VoteOrNot;
  57. _ui.m_btnVote.title = _galleryData.VoteCount.ToString();
  58. _ui.m_btnAddFriend.visible = FriendDataManager.Instance.GetFriendDataById(_galleryData.AuthorId) == null;
  59. }
  60. protected override void OnHide()
  61. {
  62. base.OnHide();
  63. _ui.m_btnAddFriend.selected = false;
  64. }
  65. protected override void RemoveEventListener()
  66. {
  67. base.RemoveEventListener();
  68. }
  69. private void OnBtnBackClick()
  70. {
  71. ViewManager.GoBackFrom(typeof(PoemGalleryPreviewView).FullName);
  72. }
  73. private async void OnBtnCollectClick(EventContext context)
  74. {
  75. if (_galleryData.CollectOrNot)
  76. {
  77. bool result = await PoemGallerySProxy.ReqCancelCollecteGalleryWorks(_galleryData.WorkId);
  78. if (result)
  79. {
  80. UpdateView();
  81. }
  82. }
  83. else
  84. {
  85. bool result = await PoemGallerySProxy.ReqCollecteGalleryWorks(_galleryData.WorkId);
  86. if (result)
  87. {
  88. UpdateView();
  89. }
  90. }
  91. }
  92. private async void OnBtnVoteClick(EventContext context)
  93. {
  94. if (_galleryData.VoteOrNot) return;
  95. bool result = await PoemGallerySProxy.ReqVoteGalleryWorks(_galleryData.WorkId);
  96. if (result)
  97. {
  98. UpdateView();
  99. int Count = GameGlobal.myNumericComponent.GetAsInt(NumericType.LikeGalleryWorksCountDaily);
  100. GalleryIntegralCfg integralCfg = GalleryIntegralCfgArray.Instance.GetCfg(Count);
  101. if (integralCfg != null)
  102. {
  103. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(integralCfg.itemId);
  104. PromptController.Instance.ShowFloatTextPrompt(string.Format("{0} +{1}", itemCfg.name, integralCfg.Count));
  105. }
  106. }
  107. }
  108. private async void OnBtnAddFriendClick(EventContext context)
  109. {
  110. if (_ui.m_btnAddFriend.selected == true) return;
  111. bool result = await FriendSProxy.ReqApplyForFriend(_galleryData.AuthorId);
  112. if (result)
  113. {
  114. _ui.m_btnAddFriend.selected = true;
  115. }
  116. }
  117. private async void OnBtnDeleteClick(EventContext context)
  118. {
  119. bool result = await PoemGallerySProxy.ReqDeleteMyWorks(_galleryData.WorkId);
  120. if (result)
  121. {
  122. this.Hide();
  123. }
  124. }
  125. }
  126. }