123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using Sfs2X.Core;
- using Sfs2X.Entities;
- using Sfs2X.Entities.Data;
- using UnityEngine;
- using UnityEngine.UI;
- public class PlazaRoomMge : Regist
- {
- #region Config
- public static float ItemHeight
- {
- get
- {
- if (itemHeight == 0)
- {
- itemHeight = (Grid.GetChild(0).GetComponent<RectTransform>().rect.height + Grid.GetComponent<VerticalLayoutGroup>().spacing);
- }
-
- return itemHeight;
- }
- }
- private static float itemHeight;
- public static float DownLoadTimespan = 30;
- public static bool DownloadLock;
- public static int LastIndex;
- public static int FirstIndex;
- public static int CustomLastIndex;
- public static int CustomFirstIndex;
- public static bool FilterEnabled;
- public static Transform Grid;
- public static VirtualScrollRect ScrollRect;
- public static List<PlazaRoomItem> PlazaRoomItems = new List<PlazaRoomItem>();
- public static Dictionary<int, RoomData> RoomDatas = new Dictionary<int, RoomData>();
- public static List<PlazaRoomItem> CustomPlazaRoomItems = new List<PlazaRoomItem>();
- public static Dictionary<int, RoomData> CustomRoomDatas = new Dictionary<int, RoomData>();
- #endregion
- private float RefreshTime = 10;
- private float RefreshTimer = 0;
- private void Update()
- {
- RefreshTimer += Time.deltaTime;
- if (RefreshTimer >= RefreshTime)
- {
- RefreshTimer = 0;
- if (FilterEnabled)
- RefreshRoomStatus(CustomPlazaRoomItems);
- else
- RefreshRoomStatus(PlazaRoomItems);
- }
- }
- public override void RegistValueC()
- {
- VirtualScrollRect virtualScrollRect = ManaReso.Get<VirtualScrollRect>("Z_ScrollRect");
- virtualScrollRect.OnVerticalLessEqual0 = NextPageGate;
- virtualScrollRect.OnVerticalGreaterEqual1 = PreviousPageGate;
- CostFml = ManaData.GetPlazaRoomConfig()[1].Value;
- ValueFml = ManaData.GetPlazaRoomConfig()[2].Value;
- }
- public override void RegistReference()
- {
- Grid = ManaReso.Get("Z_Grid");
- ScrollRect = ManaReso.Get<VirtualScrollRect>("Z_ScrollRect");
- 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);
- DurationSlider.onValueChanged.AddListener(f => ManaAudio.PlayClip(Clip.BtnClip));
- MaxPlayerSlider.onValueChanged.AddListener(OnSliderValueChange);
- MaxPlayerSlider.onValueChanged.AddListener(f => ManaAudio.PlayClip(Clip.BtnClip));
- }
- public static void RefreshRoomStatus(List<PlazaRoomItem> plazaRoomItems)
- {
- List<int> databaseRoomIDs = new List<int>();
- foreach (var plazaRoomItem in plazaRoomItems)
- {
- databaseRoomIDs.Add(plazaRoomItem.RoomData.ID);
- }
- SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.GetRoomFullStatus(databaseRoomIDs);
- }
- public static void DownloadRoomData()
- {
- ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "Loading"));
- ManaReso.Get("Z_Tip").TweenForCG();
- DownloadLock = true;
- SFSManager.GardenSmartFox.ExecuteAfterCheckConection
- (
- () => SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.GetRoomData(LastIndex),
- (succeed, baseEvent) => { if (!succeed) { ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "LoadFailed")); DelayCall.Call(DownLoadTimespan, () => { DownloadLock = false; ManaReso.Get("Z_Tip").TweenBacCG(); }); } },
- (succeed, baseEvent) => { if (!succeed) { ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "LoadFailed")); DelayCall.Call(DownLoadTimespan, () => { DownloadLock = false; ManaReso.Get("Z_Tip").TweenBacCG(); }); } }
- );
- }
- public static void DownloadCustomRoomData()
- {
- ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "Loading"));
- ManaReso.Get("Z_Tip").TweenForCG();
- DownloadLock = true;
- SFSManager.GardenSmartFox.ExecuteAfterCheckConection
- (
- () => SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.GetCustomRoomData(CustomLastIndex, long.Parse(ManaServer.SerialNumber)),
- (succeed, baseEvent) => { if (!succeed) { ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "LoadFailed")); DelayCall.Call(DownLoadTimespan, () => { DownloadLock = false; ManaReso.Get("Z_Tip").TweenBacCG(); }); } },
- (succeed, baseEvent) => { if (!succeed) { ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "LoadFailed")); DelayCall.Call(DownLoadTimespan, () => { DownloadLock = false; ManaReso.Get("Z_Tip").TweenBacCG(); }); } }
- );
- }
- public static void OnReceiveRoomData(ISFSArray sfsArray)
- {
- //Debug.LogWarning("receive " + sfsArray.Count);
- int count = RoomDatas.Count;
- for (int i = 0; i < sfsArray.Count; i++)
- {
- RoomData roomData = new RoomData(sfsArray.GetSFSObject(i));
- if (!RoomDatas.Values.Contains(roomData))
- {
- RoomDatas.Add(count + i, roomData);
- }
- }
- if (FilterEnabled)
- {
- return;
- }
- ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "LoadSucceed"));
- DelayCall.Call(0.5f, () => { ManaReso.Get("Z_Tip").TweenBacCG(); });
- if (sfsArray.Count == 0)
- {
- DelayCall.Call(DownLoadTimespan, () => { DownloadLock = false; });
- }
- else
- {
- int availableItemAmt = MaxRoomItem - PlazaRoomItems.Count;
- //if (LastIndex == 0)
- //{
- NextPage(availableItemAmt, ref FirstIndex, ref LastIndex, RoomDatas);
- //}
- DownloadLock = false;
- }
- RefreshRoomStatus(PlazaRoomItems);
- }
- public static void OnReceiveCustomRoomData(ISFSArray sfsArray)
- {
- //Debug.LogWarning("receive custom " + sfsArray.Count);
- int count = CustomRoomDatas.Count;
- for (int i = 0; i < sfsArray.Count; i++)
- {
- RoomData roomData = new RoomData(sfsArray.GetSFSObject(i));
- if (!CustomRoomDatas.Values.Contains(roomData))
- {
- CustomRoomDatas.Add(count + i, roomData);
- }
- }
- if (!FilterEnabled)
- {
- return;
- }
- ManaLan.Add(ManaReso.Get<Text>("Z_Tip"), new LanStr("UI", "LoadSucceed"));
- DelayCall.Call(0.5f, () => { ManaReso.Get("Z_Tip").TweenBacCG(); });
- if (sfsArray.Count == 0)
- {
- DelayCall.Call(DownLoadTimespan, () => { DownloadLock = false; });
- }
- else
- {
- int availableItemAmt = MaxRoomItem - PlazaRoomItems.Count;
- //if (LastIndex == 0)
- //{
- NextPage(availableItemAmt, ref CustomFirstIndex, ref CustomLastIndex, CustomRoomDatas);
- //}
- DownloadLock = false;
- }
- RefreshRoomStatus(CustomPlazaRoomItems);
- }
- public static void OnReceiveRoomFullStatus(List<int> ids, List<bool> statuses)
- {
- foreach (var plazaRoomItem in PlazaRoomItems)
- {
- int index = ids.IndexOf(plazaRoomItem.RoomData.ID);
- if (index != -1)
- {
- plazaRoomItem.RefreshStatus(statuses[index]);
- }
- }
- }
- private static int PageVolume = 5;
- public static void NextPageGate()
- {
- if (FilterEnabled)
- {
- NextPage(PageVolume, ref CustomFirstIndex, ref CustomLastIndex, CustomRoomDatas);
- }
- else
- {
- NextPage(PageVolume, ref FirstIndex, ref LastIndex, RoomDatas);
- }
- }
- public static void PreviousPageGate()
- {
- if (FilterEnabled)
- {
- PreviousPage(PageVolume, ref CustomFirstIndex, ref CustomLastIndex, CustomRoomDatas);
- }
- else
- {
- PreviousPage(PageVolume, ref FirstIndex, ref LastIndex, RoomDatas);
- }
- }
- public static void NextPage(int nextAmt, ref int firstIndex, ref int lastIndex, Dictionary<int, RoomData> dictionary)
- {
- if (lastIndex >= dictionary.Count)
- {
- if (!DownloadLock)
- {
- //Debug.LogWarning("Download Page");
- if (FilterEnabled)
- {
- DownloadCustomRoomData();
- }
- else
- {
- DownloadRoomData();
- }
- }
- }
- else
- {
- //Debug.LogWarning("Next Page");
- for (int i = 0; i < nextAmt; i++)
- {
- RoomData roomData;
- if (dictionary.TryGetValue(lastIndex, out roomData))
- {
- CreateNextRoomItem(ref firstIndex, ref lastIndex, roomData);
- }
- else
- {
- break;
- }
- }
- }
- }
- public static void PreviousPage(int nextAmt, ref int firstIndex, ref int lastIndex, Dictionary<int, RoomData> dictionary)
- {
- if (firstIndex == 0)
- {
- return;
- }
- //Debug.LogWarning("Prev Page");
- for (int i = 0; i < nextAmt; i++)
- {
- RoomData roomData;
- if (dictionary.TryGetValue(firstIndex - 1, out roomData))
- {
- CreatePreviousRoomItem(ref firstIndex, ref lastIndex, roomData);
- }
- else
- {
- break;
- }
- }
- }
- private static int MaxRoomItem = 10;
- private static void CreateNextRoomItem(ref int firstIndex, ref int lastIndex, RoomData roomData)
- {
- if (PlazaRoomItems.Count >= MaxRoomItem)
- {
- firstIndex++;
- lastIndex++;
- Transform firstChild = Grid.GetChild(0);
- firstChild.GetComponent<PlazaRoomItem>().Init(roomData);
- ScrollRect.Recycle(new Vector2(0, -ItemHeight));
- Grid.position += new Vector3(0, -ItemHeight);
- firstChild.SetAsLastSibling();
- }
- else
- {
- lastIndex++;
- PlazaRoomItems.Add(roomData.CreateItem().Init(roomData));
- }
- }
- private static void CreatePreviousRoomItem(ref int firstIndex, ref int lastIndex, RoomData roomData)
- {
- if (PlazaRoomItems.Count >= MaxRoomItem)
- {
- firstIndex--;
- lastIndex--;
- Transform lastChild = Grid.GetChild(Grid.childCount - 1);
- lastChild.GetComponent<PlazaRoomItem>().Init(roomData);
- ScrollRect.Recycle(new Vector2(0, ItemHeight));
- Grid.position += new Vector3(0, ItemHeight);
- lastChild.SetAsFirstSibling();
- }
- }
- public static void OpenPanel()
- {
- if (!DownloadLock)
- {
- DownloadRoomData();
- DownloadCustomRoomData();
- }
- OnSliderValueChange(0);
- 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);
- ClearGrid();
- NextPage(PageVolume, ref CustomFirstIndex, ref CustomLastIndex, CustomRoomDatas);
- }
- public static void DisableFilter()
- {
- FilterEnabled = false;
- ManaReso.SetActive("Z_InfoImg51", false);
- ClearGrid();
- NextPage(PageVolume, ref FirstIndex, ref LastIndex, RoomDatas);
- }
- private static void ClearGrid()
- {
- LastIndex = 0;
- FirstIndex = 0;
- CustomLastIndex = 0;
- CustomFirstIndex = 0;
- while (Grid.childCount > 0)
- {
- ManaReso.Save(Grid.GetChild(0));
- }
- PlazaRoomItems = new List<PlazaRoomItem>();
- ManaReso.Get("Z_Tip").GetTweenCG().InOrigin = true;
- DownloadLock = false;
- }
- public static int Cost;
- public static int Duration;
- public static int MaxPlayer;
- public static string CostFml;
- public static string ValueFml;
- private static Text DurationLab;
- private static Text MaxPlayerLab;
- private static Slider DurationSlider;
- private static Slider MaxPlayerSlider;
- public static void CreateRoom()
- {
- string roomName = ManaReso.Get<InputField>("AA_InputField").text;
- if (string.IsNullOrEmpty(roomName))
- {
- Bubble.Show(null, Language.GetStr("UI", "AA_AllWhiteSpace"));
- return;
- }
- if (roomName.GetBytes() > 24)
- {
- Bubble.Show(null, Language.GetStr("UI", "AA_TooLong"));
- return;
- }
- if (StringFilter.ContainSensitiveWord(roomName))
- {
- Bubble.Show(null, Language.GetStr("Common", "ContainSensitiveWord"));
- return;
- }
- ManaLan.Add(ManaReso.Get<Text>("AA_Tip"), new LanStr("UI", "AA_SendRequest"));
- ManaReso.Get("AA_Tip").TweenForCG();
- ManaReso.Get<CanvasGroup>("AA_CreatePlazaRoom").interactable = false;
- int value = (int) Auxiliary.FmlParse(ValueFml, "c", Cost.ToString(), "p", MaxPlayer.ToString(), "h", Duration.ToString());
- SFSManager.GardenSmartFox.EventManager.PlazaRoomEvent.CreateRoom(roomName, long.Parse(ManaServer.SerialNumber), Duration, MaxPlayer, value);
- }
- public static void OnCreateRoomError()
- {
- ManaLan.Add(ManaReso.Get<Text>("AA_Tip"), new LanStr("UI", "AA_CreateError"));
- ManaReso.Get("AA_Tip").TweenBacCG();
- ManaReso.Get<CanvasGroup>("AA_CreatePlazaRoom").interactable = true;
- Debug.Log("create error");
- }
- public static void OnCreateRoomSucceed(RoomData roomData)
- {
- if (!RoomDatas.Values.Contains(roomData))
- {
- RoomDatas.Add(RoomDatas.Count, roomData);
- }
- if (!CustomRoomDatas.Values.Contains(roomData))
- {
- CustomRoomDatas.Add(CustomRoomDatas.Count, roomData);
- }
- int availableItemAmt = MaxRoomItem - PlazaRoomItems.Count;
- if (FilterEnabled)
- {
- NextPage(availableItemAmt, ref CustomFirstIndex, ref CustomLastIndex, CustomRoomDatas);
- }
- else
- {
- NextPage(availableItemAmt, ref FirstIndex, ref LastIndex, RoomDatas);
- }
- ManaCenter.CreateRoomAmt++;
- ManaLan.Add(ManaReso.Get<Text>("AA_Tip"), new LanStr("UI", "AA_CreateSucceed"));
- ManaReso.Get("AA_Tip").TweenBacCG();
- ManaReso.Get<CanvasGroup>("AA_CreatePlazaRoom").interactable = true;
- DownloadRoomData();
- ManaCenter.AddDiamond(-Cost, StaticsManager.ItemID.创建派对, StaticsManager.ConsumeModule.Charge);
- PlazaRoomItem.OnJoinBtn(roomData);
- CloseCreatePanel();
- }
- public static void OnSliderValueChange(float value)
- {
- Duration = (int) DurationSlider.value;
- MaxPlayer = (int) MaxPlayerSlider.value;
- DurationLab.text = Duration + Language.GetStr("UI", "AAa_Value");
- MaxPlayerLab.text = MaxPlayer + Language.GetStr("UI", "AAb_Value");
- 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();
- string defaultName = Language.GetStr("UI", "AA_DefaultName").Replace("[&value&]", ManaNickName.NickName);
- ManaReso.Get<InputField>("AA_InputField").text = defaultName;
- }
- public static void CloseCreatePanel()
- {
- ManaReso.Get("AA_CreatePlazaRoom").TweenBacCG();
- }
- }
|