PoemPhotoView.cs 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236
  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. }
  47. protected override void OnHide()
  48. {
  49. base.OnHide();
  50. }
  51. protected override void RemoveEventListener()
  52. {
  53. base.RemoveEventListener();
  54. EventAgent.RemoveEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange);
  55. }
  56. private void OnBtnBackClick()
  57. {
  58. if (_ui.m_c2.selectedIndex == 1)
  59. {
  60. _ui.m_c2.selectedIndex = 0;
  61. }
  62. else
  63. {
  64. ViewManager.GoBackFrom(typeof(PoemPhotoView).FullName);
  65. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  66. _ui.m_c1.selectedIndex = 0;
  67. }
  68. _ui.m_c2.selectedIndex = 0;
  69. _listDelete.Clear();
  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 OnBtnConfirmDeleteClick()
  81. {
  82. AlertUI.Show("删除后的照片无法恢复,是否确认删除?")
  83. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  84. {
  85. PoemPhotoSProxy.ReqRemovedPhoto(_listDelete, _sourceType).Coroutine();
  86. });
  87. }
  88. private void OnBtnTabChange()
  89. {
  90. _ui.m_c2.selectedIndex = 0;
  91. _listDelete.Clear();
  92. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  93. UpdateView();
  94. }
  95. private void UpdateView()
  96. {
  97. if (_ui.m_c1.selectedIndex == 0)
  98. {
  99. _photoInfos = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  100. _sourceType = (int)PictureSourceType.PersonalAlbum;
  101. }
  102. else
  103. {
  104. _photoInfos = PoemPhotoDataManager.Instance.WsqsPhotoInfos;
  105. _sourceType = (int)PictureSourceType.WanShuiQianShan;
  106. }
  107. _ui.m_list.numItems = _photoInfos.Count;
  108. _ui.m_txtCount.text = string.Format("({0}/{1})", _photoInfos.Count, GlobalCfgArray.globalCfg.maxPhotoCount);
  109. _ui.m_btnConfirmDelete.m_txtTitle.text = string.Format("删除({0}/{1})", _listDelete.Count, _photoInfos.Count);
  110. }
  111. private void RenderListItem(int index, GObject obj)
  112. {
  113. UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj);
  114. item.m_imgSelect.visible = _ui.m_c2.selectedIndex == 1 && _listDelete.IndexOf(_photoInfos[index].PictureId) >= 0;
  115. item.m_comIcon.m_loaIcon.texture = PoemPhotoDataManager.Instance.BytesToTexture2D(_photoInfos[index].Bytes);
  116. item.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[index].CreationTime);
  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. 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, _sourceType }, new object[] { typeof(PoemView).FullName, this.viewData });
  141. }
  142. else if (_ui.m_c2.selectedIndex == 1)
  143. {
  144. long id = photoData.PictureId;
  145. UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj.parent);
  146. item.m_imgSelect.visible = !item.m_imgSelect.visible;
  147. if (item.m_imgSelect.visible)
  148. {
  149. _listDelete.Add(id);
  150. }
  151. else
  152. {
  153. _listDelete.Remove(id);
  154. }
  155. UI_ListPhotoItem.ProxyEnd();
  156. _ui.m_btnConfirmDelete.m_txtTitle.text = string.Format("删除({0}/{1})", _listDelete.Count, _photoInfos.Count);
  157. }
  158. }
  159. private void OnBtnLockClick(EventContext context)
  160. {
  161. GObject item = context.sender as GObject;
  162. int index = (int)item.data;
  163. PoemPhotoData photoData = _photoInfos[index];
  164. if (photoData.LockingStatus == false)
  165. {
  166. AlertUI.Show("是否确认锁定此照片?", "(锁住的照片无法被删除)")
  167. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  168. {
  169. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, true, _sourceType).Coroutine();
  170. });
  171. }
  172. else
  173. {
  174. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  175. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  176. {
  177. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, false, _sourceType).Coroutine();
  178. });
  179. }
  180. }
  181. private void OnBtnUpClick(EventContext context)
  182. {
  183. GObject item = context.sender as GObject;
  184. int index = (int)item.data;
  185. PoemPhotoData photoData = _photoInfos[index];
  186. if (photoData.ToppingStatus == false)
  187. {
  188. AlertUI.Show("是否确认置顶此照片?")
  189. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  190. {
  191. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, true, _sourceType).Coroutine();
  192. });
  193. }
  194. else
  195. {
  196. AlertUI.Show("是否确认取消置顶此照片?")
  197. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  198. {
  199. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, false, _sourceType).Coroutine();
  200. });
  201. }
  202. }
  203. }
  204. }