FashionShowHomePage.cs 16 KB

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