using System.Collections.Generic; using ET; using FairyGUI; using UI.Poem; using UnityEngine; namespace GFGGame { class TabType { /// /// 首页 /// public static int RECOVER = 0; /// /// 投稿 /// public static int JOIN = 1; /// /// 收藏 /// public static int FAVORITES = 2; } class RecommendType { /// /// 推荐 /// public static int RECOMMEND = 0; /// /// 好友 /// public static int FRIEND = 1; /// /// 排行榜 /// public static int RANK = 2; } class FavoritesType { /// /// 我的收藏 /// public static int FAVORITE = 0; /// /// 我的作品 /// public static int MY_SELF = 1; } public class PoemGalleryView : BaseWindow { private UI_PoemGalleryUI _ui; private GList _list; // private List _galleryDatas = new List(); private List _galleryDatas = new List(); private int _sortType = 0;//由GallerySortType定义 private int _pageCount = 10; private int _tabIndex = 0;//当前选中大页签下标,首页0投稿1收藏2 private int _subtabIndex = 0;//当前选中小页签下标,推荐0好友1排行榜2;我的收藏0我的作品1 public override void Dispose() { if (_ui != null) { _ui.Dispose(); _ui = null; } base.Dispose(); } protected override void OnInit() { base.OnInit(); packageName = UI_PoemGalleryUI.PACKAGE_NAME; _ui = UI_PoemGalleryUI.Create(); this.viewCom = _ui.target; isfullScreen = true; _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1"); _ui.m_comNormal.m_comBoBox.items = new string[] { "推荐", "最新" }; _ui.m_btnback.onClick.Add(OnBtnBackClick); _ui.m_btnRecover.onClick.Add(OnBtnRecoverClick); _ui.m_btnJoin.onClick.Add(OnBtnJoinClick); _ui.m_btnFavorites.onClick.Add(OnBtnFavoritesClick); _ui.m_comNormal.m_listRecommend.itemRenderer = RenderListItem; _ui.m_comNormal.m_listRecommend.SetVirtual(); _ui.m_comNormal.m_listRecommend.scrollPane.onPullDownRelease.Add(onPullDownRelease); _ui.m_comNormal.m_listRecommend.scrollPane.onScroll.Add(onScroll); _ui.m_comNormal.m_listFriend.itemRenderer = RenderListItem; _ui.m_comNormal.m_listFriend.SetVirtual(); _ui.m_comNormal.m_listFriend.scrollPane.onScroll.Add(onScroll); _ui.m_comNormal.m_listRank.itemRenderer = RenderListRankItem; _ui.m_comNormal.m_listRank.SetVirtual(); _ui.m_comNormal.m_listRank.scrollPane.onScroll.Add(onScroll); _ui.m_comFavorites.m_listFavorite.itemRenderer = RenderListItem; _ui.m_comFavorites.m_listFavorite.SetVirtual(); _ui.m_comFavorites.m_listFavorite.scrollPane.onScroll.Add(onScroll); _ui.m_comFavorites.m_listMySelf.itemRenderer = RenderListItem; _ui.m_comFavorites.m_listMySelf.SetVirtual(); _ui.m_comFavorites.m_listMySelf.scrollPane.onScroll.Add(onScroll); _ui.m_comNormal.m_btnShop.onClick.Add(OnBtnShopClick); _ui.m_comNormal.m_btnReward.onClick.Add(OnBtnRewardClick); // _ui.m_c1.onChanged.Add(OnTabChange); _ui.m_comNormal.m_c1.onChanged.Add(OnNormalTabChange); _ui.m_comFavorites.m_c1.onChanged.Add(OnFavoritesTabChange); } protected override void AddEventListener() { base.AddEventListener(); EventAgent.AddEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList); EventAgent.AddEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList); } protected override void OnShown() { base.OnShown(); if (this.viewData != null) { _tabIndex = (int)(this.viewData as object[])[0]; _subtabIndex = (int)(this.viewData as object[])[1]; _ui.m_comNormal.m_comBoBox.selectedIndex = (int)(this.viewData as object[])[2]; _ui.m_comNormal.m_c1.selectedIndex = _subtabIndex; _ui.m_comFavorites.m_c1.selectedIndex = _subtabIndex; _list.RefreshVirtualList(); } else { _tabIndex = TabType.RECOVER; _subtabIndex = RecommendType.RECOMMEND; _ui.m_comNormal.m_comBoBox.selectedIndex = 0; _ui.m_comNormal.m_c1.selectedIndex = _subtabIndex; _ui.m_comFavorites.m_c1.selectedIndex = _subtabIndex; if (_ui.m_comNormal.m_listRecommend.numItems > 0) _ui.m_comNormal.m_listRecommend.ScrollToView(0); if (_ui.m_comNormal.m_listFriend.numItems > 0) _ui.m_comNormal.m_listFriend.ScrollToView(0); if (_ui.m_comNormal.m_listRank.numItems > 0) _ui.m_comNormal.m_listRank.ScrollToView(0); if (_ui.m_comFavorites.m_listFavorite.numItems > 0) _ui.m_comFavorites.m_listFavorite.ScrollToView(0); if (_ui.m_comFavorites.m_listMySelf.numItems > 0) _ui.m_comFavorites.m_listMySelf.ScrollToView(0); OnNormalTabChange(); } _ui.m_c1.selectedIndex = _tabIndex; _ui.m_comNormal.m_listRecommend.numItems = 15; _ui.m_comNormal.m_listFriend.numItems = 15; _ui.m_comNormal.m_listRank.numItems = 15; _ui.m_comFavorites.m_listFavorite.numItems = 15; _ui.m_comFavorites.m_listMySelf.numItems = 15; _list = _ui.m_comNormal.m_listRecommend; _list.numItems = 10; // _list.RefreshVirtualList(); UpdateView(); } protected override void OnHide() { base.OnHide(); ResetPullDownRelease(); _ui.m_comNormal.m_comBoBox.selectedIndex = 0; } protected override void RemoveEventListener() { base.RemoveEventListener(); EventAgent.RemoveEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList); EventAgent.RemoveEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList); } private void OnBtnBackClick() { ViewManager.GoBackFrom(typeof(PoemGalleryView).FullName); } /// /// 积分商店 /// private void OnBtnShopClick() { object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex }; ViewManager.Show(new object[] { ConstStoreId.GALLERY_STORE_ID }, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }, true); } /// /// 排行榜奖励 /// private void OnBtnRewardClick() { ViewManager.Show(null, new object[] { typeof(PoemGalleryView).FullName, this.viewData }); } /********************************************************页签切换*************************************************/ /// /// 首页 /// private void OnBtnRecoverClick() { if (_tabIndex == TabType.RECOVER && _ui.m_comNormal.m_c1.selectedIndex == RecommendType.RECOMMEND)//当前在推荐页要刷新 { PullDown(); onPullDownRelease(); } else//当前不在推荐页只把页签切回到推荐页,不刷新 { _ui.m_comNormal.m_c1.selectedIndex = RecommendType.RECOMMEND; } _tabIndex = _ui.m_c1.selectedIndex; } /// /// 投稿 /// private void OnBtnJoinClick() { // int tabIndex = _ui.m_c1.selectedIndex; // int subType = _ui.m_c1.selectedIndex object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex }; ViewManager.Show(1, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }, true); } /// ///收藏夹 /// private void OnBtnFavoritesClick() { _tabIndex = _ui.m_c1.selectedIndex; if (_ui.m_comFavorites.m_c1.selectedIndex != FavoritesType.FAVORITE) { _ui.m_comFavorites.m_c1.selectedIndex = FavoritesType.FAVORITE; } ResetPullDownRelease(); } /// /// 切换首页页签 /// private void OnNormalTabChange() { ResetPullDownRelease(); _subtabIndex = _ui.m_comNormal.m_c1.selectedIndex; if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.RANK)//排行榜 { _galleryDatas = PoemGalleryDataManager.Instance.RankDatas; ReqGalleryRankList(); } else { if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.RECOMMEND)//首页 { // _infoType = GalleryType.Recommend; if (_ui.m_comNormal.m_comBoBox.selectedIndex == 0)//推荐 { _sortType = (int)GallerySortType.Recommend; _galleryDatas = PoemGalleryDataManager.Instance.RecommendDatas; } else//最新 { _sortType = (int)GallerySortType.Newest; _galleryDatas = PoemGalleryDataManager.Instance.NewestDatas; } _list = _ui.m_comNormal.m_listRecommend; } else if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.FRIEND)//好友 { _sortType = (int)GallerySortType.Friend; _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas; _list = _ui.m_comNormal.m_listFriend; } if (_list.numItems > 0) _list.ScrollToView(0); ReqGalleryList(0); } } /// /// 切换收藏页签 /// private void OnFavoritesTabChange() { _subtabIndex = _ui.m_comFavorites.m_c1.selectedIndex; if (_ui.m_comFavorites.m_c1.selectedIndex == FavoritesType.FAVORITE)//我的收藏 { _sortType = (int)GallerySortType.MyCollect; _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas; _list = _ui.m_comFavorites.m_listFavorite; } else if (_ui.m_comFavorites.m_c1.selectedIndex == FavoritesType.MY_SELF)//我的作品 { _sortType = (int)GallerySortType.MyWorks; _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas; _list = _ui.m_comFavorites.m_listMySelf; } if (_list.numItems > 0) _list.ScrollToView(0); ReqGalleryList(0); } /********************************************************请求更新列表*************************************************/ //分页刷新 private void onScroll() { if (_list == null) return; int itemIndex = _list.ChildIndexToItemIndex(0); int startIndex = itemIndex + 1; if (startIndex >= _list.numItems && startIndex % _pageCount == 0) { ReqGalleryList(startIndex); } } //请求刷新 private void ReqGalleryList(int startIndex) { PoemGallerySProxy.ReqGalleryList(_sortType, startIndex, _pageCount).Coroutine(); } private void UpdateGalleryList() { _list.numItems = _galleryDatas.Count; UpdateView(); } //请求排行榜刷新 private void ReqGalleryRankList() { PoemGallerySProxy.ReqRankList().Coroutine(); } private void UpdateGalleryRankList() { _ui.m_comNormal.m_listRank.numItems = _galleryDatas.Count; UpdateView(); } private void RefreshList() { if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.RANK) { _ui.m_comNormal.m_listRank.RefreshVirtualList(); } else { _list.RefreshVirtualList(); } UpdateView(); } /********************************************************界面更新*************************************************/ private void UpdateView() { GalleryThemeCfg themeCfg = GalleryThemeCfgArray.Instance.GetCfg((int)PoemGalleryDataManager.Instance.ThemeId); _ui.m_comNormal.m_txtTheme.text = string.Format("本期主题:{0}", themeCfg.theme); _ui.m_comNormal.m_txtRank.text = string.Format("我的排名:{0}", PoemGalleryDataManager.Instance.MyRank); _ui.m_comNormal.m_txtRewardCount.text = string.Format("奖励次数:{0}/{1}", PoemGalleryDataManager.Instance.VoteCount, GalleryRewardCfgArray.Instance.dataArray.Length); _ui.m_comNormal.m_txtTime.text = PoemGalleryDataManager.Instance.GetThemeTime(); _ui.m_comNormal.m_grpResult.visible = PoemGalleryDataManager.Instance.IsResulting(); } private void RenderListItem(int index, GObject obj) { // long workId = _galleryDatas[index]; // PoemGalleryData data = PoemGalleryDataManager.Instance.GetGalleryDataById(workId); UI_ListItem item = UI_ListItem.Proxy(obj); // item.m_loaIcon.height = 550 + Random.Range(40, 100); // if (index > 1) // { // item.target.y= // } // item.target.height = item.m_loaIcon.height + 80; // item.m_loaIcon.texture = data.Ntexture; // item.m_txtName.text = data.AuthorName; // item.m_btnCollect.title = data.CollectCount.ToString(); // item.m_btnCollect.selected = data.CollectOrNot; // item.m_btnVote.title = data.VoteCount.ToString(); // item.m_btnVote.selected = data.VoteOrNot; // if (item.m_loaIcon.data == null) // { // item.m_loaIcon.onClick.Add(OnLoaIconClick); // } // item.m_loaIcon.data = workId; // if (item.m_btnCollect.data == null) // { // item.m_btnCollect.onClick.Add(OnBtnCollectClick); // } // item.m_btnCollect.data = workId; // if (item.m_btnVote.data == null) // { // item.m_btnVote.onClick.Add(OnBtnVoteClick); // } // item.m_btnVote.data = workId; UI_ListItem.ProxyEnd(); } private void RenderListRankItem(int index, GObject obj) { // long workId = _galleryDatas[index]; // PoemGalleryData data = PoemGalleryDataManager.Instance.GetGalleryDataById(workId); // UI_ListRankItem item = UI_ListRankItem.Proxy(obj); // item.m_loaIcon.height = 550 + Random.Range(40, 100); // item.target.height = item.m_loaIcon.height + 80; // item.m_loaIcon.texture = data.Ntexture; // item.m_txtName.text = data.AuthorName; // item.m_btnCollect.title = data.CollectCount.ToString(); // item.m_btnCollect.selected = data.CollectOrNot; // item.m_btnVote.title = data.VoteCount.ToString(); // item.m_btnVote.selected = data.VoteOrNot; // item.m_c1.selectedIndex = index < 3 ? index : 3; // if (item.m_loaIcon.data == null) // { // item.m_loaIcon.onClick.Add(OnLoaIconClick); // } // item.m_loaIcon.data = workId; // if (item.m_btnCollect.data == null) // { // item.m_btnCollect.onClick.Add(OnBtnCollectClick); // } // item.m_btnCollect.data = workId; // if (item.m_btnVote.data == null) // { // item.m_btnVote.onClick.Add(OnBtnVoteClick); // } // item.m_btnVote.data = workId; // UI_ListRankItem.ProxyEnd(); } private void OnLoaIconClick(EventContext context) { GObject obj = context.data as GObject; // PoemGalleryData data = obj.data as PoemGalleryData; long workId = (long)obj.data; object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex }; ViewManager.Show(new object[] { _sortType, workId }, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }); } private async void OnBtnCollectClick(EventContext context) { GObject obj = context.data as GObject; long workId = (long)obj.data; PoemGalleryData galleryData = PoemGalleryDataManager.Instance.GetGalleryDataById(workId); if (galleryData.CollectOrNot) { bool result = await PoemGallerySProxy.ReqCancelCollecteGalleryWorks(workId); if (result) { // galleryData.CollectOrNot = false; // galleryData.CollectCount = galleryData.CollectCount - 1; if (_tabIndex == TabType.FAVORITES && _subtabIndex == FavoritesType.FAVORITE) { ReqGalleryList(0);//当前为收藏页要重新拉取数据 } else { RefreshList(); } } } else { bool result = await PoemGallerySProxy.ReqCollecteGalleryWorks(workId); if (result) { // galleryData.CollectOrNot = true; // galleryData.CollectCount = galleryData.CollectCount + 1; if (_tabIndex == TabType.FAVORITES && _subtabIndex == FavoritesType.FAVORITE) { ReqGalleryList(0);//当前为收藏页要重新拉取数据 } else { RefreshList(); } } } } private async void OnBtnVoteClick(EventContext context) { GObject obj = context.data as GObject; // PoemGalleryData galleryData = obj.data as PoemGalleryData; long workId = (long)obj.data; PoemGalleryData galleryData = PoemGalleryDataManager.Instance.GetGalleryDataById(workId); if (galleryData.VoteOrNot) return; bool result = await PoemGallerySProxy.ReqVoteGalleryWorks(workId); if (result) { // galleryData.VoteOrNot = true; // galleryData.CollectCount = galleryData.CollectCount + 1; RefreshList(); int Count = GameGlobal.myNumericComponent.GetAsInt(NumericType.LikeGalleryWorksCountDaily); GalleryIntegralCfg integralCfg = GalleryIntegralCfgArray.Instance.GetCfg(Count); if (integralCfg != null) { ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(integralCfg.itemId); PromptController.Instance.ShowFloatTextPrompt(string.Format("{0} +{1}", itemCfg.name, integralCfg.Count)); } } } /********************************************************下拉刷新*************************************************/ private void PullDown() { if (_ui.m_comNormal.m_listRecommend.numItems > 0) _ui.m_comNormal.m_listRecommend.ScrollToView(0); GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header; header.height = header.sourceHeight; } //下拉刷新 private void onPullDownRelease() { // ReqGalleryList(0); GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header; if (header.height < header.sourceHeight) return; // Transition transition = header.GetTransition("t0"); // transition.Play(); // controller.selectedIndex = 1; _ui.m_comNormal.m_listRecommend.scrollPane.LockHeader(header.sourceHeight); Timers.inst.Add(2, 1, OnTimeComplete); } private void OnTimeComplete(object param) { GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header; Transition transition = header.GetTransition("t0"); transition.Stop(); // header.GetController("c1").selectedIndex = 2; _ui.m_comNormal.m_listRecommend.scrollPane.LockHeader(0); } /// /// 重置下拉刷新状态 /// private void ResetPullDownRelease() { Timers.inst.Remove(OnTimeComplete); OnTimeComplete(null); } } }