PoemPhotoView.cs 9.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  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. loaIcon.texture = PoemPhotoDataManager.Instance.BytesToTexture2D(_photoInfos[index].Bytes);
  109. loaIcon.SetSize(loaIcon.width, loaIcon.texture.height * loaIcon.width / loaIcon.texture.width);
  110. item.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[index].CreationTime);
  111. item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0;
  112. item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0;
  113. if (item.m_btnLock.target.data == null)
  114. {
  115. item.m_btnLock.target.onClick.Add(OnBtnLockClick);
  116. }
  117. item.m_btnLock.target.data = index;
  118. if (item.m_btnUp.target.data == null)
  119. {
  120. item.m_btnUp.target.onClick.Add(OnBtnUpClick);
  121. }
  122. item.m_btnUp.target.data = index;
  123. if (item.m_comIcon.target.data == null)
  124. {
  125. item.m_comIcon.target.onClick.Add(OnLoaIconClick);
  126. }
  127. item.m_comIcon.target.data = index;
  128. UI_ListPhotoItem.ProxyEnd();
  129. }
  130. private void OnLoaIconClick(EventContext context)
  131. {
  132. GObject obj = context.sender as GObject;
  133. int index = (int)obj.data;
  134. PoemPhotoData photoData = _photoInfos[index];
  135. if (_ui.m_c2.selectedIndex == 0)
  136. {
  137. ViewManager.Show<PoemPhotoPreView>(new object[] { index, _photoInfos }, new object[] { typeof(PoemView).FullName, this.viewData });
  138. }
  139. else if (_ui.m_c2.selectedIndex == 1)
  140. {
  141. if (photoData.LockingStatus)
  142. {
  143. PromptController.Instance.ShowFloatTextPrompt("锁定的照片无法删除");
  144. return;
  145. }
  146. if (photoData.ToppingStatus)
  147. {
  148. PromptController.Instance.ShowFloatTextPrompt("置顶的照片无法删除");
  149. return;
  150. }
  151. UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj.parent);
  152. item.m_imgSelect.visible = !item.m_imgSelect.visible;
  153. if (item.m_imgSelect.visible)
  154. {
  155. _listDelete.Add(photoData.PictureId);
  156. }
  157. else
  158. {
  159. _listDelete.Remove(photoData.PictureId);
  160. }
  161. UI_ListPhotoItem.ProxyEnd();
  162. _ui.m_btnConfirmDelete.m_txtTitle.text = string.Format("删除({0}/{1})", _listDelete.Count, _photoInfos.Count);
  163. }
  164. }
  165. private void OnBtnConfirmDeleteClick()
  166. {
  167. if (_listDelete.Count == 0)
  168. {
  169. PromptController.Instance.ShowFloatTextPrompt("请选择要删除的照片");
  170. return;
  171. }
  172. AlertUI.Show("删除后的照片无法恢复,是否确认删除?")
  173. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  174. {
  175. bool result = await PoemPhotoSProxy.ReqRemovedPhoto(_listDelete, _sourceType);
  176. if (result)
  177. {
  178. _listDelete.Clear();
  179. OnBtnTabChange();
  180. }
  181. });
  182. }
  183. private void OnBtnLockClick(EventContext context)
  184. {
  185. if (_ui.m_c2.selectedIndex == 1)
  186. {
  187. PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作");
  188. return;
  189. }
  190. GObject item = context.sender as GObject;
  191. int index = (int)item.data;
  192. PoemPhotoData photoData = _photoInfos[index];
  193. if (photoData.LockingStatus == false)
  194. {
  195. AlertUI.Show("是否确认锁定此照片?", "(锁定的照片无法被删除)")
  196. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  197. {
  198. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, true, _sourceType).Coroutine();
  199. });
  200. }
  201. else
  202. {
  203. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  204. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  205. {
  206. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, false, _sourceType).Coroutine();
  207. });
  208. }
  209. }
  210. private void OnBtnUpClick(EventContext context)
  211. {
  212. if (_ui.m_c2.selectedIndex == 1)
  213. {
  214. PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作");
  215. return;
  216. }
  217. GObject item = context.sender as GObject;
  218. int index = (int)item.data;
  219. PoemPhotoData photoData = _photoInfos[index];
  220. if (photoData.ToppingStatus == false)
  221. {
  222. AlertUI.Show("是否确认置顶此照片?")
  223. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  224. {
  225. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, true, _sourceType).Coroutine();
  226. });
  227. }
  228. else
  229. {
  230. AlertUI.Show("是否确认取消置顶此照片?")
  231. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  232. {
  233. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, false, _sourceType).Coroutine();
  234. });
  235. }
  236. }
  237. }
  238. }