PoemPhotoView.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272
  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 PoemPhotoView : BaseWindow
  9. {
  10. private UI_PoemPhotoUI _ui;
  11. private List<long> _listDelete = new List<long>();
  12. private List<PoemPhotoData> _photoInfos;
  13. private int _sourceType = 0;
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_PoemPhotoUI.PACKAGE_NAME;
  27. _ui = UI_PoemPhotoUI.Create();
  28. this.viewCom = _ui.target;
  29. isfullScreen = true;
  30. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("xc_bjbj");
  31. _ui.m_list.SetVirtual();
  32. _ui.m_list.itemRenderer = RenderListItem;
  33. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  34. _ui.m_btnDelete.onClick.Add(OnBtnDeleteClick);
  35. _ui.m_btnConfirmDelete.target.onClick.Add(OnBtnConfirmDeleteClick);
  36. _ui.m_c1.onChanged.Add(OnBtnTabChange);
  37. }
  38. protected override void AddEventListener()
  39. {
  40. base.AddEventListener();
  41. EventAgent.AddEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange);
  42. }
  43. protected override void OnShown()
  44. {
  45. base.OnShown();
  46. OnBtnTabChange();
  47. }
  48. protected override void OnHide()
  49. {
  50. base.OnHide();
  51. }
  52. protected override void RemoveEventListener()
  53. {
  54. base.RemoveEventListener();
  55. EventAgent.RemoveEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange);
  56. }
  57. private void OnBtnBackClick()
  58. {
  59. if (_ui.m_c2.selectedIndex == 1)
  60. {
  61. _ui.m_c2.selectedIndex = 0;
  62. }
  63. else
  64. {
  65. ViewManager.GoBackFrom(typeof(PoemPhotoView).FullName);
  66. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  67. _ui.m_c1.selectedIndex = 0;
  68. }
  69. _ui.m_c2.selectedIndex = 0;
  70. }
  71. private void OnBtnDeleteClick()
  72. {
  73. if (_ui.m_list.numItems == 0)
  74. {
  75. PromptController.Instance.ShowFloatTextPrompt("暂无照片可删除");
  76. return;
  77. }
  78. _ui.m_c2.selectedIndex = 1;
  79. }
  80. private void OnBtnTabChange()
  81. {
  82. _ui.m_c2.selectedIndex = 0;
  83. _listDelete.Clear();
  84. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  85. UpdateView();
  86. }
  87. private void UpdateView()
  88. {
  89. if (_ui.m_c1.selectedIndex == 0)
  90. {
  91. _photoInfos = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  92. _sourceType = (int)PictureSourceType.PersonalAlbum;
  93. }
  94. else
  95. {
  96. _photoInfos = PoemPhotoDataManager.Instance.WsqsPhotoInfos;
  97. _sourceType = (int)PictureSourceType.WanShuiQianShan;
  98. }
  99. _ui.m_list.numItems = _photoInfos.Count;
  100. _ui.m_txtCount.text = string.Format("({0}/{1})", _photoInfos.Count, GlobalCfgArray.globalCfg.maxPhotoCount);
  101. _ui.m_btnConfirmDelete.m_txtTitle.text = string.Format("删除({0}/{1})", _listDelete.Count, _photoInfos.Count);
  102. }
  103. private void RenderListItem(int index, GObject obj)
  104. {
  105. UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj);
  106. item.m_imgSelect.visible = _ui.m_c2.selectedIndex == 1 && _listDelete.IndexOf(_photoInfos[index].PictureId) >= 0;
  107. GLoader loaIcon = item.m_comIcon.m_loaIcon;
  108. if (_photoInfos[index].Ntexture == null)
  109. {
  110. _photoInfos[index].Ntexture = PoemPhotoDataManager.Instance.BytesToTexture2D(_photoInfos[index].Bytes);
  111. }
  112. loaIcon.texture = _photoInfos[index].Ntexture;
  113. item.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[index].CreationTime);
  114. item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0;
  115. item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0;
  116. if (item.m_btnLock.target.data == null)
  117. {
  118. item.m_btnLock.target.onClick.Add(OnBtnLockClick);
  119. }
  120. item.m_btnLock.target.data = index;
  121. if (item.m_btnUp.target.data == null)
  122. {
  123. item.m_btnUp.target.onClick.Add(OnBtnUpClick);
  124. }
  125. item.m_btnUp.target.data = index;
  126. if (item.m_comIcon.target.data == null)
  127. {
  128. item.m_comIcon.target.onClick.Add(OnLoaIconClick);
  129. }
  130. item.m_comIcon.target.data = index;
  131. UI_ListPhotoItem.ProxyEnd();
  132. }
  133. private void OnLoaIconClick(EventContext context)
  134. {
  135. GObject obj = context.sender as GObject;
  136. int index = (int)obj.data;
  137. PoemPhotoData photoData = _photoInfos[index];
  138. if (_ui.m_c2.selectedIndex == 0)
  139. {
  140. ViewManager.Show<PoemPhotoPreView>(new object[] { index, _photoInfos }, new object[] { typeof(PoemView).FullName, this.viewData });
  141. }
  142. else if (_ui.m_c2.selectedIndex == 1)
  143. {
  144. if (photoData.LockingStatus)
  145. {
  146. PromptController.Instance.ShowFloatTextPrompt("锁定的照片无法删除");
  147. return;
  148. }
  149. if (photoData.ToppingStatus)
  150. {
  151. PromptController.Instance.ShowFloatTextPrompt("置顶的照片无法删除");
  152. return;
  153. }
  154. UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj.parent);
  155. item.m_imgSelect.visible = !item.m_imgSelect.visible;
  156. if (item.m_imgSelect.visible)
  157. {
  158. _listDelete.Add(photoData.PictureId);
  159. }
  160. else
  161. {
  162. _listDelete.Remove(photoData.PictureId);
  163. }
  164. UI_ListPhotoItem.ProxyEnd();
  165. _ui.m_btnConfirmDelete.m_txtTitle.text = string.Format("删除({0}/{1})", _listDelete.Count, _photoInfos.Count);
  166. }
  167. }
  168. private void OnBtnConfirmDeleteClick()
  169. {
  170. if (_listDelete.Count == 0)
  171. {
  172. PromptController.Instance.ShowFloatTextPrompt("请选择要删除的照片");
  173. return;
  174. }
  175. AlertUI.Show("删除后的照片无法恢复,是否确认删除?")
  176. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  177. {
  178. bool result = await PoemPhotoSProxy.ReqRemovedPhoto(_listDelete, _sourceType);
  179. if (result)
  180. {
  181. _listDelete.Clear();
  182. OnBtnTabChange();
  183. }
  184. });
  185. }
  186. private void OnBtnLockClick(EventContext context)
  187. {
  188. if (_ui.m_c2.selectedIndex == 1)
  189. {
  190. PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作");
  191. return;
  192. }
  193. GObject item = context.sender as GObject;
  194. int index = (int)item.data;
  195. PoemPhotoData photoData = _photoInfos[index];
  196. if (photoData.LockingStatus == false)
  197. {
  198. AlertUI.Show("是否确认锁定此照片?", "(锁定的照片无法被删除)")
  199. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  200. {
  201. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, true, _sourceType).Coroutine();
  202. });
  203. }
  204. else
  205. {
  206. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  207. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  208. {
  209. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, false, _sourceType).Coroutine();
  210. });
  211. }
  212. }
  213. private void OnBtnUpClick(EventContext context)
  214. {
  215. if (_ui.m_c2.selectedIndex == 1)
  216. {
  217. PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作");
  218. return;
  219. }
  220. GObject item = context.sender as GObject;
  221. int index = (int)item.data;
  222. PoemPhotoData photoData = _photoInfos[index];
  223. if (photoData.ToppingStatus == false)
  224. {
  225. AlertUI.Show("是否确认置顶此照片?")
  226. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  227. {
  228. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, true, _sourceType).Coroutine();
  229. });
  230. }
  231. else
  232. {
  233. AlertUI.Show("是否确认取消置顶此照片?")
  234. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  235. {
  236. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, false, _sourceType).Coroutine();
  237. });
  238. }
  239. }
  240. }
  241. }