PoemPhotoPreView.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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 = _photoInfos[index].Ntexture;// 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. item.m_imgBorder.SetSize(item.target.width, item.target.height);
  94. UI_ListPhotoPreviewItem.ProxyEnd();
  95. }
  96. private void OnBtnLeftClick()
  97. {
  98. _curIndex--;
  99. _curIndex = Mathf.Max(0, _curIndex);
  100. UpdateView();
  101. }
  102. private void OnBtnRightClick()
  103. {
  104. _curIndex++;
  105. _curIndex = Mathf.Min(_ui.m_list.numItems - 1, _curIndex);
  106. UpdateView();
  107. }
  108. private void OnListScrollEnd()
  109. {
  110. _curIndex = _ui.m_list.ChildIndexToItemIndex(0);
  111. UpdateView();
  112. }
  113. private void OnBtnLockClick()
  114. {
  115. if (_curPhotoData.LockingStatus == false)
  116. {
  117. AlertUI.Show("是否确认锁定此照片?", "(锁住的照片无法被删除)")
  118. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  119. {
  120. bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, true, _sourceType);
  121. if (result)
  122. {
  123. _photoInfos[_curIndex].LockingStatus = true;
  124. UpdateView();
  125. }
  126. });
  127. }
  128. else
  129. {
  130. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  131. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  132. {
  133. bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, false, _sourceType);
  134. if (result)
  135. {
  136. _photoInfos[_curIndex].LockingStatus = false;
  137. UpdateView();
  138. }
  139. });
  140. }
  141. }
  142. private void OnBtnUpClick()
  143. {
  144. if (_curPhotoData.ToppingStatus == false)
  145. {
  146. AlertUI.Show("是否确认置顶此照片?")
  147. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  148. {
  149. bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, true, _sourceType);
  150. if (result)
  151. {
  152. _photoInfos[_curIndex].ToppingStatus = true;
  153. UpdateView();
  154. }
  155. });
  156. }
  157. else
  158. {
  159. AlertUI.Show("是否确认取消置顶此照片?")
  160. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  161. {
  162. bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, false, _sourceType);
  163. if (result)
  164. {
  165. _photoInfos[_curIndex].ToppingStatus = false;
  166. UpdateView();
  167. }
  168. });
  169. }
  170. }
  171. private void OnBtnShareClick()
  172. {
  173. ViewManager.Show<PoemPhotoShareView>(_curPhotoData, new object[] { typeof(PoemPhotoPreView).FullName, new object[] { _curIndex, _photoInfos } });
  174. }
  175. }
  176. }