PoemGalleryView.cs 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. using System.Collections.Generic;
  2. using ET;
  3. using FairyGUI;
  4. using UI.Poem;
  5. using UnityEngine;
  6. namespace GFGGame
  7. {
  8. class TabType
  9. {
  10. /// <summary>
  11. /// 首页
  12. /// </summary>
  13. public static int RECOVER = 0;
  14. /// <summary>
  15. /// 投稿
  16. /// </summary>
  17. public static int JOIN = 1;
  18. /// <summary>
  19. /// 收藏
  20. /// </summary>
  21. public static int FAVORITES = 2;
  22. }
  23. class RecommendType
  24. {
  25. /// <summary>
  26. /// 推荐
  27. /// </summary>
  28. public static int RECOMMEND = 0;
  29. /// <summary>
  30. /// 好友
  31. /// </summary>
  32. public static int FRIEND = 1;
  33. /// <summary>
  34. /// 排行榜
  35. /// </summary>
  36. public static int RANK = 2;
  37. }
  38. class FavoritesType
  39. {
  40. /// <summary>
  41. /// 我的收藏
  42. /// </summary>
  43. public static int FAVORITE = 0;
  44. /// <summary>
  45. /// 我的作品
  46. /// </summary>
  47. public static int MY_SELF = 1;
  48. }
  49. public class PoemGalleryView : BaseWindow
  50. {
  51. private UI_PoemGalleryUI _ui;
  52. private GList _list;
  53. private GList _list1;
  54. private GComponent _comScroll;
  55. // private List<PoemGalleryData> _galleryDatas = new List<PoemGalleryData>();
  56. private List<long> _galleryDatas = new List<long>();
  57. private int _sortType = 0;//由GallerySortType定义
  58. private int _lastListCount = 0;
  59. private int _lastList1Count = 0;
  60. private int _lastGalleryDatasCount = 0;
  61. private int _tabIndex = 0;//当前选中大页签下标,首页0投稿1收藏2
  62. private int _subtabIndex = 0;//当前选中小页签下标,推荐0好友1排行榜2;我的收藏0我的作品1
  63. private bool isPullDown = false;//是否下拉刷新中,刷新中再次下拉不会重新请求更新数据
  64. private bool isPullUp = false;//是否上拉刷新中,刷新中再次下拉不会重新请求更新数据
  65. public override void Dispose()
  66. {
  67. if (_ui != null)
  68. {
  69. _ui.Dispose();
  70. _ui = null;
  71. }
  72. base.Dispose();
  73. }
  74. protected override void OnInit()
  75. {
  76. base.OnInit();
  77. packageName = UI_PoemGalleryUI.PACKAGE_NAME;
  78. _ui = UI_PoemGalleryUI.Create();
  79. this.viewCom = _ui.target;
  80. isfullScreen = true;
  81. _ui.m_loaBg.url = ResPathUtil.GetBgImgPath("hc_bj_1");
  82. _ui.m_comNormal.m_comBoBox.items = new string[] { "推荐", "最新" };
  83. _ui.m_comNormal.m_comBoBox.icons = new string[] { "ui://Poem/hl_pxpx", "ui://Poem/hl_zxzx" };
  84. _ui.m_comNormal.m_comBoBox.onChanged.Add(OnNormalTabChange);
  85. _ui.m_btnback.onClick.Add(OnBtnBackClick);
  86. _ui.m_btnRecover.onClick.Add(OnBtnRecoverClick);
  87. _ui.m_btnJoin.onClick.Add(OnBtnJoinClick);
  88. _ui.m_btnFavorites.onClick.Add(OnBtnFavoritesClick);
  89. _ui.m_comNormal.m_comScroll.target.scrollPane.onPullDownRelease.Add(onPullDownRelease);
  90. _ui.m_comNormal.m_comScroll.target.scrollPane.onPullUpRelease.Add(OnPullUpToRefresh);
  91. _ui.m_comFavorites.m_comScroll.target.scrollPane.onPullDownRelease.Add(onPullDownRelease);
  92. _ui.m_comFavorites.m_comScroll.target.scrollPane.onPullUpRelease.Add(OnPullUpToRefresh);
  93. _ui.m_comNormal.m_comScroll.m_listRecommend.itemRenderer = RenderListItem;
  94. _ui.m_comNormal.m_comScroll.m_listRecommend1.itemRenderer = RenderListItem1;
  95. _ui.m_comFavorites.m_comScroll.m_listRecommend.itemRenderer = RenderListItem;
  96. _ui.m_comFavorites.m_comScroll.m_listRecommend1.itemRenderer = RenderListItem1;
  97. _ui.m_comNormal.m_listRank.itemRenderer = RenderListRankItem;
  98. // _ui.m_comNormal.m_listRank.SetVirtual();
  99. _ui.m_comNormal.m_btnShop.onClick.Add(OnBtnShopClick);
  100. _ui.m_comNormal.m_btnReward.onClick.Add(OnBtnRewardClick);
  101. _ui.m_comNormal.m_c1.onChanged.Add(OnNormalTabChange);
  102. _ui.m_comFavorites.m_c1.onChanged.Add(OnFavoritesTabChange);
  103. }
  104. protected override void AddEventListener()
  105. {
  106. base.AddEventListener();
  107. EventAgent.AddEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  108. EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH_ONE, UpdateGalleryList);
  109. EventAgent.AddEventListener(ConstMessage.DOWNLOAD_FINISH_ONE, UpdateGalleryRankList);
  110. }
  111. protected override async void OnShown()
  112. {
  113. base.OnShown();
  114. if (this.viewData != null)
  115. {
  116. _tabIndex = (int)(this.viewData as object[])[0];
  117. _subtabIndex = (int)(this.viewData as object[])[1];
  118. _ui.m_comNormal.m_comBoBox.selectedIndex = (int)(this.viewData as object[])[2];
  119. UpdateList();
  120. UpdateGalleryList();
  121. UpdateGalleryRankList();
  122. if (_tabIndex == TabType.RECOVER)
  123. {
  124. _ui.m_comNormal.m_c1.selectedIndex = _subtabIndex;
  125. }
  126. else if (_tabIndex == TabType.FAVORITES)
  127. {
  128. _ui.m_comFavorites.m_c1.selectedIndex = _subtabIndex;
  129. }
  130. }
  131. else
  132. {
  133. _tabIndex = TabType.RECOVER;
  134. _subtabIndex = RecommendType.RECOMMEND;
  135. _ui.m_comNormal.m_comBoBox.selectedIndex = 0;
  136. _ui.m_comNormal.m_c1.selectedIndex = _subtabIndex;
  137. _ui.m_comFavorites.m_c1.selectedIndex = _subtabIndex;
  138. _comScroll = _ui.m_comNormal.m_comScroll.target;
  139. if (_ui.m_comNormal.m_comScroll.m_listRecommend.numItems > 0) _ui.m_comNormal.m_comScroll.m_listRecommend.ScrollToView(0);
  140. if (_ui.m_comNormal.m_comScroll.m_listRecommend1.numItems > 0) _ui.m_comNormal.m_comScroll.m_listRecommend1.ScrollToView(0);
  141. if (_ui.m_comFavorites.m_comScroll.m_listRecommend.numItems > 0) _ui.m_comFavorites.m_comScroll.m_listRecommend.ScrollToView(0);
  142. if (_ui.m_comFavorites.m_comScroll.m_listRecommend1.numItems > 0) _ui.m_comFavorites.m_comScroll.m_listRecommend1.ScrollToView(0);
  143. _ui.m_comNormal.m_comScroll.m_listRecommend.numItems = 0;
  144. _ui.m_comNormal.m_comScroll.m_listRecommend1.numItems = 0;
  145. _ui.m_comFavorites.m_comScroll.m_listRecommend.numItems = 0;
  146. _ui.m_comFavorites.m_comScroll.m_listRecommend1.numItems = 0;
  147. // OnFavoritesTabChange();
  148. // OnNormalTabChange();
  149. // _ui.m_comNormal.m_comOpenLoad.target.visible = true;
  150. ViewManager.Show<ModalStatusView>();
  151. UpdateList();
  152. PullDown();
  153. onPullDownRelease();
  154. }
  155. _ui.m_c1.selectedIndex = _tabIndex;
  156. UpdateView();
  157. if (PoemGalleryDataManager.Instance.HasBonus)
  158. {
  159. bool result = await PoemGallerySProxy.ReqGetGalleryRankBonus();
  160. if (result && PoemGalleryDataManager.Instance.MyWorksRanks.Count > 0)
  161. {
  162. ViewManager.Show<PoemGalleryRewardGetView>();
  163. }
  164. }
  165. }
  166. protected override void OnHide()
  167. {
  168. base.OnHide();
  169. ResetPullRelease();
  170. _ui.m_comNormal.m_comBoBox.selectedIndex = 0;
  171. }
  172. protected override void RemoveEventListener()
  173. {
  174. base.RemoveEventListener();
  175. EventAgent.RemoveEventListener(ConstMessage.GALLERY_DATA_CHANGE, UpdateGalleryList);
  176. EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH_ONE, UpdateGalleryList);
  177. EventAgent.RemoveEventListener(ConstMessage.DOWNLOAD_FINISH_ONE, UpdateGalleryRankList);
  178. }
  179. private void OnBtnBackClick()
  180. {
  181. ViewManager.GoBackFrom(typeof(PoemGalleryView).FullName);
  182. }
  183. /// <summary>
  184. /// 积分商店
  185. /// </summary>
  186. private void OnBtnShopClick()
  187. {
  188. object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex };
  189. ViewManager.Show<GalleryShopView>(new object[] { ConstStoreId.GALLERY_STORE_ID }, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }, true);
  190. }
  191. /// <summary>
  192. /// 排行榜奖励
  193. /// </summary>
  194. private void OnBtnRewardClick()
  195. {
  196. ViewManager.Show<PoemGalleryRewardView>(null, new object[] { typeof(PoemGalleryView).FullName, this.viewData });
  197. }
  198. /********************************************************页签切换*************************************************/
  199. /// <summary>
  200. /// 首页
  201. /// </summary>
  202. private void OnBtnRecoverClick()
  203. {
  204. int lastTabIndex = _tabIndex;
  205. _tabIndex = _ui.m_c1.selectedIndex;
  206. _subtabIndex = _ui.m_comNormal.m_c1.selectedIndex;
  207. if (lastTabIndex == TabType.RECOVER)//当前在推荐页要刷新
  208. {
  209. if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.RECOMMEND)//重新拉取数据
  210. {
  211. PullDown();
  212. onPullDownRelease();
  213. }
  214. else//切页签并重新拉取数据
  215. {
  216. _ui.m_comNormal.m_c1.selectedIndex = RecommendType.RECOMMEND;
  217. }
  218. }
  219. else//更新列表
  220. {
  221. _ui.m_comNormal.m_c1.selectedIndex = RecommendType.RECOMMEND;
  222. UpdateList();
  223. UpdateGalleryList();
  224. }
  225. }
  226. /// <summary>
  227. /// 投稿
  228. /// </summary>
  229. private void OnBtnJoinClick()
  230. {
  231. object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex };
  232. ViewManager.Show<DressUpView>(1, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas }, true);
  233. }
  234. /// <summary>
  235. ///收藏夹
  236. /// </summary>
  237. private void OnBtnFavoritesClick()
  238. {
  239. if (_tabIndex == TabType.FAVORITES) return;
  240. ResetPullRelease();
  241. _tabIndex = _ui.m_c1.selectedIndex;
  242. _ui.m_comFavorites.m_c1.selectedIndex = FavoritesType.FAVORITE;
  243. _subtabIndex = _ui.m_comFavorites.m_c1.selectedIndex;
  244. OnFavoritesTabChange();
  245. }
  246. /// <summary>
  247. /// 切换首页页签
  248. /// </summary>
  249. private void OnNormalTabChange()
  250. {
  251. ResetPullRelease();
  252. _ui.m_comNormal.m_comScroll.target.scrollPane.header.visible = false;
  253. _subtabIndex = _ui.m_comNormal.m_c1.selectedIndex;
  254. if (_ui.m_comNormal.m_c1.selectedIndex == RecommendType.RANK)//排行榜
  255. {
  256. _galleryDatas = PoemGalleryDataManager.Instance.RankDatas;
  257. ReqGalleryRankList();
  258. }
  259. else
  260. {
  261. UpdateList();
  262. if (_list.numItems > 0) _list.ScrollToView(0);
  263. if (_list1.numItems > 0) _list.ScrollToView(0);
  264. _list.numItems = 0;
  265. _list1.numItems = 0;
  266. ReqGalleryList(0);
  267. }
  268. }
  269. private void UpdateList()
  270. {
  271. if (_tabIndex == TabType.RECOVER)
  272. {
  273. if (_subtabIndex == RecommendType.RECOMMEND)//首页
  274. {
  275. _ui.m_comNormal.m_comScroll.target.scrollPane.header.visible = true;
  276. if (_ui.m_comNormal.m_comBoBox.selectedIndex == 0)//推荐
  277. {
  278. _sortType = (int)GallerySortType.Recommend;
  279. _galleryDatas = PoemGalleryDataManager.Instance.RecommendDatas;
  280. }
  281. else//最新
  282. {
  283. _sortType = (int)GallerySortType.Newest;
  284. _galleryDatas = PoemGalleryDataManager.Instance.NewestDatas;
  285. }
  286. }
  287. else if (_subtabIndex == RecommendType.FRIEND)//好友
  288. {
  289. _sortType = (int)GallerySortType.Friend;
  290. _galleryDatas = PoemGalleryDataManager.Instance.FrinedDatas;
  291. }
  292. else if (_subtabIndex == RecommendType.RANK)
  293. {
  294. _galleryDatas = PoemGalleryDataManager.Instance.RankDatas;
  295. }
  296. _list = _ui.m_comNormal.m_comScroll.m_listRecommend;
  297. _list1 = _ui.m_comNormal.m_comScroll.m_listRecommend1;
  298. _comScroll = _ui.m_comNormal.m_comScroll.target;
  299. }
  300. else if (_tabIndex == TabType.FAVORITES)
  301. {
  302. if (_subtabIndex == FavoritesType.FAVORITE)//我的收藏
  303. {
  304. _sortType = (int)GallerySortType.MyCollect;
  305. _galleryDatas = PoemGalleryDataManager.Instance.FavoriteDatas;
  306. }
  307. else if (_subtabIndex == FavoritesType.MY_SELF)//我的作品
  308. {
  309. _sortType = (int)GallerySortType.MyWorks;
  310. _galleryDatas = PoemGalleryDataManager.Instance.MySelfDatas;
  311. }
  312. _list = _ui.m_comFavorites.m_comScroll.m_listRecommend;
  313. _list1 = _ui.m_comFavorites.m_comScroll.m_listRecommend1;
  314. _comScroll = _ui.m_comFavorites.m_comScroll.target;
  315. }
  316. }
  317. /// <summary>
  318. /// 切换收藏页签
  319. /// </summary>
  320. private void OnFavoritesTabChange()
  321. {
  322. _ui.m_comFavorites.m_comScroll.target.scrollPane.header.visible = false;
  323. _subtabIndex = _ui.m_comFavorites.m_c1.selectedIndex;
  324. UpdateList();
  325. if (_list.numItems > 0) _list.ScrollToView(0);
  326. if (_list1.numItems > 0) _list.ScrollToView(0);
  327. ReqGalleryList(0);
  328. }
  329. /********************************************************请求更新列表*************************************************/
  330. private void onScrollEnd()
  331. {
  332. GComponent header = _comScroll.scrollPane.header;
  333. if (!header.visible || header.height >= header.sourceHeight || isPullDown) return;
  334. if (_comScroll.scrollPane.percY == 1)
  335. {
  336. ReqGalleryList(_galleryDatas.Count);
  337. // PullUp();
  338. // OnPullUpToRefresh();
  339. }
  340. }
  341. //请求刷新
  342. private async void ReqGalleryList(int startIndex)
  343. {
  344. if (PoemGalleryDataManager.Instance.IsResulting())
  345. {
  346. if (_sortType == (int)GallerySortType.Recommend || _sortType == (int)GallerySortType.Newest || _sortType == (int)GallerySortType.Friend)
  347. {
  348. return;
  349. }
  350. }
  351. bool result = await PoemGallerySProxy.ReqGalleryList(_sortType, startIndex, PoemGalleryDataManager.pageCount);
  352. if (result)
  353. {
  354. Timers.inst.StartCoroutine(PictureStorageHelper.Download(_galleryDatas, startIndex, UpdateGalleryList));
  355. }
  356. }
  357. private void UpdateGalleryList()
  358. {
  359. if (_tabIndex == TabType.RECOVER && _subtabIndex == RecommendType.RANK)
  360. {
  361. _ui.m_comNormal.m_listRank.numItems = _galleryDatas.Count;
  362. }
  363. else
  364. {
  365. if (_galleryDatas.Count % 2 == 0)
  366. {
  367. _list.numItems = _galleryDatas.Count / 2;
  368. _list1.numItems = _galleryDatas.Count / 2;
  369. }
  370. else
  371. {
  372. _list.numItems = (_galleryDatas.Count + 1) / 2;
  373. _list1.numItems = (_galleryDatas.Count - 1) / 2;
  374. }
  375. _list.ResizeToFit();
  376. _list1.ResizeToFit();
  377. }
  378. UpdateView();
  379. ResetPullRelease();
  380. }
  381. //请求排行榜刷新
  382. private async void ReqGalleryRankList()
  383. {
  384. if (PoemGalleryDataManager.Instance.IsResulting())
  385. {
  386. return;
  387. }
  388. bool result = await PoemGallerySProxy.ReqRankList();
  389. if (result)
  390. {
  391. Timers.inst.StartCoroutine(PictureStorageHelper.Download(_galleryDatas, 0, UpdateGalleryRankList));
  392. }
  393. }
  394. private void UpdateGalleryRankList()
  395. {
  396. if (_tabIndex != TabType.RECOVER || _subtabIndex != RecommendType.RANK) return;
  397. if (_ui.m_comNormal.m_listRank.numItems > 0) _ui.m_comNormal.m_listRank.ScrollToView(0);
  398. _ui.m_comNormal.m_listRank.numItems = _galleryDatas.Count;
  399. UpdateView();
  400. }
  401. /********************************************************界面更新*************************************************/
  402. private void UpdateView()
  403. {
  404. bool isResulting = PoemGalleryDataManager.Instance.IsResulting();
  405. _ui.m_comNormal.m_grpResult.visible = isResulting;
  406. _ui.m_comNormal.m_comScroll.target.visible = !isResulting;
  407. _ui.m_comNormal.m_listRank.visible = !isResulting;
  408. GalleryThemeCfg themeCfg = GalleryThemeCfgArray.Instance.GetCfg((int)PoemGalleryDataManager.Instance.ThemeId);
  409. _ui.m_comNormal.m_txtTheme.text = string.Format("本期主题:{0}", themeCfg.theme);
  410. _ui.m_comNormal.m_txtRank.text = string.Format("我的排名: {0}", PoemGalleryDataManager.Instance.MyRank > 0 && !isResulting ? PoemGalleryDataManager.Instance.MyRank.ToString() : "- -");
  411. int curCount = GameGlobal.myNumericComponent.GetAsInt(NumericType.LikeGalleryWorksCountDaily);
  412. int maxCount = GalleryIntegralCfgArray.Instance.dataArray.Length;
  413. _ui.m_comNormal.m_txtRewardCount.text = string.Format("奖励次数:{0}/{1}", Mathf.Min(curCount, maxCount), maxCount);
  414. _ui.m_comNormal.m_txtTime.text = string.Format("截止日期:{0}", PoemGalleryDataManager.Instance.GetThemeTime());
  415. }
  416. private void RenderListItem(int index, GObject obj)
  417. {
  418. long workId = _galleryDatas[index * 2];
  419. UpdateListItem(workId, obj);
  420. }
  421. private void RenderListItem1(int index, GObject obj)
  422. {
  423. long workId = _galleryDatas[index * 2 + 1];
  424. UpdateListItem(workId, obj);
  425. }
  426. private void UpdateListItem(long workId, GObject obj)
  427. {
  428. PoemGalleryData data = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  429. UI_ListItem item = UI_ListItem.Proxy(obj);
  430. item.m_c1.selectedIndex = 0;
  431. if (data.Ntexture == null) return;
  432. item.m_c1.selectedIndex = 1;
  433. item.m_loaIcon.texture = data.Ntexture;
  434. item.m_loaIcon.height = item.m_loaIcon.width * item.m_loaIcon.texture.height / item.m_loaIcon.texture.width;
  435. item.m_txtName.text = data.AuthorName;
  436. item.m_btnCollect.title = data.CollectCount.ToString();
  437. item.m_btnCollect.selected = data.CollectOrNot;
  438. item.m_btnVote.title = data.VoteCount.ToString();
  439. item.m_btnVote.selected = data.VoteOrNot;
  440. if (item.m_loaIcon.data == null)
  441. {
  442. item.m_loaIcon.onClick.Add(OnLoaIconClick);
  443. }
  444. item.m_loaIcon.data = workId;
  445. if (item.m_btnCollect.data == null)
  446. {
  447. item.m_btnCollect.onClick.Add(OnBtnCollectClick);
  448. }
  449. item.m_btnCollect.data = workId;
  450. if (item.m_btnVote.data == null)
  451. {
  452. item.m_btnVote.onClick.Add(OnBtnVoteClick);
  453. }
  454. item.m_btnVote.data = workId;
  455. UI_ListItem.ProxyEnd();
  456. }
  457. private void RenderListRankItem(int index, GObject obj)
  458. {
  459. long workId = _galleryDatas[index];
  460. PoemGalleryData data = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  461. UI_ListRankItem item = UI_ListRankItem.Proxy(obj);
  462. if (data.Ntexture == null) return;
  463. item.m_loaIcon.texture = data.Ntexture;
  464. item.m_loaIcon.height = item.m_loaIcon.width * item.m_loaIcon.texture.height / item.m_loaIcon.texture.width;
  465. item.m_txtName.text = data.AuthorName;
  466. item.m_btnCollect.title = data.CollectCount.ToString();
  467. item.m_btnCollect.selected = data.CollectOrNot;
  468. item.m_btnVote.title = data.VoteCount.ToString();
  469. item.m_btnVote.selected = data.VoteOrNot;
  470. item.m_txtRank.text = data.Rank.ToString();
  471. item.m_c1.selectedIndex = index < 3 ? index : 3;
  472. if (item.m_loaIcon.data == null)
  473. {
  474. item.m_loaIcon.onClick.Add(OnLoaIconClick);
  475. }
  476. item.m_loaIcon.data = workId;
  477. if (item.m_btnCollect.data == null)
  478. {
  479. item.m_btnCollect.onClick.Add(OnBtnCollectClick);
  480. }
  481. item.m_btnCollect.data = workId;
  482. if (item.m_btnVote.data == null)
  483. {
  484. item.m_btnVote.onClick.Add(OnBtnVoteClick);
  485. }
  486. item.m_btnVote.data = workId;
  487. UI_ListRankItem.ProxyEnd();
  488. }
  489. private void OnLoaIconClick(EventContext context)
  490. {
  491. GObject obj = context.sender as GObject;
  492. long workId = (long)obj.data;
  493. object[] gobackParamDatas = new object[] { _tabIndex, _subtabIndex, _ui.m_comNormal.m_comBoBox.selectedIndex };
  494. ViewManager.Show<PoemGalleryPreviewView>(new object[] { _sortType, workId }, new object[] { typeof(PoemGalleryView).FullName, gobackParamDatas });
  495. }
  496. private async void OnBtnCollectClick(EventContext context)
  497. {
  498. GObject obj = context.sender as GObject;
  499. long workId = (long)obj.data;
  500. PoemGalleryData galleryData = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  501. if (galleryData.CollectOrNot)
  502. {
  503. bool result = await PoemGallerySProxy.ReqCancelCollecteGalleryWorks(workId);
  504. if (result)
  505. {
  506. if (_tabIndex == TabType.FAVORITES && _subtabIndex == FavoritesType.FAVORITE)
  507. {
  508. ReqGalleryList(0);//当前为收藏页要重新拉取数据
  509. }
  510. else
  511. {
  512. UpdateGalleryList();
  513. }
  514. }
  515. }
  516. else
  517. {
  518. bool result = await PoemGallerySProxy.ReqCollecteGalleryWorks(workId);
  519. if (result)
  520. {
  521. if (_tabIndex == TabType.FAVORITES && _subtabIndex == FavoritesType.FAVORITE)
  522. {
  523. ReqGalleryList(0);//当前为收藏页要重新拉取数据
  524. }
  525. else
  526. {
  527. UpdateGalleryList();
  528. }
  529. }
  530. }
  531. }
  532. private async void OnBtnVoteClick(EventContext context)
  533. {
  534. GButton obj = context.sender as GButton;
  535. long workId = (long)obj.data;
  536. PoemGalleryData galleryData = PoemGalleryDataManager.Instance.GetGalleryDataById(workId);
  537. if (galleryData.VoteOrNot) return;
  538. if (PoemGalleryDataManager.Instance.IsResulting())
  539. {
  540. obj.selected = galleryData.VoteOrNot;
  541. PromptController.Instance.ShowFloatTextPrompt("排行榜数据正在结算,无法操作");
  542. return;
  543. }
  544. if (!PoemGalleryDataManager.Instance.IsCurThemeWork(galleryData.CreateTime))
  545. {
  546. obj.selected = galleryData.VoteOrNot;
  547. PromptController.Instance.ShowFloatTextPrompt("往期作品,无法操作");
  548. return;
  549. }
  550. bool result = await PoemGallerySProxy.ReqVoteGalleryWorks(workId);
  551. if (result)
  552. {
  553. UpdateGalleryList();
  554. int Count = GameGlobal.myNumericComponent.GetAsInt(NumericType.LikeGalleryWorksCountDaily);
  555. GalleryIntegralCfg integralCfg = GalleryIntegralCfgArray.Instance.GetCfg(Count);
  556. if (integralCfg != null)
  557. {
  558. ItemCfg itemCfg = ItemCfgArray.Instance.GetCfg(integralCfg.itemId);
  559. PromptController.Instance.ShowFloatTextPrompt(string.Format("{0} +{1}", itemCfg.name, integralCfg.Count));
  560. }
  561. }
  562. }
  563. /********************************************************下拉刷新*************************************************/
  564. //自动下拉
  565. private void PullDown()
  566. {
  567. if (_list.numItems > 0) _list.ScrollToView(0);
  568. GComponent header = _comScroll.scrollPane.header;
  569. header.height = header.sourceHeight;
  570. }
  571. //下拉刷新
  572. private async void onPullDownRelease()
  573. {
  574. GComponent header = _comScroll.scrollPane.header;
  575. if (!header.visible || header.height < header.sourceHeight || isPullDown) return;
  576. isPullDown = true;
  577. _comScroll.scrollPane.LockHeader(header.sourceHeight);
  578. bool result = await PoemGallerySProxy.ReqGalleryList(_sortType, 0, PoemGalleryDataManager.pageCount);
  579. // OnPullDownTimeComplete();
  580. if (result)
  581. {
  582. Timers.inst.StartCoroutine(PictureStorageHelper.Download(_galleryDatas, 0, UpdateGalleryList));
  583. }
  584. }
  585. private void OnPullDownTimeComplete()
  586. {
  587. if (_comScroll == null) return;
  588. GComponent header = _comScroll.scrollPane.header;
  589. Transition transition = header.GetTransition("t0");
  590. transition.Stop();
  591. header.height = 1;
  592. _comScroll.scrollPane.LockHeader(0);
  593. isPullDown = false;
  594. }
  595. //自动上拉
  596. private void PullUp()
  597. {
  598. GComponent header = _comScroll.scrollPane.footer;
  599. header.height = header.sourceHeight;
  600. }
  601. //上拉刷新
  602. private async void OnPullUpToRefresh()
  603. {
  604. GComponent header = _comScroll.scrollPane.header;
  605. if (!header.visible || header.height >= header.sourceHeight || isPullDown) return;
  606. GComponent footer = _comScroll.scrollPane.footer;
  607. if (footer.height < footer.sourceHeight || isPullUp) return;
  608. // _lastListCount = _list.numItems;
  609. // _lastList1Count = _list1.numItems;
  610. _lastGalleryDatasCount = _galleryDatas.Count;
  611. isPullUp = true;
  612. _comScroll.scrollPane.LockFooter(footer.sourceHeight + 10);
  613. bool result = await PoemGallerySProxy.ReqGalleryList(_sortType, _galleryDatas.Count, PoemGalleryDataManager.pageCount);
  614. // OnPullUpTimeComplete();
  615. if (result)
  616. {
  617. Timers.inst.StartCoroutine(PictureStorageHelper.Download(_galleryDatas, _lastGalleryDatasCount, UpdateGalleryList));
  618. }
  619. }
  620. private void OnPullUpTimeComplete()
  621. {
  622. if (_comScroll == null) return;
  623. GComponent footer = _comScroll.scrollPane.footer;
  624. Transition transition = footer.GetTransition("t0");
  625. transition.Stop();
  626. // header.GetController("c1").selectedIndex = 2;
  627. _comScroll.scrollPane.LockFooter(0);
  628. isPullUp = false;
  629. }
  630. //重置上拉/下拉刷新状态
  631. private void ResetPullRelease()
  632. {
  633. // Timers.inst.Remove(OnPullDownTimeComplete);
  634. OnPullDownTimeComplete();
  635. // Timers.inst.Remove(OnPullUpTimeComplete);
  636. OnPullUpTimeComplete();
  637. // _ui.m_comNormal.m_comOpenLoad.target.visible = false;
  638. ViewManager.Hide<ModalStatusView>();
  639. }
  640. }
  641. }