PoemPhotoView.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Poem;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public struct SavePhotoList
  9. {
  10. public int pageIndex;
  11. public List<PoemPhotoData> photoInfos;
  12. public List<long> listChoose;
  13. }
  14. public class PoemPhotoView : BaseWindow
  15. {
  16. private UI_PoemPhotoUI _ui;
  17. private List<long> _listChoose = new List<long>();
  18. private List<PoemPhotoData> _photoInfos;
  19. private int _sourceType = 0;
  20. public override void Dispose()
  21. {
  22. if (_ui != null)
  23. {
  24. _ui.Dispose();
  25. _ui = null;
  26. }
  27. base.Dispose();
  28. }
  29. protected override void OnInit()
  30. {
  31. base.OnInit();
  32. packageName = UI_PoemPhotoUI.PACKAGE_NAME;
  33. _ui = UI_PoemPhotoUI.Create();
  34. this.viewCom = _ui.target;
  35. isfullScreen = true;
  36. isReturnView = true;
  37. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg");
  38. _ui.m_list.SetVirtual();
  39. _ui.m_list.itemRenderer = RenderListItem;
  40. _ui.m_listTravel.SetVirtual();
  41. _ui.m_listTravel.itemRenderer = RenderListTravelItem;
  42. _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView);
  43. _ui.m_btnRule.data = 300018;
  44. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  45. _ui.m_btnDelete.onClick.Add(OnBtnDeleteClick);
  46. _ui.m_btnSave.onClick.Add(OnBtnSaveClick);
  47. _ui.m_btnConfirmDelete.onClick.Add(OnBtnConfirmDeleteClick);
  48. _ui.m_c1.onChanged.Add(OnBtnTabChange);
  49. _ui.m_btnChooseAll.onClick.Add(OnClickBtnChooseAll);
  50. _ui.m_btnConfirmSave.onClick.Add(OnClickConfirmSave);
  51. InitTypeList();
  52. }
  53. protected override void AddEventListener()
  54. {
  55. base.AddEventListener();
  56. EventAgent.AddEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange);
  57. }
  58. protected override void OnShown()
  59. {
  60. base.OnShown();
  61. if (this.viewData != null)
  62. {
  63. _ui.m_c1.selectedIndex = (int)this.viewData;
  64. }
  65. //_ui.m_c1.selectedIndex = (this.viewData == null) ? (int)PictureSourceType.PersonalAlbum : (int)this.viewData;
  66. OnBtnTabChange();
  67. // UpdateView();
  68. Timers.inst.AddUpdate(CheckGuide);
  69. }
  70. protected override void OnHide()
  71. {
  72. base.OnHide();
  73. _ui.m_c2.selectedIndex = 0;
  74. _listChoose.Clear();
  75. Timers.inst.Remove(CheckGuide);
  76. }
  77. protected override void RemoveEventListener()
  78. {
  79. base.RemoveEventListener();
  80. EventAgent.RemoveEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange);
  81. }
  82. private void OnBtnBackClick()
  83. {
  84. if (_ui.m_c2.selectedIndex == 1)
  85. {
  86. _ui.m_c2.selectedIndex = 0;
  87. }
  88. else
  89. {
  90. ViewManager.GoBackFrom(typeof(PoemPhotoView).FullName);
  91. if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0);
  92. _ui.m_c1.selectedIndex = 0;
  93. }
  94. _ui.m_c2.selectedIndex = 0;
  95. }
  96. private void OnBtnDeleteClick()
  97. {
  98. if (_ui.m_c1.selectedIndex == 0 && GetEnablePhotoNum(true) == 0)
  99. {
  100. PromptController.Instance.ShowFloatTextPrompt("暂无照片可删除");
  101. return;
  102. }
  103. if (_ui.m_c1.selectedIndex == 1 && GetEnablePhotoNum(true) == 0)
  104. {
  105. PromptController.Instance.ShowFloatTextPrompt("暂无明信片可删除");
  106. return;
  107. }
  108. _ui.m_c2.selectedIndex = 1;
  109. _ui.m_btnChooseAll.selected = false;
  110. }
  111. private void OnBtnSaveClick()
  112. {
  113. if (_ui.m_c1.selectedIndex == 0 && _photoInfos.Count == 0)
  114. {
  115. PromptController.Instance.ShowFloatTextPrompt("暂无照片可保存");
  116. return;
  117. }
  118. if (_ui.m_c1.selectedIndex == 1 && _photoInfos.Count == 0)
  119. {
  120. PromptController.Instance.ShowFloatTextPrompt("暂无明信片可保存");
  121. return;
  122. }
  123. _ui.m_c2.selectedIndex = 2;
  124. _ui.m_btnChooseAll.selected = false;
  125. }
  126. private void OnBtnTabChange()
  127. {
  128. _ui.m_c2.selectedIndex = 0;
  129. _listChoose.Clear();
  130. UpdateView();
  131. }
  132. private void UpdateView()
  133. {
  134. if (_ui.m_c1.selectedIndex == 0)
  135. {
  136. _ui.m_listTravel.numItems = 0;
  137. _photoInfos = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  138. _sourceType = (int)PictureSourceType.PersonalAlbum;
  139. _ui.m_list.numItems = _photoInfos.Count;
  140. _ui.m_txtCount.text = string.Format("{0}/{1}", _photoInfos.Count, GlobalCfgArray.globalCfg.maxPhotoCount);
  141. }
  142. else
  143. {
  144. _ui.m_list.numItems = 0;
  145. _photoInfos = PoemPhotoDataManager.Instance.WsqsPhotoInfos;
  146. _sourceType = (int)PictureSourceType.WanShuiQianShan;
  147. _ui.m_listTravel.numItems = _photoInfos.Count;
  148. _ui.m_txtCount.text = string.Format("{0}/{1}", _photoInfos.Count, RoleDataManager.WanShuiQianShanMaxStorageCount);
  149. }
  150. _ui.m_btnConfirmDelete.title = string.Format("删除 {0}/{1}", _listChoose.Count, _photoInfos.Count);
  151. _ui.m_btnConfirmSave.title = string.Format("保存 {0}/{1}", _listChoose.Count, _photoInfos.Count);
  152. }
  153. private void RenderListItem(int index, GObject obj)
  154. {
  155. UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj);
  156. if (_ui.m_c2.selectedIndex != 0 && _listChoose.IndexOf(_photoInfos[index].PictureId) >= 0)
  157. {
  158. item.m_c1.SetSelectedIndex(1);
  159. }
  160. else
  161. {
  162. item.m_c1.SetSelectedIndex(0);
  163. }
  164. GLoader loaIcon = item.m_comIcon.m_loaIcon;
  165. loaIcon.visible = true;
  166. if (_photoInfos[index].Ntexture == null)
  167. {
  168. loaIcon.visible = false;
  169. }
  170. loaIcon.texture = _photoInfos[index].Ntexture;
  171. string[] timeStr = TimeUtil.FormattingTime1(_photoInfos[index].CreationTime, '/').Split(' ');
  172. item.m_txtTime.text = timeStr[0];
  173. //item.m_txtTime.visible = false;
  174. item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0;
  175. item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0;
  176. if (item.m_btnLock.target.data == null)
  177. {
  178. item.m_btnLock.target.onClick.Add(OnBtnLockClick);
  179. }
  180. item.m_btnLock.target.data = index;
  181. if (item.m_btnUp.target.data == null)
  182. {
  183. item.m_btnUp.target.onClick.Add(OnBtnUpClick);
  184. }
  185. item.m_btnUp.target.data = index;
  186. if (item.m_comIcon.target.data == null)
  187. {
  188. item.m_comIcon.target.onClick.Add(OnLoaIconClick);
  189. }
  190. item.m_comIcon.target.data = index;
  191. UI_ListPhotoItem.ProxyEnd();
  192. }
  193. private void RenderListTravelItem(int index, GObject obj)
  194. {
  195. PoemPhotoData poemPhotoData = _photoInfos[index];
  196. TravelLoactionCfg loactionCfg = TravelLoactionCfgArray.Instance.GetCfg(poemPhotoData.TravelLocationId);
  197. UI_ComPhotoPostcard item = UI_ComPhotoPostcard.Proxy(obj);
  198. item.m_c1.selectedIndex = _ui.m_c2.selectedIndex != 0 && _listChoose.IndexOf(_photoInfos[index].PictureId) >= 0 ? 1 : 0;
  199. item.m_comTravel.m_loaBg.url = ResPathUtil.GetTravelBgPath(loactionCfg.res);
  200. item.m_comTravel.m_loaRole.url = "";
  201. if (poemPhotoData.TravelSuitId > 0)
  202. {
  203. TravelSuitCfg travelSuitCfg = TravelSuitCfgArray.Instance.GetCfg(poemPhotoData.TravelSuitId);
  204. item.m_comTravel.m_loaRole.url = ResPathUtil.GetTravelRolePath(travelSuitCfg.reourcesArr[poemPhotoData.SuitResIndex]);
  205. item.m_comTravel.m_loaRole.SetXY(loactionCfg.positionsArr[poemPhotoData.PositionIndex][0], loactionCfg.positionsArr[poemPhotoData.PositionIndex][1]);
  206. }
  207. item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0;
  208. item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0;
  209. if (item.m_btnLock.target.data == null)
  210. {
  211. item.m_btnLock.target.onClick.Add(OnBtnLockClick);
  212. }
  213. item.m_btnLock.target.data = index;
  214. if (item.m_btnUp.target.data == null)
  215. {
  216. item.m_btnUp.target.onClick.Add(OnBtnUpClick);
  217. }
  218. item.m_btnUp.target.data = index;
  219. if (item.m_comTravel.target.data == null)
  220. {
  221. item.m_comTravel.target.onClick.Add(OnLoaIconClick);
  222. }
  223. item.m_comTravel.target.data = index;
  224. UI_ComPhotoPostcard.ProxyEnd();
  225. }
  226. private void OnLoaIconClick(EventContext context)
  227. {
  228. GObject obj = context.sender as GObject;
  229. int index = (int)obj.data;
  230. PoemPhotoData photoData = _photoInfos[index];
  231. if (_ui.m_c2.selectedIndex == 0)
  232. {
  233. ViewManager.Show<PoemPhotoPreView>(new object[] { index, _photoInfos, _sourceType });
  234. }
  235. else
  236. {
  237. if (_ui.m_c2.selectedIndex == 1)
  238. {
  239. if (photoData.LockingStatus)
  240. {
  241. PromptController.Instance.ShowFloatTextPrompt("锁定的照片无法删除");
  242. return;
  243. }
  244. if (photoData.ToppingStatus)
  245. {
  246. PromptController.Instance.ShowFloatTextPrompt("置顶的照片无法删除");
  247. return;
  248. }
  249. }
  250. UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj.parent);
  251. item.m_c1.selectedIndex ^= 1;
  252. if (item.m_c1.selectedIndex == 1)
  253. {
  254. _listChoose.Add(photoData.PictureId);
  255. }
  256. else
  257. {
  258. _listChoose.Remove(photoData.PictureId);
  259. }
  260. UI_ListPhotoItem.ProxyEnd();
  261. if (_ui.m_c2.selectedIndex == 1)
  262. {
  263. _ui.m_btnConfirmDelete.title = string.Format("删除({0}/{1})", _listChoose.Count, _photoInfos.Count);
  264. _ui.m_btnChooseAll.selected = (GetEnablePhotoNum(true) == _listChoose.Count);
  265. }
  266. else if (_ui.m_c2.selectedIndex == 2)
  267. {
  268. _ui.m_btnConfirmSave.title = string.Format("保存({0}/{1})", _listChoose.Count, _photoInfos.Count);
  269. _ui.m_btnChooseAll.selected = (GetEnablePhotoNum(false) == _listChoose.Count);
  270. }
  271. }
  272. }
  273. private void OnBtnConfirmDeleteClick()
  274. {
  275. if (_listChoose.Count == 0)
  276. {
  277. PromptController.Instance.ShowFloatTextPrompt("请选择要删除的照片");
  278. return;
  279. }
  280. AlertUI.Show("删除后的照片无法恢复,是否确认删除?")
  281. .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) =>
  282. {
  283. bool result = await PoemPhotoSProxy.ReqRemovedPhoto(_listChoose, _sourceType);
  284. if (result)
  285. {
  286. _listChoose.Clear();
  287. OnBtnTabChange();
  288. }
  289. });
  290. }
  291. private void OnBtnLockClick(EventContext context)
  292. {
  293. if (_ui.m_c2.selectedIndex != 0)
  294. {
  295. //PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作");
  296. return;
  297. }
  298. GObject item = context.sender as GObject;
  299. int index = (int)item.data;
  300. PoemPhotoData photoData = _photoInfos[index];
  301. if (photoData.LockingStatus == false)
  302. {
  303. AlertUI.Show("是否确认锁定此照片?", "(锁定的照片无法被删除)")
  304. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  305. {
  306. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, true, _sourceType).Coroutine();
  307. });
  308. }
  309. else
  310. {
  311. AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)")
  312. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  313. {
  314. PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, false, _sourceType).Coroutine();
  315. });
  316. }
  317. }
  318. private void OnBtnUpClick(EventContext context)
  319. {
  320. if (_ui.m_c2.selectedIndex != 0)
  321. {
  322. //PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作");
  323. return;
  324. }
  325. GObject item = context.sender as GObject;
  326. int index = (int)item.data;
  327. PoemPhotoData photoData = _photoInfos[index];
  328. if (photoData.ToppingStatus == false)
  329. {
  330. AlertUI.Show("是否确认置顶此照片?")
  331. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  332. {
  333. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, true, _sourceType).Coroutine();
  334. });
  335. }
  336. else
  337. {
  338. AlertUI.Show("是否确认取消置顶此照片?")
  339. .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) =>
  340. {
  341. PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, false, _sourceType).Coroutine();
  342. });
  343. }
  344. }
  345. private void CheckGuide(object param)
  346. {
  347. if (GuideDataManager.IsGuideFinish(ConstGuideId.POEM) <= 0)
  348. {
  349. UpdateToCheckGuide(null);
  350. }
  351. else
  352. {
  353. Timers.inst.Remove(CheckGuide);
  354. }
  355. }
  356. protected override void UpdateToCheckGuide(object param)
  357. {
  358. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  359. GuideController.TryGuide(null, ConstGuideId.POEM, 1, "在“拍照”中保存的图片都会保存到这里。");
  360. GuideController.TryGuide(_ui.m_btnback, ConstGuideId.POEM, 2, "");
  361. GuideController.TryCompleteGuideIndex(ConstGuideId.POEM, 2);
  362. GuideController.TryCompleteGuide(ConstGuideId.POEM, 2);
  363. }
  364. /// <summary>
  365. /// 初始化分类菜单文本,点击和未点击是两种样式,需要统一文字
  366. /// </summary>
  367. private void InitTypeList()
  368. {
  369. for (int i = 0; i < _ui.m_typeList.numChildren; i++)
  370. {
  371. UI_Button6 button6 = UI_Button6.Proxy(_ui.m_typeList.GetChildAt(i));
  372. button6.m_title1.text = button6.target.title;
  373. UI_Button6.ProxyEnd();
  374. }
  375. }
  376. /// <summary>
  377. /// 获取当前相册可操作的相片数量
  378. /// </summary>
  379. /// <param name="delete">为true时跳过锁住的和置顶的相片</param>
  380. /// <returns></returns>
  381. private int GetEnablePhotoNum(bool delete)
  382. {
  383. int num = 0;
  384. for (int i = 0; i < _photoInfos.Count; i++)
  385. {
  386. PoemPhotoData photoData = _photoInfos[i];
  387. if (delete && (photoData.LockingStatus || photoData.ToppingStatus))
  388. {
  389. continue;
  390. }
  391. ++num;
  392. }
  393. return num;
  394. }
  395. private void OnClickBtnChooseAll()
  396. {
  397. _listChoose.Clear();
  398. GList list = ((_ui.m_c1.selectedIndex == 0) ? _ui.m_list : _ui.m_listTravel);
  399. for (int i = 0; i < _photoInfos.Count; i++)
  400. {
  401. PoemPhotoData photoData = _photoInfos[i];
  402. // 删除全选时不选择 置顶或者锁住 的照片
  403. if (_ui.m_c2.selectedIndex == 1 && (photoData.LockingStatus || photoData.ToppingStatus))
  404. {
  405. continue;
  406. }
  407. if (_ui.m_btnChooseAll.selected)
  408. {
  409. _listChoose.Add(photoData.PictureId);
  410. }
  411. }
  412. list.numItems = _photoInfos.Count;
  413. if (_ui.m_c2.selectedIndex == 1)
  414. {
  415. _ui.m_btnConfirmDelete.title = string.Format("删除({0}/{1})", _listChoose.Count, _photoInfos.Count);
  416. }
  417. else if (_ui.m_c2.selectedIndex == 2)
  418. {
  419. _ui.m_btnConfirmSave.title = string.Format("保存({0}/{1})", _listChoose.Count, _photoInfos.Count);
  420. }
  421. }
  422. private void OnClickConfirmSave()
  423. {
  424. if (_listChoose.Count == 0)
  425. {
  426. PromptController.Instance.ShowFloatTextPrompt("请选择要保存的照片");
  427. return;
  428. }
  429. #if UNITY_EDITOR
  430. OpenSaveView();
  431. #else
  432. CheckSaveLocal();
  433. #endif
  434. }
  435. /// <summary>
  436. /// 检查保存相片相应权限
  437. /// </summary>
  438. private async void CheckSaveLocal()
  439. {
  440. string permissionName = "存储";
  441. #if UNITY_IOS
  442. permissionName = "相册";
  443. #endif
  444. NativeGallery.Permission permission = NativeGallery.CheckPermission(NativeGallery.PermissionType.Write, NativeGallery.MediaType.Image);
  445. Debug.Log("Permission result: " + permission);
  446. if (permission.Equals(NativeGallery.Permission.Denied))
  447. {
  448. string tips = $"保存至本地需要使用{permissionName}权限,您已经禁止!请前往手机系统设置开启应用的{permissionName}权限。";
  449. if (NativeGallery.CanOpenSettings())
  450. {
  451. AlertSystem.Show(tips)
  452. .SetLeftButton(true, "前往", (data) => { NativeGallery.OpenSettings(); })
  453. .SetRightButton(true, "拒绝");
  454. }
  455. else
  456. {
  457. AlertSystem.Show(tips)
  458. .SetLeftButton(true, "知道了");
  459. }
  460. }
  461. else
  462. {
  463. if (permission.Equals(NativeGallery.Permission.ShouldAsk))
  464. {
  465. string tips = $"保存至本地需要使用{permissionName}权限,请同意!";
  466. PromptController.Instance.ShowFloatTextPrompt(tips);
  467. permission = await NativeGallery.RequestPermissionAsync(NativeGallery.PermissionType.Write, NativeGallery.MediaType.Image);
  468. //Debug.Log("Permission result: " + permission);
  469. if (!permission.Equals(NativeGallery.Permission.Granted))
  470. {
  471. PromptController.Instance.ShowFloatTextPrompt($"由于被禁止{permissionName}权限,保存失败!");
  472. return;
  473. }
  474. }
  475. //Debug.Log("Permission result: " + permission);
  476. }
  477. OpenSaveView();
  478. }
  479. private void OpenSaveView()
  480. {
  481. SavePhotoList savePhoto = new SavePhotoList();
  482. savePhoto.pageIndex = _ui.m_c1.selectedIndex;
  483. savePhoto.photoInfos = _photoInfos;
  484. savePhoto.listChoose = _listChoose;
  485. ViewManager.Show<PoemPhotoSaveView>(savePhoto);
  486. }
  487. }
  488. }