PhotographSaveView.cs 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Threading.Tasks;
  6. using ET;
  7. using FairyGUI;
  8. using UI.DressUp;
  9. using UnityEngine;
  10. using UnityEngine.Android;
  11. namespace GFGGame
  12. {
  13. public class PhotographSaveView : BaseView
  14. {
  15. private UI_PhotographSaveUI _ui;
  16. private Texture2D tex;
  17. private byte[] bytes;
  18. protected override void OnInit()
  19. {
  20. base.OnInit();
  21. packageName = UI_PhotographUI.PACKAGE_NAME;
  22. _ui = UI_PhotographSaveUI.Create();
  23. viewCom = _ui.target;
  24. isfullScreen = true;
  25. _ui.m_btnClose.onClick.Add(this.Hide);
  26. _ui.m_btnSave.onClick.Add(this.OnClickBtnSave);
  27. _ui.m_btnSavePhoto.onClick.Add(this.OnClickBtnSavePhoto);
  28. }
  29. protected override void OnShown()
  30. {
  31. base.OnShown();
  32. tex = this.viewData as Texture2D;
  33. bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  34. _ui.m_imgRes.texture = new NTexture(tex);
  35. float width = _ui.m_imgBorder.width;
  36. float height = width * tex.height / tex.width;
  37. _ui.m_imgRes.SetSize(width, height);
  38. _ui.m_imgBorder.SetSize(width, height + 12);
  39. Timers.inst.AddUpdate(CheckGuide);
  40. }
  41. protected override void OnHide()
  42. {
  43. base.OnHide();
  44. _ui.m_btnSave.selected = false;
  45. _ui.m_btnSave.touchable = true;
  46. _ui.m_btnSavePhoto.selected = false;
  47. _ui.m_btnSavePhoto.touchable = true;
  48. Timers.inst.Remove(CheckGuide);
  49. }
  50. public override void Dispose()
  51. {
  52. if (_ui != null)
  53. {
  54. _ui.Dispose();
  55. _ui = null;
  56. }
  57. base.Dispose();
  58. }
  59. private void OnClickBtnSave()
  60. {
  61. //检查用户是否已授予对需要授权的设备资源或信息的访问权。
  62. if (!Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
  63. {
  64. //请求用户授权访问需要授权的设备资源或信息.
  65. Permission.RequestUserPermission(Permission.ExternalStorageWrite);
  66. }
  67. if (Permission.HasUserAuthorizedPermission(Permission.ExternalStorageWrite))
  68. {
  69. string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
  70. PhotographUtil.Instance.SavePicturoToLocal(bytes, fileName);
  71. _ui.m_btnSave.touchable = false;
  72. }
  73. }
  74. private async void OnClickBtnSavePhoto()
  75. {
  76. if (PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxPhotoCount)
  77. {
  78. PromptController.Instance.ShowFloatTextPrompt("照片数量已达上限");
  79. return;
  80. }
  81. object[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl();
  82. if (rsp == null) return;
  83. bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0].ToString(), bytes);
  84. if (!pushResult) return;
  85. long addResult = await PoemPhotoSProxy.ReqAddTophoto((long)rsp[1]);
  86. if (addResult > 0)
  87. {
  88. List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  89. for (int i = 0; i < list.Count; i++)
  90. {
  91. if (list[i].PictureId == addResult)
  92. {
  93. list[i].Bytes = bytes;
  94. list[i].Ntexture = new NTexture(tex);
  95. break;
  96. }
  97. }
  98. }
  99. _ui.m_btnSavePhoto.touchable = false;
  100. }
  101. private void CheckGuide(object param)
  102. {
  103. if (GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0)
  104. {
  105. UpdateToCheckGuide(null);
  106. }
  107. else
  108. {
  109. Timers.inst.Remove(CheckGuide);
  110. }
  111. }
  112. protected override void UpdateToCheckGuide(object param)
  113. {
  114. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  115. GuideController.TryGuide(_ui.m_btnClose, ConstGuideId.FREEDOM_DRESS, 9, "");
  116. GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 9);
  117. }
  118. protected override void TryCompleteGuide()
  119. {
  120. base.TryCompleteGuide();
  121. // GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FREEDOM_DRESS);
  122. GuideController.TryCompleteGuideIndex(ConstGuideId.FREEDOM_DRESS, 9);
  123. GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 9);
  124. }
  125. }
  126. }