Update MenuManager.cs

This commit is contained in:
Mister_Nebula 2021-08-24 22:30:53 +01:00
parent 3e5422af02
commit a5259cb237

View File

@ -7,7 +7,8 @@ namespace QSB.Menus
{ {
private IMenuAPI MenuApi => QSBCore.MenuApi; private IMenuAPI MenuApi => QSBCore.MenuApi;
private PopupMenu PopupMenu; private PopupMenu PopupMenu;
private GameObject MultiplayerButton; private Button HostButton;
private GameObject ClientButton;
private Button DisconnectButton; private Button DisconnectButton;
public void Start() public void Start()
@ -17,28 +18,36 @@ namespace QSB.Menus
private void MakeTitleMenus() private void MakeTitleMenus()
{ {
PopupMenu = MenuApi.MakeInputFieldPopup("IP Address", "IP Address", "Host a server", "Connect to server"); PopupMenu = MenuApi.MakeInputFieldPopup("IP Address", "IP Address", "Connect", "Cancel");
PopupMenu.OnPopupConfirm += Host; PopupMenu.OnPopupConfirm += Connect;
PopupMenu.OnPopupCancel += Connect;
HostButton = MenuApi.TitleScreen_MakeSimpleButton("MULTIPLAYER (HOST)");
HostButton.onClick.AddListener(Host);
ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton("MULTIPLAYER (CONNECT)", PopupMenu);
MultiplayerButton = MenuApi.TitleScreen_MakeMenuOpenButton("MULTIPLAYER", PopupMenu);
DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT"); DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT");
DisconnectButton.gameObject.SetActive(false);
DisconnectButton.onClick.AddListener(Disconnect); DisconnectButton.onClick.AddListener(Disconnect);
DisconnectButton.gameObject.SetActive(false);
DisconnectButton.GetComponent<CanvasGroup>().alpha = 1f;
} }
private void Disconnect() private void Disconnect()
{ {
QSBNetworkManager.Instance.StopHost(); QSBNetworkManager.Instance.StopHost();
DisconnectButton.gameObject.SetActive(false); DisconnectButton.gameObject.SetActive(false);
MultiplayerButton.SetActive(true); ClientButton.SetActive(true);
HostButton.gameObject.SetActive(true);
} }
private void Host() private void Host()
{ {
QSBNetworkManager.Instance.StartHost(); QSBNetworkManager.Instance.StartHost();
DisconnectButton.gameObject.SetActive(true); DisconnectButton.gameObject.SetActive(true);
MultiplayerButton.SetActive(false); DisconnectButton.GetComponent<CanvasGroup>().alpha = 1f;
ClientButton.SetActive(false);
HostButton.gameObject.SetActive(false);
} }
private void Connect() private void Connect()
@ -46,7 +55,9 @@ namespace QSB.Menus
QSBNetworkManager.Instance.networkAddress = (PopupMenu as PopupInputMenu).GetInputText(); QSBNetworkManager.Instance.networkAddress = (PopupMenu as PopupInputMenu).GetInputText();
QSBNetworkManager.Instance.StartClient(); QSBNetworkManager.Instance.StartClient();
DisconnectButton.gameObject.SetActive(true); DisconnectButton.gameObject.SetActive(true);
MultiplayerButton.SetActive(false); DisconnectButton.GetComponent<CanvasGroup>().alpha = 1f;
ClientButton.SetActive(false);
HostButton.gameObject.SetActive(false);
} }
} }
} }