PhotographSaveView.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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. namespace GFGGame
  11. {
  12. public class PhotographSaveView : BaseView
  13. {
  14. private UI_PhotographSaveUI _ui;
  15. private Texture2D tex;
  16. private byte[] bytes;
  17. protected override void OnInit()
  18. {
  19. base.OnInit();
  20. packageName = UI_PhotographUI.PACKAGE_NAME;
  21. _ui = UI_PhotographSaveUI.Create();
  22. viewCom = _ui.target;
  23. isfullScreen = true;
  24. _ui.m_btnClose.onClick.Add(this.Hide);
  25. _ui.m_btnSave.onClick.Add(this.OnClickBtnSave);
  26. _ui.m_btnSavePhoto.onClick.Add(this.OnClickBtnSavePhoto);
  27. }
  28. protected override void OnShown()
  29. {
  30. base.OnShown();
  31. tex = this.viewData as Texture2D;
  32. bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  33. _ui.m_imgRes.texture = new NTexture(tex);
  34. float width = _ui.m_imgBorder.width;
  35. float height = width * tex.height / tex.width;
  36. _ui.m_imgRes.SetSize(width, height);
  37. _ui.m_imgBorder.SetSize(width, height + 12);
  38. Timers.inst.AddUpdate(CheckGuide);
  39. }
  40. protected override void OnHide()
  41. {
  42. base.OnHide();
  43. _ui.m_btnSave.selected = false;
  44. _ui.m_btnSave.touchable = true;
  45. _ui.m_btnSavePhoto.selected = false;
  46. _ui.m_btnSavePhoto.touchable = true;
  47. Timers.inst.Remove(CheckGuide);
  48. }
  49. public override void Dispose()
  50. {
  51. if (_ui != null)
  52. {
  53. _ui.Dispose();
  54. _ui = null;
  55. }
  56. base.Dispose();
  57. }
  58. private void OnClickBtnSave()
  59. {
  60. string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
  61. PhotographDataManager.Instance.SavePicturoToLocal(bytes, fileName);
  62. _ui.m_btnSave.touchable = false;
  63. }
  64. private async void OnClickBtnSavePhoto()
  65. {
  66. if (PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxPhotoCount)
  67. {
  68. PromptController.Instance.ShowFloatTextPrompt("照片数量已达上限");
  69. return;
  70. }
  71. string[] rsp = await PictureStorageHelper.ReqTempPictureUrl((int)PictureType.jpg);
  72. if (rsp == null) return;
  73. bool pushResult = await PictureStorageHelper.PushToHWCloud(rsp[0], bytes);
  74. if (!pushResult) return;
  75. long addResult = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
  76. if (addResult > 0)
  77. {
  78. List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  79. for (int i = 0; i < list.Count; i++)
  80. {
  81. if (list[i].PictureId == addResult)
  82. {
  83. list[i].Bytes = bytes;
  84. list[i].Ntexture = new NTexture(tex);
  85. break;
  86. }
  87. }
  88. }
  89. _ui.m_btnSavePhoto.touchable = false;
  90. }
  91. private void CheckGuide(object param)
  92. {
  93. if (GuideDataManager.IsGuideFinish(ConstGuideId.FREEDOM_DRESS) <= 0)
  94. {
  95. UpdateToCheckGuide(null);
  96. }
  97. else
  98. {
  99. Timers.inst.Remove(CheckGuide);
  100. }
  101. }
  102. protected override void UpdateToCheckGuide(object param)
  103. {
  104. if (!ViewManager.CheckIsTopView(this.viewCom)) return;
  105. GuideController.TryGuide(_ui.m_btnClose, ConstGuideId.FREEDOM_DRESS, 9, "");
  106. GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 9);
  107. }
  108. protected override void TryCompleteGuide()
  109. {
  110. base.TryCompleteGuide();
  111. GuideCfg cfg = GuideCfgArray.Instance.GetCfg(ConstGuideId.FREEDOM_DRESS);
  112. GuideController.TryCompleteGuideIndex(cfg.id, 9);
  113. GuideController.TryCompleteGuide(ConstGuideId.FREEDOM_DRESS, 9);
  114. }
  115. }
  116. }