PoemPhotoView.cs 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550
  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(_ui.m_btnback, ConstGuideId.POEM, 2, "");
  360. }
  361. /// <summary>
  362. /// 初始化分类菜单文本,点击和未点击是两种样式,需要统一文字
  363. /// </summary>
  364. private void InitTypeList()
  365. {
  366. for (int i = 0; i < _ui.m_typeList.numChildren; i++)
  367. {
  368. UI_Button6 button6 = UI_Button6.Proxy(_ui.m_typeList.GetChildAt(i));
  369. button6.m_title1.text = button6.target.title;
  370. UI_Button6.ProxyEnd();
  371. }
  372. }
  373. /// <summary>
  374. /// 获取当前相册可操作的相片数量
  375. /// </summary>
  376. /// <param name="delete">为true时跳过锁住的和置顶的相片</param>
  377. /// <returns></returns>
  378. private int GetEnablePhotoNum(bool delete)
  379. {
  380. int num = 0;
  381. for (int i = 0; i < _photoInfos.Count; i++)
  382. {
  383. PoemPhotoData photoData = _photoInfos[i];
  384. if (delete && (photoData.LockingStatus || photoData.ToppingStatus))
  385. {
  386. continue;
  387. }
  388. ++num;
  389. }
  390. return num;
  391. }
  392. private void OnClickBtnChooseAll()
  393. {
  394. _listChoose.Clear();
  395. GList list = ((_ui.m_c1.selectedIndex == 0) ? _ui.m_list : _ui.m_listTravel);
  396. for (int i = 0; i < _photoInfos.Count; i++)
  397. {
  398. PoemPhotoData photoData = _photoInfos[i];
  399. // 删除全选时不选择 置顶或者锁住 的照片
  400. if (_ui.m_c2.selectedIndex == 1 && (photoData.LockingStatus || photoData.ToppingStatus))
  401. {
  402. continue;
  403. }
  404. if (_ui.m_btnChooseAll.selected)
  405. {
  406. _listChoose.Add(photoData.PictureId);
  407. }
  408. }
  409. list.numItems = _photoInfos.Count;
  410. if (_ui.m_c2.selectedIndex == 1)
  411. {
  412. _ui.m_btnConfirmDelete.title = string.Format("删除({0}/{1})", _listChoose.Count, _photoInfos.Count);
  413. }
  414. else if (_ui.m_c2.selectedIndex == 2)
  415. {
  416. _ui.m_btnConfirmSave.title = string.Format("保存({0}/{1})", _listChoose.Count, _photoInfos.Count);
  417. }
  418. }
  419. private void OnClickConfirmSave()
  420. {
  421. if (_listChoose.Count == 0)
  422. {
  423. PromptController.Instance.ShowFloatTextPrompt("请选择要保存的照片");
  424. return;
  425. }
  426. #if UNITY_EDITOR
  427. OpenSaveView();
  428. #else
  429. CheckSaveLocal();
  430. #endif
  431. }
  432. /// <summary>
  433. /// 检查保存相片相应权限
  434. /// </summary>
  435. private async void CheckSaveLocal()
  436. {
  437. string permissionName = "存储";
  438. #if UNITY_IOS
  439. permissionName = "相册";
  440. #endif
  441. NativeGallery.Permission permission = NativeGallery.CheckPermission(NativeGallery.PermissionType.Write, NativeGallery.MediaType.Image);
  442. Debug.Log("Permission result: " + permission);
  443. if (permission.Equals(NativeGallery.Permission.Denied))
  444. {
  445. string tips = $"保存至本地需要使用{permissionName}权限,您已经禁止!请前往手机系统设置开启应用的{permissionName}权限。";
  446. if (NativeGallery.CanOpenSettings())
  447. {
  448. AlertSystem.Show(tips)
  449. .SetLeftButton(true, "前往", (data) => { NativeGallery.OpenSettings(); })
  450. .SetRightButton(true, "拒绝");
  451. }
  452. else
  453. {
  454. AlertSystem.Show(tips)
  455. .SetLeftButton(true, "知道了");
  456. }
  457. }
  458. else
  459. {
  460. if (permission.Equals(NativeGallery.Permission.ShouldAsk))
  461. {
  462. string tips = $"保存至本地需要使用{permissionName}权限,请同意!";
  463. PromptController.Instance.ShowFloatTextPrompt(tips);
  464. permission = await NativeGallery.RequestPermissionAsync(NativeGallery.PermissionType.Write, NativeGallery.MediaType.Image);
  465. //Debug.Log("Permission result: " + permission);
  466. if (!permission.Equals(NativeGallery.Permission.Granted))
  467. {
  468. PromptController.Instance.ShowFloatTextPrompt($"由于被禁止{permissionName}权限,保存失败!");
  469. return;
  470. }
  471. }
  472. //Debug.Log("Permission result: " + permission);
  473. }
  474. OpenSaveView();
  475. }
  476. private void OpenSaveView()
  477. {
  478. SavePhotoList savePhoto = new SavePhotoList();
  479. savePhoto.pageIndex = _ui.m_c1.selectedIndex;
  480. savePhoto.photoInfos = _photoInfos;
  481. savePhoto.listChoose = _listChoose;
  482. ViewManager.Show<PoemPhotoSaveView>(savePhoto);
  483. }
  484. }
  485. }