PoemPhotoPreView.cs 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Poem;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class PoemPhotoPreView : BaseWindow
  9. {
  10. private UI_PoemPhotoPreviewUI _ui;
  11. private List<PoemPhotoData> _photoInfos;
  12. private int _curIndex = 0;
  13. private int _sourceType = 0;
  14. private PoemPhotoData _curPhotoData;
  15. public override void Dispose()
  16. {
  17. if (_ui != null)
  18. {
  19. _ui.Dispose();
  20. _ui = null;
  21. }
  22. base.Dispose();
  23. }
  24. protected override void OnInit()
  25. {
  26. base.OnInit();
  27. packageName = UI_PoemPhotoPreviewUI.PACKAGE_NAME;
  28. _ui = UI_PoemPhotoPreviewUI.Create();
  29. this.viewCom = _ui.target;
  30. isfullScreen = true;
  31. _ui.m_grhBg.onClick.Add(OnBtnBackClick);
  32. _ui.m_list.SetVirtual();
  33. _ui.m_list.itemRenderer = RenderListItem;
  34. _ui.m_list.scrollPane.onScrollEnd.Add(OnListScrollEnd);
  35. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  36. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  37. _ui.m_btnLock.target.onClick.Add(OnBtnLockClick);
  38. _ui.m_btnUp.target.onClick.Add(OnBtnUpClick);
  39. _ui.m_btnShare.onClick.Add(OnBtnShareClick);
  40. }
  41. protected override void AddEventListener()
  42. {
  43. base.AddEventListener();
  44. }
  45. protected override void OnShown()
  46. {
  47. base.OnShown();
  48. _curIndex = (int)(this.viewData as object[])[0];
  49. _photoInfos = (this.viewData as object[])[1] as List<PoemPhotoData>;
  50. _ui.m_list.numItems = _photoInfos.Count;
  51. _ui.m_list.height = _ui.m_list.GetChildAt(0).height;
  52. UpdateView();
  53. }
  54. protected override void OnHide()
  55. {
  56. base.OnHide();
  57. }
  58. protected override void RemoveEventListener()
  59. {
  60. base.RemoveEventListener();
  61. }
  62. private void OnBtnBackClick()
  63. {
  64. ViewManager.GoBackFrom(typeof(PoemPhotoPreView).FullName);
  65. }
  66. private void UpdateView()
  67. {
  68. _ui.m_btnLeft.enabled = _curIndex > 0;
  69. _ui.m_btnRight.enabled = _curIndex < _ui.m_list.numItems - 1;
  70. _ui.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[_curIndex].CreationTime);
  71. _ui.m_btnLock.m_c1.selectedIndex = _photoInfos[_curIndex].LockingStatus ? 1 : 0;
  72. _ui.m_btnUp.m_c1.selectedIndex = _photoInfos[_curIndex].ToppingStatus ? 1 : 0;
  73. if (_photoInfos.Count > 0) _ui.m_list.ScrollToView(_curIndex);
  74. if (_ui.m_btnLock.target.data == null)
  75. {
  76. _ui.m_btnLock.target.onClick.Add(OnBtnLockClick);
  77. }
  78. _ui.m_btnLock.target.data = _curIndex;
  79. if (_ui.m_btnUp.target.data == null)
  80. {
  81. _ui.m_btnUp.target.onClick.Add(OnBtnUpClick);
  82. }
  83. _curPhotoData = _photoInfos[_curIndex];
  84. }
  85. private void RenderListItem(int index, GObject obj)
  86. {
  87. UI_ListPhotoPreviewItem item = UI_ListPhotoPreviewItem.Proxy(obj);
  88. GLoader loaIcon = item.m_comPhoto.m_loaPhoto;
  89. item.m_comPhoto.m_loaPhoto.texture = PoemPhotoDataManager.Instance.BytesToTexture2D(_photoInfos[index].Bytes);
  90. item.target.SetSize(item.target.width, item.target.initHeight * _ui.target.height / _ui.target.initHeight);
  91. loaIcon.SetSize(loaIcon.width, loaIcon.texture.height * loaIcon.width / loaIcon.texture.width);
  92. loaIcon.y = item.target.height / 2;
  93. UI_ListPhotoPreviewItem.ProxyEnd();
  94. }
  95. private void OnBtnLeftClick()
  96. {
  97. _curIndex--;
  98. _curIndex = Mathf.Max(0, _curIndex);
  99. UpdateView();
  100. }
  101. private void OnBtnRightClick()
  102. {
  103. _curIndex++;
  104. _curIndex = Mathf.Min(_ui.m_list.numItems - 1, _curIndex);
  105. UpdateView();
  106. }
  107. private void OnListScrollEnd()
  108. {
  109. _curIndex = _ui.m_list.ChildIndexToItemIndex(0);
  110. UpdateView();
  111. }
  112. private void OnBtnLockClick()
  113. {
  114. if (_curPhotoData.LockingStatus == false)
  115. {
  116. AlertUI.Show("是否确认锁定此照片?", "(锁住的照片无法被删除)")
  117. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  118. {
  119. bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, true, _sourceType);
  120. if (result)
  121. {
  122. _photoInfos[_curIndex].LockingStatus = true;
  123. UpdateView();
  124. }
  125. });
  126. }
  127. else
  128. {
  129. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  130. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  131. {
  132. bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, false, _sourceType);
  133. if (result)
  134. {
  135. _photoInfos[_curIndex].LockingStatus = false;
  136. UpdateView();
  137. }
  138. });
  139. }
  140. }
  141. private void OnBtnUpClick()
  142. {
  143. if (_curPhotoData.ToppingStatus == false)
  144. {
  145. AlertUI.Show("是否确认置顶此照片?")
  146. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  147. {
  148. bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, true, _sourceType);
  149. if (result)
  150. {
  151. _photoInfos[_curIndex].ToppingStatus = true;
  152. UpdateView();
  153. }
  154. });
  155. }
  156. else
  157. {
  158. AlertUI.Show("是否确认取消置顶此照片?")
  159. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  160. {
  161. bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, false, _sourceType);
  162. if (result)
  163. {
  164. _photoInfos[_curIndex].ToppingStatus = false;
  165. UpdateView();
  166. }
  167. });
  168. }
  169. }
  170. private void OnBtnShareClick()
  171. {
  172. ViewManager.Show<PoemPhotoShareView>(_curPhotoData, new object[] { typeof(PoemPhotoPreView).FullName, new object[] { _curIndex, _photoInfos } });
  173. }
  174. }
  175. }