summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/FindAGameManager.cs
blob: b428861d5bb1cbf856a204f1a803936275d34389 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
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);
	}
}