quantum-space-buddies/QSB/Menus/MenuManager.cs

62 lines
1.7 KiB
C#
Raw Normal View History

2021-08-24 20:08:55 +00:00
using UnityEngine;
using UnityEngine.UI;
2021-06-04 10:31:09 +00:00
namespace QSB.Menus
{
class MenuManager : MonoBehaviour
{
private IMenuAPI MenuApi => QSBCore.MenuApi;
2021-08-24 20:08:55 +00:00
private PopupMenu PopupMenu;
2021-08-24 21:30:53 +00:00
private Button HostButton;
private GameObject ClientButton;
2021-08-24 20:08:55 +00:00
private Button DisconnectButton;
2021-06-04 10:31:09 +00:00
public void Start()
{
MakeTitleMenus();
}
private void MakeTitleMenus()
{
2021-08-24 21:30:53 +00:00
PopupMenu = MenuApi.MakeInputFieldPopup("IP Address", "IP Address", "Connect", "Cancel");
PopupMenu.OnPopupConfirm += Connect;
HostButton = MenuApi.TitleScreen_MakeSimpleButton("MULTIPLAYER (HOST)");
HostButton.onClick.AddListener(Host);
ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("MULTIPLAYER (CONNECT)", PopupMenu);
2021-08-24 20:08:55 +00:00
DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT");
DisconnectButton.onClick.AddListener(Disconnect);
2021-08-24 21:30:53 +00:00
DisconnectButton.gameObject.SetActive(false);
DisconnectButton.GetComponent<CanvasGroup>().alpha = 1f;
2021-06-04 10:31:09 +00:00
}
2021-08-24 20:08:55 +00:00
private void Disconnect()
2021-06-04 10:31:09 +00:00
{
2021-08-24 20:08:55 +00:00
QSBNetworkManager.Instance.StopHost();
DisconnectButton.gameObject.SetActive(false);
2021-08-24 21:30:53 +00:00
ClientButton.SetActive(true);
HostButton.gameObject.SetActive(true);
2021-06-04 10:31:09 +00:00
}
2021-08-24 20:08:55 +00:00
private void Host()
2021-06-04 10:31:09 +00:00
{
2021-08-24 20:08:55 +00:00
QSBNetworkManager.Instance.StartHost();
DisconnectButton.gameObject.SetActive(true);
2021-08-24 21:30:53 +00:00
DisconnectButton.GetComponent<CanvasGroup>().alpha = 1f;
ClientButton.SetActive(false);
HostButton.gameObject.SetActive(false);
2021-06-04 10:31:09 +00:00
}
2021-08-24 20:08:55 +00:00
private void Connect()
2021-06-04 10:31:09 +00:00
{
2021-08-24 20:08:55 +00:00
QSBNetworkManager.Instance.networkAddress = (PopupMenu as PopupInputMenu).GetInputText();
2021-06-04 10:31:09 +00:00
QSBNetworkManager.Instance.StartClient();
2021-08-24 20:08:55 +00:00
DisconnectButton.gameObject.SetActive(true);
2021-08-24 21:30:53 +00:00
DisconnectButton.GetComponent<CanvasGroup>().alpha = 1f;
ClientButton.SetActive(false);
HostButton.gameObject.SetActive(false);
2021-06-04 10:31:09 +00:00
}
}
}