PoemPhotoPreView.cs 8.7 KB

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