PoemPhotoPreView.cs 8.7 KB

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