PoemGalleryView.cs 27 KB

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