FashionShowHomePage.cs 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355
  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. //#NAME.Init()
  116. //#NAME.OnSaveItem += OnSave#NAMEItem
  117. //#NAME.OnGetNextItem += OnGetNext#NAMEItem
  118. //#NAME.OnGetPreviousItem += OnGetPrevious#NAMEItem
  119. //OnSave#NAMEItem
  120. //OnGetNext#NAMEItem
  121. //OnGetPrevious#NAMEItem
  122. HomeScrollRect.Init(1, 3);
  123. CuteScrollRect.Init(1, 3);
  124. GraceScrollRect.Init(1, 3);
  125. SimpleScrollRect.Init(1, 3);
  126. VividScrollRect.Init(1, 3);
  127. GloryScrollRect.Init(1, 3);
  128. HomeScrollRect.OnSaveItem += OnSaveItem;
  129. HomeScrollRect.OnGetNextItem += OnGetNextItem;
  130. HomeScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  131. CuteScrollRect.OnSaveItem += OnSaveItem;
  132. CuteScrollRect.OnGetNextItem += OnGetNextItem;
  133. CuteScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  134. GraceScrollRect.OnSaveItem += OnSaveItem;
  135. GraceScrollRect.OnGetNextItem += OnGetNextItem;
  136. GraceScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  137. SimpleScrollRect.OnSaveItem += OnSaveItem;
  138. SimpleScrollRect.OnGetNextItem += OnGetNextItem;
  139. SimpleScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  140. VividScrollRect.OnSaveItem += OnSaveItem;
  141. VividScrollRect.OnGetNextItem += OnGetNextItem;
  142. VividScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  143. GloryScrollRect.OnSaveItem += OnSaveItem;
  144. GloryScrollRect.OnGetNextItem += OnGetNextItem;
  145. GloryScrollRect.OnGetPreviousItem += OnGetPreviousItem;
  146. }
  147. private static void ShowPanel()
  148. {
  149. TweenRoot tween = Panel.TweenForVec();
  150. tween.AddEventOnetime
  151. (
  152. EventType.ForwardFinish,
  153. () =>
  154. {
  155. ResourceManager.SetActive(ResourceLabel.Garden, false);
  156. Player.InDressRoom = true;
  157. }
  158. );
  159. ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
  160. OnTabButtonClick(CurrentTabButton);
  161. }
  162. private static void HidePanel()
  163. {
  164. TweenRoot tween = Panel.GetTweenVec();
  165. tween.AddEventOnetime
  166. (
  167. EventType.BackwardStart,
  168. () =>
  169. {
  170. ResourceManager.SetActive(ResourceLabel.Garden, true);
  171. Player.InDressRoom = false;
  172. }
  173. );
  174. tween.AddEventOnetime
  175. (
  176. EventType.BackwardFinish, () =>
  177. {
  178. ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
  179. }
  180. );
  181. tween.StartBackward();
  182. }
  183. public static TweenRoot ShowSidePanel()
  184. {
  185. return SidePanel.TweenForVec();
  186. }
  187. public static TweenRoot HideSidePanel()
  188. {
  189. return SidePanel.TweenBacVec();
  190. }
  191. private static void OnOpenButtonClick()
  192. {
  193. //AudioManager.PlayClip(ResourceLabel.BtnClip);
  194. ShowPanel();
  195. }
  196. private static void OnCloseButtonClick()
  197. {
  198. AudioManager.PlayClip(ResourceLabel.BtnClip);
  199. HidePanel();
  200. }
  201. private static void OnTabButtonClick(Button button)
  202. {
  203. int index = TabButtons.IndexOf(button);
  204. CurrentTabButton = button;
  205. CurrentScrollRect = ScrollRects[index];
  206. CurrentDatas = TabDatasList[index];
  207. AudioManager.PlayClip(ResourceLabel.BtnClip);
  208. for (int i = 0; i < TabButtons.Count; i++)
  209. {
  210. TabButtons[i].transform.SetSiblingIndex(i);
  211. TabButtons[i].TweenBacScale();
  212. TabButtons[i].interactable = true;
  213. ScrollRects[i].transform.parent.SetActive(false);
  214. }
  215. button.GetTweenScale().Pause();
  216. button.transform.SetAsLastSibling();
  217. button.TweenForScale();
  218. button.interactable = false;
  219. CurrentScrollRect.transform.parent.SetActive(true);
  220. CurrentScrollRect.SaveAllChild();
  221. for (int i = 0; i < CurrentDatas.Count; i++)
  222. {
  223. CurrentDatas.RemoveAt(i--);
  224. }
  225. RefreshCurrentTabPage();
  226. }
  227. private static void RefreshCurrentTabPage()
  228. {
  229. if (CurrentScrollRect.content.transform.childCount > 0) return;
  230. if (CurrentDatas.Count == 0)
  231. {
  232. CurrentScrollRect.NextHorizontalPage();
  233. }
  234. else
  235. {
  236. for (int i = 0; i < 2; i++) CurrentScrollRect.NextHorizontalPage();
  237. }
  238. }
  239. private static FashionShowCloseBox GetAvailableBox()
  240. {
  241. foreach (var box in Boxes)
  242. {
  243. if (box.HaveUnusedCell()) return box;
  244. }
  245. return null;
  246. }
  247. private static void OnSaveItem(int index, VirtualScrollRectItem item)
  248. {
  249. FashionShowCloseBox box = (FashionShowCloseBox) item;
  250. box.reset();
  251. Boxes.Remove(box);
  252. ResourceManager.Save(item);
  253. }
  254. private static VirtualScrollRectItem OnGetNextItem(int index)
  255. {
  256. if (CurrentDatas.Count > index)
  257. {
  258. FashionShowCloseBox closeBox = GetAvailableBox();
  259. if (closeBox == null)
  260. {
  261. closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
  262. Boxes.Add(closeBox);
  263. closeBox.Init();
  264. closeBox.SetNextCell(CurrentDatas[index]);
  265. if (closeBox.HaveUnusedCell())
  266. {
  267. CurrentScrollRect.NextHorizontalPage();
  268. }
  269. return closeBox;
  270. }
  271. else
  272. {
  273. closeBox.SetNextCell(CurrentDatas[index]);
  274. if (closeBox.HaveUnusedCell())
  275. {
  276. CurrentScrollRect.NextHorizontalPage();
  277. }
  278. return null;
  279. }
  280. }
  281. else
  282. {
  283. List<FashionShowData> fashionShowDatas = CurrentDatas;
  284. HttpManager.GetFashionShowDatas
  285. (
  286. datas =>
  287. {
  288. RefreshCurrentTabPage();
  289. fashionShowDatas.AddRange(datas);
  290. },
  291. null
  292. );
  293. return null;
  294. }
  295. }
  296. private static VirtualScrollRectItem OnGetPreviousItem(int index)
  297. {
  298. if (index >= 0)
  299. {
  300. FashionShowCloseBox closeBox = GetAvailableBox();
  301. if (closeBox == null)
  302. {
  303. closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
  304. Boxes.Add(closeBox);
  305. closeBox.reset();
  306. closeBox.SetNextCell(CurrentDatas[index]);
  307. if (closeBox.HaveUnusedCell())
  308. {
  309. CurrentScrollRect.PreviousHorizontalPage();
  310. }
  311. return closeBox;
  312. }
  313. else
  314. {
  315. closeBox.SetNextCell(CurrentDatas[index]);
  316. if (closeBox.HaveUnusedCell())
  317. {
  318. CurrentScrollRect.PreviousHorizontalPage();
  319. }
  320. return null;
  321. }
  322. }
  323. else
  324. {
  325. return null;
  326. }
  327. }
  328. }