using System.Collections.Generic; using ET; using FairyGUI; using UI.Poem; using UnityEngine; namespace GFGGame { public struct SavePhotoList { public int pageIndex; public List photoInfos; public List listChoose; } public class PoemPhotoView : BaseWindow { private UI_PoemPhotoUI _ui; private List _listChoose = new List(); private List _photoInfos; private int _sourceType = 0; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_PoemPhotoUI.PACKAGE_NAME; _ui = UI_PoemPhotoUI.Create(); this.viewCom = _ui.target; isfullScreen = true; isReturnView = true; _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg"); _ui.m_list.SetVirtual(); _ui.m_list.itemRenderer = RenderListItem; _ui.m_listTravel.SetVirtual(); _ui.m_listTravel.itemRenderer = RenderListTravelItem; _ui.m_listCompetion.itemRenderer = RenderMatchingListItem; _ui.m_btnRule.onClick.Add(RuleController.ShowRuleView); _ui.m_btnRule.data = 300018; _ui.m_btnback.onClick.Add(OnBtnBackClick); _ui.m_btnDelete.onClick.Add(OnBtnDeleteClick); _ui.m_btnSave.onClick.Add(OnBtnSaveClick); _ui.m_btnConfirmDelete.onClick.Add(OnBtnConfirmDeleteClick); _ui.m_c1.onChanged.Add(OnBtnTabChange); _ui.m_btnChooseAll.onClick.Add(OnClickBtnChooseAll); _ui.m_btnConfirmSave.onClick.Add(OnClickConfirmSave); InitTypeList(); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange); } protected override void OnShown() { base.OnShown(); if (this.viewData != null) { _ui.m_c1.selectedIndex = (int)this.viewData; } //_ui.m_c1.selectedIndex = (this.viewData == null) ? (int)PictureSourceType.PersonalAlbum : (int)this.viewData; OnBtnTabChange(); // UpdateView(); Timers.inst.AddUpdate(CheckGuide); } protected override void OnHide() { base.OnHide(); _ui.m_c2.selectedIndex = 0; _listChoose.Clear(); Timers.inst.Remove(CheckGuide); } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.POEM_PHOTO_INFOS_CHANGE, OnBtnTabChange); } private void OnBtnBackClick() { if (_ui.m_c2.selectedIndex == 1) { _ui.m_c2.selectedIndex = 0; } else { ViewManager.GoBackFrom(typeof(PoemPhotoView).FullName); if (_ui.m_list.numItems > 0) _ui.m_list.ScrollToView(0); _ui.m_c1.selectedIndex = 0; } _ui.m_c2.selectedIndex = 0; } private void OnBtnDeleteClick() { if (_ui.m_c1.selectedIndex == 0 && GetEnablePhotoNum(true) == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无照片可删除"); return; } if (_ui.m_c1.selectedIndex == 1 && GetEnablePhotoNum(true) == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无明信片可删除"); return; } if (_ui.m_c1.selectedIndex == 2 && GetEnablePhotoNum(true) == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无图片可删除"); return; } _ui.m_c2.selectedIndex = 1; _ui.m_btnChooseAll.selected = false; } private void OnBtnSaveClick() { if (_ui.m_c1.selectedIndex == 0 && _photoInfos.Count == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无照片可保存"); return; } if (_ui.m_c1.selectedIndex == 1 && _photoInfos.Count == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无明信片可保存"); return; } if (_ui.m_c1.selectedIndex == 2 && _photoInfos.Count == 0) { PromptController.Instance.ShowFloatTextPrompt("暂无图片可保存"); return; } _ui.m_c2.selectedIndex = 2; _ui.m_btnChooseAll.selected = false; } private void OnBtnTabChange() { _ui.m_c2.selectedIndex = 0; _listChoose.Clear(); UpdateView(); } private void UpdateView() { if (_ui.m_c1.selectedIndex == 0) { _ui.m_btnDelete.visible = true; _ui.m_listTravel.numItems = 0; _ui.m_descText.visible = false; _photoInfos = PoemPhotoDataManager.Instance.PersonalPhotoInfos; _sourceType = (int)PictureSourceType.PersonalAlbum; _ui.m_list.numItems = _photoInfos.Count; _ui.m_txtCount.text = string.Format("{0}/{1}", _photoInfos.Count, GlobalCfgArray.globalCfg.maxPhotoCount); } else if(_ui.m_c1.selectedIndex == 1) { _ui.m_btnDelete.visible = true; _ui.m_list.numItems = 0; _ui.m_descText.visible = false; _photoInfos = PoemPhotoDataManager.Instance.WsqsPhotoInfos; _sourceType = (int)PictureSourceType.WanShuiQianShan; _ui.m_listTravel.numItems = _photoInfos.Count; _ui.m_txtCount.text = string.Format("{0}/{1}", _photoInfos.Count, RoleDataManager.WanShuiQianShanMaxStorageCount); } else if(_ui.m_c1.selectedIndex == 2) { _ui.m_list.numItems = 0; _ui.m_listTravel.numItems = 0; _photoInfos = MatchingCompetitionDataManager.Instance.MatchingPhotoInfos; _sourceType = 2; _ui.m_listCompetion.numItems = _photoInfos.Count; if (_photoInfos.Count == 0) { _ui.m_descText.visible = true; } else { _ui.m_descText.visible = false; } _ui.m_txtCount.text = ""; _ui.m_btnDelete.visible = false; } _ui.m_btnConfirmDelete.title = string.Format("删除 {0}/{1}", _listChoose.Count, _photoInfos.Count); _ui.m_btnConfirmSave.title = string.Format("保存 {0}/{1}", _listChoose.Count, _photoInfos.Count); } private void RenderListItem(int index, GObject obj) { UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj); if (_ui.m_c2.selectedIndex != 0 && _listChoose.IndexOf(_photoInfos[index].PictureId) >= 0) { item.m_c1.SetSelectedIndex(1); } else { item.m_c1.SetSelectedIndex(0); } GLoader loaIcon = item.m_comIcon.m_loaIcon; loaIcon.visible = true; if (_photoInfos[index].Ntexture == null) { loaIcon.visible = false; } loaIcon.texture = _photoInfos[index].Ntexture; string[] timeStr = TimeUtil.FormattingTime1(_photoInfos[index].CreationTime, '/').Split(' '); item.m_txtTime.text = timeStr[0]; //item.m_txtTime.visible = false; item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0; item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0; if (item.m_btnLock.target.data == null) { item.m_btnLock.target.onClick.Add(OnBtnLockClick); } item.m_btnLock.target.data = index; if (item.m_btnUp.target.data == null) { item.m_btnUp.target.onClick.Add(OnBtnUpClick); } item.m_btnUp.target.data = index; if (item.m_comIcon.target.data == null) { item.m_comIcon.target.onClick.Add(OnLoaIconClick); } item.m_comIcon.target.data = index; UI_ListPhotoItem.ProxyEnd(); } private void RenderListTravelItem(int index, GObject obj) { PoemPhotoData poemPhotoData = _photoInfos[index]; TravelLoactionCfg loactionCfg = TravelLoactionCfgArray.Instance.GetCfg(poemPhotoData.TravelLocationId); UI_ComPhotoPostcard item = UI_ComPhotoPostcard.Proxy(obj); item.m_c1.selectedIndex = _ui.m_c2.selectedIndex != 0 && _listChoose.IndexOf(_photoInfos[index].PictureId) >= 0 ? 1 : 0; item.m_comTravel.m_loaBg.url = ResPathUtil.GetTravelBgPath(loactionCfg.res); item.m_comTravel.m_loaRole.url = ""; if (poemPhotoData.TravelSuitId > 0) { TravelSuitCfg travelSuitCfg = TravelSuitCfgArray.Instance.GetCfg(poemPhotoData.TravelSuitId); item.m_comTravel.m_loaRole.url = ResPathUtil.GetTravelRolePath(travelSuitCfg.reourcesArr[poemPhotoData.SuitResIndex]); item.m_comTravel.m_loaRole.SetXY(loactionCfg.positionsArr[poemPhotoData.PositionIndex][0], loactionCfg.positionsArr[poemPhotoData.PositionIndex][1]); } item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0; item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0; if (item.m_btnLock.target.data == null) { item.m_btnLock.target.onClick.Add(OnBtnLockClick); } item.m_btnLock.target.data = index; if (item.m_btnUp.target.data == null) { item.m_btnUp.target.onClick.Add(OnBtnUpClick); } item.m_btnUp.target.data = index; if (item.m_comTravel.target.data == null) { item.m_comTravel.target.onClick.Add(OnLoaIconClick); } item.m_comTravel.target.data = index; UI_ComPhotoPostcard.ProxyEnd(); } private void RenderMatchingListItem(int index, GObject obj) { UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj); if (_ui.m_c2.selectedIndex != 0 && _listChoose.IndexOf(_photoInfos[index].PictureId) >= 0) { item.m_c1.SetSelectedIndex(1); } else { item.m_c1.SetSelectedIndex(0); } GLoader loaIcon = item.m_comIcon.m_loaIcon; loaIcon.visible = true; if (_photoInfos[index].Ntexture == null) { loaIcon.visible = false; } loaIcon.texture = _photoInfos[index].Ntexture; string[] timeStr = TimeUtil.FormattingTime1(_photoInfos[index].CreationTime, '/').Split(' '); item.m_txtTime.text = timeStr[0]; //item.m_txtTime.visible = false; item.m_btnLock.m_c1.selectedIndex = _photoInfos[index].LockingStatus ? 1 : 0; item.m_btnUp.m_c1.selectedIndex = _photoInfos[index].ToppingStatus ? 1 : 0; if (item.m_btnLock.target.data == null) { item.m_btnLock.target.onClick.Add(OnBtnMatchingLockClick); } item.m_btnLock.target.data = index; if (item.m_btnUp.target.data == null) { item.m_btnUp.target.onClick.Add(OnBtnMatchingUpClick); } item.m_btnUp.target.data = index; if (item.m_comIcon.target.data == null) { item.m_comIcon.target.onClick.Add(OnMatchingLoaIconClick); } item.m_comIcon.target.data = index; UI_ListPhotoItem.ProxyEnd(); } private void OnLoaIconClick(EventContext context) { GObject obj = context.sender as GObject; int index = (int)obj.data; PoemPhotoData photoData = _photoInfos[index]; if (_ui.m_c2.selectedIndex == 0) { ViewManager.Show(new object[] { index, _photoInfos, _sourceType }); } else { if (_ui.m_c2.selectedIndex == 1) { if (photoData.LockingStatus) { PromptController.Instance.ShowFloatTextPrompt("锁定的照片无法删除"); return; } if (photoData.ToppingStatus) { PromptController.Instance.ShowFloatTextPrompt("置顶的照片无法删除"); return; } } UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj.parent); item.m_c1.selectedIndex ^= 1; if (item.m_c1.selectedIndex == 1) { _listChoose.Add(photoData.PictureId); } else { _listChoose.Remove(photoData.PictureId); } UI_ListPhotoItem.ProxyEnd(); if (_ui.m_c2.selectedIndex == 1) { _ui.m_btnConfirmDelete.title = string.Format("删除({0}/{1})", _listChoose.Count, _photoInfos.Count); _ui.m_btnChooseAll.selected = (GetEnablePhotoNum(true) == _listChoose.Count); } else if (_ui.m_c2.selectedIndex == 2) { _ui.m_btnConfirmSave.title = string.Format("保存({0}/{1})", _listChoose.Count, _photoInfos.Count); _ui.m_btnChooseAll.selected = (GetEnablePhotoNum(false) == _listChoose.Count); } } } private void OnMatchingLoaIconClick(EventContext context) { GObject obj = context.sender as GObject; int index = (int)obj.data; PoemPhotoData photoData = _photoInfos[index]; if (_ui.m_c2.selectedIndex == 0) { ViewManager.Show(new object[] { index, _photoInfos, _sourceType }); } else { if (_ui.m_c2.selectedIndex == 1) { if (photoData.LockingStatus) { PromptController.Instance.ShowFloatTextPrompt("锁定的照片无法删除"); return; } if (photoData.ToppingStatus) { PromptController.Instance.ShowFloatTextPrompt("置顶的照片无法删除"); return; } } UI_ListPhotoItem item = UI_ListPhotoItem.Proxy(obj.parent); item.m_c1.selectedIndex ^= 1; if (item.m_c1.selectedIndex == 1) { _listChoose.Add(photoData.PictureId); } else { _listChoose.Remove(photoData.PictureId); } UI_ListPhotoItem.ProxyEnd(); if (_ui.m_c2.selectedIndex == 1) { _ui.m_btnConfirmDelete.title = string.Format("删除({0}/{1})", _listChoose.Count, _photoInfos.Count); _ui.m_btnChooseAll.selected = (GetEnablePhotoNum(true) == _listChoose.Count); } else if (_ui.m_c2.selectedIndex == 2) { _ui.m_btnConfirmSave.title = string.Format("保存({0}/{1})", _listChoose.Count, _photoInfos.Count); _ui.m_btnChooseAll.selected = (GetEnablePhotoNum(false) == _listChoose.Count); } } } private void OnBtnConfirmDeleteClick() { if (_listChoose.Count == 0) { PromptController.Instance.ShowFloatTextPrompt("请选择要删除的照片"); return; } AlertUI.Show("删除后的照片无法恢复,是否确认删除?") .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) => { if (_ui.m_c2.selectedIndex != 2) { bool result = await PoemPhotoSProxy.ReqRemovedPhoto(_listChoose, _sourceType); if (result) { _listChoose.Clear(); OnBtnTabChange(); } } else { bool result = await MatchingCompetitionSproxy.ReqRemovedPhoto(_listChoose, _sourceType); if (result) { _listChoose.Clear(); OnBtnTabChange(); } } }); } private void OnBtnLockClick(EventContext context) { if (_ui.m_c2.selectedIndex != 0) { //PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作"); return; } GObject item = context.sender as GObject; int index = (int)item.data; PoemPhotoData photoData = _photoInfos[index]; if (photoData.LockingStatus == false) { AlertUI.Show("是否确认锁定此照片?", "(锁定的照片无法被删除)") .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) => { PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, true, _sourceType).Coroutine(); }); } else { AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)") .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) => { PoemPhotoSProxy.ReqChangeLockingState(photoData.PictureId, false, _sourceType).Coroutine(); }); } } private void OnBtnMatchingLockClick(EventContext context) { if (_ui.m_c2.selectedIndex != 0) { //PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作"); return; } GObject item = context.sender as GObject; int index = (int)item.data; PoemPhotoData photoData = _photoInfos[index]; if (photoData.LockingStatus == false) { AlertUI.Show("是否确认锁定此照片?", "(锁定的照片无法被删除)") .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) => { MatchingCompetitionSproxy.ReqChangeLockingState(photoData.PictureId, true, _sourceType).Coroutine(); }); } else { AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)") .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) => { MatchingCompetitionSproxy.ReqChangeLockingState(photoData.PictureId, false, _sourceType).Coroutine(); }); } } private void OnBtnUpClick(EventContext context) { if (_ui.m_c2.selectedIndex != 0) { //PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作"); return; } GObject item = context.sender as GObject; int index = (int)item.data; PoemPhotoData photoData = _photoInfos[index]; if (photoData.ToppingStatus == false) { AlertUI.Show("是否确认置顶此照片?") .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) => { PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, true, _sourceType).Coroutine(); }); } else { AlertUI.Show("是否确认取消置顶此照片?") .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) => { PoemPhotoSProxy.ReqChangeToppingState(photoData.PictureId, false, _sourceType).Coroutine(); }); } } private void OnBtnMatchingUpClick(EventContext context) { if (_ui.m_c2.selectedIndex != 0) { //PromptController.Instance.ShowFloatTextPrompt("删除状态无法操作"); return; } GObject item = context.sender as GObject; int index = (int)item.data; PoemPhotoData photoData = _photoInfos[index]; if (photoData.ToppingStatus == false) { AlertUI.Show("是否确认置顶此照片?") .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) => { MatchingCompetitionSproxy.ReqChangeToppingState(photoData.PictureId, true, _sourceType).Coroutine(); }); } else { AlertUI.Show("是否确认取消置顶此照片?") .SetLeftButton(true, "否").SetRightButton(true, "是", (object data) => { MatchingCompetitionSproxy.ReqChangeToppingState(photoData.PictureId, false, _sourceType).Coroutine(); }); } } private void CheckGuide(object param) { if (GuideDataManager.IsGuideFinish(ConstGuideId.POEM) <= 0) { UpdateToCheckGuide(null); } else { Timers.inst.Remove(CheckGuide); } } protected override void UpdateToCheckGuide(object param) { if (!ViewManager.CheckIsTopView(this.viewCom)) return; GuideController.TryGuide(null, ConstGuideId.POEM, 1, "在“拍照”中保存的图片都会保存到这里。"); GuideController.TryGuide(_ui.m_btnback, ConstGuideId.POEM, 2, ""); GuideController.TryCompleteGuideIndex(ConstGuideId.POEM, 2); GuideController.TryCompleteGuide(ConstGuideId.POEM, 2); } /// /// 初始化分类菜单文本,点击和未点击是两种样式,需要统一文字 /// private void InitTypeList() { for (int i = 0; i < _ui.m_typeList.numChildren; i++) { UI_Button6 button6 = UI_Button6.Proxy(_ui.m_typeList.GetChildAt(i)); button6.m_title1.text = button6.target.title; UI_Button6.ProxyEnd(); } } /// /// 获取当前相册可操作的相片数量 /// /// 为true时跳过锁住的和置顶的相片 /// private int GetEnablePhotoNum(bool delete) { int num = 0; for (int i = 0; i < _photoInfos.Count; i++) { PoemPhotoData photoData = _photoInfos[i]; if (delete && (photoData.LockingStatus || photoData.ToppingStatus)) { continue; } ++num; } return num; } private void OnClickBtnChooseAll() { _listChoose.Clear(); GList list = ((_ui.m_c1.selectedIndex == 0) ? _ui.m_list : _ui.m_listTravel); for (int i = 0; i < _photoInfos.Count; i++) { PoemPhotoData photoData = _photoInfos[i]; // 删除全选时不选择 置顶或者锁住 的照片 if (_ui.m_c2.selectedIndex == 1 && (photoData.LockingStatus || photoData.ToppingStatus)) { continue; } if (_ui.m_btnChooseAll.selected) { _listChoose.Add(photoData.PictureId); } } list.numItems = _photoInfos.Count; if (_ui.m_c2.selectedIndex == 1) { _ui.m_btnConfirmDelete.title = string.Format("删除({0}/{1})", _listChoose.Count, _photoInfos.Count); } else if (_ui.m_c2.selectedIndex == 2) { _ui.m_btnConfirmSave.title = string.Format("保存({0}/{1})", _listChoose.Count, _photoInfos.Count); } } private void OnClickConfirmSave() { if (_listChoose.Count == 0) { PromptController.Instance.ShowFloatTextPrompt("请选择要保存的照片"); return; } #if UNITY_EDITOR OpenSaveView(); #else CheckSaveLocal(); #endif } /// /// 检查保存相片相应权限 /// private async void CheckSaveLocal() { string permissionName = "存储"; #if UNITY_IOS permissionName = "相册"; #endif NativeGallery.Permission permission = NativeGallery.CheckPermission(NativeGallery.PermissionType.Write, NativeGallery.MediaType.Image); Debug.Log("Permission result: " + permission); if (permission.Equals(NativeGallery.Permission.Denied)) { string tips = $"保存至本地需要使用{permissionName}权限,您已经禁止!请前往手机系统设置开启应用的{permissionName}权限。"; if (NativeGallery.CanOpenSettings()) { AlertSystem.Show(tips) .SetLeftButton(true, "前往", (data) => { NativeGallery.OpenSettings(); }) .SetRightButton(true, "拒绝"); } else { AlertSystem.Show(tips) .SetLeftButton(true, "知道了"); } } else { if (permission.Equals(NativeGallery.Permission.ShouldAsk)) { string tips = $"保存至本地需要使用{permissionName}权限,请同意!"; PromptController.Instance.ShowFloatTextPrompt(tips); permission = await NativeGallery.RequestPermissionAsync(NativeGallery.PermissionType.Write, NativeGallery.MediaType.Image); //Debug.Log("Permission result: " + permission); if (!permission.Equals(NativeGallery.Permission.Granted)) { PromptController.Instance.ShowFloatTextPrompt($"由于被禁止{permissionName}权限,保存失败!"); return; } } //Debug.Log("Permission result: " + permission); } OpenSaveView(); } private void OpenSaveView() { SavePhotoList savePhoto = new SavePhotoList(); savePhoto.pageIndex = _ui.m_c1.selectedIndex; savePhoto.photoInfos = _photoInfos; savePhoto.listChoose = _listChoose; ViewManager.Show(savePhoto); } } }