using UI.RoleInfo; using FairyGUI; namespace GFGGame { public class PersonalPhotoView : BaseWindow { private UI_PersonalPhotoUI _ui; private int _showIndex = 0; private long _showPictureId = 0; public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_PersonalPhotoUI.PACKAGE_NAME; _ui = UI_PersonalPhotoUI.Create(); this.viewCom = _ui.target; isfullScreen = true; isReturnView = true; _ui.m_btnback.onClick.Add(OnBtnBackClick); _ui.m_list.SetVirtual(); _ui.m_list.itemRenderer = RenderListItem; _ui.m_list.onClickItem.Add(OnListItemClick); _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("tjbg"); } protected override void OnShown() { base.OnShown(); _showIndex = (int)this.viewData; _showPictureId = RoleDataManager.photoDatas[_showIndex]; _ui.m_list.numItems = PoemPhotoDataManager.Instance.PersonalPhotoInfos.Count; _ui.m_grpNothing.visible = _ui.m_list.numItems == 0; } protected override void OnHide() { base.OnHide(); } private void OnBtnBackClick() { ViewManager.GoBackFrom(typeof(PersonalPhotoView).FullName); } private void RenderListItem(int index, GObject obj) { PoemPhotoData photoData = PoemPhotoDataManager.Instance.PersonalPhotoInfos[index]; UI_ListPhotoItemDetail item = UI_ListPhotoItemDetail.Proxy(obj); item.m_comIcon.m_loaIcon.texture = photoData.Ntexture; bool curSelect = photoData.PictureId == _showPictureId; bool otherSelect = !curSelect && RoleDataManager.photoDatas.IndexOf(photoData.PictureId) >= 0; if (curSelect) { item.m_c1.SetSelectedIndex(2); } else if (otherSelect) { item.m_c1.SetSelectedIndex(1); } else { item.m_c1.SetSelectedIndex(0); } string[] timeStr = TimeUtil.FormattingTime1(photoData.CreationTime, '/').Split(' '); item.m_txtTime.text = timeStr[0]; item.target.data = photoData.PictureId; UI_ListPhotoItemDetail.ProxyEnd(); } private async void OnListItemClick(EventContext context) { GObject obj = context.data as GObject; long selectPictureId = (long)obj.data; if (selectPictureId == _showPictureId)//删除:点击相同id照片 { RoleDataManager.photoDatas[_showIndex] = 0; // 将空位移动到后面 for (int i = _showIndex; i < RoleDataManager.photoDatas.Count - 1; i++) { if (RoleDataManager.photoDatas[i + 1] == 0) { break; } else { RoleDataManager.photoDatas[i] = RoleDataManager.photoDatas[i + 1]; RoleDataManager.photoDatas[i + 1] = 0; } } } else { if (_showPictureId == 0)//添加:原来未展示图片 { if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//选中的图片未被选中 { // 找到第一个空位 for(int i = 0; i < RoleDataManager.photoDatas.Count; i++) { if(RoleDataManager.photoDatas[i] == 0) { RoleDataManager.photoDatas[i] = selectPictureId; break; } } } } else//原来有展示图片 { if (RoleDataManager.photoDatas.IndexOf(selectPictureId) < 0)//更换:选中的图片未被选中 { RoleDataManager.photoDatas[_showIndex] = selectPictureId; } else { int selectPictureIndex = RoleDataManager.photoDatas.IndexOf(selectPictureId); RoleDataManager.photoDatas[_showIndex] = selectPictureId; RoleDataManager.photoDatas[selectPictureIndex] = _showPictureId; } } } bool result = await RoleInfoSProxy.ReqModifyShowPhoto(RoleDataManager.photoDatas); if (result) { Hide(); } } } }