using System.Collections.Generic; using ET; using FairyGUI; using UI.Poem; using UnityEngine; namespace GFGGame { public class PoemPhotoPreView : BaseWindow { private UI_PoemPhotoPreviewUI _ui; private List _photoInfos; private int _curIndex = 0; private int _sourceType = 0; private PoemPhotoData _curPhotoData; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_PoemPhotoPreviewUI.PACKAGE_NAME; _ui = UI_PoemPhotoPreviewUI.Create(); this.viewCom = _ui.target; isfullScreen = true; _ui.m_grhBg.onClick.Add(OnBtnBackClick); _ui.m_list.SetVirtual(); _ui.m_list.itemRenderer = RenderListItem; _ui.m_list.scrollPane.onScrollEnd.Add(OnListScrollEnd); _ui.m_btnLeft.onClick.Add(OnBtnLeftClick); _ui.m_btnRight.onClick.Add(OnBtnRightClick); _ui.m_btnLock.target.onClick.Add(OnBtnLockClick); _ui.m_btnUp.target.onClick.Add(OnBtnUpClick); _ui.m_btnShare.onClick.Add(OnBtnShareClick); } protected override void AddEventListener() { base.AddEventListener(); } protected override void OnShown() { base.OnShown(); _curIndex = (int)(this.viewData as object[])[0]; List photoInfos = (this.viewData as object[])[1] as List; _photoInfos = new List(photoInfos.ToArray()); _ui.m_list.numItems = _photoInfos.Count; _ui.m_list.height = _ui.m_list.GetChildAt(0).height; UpdateView(); } protected override void OnHide() { base.OnHide(); } protected override void RemoveEventListener() { base.RemoveEventListener(); } private void OnBtnBackClick() { ViewManager.GoBackFrom(typeof(PoemPhotoPreView).FullName); } private void UpdateView() { _ui.m_btnLeft.enabled = _curIndex > 0; _ui.m_btnRight.enabled = _curIndex < _ui.m_list.numItems - 1; _ui.m_txtTime.text = TimeUtil.FormattingTime1(_photoInfos[_curIndex].CreationTime); _ui.m_btnLock.m_c1.selectedIndex = _photoInfos[_curIndex].LockingStatus ? 1 : 0; _ui.m_btnUp.m_c1.selectedIndex = _photoInfos[_curIndex].ToppingStatus ? 1 : 0; if (_photoInfos.Count > 0) _ui.m_list.ScrollToView(_curIndex); if (_ui.m_btnLock.target.data == null) { _ui.m_btnLock.target.onClick.Add(OnBtnLockClick); } _ui.m_btnLock.target.data = _curIndex; if (_ui.m_btnUp.target.data == null) { _ui.m_btnUp.target.onClick.Add(OnBtnUpClick); } _curPhotoData = _photoInfos[_curIndex]; } private void RenderListItem(int index, GObject obj) { UI_ListPhotoPreviewItem item = UI_ListPhotoPreviewItem.Proxy(obj); GLoader loaIcon = item.m_comPhoto.m_loaPhoto; item.m_comPhoto.m_loaPhoto.texture = _photoInfos[index].Ntexture;// PoemPhotoDataManager.Instance.BytesToTexture2D(_photoInfos[index].Bytes); item.target.SetSize(item.target.width, item.target.initHeight * _ui.target.height / _ui.target.initHeight); loaIcon.SetSize(loaIcon.width, loaIcon.texture.height * loaIcon.width / loaIcon.texture.width); loaIcon.y = item.target.height / 2; item.m_imgBorder.SetSize(item.target.width, item.target.height); UI_ListPhotoPreviewItem.ProxyEnd(); } private void OnBtnLeftClick() { _curIndex--; _curIndex = Mathf.Max(0, _curIndex); UpdateView(); } private void OnBtnRightClick() { _curIndex++; _curIndex = Mathf.Min(_ui.m_list.numItems - 1, _curIndex); UpdateView(); } private void OnListScrollEnd() { _curIndex = _ui.m_list.ChildIndexToItemIndex(0); UpdateView(); } private void OnBtnLockClick() { if (_curPhotoData.LockingStatus == false) { AlertUI.Show("是否确认锁定此照片?", "(锁住的照片无法被删除)") .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) => { bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, true, _sourceType); if (result) { _photoInfos[_curIndex].LockingStatus = true; UpdateView(); } }); } else { AlertUI.Show("是否确认解锁此照片?", "(解锁后的照片可随意删除)") .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) => { bool result = await PoemPhotoSProxy.ReqChangeLockingState(_curPhotoData.PictureId, false, _sourceType); if (result) { _photoInfos[_curIndex].LockingStatus = false; UpdateView(); } }); } } private void OnBtnUpClick() { if (_curPhotoData.ToppingStatus == false) { AlertUI.Show("是否确认置顶此照片?") .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) => { bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, true, _sourceType); if (result) { _photoInfos[_curIndex].ToppingStatus = true; UpdateView(); } }); } else { AlertUI.Show("是否确认取消置顶此照片?") .SetLeftButton(true, "否").SetRightButton(true, "是", async (object data) => { bool result = await PoemPhotoSProxy.ReqChangeToppingState(_curPhotoData.PictureId, false, _sourceType); if (result) { _photoInfos[_curIndex].ToppingStatus = false; UpdateView(); } }); } } private void OnBtnShareClick() { ViewManager.Show(_curPhotoData, new object[] { typeof(PoemPhotoPreView).FullName, new object[] { _curIndex, _photoInfos } }); } } }