PoemGalleryView.cs 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  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 _infoType = 0;//0推荐1好友2收藏3我的
  14. public override void Dispose()
  15. {
  16. if (_ui != null)
  17. {
  18. _ui.Dispose();
  19. _ui = null;
  20. }
  21. base.Dispose();
  22. }
  23. protected override void OnInit()
  24. {
  25. base.OnInit();
  26. packageName = UI_PoemGalleryUI.PACKAGE_NAME;
  27. _ui = UI_PoemGalleryUI.Create();
  28. this.viewCom = _ui.target;
  29. isfullScreen = true;
  30. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  31. _ui.m_comNormal.m_comBoBox.items = new string[] { "推荐", "最新" };
  32. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  33. _ui.m_btnRecover.onClick.Add(OnBtnRecoverClick);
  34. _ui.m_btnJoin.onClick.Add(OnBtnJoinClick);
  35. _ui.m_btnFavorites.onClick.Add(OnBtnFavoritesClick);
  36. _ui.m_comNormal.m_listRecommend.itemRenderer = RenderListItem;
  37. _ui.m_comNormal.m_listRecommend.SetVirtual();
  38. _ui.m_comNormal.m_listRecommend.scrollPane.onPullDownRelease.Add(onPullDownRelease);
  39. _ui.m_comNormal.m_listRecommend.scrollPane.header.onSizeChanged.Add(OnSizeChanged);
  40. _ui.m_comNormal.m_listFriend.itemRenderer = RenderListItem;
  41. _ui.m_comNormal.m_listFriend.SetVirtual();
  42. _ui.m_comNormal.m_listRank.itemRenderer = RenderListRankItem;
  43. _ui.m_comNormal.m_listRank.SetVirtual();
  44. _ui.m_comNormal.m_btnShop.onClick.Add(OnBtnShopClick);
  45. _ui.m_comNormal.m_btnReward.onClick.Add(OnBtnRewardClick);
  46. _ui.m_comNormal.m_c1.onChanged.Add(OnNormalTabChange);
  47. _ui.m_comFavorites.m_c1.onChanged.Add(OnFavoritesTabChange);
  48. }
  49. protected override void AddEventListener()
  50. {
  51. base.AddEventListener();
  52. EventAgent.AddEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  53. EventAgent.AddEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList);
  54. }
  55. protected override void OnShown()
  56. {
  57. base.OnShown();
  58. _list = _ui.m_comNormal.m_listRecommend;
  59. }
  60. protected override void OnHide()
  61. {
  62. base.OnHide();
  63. }
  64. protected override void RemoveEventListener()
  65. {
  66. base.RemoveEventListener();
  67. EventAgent.RemoveEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  68. EventAgent.RemoveEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList);
  69. }
  70. private void OnBtnBackClick()
  71. {
  72. ViewManager.GoBackFrom(typeof(PoemGalleryView).FullName);
  73. }
  74. /// <summary>
  75. /// 投稿
  76. /// </summary>
  77. private void OnBtnJoinClick()
  78. {
  79. ViewManager.Show<DressUpView>(1, new object[] { typeof(PoemGalleryView).FullName, this.viewData }, true);
  80. }
  81. /// <summary>
  82. /// 首页
  83. /// </summary>
  84. private void OnBtnRecoverClick()
  85. {
  86. _ui.m_comNormal.m_c1.selectedIndex = 0;
  87. }
  88. /// <summary>
  89. ///收藏夹
  90. /// </summary>
  91. private void OnBtnFavoritesClick()
  92. {
  93. _ui.m_comFavorites.m_c1.selectedIndex = 0;
  94. }
  95. /// <summary>
  96. /// 切换首页页签
  97. /// </summary>
  98. private void OnNormalTabChange()
  99. {
  100. if (_ui.m_comNormal.m_c1.selectedIndex == 2)//排行榜
  101. {
  102. }
  103. else
  104. {
  105. if (_ui.m_comNormal.m_c1.selectedIndex == 0)//首页
  106. {
  107. // _infoType = GalleryType.Recommend;
  108. if (_ui.m_comNormal.m_comBoBox.selectedIndex == 0)//推荐
  109. {
  110. _infoType = (int)GallerySortType.Recommend;
  111. _galleryDatas = PoemGalleryDataManager.Instance.RecommendDatas;
  112. }
  113. else//最新
  114. {
  115. _infoType = (int)GallerySortType.Newest;
  116. _galleryDatas = PoemGalleryDataManager.Instance.NewestDatas;
  117. }
  118. _list = _ui.m_comNormal.m_listRecommend;
  119. }
  120. else if (_ui.m_comNormal.m_c1.selectedIndex == 1)//好友
  121. {
  122. _infoType = (int)GallerySortType.Friend;
  123. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  124. _list = _ui.m_comNormal.m_listFriend;
  125. }
  126. }
  127. }
  128. /// <summary>
  129. /// 切换收藏页签
  130. /// </summary>
  131. private void OnFavoritesTabChange()
  132. {
  133. if (_ui.m_comFavorites.m_c1.selectedIndex == 0)
  134. {
  135. // _infoType = GalleryType.Favorite;
  136. // _galleryIds = PoemGalleryDataManager.Instance.FavoriteInfos;
  137. }
  138. else if (_ui.m_comFavorites.m_c1.selectedIndex == 1)
  139. {
  140. // _infoType = GalleryType.MySelf;
  141. // _galleryIds = PoemGalleryDataManager.Instance.MySelfInfos;
  142. }
  143. }
  144. private void UpdateGalleryList()
  145. {
  146. _list.numItems = _galleryDatas.Count;
  147. }
  148. private void UpdateGalleryRankList()
  149. {
  150. _ui.m_comNormal.m_listRank.numItems = _galleryDatas.Count;
  151. }
  152. /// <summary>
  153. /// 积分商店
  154. /// </summary>
  155. private void OnBtnShopClick()
  156. {
  157. ViewManager.Show<ClothingShopView>(new object[] { ConstStoreId.GALLERY_STORE_ID }, new object[] { typeof(PoemGalleryView).FullName, this.viewData }, true);
  158. }
  159. /// <summary>
  160. /// 推荐
  161. /// </summary>
  162. private void OnBtnRecommendClick()
  163. {
  164. }
  165. /// <summary>
  166. /// 最新
  167. /// </summary>
  168. private void OnBtnNewestClick()
  169. {
  170. ViewManager.Show<PoemGalleryRewardView>(null, new object[] { typeof(PoemGalleryView).FullName, this.viewData }, true);
  171. }
  172. /// <summary>
  173. /// 排行榜奖励
  174. /// </summary>
  175. private void OnBtnRewardClick()
  176. {
  177. }
  178. private void RenderListItem(int index, GObject obj)
  179. {
  180. // PoemGalleryData data = PoemGalleryDataManager.Instance.GetGalleryDataById(_galleryIds[index]);
  181. PoemGalleryData data = _galleryDatas[index];
  182. UI_ListItem item = UI_ListItem.Proxy(obj);
  183. if (item.m_loaIcon.data == null)
  184. {
  185. item.m_loaIcon.onClick.Add(OnLoaIconClick);
  186. }
  187. item.m_loaIcon.data = data;
  188. if (item.m_btnCollect.data == null)
  189. {
  190. item.m_btnCollect.onClick.Add(OnBtnCollectClick);
  191. }
  192. item.m_btnCollect.data = data;
  193. if (item.m_btnVote.data == null)
  194. {
  195. item.m_btnVote.onClick.Add(OnBtnVoteClick);
  196. }
  197. item.m_btnVote.data = data;
  198. UI_ListItem.ProxyEnd();
  199. }
  200. private void RenderListRankItem(int index, GObject obj)
  201. {
  202. }
  203. private void OnLoaIconClick(EventContext context)
  204. {
  205. GObject obj = context.data as GObject;
  206. PoemGalleryData data = obj.data as PoemGalleryData;
  207. }
  208. private void OnBtnCollectClick(EventContext context)
  209. {
  210. GObject obj = context.data as GObject;
  211. PoemGalleryData data = obj.data as PoemGalleryData;
  212. }
  213. private void OnBtnVoteClick(EventContext context)
  214. {
  215. GObject obj = context.data as GObject;
  216. PoemGalleryData data = obj.data as PoemGalleryData;
  217. }
  218. private void onPullDownRelease()
  219. {
  220. GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header;
  221. Controller controller = header.GetController("c1");
  222. controller.selectedIndex = 1;
  223. _ui.m_comNormal.m_listRecommend.scrollPane.LockHeader(header.sourceHeight);
  224. Timers.inst.Add(2, 1, (object param) =>
  225. {
  226. controller.selectedIndex = 2;
  227. _ui.m_comNormal.m_listRecommend.scrollPane.LockHeader(0);
  228. });
  229. }
  230. private void OnSizeChanged()
  231. {
  232. GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header;
  233. Controller controller = _ui.m_comNormal.m_listRecommend.scrollPane.header.GetController("c1");
  234. if (header.height <= 1)
  235. {
  236. controller.selectedIndex = 0;
  237. }
  238. }
  239. }
  240. }