PoemGalleryView.cs 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Poem;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. public class PoemGalleryView : BaseWindow
  9. {
  10. private UI_PoemGalleryUI _ui;
  11. private GList _list;
  12. private List<PoemGalleryData> _galleryDatas = new List<PoemGalleryData>();
  13. private int _sortType = 0;//由GallerySortType定义
  14. private int _pageCount = 10;
  15. public override void Dispose()
  16. {
  17. if (_ui != null)
  18. {
  19. _ui.Dispose();
  20. _ui = null;
  21. }
  22. base.Dispose();
  23. }
  24. protected override void OnInit()
  25. {
  26. base.OnInit();
  27. packageName = UI_PoemGalleryUI.PACKAGE_NAME;
  28. _ui = UI_PoemGalleryUI.Create();
  29. this.viewCom = _ui.target;
  30. isfullScreen = true;
  31. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  32. _ui.m_comNormal.m_comBoBox.items = new string[] { "推荐", "最新" };
  33. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  34. _ui.m_btnRecover.onClick.Add(OnBtnRecoverClick);
  35. _ui.m_btnJoin.onClick.Add(OnBtnJoinClick);
  36. _ui.m_btnFavorites.onClick.Add(OnBtnFavoritesClick);
  37. _ui.m_comNormal.m_listRecommend.itemRenderer = RenderListItem;
  38. _ui.m_comNormal.m_listRecommend.SetVirtual();
  39. _ui.m_comNormal.m_listRecommend.scrollPane.onPullDownRelease.Add(onPullDownRelease);
  40. _ui.m_comNormal.m_listRecommend.scrollPane.header.onSizeChanged.Add(OnSizeChanged);
  41. _ui.m_comNormal.m_listRecommend.scrollPane.onScroll.Add(onScroll);
  42. _ui.m_comNormal.m_listFriend.itemRenderer = RenderListItem;
  43. _ui.m_comNormal.m_listFriend.SetVirtual();
  44. _ui.m_comNormal.m_listFriend.scrollPane.onScroll.Add(onScroll);
  45. _ui.m_comNormal.m_listRank.itemRenderer = RenderListRankItem;
  46. _ui.m_comNormal.m_listRank.SetVirtual();
  47. _ui.m_comNormal.m_listRank.scrollPane.onScroll.Add(onScroll);
  48. _ui.m_comFavorites.m_listFavorite.itemRenderer = RenderListItem;
  49. _ui.m_comFavorites.m_listFavorite.SetVirtual();
  50. _ui.m_comFavorites.m_listFavorite.scrollPane.onScroll.Add(onScroll);
  51. _ui.m_comFavorites.m_listMySelf.itemRenderer = RenderListItem;
  52. _ui.m_comFavorites.m_listMySelf.SetVirtual();
  53. _ui.m_comFavorites.m_listMySelf.scrollPane.onScroll.Add(onScroll);
  54. _ui.m_comNormal.m_btnShop.onClick.Add(OnBtnShopClick);
  55. _ui.m_comNormal.m_btnReward.onClick.Add(OnBtnRewardClick);
  56. // _ui.m_c1.onChanged.Add(OnTabChange);
  57. _ui.m_comNormal.m_c1.onChanged.Add(OnNormalTabChange);
  58. _ui.m_comFavorites.m_c1.onChanged.Add(OnFavoritesTabChange);
  59. }
  60. protected override void AddEventListener()
  61. {
  62. base.AddEventListener();
  63. EventAgent.AddEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  64. EventAgent.AddEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList);
  65. }
  66. protected override void OnShown()
  67. {
  68. base.OnShown();
  69. _list = _ui.m_comNormal.m_listRecommend;
  70. _list.numItems = 4;
  71. }
  72. protected override void OnHide()
  73. {
  74. base.OnHide();
  75. ResetPullDownRelease();
  76. }
  77. protected override void RemoveEventListener()
  78. {
  79. base.RemoveEventListener();
  80. EventAgent.RemoveEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  81. EventAgent.RemoveEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList);
  82. }
  83. private void OnBtnBackClick()
  84. {
  85. ViewManager.GoBackFrom(typeof(PoemGalleryView).FullName);
  86. }
  87. /// <summary>
  88. /// 投稿
  89. /// </summary>
  90. private void OnBtnJoinClick()
  91. {
  92. ViewManager.Show<DressUpView>(1, new object[] { typeof(PoemGalleryView).FullName, this.viewData }, true);
  93. }
  94. /// <summary>
  95. /// 首页
  96. /// </summary>
  97. private void OnBtnRecoverClick()
  98. {
  99. if (_ui.m_comNormal.m_c1.selectedIndex == 0)
  100. {
  101. onPullDownRelease();
  102. // OnNormalTabChange();//每次点首页都要刷新
  103. }
  104. else
  105. {
  106. _ui.m_comNormal.m_c1.selectedIndex = 0;
  107. }
  108. }
  109. /// <summary>
  110. ///收藏夹
  111. /// </summary>
  112. private void OnBtnFavoritesClick()
  113. {
  114. if (_ui.m_comFavorites.m_c1.selectedIndex != 0)
  115. {
  116. _ui.m_comFavorites.m_c1.selectedIndex = 0;
  117. }
  118. ResetPullDownRelease();
  119. }
  120. // /// <summary>
  121. // /// 切换ui页签:首页,投稿,收藏
  122. // /// </summary>
  123. // private void OnTabChange()
  124. // {
  125. // if (_ui.m_c1.selectedIndex == 0)//刷新首页
  126. // {
  127. // if (_ui.m_comNormal.m_c1.selectedIndex == 0)
  128. // {
  129. // OnNormalTabChange();
  130. // }
  131. // else
  132. // {
  133. // _ui.m_comNormal.m_c1.selectedIndex = 0;
  134. // }
  135. // }
  136. // else if (_ui.m_c1.selectedIndex == 2)//刷新收藏页
  137. // {
  138. // if (_ui.m_comFavorites.m_c1.selectedIndex == 0)
  139. // {
  140. // OnFavoritesTabChange();
  141. // }
  142. // else
  143. // {
  144. // _ui.m_comFavorites.m_c1.selectedIndex = 0;
  145. // }
  146. // }
  147. // }
  148. /// <summary>
  149. /// 切换首页页签
  150. /// </summary>
  151. private void OnNormalTabChange()
  152. {
  153. ResetPullDownRelease();
  154. if (_ui.m_comNormal.m_c1.selectedIndex == 2)//排行榜
  155. {
  156. }
  157. else
  158. {
  159. if (_ui.m_comNormal.m_c1.selectedIndex == 0)//首页
  160. {
  161. // _infoType = GalleryType.Recommend;
  162. if (_ui.m_comNormal.m_comBoBox.selectedIndex == 0)//推荐
  163. {
  164. _sortType = (int)GallerySortType.Recommend;
  165. _galleryDatas = PoemGalleryDataManager.Instance.RecommendDatas;
  166. }
  167. else//最新
  168. {
  169. _sortType = (int)GallerySortType.Newest;
  170. _galleryDatas = PoemGalleryDataManager.Instance.NewestDatas;
  171. }
  172. _list = _ui.m_comNormal.m_listRecommend;
  173. }
  174. else if (_ui.m_comNormal.m_c1.selectedIndex == 1)//好友
  175. {
  176. _sortType = (int)GallerySortType.Friend;
  177. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  178. _list = _ui.m_comNormal.m_listFriend;
  179. }
  180. if (_list.numItems > 0) _list.ScrollToView(0);
  181. ReqGalleryList(0);
  182. }
  183. }
  184. /// <summary>
  185. /// 切换收藏页签
  186. /// </summary>
  187. private void OnFavoritesTabChange()
  188. {
  189. if (_ui.m_comFavorites.m_c1.selectedIndex == 0)//我的收藏
  190. {
  191. _sortType = (int)GallerySortType.MyCollect;
  192. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  193. _list = _ui.m_comFavorites.m_listFavorite;
  194. }
  195. else if (_ui.m_comFavorites.m_c1.selectedIndex == 1)//我的作品
  196. {
  197. _sortType = (int)GallerySortType.MyWorks;
  198. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  199. _list = _ui.m_comFavorites.m_listMySelf;
  200. }
  201. if (_list.numItems > 0) _list.ScrollToView(0);
  202. ReqGalleryList(0);
  203. }
  204. //分页刷新
  205. private void onScroll()
  206. {
  207. int itemIndex = _list.ChildIndexToItemIndex(0);
  208. int startIndex = itemIndex + 1;
  209. if (startIndex >= _list.numItems && startIndex % _pageCount == 0)
  210. {
  211. ReqGalleryList(startIndex);
  212. }
  213. }
  214. //请求刷新
  215. private void ReqGalleryList(int startIndex)
  216. {
  217. PoemGallerySProxy.ReqGalleryList(_sortType, startIndex, _pageCount).Coroutine();
  218. }
  219. private void UpdateGalleryList()
  220. {
  221. _list.numItems = _galleryDatas.Count;
  222. }
  223. private void UpdateGalleryRankList()
  224. {
  225. _ui.m_comNormal.m_listRank.numItems = _galleryDatas.Count;
  226. }
  227. /// <summary>
  228. /// 积分商店
  229. /// </summary>
  230. private void OnBtnShopClick()
  231. {
  232. ViewManager.Show<ClothingShopView>(new object[] { ConstStoreId.GALLERY_STORE_ID }, new object[] { typeof(PoemGalleryView).FullName, this.viewData }, true);
  233. }
  234. /// <summary>
  235. /// 排行榜奖励
  236. /// </summary>
  237. private void OnBtnRewardClick()
  238. {
  239. ViewManager.Show<PoemGalleryRewardView>(null, new object[] { typeof(PoemGalleryView).FullName, this.viewData });
  240. }
  241. private void RenderListItem(int index, GObject obj)
  242. {
  243. // PoemGalleryData data = _galleryDatas[index];
  244. // UI_ListItem item = UI_ListItem.Proxy(obj);
  245. // if (item.m_loaIcon.data == null)
  246. // {
  247. // item.m_loaIcon.onClick.Add(OnLoaIconClick);
  248. // }
  249. // item.m_loaIcon.data = data;
  250. // if (item.m_btnCollect.data == null)
  251. // {
  252. // item.m_btnCollect.onClick.Add(OnBtnCollectClick);
  253. // }
  254. // item.m_btnCollect.data = data;
  255. // if (item.m_btnVote.data == null)
  256. // {
  257. // item.m_btnVote.onClick.Add(OnBtnVoteClick);
  258. // }
  259. // item.m_btnVote.data = data;
  260. // UI_ListItem.ProxyEnd();
  261. }
  262. private void RenderListRankItem(int index, GObject obj)
  263. {
  264. }
  265. private void OnLoaIconClick(EventContext context)
  266. {
  267. GObject obj = context.data as GObject;
  268. PoemGalleryData data = obj.data as PoemGalleryData;
  269. }
  270. private void OnBtnCollectClick(EventContext context)
  271. {
  272. GObject obj = context.data as GObject;
  273. PoemGalleryData data = obj.data as PoemGalleryData;
  274. }
  275. private void OnBtnVoteClick(EventContext context)
  276. {
  277. GObject obj = context.data as GObject;
  278. PoemGalleryData data = obj.data as PoemGalleryData;
  279. }
  280. //下拉刷新
  281. private void onPullDownRelease()
  282. {
  283. // ReqGalleryList(0);
  284. GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header;
  285. Controller controller = header.GetController("c1");
  286. controller.selectedIndex = 1;
  287. _ui.m_comNormal.m_listRecommend.scrollPane.LockHeader(header.sourceHeight);
  288. Timers.inst.Add(2, 1, OnTimeComplete);
  289. }
  290. private void OnTimeComplete(object param)
  291. {
  292. GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header;
  293. // Controller controller = header.GetController("c1");
  294. header.GetController("c1").selectedIndex = 2;
  295. _ui.m_comNormal.m_listRecommend.scrollPane.LockHeader(0);
  296. }
  297. private void OnSizeChanged()
  298. {
  299. GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header;
  300. Controller controller = _ui.m_comNormal.m_listRecommend.scrollPane.header.GetController("c1");
  301. if (header.height <= 1)
  302. {
  303. controller.selectedIndex = 0;
  304. }
  305. }
  306. /// <summary>
  307. /// 重置下拉刷新状态
  308. /// </summary>
  309. private void ResetPullDownRelease()
  310. {
  311. Timers.inst.Remove(OnTimeComplete);
  312. OnTimeComplete(null);
  313. }
  314. }
  315. }