86 lines
3.0 KiB
C#
86 lines
3.0 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class PvPModePopup : PopupBase
|
|
{
|
|
[Header("Buttons")]
|
|
[SerializeField] private Button twoPlayerBtn;
|
|
[SerializeField] private Button threePlayerBtn;
|
|
[SerializeField] private Button fourPlayerBtn;
|
|
[SerializeField] private Button playBtn;
|
|
[SerializeField] private Button closeBtn;
|
|
|
|
[Header("Input Field")]
|
|
[SerializeField] private TMP_InputField playerOneNameInput;
|
|
[SerializeField] private TMP_InputField playerTwoNameInput;
|
|
[SerializeField] private TMP_InputField playerThreeNameInput;
|
|
[SerializeField] private TMP_InputField playerFourNameInput;
|
|
|
|
[Header("Player Names")]
|
|
private string playerOneName;
|
|
private string playerTwoName;
|
|
private string playerThreeName;
|
|
private string playerFourName;
|
|
|
|
private ScreenManager screenManager;
|
|
private int selectedPlayerCount;
|
|
public int SelectedPlayerCount => selectedPlayerCount;
|
|
|
|
private void OnEnable()
|
|
{
|
|
twoPlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(2));
|
|
threePlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(3));
|
|
fourPlayerBtn.onClick.AddListener(() => OnPlayerCountSelected(4));
|
|
playBtn.onClick.AddListener(OnClick_playBtn);
|
|
closeBtn.onClick.AddListener(OnClick_closeBtn);
|
|
}
|
|
|
|
private void OnDisable()
|
|
{
|
|
twoPlayerBtn.onClick.RemoveAllListeners();
|
|
threePlayerBtn.onClick.RemoveAllListeners();
|
|
fourPlayerBtn.onClick.RemoveAllListeners();
|
|
playBtn.onClick.RemoveAllListeners();
|
|
closeBtn.onClick.RemoveAllListeners();
|
|
}
|
|
private void OnPlayerCountSelected(int count)
|
|
{
|
|
selectedPlayerCount = count;
|
|
UpdateInputFieldsVisibility();
|
|
}
|
|
|
|
private void UpdateInputFieldsVisibility()
|
|
{
|
|
playerOneNameInput.transform.parent.gameObject.SetActive(true);
|
|
playerTwoNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 2);
|
|
playerThreeNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 3);
|
|
playerFourNameInput.transform.parent.gameObject.SetActive(selectedPlayerCount >= 4);
|
|
}
|
|
|
|
private void OnClick_playBtn()
|
|
{
|
|
playerOneName = playerOneNameInput.text;
|
|
playerTwoName = playerTwoNameInput.text;
|
|
playerThreeName = playerThreeNameInput.text;
|
|
playerFourName = playerFourNameInput.text;
|
|
|
|
Debug.Log($"Starting PVP Mode with {selectedPlayerCount} players:");
|
|
Debug.Log($"Player 1: {playerOneName}");
|
|
Debug.Log($"Player 2: {playerTwoName}");
|
|
if (selectedPlayerCount >= 3)
|
|
Debug.Log($"Player 3: {playerThreeName}");
|
|
if (selectedPlayerCount == 4)
|
|
Debug.Log($"Player 4: {playerFourName}");
|
|
|
|
}
|
|
|
|
private void OnClick_closeBtn()
|
|
{
|
|
screenManager = screenManager == null ? InterfaceManager.Instance?.GetInterfaceInstance<ScreenManager>() : screenManager;
|
|
screenManager.ShowScreen(ScreenType.MenuHUDScreen);
|
|
|
|
Hide();
|
|
}
|
|
}
|