FashionShowHomePage.cs 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424
  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. TweenRoot tween = Panel.GetTweenVec();
  176. tween.AddEventOnetime
  177. (
  178. EventType.BackwardStart,
  179. () =>
  180. {
  181. ResourceManager.SetActive(ResourceLabel.Garden, true);
  182. Player.InDressRoom = false;
  183. }
  184. );
  185. tween.AddEventOnetime
  186. (
  187. EventType.BackwardFinish, () =>
  188. {
  189. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  190. }
  191. );
  192. tween.StartBackward();
  193. }
  194. public static TweenRoot ShowSidePanel()
  195. {
  196. return SidePanel.TweenForVec();
  197. }
  198. public static TweenRoot HideSidePanel()
  199. {
  200. return SidePanel.TweenBacVec();
  201. }
  202. private static void OnOpenButtonClick()
  203. {
  204. //AudioManager.PlayClip(ResourceLabel.BtnClip);
  205. ShowPanel();
  206. }
  207. private static void OnCloseButtonClick()
  208. {
  209. AudioManager.PlayClip(ResourceLabel.BtnClip);
  210. HidePanel();
  211. }
  212. private static void OnTabButtonClick(Button button)
  213. {
  214. int index = TabButtons.IndexOf(button);
  215. requesting = false;
  216. currentDataIndex = 0;
  217. currentPage = 0;
  218. currentType = (FashionShowType) index;
  219. CurrentTabButton = button;
  220. CurrentScrollRect = ScrollRects[index];
  221. CurrentDatas = TabDatasList[index];
  222. if (http != null)
  223. {
  224. http.disable = true;
  225. }
  226. AudioManager.PlayClip(ResourceLabel.BtnClip);
  227. for (int i = 0; i < TabButtons.Count; i++)
  228. {
  229. TabButtons[i].transform.SetSiblingIndex(i);
  230. TabButtons[i].TweenBacScale();
  231. TabButtons[i].interactable = true;
  232. ScrollRects[i].transform.parent.SetActive(false);
  233. }
  234. button.GetTweenScale().Pause();
  235. button.transform.SetAsLastSibling();
  236. button.TweenForScale();
  237. button.interactable = false;
  238. CurrentScrollRect.transform.parent.SetActive(true);
  239. CurrentScrollRect.SaveAllChild();
  240. for (int i = 0; i < Boxes.Count; i++)
  241. {
  242. DestroyImmediate(Boxes[i].gameObject);
  243. }
  244. Boxes = new List<FashionShowCloseBox>();
  245. for (int i = 0; i < CurrentDatas.Count; i++)
  246. {
  247. CurrentDatas.RemoveAt(i--);
  248. }
  249. RefreshCurrentTabPage();
  250. }
  251. private static void RefreshCurrentTabPage()
  252. {
  253. if (CurrentScrollRect.content.transform.childCount > 0) return;
  254. if (CurrentDatas.Count == 0)
  255. {
  256. CurrentScrollRect.NextHorizontalPage();
  257. }
  258. else
  259. {
  260. for (int i = 0; i < 2; i++) CurrentScrollRect.NextHorizontalPage();
  261. }
  262. }
  263. private static FashionShowCloseBox GetAvailableBox()
  264. {
  265. foreach (var box in Boxes)
  266. {
  267. if (box.HaveUnusedCell()) return box;
  268. }
  269. return null;
  270. }
  271. private static void OnSaveItem(int index, VirtualScrollRectItem item)
  272. {
  273. //FashionShowCloseBox box = (FashionShowCloseBox)item;
  274. //Boxes.Remove(box);
  275. //DestroyImmediate(box.gameObject);
  276. //FashionShowCloseBox box = (FashionShowCloseBox) item;
  277. //box.reset();
  278. //Boxes.Remove(box);
  279. //ResourceManager.Save(item);
  280. //Debug.Log(Boxes.Count);
  281. }
  282. private static VirtualScrollRectItem OnGetNextItem(int index)
  283. {
  284. //Debug.LogWarning(Boxes.Count);
  285. //Debug.Log(CurrentDatas.Count + " " + currentDataIndex);
  286. if (CurrentDatas.Count > currentDataIndex)
  287. {
  288. FashionShowCloseBox closeBox = GetAvailableBox();
  289. //Debug.Log(closeBox);
  290. if (closeBox == null)
  291. {
  292. closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
  293. Boxes.Add(closeBox);
  294. closeBox.Init();
  295. closeBox.SetNextCell(CurrentDatas[currentDataIndex++]);
  296. if (closeBox.HaveUnusedCell())
  297. {
  298. CurrentScrollRect.NextHorizontalPage();
  299. }
  300. return closeBox;
  301. }
  302. else
  303. {
  304. closeBox.SetNextCell(CurrentDatas[currentDataIndex++]);
  305. if (closeBox.HaveUnusedCell())
  306. {
  307. CurrentScrollRect.NextHorizontalPage();
  308. }
  309. return null;
  310. }
  311. }
  312. else
  313. {
  314. GetShowList();
  315. return null;
  316. }
  317. }
  318. private static void GetShowList()
  319. {
  320. if (requesting)
  321. {
  322. return;
  323. }
  324. requesting = true;
  325. if (currentType == FashionShowType.Mine)
  326. {
  327. http = ShowListHttp.Get
  328. (
  329. HttpManager.GetPlayerId(), HttpManager.GetPlayerId(), currentPage,
  330. OnGetShowListSucceed, OnGetShowListFailed
  331. );
  332. }
  333. else
  334. {
  335. http = ShowListHttp.Get
  336. (
  337. HttpManager.GetPlayerId(), currentPage, currentType,
  338. OnGetShowListSucceed, OnGetShowListFailed
  339. );
  340. }
  341. }
  342. private static void OnGetShowListSucceed(object obj)
  343. {
  344. requesting = false;
  345. currentPage++;
  346. List<GetFashionShowData> datas = (List<GetFashionShowData>) obj;
  347. //Debug.Log(datas.Count);
  348. RefreshCurrentTabPage();
  349. for (int i = 0; i < datas.Count; i++)
  350. {
  351. GetFashionShowData data = datas[i];
  352. CurrentDatas.AddUnique(data, (showData0, showData1) => showData0.showId == showData1.showId);
  353. }
  354. //Debug.Log(CurrentDatas.Count);
  355. }
  356. private static void OnGetShowListFailed()
  357. {
  358. requesting = false;
  359. }
  360. private static VirtualScrollRectItem OnGetPreviousItem(int index)
  361. {
  362. if (index >= 0)
  363. {
  364. FashionShowCloseBox closeBox = GetAvailableBox();
  365. if (closeBox == null)
  366. {
  367. closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
  368. Boxes.Add(closeBox);
  369. closeBox.reset();
  370. closeBox.SetNextCell(CurrentDatas[index]);
  371. if (closeBox.HaveUnusedCell())
  372. {
  373. CurrentScrollRect.PreviousHorizontalPage();
  374. }
  375. return closeBox;
  376. }
  377. else
  378. {
  379. closeBox.SetNextCell(CurrentDatas[index]);
  380. if (closeBox.HaveUnusedCell())
  381. {
  382. CurrentScrollRect.PreviousHorizontalPage();
  383. }
  384. return null;
  385. }
  386. }
  387. else
  388. {
  389. return null;
  390. }
  391. }
  392. }