FashionShowHomePage.cs 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348
  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 Button CurrentTabButton;
  30. private static VirtualScrollRectPlus CurrentScrollRect;
  31. private static List<FashionShowData> CurrentDatas = new List<FashionShowData>();
  32. private static Button OpenHomePageButton;
  33. private static Transform Panel;
  34. private static Transform SidePanel;
  35. private static List<Button> TabButtons = new List<Button>();
  36. private static List<VirtualScrollRectPlus> ScrollRects = new List<VirtualScrollRectPlus>();
  37. private static List<FashionShowData> HomeDatas = new List<FashionShowData>();
  38. private static List<FashionShowData> CuteDatas = new List<FashionShowData>();
  39. private static List<FashionShowData> GraceDatas = new List<FashionShowData>();
  40. private static List<FashionShowData> VividDatas = new List<FashionShowData>();
  41. private static List<FashionShowData> SimpleDatas = new List<FashionShowData>();
  42. private static List<FashionShowData> GloryDatas = new List<FashionShowData>();
  43. private static List<List<FashionShowData>> TabDatasList = new List<List<FashionShowData>>();
  44. private static List<FashionShowCloseBox> Boxes = new List<FashionShowCloseBox>();
  45. #endregion
  46. public override void RegistReference()
  47. {
  48. //RegistStartMark-Used by LabelUtility-Do not remove
  49. HomeTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_HomeTabButtonText);
  50. CuteTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_CuteTabButtonText);
  51. GraceTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_GraceTabButtonText);
  52. VividTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_VividTabButtonText);
  53. SimpleTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_SimpleTabButtonText);
  54. GloryTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_GloryTabButtonText);
  55. RecommendTitle = ResourceManager.Get<Text>(CanvasLabel.Pi_RecommendTitle);
  56. Return = ResourceManager.Get<Button>(CanvasLabel.Pi_Return);
  57. HomeTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_HomeTabButton);
  58. CuteTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_CuteTabButton);
  59. GraceTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_GraceTabButton);
  60. VividTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_VividTabButton);
  61. SimpleTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_SimpleTabButton);
  62. GloryTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_GloryTabButton);
  63. HomeScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_HomeScrollRect);
  64. CuteScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_CuteScrollRect);
  65. GraceScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_GraceScrollRect);
  66. VividScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_VividScrollRect);
  67. SimpleScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_SimpleScrollRect);
  68. GloryScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_GloryScrollRect);
  69. //RegistEndMark-Used by LabelUtility-Do not remove
  70. Panel = ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanel);
  71. SidePanel = ResourceManager.Get(CanvasLabel.Pi_FashionShowHomeSidePanel);
  72. OpenHomePageButton = ResourceManager.Get<Button>(CanvasLabel.C_FashionShowButton);
  73. CurrentTabButton = HomeTabButton;
  74. TabButtons.Add(HomeTabButton);
  75. TabButtons.Add(CuteTabButton);
  76. TabButtons.Add(GraceTabButton);
  77. TabButtons.Add(VividTabButton);
  78. TabButtons.Add(SimpleTabButton);
  79. TabButtons.Add(GloryTabButton);
  80. ScrollRects.Add(HomeScrollRect);
  81. ScrollRects.Add(CuteScrollRect);
  82. ScrollRects.Add(GraceScrollRect);
  83. ScrollRects.Add(VividScrollRect);
  84. ScrollRects.Add(SimpleScrollRect);
  85. ScrollRects.Add(GloryScrollRect);
  86. TabDatasList.Add(HomeDatas);
  87. TabDatasList.Add(CuteDatas);
  88. TabDatasList.Add(GraceDatas);
  89. TabDatasList.Add(VividDatas);
  90. TabDatasList.Add(SimpleDatas);
  91. TabDatasList.Add(GloryDatas);
  92. Panel.CreateTweenVec2D(ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanelPosition).position, 0.5f, false, false, true, Curve.EaseOutQuad);
  93. SidePanel.CreateTweenVec2D(ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanelPosition).position, 0.5f, false, false, true, Curve.EaseOutQuad);
  94. HomeTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  95. CuteTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  96. GraceTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  97. VividTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  98. SimpleTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  99. GloryTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
  100. LanguageManager.Add(HomeTabButtonText, new MulLanStr(LanguageLabel.UI__Pi_HomePage));
  101. LanguageManager.Add(CuteTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Cute));
  102. LanguageManager.Add(GraceTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Grace));
  103. LanguageManager.Add(VividTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Vivid));
  104. LanguageManager.Add(GloryTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Glory));
  105. LanguageManager.Add(SimpleTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Simple));
  106. LanguageManager.Add(RecommendTitle, new MulLanStr(LanguageLabel.UI__Pi_Title));
  107. Return.onClick.AddListener(OnCloseButtonClick);
  108. OpenHomePageButton.onClick.AddListener(OnOpenButtonClick);
  109. HomeTabButton.onClick.AddListener(() => OnTabButtonClick(HomeTabButton));
  110. CuteTabButton.onClick.AddListener(() => OnTabButtonClick(CuteTabButton));
  111. GraceTabButton.onClick.AddListener(() => OnTabButtonClick(GraceTabButton));
  112. VividTabButton.onClick.AddListener(() => OnTabButtonClick(VividTabButton));
  113. SimpleTabButton.onClick.AddListener(() => OnTabButtonClick(SimpleTabButton));
  114. GloryTabButton.onClick.AddListener(() => OnTabButtonClick(GloryTabButton));
  115. HomeScrollRect.Init(1, 3);
  116. CuteScrollRect.Init(1, 3);
  117. GraceScrollRect.Init(1, 3);
  118. SimpleScrollRect.Init(1, 3);
  119. VividScrollRect.Init(1, 3);
  120. GloryScrollRect.Init(1, 3);
  121. HomeScrollRect.OnSaveItem += OnSaveItem;
  122. HomeScrollRect.OnGetNextItem += OnGetNextItem;
  123. HomeScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  124. CuteScrollRect.OnSaveItem += OnSaveItem;
  125. CuteScrollRect.OnGetNextItem += OnGetNextItem;
  126. CuteScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  127. GraceScrollRect.OnSaveItem += OnSaveItem;
  128. GraceScrollRect.OnGetNextItem += OnGetNextItem;
  129. GraceScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  130. SimpleScrollRect.OnSaveItem += OnSaveItem;
  131. SimpleScrollRect.OnGetNextItem += OnGetNextItem;
  132. SimpleScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  133. VividScrollRect.OnSaveItem += OnSaveItem;
  134. VividScrollRect.OnGetNextItem += OnGetNextItem;
  135. VividScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  136. GloryScrollRect.OnSaveItem += OnSaveItem;
  137. GloryScrollRect.OnGetNextItem += OnGetNextItem;
  138. GloryScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  139. }
  140. private static void ShowPanel()
  141. {
  142. TweenRoot tween = Panel.TweenForVec();
  143. tween.AddEventOnetime
  144. (
  145. EventType.ForwardFinish,
  146. () =>
  147. {
  148. ResourceManager.SetActive(ResourceLabel.Garden, false);
  149. Player.InDressRoom = true;
  150. }
  151. );
  152. ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
  153. OnTabButtonClick(CurrentTabButton);
  154. }
  155. private static void HidePanel()
  156. {
  157. TweenRoot tween = Panel.GetTweenVec();
  158. tween.AddEventOnetime
  159. (
  160. EventType.BackwardStart,
  161. () =>
  162. {
  163. ResourceManager.SetActive(ResourceLabel.Garden, true);
  164. Player.InDressRoom = false;
  165. }
  166. );
  167. tween.AddEventOnetime
  168. (
  169. EventType.BackwardFinish, () =>
  170. {
  171. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  172. }
  173. );
  174. tween.StartBackward();
  175. }
  176. public static TweenRoot ShowSidePanel()
  177. {
  178. return SidePanel.TweenForVec();
  179. }
  180. public static TweenRoot HideSidePanel()
  181. {
  182. return SidePanel.TweenBacVec();
  183. }
  184. private static void OnOpenButtonClick()
  185. {
  186. //AudioManager.PlayClip(ResourceLabel.BtnClip);
  187. ShowPanel();
  188. }
  189. private static void OnCloseButtonClick()
  190. {
  191. AudioManager.PlayClip(ResourceLabel.BtnClip);
  192. HidePanel();
  193. }
  194. private static void OnTabButtonClick(Button button)
  195. {
  196. int index = TabButtons.IndexOf(button);
  197. CurrentTabButton = button;
  198. CurrentScrollRect = ScrollRects[index];
  199. CurrentDatas = TabDatasList[index];
  200. AudioManager.PlayClip(ResourceLabel.BtnClip);
  201. for (int i = 0; i < TabButtons.Count; i++)
  202. {
  203. TabButtons[i].transform.SetSiblingIndex(i);
  204. TabButtons[i].TweenBacScale();
  205. TabButtons[i].interactable = true;
  206. ScrollRects[i].transform.parent.SetActive(false);
  207. }
  208. button.GetTweenScale().Pause();
  209. button.transform.SetAsLastSibling();
  210. button.TweenForScale();
  211. button.interactable = false;
  212. CurrentScrollRect.transform.parent.SetActive(true);
  213. CurrentScrollRect.SaveAllChild();
  214. for (int i = 0; i < CurrentDatas.Count; i++)
  215. {
  216. CurrentDatas.RemoveAt(i--);
  217. }
  218. RefreshCurrentTabPage();
  219. }
  220. private static void RefreshCurrentTabPage()
  221. {
  222. if (CurrentScrollRect.content.transform.childCount > 0) return;
  223. if (CurrentDatas.Count == 0)
  224. {
  225. CurrentScrollRect.NextHorizontalPage();
  226. }
  227. else
  228. {
  229. for (int i = 0; i < 2; i++) CurrentScrollRect.NextHorizontalPage();
  230. }
  231. }
  232. private static FashionShowCloseBox GetAvailableBox()
  233. {
  234. foreach (var box in Boxes)
  235. {
  236. if (box.HaveUnusedCell()) return box;
  237. }
  238. return null;
  239. }
  240. private static void OnSaveItem(int index, VirtualScrollRectItem item)
  241. {
  242. FashionShowCloseBox box = (FashionShowCloseBox) item;
  243. box.reset();
  244. Boxes.Remove(box);
  245. ResourceManager.Save(item);
  246. }
  247. private static VirtualScrollRectItem OnGetNextItem(int index)
  248. {
  249. if (CurrentDatas.Count > index)
  250. {
  251. FashionShowCloseBox closeBox = GetAvailableBox();
  252. if (closeBox == null)
  253. {
  254. closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
  255. Boxes.Add(closeBox);
  256. closeBox.Init();
  257. closeBox.SetNextCell(CurrentDatas[index]);
  258. if (closeBox.HaveUnusedCell())
  259. {
  260. CurrentScrollRect.NextHorizontalPage();
  261. }
  262. return closeBox;
  263. }
  264. else
  265. {
  266. closeBox.SetNextCell(CurrentDatas[index]);
  267. if (closeBox.HaveUnusedCell())
  268. {
  269. CurrentScrollRect.NextHorizontalPage();
  270. }
  271. return null;
  272. }
  273. }
  274. else
  275. {
  276. List<FashionShowData> fashionShowDatas = CurrentDatas;
  277. HttpManager.GetFashionShowDatas
  278. (
  279. datas =>
  280. {
  281. RefreshCurrentTabPage();
  282. fashionShowDatas.AddRange(datas);
  283. },
  284. null
  285. );
  286. return null;
  287. }
  288. }
  289. private static VirtualScrollRectItem OnGetPreviousItem(int index)
  290. {
  291. if (index >= 0)
  292. {
  293. FashionShowCloseBox closeBox = GetAvailableBox();
  294. if (closeBox == null)
  295. {
  296. closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
  297. Boxes.Add(closeBox);
  298. closeBox.reset();
  299. closeBox.SetNextCell(CurrentDatas[index]);
  300. if (closeBox.HaveUnusedCell())
  301. {
  302. CurrentScrollRect.PreviousHorizontalPage();
  303. }
  304. return closeBox;
  305. }
  306. else
  307. {
  308. closeBox.SetNextCell(CurrentDatas[index]);
  309. if (closeBox.HaveUnusedCell())
  310. {
  311. CurrentScrollRect.PreviousHorizontalPage();
  312. }
  313. return null;
  314. }
  315. }
  316. else
  317. {
  318. return null;
  319. }
  320. }
  321. }