PoemPhotoPreView.cs 6.6 KB

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