PoemPhotoPreView.cs 8.5 KB

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