FashionShowHomePage.cs 17 KB

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