summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/BanMenu.cs
blob: eaa744018aa314c520f53a8037d9c005312bf642 (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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.Linq;
using InnerNet;
using UnityEngine;

public class BanMenu : MonoBehaviour
{
	public BanButton BanButtonPrefab;

	public SpriteRenderer Background;

	public SpriteRenderer BanButton;

	public SpriteRenderer KickButton;

	public GameObject ContentParent;

	public int selected = -1;

	[HideInInspector]
	public List<BanButton> allButtons = new List<BanButton>();

	public void SetVisible(bool show)
	{
		show &= (PlayerControl.LocalPlayer && PlayerControl.LocalPlayer.Data != null && !PlayerControl.LocalPlayer.Data.IsDead);
		show &= AmongUsClient.Instance.CanKick();
		show &= (MeetingHud.Instance || !ShipStatus.Instance);
		this.BanButton.gameObject.SetActive(AmongUsClient.Instance.CanBan());
		this.KickButton.gameObject.SetActive(AmongUsClient.Instance.CanKick());
		base.GetComponent<SpriteRenderer>().enabled = show;
		base.GetComponent<PassiveButton>().enabled = show;
	}

	private void Update()
	{
		for (int i = 0; i < AmongUsClient.Instance.allClients.Count; i++)
		{
			try
			{
				ClientData client = AmongUsClient.Instance.allClients[i];
				if (client == null)
				{
					break;
				}
				int[] source;
				if (VoteBanSystem.Instance.HasMyVote(client.Id) && VoteBanSystem.Instance.Votes.TryGetValue(client.Id, out source))
				{
					int num = source.Count((int c) => c != 0);
					BanButton banButton = this.allButtons.FirstOrDefault((BanButton b) => b.TargetClientId == client.Id);
					if (banButton && banButton.numVotes != num)
					{
						banButton.SetVotes(num);
					}
				}
			}
			catch
			{
				break;
			}
		}
	}

	public void Show()
	{
		if (this.ContentParent.activeSelf)
		{
			this.Hide();
			return;
		}
		this.selected = -1;
		this.KickButton.color = Color.gray;
		this.BanButton.color = Color.gray;
		this.ContentParent.SetActive(true);
		int num = 0;
		if (AmongUsClient.Instance)
		{
			List<ClientData> allClients = AmongUsClient.Instance.allClients;
			for (int i = 0; i < allClients.Count; i++)
			{
				ClientData clientData = allClients[i];
				if (clientData.Id != AmongUsClient.Instance.ClientId && clientData.Character)
				{
					GameData.PlayerInfo data = clientData.Character.Data;
					if (!string.IsNullOrWhiteSpace(data.PlayerName))
					{
						BanButton banButton = UnityEngine.Object.Instantiate<BanButton>(this.BanButtonPrefab, this.ContentParent.transform);
						banButton.transform.localPosition = new Vector3(-0.2f, -0.15f - 0.4f * (float)num, -1f);
						banButton.Parent = this;
						banButton.NameText.Text = data.PlayerName;
						banButton.TargetClientId = clientData.Id;
						banButton.Unselect();
						this.allButtons.Add(banButton);
						num++;
					}
				}
			}
		}
		this.KickButton.transform.localPosition = new Vector3(-0.8f, -0.15f - 0.4f * (float)num - 0.1f, -1f);
		this.BanButton.transform.localPosition = new Vector3(0.3f, -0.15f - 0.4f * (float)num - 0.1f, -1f);
		float num2 = 0.3f + (float)(num + 1) * 0.4f;
		this.Background.size = new Vector2(3f, num2);
		this.Background.GetComponent<BoxCollider2D>().size = new Vector2(3f, num2);
		this.Background.transform.localPosition = new Vector3(0f, -num2 / 2f + 0.15f, 0.1f);
	}

	public void Hide()
	{
		this.selected = -1;
		this.ContentParent.SetActive(false);
		for (int i = 0; i < this.allButtons.Count; i++)
		{
			UnityEngine.Object.Destroy(this.allButtons[i].gameObject);
		}
		this.allButtons.Clear();
	}

	public void Select(int client)
	{
		if (VoteBanSystem.Instance.HasMyVote(client))
		{
			return;
		}
		this.selected = client;
		for (int i = 0; i < this.allButtons.Count; i++)
		{
			BanButton banButton = this.allButtons[i];
			if (banButton.TargetClientId != client)
			{
				banButton.Unselect();
			}
		}
		this.KickButton.color = Color.white;
		this.BanButton.color = Color.white;
	}

	public void Kick(bool ban)
	{
		if (this.selected >= 0)
		{
			if (AmongUsClient.Instance.CanBan())
			{
				AmongUsClient.Instance.KickPlayer(this.selected, ban);
				this.Hide();
			}
			else
			{
				VoteBanSystem.Instance.CmdAddVote(this.selected);
			}
		}
		this.Select(-1);
	}
}