PhotographSaveView.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. }
  39. protected override void OnHide()
  40. {
  41. base.OnHide();
  42. }
  43. public override void Dispose()
  44. {
  45. if (_ui != null)
  46. {
  47. _ui.Dispose();
  48. _ui = null;
  49. }
  50. base.Dispose();
  51. }
  52. private void OnClickBtnSave()
  53. {
  54. // Texture2D tex = this.viewData as Texture2D;
  55. // byte[] bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
  56. string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
  57. PhotographDataManager.Instance.SavePicturoToLocal(bytes, fileName);
  58. }
  59. private async void OnClickBtnSavePhoto()
  60. {
  61. if (PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count >= GlobalCfgArray.globalCfg.maxPhotoCount)
  62. {
  63. PromptController.Instance.ShowFloatTextPrompt("照片数量已达上限");
  64. return;
  65. }
  66. string[] rsp = await PoemPhotoSProxy.ReqTempPictureUrl((int)PictureType.jpg);
  67. if (rsp == null) return;
  68. bool pushResult = await PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes);
  69. if (!pushResult) return;
  70. long addResult = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
  71. if (addResult > 0)
  72. {
  73. List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  74. for (int i = 0; i < list.Count; i++)
  75. {
  76. if (list[i].PictureId == addResult)
  77. {
  78. list[i].Ntexture = new NTexture(tex);
  79. break;
  80. }
  81. }
  82. }
  83. // Timers.inst.StartCoroutine(PoemPhotoSProxy.PushToHWCloud(rsp[0], bytes, async () =>
  84. // {
  85. // long result = await PoemPhotoSProxy.ReqAddTophoto(rsp[1], (int)PictureSourceType.PersonalAlbum);
  86. // if (result > 0)
  87. // {
  88. // List<PoemPhotoData> list = PoemPhotoDataManager.Instance.PersonalPhotoInfos;
  89. // for (int i = 0; i < list.Count; i++)
  90. // {
  91. // if (list[i].PictureId == result)
  92. // {
  93. // list[i].Ntexture = new NTexture(tex);
  94. // break;
  95. // }
  96. // }
  97. // }
  98. // }));
  99. }
  100. }
  101. }