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. List<PoemPhotoData> photoInfos = (this.viewData as object[])[1] as List<PoemPhotoData>;
  50. _photoInfos = new List<PoemPhotoData>(photoInfos.ToArray());
  51. _ui.m_list.numItems = _photoInfos.Count;
  52. _ui.m_list.height = _ui.m_list.GetChildAt(0).height;
  53. UpdateView();
  54. }
  55. protected override void OnHide()
  56. {
  57. base.OnHide();
  58. }
  59. protected override void RemoveEventListener()
  60. {
  61. base.RemoveEventListener();
  62. }
  63. private void OnBtnBackClick()
  64. {
  65. ViewManager.GoBackFrom(typeof(PoemPhotoPreView).FullName);
  66. }
  67. private void UpdateView()
  68. {
  69. _ui.m_btnLeft.enabled = _curIndex > 0;
  70. _ui.m_btnRight.enabled = _curIndex < _ui.m_list.numItems - 1;
  71. _ui.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[_curIndex].CreationTime);
  72. _ui.m_btnLock.m_c1.selectedIndex = _photoInfos[_curIndex].LockingStatus ? 1 : 0;
  73. _ui.m_btnUp.m_c1.selectedIndex = _photoInfos[_curIndex].ToppingStatus ? 1 : 0;
  74. if (_photoInfos.Count > 0) _ui.m_list.ScrollToView(_curIndex);
  75. if (_ui.m_btnLock.target.data == null)
  76. {
  77. _ui.m_btnLock.target.onClick.Add(OnBtnLockClick);
  78. }
  79. _ui.m_btnLock.target.data = _curIndex;
  80. if (_ui.m_btnUp.target.data == null)
  81. {
  82. _ui.m_btnUp.target.onClick.Add(OnBtnUpClick);
  83. }
  84. _curPhotoData = _photoInfos[_curIndex];
  85. }
  86. private void RenderListItem(int index, GObject obj)
  87. {
  88. UI_ListPhotoPreviewItem item = UI_ListPhotoPreviewItem.Proxy(obj);
  89. GLoader loaIcon = item.m_comPhoto.m_loaPhoto;
  90. item.m_comPhoto.m_loaPhoto.texture = _photoInfos[index].Ntexture;// PoemPhotoDataManager.Instance.BytesToTexture2D(_photoInfos[index].Bytes);
  91. item.target.SetSize(item.target.width, item.target.initHeight * _ui.target.height / _ui.target.initHeight);
  92. loaIcon.SetSize(loaIcon.width, loaIcon.texture.height * loaIcon.width / loaIcon.texture.width);
  93. loaIcon.y = item.target.height / 2;
  94. item.m_imgBorder.SetSize(item.target.width, item.target.height);
  95. UI_ListPhotoPreviewItem.ProxyEnd();
  96. }
  97. private void OnBtnLeftClick()
  98. {
  99. _curIndex--;
  100. _curIndex = Mathf.Max(0, _curIndex);
  101. UpdateView();
  102. }
  103. private void OnBtnRightClick()
  104. {
  105. _curIndex++;
  106. _curIndex = Mathf.Min(_ui.m_list.numItems - 1, _curIndex);
  107. UpdateView();
  108. }
  109. private void OnListScrollEnd()
  110. {
  111. _curIndex = _ui.m_list.ChildIndexToItemIndex(0);
  112. UpdateView();
  113. }
  114. private void OnBtnLockClick()
  115. {
  116. if (_curPhotoData.LockingStatus == false)
  117. {
  118. AlertUI.Show("是否确认锁定此照片?", "(锁住的照片无法被删除)")
  119. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  120. {
  121. bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, true, _sourceType);
  122. if (result)
  123. {
  124. _photoInfos[_curIndex].LockingStatus = true;
  125. UpdateView();
  126. }
  127. });
  128. }
  129. else
  130. {
  131. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  132. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  133. {
  134. bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, false, _sourceType);
  135. if (result)
  136. {
  137. _photoInfos[_curIndex].LockingStatus = false;
  138. UpdateView();
  139. }
  140. });
  141. }
  142. }
  143. private void OnBtnUpClick()
  144. {
  145. if (_curPhotoData.ToppingStatus == false)
  146. {
  147. AlertUI.Show("是否确认置顶此照片?")
  148. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  149. {
  150. bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, true, _sourceType);
  151. if (result)
  152. {
  153. _photoInfos[_curIndex].ToppingStatus = true;
  154. UpdateView();
  155. }
  156. });
  157. }
  158. else
  159. {
  160. AlertUI.Show("是否确认取消置顶此照片?")
  161. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  162. {
  163. bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, false, _sourceType);
  164. if (result)
  165. {
  166. _photoInfos[_curIndex].ToppingStatus = false;
  167. UpdateView();
  168. }
  169. });
  170. }
  171. }
  172. private void OnBtnShareClick()
  173. {
  174. ViewManager.Show<PoemPhotoShareView>(_curPhotoData, new object[] { typeof(PoemPhotoPreView).FullName, new object[] { _curIndex, _photoInfos } });
  175. }
  176. }
  177. }