PoemPhotoView.cs 13 KB

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