123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using Sfs2X.Entities.Data;
- using UnityEngine;
- using UnityEngine.UI;
- public class PlazaRoomMge : Regist
- {
- #region Config
- public static int CurrentRoomPage = 0;
- public static int CurrentRoomCount = 1;
- public static int DownloadVolume = 20;
- public static bool FilterEnabled;
- public static bool DownloadLock;
- public static Transform Grid;
- public static CounterAction DownloadCallback;
- public static List<PlazaRoomItem> PlazaRoomItems = new List<PlazaRoomItem>();
- public static Dictionary<int, RoomData> RoomDatas = new Dictionary<int, RoomData>();
- #endregion
- public override void RegistValueC()
- {
- DatabaseManager.OnReceiveRoomData += OnReceiveRoomData;
- Download(DownloadVolume);
- VirtualScrollRect virtualScrollRect = ManaReso.Get<VirtualScrollRect>("Z_ScrollRect");
- virtualScrollRect.OnVerticalLessEqual0 = NextPage;
- virtualScrollRect.OnVerticalGreaterEqual1 = PreviousPage;
- CostFml = ManaData.GetPlazaRoomConfig()[1].Value;
- OnSliderValueChange(0);
- }
- public override void RegistReference()
- {
- Grid = ManaReso.Get("Z_Grid");
- DurationLab = ManaReso.Get<Text>("AAa_ValueLab");
- DurationSlider = ManaReso.Get<Slider>("AAa_Slider");
- MaxPlayerLab = ManaReso.Get<Text>("AAb_ValueLab");
- MaxPlayerSlider = ManaReso.Get<Slider>("AAb_Slider");
- DurationSlider.onValueChanged.AddListener(OnSliderValueChange);
- MaxPlayerSlider.onValueChanged.AddListener(OnSliderValueChange);
- }
- public static void OnReceiveRoomData(ISFSArray sfsArray)
- {
- Debug.Log(sfsArray.Size());
- CurrentRoomCount = sfsArray.Size();
- RoomDatas = new Dictionary<int, RoomData>();
- for (int i = 0; i < sfsArray.Count; i++)
- {
- RoomData roomData = new RoomData(sfsArray.GetSFSObject(i));
- RoomDatas.Add(i, roomData);
- }
- UpdateRoomItem();
- if (DownloadCallback != null)
- {
- DownloadCallback.Invoke();
- }
- }
- public static void NextPage()
- {
- if (RoomDatas.Count <= CurrentRoomPage*PageAmt)
- {
- if (!DownloadLock)
- {
- Debug.LogWarning("Download Page");
- ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "Loading"));
- ManaReso.Get("Z_Tip").TweenForCG();
- DownloadLock = true;
- DownloadNext
- (
- () =>
- {
- ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "LoadSucceed"));
- DelayCall.Call(0.5f, () => { ManaReso.Get("Z_Tip").TweenBacCG(); });
- }
- );
- }
- }
- else
- {
- Debug.LogWarning("Next Page");
- List<RoomData> roomDatas = GetRoomDatas(++CurrentRoomPage);
- for (int i = 0; i < roomDatas.Count; i++)
- {
- CreateNextRoomItem(roomDatas[i]);
- }
- }
- }
- public static void PreviousPage()
- {
- if (CurrentRoomPage < 1)
- {
- return;
- }
- Debug.LogWarning("Prev Page");
- List<RoomData> roomDatas = GetRoomDatas(--CurrentRoomPage);
- for (int i = 0; i < roomDatas.Count; i++)
- {
- CreatePreviousRoomItem(roomDatas[i]);
- }
- }
- private static int MaxRoomItem = 10;
- private static void CreateNextRoomItem(RoomData roomData)
- {
- if (PlazaRoomItems.Count >= MaxRoomItem)
- {
- Transform firstChild = Grid.GetChild(0);
- firstChild.GetComponent<PlazaRoomItem>().Init(roomData);
- firstChild.SetAsLastSibling();
- }
- else
- {
- PlazaRoomItems.Add(roomData.CreateItem().Init(roomData));
- }
- }
- private static void CreatePreviousRoomItem(RoomData roomData)
- {
- if (PlazaRoomItems.Count >= MaxRoomItem)
- {
- Transform lastChild = Grid.GetChild(Grid.childCount - 1);
- lastChild.GetComponent<PlazaRoomItem>().Init(roomData);
- lastChild.SetAsFirstSibling();
- }
- else
- {
- return;
- }
- }
- private static void UpdateRoomItem()
- {
- Debug.LogWarning("Update Page");
- if (CurrentRoomPage == 0)
- {
- return;
- }
- int lastPage = (RoomDatas.Count/PageAmt) + 1;
- if (CurrentRoomPage > lastPage)
- {
- CurrentRoomPage = lastPage;
- }
- if (CurrentRoomPage == 1)
- {
- for (int i = PageAmt; i < Grid.childCount; i++)
- {
- ManaReso.Save(Grid.GetChild(i--));
- }
- for (int i = 0; i < PageAmt; i++)
- {
- if (RoomDatas.Count > i)
- {
- if (Grid.childCount > i + 1)
- {
- Grid.GetChild(i).GetComponent<PlazaRoomItem>().Init(RoomDatas[i]);
- }
- else
- {
- RoomDatas[i].CreateItem().Init(RoomDatas[i]);
- }
- }
- else
- {
- if (Grid.childCount > i + 1)
- {
- ManaReso.Save(Grid.GetChild(i--));
- }
- }
- }
- }
- else
- {
- int startIndex = (CurrentRoomPage - 1)*5;
- for (int i = startIndex; i < startIndex + 10; i++)
- {
- if (RoomDatas.Count > i)
- {
- if (Grid.childCount > i + 1)
- {
- Grid.GetChild(i).GetComponent<PlazaRoomItem>().Init(RoomDatas[i]);
- }
- else
- {
- RoomDatas[i].CreateItem().Init(RoomDatas[i]);
- }
- }
- else
- {
- if (Grid.childCount > i + 1)
- {
- ManaReso.Save(Grid.GetChild(i--));
- }
- }
- }
- }
- }
- private static void Download(int limit)
- {
- GardenSmartFoxManager.GardenSmartFox.ExecuteAfterCheckConection
- (
- () =>
- {
- DatabaseManager.GetRoomList(limit);
- }
- );
- }
- private static void DownloadNext(Action action)
- {
- int limit = (CurrentRoomCount/DownloadVolume + 1)*DownloadVolume;
- DownloadCallback = new CounterAction(action);
- Download(limit);
- }
- private static int PageAmt = 5;
- private static List<RoomData> GetRoomDatas(int page)
- {
- List<RoomData> roomDatas = new List<RoomData>();
- if (RoomDatas.Count >= page*PageAmt)
- {
- for (int i = 0; i < PageAmt; i++)
- {
- roomDatas.Add(RoomDatas[(page - 1)*PageAmt + i]);
- }
- }
- else
- {
- for (int i = 0; i < (PageAmt - page*PageAmt - RoomDatas.Count); i++)
- {
- roomDatas.Add(RoomDatas[(page - 1)*PageAmt + i]);
- }
- }
- return roomDatas;
- }
- public static void OpenPanel()
- {
- ManaReso.Get("Z_BK").TweenForCG();
- }
- public static void ClosePanel()
- {
- ManaReso.Get("Z_BK").TweenBacCG();
- }
- public static void EnableFilter()
- {
- FilterEnabled = true;
- ManaReso.SetActive("Z_InfoImg51", true);
- }
- public static void DisableFilter()
- {
- FilterEnabled = false;
- ManaReso.SetActive("Z_InfoImg51", false);
- }
- public static int Duration;
- public static int MaxPlayer;
- public static string CostFml;
- private static Text DurationLab;
- private static Text MaxPlayerLab;
- private static Slider DurationSlider;
- private static Slider MaxPlayerSlider;
- public static void CreateRoom()
- {
- string rawName = ManaReso.Get<InputField>("AA_InputField").text;
- if (string.IsNullOrEmpty(rawName))
- {
- Bubble.Show(null, Language.GetStr("UI", "AA_AllWhiteSpace"));
- return;
- }
- if (StringFilter.ContainSensitiveWord(rawName))
- {
- Bubble.Show(null, Language.GetStr("Common", "ContainSensitiveWord"));
- return;
- }
- //if (ManaCenter.Pay())
- //{
-
- //}
- }
- public static void OnSliderValueChange(float value)
- {
- //if (!DurationSlider.gameObject.activeInHierarchy || !MaxPlayerSlider.gameObject.activeInHierarchy)
- //{
- // return;
- //}
- Duration = (int) DurationSlider.value;
- MaxPlayer = (int) MaxPlayerSlider.value;
- DurationLab.text = Duration + Language.GetStr("UI", "AAa_Value");
- MaxPlayerLab.text = MaxPlayer + Language.GetStr("UI", "AAb_Value");
- int cost = (int) Auxiliary.FmlParse(CostFml, "h", Duration.ToString(), "p", MaxPlayer.ToString());
- ManaReso.SetText("AA_Desc", Language.GetStr("UI", "AA_Cost") + "<(钻石)>" + cost);
-
- if (cost > ManaCenter.Diamond)
- {
- ManaReso.SetText("AA_BtnLab", Language.GetStr("UI", "AA_NoEnoughDiamond"));
- ManaReso.Get<Button>("AA_Btn").image.material = Lib.GrayMat;
- ManaReso.Get<Button>("AA_Btn").interactable = false;
- }
- else
- {
- ManaReso.SetText("AA_BtnLab", Language.GetStr("UI", "AA_Create"));
- ManaReso.Get<Button>("AA_Btn").image.material = null;
- ManaReso.Get<Button>("AA_Btn").interactable = true;
- }
- }
- public static void OpenCreatePanel()
- {
- ManaReso.Get("AA_CreatePlazaRoom").TweenForCG();
- }
- public static void CloseCreatePanel()
- {
- ManaReso.Get("AA_CreatePlazaRoom").TweenBacCG();
- }
- }
|