123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- using System.Collections.Generic;
- using ET;
- using FairyGUI;
- using UI.DressUp;
- using UnityEngine;
- using UnityEngine.Android;
- namespace GFGGame
- {
- public class PhotographSaveView : BaseView
- {
- private UI_PhotographSaveUI _ui;
- private Texture2D tex;
- private byte[] bytes;
- protected override void OnInit()
- {
- base.OnInit();
- packageName = UI_PhotographUI.PACKAGE_NAME;
- _ui = UI_PhotographSaveUI.Create();
- viewCom = _ui.target;
- isfullScreen = true;
- _ui.m_btnClose.onClick.Add(this.Hide);
- _ui.m_btnSave.onClick.Add(this.OnClickBtnSave);
- _ui.m_btnSavePhoto.onClick.Add(this.OnClickBtnSavePhoto);
- _ui.m_share.onClick.Add(this.BtnClickShare);
- }
- protected override void OnShown()
- {
- base.OnShown();
- tex = this.viewData as Texture2D;
- bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
- ShareDataManager.Instance.imageBytes = bytes;
- _ui.m_imgRes.texture = new NTexture(tex);
- float width = _ui.m_imgBorder.width;
- float height = width * tex.height / tex.width;
- _ui.m_imgRes.SetSize(width, height);
- _ui.m_imgBorder.SetSize(width, height + 12);
- _ui.m_share.visible = false;
- Timers.inst.AddUpdate(CheckGuide);
- }
- protected override void OnHide()
- {
- base.OnHide();
- _ui.m_btnSave.selected = false;
- _ui.m_btnSave.enabled = true;
- _ui.m_btnSavePhoto.selected = false;
- _ui.m_btnSavePhoto.enabled = true;
- Timers.inst.Remove(CheckGuide);
- }
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- private void OnClickBtnSave()
- {
- #if UNITY_EDITOR
- PromptController.Instance.ShowFloatTextPrompt("此功能只能在移动端使用!");
- #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;
- }
- }
- string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
- permission = NativeGallery.SaveImageToGallery(bytes, "Wanshijing", fileName, (success, path) =>
- {
- if(success)
- {
- PromptController.Instance.ShowFloatTextPrompt("已保存至本地!");
- _ui.m_btnSave.enabled = false;
- }
- else
- {
- PromptController.Instance.ShowFloatTextPrompt("保存失败!");
- }
- });
- //Debug.Log("Permission result: " + permission);
- }
- }
- //private void OnClickBtnSaveBackup()
- //{
- // //检查用户是否已授予对需要授权的设备资源或信息的访问权。
- // if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
- // {
- // if (LocalCache.GetBool(GameConst.WRITE_EXTERNAL_STORAGE_FORBIDDEN, false))
- // {
- // AlertSystem.Show("保存至本地需要使用存储权限,您已经禁止!请前往手机系统设置开启应用存储权限。")
- // .SetLeftButton(true, "知道了");
- // return;
- // }
- // PromptController.Instance.ShowFloatTextPrompt("保存至本地需要使用存储权限,请同意!");
- // //请求用户授权访问需要授权的设备资源或信息.
- // PermissionCallbacks permissionCallbacks = new PermissionCallbacks();
- // permissionCallbacks.PermissionGranted += (string a) =>
- // {
- // TrySavePicturoToLocal();
- // };
- // permissionCallbacks.PermissionDenied += (string a) =>
- // {
- // PromptController.Instance.ShowFloatTextPrompt("由于被禁止存储权限,保存失败!");
- // };
- // permissionCallbacks.PermissionDeniedAndDontAskAgain += (string a) =>
- // {
- // LocalCache.SetBool(GameConst.WRITE_EXTERNAL_STORAGE_FORBIDDEN, true);
- // PromptController.Instance.ShowFloatTextPrompt("由于被禁止存储权限,保存失败!");
- // };
- // Permission.RequestUserPermission(Permission.ExternalStorageWrite, permissionCallbacks);
- // }
- // else
- // {
- // LocalCache.SetBool(GameConst.WRITE_EXTERNAL_STORAGE_FORBIDDEN, false);
- // TrySavePicturoToLocal();
- // }
- //}
- //private void TrySavePicturoToLocal()
- //{
- // if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
- // {
- // string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
- // PhotographUtil.Instance.SavePicturoToLocal(bytes, fileName);
- // _ui.m_btnSave.enabled = false;
- // }
- //}
- private async void OnClickBtnSavePhoto()
- {
- if (GuideDataManager.currentGuideId > 0) return;//引导时不保存
- if (PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxPhotoCount)
- {
- PromptController.Instance.ShowFloatTextPrompt("照片数量已达上限");
- return;
- }
- object[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl();
- if (rsp == null) return;
- bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes);
- if (!pushResult) {
- ViewManager.Hide<ModalStatusView>();
- return;
- }
- long addResult = await PoemPhotoSProxy.ReqAddTophoto((long)rsp[1]);
- if (addResult > 0)
- {
- List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].PictureId == addResult)
- {
- list[i].Bytes = bytes;
- list[i].Ntexture = new NTexture(tex);
- break;
- }
- }
- }
- _ui.m_btnSavePhoto.enabled = false;
- }
- private void BtnClickShare()
- {
- ShareDataManager.Instance.CaptureCameraToImage(true,false);
- }
- private void CheckGuide(object param)
- {
- if (GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0)
- {
- UpdateToCheckGuide(null);
- }
- else
- {
- Timers.inst.Remove(CheckGuide);
- }
- }
- protected override void UpdateToCheckGuide(object param)
- {
- if (!ViewManager.CheckIsTopView(this.viewCom)) return;
- GuideController.TryGuide(_ui.m_btnSavePhoto, ConstGuideId.FREEDOM_DRESS, 9, "下次点击这里可以保存至相册哦!");
- GuideController.TryGuide(_ui.m_btnClose, ConstGuideId.FREEDOM_DRESS, 10, "");
- GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 10);
- }
- protected override void TryCompleteGuide()
- {
- base.TryCompleteGuide();
- // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FREEDOM_DRESS);
- GuideController.TryCompleteGuideIndex(ConstGuideId.FREEDOM_DRESS, 10);
- GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 10);
- }
- }
- }
|