diff options
Diffstat (limited to 'Client/Assembly-CSharp/FindAGameManager.cs')
-rw-r--r-- | Client/Assembly-CSharp/FindAGameManager.cs | 124 |
1 files changed, 124 insertions, 0 deletions
diff --git a/Client/Assembly-CSharp/FindAGameManager.cs b/Client/Assembly-CSharp/FindAGameManager.cs new file mode 100644 index 0000000..b428861 --- /dev/null +++ b/Client/Assembly-CSharp/FindAGameManager.cs @@ -0,0 +1,124 @@ +using System; +using System.Collections.Generic; +using InnerNet; +using UnityEngine; +using UnityEngine.SceneManagement; + +public class FindAGameManager : DestroyableSingleton<FindAGameManager>, IGameListHandler +{ + private const float RefreshTime = 5f; + + private float timer; + + public ObjectPoolBehavior buttonPool; + + public SpinAnimator RefreshSpinner; + + public Scroller TargetArea; + + public float ButtonStart = 1.75f; + + public float ButtonHeight = 0.6f; + + public const bool showPrivate = false; + + private class GameSorter : IComparer<GameListing> + { + public static readonly FindAGameManager.GameSorter Instance = new FindAGameManager.GameSorter(); + + public int Compare(GameListing x, GameListing y) + { + return -x.PlayerCount.CompareTo(y.PlayerCount); + } + } + + public void ResetTimer() + { + this.timer = 5f; + this.RefreshSpinner.Appear(); + this.RefreshSpinner.StartPulse(); + } + + public void Start() + { + if (!AmongUsClient.Instance) + { + AmongUsClient.Instance = UnityEngine.Object.FindObjectOfType<AmongUsClient>(); + if (!AmongUsClient.Instance) + { + SceneManager.LoadScene("MMOnline"); + return; + } + } + AmongUsClient.Instance.GameListHandlers.Add(this); + AmongUsClient.Instance.RequestGameList(false, SaveManager.GameSearchOptions); + } + + public void Update() + { + this.timer += Time.deltaTime; + GameOptionsData gameSearchOptions = SaveManager.GameSearchOptions; + if ((this.timer < 0f || this.timer > 5f) && gameSearchOptions.MapId != 0) + { + this.RefreshSpinner.Appear(); + } + else + { + this.RefreshSpinner.Disappear(); + } + if (Input.GetKeyUp(KeyCode.Escape)) + { + this.ExitGame(); + } + } + + public void RefreshList() + { + if (this.timer > 5f) + { + this.timer = -5f; + this.RefreshSpinner.Play(); + AmongUsClient.Instance.RequestGameList(false, SaveManager.GameSearchOptions); + } + } + + public override void OnDestroy() + { + if (AmongUsClient.Instance) + { + AmongUsClient.Instance.GameListHandlers.Remove(this); + } + base.OnDestroy(); + } + + public void HandleList(int totalGames, List<GameListing> availableGames) + { + Debug.Log(string.Format("TotalGames: {0}\tAvailable: {1}", totalGames, availableGames.Count)); + this.RefreshSpinner.Disappear(); + this.timer = 0f; + availableGames.Sort(FindAGameManager.GameSorter.Instance); + while (this.buttonPool.activeChildren.Count > availableGames.Count) + { + PoolableBehavior poolableBehavior = this.buttonPool.activeChildren[this.buttonPool.activeChildren.Count - 1]; + poolableBehavior.OwnerPool.Reclaim(poolableBehavior); + } + while (this.buttonPool.activeChildren.Count < availableGames.Count) + { + this.buttonPool.Get<PoolableBehavior>().transform.SetParent(this.TargetArea.Inner); + } + Vector3 vector = new Vector3(0f, this.ButtonStart, -1f); + for (int i = 0; i < this.buttonPool.activeChildren.Count; i++) + { + MatchMakerGameButton matchMakerGameButton = (MatchMakerGameButton)this.buttonPool.activeChildren[i]; + matchMakerGameButton.SetGame(availableGames[i]); + matchMakerGameButton.transform.localPosition = vector; + vector.y -= this.ButtonHeight; + } + this.TargetArea.YBounds.max = Mathf.Max(0f, -vector.y - this.ButtonStart); + } + + public void ExitGame() + { + AmongUsClient.Instance.ExitGame(DisconnectReasons.ExitGame); + } +} |