PoemGalleryView.cs 18 KB

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