123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.IO;
- using System.Threading.Tasks;
- using ET;
- using FairyGUI;
- using UI.DressUp;
- using UnityEngine;
- 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);
- }
- protected override void OnShown()
- {
- base.OnShown();
- tex = this.viewData as Texture2D;
- bytes = tex.EncodeToJPG();//将纹理数据,转化成一个jpg图片
- _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);
- Timers.inst.AddUpdate(CheckGuide);
- }
- protected override void OnHide()
- {
- base.OnHide();
- _ui.m_btnSave.selected = false;
- _ui.m_btnSave.touchable = true;
- _ui.m_btnSavePhoto.selected = false;
- _ui.m_btnSavePhoto.touchable = true;
- Timers.inst.Remove(CheckGuide);
- }
- public override void Dispose()
- {
- if (_ui != null)
- {
- _ui.Dispose();
- _ui = null;
- }
- base.Dispose();
- }
- private void OnClickBtnSave()
- {
- string fileName = "wsj" + TimeHelper.ServerNowSecs + ".jpg";
- PhotographUtil.Instance.SavePicturoToLocal(bytes, fileName);
- _ui.m_btnSave.touchable = false;
- }
- private async void OnClickBtnSavePhoto()
- {
- 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) 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.touchable = 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_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);
- }
- }
- }
|