LethalCompany/Lethal Company/ExportedProject/Assets/Scripts/Assembly-CSharp/QuickMenuManager.cs
2023-12-22 19:30:32 -05:00

219 lines
5.4 KiB
C#

using Dissonance;
using Steamworks;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;
public class QuickMenuManager : MonoBehaviour
{
[Header("HUD")]
public TextMeshProUGUI interactTipText;
public TextMeshProUGUI leaveGameClarificationText;
public Image cursorIcon;
[Header("In-game Menu")]
public GameObject menuContainer;
public GameObject mainButtonsPanel;
public GameObject leaveGameConfirmPanel;
public GameObject settingsPanel;
[Space(3f)]
public GameObject ConfirmKickUserPanel;
public TextMeshProUGUI ConfirmKickPlayerText;
public bool isMenuOpen;
private int currentMicrophoneDevice;
public TextMeshProUGUI currentMicrophoneText;
public DissonanceComms voiceChatModule;
public TextMeshProUGUI changesNotAppliedText;
public TextMeshProUGUI settingsBackButton;
public GameObject PleaseConfirmChangesSettingsPanel;
public Button PleaseConfirmChangesSettingsPanelBackButton;
public CanvasGroup inviteFriendsTextAlpha;
[Header("Player list")]
public PlayerListSlot[] playerListSlots;
public GameObject playerListPanel;
private int playerObjToKick;
private void Start()
{
currentMicrophoneDevice = PlayerPrefs.GetInt("LethalCompany_currentMic", 0);
}
public void OpenQuickMenu()
{
menuContainer.SetActive(value: true);
Cursor.lockState = CursorLockMode.None;
if (!StartOfRound.Instance.localPlayerUsingController)
{
Cursor.visible = true;
}
isMenuOpen = true;
playerListPanel.SetActive(NonHostPlayerSlotsEnabled());
}
public void CloseQuickMenu()
{
if (settingsPanel.activeSelf)
{
IngamePlayerSettings.Instance.DiscardChangedSettings();
}
CloseQuickMenuPanels();
menuContainer.SetActive(value: false);
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
isMenuOpen = false;
}
public void CloseQuickMenuPanels()
{
leaveGameConfirmPanel.SetActive(value: false);
settingsPanel.SetActive(value: false);
mainButtonsPanel.SetActive(value: true);
playerListPanel.SetActive(NonHostPlayerSlotsEnabled());
}
public void DisableInviteFriendsButton()
{
inviteFriendsTextAlpha.alpha = 0.2f;
}
public void InviteFriendsButton()
{
if (!GameNetworkManager.Instance.gameHasStarted)
{
GameNetworkManager.Instance.InviteFriendsUI();
}
}
public void LeaveGame()
{
playerListPanel.SetActive(value: false);
leaveGameConfirmPanel.SetActive(value: true);
mainButtonsPanel.SetActive(value: false);
leaveGameClarificationText.enabled = NetworkManager.Singleton != null && NetworkManager.Singleton.IsServer && !StartOfRound.Instance.inShipPhase;
}
public void LeaveGameConfirm()
{
if (GameNetworkManager.Instance != null)
{
GameNetworkManager.Instance.Disconnect();
}
}
public void EnableUIPanel(GameObject enablePanel)
{
enablePanel.SetActive(value: true);
playerListPanel.SetActive(value: false);
}
public void DisableUIPanel(GameObject enablePanel)
{
enablePanel.SetActive(value: false);
if (enablePanel != mainButtonsPanel)
{
playerListPanel.SetActive(NonHostPlayerSlotsEnabled());
}
}
private void Update()
{
for (int i = 0; i < playerListSlots.Length; i++)
{
if (playerListSlots[i].isConnected)
{
float num = playerListSlots[i].volumeSlider.value / playerListSlots[i].volumeSlider.maxValue;
if (num == -1f)
{
SoundManager.Instance.playerVoiceVolumes[i] = -70f;
}
else
{
SoundManager.Instance.playerVoiceVolumes[i] = num;
}
}
}
}
private bool NonHostPlayerSlotsEnabled()
{
for (int i = 1; i < playerListSlots.Length; i++)
{
if (playerListSlots[i].isConnected)
{
return true;
}
}
return false;
}
public void AddUserToPlayerList(ulong steamId, string playerName, int playerObjectId)
{
if (playerObjectId >= 0 && playerObjectId <= 4)
{
playerListSlots[playerObjectId].KickUserButton.SetActive(StartOfRound.Instance.IsServer);
playerListSlots[playerObjectId].slotContainer.SetActive(value: true);
playerListSlots[playerObjectId].isConnected = true;
playerListSlots[playerObjectId].playerSteamId = steamId;
playerListSlots[playerObjectId].usernameHeader.text = playerName;
if (GameNetworkManager.Instance.localPlayerController != null)
{
playerListSlots[playerObjectId].volumeSliderContainer.SetActive(playerObjectId != (int)GameNetworkManager.Instance.localPlayerController.playerClientId);
}
}
}
public void KickUserFromServer(int playerObjId)
{
ConfirmKickPlayerText.text = "Kick out " + StartOfRound.Instance.allPlayerScripts[playerObjId].playerUsername.Substring(0, Mathf.Min(6, StartOfRound.Instance.allPlayerScripts[playerObjId].playerUsername.Length - 1)) + "?";
playerObjToKick = playerObjId;
ConfirmKickUserPanel.SetActive(value: true);
}
public void CancelKickUserFromServer()
{
ConfirmKickUserPanel.SetActive(value: false);
}
public void ConfirmKickUserFromServer()
{
if (playerObjToKick > 0 && playerObjToKick <= 3)
{
StartOfRound.Instance.KickPlayer(playerObjToKick);
ConfirmKickUserPanel.SetActive(value: false);
}
}
public void RemoveUserFromPlayerList(int playerObjectId)
{
playerListSlots[playerObjectId].slotContainer.SetActive(value: false);
playerListSlots[playerObjectId].isConnected = false;
}
public void OpenUserSteamProfile(int slotId)
{
if (!GameNetworkManager.Instance.disableSteam && playerListSlots[slotId].isConnected && playerListSlots[slotId].playerSteamId != 0L)
{
SteamFriends.OpenUserOverlay(playerListSlots[slotId].playerSteamId, "steamid");
}
}
}