PoemPhotoView.cs 14 KB

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