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;
|
|
|
|
|
private GameObject MultiplayerButton;
|
|
|
|
|
private Button DisconnectButton;
|
2021-06-04 10:31:09 +00:00
|
|
|
|
|
|
|
|
|
public void Start()
|
|
|
|
|
{
|
|
|
|
|
MakeTitleMenus();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void MakeTitleMenus()
|
|
|
|
|
{
|
2021-08-24 20:08:55 +00:00
|
|
|
|
PopupMenu = MenuApi.MakeInputFieldPopup("IP Address", "IP Address", "Host a server", "Connect to server");
|
|
|
|
|
PopupMenu.OnPopupConfirm += Host;
|
|
|
|
|
PopupMenu.OnPopupCancel += Connect;
|
|
|
|
|
|
|
|
|
|
MultiplayerButton = MenuApi.TitleScreen_MakeMenuOpenButton("MULTIPLAYER", PopupMenu);
|
|
|
|
|
DisconnectButton = MenuApi.TitleScreen_MakeSimpleButton("DISCONNECT");
|
|
|
|
|
DisconnectButton.gameObject.SetActive(false);
|
|
|
|
|
DisconnectButton.onClick.AddListener(Disconnect);
|
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);
|
|
|
|
|
MultiplayerButton.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);
|
|
|
|
|
MultiplayerButton.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);
|
|
|
|
|
MultiplayerButton.SetActive(false);
|
2021-06-04 10:31:09 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|