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 allButtons = new List(); 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().enabled = show; base.GetComponent().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 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(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().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); } }