PoemGalleryView.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  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. private int _tabIndex = 0;//当前选中大页签下标,首页0投稿1收藏2
  16. private int _subtabIndex = 0;//当前选中小页签下标,推荐0好友1排行榜2;我的收藏0我的作品1
  17. public override void Dispose()
  18. {
  19. if (_ui != null)
  20. {
  21. _ui.Dispose();
  22. _ui = null;
  23. }
  24. base.Dispose();
  25. }
  26. protected override void OnInit()
  27. {
  28. base.OnInit();
  29. packageName = UI_PoemGalleryUI.PACKAGE_NAME;
  30. _ui = UI_PoemGalleryUI.Create();
  31. this.viewCom = _ui.target;
  32. isfullScreen = true;
  33. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  34. _ui.m_comNormal.m_comBoBox.items = new string[] { "推荐", "最新" };
  35. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  36. _ui.m_btnRecover.onClick.Add(OnBtnRecoverClick);
  37. _ui.m_btnJoin.onClick.Add(OnBtnJoinClick);
  38. _ui.m_btnFavorites.onClick.Add(OnBtnFavoritesClick);
  39. _ui.m_comNormal.m_listRecommend.itemRenderer = RenderListItem;
  40. _ui.m_comNormal.m_listRecommend.SetVirtual();
  41. _ui.m_comNormal.m_listRecommend.scrollPane.onPullDownRelease.Add(onPullDownRelease);
  42. _ui.m_comNormal.m_listRecommend.scrollPane.onScroll.Add(onScroll);
  43. _ui.m_comNormal.m_listFriend.itemRenderer = RenderListItem;
  44. _ui.m_comNormal.m_listFriend.SetVirtual();
  45. _ui.m_comNormal.m_listFriend.scrollPane.onScroll.Add(onScroll);
  46. _ui.m_comNormal.m_listRank.itemRenderer = RenderListRankItem;
  47. _ui.m_comNormal.m_listRank.SetVirtual();
  48. _ui.m_comNormal.m_listRank.scrollPane.onScroll.Add(onScroll);
  49. _ui.m_comFavorites.m_listFavorite.itemRenderer = RenderListItem;
  50. _ui.m_comFavorites.m_listFavorite.SetVirtual();
  51. _ui.m_comFavorites.m_listFavorite.scrollPane.onScroll.Add(onScroll);
  52. _ui.m_comFavorites.m_listMySelf.itemRenderer = RenderListItem;
  53. _ui.m_comFavorites.m_listMySelf.SetVirtual();
  54. _ui.m_comFavorites.m_listMySelf.scrollPane.onScroll.Add(onScroll);
  55. _ui.m_comNormal.m_btnShop.onClick.Add(OnBtnShopClick);
  56. _ui.m_comNormal.m_btnReward.onClick.Add(OnBtnRewardClick);
  57. // _ui.m_c1.onChanged.Add(OnTabChange);
  58. _ui.m_comNormal.m_c1.onChanged.Add(OnNormalTabChange);
  59. _ui.m_comFavorites.m_c1.onChanged.Add(OnFavoritesTabChange);
  60. }
  61. protected override void AddEventListener()
  62. {
  63. base.AddEventListener();
  64. EventAgent.AddEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  65. EventAgent.AddEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList);
  66. }
  67. protected override void OnShown()
  68. {
  69. base.OnShown();
  70. _tabIndex = 0;
  71. _subtabIndex = 0;
  72. if (this.viewData != null)
  73. {
  74. _tabIndex = (int)(this.viewData as object[])[0];
  75. _subtabIndex = (int)(this.viewData as object[])[1];
  76. }
  77. _ui.m_c1.selectedIndex = _tabIndex;
  78. if (_tabIndex == 0)
  79. {
  80. _ui.m_comNormal.m_c1.selectedIndex = _subtabIndex;
  81. OnNormalTabChange();
  82. }
  83. else if (_tabIndex == 2)
  84. {
  85. _ui.m_comFavorites.m_c1.selectedIndex = _subtabIndex;
  86. OnFavoritesTabChange();
  87. }
  88. _list = _ui.m_comNormal.m_listRecommend;
  89. _list.numItems = 10;
  90. UpdateView();
  91. }
  92. protected override void OnHide()
  93. {
  94. base.OnHide();
  95. ResetPullDownRelease();
  96. _ui.m_comNormal.m_comBoBox.selectedIndex = 0;
  97. }
  98. protected override void RemoveEventListener()
  99. {
  100. base.RemoveEventListener();
  101. EventAgent.RemoveEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  102. EventAgent.RemoveEventListener(ConstMessage.GALLERY_RANK_DATA_CHANGE, UpdateGalleryRankList);
  103. }
  104. private void OnBtnBackClick()
  105. {
  106. ViewManager.GoBackFrom(typeof(PoemGalleryView).FullName);
  107. }
  108. /// <summary>
  109. /// 首页
  110. /// </summary>
  111. private void OnBtnRecoverClick()
  112. {
  113. _tabIndex = _ui.m_c1.selectedIndex;
  114. if (_ui.m_comNormal.m_c1.selectedIndex == 0)
  115. {
  116. onPullDownRelease();
  117. // OnNormalTabChange();//每次点首页都要刷新
  118. }
  119. else
  120. {
  121. _ui.m_comNormal.m_c1.selectedIndex = 0;
  122. }
  123. }
  124. /// <summary>
  125. /// 投稿
  126. /// </summary>
  127. private void OnBtnJoinClick()
  128. {
  129. // int tabIndex = _ui.m_c1.selectedIndex;
  130. // int subType = _ui.m_c1.selectedIndex
  131. object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex };
  132. ViewManager.Show<DressUpView>(1, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }, true);
  133. }
  134. /// <summary>
  135. ///收藏夹
  136. /// </summary>
  137. private void OnBtnFavoritesClick()
  138. {
  139. _tabIndex = _ui.m_c1.selectedIndex;
  140. if (_ui.m_comFavorites.m_c1.selectedIndex != 0)
  141. {
  142. _ui.m_comFavorites.m_c1.selectedIndex = 0;
  143. }
  144. ResetPullDownRelease();
  145. }
  146. // /// <summary>
  147. // /// 切换ui页签:首页,投稿,收藏
  148. // /// </summary>
  149. // private void OnTabChange()
  150. // {
  151. // if (_ui.m_c1.selectedIndex == 0)//刷新首页
  152. // {
  153. // if (_ui.m_comNormal.m_c1.selectedIndex == 0)
  154. // {
  155. // OnNormalTabChange();
  156. // }
  157. // else
  158. // {
  159. // _ui.m_comNormal.m_c1.selectedIndex = 0;
  160. // }
  161. // }
  162. // else if (_ui.m_c1.selectedIndex == 2)//刷新收藏页
  163. // {
  164. // if (_ui.m_comFavorites.m_c1.selectedIndex == 0)
  165. // {
  166. // OnFavoritesTabChange();
  167. // }
  168. // else
  169. // {
  170. // _ui.m_comFavorites.m_c1.selectedIndex = 0;
  171. // }
  172. // }
  173. // }
  174. /// <summary>
  175. /// 切换首页页签
  176. /// </summary>
  177. private void OnNormalTabChange()
  178. {
  179. ResetPullDownRelease();
  180. _subtabIndex = _ui.m_comNormal.m_c1.selectedIndex;
  181. if (_ui.m_comNormal.m_c1.selectedIndex == 2)//排行榜
  182. {
  183. }
  184. else
  185. {
  186. if (_ui.m_comNormal.m_c1.selectedIndex == 0)//首页
  187. {
  188. // _infoType = GalleryType.Recommend;
  189. if (_ui.m_comNormal.m_comBoBox.selectedIndex == 0)//推荐
  190. {
  191. _sortType = (int)GallerySortType.Recommend;
  192. _galleryDatas = PoemGalleryDataManager.Instance.RecommendDatas;
  193. }
  194. else//最新
  195. {
  196. _sortType = (int)GallerySortType.Newest;
  197. _galleryDatas = PoemGalleryDataManager.Instance.NewestDatas;
  198. }
  199. _list = _ui.m_comNormal.m_listRecommend;
  200. }
  201. else if (_ui.m_comNormal.m_c1.selectedIndex == 1)//好友
  202. {
  203. _sortType = (int)GallerySortType.Friend;
  204. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  205. _list = _ui.m_comNormal.m_listFriend;
  206. }
  207. if (_list.numItems > 0) _list.ScrollToView(0);
  208. ReqGalleryList(0);
  209. }
  210. }
  211. /// <summary>
  212. /// 切换收藏页签
  213. /// </summary>
  214. private void OnFavoritesTabChange()
  215. {
  216. _subtabIndex = _ui.m_comFavorites.m_c1.selectedIndex;
  217. if (_ui.m_comFavorites.m_c1.selectedIndex == 0)//我的收藏
  218. {
  219. _sortType = (int)GallerySortType.MyCollect;
  220. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  221. _list = _ui.m_comFavorites.m_listFavorite;
  222. }
  223. else if (_ui.m_comFavorites.m_c1.selectedIndex == 1)//我的作品
  224. {
  225. _sortType = (int)GallerySortType.MyWorks;
  226. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  227. _list = _ui.m_comFavorites.m_listMySelf;
  228. }
  229. if (_list.numItems > 0) _list.ScrollToView(0);
  230. ReqGalleryList(0);
  231. }
  232. //分页刷新
  233. private void onScroll()
  234. {
  235. if (_list == null) return;
  236. int itemIndex = _list.ChildIndexToItemIndex(0);
  237. int startIndex = itemIndex + 1;
  238. if (startIndex >= _list.numItems && startIndex % _pageCount == 0)
  239. {
  240. ReqGalleryList(startIndex);
  241. }
  242. }
  243. //请求刷新
  244. private void ReqGalleryList(int startIndex)
  245. {
  246. PoemGallerySProxy.ReqGalleryList(_sortType, startIndex, _pageCount).Coroutine();
  247. }
  248. private void UpdateGalleryList()
  249. {
  250. _list.numItems = _galleryDatas.Count;
  251. UpdateView();
  252. }
  253. private void UpdateGalleryRankList()
  254. {
  255. _ui.m_comNormal.m_listRank.numItems = _galleryDatas.Count;
  256. UpdateView();
  257. }
  258. /// <summary>
  259. /// 积分商店
  260. /// </summary>
  261. private void OnBtnShopClick()
  262. {
  263. object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex };
  264. ViewManager.Show<ClothingShopView>(new object[] { ConstStoreId.GALLERY_STORE_ID }, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }, true);
  265. }
  266. /// <summary>
  267. /// 排行榜奖励
  268. /// </summary>
  269. private void OnBtnRewardClick()
  270. {
  271. ViewManager.Show<PoemGalleryRewardView>(null, new object[] { typeof(PoemGalleryView).FullName, this.viewData });
  272. }
  273. private void UpdateView()
  274. {
  275. GalleryThemeCfg themeCfg = GalleryThemeCfgArray.Instance.GetCfg((int)PoemGalleryDataManager.Instance.ThemeId);
  276. _ui.m_comNormal.m_txtTheme.text = string.Format("本期主题:{0}", themeCfg.theme);
  277. long monday = TimeUtil.GetCurWeekMondayTime(GlobalCfgArray.globalCfg.refreshTime);//本周一5点
  278. long startTime = 0;
  279. long endTime = 0;
  280. if ((TimeInfo.Instance.ServerNow() / 1000) < monday)//本周一5点之前显示上周
  281. {
  282. startTime = TimeUtil.GetLastWeekMondayTime(GlobalCfgArray.globalCfg.refreshTime);
  283. endTime = TimeUtil.GetLastWeekSundayTime("23:59:59");
  284. }
  285. else
  286. {
  287. startTime = monday * 1000;
  288. endTime = TimeUtil.GetCurWeekSundayTime("23:59:59") * 1000; ;
  289. }
  290. string strStartTime = TimeUtil.FormattingTime3(startTime);
  291. string strEndTime = TimeUtil.FormattingTime3(endTime); ;
  292. _ui.m_comNormal.m_txtTime.text = string.Format("截止日期:{0}至{1}", strStartTime, strEndTime);
  293. _ui.m_comNormal.m_txtRank.text = string.Format("我的排名:{0}", PoemGalleryDataManager.Instance.MyRank);
  294. }
  295. private void RenderListItem(int index, GObject obj)
  296. {
  297. // PoemGalleryData data = _galleryDatas[index];
  298. UI_ListItem item = UI_ListItem.Proxy(obj);
  299. // item.m_loaIcon.height = 550 + Random.Range(40, 100);
  300. // if (index > 1)
  301. // {
  302. // item.target.y=
  303. // }
  304. // item.target.height = item.m_loaIcon.height + 80;
  305. // item.m_loaIcon.texture = data.Ntexture;
  306. // item.m_txtName.text = data.AuthorName;
  307. // item.m_btnCollect.title = data.CollectCount.ToString();
  308. // item.m_btnCollect.selected = data.CollectOrNot;
  309. // item.m_btnVote.title = data.VoteCount.ToString();
  310. // item.m_btnVote.selected = data.VoteOrNot;
  311. // if (item.m_loaIcon.data == null)
  312. // {
  313. // item.m_loaIcon.onClick.Add(OnLoaIconClick);
  314. // }
  315. // item.m_loaIcon.data = data;
  316. // if (item.m_btnCollect.data == null)
  317. // {
  318. // item.m_btnCollect.onClick.Add(OnBtnCollectClick);
  319. // }
  320. // item.m_btnCollect.data = data;
  321. // if (item.m_btnVote.data == null)
  322. // {
  323. // item.m_btnVote.onClick.Add(OnBtnVoteClick);
  324. // }
  325. // item.m_btnVote.data = data;
  326. UI_ListItem.ProxyEnd();
  327. }
  328. private void RenderListRankItem(int index, GObject obj)
  329. {
  330. }
  331. private void OnLoaIconClick(EventContext context)
  332. {
  333. GObject obj = context.data as GObject;
  334. PoemGalleryData data = obj.data as PoemGalleryData;
  335. }
  336. private void OnBtnCollectClick(EventContext context)
  337. {
  338. GObject obj = context.data as GObject;
  339. PoemGalleryData data = obj.data as PoemGalleryData;
  340. }
  341. private void OnBtnVoteClick(EventContext context)
  342. {
  343. GObject obj = context.data as GObject;
  344. PoemGalleryData data = obj.data as PoemGalleryData;
  345. }
  346. //下拉刷新
  347. private void onPullDownRelease()
  348. {
  349. // ReqGalleryList(0);
  350. GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header;
  351. if (header.height < header.sourceHeight) return;
  352. // Transition transition = header.GetTransition("t0");
  353. // transition.Play();
  354. // controller.selectedIndex = 1;
  355. _ui.m_comNormal.m_listRecommend.scrollPane.LockHeader(header.sourceHeight);
  356. Timers.inst.Add(2, 1, OnTimeComplete);
  357. }
  358. private void OnTimeComplete(object param)
  359. {
  360. GComponent header = _ui.m_comNormal.m_listRecommend.scrollPane.header;
  361. Transition transition = header.GetTransition("t0");
  362. transition.Stop();
  363. // header.GetController("c1").selectedIndex = 2;
  364. _ui.m_comNormal.m_listRecommend.scrollPane.LockHeader(0);
  365. }
  366. /// <summary>
  367. /// 重置下拉刷新状态
  368. /// </summary>
  369. private void ResetPullDownRelease()
  370. {
  371. Timers.inst.Remove(OnTimeComplete);
  372. OnTimeComplete(null);
  373. }
  374. }
  375. }