PoemPhotoPreView.cs 8.6 KB

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