PoemPhotoView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Poem;
  5. namespace GFGGame
  6. {
  7. public class PoemPhotoView : BaseWindow
  8. {
  9. private UI_PoemPhotoUI _ui;
  10. private List<long> _listDelete = new List<long>();
  11. private List<PoemPhotoData> _photoInfos;
  12. private int _sourceType = 0;
  13. public override void Dispose()
  14. {
  15. if (_ui != null)
  16. {
  17. _ui.Dispose();
  18. _ui = null;
  19. }
  20. base.Dispose();
  21. }
  22. protected override void OnInit()
  23. {
  24. base.OnInit();
  25. packageName = UI_PoemPhotoUI.PACKAGE_NAME;
  26. _ui = UI_PoemPhotoUI.Create();
  27. this.viewCom = _ui.target;
  28. isfullScreen = true;
  29. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("xc_bjbj");
  30. _ui.m_list.SetVirtual();
  31. _ui.m_list.itemRenderer = RenderListItem;
  32. _ui.m_listTravel.SetVirtual();
  33. _ui.m_listTravel.itemRenderer = RenderListTravelItem;
  34. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  35. _ui.m_btnDelete.onClick.Add(OnBtnDeleteClick);
  36. _ui.m_btnConfirmDelete.target.onClick.Add(OnBtnConfirmDeleteClick);
  37. _ui.m_c1.onChanged.Add(OnBtnTabChange);
  38. }
  39. protected override void AddEventListener()
  40. {
  41. base.AddEventListener();
  42. EventAgent.AddEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange);
  43. }
  44. protected override void OnShown()
  45. {
  46. base.OnShown();
  47. _ui.m_c1.selectedIndex = (this.viewData == null) ? (int)PictureSourceType.PersonalAlbum : (int)this.viewData;
  48. OnBtnTabChange();
  49. UpdateView();
  50. Timers.inst.AddUpdate(CheckGuide);
  51. }
  52. protected override void OnHide()
  53. {
  54. base.OnHide();
  55. _ui.m_c2.selectedIndex = 0;
  56. _listDelete.Clear();
  57. Timers.inst.Remove(CheckGuide);
  58. }
  59. protected override void RemoveEventListener()
  60. {
  61. base.RemoveEventListener();
  62. EventAgent.RemoveEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange);
  63. }
  64. private void OnBtnBackClick()
  65. {
  66. if (_ui.m_c2.selectedIndex == 1)
  67. {
  68. _ui.m_c2.selectedIndex = 0;
  69. }
  70. else
  71. {
  72. ViewManager.GoBackFrom(typeof(PoemPhotoView).FullName);
  73. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  74. _ui.m_c1.selectedIndex = 0;
  75. }
  76. _ui.m_c2.selectedIndex = 0;
  77. }
  78. private void OnBtnDeleteClick()
  79. {
  80. if (_ui.m_list.numItems == 0)
  81. {
  82. PromptController.Instance.ShowFloatTextPrompt("暂无照片可删除");
  83. return;
  84. }
  85. _ui.m_c2.selectedIndex = 1;
  86. }
  87. private void OnBtnTabChange()
  88. {
  89. _ui.m_c2.selectedIndex = 0;
  90. _listDelete.Clear();
  91. // if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  92. UpdateView();
  93. }
  94. private void UpdateView()
  95. {
  96. if (_ui.m_c1.selectedIndex == 0)
  97. {
  98. _photoInfos = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  99. _sourceType = (int)PictureSourceType.PersonalAlbum;
  100. _ui.m_list.numItems = _photoInfos.Count;
  101. }
  102. else
  103. {
  104. _photoInfos = PoemPhotoDataManager.Instance.WsqsPhotoInfos;
  105. _sourceType = (int)PictureSourceType.WanShuiQianShan;
  106. _ui.m_listTravel.numItems = _photoInfos.Count;
  107. }
  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. GLoader loaIcon = item.m_comIcon.m_loaIcon;
  116. if (_photoInfos[index].Ntexture == null)
  117. {
  118. _photoInfos[index].Ntexture = PoemPhotoDataManager.Instance.BytesToTexture2D(_photoInfos[index].Bytes);
  119. }
  120. loaIcon.texture = _photoInfos[index].Ntexture;
  121. item.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[index].CreationTime);
  122. item.m_txtTime.visible = false;
  123. item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0;
  124. item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0;
  125. if (item.m_btnLock.target.data == null)
  126. {
  127. item.m_btnLock.target.onClick.Add(OnBtnLockClick);
  128. }
  129. item.m_btnLock.target.data = index;
  130. if (item.m_btnUp.target.data == null)
  131. {
  132. item.m_btnUp.target.onClick.Add(OnBtnUpClick);
  133. }
  134. item.m_btnUp.target.data = index;
  135. if (item.m_comIcon.target.data == null)
  136. {
  137. item.m_comIcon.target.onClick.Add(OnLoaIconClick);
  138. }
  139. item.m_comIcon.target.data = index;
  140. UI_ListPhotoItem.ProxyEnd();
  141. }
  142. private void RenderListTravelItem(int index, GObject obj)
  143. {
  144. PoemPhotoData poemPhotoData = _photoInfos[index];
  145. TravelLoactionCfg loactionCfg = TravelLoactionCfgArray.Instance.GetCfg(poemPhotoData.TravelLocationId);
  146. UI_ComPhotoPostcard item = UI_ComPhotoPostcard.Proxy(obj);
  147. item.m_imgSelect.visible = _ui.m_c2.selectedIndex == 1 && _listDelete.IndexOf(_photoInfos[index].PictureId) >= 0;
  148. item.m_comTravel.m_loaBg.url = ResPathUtil.GetTravelBgPath(loactionCfg.res);
  149. item.m_comTravel.m_loaRole.url = "";
  150. if (poemPhotoData.TravelSuitId > 0)
  151. {
  152. TravelSuitCfg travelSuitCfg = TravelSuitCfgArray.Instance.GetCfg(poemPhotoData.TravelSuitId);
  153. item.m_comTravel.m_loaRole.url = ResPathUtil.GetTravelRolePath(travelSuitCfg.reourcesArr[poemPhotoData.SuitResIndex]);
  154. item.m_comTravel.m_loaRole.SetXY(loactionCfg.positionsArr[poemPhotoData.PositionIndex][0], loactionCfg.positionsArr[poemPhotoData.PositionIndex][1]);
  155. }
  156. item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0;
  157. item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0;
  158. if (item.m_btnLock.target.data == null)
  159. {
  160. item.m_btnLock.target.onClick.Add(OnBtnLockClick);
  161. }
  162. item.m_btnLock.target.data = index;
  163. if (item.m_btnUp.target.data == null)
  164. {
  165. item.m_btnUp.target.onClick.Add(OnBtnUpClick);
  166. }
  167. item.m_btnUp.target.data = index;
  168. if (item.m_comTravel.target.data == null)
  169. {
  170. item.m_comTravel.target.onClick.Add(OnLoaIconClick);
  171. }
  172. item.m_comTravel.target.data = index;
  173. UI_ComPhotoPostcard.ProxyEnd();
  174. }
  175. private void OnLoaIconClick(EventContext context)
  176. {
  177. GObject obj = context.sender as GObject;
  178. int index = (int)obj.data;
  179. PoemPhotoData photoData = _photoInfos[index];
  180. if (_ui.m_c2.selectedIndex == 0)
  181. {
  182. ViewManager.Show<PoemPhotoPreView>(new object[] { index, _photoInfos, _sourceType }, new object[] { typeof(PoemPhotoView).FullName, _sourceType });
  183. }
  184. else if (_ui.m_c2.selectedIndex == 1)
  185. {
  186. if (photoData.LockingStatus)
  187. {
  188. PromptController.Instance.ShowFloatTextPrompt("锁定的照片无法删除");
  189. return;
  190. }
  191. if (photoData.ToppingStatus)
  192. {
  193. PromptController.Instance.ShowFloatTextPrompt("置顶的照片无法删除");
  194. return;
  195. }
  196. UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj.parent);
  197. item.m_imgSelect.visible = !item.m_imgSelect.visible;
  198. if (item.m_imgSelect.visible)
  199. {
  200. _listDelete.Add(photoData.PictureId);
  201. }
  202. else
  203. {
  204. _listDelete.Remove(photoData.PictureId);
  205. }
  206. UI_ListPhotoItem.ProxyEnd();
  207. _ui.m_btnConfirmDelete.m_txtTitle.text = string.Format("删除({0}/{1})", _listDelete.Count, _photoInfos.Count);
  208. }
  209. }
  210. private void OnBtnConfirmDeleteClick()
  211. {
  212. if (_listDelete.Count == 0)
  213. {
  214. PromptController.Instance.ShowFloatTextPrompt("请选择要删除的照片");
  215. return;
  216. }
  217. AlertUI.Show("删除后的照片无法恢复,是否确认删除?")
  218. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  219. {
  220. bool result = await PoemPhotoSProxy.ReqRemovedPhoto(_listDelete, _sourceType);
  221. if (result)
  222. {
  223. _listDelete.Clear();
  224. OnBtnTabChange();
  225. }
  226. });
  227. }
  228. private void OnBtnLockClick(EventContext context)
  229. {
  230. if (_ui.m_c2.selectedIndex == 1)
  231. {
  232. PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作");
  233. return;
  234. }
  235. GObject item = context.sender as GObject;
  236. int index = (int)item.data;
  237. PoemPhotoData photoData = _photoInfos[index];
  238. if (photoData.LockingStatus == false)
  239. {
  240. AlertUI.Show("是否确认锁定此照片?", "(锁定的照片无法被删除)")
  241. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  242. {
  243. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, true, _sourceType).Coroutine();
  244. });
  245. }
  246. else
  247. {
  248. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  249. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  250. {
  251. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, false, _sourceType).Coroutine();
  252. });
  253. }
  254. }
  255. private void OnBtnUpClick(EventContext context)
  256. {
  257. if (_ui.m_c2.selectedIndex == 1)
  258. {
  259. PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作");
  260. return;
  261. }
  262. GObject item = context.sender as GObject;
  263. int index = (int)item.data;
  264. PoemPhotoData photoData = _photoInfos[index];
  265. if (photoData.ToppingStatus == false)
  266. {
  267. AlertUI.Show("是否确认置顶此照片?")
  268. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  269. {
  270. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, true, _sourceType).Coroutine();
  271. });
  272. }
  273. else
  274. {
  275. AlertUI.Show("是否确认取消置顶此照片?")
  276. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  277. {
  278. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, false, _sourceType).Coroutine();
  279. });
  280. }
  281. }
  282. private void CheckGuide(object param)
  283. {
  284. if (GuideDataManager.IsGuideFinish(ConstGuideId.POEM) <= 0)
  285. {
  286. UpdateToCheckGuide(null);
  287. }
  288. else
  289. {
  290. Timers.inst.Remove(CheckGuide);
  291. }
  292. }
  293. protected override void UpdateToCheckGuide(object param)
  294. {
  295. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  296. GuideController.TryGuide(_ui.m_btnback, ConstGuideId.POEM, 2, "");
  297. }
  298. }
  299. }