PoemPhotoPreView.cs 8.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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 GList _list;
  12. private List<PoemPhotoData> _photoInfos;
  13. private int _curIndex = 0;
  14. private int _sourceType = 0;
  15. private PoemPhotoData _curPhotoData;
  16. public override void Dispose()
  17. {
  18. if (_ui != null)
  19. {
  20. _ui.Dispose();
  21. _ui = null;
  22. }
  23. base.Dispose();
  24. }
  25. protected override void OnInit()
  26. {
  27. base.OnInit();
  28. packageName = UI_PoemPhotoPreviewUI.PACKAGE_NAME;
  29. _ui = UI_PoemPhotoPreviewUI.Create();
  30. this.viewCom = _ui.target;
  31. isfullScreen = true;
  32. _ui.m_mask.onClick.Add(OnBtnBackClick);
  33. _ui.m_list.SetVirtual();
  34. _ui.m_list.itemRenderer = RenderListItem;
  35. _ui.m_list.scrollPane.onScrollEnd.Add(OnListScrollEnd);
  36. _ui.m_list.scrollPane.decelerationRate = 0.8f;
  37. _ui.m_listTravel.SetVirtual();
  38. _ui.m_listTravel.itemRenderer = RenderListTravelItem;
  39. _ui.m_listTravel.scrollPane.onScrollEnd.Add(OnListScrollEnd);
  40. _ui.m_listTravel.scrollPane.decelerationRate = 0.8f;
  41. _ui.m_btnLeft.onClick.Add(OnBtnLeftClick);
  42. _ui.m_btnRight.onClick.Add(OnBtnRightClick);
  43. _ui.m_btnLock.target.onClick.Add(OnBtnLockClick);
  44. _ui.m_btnUp.target.onClick.Add(OnBtnUpClick);
  45. _ui.m_btnShare.onClick.Add(OnBtnShareClick);
  46. }
  47. protected override void AddEventListener()
  48. {
  49. base.AddEventListener();
  50. }
  51. protected override void OnShown()
  52. {
  53. base.OnShown();
  54. _curIndex = (int)(this.viewData as object[])[0];
  55. List<PoemPhotoData> photoInfos = (this.viewData as object[])[1] as List<PoemPhotoData>;
  56. _photoInfos = new List<PoemPhotoData>(photoInfos.ToArray());
  57. _sourceType = (int)(this.viewData as object[])[2];
  58. if (_sourceType == 2)
  59. {
  60. _sourceType = 0;
  61. }
  62. _ui.m_c1.selectedIndex = _sourceType;
  63. if (_sourceType == (int)PictureSourceType.PersonalAlbum)
  64. {
  65. _list = _ui.m_list;
  66. _list.numItems = _photoInfos.Count;
  67. // _list.height = _list.GetChildAt(0).height;
  68. }
  69. else if (_sourceType == (int)PictureSourceType.WanShuiQianShan)
  70. {
  71. _list = _ui.m_listTravel;
  72. _list.numItems = _photoInfos.Count;
  73. }
  74. UpdateView();
  75. }
  76. protected override void OnHide()
  77. {
  78. base.OnHide();
  79. }
  80. protected override void RemoveEventListener()
  81. {
  82. base.RemoveEventListener();
  83. }
  84. private void OnBtnBackClick()
  85. {
  86. ViewManager.GoBackFrom(typeof(PoemPhotoPreView).FullName);
  87. }
  88. private void UpdateView(bool ani = false)
  89. {
  90. _ui.m_btnLeft.grayed = _curIndex <= 0;
  91. _ui.m_btnRight.grayed = _curIndex >= _list.numItems - 1;
  92. _ui.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[_curIndex].CreationTime);
  93. _ui.m_btnLock.m_c1.selectedIndex = _photoInfos[_curIndex].LockingStatus ? 1 : 0;
  94. _ui.m_btnUp.m_c1.selectedIndex = _photoInfos[_curIndex].ToppingStatus ? 1 : 0;
  95. if (_list.numItems > 0) _list.ScrollToView(_curIndex, ani);
  96. if (_ui.m_btnLock.target.data == null)
  97. {
  98. _ui.m_btnLock.target.onClick.Add(OnBtnLockClick);
  99. }
  100. _ui.m_btnLock.target.data = _curIndex;
  101. if (_ui.m_btnUp.target.data == null)
  102. {
  103. _ui.m_btnUp.target.onClick.Add(OnBtnUpClick);
  104. }
  105. _curPhotoData = _photoInfos[_curIndex];
  106. }
  107. private void RenderListItem(int index, GObject obj)
  108. {
  109. UI_ListPhotoPreviewItem item = UI_ListPhotoPreviewItem.Proxy(obj);
  110. item.m_comPhoto.m_loaPhoto.texture = _photoInfos[index].Ntexture;
  111. // item.target.SetSize(item.target.width, item.target.initHeight * _ui.target.height / _ui.target.initHeight);
  112. UI_ListPhotoPreviewItem.ProxyEnd();
  113. }
  114. private void RenderListTravelItem(int index, GObject obj)
  115. {
  116. UI_ComPostcard item = UI_ComPostcard.Proxy(obj);
  117. PoemPhotoData photoData = _photoInfos[index];
  118. TravelLoactionCfg loactionCfg = TravelLoactionCfgArray.Instance.GetCfg(photoData.TravelLocationId);
  119. item.m_comTravel.m_loaBg.url = ResPathUtil.GetTravelBgPath(loactionCfg.res);
  120. item.m_txtLocationName.text = loactionCfg.name;
  121. item.m_txtTime.text = TimeUtil.FormattingTimeTo_yyyMMdd1(photoData.CreationTime);
  122. item.m_comTravel.m_loaRole.url = "";
  123. if (photoData.TravelSuitId > 0)
  124. {
  125. TravelSuitCfg travelSuitCfg = TravelSuitCfgArray.Instance.GetCfg(photoData.TravelSuitId);
  126. item.m_comTravel.m_loaRole.url = ResPathUtil.GetTravelRolePath(travelSuitCfg.reourcesArr[photoData.SuitResIndex]);
  127. item.m_comTravel.m_loaRole.SetXY(loactionCfg.positionsArr[photoData.PositionIndex][0], loactionCfg.positionsArr[photoData.PositionIndex][1]);
  128. }
  129. UI_ComPostcard.ProxyEnd();
  130. }
  131. private void OnBtnLeftClick()
  132. {
  133. _curIndex--;
  134. _curIndex = Mathf.Max(0, _curIndex);
  135. UpdateView(true);
  136. }
  137. private void OnBtnRightClick()
  138. {
  139. _curIndex++;
  140. _curIndex = Mathf.Min(_list.numItems - 1, _curIndex);
  141. UpdateView(true);
  142. }
  143. private void OnListScrollEnd()
  144. {
  145. _curIndex = _list.ChildIndexToItemIndex(0);
  146. UpdateView();
  147. }
  148. private void OnBtnLockClick()
  149. {
  150. if (_curPhotoData.LockingStatus == false)
  151. {
  152. AlertUI.Show("是否确认锁定此照片?", "(锁住的照片无法被删除)")
  153. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  154. {
  155. bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, true, _sourceType);
  156. if (result)
  157. {
  158. _photoInfos[_curIndex].LockingStatus = true;
  159. UpdateView();
  160. }
  161. });
  162. }
  163. else
  164. {
  165. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  166. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  167. {
  168. bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, false, _sourceType);
  169. if (result)
  170. {
  171. _photoInfos[_curIndex].LockingStatus = false;
  172. UpdateView();
  173. }
  174. });
  175. }
  176. }
  177. private void OnBtnUpClick()
  178. {
  179. if (_curPhotoData.ToppingStatus == false)
  180. {
  181. AlertUI.Show("是否确认置顶此照片?")
  182. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  183. {
  184. bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, true, _sourceType);
  185. if (result)
  186. {
  187. _photoInfos[_curIndex].ToppingStatus = true;
  188. UpdateView();
  189. }
  190. });
  191. }
  192. else
  193. {
  194. AlertUI.Show("是否确认取消置顶此照片?")
  195. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  196. {
  197. bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, false, _sourceType);
  198. if (result)
  199. {
  200. _photoInfos[_curIndex].ToppingStatus = false;
  201. UpdateView();
  202. }
  203. });
  204. }
  205. }
  206. private void OnBtnShareClick()
  207. {
  208. if (_sourceType == (int)PictureSourceType.WanShuiQianShan)
  209. {
  210. PromptController.Instance.ShowFloatTextPrompt("暂时没有可以分享的对象");
  211. return;
  212. }
  213. ViewManager.Show<PoemPhotoShareView>(_curPhotoData);
  214. }
  215. }
  216. }