123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424 |
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- public class FashionShowHomePage : Regist
- {
- #region Config
- private static Text HomeTabButtonText;
- private static Text CuteTabButtonText;
- private static Text GraceTabButtonText;
- private static Text VividTabButtonText;
- private static Text SimpleTabButtonText;
- private static Text GloryTabButtonText;
- private static Text MineTabButtonText;
- private static Text RecommendTitle;
- private static Button Return;
- private static Button HomeTabButton;
- private static Button CuteTabButton;
- private static Button GraceTabButton;
- private static Button VividTabButton;
- private static Button SimpleTabButton;
- private static Button GloryTabButton;
- private static Button MineTabButton;
- private static VirtualScrollRectPlus HomeScrollRect;
- private static VirtualScrollRectPlus CuteScrollRect;
- private static VirtualScrollRectPlus GraceScrollRect;
- private static VirtualScrollRectPlus VividScrollRect;
- private static VirtualScrollRectPlus SimpleScrollRect;
- private static VirtualScrollRectPlus GloryScrollRect;
- private static VirtualScrollRectPlus MineScrollRect;
- private static int currentDataIndex;
- private static int currentPage;
- private static bool requesting;
- private static ShowListHttp http;
- private static FashionShowType currentType;
- private static Button CurrentTabButton;
- private static VirtualScrollRectPlus CurrentScrollRect;
- private static List<GetFashionShowData> CurrentDatas = new List<GetFashionShowData>();
- private static Button OpenHomePageButton;
- private static Transform Panel;
- private static Transform SidePanel;
- private static List<Button> TabButtons = new List<Button>();
- private static List<VirtualScrollRectPlus> ScrollRects = new List<VirtualScrollRectPlus>();
- private static List<GetFashionShowData> HomeDatas = new List<GetFashionShowData>();
- private static List<GetFashionShowData> CuteDatas = new List<GetFashionShowData>();
- private static List<GetFashionShowData> GraceDatas = new List<GetFashionShowData>();
- private static List<GetFashionShowData> VividDatas = new List<GetFashionShowData>();
- private static List<GetFashionShowData> SimpleDatas = new List<GetFashionShowData>();
- private static List<GetFashionShowData> GloryDatas = new List<GetFashionShowData>();
- private static List<GetFashionShowData> MineDatas = new List<GetFashionShowData>();
- private static List<List<GetFashionShowData>> TabDatasList = new List<List<GetFashionShowData>>();
- private static List<FashionShowCloseBox> Boxes = new List<FashionShowCloseBox>();
- #endregion
- public override void RegistReference()
- {
- HomeTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_HomeTabButtonText);
- CuteTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_CuteTabButtonText);
- GraceTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_GraceTabButtonText);
- VividTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_VividTabButtonText);
- SimpleTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_SimpleTabButtonText);
- GloryTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_GloryTabButtonText);
- MineTabButtonText = ResourceManager.Get<Text>(CanvasLabel.Pi_MineTabButtonText);
- RecommendTitle = ResourceManager.Get<Text>(CanvasLabel.Pi_RecommendTitle);
- Return = ResourceManager.Get<Button>(CanvasLabel.Pi_Return);
- HomeTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_HomeTabButton);
- CuteTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_CuteTabButton);
- GraceTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_GraceTabButton);
- VividTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_VividTabButton);
- SimpleTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_SimpleTabButton);
- GloryTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_GloryTabButton);
- MineTabButton = ResourceManager.Get<Button>(CanvasLabel.Pi_MineTabButton);
- HomeScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_HomeScrollRect);
- CuteScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_CuteScrollRect);
- GraceScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_GraceScrollRect);
- VividScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_VividScrollRect);
- SimpleScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_SimpleScrollRect);
- GloryScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_GloryScrollRect);
- MineScrollRect = ResourceManager.Get<VirtualScrollRectPlus>(CanvasLabel.Pi_MineScrollRect);
- Panel = ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanel);
- SidePanel = ResourceManager.Get(CanvasLabel.Pi_FashionShowHomeSidePanel);
- OpenHomePageButton = ResourceManager.Get<Button>(CanvasLabel.C_FashionShowButton);
- CurrentTabButton = HomeTabButton;
- TabButtons.Add(HomeTabButton);
- TabButtons.Add(CuteTabButton);
- TabButtons.Add(GraceTabButton);
- TabButtons.Add(VividTabButton);
- TabButtons.Add(SimpleTabButton);
- TabButtons.Add(GloryTabButton);
- TabButtons.Add(MineTabButton);
- ScrollRects.Add(HomeScrollRect);
- ScrollRects.Add(CuteScrollRect);
- ScrollRects.Add(GraceScrollRect);
- ScrollRects.Add(VividScrollRect);
- ScrollRects.Add(SimpleScrollRect);
- ScrollRects.Add(GloryScrollRect);
- ScrollRects.Add(MineScrollRect);
- TabDatasList.Add(HomeDatas);
- TabDatasList.Add(CuteDatas);
- TabDatasList.Add(GraceDatas);
- TabDatasList.Add(VividDatas);
- TabDatasList.Add(SimpleDatas);
- TabDatasList.Add(GloryDatas);
- TabDatasList.Add(MineDatas);
- Panel.CreateTweenVec2D(ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanelPosition).position, 0.5f, false, false, true, Curve.EaseOutQuad);
- SidePanel.CreateTweenVec2D(ResourceManager.Get(CanvasLabel.Pi_FashionShowHomePanelPosition).position, 0.5f, false, false, true, Curve.EaseOutQuad);
- HomeTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
- CuteTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
- GraceTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
- VividTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
- SimpleTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
- GloryTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
- MineTabButton.CreateTweenScale(new Vector3(1, 1, 1), new Vector3(1.1f, 1.1f, 1.1f), 0.25f, true, true, Curve.EaseOutQuad);
- LanguageManager.Add(HomeTabButtonText, new MulLanStr(LanguageLabel.UI__Pi_HomePage));
- LanguageManager.Add(CuteTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Cute));
- LanguageManager.Add(GraceTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Grace));
- LanguageManager.Add(VividTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Vivid));
- LanguageManager.Add(GloryTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Glory));
- LanguageManager.Add(SimpleTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Simple));
- LanguageManager.Add(MineTabButtonText, new MulLanStr(LanguageLabel.UI__Pg_Mine));
- LanguageManager.Add(RecommendTitle, new MulLanStr(LanguageLabel.UI__Pi_Title));
- Return.onClick.AddListener(OnCloseButtonClick);
- OpenHomePageButton.onClick.AddListener(OnOpenButtonClick);
- HomeTabButton.onClick.AddListener(() => OnTabButtonClick(HomeTabButton));
- CuteTabButton.onClick.AddListener(() => OnTabButtonClick(CuteTabButton));
- GraceTabButton.onClick.AddListener(() => OnTabButtonClick(GraceTabButton));
- VividTabButton.onClick.AddListener(() => OnTabButtonClick(VividTabButton));
- SimpleTabButton.onClick.AddListener(() => OnTabButtonClick(SimpleTabButton));
- GloryTabButton.onClick.AddListener(() => OnTabButtonClick(GloryTabButton));
- MineTabButton.onClick.AddListener(() => OnTabButtonClick(MineTabButton));
- HomeScrollRect.Init(1, 1000000);
- CuteScrollRect.Init(1, 1000000);
- GraceScrollRect.Init(1, 1000000);
- SimpleScrollRect.Init(1, 1000000);
- VividScrollRect.Init(1, 1000000);
- GloryScrollRect.Init(1, 1000000);
- MineScrollRect.Init(1, 1000000);
- HomeScrollRect.OnSaveItem += OnSaveItem;
- HomeScrollRect.OnGetNextItem += OnGetNextItem;
- HomeScrollRect.OnGetPreviousItem += OnGetPreviousItem;
- CuteScrollRect.OnSaveItem += OnSaveItem;
- CuteScrollRect.OnGetNextItem += OnGetNextItem;
- CuteScrollRect.OnGetPreviousItem += OnGetPreviousItem;
- GraceScrollRect.OnSaveItem += OnSaveItem;
- GraceScrollRect.OnGetNextItem += OnGetNextItem;
- GraceScrollRect.OnGetPreviousItem += OnGetPreviousItem;
- SimpleScrollRect.OnSaveItem += OnSaveItem;
- SimpleScrollRect.OnGetNextItem += OnGetNextItem;
- SimpleScrollRect.OnGetPreviousItem += OnGetPreviousItem;
- VividScrollRect.OnSaveItem += OnSaveItem;
- VividScrollRect.OnGetNextItem += OnGetNextItem;
- VividScrollRect.OnGetPreviousItem += OnGetPreviousItem;
- GloryScrollRect.OnSaveItem += OnSaveItem;
- GloryScrollRect.OnGetNextItem += OnGetNextItem;
- GloryScrollRect.OnGetPreviousItem += OnGetPreviousItem;
- MineScrollRect.OnSaveItem += OnSaveItem;
- MineScrollRect.OnGetNextItem += OnGetNextItem;
- MineScrollRect.OnGetPreviousItem += OnGetPreviousItem;
- }
- public static void ShowPanel()
- {
- TweenRoot tween = Panel.TweenForVec();
- tween.AddEventOnetime
- (
- EventType.ForwardFinish,
- () =>
- {
- ResourceManager.SetActive(ResourceLabel.Garden, false);
- Player.InDressRoom = true;
- }
- );
- ResourceManager.Get(CanvasLabel.C_Main).TweenBacCG();
- OnTabButtonClick(CurrentTabButton);
- }
- public static void HidePanel()
- {
- TweenRoot tween = Panel.GetTweenVec();
- tween.AddEventOnetime
- (
- EventType.BackwardStart,
- () =>
- {
- ResourceManager.SetActive(ResourceLabel.Garden, true);
- Player.InDressRoom = false;
- }
- );
- tween.AddEventOnetime
- (
- EventType.BackwardFinish, () =>
- {
- ResourceManager.Get(CanvasLabel.C_Main).TweenForCG();
- }
- );
- tween.StartBackward();
- }
- public static TweenRoot ShowSidePanel()
- {
- return SidePanel.TweenForVec();
- }
- public static TweenRoot HideSidePanel()
- {
- return SidePanel.TweenBacVec();
- }
- private static void OnOpenButtonClick()
- {
- //AudioManager.PlayClip(ResourceLabel.BtnClip);
- ShowPanel();
- }
- private static void OnCloseButtonClick()
- {
- AudioManager.PlayClip(ResourceLabel.BtnClip);
- HidePanel();
- }
- private static void OnTabButtonClick(Button button)
- {
- int index = TabButtons.IndexOf(button);
- requesting = false;
- currentDataIndex = 0;
- currentPage = 0;
- currentType = (FashionShowType) index;
- CurrentTabButton = button;
- CurrentScrollRect = ScrollRects[index];
- CurrentDatas = TabDatasList[index];
- if (http != null)
- {
- http.disable = true;
- }
- AudioManager.PlayClip(ResourceLabel.BtnClip);
- for (int i = 0; i < TabButtons.Count; i++)
- {
- TabButtons[i].transform.SetSiblingIndex(i);
- TabButtons[i].TweenBacScale();
- TabButtons[i].interactable = true;
- ScrollRects[i].transform.parent.SetActive(false);
- }
- button.GetTweenScale().Pause();
- button.transform.SetAsLastSibling();
- button.TweenForScale();
- button.interactable = false;
- CurrentScrollRect.transform.parent.SetActive(true);
- CurrentScrollRect.SaveAllChild();
- for (int i = 0; i < Boxes.Count; i++)
- {
- DestroyImmediate(Boxes[i].gameObject);
- }
- Boxes = new List<FashionShowCloseBox>();
- for (int i = 0; i < CurrentDatas.Count; i++)
- {
- CurrentDatas.RemoveAt(i--);
- }
- RefreshCurrentTabPage();
- }
- private static void RefreshCurrentTabPage()
- {
- if (CurrentScrollRect.content.transform.childCount > 0) return;
- if (CurrentDatas.Count == 0)
- {
- CurrentScrollRect.NextHorizontalPage();
- }
- else
- {
- for (int i = 0; i < 2; i++) CurrentScrollRect.NextHorizontalPage();
- }
- }
- private static FashionShowCloseBox GetAvailableBox()
- {
- foreach (var box in Boxes)
- {
- if (box.HaveUnusedCell()) return box;
- }
- return null;
- }
- private static void OnSaveItem(int index, VirtualScrollRectItem item)
- {
- //FashionShowCloseBox box = (FashionShowCloseBox)item;
- //Boxes.Remove(box);
- //DestroyImmediate(box.gameObject);
- //FashionShowCloseBox box = (FashionShowCloseBox) item;
- //box.reset();
- //Boxes.Remove(box);
- //ResourceManager.Save(item);
- //Debug.Log(Boxes.Count);
- }
- private static VirtualScrollRectItem OnGetNextItem(int index)
- {
- //Debug.LogWarning(Boxes.Count);
- //Debug.Log(CurrentDatas.Count + " " + currentDataIndex);
- if (CurrentDatas.Count > currentDataIndex)
- {
- FashionShowCloseBox closeBox = GetAvailableBox();
- //Debug.Log(closeBox);
- if (closeBox == null)
- {
- closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
- Boxes.Add(closeBox);
- closeBox.Init();
- closeBox.SetNextCell(CurrentDatas[currentDataIndex++]);
- if (closeBox.HaveUnusedCell())
- {
- CurrentScrollRect.NextHorizontalPage();
- }
- return closeBox;
- }
- else
- {
- closeBox.SetNextCell(CurrentDatas[currentDataIndex++]);
- if (closeBox.HaveUnusedCell())
- {
- CurrentScrollRect.NextHorizontalPage();
- }
- return null;
- }
- }
- else
- {
- GetShowList();
- return null;
- }
- }
- private static void GetShowList()
- {
- if (requesting)
- {
- return;
- }
- requesting = true;
- if (currentType == FashionShowType.Mine)
- {
- http = ShowListHttp.Get
- (
- HttpManager.GetPlayerId(), HttpManager.GetPlayerId(), currentPage,
- OnGetShowListSucceed, OnGetShowListFailed
- );
- }
- else
- {
- http = ShowListHttp.Get
- (
- HttpManager.GetPlayerId(), currentPage, currentType,
- OnGetShowListSucceed, OnGetShowListFailed
- );
- }
- }
- private static void OnGetShowListSucceed(object obj)
- {
- requesting = false;
- currentPage++;
- List<GetFashionShowData> datas = (List<GetFashionShowData>) obj;
- //Debug.Log(datas.Count);
- RefreshCurrentTabPage();
- for (int i = 0; i < datas.Count; i++)
- {
- GetFashionShowData data = datas[i];
- CurrentDatas.AddUnique(data, (showData0, showData1) => showData0.showId == showData1.showId);
- }
- //Debug.Log(CurrentDatas.Count);
- }
- private static void OnGetShowListFailed()
- {
- requesting = false;
- }
- private static VirtualScrollRectItem OnGetPreviousItem(int index)
- {
- if (index >= 0)
- {
- FashionShowCloseBox closeBox = GetAvailableBox();
- if (closeBox == null)
- {
- closeBox = ResourceManager.Get(FashionShowCloseBoxLabel.FashionShowCloseBox, Folder.UI, false, CurrentScrollRect.content, false, ObjType.FashionShowCloseBox, typeof(FashionShowCloseBox)).GetComponent<FashionShowCloseBox>();
- Boxes.Add(closeBox);
- closeBox.reset();
- closeBox.SetNextCell(CurrentDatas[index]);
- if (closeBox.HaveUnusedCell())
- {
- CurrentScrollRect.PreviousHorizontalPage();
- }
- return closeBox;
- }
- else
- {
- closeBox.SetNextCell(CurrentDatas[index]);
- if (closeBox.HaveUnusedCell())
- {
- CurrentScrollRect.PreviousHorizontalPage();
- }
- return null;
- }
- }
- else
- {
- return null;
- }
- }
- }
|