FashionShowHomePage.cs 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459
  1. using System.Collections.Generic;
  2. using UnityEngine;
  3. using UnityEngine.UI;
  4. public class FashionShowHomePage : Regist
  5. {
  6. #region Config
  7. private static Text HomeTabButtonText;
  8. private static Text CuteTabButtonText;
  9. private static Text GraceTabButtonText;
  10. private static Text VividTabButtonText;
  11. private static Text SimpleTabButtonText;
  12. private static Text GloryTabButtonText;
  13. private static Text MineTabButtonText;
  14. private static Text RecommendTitle;
  15. private static Button Return;
  16. private static Button HomeTabButton;
  17. private static Button CuteTabButton;
  18. private static Button GraceTabButton;
  19. private static Button VividTabButton;
  20. private static Button SimpleTabButton;
  21. private static Button GloryTabButton;
  22. private static Button MineTabButton;
  23. private static Image HomeBubble;
  24. private static Image CuteBubble;
  25. private static Image GraceBubble;
  26. private static Image VividBubble;
  27. private static Image SimpleBubble;
  28. private static Image GloryBubble;
  29. private static Image MineBubble;
  30. private static VirtualScrollRectPlus HomeScrollRect;
  31. private static VirtualScrollRectPlus CuteScrollRect;
  32. private static VirtualScrollRectPlus GraceScrollRect;
  33. private static VirtualScrollRectPlus VividScrollRect;
  34. private static VirtualScrollRectPlus SimpleScrollRect;
  35. private static VirtualScrollRectPlus GloryScrollRect;
  36. private static VirtualScrollRectPlus MineScrollRect;
  37. private static int currentDataIndex;
  38. private static int currentPage;
  39. private static bool requesting;
  40. private static ShowListHttp http;
  41. private static FashionShowType currentType;
  42. private static Button CurrentTabButton;
  43. private static VirtualScrollRectPlus CurrentScrollRect;
  44. private static List<GetFashionShowData> CurrentDatas = new List<GetFashionShowData>();
  45. private static Button OpenHomePageButton;
  46. private static Transform Panel;
  47. private static Transform SidePanel;
  48. private static List<Button> TabButtons = new List<Button>();
  49. private static List<Image> TabBubbles = new List<Image>();
  50. private static List<VirtualScrollRectPlus> ScrollRects = new List<VirtualScrollRectPlus>();
  51. private static List<GetFashionShowData> HomeDatas = new List<GetFashionShowData>();
  52. private static List<GetFashionShowData> CuteDatas = new List<GetFashionShowData>();
  53. private static List<GetFashionShowData> GraceDatas = new List<GetFashionShowData>();
  54. private static List<GetFashionShowData> VividDatas = new List<GetFashionShowData>();
  55. private static List<GetFashionShowData> SimpleDatas = new List<GetFashionShowData>();
  56. private static List<GetFashionShowData> GloryDatas = new List<GetFashionShowData>();
  57. private static List<GetFashionShowData> MineDatas = new List<GetFashionShowData>();
  58. private static List<List<GetFashionShowData>> TabDatasList = new List<List<GetFashionShowData>>();
  59. private static List<FashionShowCloseBox> Boxes = new List<FashionShowCloseBox>();
  60. #endregion
  61. public override void RegistReference()
  62. {
  63. HomeTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_HomeTabButtonText);
  64. CuteTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_CuteTabButtonText);
  65. GraceTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_GraceTabButtonText);
  66. VividTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_VividTabButtonText);
  67. SimpleTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_SimpleTabButtonText);
  68. GloryTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_GloryTabButtonText);
  69. MineTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_MineTabButtonText);
  70. RecommendTitle = ResourceManager.Get<Text>(CanvasLabel.Pi_RecommendTitle);
  71. Return = ResourceManager.Get<Button>(CanvasLabel.Pi_Return);
  72. HomeTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_HomeTabButton);
  73. CuteTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_CuteTabButton);
  74. GraceTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_GraceTabButton);
  75. VividTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_VividTabButton);
  76. SimpleTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_SimpleTabButton);
  77. GloryTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_GloryTabButton);
  78. MineTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_MineTabButton);
  79. HomeBubble = ResourceManager.Get<Image>(CanvasLabel.Pi_HomeTabBubble);
  80. CuteBubble = ResourceManager.Get<Image>(CanvasLabel.Pi_CuteTabBubble);
  81. GraceBubble = ResourceManager.Get<Image>(CanvasLabel.Pi_GraceTabBubble);
  82. VividBubble = ResourceManager.Get<Image>(CanvasLabel.Pi_VividTabBubble);
  83. SimpleBubble = ResourceManager.Get<Image>(CanvasLabel.Pi_SimpleTabBubble);
  84. GloryBubble = ResourceManager.Get<Image>(CanvasLabel.Pi_GloryTabBubble);
  85. MineBubble = ResourceManager.Get<Image>(CanvasLabel.Pi_MineTabBubble);
  86. HomeScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_HomeScrollRect);
  87. CuteScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_CuteScrollRect);
  88. GraceScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_GraceScrollRect);
  89. VividScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_VividScrollRect);
  90. SimpleScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_SimpleScrollRect);
  91. GloryScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_GloryScrollRect);
  92. MineScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_MineScrollRect);
  93. Panel = ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanel);
  94. SidePanel = ResourceManager.Get(CanvasLabel.Pi_FashionShowHomeSidePanel);
  95. OpenHomePageButton = ResourceManager.Get<Button>(CanvasLabel.C_FashionShowButton);
  96. CurrentTabButton = HomeTabButton;
  97. TabButtons.Add(HomeTabButton);
  98. TabButtons.Add(CuteTabButton);
  99. TabButtons.Add(GraceTabButton);
  100. TabButtons.Add(VividTabButton);
  101. TabButtons.Add(SimpleTabButton);
  102. TabButtons.Add(GloryTabButton);
  103. TabButtons.Add(MineTabButton);
  104. TabBubbles.Add(HomeBubble);
  105. TabBubbles.Add(CuteBubble);
  106. TabBubbles.Add(GraceBubble);
  107. TabBubbles.Add(VividBubble);
  108. TabBubbles.Add(SimpleBubble);
  109. TabBubbles.Add(GloryBubble);
  110. TabBubbles.Add(MineBubble);
  111. ScrollRects.Add(HomeScrollRect);
  112. ScrollRects.Add(CuteScrollRect);
  113. ScrollRects.Add(GraceScrollRect);
  114. ScrollRects.Add(VividScrollRect);
  115. ScrollRects.Add(SimpleScrollRect);
  116. ScrollRects.Add(GloryScrollRect);
  117. ScrollRects.Add(MineScrollRect);
  118. TabDatasList.Add(HomeDatas);
  119. TabDatasList.Add(CuteDatas);
  120. TabDatasList.Add(GraceDatas);
  121. TabDatasList.Add(VividDatas);
  122. TabDatasList.Add(SimpleDatas);
  123. TabDatasList.Add(GloryDatas);
  124. TabDatasList.Add(MineDatas);
  125. Panel.CreateTweenVec2D(ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanelPosition).position, 0.5f, false, false, true, Curve.EaseOutQuad);
  126. SidePanel.CreateTweenVec2D(ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanelPosition).position, 0.5f, false, false, true, Curve.EaseOutQuad);
  127. HomeTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  128. CuteTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  129. GraceTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  130. VividTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  131. SimpleTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  132. GloryTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  133. MineTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  134. LanguageManager.Add(HomeTabButtonText, new MulLanStr(LanguageLabel.UI__Pi_HomePage));
  135. LanguageManager.Add(CuteTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Cute));
  136. LanguageManager.Add(GraceTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Grace));
  137. LanguageManager.Add(VividTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Vivid));
  138. LanguageManager.Add(GloryTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Glory));
  139. LanguageManager.Add(SimpleTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Simple));
  140. LanguageManager.Add(MineTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Mine));
  141. LanguageManager.Add(RecommendTitle, new MulLanStr(LanguageLabel.UI__Pi_Title));
  142. Return.onClick.AddListener(OnCloseButtonClick);
  143. OpenHomePageButton.onClick.AddListener(OnOpenButtonClick);
  144. HomeTabButton.onClick.AddListener(() => OnTabButtonClick(HomeTabButton));
  145. CuteTabButton.onClick.AddListener(() => OnTabButtonClick(CuteTabButton));
  146. GraceTabButton.onClick.AddListener(() => OnTabButtonClick(GraceTabButton));
  147. VividTabButton.onClick.AddListener(() => OnTabButtonClick(VividTabButton));
  148. SimpleTabButton.onClick.AddListener(() => OnTabButtonClick(SimpleTabButton));
  149. GloryTabButton.onClick.AddListener(() => OnTabButtonClick(GloryTabButton));
  150. MineTabButton.onClick.AddListener(() => OnTabButtonClick(MineTabButton));
  151. HomeScrollRect.Init(1, 1000000);
  152. CuteScrollRect.Init(1, 1000000);
  153. GraceScrollRect.Init(1, 1000000);
  154. SimpleScrollRect.Init(1, 1000000);
  155. VividScrollRect.Init(1, 1000000);
  156. GloryScrollRect.Init(1, 1000000);
  157. MineScrollRect.Init(1, 1000000);
  158. HomeScrollRect.OnSaveItem += OnSaveItem;
  159. HomeScrollRect.OnGetNextItem += OnGetNextItem;
  160. HomeScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  161. CuteScrollRect.OnSaveItem += OnSaveItem;
  162. CuteScrollRect.OnGetNextItem += OnGetNextItem;
  163. CuteScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  164. GraceScrollRect.OnSaveItem += OnSaveItem;
  165. GraceScrollRect.OnGetNextItem += OnGetNextItem;
  166. GraceScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  167. SimpleScrollRect.OnSaveItem += OnSaveItem;
  168. SimpleScrollRect.OnGetNextItem += OnGetNextItem;
  169. SimpleScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  170. VividScrollRect.OnSaveItem += OnSaveItem;
  171. VividScrollRect.OnGetNextItem += OnGetNextItem;
  172. VividScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  173. GloryScrollRect.OnSaveItem += OnSaveItem;
  174. GloryScrollRect.OnGetNextItem += OnGetNextItem;
  175. GloryScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  176. MineScrollRect.OnSaveItem += OnSaveItem;
  177. MineScrollRect.OnGetNextItem += OnGetNextItem;
  178. MineScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  179. }
  180. public static void ShowPanel()
  181. {
  182. TweenRoot tween = Panel.TweenForVec();
  183. tween.AddEventOnetime
  184. (
  185. EventType.ForwardFinish,
  186. () =>
  187. {
  188. ResourceManager.SetActive(ResourceLabel.Garden, false);
  189. Player.InDressRoom = true;
  190. }
  191. );
  192. ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
  193. OnTabButtonClick(CurrentTabButton);
  194. }
  195. public static void HidePanel()
  196. {
  197. GardenManager.RetrieveAllElf();
  198. TweenRoot tween = Panel.GetTweenVec();
  199. tween.AddEventOnetime
  200. (
  201. EventType.BackwardStart,
  202. () =>
  203. {
  204. ResourceManager.SetActive(ResourceLabel.Garden, true);
  205. Player.InDressRoom = false;
  206. }
  207. );
  208. tween.AddEventOnetime
  209. (
  210. EventType.BackwardFinish, () =>
  211. {
  212. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  213. }
  214. );
  215. tween.StartBackward();
  216. }
  217. public static TweenRoot ShowSidePanel()
  218. {
  219. return SidePanel.TweenForVec();
  220. }
  221. public static TweenRoot HideSidePanel()
  222. {
  223. return SidePanel.TweenBacVec();
  224. }
  225. private static void OnOpenButtonClick()
  226. {
  227. //AudioManager.PlayClip(ResourceLabel.BtnClip);
  228. ShowPanel();
  229. }
  230. private static void OnCloseButtonClick()
  231. {
  232. AudioManager.PlayClip(ResourceLabel.BtnClip);
  233. HidePanel();
  234. }
  235. private static void OnTabButtonClick(Button button)
  236. {
  237. int index = TabButtons.IndexOf(button);
  238. //Debug.Log(index);
  239. requesting = false;
  240. currentDataIndex = 0;
  241. currentPage = 0;
  242. currentType = (FashionShowType) index;
  243. CurrentTabButton = button;
  244. CurrentScrollRect = ScrollRects[index];
  245. CurrentDatas = TabDatasList[index];
  246. if (http != null)
  247. {
  248. http.disable = true;
  249. }
  250. foreach (var tabBubble in TabBubbles)
  251. {
  252. tabBubble.SetActive(false);
  253. }
  254. TabBubbles[index].SetActive(true);
  255. AudioManager.PlayClip(ResourceLabel.BtnClip);
  256. for (int i = 0; i < TabButtons.Count; i++)
  257. {
  258. TabButtons[i].transform.SetSiblingIndex(i);
  259. TabButtons[i].TweenBacScale();
  260. TabButtons[i].interactable = true;
  261. ScrollRects[i].transform.parent.SetActive(false);
  262. }
  263. button.GetTweenScale().Pause();
  264. button.transform.SetAsLastSibling();
  265. button.TweenForScale();
  266. button.interactable = false;
  267. CurrentScrollRect.transform.parent.SetActive(true);
  268. CurrentScrollRect.SaveAllChild();
  269. for (int i = 0; i < Boxes.Count; i++)
  270. {
  271. DestroyImmediate(Boxes[i].gameObject);
  272. }
  273. Boxes = new List<FashionShowCloseBox>();
  274. for (int i = 0; i < CurrentDatas.Count; i++)
  275. {
  276. CurrentDatas.RemoveAt(i--);
  277. }
  278. RefreshCurrentTabPage();
  279. }
  280. private static void RefreshCurrentTabPage()
  281. {
  282. if (CurrentScrollRect.content.transform.childCount > 0) return;
  283. if (CurrentDatas.Count == 0)
  284. {
  285. CurrentScrollRect.NextHorizontalPage();
  286. }
  287. else
  288. {
  289. for (int i = 0; i < 2; i++) CurrentScrollRect.NextHorizontalPage();
  290. }
  291. }
  292. private static FashionShowCloseBox GetAvailableBox()
  293. {
  294. foreach (var box in Boxes)
  295. {
  296. if (box.HaveUnusedCell()) return box;
  297. }
  298. return null;
  299. }
  300. private static void OnSaveItem(int index, VirtualScrollRectItem item)
  301. {
  302. //FashionShowCloseBox box = (FashionShowCloseBox)item;
  303. //Boxes.Remove(box);
  304. //DestroyImmediate(box.gameObject);
  305. //FashionShowCloseBox box = (FashionShowCloseBox) item;
  306. //box.reset();
  307. //Boxes.Remove(box);
  308. //ResourceManager.Save(item);
  309. //Debug.Log(Boxes.Count);
  310. }
  311. private static VirtualScrollRectItem OnGetNextItem(int index)
  312. {
  313. //Debug.LogWarning(Boxes.Count);
  314. //Debug.Log(CurrentDatas.Count + " " + currentDataIndex);
  315. if (CurrentDatas.Count > currentDataIndex)
  316. {
  317. FashionShowCloseBox closeBox = GetAvailableBox();
  318. //Debug.Log(closeBox);
  319. if (closeBox == null)
  320. {
  321. closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
  322. Boxes.Add(closeBox);
  323. closeBox.Init();
  324. closeBox.SetNextCell(CurrentDatas[currentDataIndex++]);
  325. if (closeBox.HaveUnusedCell())
  326. {
  327. CurrentScrollRect.NextHorizontalPage();
  328. }
  329. return closeBox;
  330. }
  331. else
  332. {
  333. closeBox.SetNextCell(CurrentDatas[currentDataIndex++]);
  334. if (closeBox.HaveUnusedCell())
  335. {
  336. CurrentScrollRect.NextHorizontalPage();
  337. }
  338. return null;
  339. }
  340. }
  341. else
  342. {
  343. GetShowList();
  344. return null;
  345. }
  346. }
  347. private static void GetShowList()
  348. {
  349. if (requesting)
  350. {
  351. return;
  352. }
  353. requesting = true;
  354. if (currentType == FashionShowType.Mine)
  355. {
  356. http = ShowListHttp.Get
  357. (
  358. HttpManager.GetPlayerId(), HttpManager.GetPlayerId(), currentPage,
  359. OnGetShowListSucceed, OnGetShowListFailed
  360. );
  361. }
  362. else
  363. {
  364. http = ShowListHttp.Get
  365. (
  366. HttpManager.GetPlayerId(), currentPage, currentType,
  367. OnGetShowListSucceed, OnGetShowListFailed
  368. );
  369. }
  370. }
  371. private static void OnGetShowListSucceed(object obj)
  372. {
  373. requesting = false;
  374. currentPage++;
  375. List<GetFashionShowData> datas = (List<GetFashionShowData>) obj;
  376. //Debug.Log(datas.Count);
  377. RefreshCurrentTabPage();
  378. for (int i = 0; i < datas.Count; i++)
  379. {
  380. GetFashionShowData data = datas[i];
  381. CurrentDatas.AddUnique(data, (showData0, showData1) => showData0.showId == showData1.showId);
  382. }
  383. //Debug.Log(CurrentDatas.Count);
  384. }
  385. private static void OnGetShowListFailed()
  386. {
  387. requesting = false;
  388. }
  389. private static VirtualScrollRectItem OnGetPreviousItem(int index)
  390. {
  391. if (index >= 0)
  392. {
  393. FashionShowCloseBox closeBox = GetAvailableBox();
  394. if (closeBox == null)
  395. {
  396. closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
  397. Boxes.Add(closeBox);
  398. closeBox.reset();
  399. closeBox.SetNextCell(CurrentDatas[index]);
  400. if (closeBox.HaveUnusedCell())
  401. {
  402. CurrentScrollRect.PreviousHorizontalPage();
  403. }
  404. return closeBox;
  405. }
  406. else
  407. {
  408. closeBox.SetNextCell(CurrentDatas[index]);
  409. if (closeBox.HaveUnusedCell())
  410. {
  411. CurrentScrollRect.PreviousHorizontalPage();
  412. }
  413. return null;
  414. }
  415. }
  416. else
  417. {
  418. return null;
  419. }
  420. }
  421. }