PoemPhotoView.cs 9.5 KB

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