2022-01-17 21:04:02 +00:00
|
|
|
|
using Mirror;
|
|
|
|
|
using Mirror.FizzySteam;
|
|
|
|
|
using QSB.Messaging;
|
2021-12-05 14:06:43 +00:00
|
|
|
|
using QSB.Player;
|
|
|
|
|
using QSB.Player.TransformSync;
|
2021-12-23 17:07:29 -08:00
|
|
|
|
using QSB.SaveSync.Messages;
|
2021-12-04 23:24:26 +00:00
|
|
|
|
using QSB.Utility;
|
2022-01-17 21:04:02 +00:00
|
|
|
|
using Steamworks;
|
|
|
|
|
using System;
|
2021-12-05 14:06:43 +00:00
|
|
|
|
using System.Text;
|
2022-01-14 19:26:58 +00:00
|
|
|
|
using System.Text.RegularExpressions;
|
2021-08-26 08:51:33 +01:00
|
|
|
|
using UnityEngine;
|
2021-08-24 21:08:55 +01:00
|
|
|
|
using UnityEngine.UI;
|
2022-01-17 21:04:02 +00:00
|
|
|
|
using Button = UnityEngine.UI.Button;
|
2021-06-04 11:31:09 +01:00
|
|
|
|
|
|
|
|
|
namespace QSB.Menus
|
|
|
|
|
{
|
2021-10-29 23:00:13 +01:00
|
|
|
|
internal class MenuManager : MonoBehaviour
|
2021-06-04 11:31:09 +01:00
|
|
|
|
{
|
2021-08-27 13:02:05 +01:00
|
|
|
|
public static MenuManager Instance;
|
|
|
|
|
|
2021-06-04 11:31:09 +01:00
|
|
|
|
private IMenuAPI MenuApi => QSBCore.MenuApi;
|
2021-12-08 10:48:11 +00:00
|
|
|
|
|
|
|
|
|
private PopupMenu IPPopup;
|
2022-01-17 21:04:02 +00:00
|
|
|
|
private PopupMenu OneButtonInfoPopup;
|
|
|
|
|
private PopupMenu TwoButtonInfoPopup;
|
2021-12-04 23:24:26 +00:00
|
|
|
|
private bool _addedPauseLock;
|
|
|
|
|
|
2021-12-08 10:48:11 +00:00
|
|
|
|
// Pause menu only
|
2021-08-24 22:30:53 +01:00
|
|
|
|
private Button HostButton;
|
2021-12-08 10:48:11 +00:00
|
|
|
|
private GameObject QuitButton;
|
|
|
|
|
private GameObject DisconnectButton;
|
|
|
|
|
private PopupMenu DisconnectPopup;
|
|
|
|
|
private StringBuilder _nowLoadingSB;
|
|
|
|
|
protected Text _loadingText;
|
2021-12-04 23:24:26 +00:00
|
|
|
|
|
2021-12-08 10:48:11 +00:00
|
|
|
|
// title screen only
|
2021-12-04 23:24:26 +00:00
|
|
|
|
private GameObject ResumeGameButton;
|
|
|
|
|
private GameObject NewGameButton;
|
2021-12-08 10:48:11 +00:00
|
|
|
|
private GameObject ClientButton;
|
2021-12-04 23:24:26 +00:00
|
|
|
|
|
2021-12-05 11:00:18 +00:00
|
|
|
|
private const int _ClientButtonIndex = 2;
|
|
|
|
|
private const int _DisconnectIndex = 3;
|
2021-06-04 11:31:09 +01:00
|
|
|
|
|
2022-01-16 22:15:29 +00:00
|
|
|
|
private const string OpenString = "OPEN TO MULTIPLAYER";
|
|
|
|
|
private const string ConnectString = "CONNECT TO MULTIPLAYER";
|
|
|
|
|
private const string DisconnectString = "DISCONNECT";
|
|
|
|
|
private const string StopHostingString = "STOP HOSTING";
|
|
|
|
|
|
2022-01-17 21:04:02 +00:00
|
|
|
|
private Action PopupOK;
|
|
|
|
|
|
2021-06-04 11:31:09 +01:00
|
|
|
|
public void Start()
|
|
|
|
|
{
|
2021-08-27 13:02:05 +01:00
|
|
|
|
Instance = this;
|
2021-06-04 11:31:09 +01:00
|
|
|
|
MakeTitleMenus();
|
2021-08-26 08:51:33 +01:00
|
|
|
|
QSBSceneManager.OnSceneLoaded += OnSceneLoaded;
|
2022-01-14 22:25:23 -08:00
|
|
|
|
QSBNetworkManager.singleton.OnClientConnected += OnConnected;
|
|
|
|
|
QSBNetworkManager.singleton.OnClientDisconnected += OnDisconnected;
|
2021-08-26 08:51:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-10-29 23:00:13 +01:00
|
|
|
|
private void OnSceneLoaded(OWScene oldScene, OWScene newScene, bool isUniverse)
|
2021-08-26 08:51:33 +01:00
|
|
|
|
{
|
2021-12-30 18:00:05 -08:00
|
|
|
|
if (newScene == OWScene.EyeOfTheUniverse)
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<EyeState>.AddListener(OWEvents.EyeStateChanged, OnEyeStateChanged);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
GlobalMessenger<EyeState>.RemoveListener(OWEvents.EyeStateChanged, OnEyeStateChanged);
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-26 08:51:33 +01:00
|
|
|
|
if (isUniverse)
|
|
|
|
|
{
|
|
|
|
|
InitPauseMenus();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (newScene == OWScene.TitleScreen)
|
|
|
|
|
{
|
|
|
|
|
MakeTitleMenus();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-05 14:06:43 +00:00
|
|
|
|
private void ResetStringBuilder()
|
|
|
|
|
{
|
|
|
|
|
if (_nowLoadingSB == null)
|
|
|
|
|
{
|
|
|
|
|
_nowLoadingSB = new StringBuilder();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2022-01-01 22:19:10 +00:00
|
|
|
|
|
2021-12-05 14:06:43 +00:00
|
|
|
|
_nowLoadingSB.Length = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
2021-12-08 10:48:11 +00:00
|
|
|
|
if (QSBCore.IsInMultiplayer
|
2021-12-22 22:44:31 -08:00
|
|
|
|
&& (LoadManager.GetLoadingScene() == OWScene.SolarSystem || LoadManager.GetLoadingScene() == OWScene.EyeOfTheUniverse)
|
|
|
|
|
&& _loadingText != null)
|
2021-12-05 14:06:43 +00:00
|
|
|
|
{
|
|
|
|
|
var num = LoadManager.GetAsyncLoadProgress();
|
|
|
|
|
num = num < 0.1f
|
|
|
|
|
? Mathf.InverseLerp(0f, 0.1f, num) * 0.9f
|
|
|
|
|
: 0.9f + (Mathf.InverseLerp(0.1f, 1f, num) * 0.1f);
|
|
|
|
|
ResetStringBuilder();
|
|
|
|
|
_nowLoadingSB.Append(UITextLibrary.GetString(UITextType.LoadingMessage));
|
|
|
|
|
_nowLoadingSB.Append(num.ToString("P0"));
|
|
|
|
|
_loadingText.text = _nowLoadingSB.ToString();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-21 14:35:35 -08:00
|
|
|
|
public void JoinGame(bool inEye)
|
2021-12-05 14:06:43 +00:00
|
|
|
|
{
|
|
|
|
|
if (inEye)
|
|
|
|
|
{
|
|
|
|
|
LoadManager.LoadSceneAsync(OWScene.EyeOfTheUniverse, true, LoadManager.FadeType.ToBlack, 1f, false);
|
|
|
|
|
Locator.GetMenuInputModule().DisableInputs();
|
|
|
|
|
}
|
2021-12-21 14:35:35 -08:00
|
|
|
|
else
|
2021-12-05 14:06:43 +00:00
|
|
|
|
{
|
|
|
|
|
LoadManager.LoadSceneAsync(OWScene.SolarSystem, true, LoadManager.FadeType.ToBlack, 1f, false);
|
|
|
|
|
Locator.GetMenuInputModule().DisableInputs();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 21:04:02 +00:00
|
|
|
|
private void OpenInfoPopup(string message, string okButtonText)
|
2021-08-26 14:56:42 +01:00
|
|
|
|
{
|
2022-01-17 21:04:02 +00:00
|
|
|
|
OneButtonInfoPopup.SetUpPopup(message, InputLibrary.menuConfirm, InputLibrary.cancel, new ScreenPrompt(okButtonText), null, true, false);
|
2021-08-26 14:56:42 +01:00
|
|
|
|
|
|
|
|
|
OWTime.Pause(OWTime.PauseType.System);
|
|
|
|
|
OWInput.ChangeInputMode(InputMode.Menu);
|
|
|
|
|
|
|
|
|
|
var pauseCommandListener = Locator.GetPauseCommandListener();
|
|
|
|
|
if (pauseCommandListener != null)
|
|
|
|
|
{
|
|
|
|
|
pauseCommandListener.AddPauseCommandLock();
|
|
|
|
|
_addedPauseLock = true;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 21:04:02 +00:00
|
|
|
|
OneButtonInfoPopup.EnableMenu(true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OpenInfoPopup(string message, string okButtonText, string cancelButtonText)
|
|
|
|
|
{
|
|
|
|
|
TwoButtonInfoPopup.SetUpPopup(message, InputLibrary.menuConfirm, InputLibrary.cancel, new ScreenPrompt(okButtonText), new ScreenPrompt(cancelButtonText), true, true);
|
|
|
|
|
|
|
|
|
|
OWTime.Pause(OWTime.PauseType.System);
|
|
|
|
|
OWInput.ChangeInputMode(InputMode.Menu);
|
|
|
|
|
|
|
|
|
|
var pauseCommandListener = Locator.GetPauseCommandListener();
|
|
|
|
|
if (pauseCommandListener != null)
|
|
|
|
|
{
|
|
|
|
|
pauseCommandListener.AddPauseCommandLock();
|
|
|
|
|
_addedPauseLock = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TwoButtonInfoPopup.EnableMenu(true);
|
2021-08-26 14:56:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCloseInfoPopup()
|
|
|
|
|
{
|
|
|
|
|
var pauseCommandListener = Locator.GetPauseCommandListener();
|
|
|
|
|
if (pauseCommandListener != null && _addedPauseLock)
|
|
|
|
|
{
|
|
|
|
|
pauseCommandListener.RemovePauseCommandLock();
|
|
|
|
|
_addedPauseLock = false;
|
|
|
|
|
}
|
2021-11-25 15:38:05 +00:00
|
|
|
|
|
2021-08-26 14:56:42 +01:00
|
|
|
|
OWTime.Unpause(OWTime.PauseType.System);
|
|
|
|
|
OWInput.RestorePreviousInputs();
|
2021-12-08 10:57:00 +00:00
|
|
|
|
|
2022-01-17 21:04:02 +00:00
|
|
|
|
//if (QSBSceneManager.IsInUniverse)
|
|
|
|
|
//{
|
|
|
|
|
// LoadManager.LoadScene(OWScene.TitleScreen, LoadManager.FadeType.ToBlack, 2f);
|
|
|
|
|
//}
|
|
|
|
|
PopupOK?.SafeInvoke();
|
|
|
|
|
PopupOK = null;
|
2021-08-26 14:56:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void CreateCommonPopups()
|
2021-08-26 08:51:33 +01:00
|
|
|
|
{
|
2022-01-16 22:15:29 +00:00
|
|
|
|
IPPopup = MenuApi.MakeInputFieldPopup("Steam ID", "Steam ID", "Connect", "Cancel");
|
2021-12-08 10:48:11 +00:00
|
|
|
|
IPPopup.OnPopupConfirm += Connect;
|
2022-01-14 19:26:58 +00:00
|
|
|
|
IPPopup.OnPopupValidate += Validate;
|
2021-08-26 08:51:33 +01:00
|
|
|
|
|
2022-01-17 21:04:02 +00:00
|
|
|
|
OneButtonInfoPopup = MenuApi.MakeInfoPopup("", "");
|
|
|
|
|
OneButtonInfoPopup.OnDeactivateMenu += OnCloseInfoPopup;
|
|
|
|
|
|
|
|
|
|
TwoButtonInfoPopup = MenuApi.MakeTwoChoicePopup("", "", "");
|
|
|
|
|
TwoButtonInfoPopup.OnDeactivateMenu += OnCloseInfoPopup;
|
2021-08-26 14:56:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 23:24:26 +00:00
|
|
|
|
private void SetButtonActive(Button button, bool active)
|
2021-12-05 14:06:43 +00:00
|
|
|
|
=> SetButtonActive(button?.gameObject, active);
|
2021-12-04 23:24:26 +00:00
|
|
|
|
|
|
|
|
|
private void SetButtonActive(GameObject button, bool active)
|
|
|
|
|
{
|
2021-12-05 11:00:18 +00:00
|
|
|
|
if (button == null)
|
|
|
|
|
{
|
2021-12-08 10:48:11 +00:00
|
|
|
|
DebugLog.DebugWrite($"Warning - Tried to set button to {active}, but it was null.", OWML.Common.MessageType.Warning);
|
2021-12-05 11:00:18 +00:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-04 23:24:26 +00:00
|
|
|
|
button.SetActive(active);
|
|
|
|
|
button.GetComponent<CanvasGroup>().alpha = active ? 1 : 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-26 14:56:42 +01:00
|
|
|
|
private void InitPauseMenus()
|
|
|
|
|
{
|
|
|
|
|
CreateCommonPopups();
|
2021-08-26 08:51:33 +01:00
|
|
|
|
|
2022-01-16 22:15:29 +00:00
|
|
|
|
HostButton = MenuApi.PauseMenu_MakeSimpleButton(OpenString);
|
2021-08-26 08:51:33 +01:00
|
|
|
|
HostButton.onClick.AddListener(Host);
|
|
|
|
|
|
2021-12-08 10:48:11 +00:00
|
|
|
|
DisconnectPopup = MenuApi.MakeTwoChoicePopup("Are you sure you want to disconnect?\r\nThis will send you back to the main menu.", "YES", "NO");
|
|
|
|
|
DisconnectPopup.OnPopupConfirm += Disconnect;
|
|
|
|
|
|
2022-01-16 22:15:29 +00:00
|
|
|
|
DisconnectButton = MenuApi.PauseMenu_MakeMenuOpenButton(DisconnectString, DisconnectPopup);
|
2021-12-08 10:48:11 +00:00
|
|
|
|
|
2021-12-12 10:47:59 +00:00
|
|
|
|
QuitButton = FindObjectOfType<PauseMenuManager>()._exitToMainMenuAction.gameObject;
|
2021-10-15 21:08:17 +01:00
|
|
|
|
|
2021-09-08 09:29:48 +01:00
|
|
|
|
if (QSBCore.IsInMultiplayer)
|
|
|
|
|
{
|
2021-12-05 14:06:43 +00:00
|
|
|
|
SetButtonActive(HostButton, false);
|
2021-12-04 23:24:26 +00:00
|
|
|
|
SetButtonActive(DisconnectButton, true);
|
2021-12-08 10:48:11 +00:00
|
|
|
|
SetButtonActive(QuitButton, false);
|
2021-09-08 09:29:48 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-05 14:06:43 +00:00
|
|
|
|
SetButtonActive(HostButton, true);
|
2021-12-04 23:24:26 +00:00
|
|
|
|
SetButtonActive(DisconnectButton, false);
|
2021-12-08 10:48:11 +00:00
|
|
|
|
SetButtonActive(QuitButton, true);
|
2021-09-08 09:29:48 +01:00
|
|
|
|
}
|
2021-09-25 09:49:53 +01:00
|
|
|
|
|
2021-12-08 10:48:11 +00:00
|
|
|
|
var text = QSBCore.IsHost
|
2022-01-16 22:15:29 +00:00
|
|
|
|
? StopHostingString
|
|
|
|
|
: DisconnectString;
|
2021-12-08 10:48:11 +00:00
|
|
|
|
DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = text;
|
|
|
|
|
|
|
|
|
|
var popupText = QSBCore.IsHost
|
|
|
|
|
? "Are you sure you want to stop hosting?\r\nThis will disconnect all clients and send everyone back to the main menu."
|
|
|
|
|
: "Are you sure you want to disconnect?\r\nThis will send you back to the main menu.";
|
|
|
|
|
DisconnectPopup._labelText.text = popupText;
|
2021-06-04 11:31:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 18:00:05 -08:00
|
|
|
|
private void OnEyeStateChanged(EyeState state)
|
2021-12-30 15:53:10 -08:00
|
|
|
|
{
|
2022-01-16 09:13:18 -08:00
|
|
|
|
if (state >= EyeState.Observatory)
|
2021-12-30 15:53:10 -08:00
|
|
|
|
{
|
|
|
|
|
SetButtonActive(HostButton, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-06-04 11:31:09 +01:00
|
|
|
|
private void MakeTitleMenus()
|
|
|
|
|
{
|
2021-08-26 14:56:42 +01:00
|
|
|
|
CreateCommonPopups();
|
2021-08-26 08:51:33 +01:00
|
|
|
|
|
2022-01-16 22:15:29 +00:00
|
|
|
|
ClientButton = MenuApi.TitleScreen_MakeMenuOpenButton(ConnectString, _ClientButtonIndex, IPPopup);
|
2021-12-08 10:48:11 +00:00
|
|
|
|
_loadingText = ClientButton.transform.GetChild(0).GetChild(1).GetComponent<Text>();
|
2021-09-25 09:49:53 +01:00
|
|
|
|
|
2021-12-04 23:24:26 +00:00
|
|
|
|
ResumeGameButton = GameObject.Find("MainMenuLayoutGroup/Button-ResumeGame");
|
|
|
|
|
NewGameButton = GameObject.Find("MainMenuLayoutGroup/Button-NewGame");
|
|
|
|
|
|
2021-09-25 09:49:53 +01:00
|
|
|
|
if (QSBCore.IsInMultiplayer)
|
|
|
|
|
{
|
2021-12-08 10:48:11 +00:00
|
|
|
|
SetButtonActive(ClientButton, false);
|
2021-12-04 23:24:26 +00:00
|
|
|
|
|
|
|
|
|
if (QSBCore.IsHost)
|
|
|
|
|
{
|
2022-01-18 17:53:10 -08:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(PlayerData.IsLoaded, () => SetButtonActive(ResumeGameButton, PlayerData.LoadLoopCount() > 1));
|
2021-12-04 23:24:26 +00:00
|
|
|
|
SetButtonActive(NewGameButton, true);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
SetButtonActive(ResumeGameButton, false);
|
|
|
|
|
SetButtonActive(NewGameButton, false);
|
|
|
|
|
}
|
2021-09-25 09:49:53 +01:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2021-12-08 10:48:11 +00:00
|
|
|
|
SetButtonActive(ClientButton, true);
|
2022-01-18 17:53:10 -08:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(PlayerData.IsLoaded, () => SetButtonActive(ResumeGameButton, PlayerData.LoadLoopCount() > 1));
|
2021-12-04 23:24:26 +00:00
|
|
|
|
SetButtonActive(NewGameButton, true);
|
2021-09-25 09:49:53 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-11-25 22:44:15 +00:00
|
|
|
|
if (QSBCore.SkipTitleScreen)
|
2021-11-18 18:12:55 -08:00
|
|
|
|
{
|
2022-01-17 21:04:02 +00:00
|
|
|
|
UnityEngine.Application.runInBackground = true;
|
2021-11-18 18:12:55 -08:00
|
|
|
|
var titleScreenManager = FindObjectOfType<TitleScreenManager>();
|
|
|
|
|
var titleScreenAnimation = titleScreenManager._cameraController;
|
|
|
|
|
const float small = 1 / 1000f;
|
|
|
|
|
titleScreenAnimation._gamepadSplash = false;
|
|
|
|
|
titleScreenAnimation._introPan = false;
|
|
|
|
|
titleScreenAnimation._fadeDuration = small;
|
|
|
|
|
titleScreenAnimation.Start();
|
|
|
|
|
var titleAnimationController = titleScreenManager._gfxController;
|
|
|
|
|
titleAnimationController._logoFadeDelay = small;
|
|
|
|
|
titleAnimationController._logoFadeDuration = small;
|
|
|
|
|
titleAnimationController._echoesFadeDelay = small;
|
|
|
|
|
titleAnimationController._optionsFadeDelay = small;
|
|
|
|
|
titleAnimationController._optionsFadeDuration = small;
|
|
|
|
|
titleAnimationController._optionsFadeSpacing = small;
|
|
|
|
|
}
|
2021-06-04 11:31:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 21:08:55 +01:00
|
|
|
|
private void Disconnect()
|
2021-06-04 11:31:09 +01:00
|
|
|
|
{
|
2022-01-15 23:11:40 -08:00
|
|
|
|
QSBNetworkManager.singleton._intentionalDisconnect = true;
|
2022-01-14 22:25:23 -08:00
|
|
|
|
QSBNetworkManager.singleton.StopHost();
|
2021-12-04 23:24:26 +00:00
|
|
|
|
SetButtonActive(DisconnectButton.gameObject, false);
|
2021-12-08 10:48:11 +00:00
|
|
|
|
|
|
|
|
|
Locator.GetSceneMenuManager().pauseMenu._pauseMenu.EnableMenu(false);
|
|
|
|
|
Locator.GetSceneMenuManager().pauseMenu._isPaused = false;
|
|
|
|
|
|
|
|
|
|
OWInput.RestorePreviousInputs();
|
|
|
|
|
|
2021-12-26 21:08:36 -08:00
|
|
|
|
LoadManager.LoadScene(OWScene.TitleScreen, LoadManager.FadeType.ToBlack, 2f);
|
2021-06-04 11:31:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 21:08:55 +01:00
|
|
|
|
private void Host()
|
2021-06-04 11:31:09 +01:00
|
|
|
|
{
|
2022-01-14 22:25:23 -08:00
|
|
|
|
QSBNetworkManager.singleton.StartHost();
|
2022-01-14 22:24:31 -08:00
|
|
|
|
SetButtonActive(DisconnectButton, true);
|
|
|
|
|
SetButtonActive(HostButton, false);
|
|
|
|
|
SetButtonActive(QuitButton, false);
|
2021-12-08 10:48:11 +00:00
|
|
|
|
|
|
|
|
|
var text = QSBCore.IsHost
|
2022-01-16 22:15:29 +00:00
|
|
|
|
? StopHostingString
|
|
|
|
|
: DisconnectString;
|
2021-12-08 10:48:11 +00:00
|
|
|
|
DisconnectButton.transform.GetChild(0).GetChild(1).GetComponent<Text>().text = text;
|
|
|
|
|
|
|
|
|
|
var popupText = QSBCore.IsHost
|
|
|
|
|
? "Are you sure you want to stop hosting?\r\nThis will disconnect all clients and send everyone back to the main menu."
|
|
|
|
|
: "Are you sure you want to disconnect?\r\nThis will send you back to the main menu.";
|
|
|
|
|
DisconnectPopup._labelText.text = popupText;
|
2022-01-17 21:04:02 +00:00
|
|
|
|
|
|
|
|
|
var steamId = ((FizzyFacepunch)Transport.activeTransport).GetSteamID();
|
|
|
|
|
|
2022-01-18 09:22:37 +00:00
|
|
|
|
PopupOK += () => GUIUtility.systemCopyBuffer = steamId;
|
2022-01-17 21:04:02 +00:00
|
|
|
|
|
|
|
|
|
OpenInfoPopup($"Hosting server.\r\nClients will connect using your steam id, which is :\r\n" +
|
|
|
|
|
$"{steamId}\r\n" +
|
|
|
|
|
$"Do you want to copy this to the clipboard?"
|
|
|
|
|
, "YES"
|
|
|
|
|
, "NO");
|
2021-06-04 11:31:09 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-14 19:26:58 +00:00
|
|
|
|
private bool Validate()
|
|
|
|
|
{
|
2022-01-16 17:45:51 +00:00
|
|
|
|
//var inputText = ((PopupInputMenu)IPPopup).GetInputText();
|
|
|
|
|
//var regex = new Regex(@"\A(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\z");
|
|
|
|
|
//return inputText == "localhost" || regex.Match(inputText).Success;
|
|
|
|
|
return ((PopupInputMenu)IPPopup).GetInputText() != "";
|
2022-01-14 19:26:58 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-24 21:08:55 +01:00
|
|
|
|
private void Connect()
|
2021-06-04 11:31:09 +01:00
|
|
|
|
{
|
2022-01-14 19:26:58 +00:00
|
|
|
|
var address = ((PopupInputMenu)IPPopup).GetInputText();
|
2022-01-01 22:19:10 +00:00
|
|
|
|
|
2022-01-14 22:25:23 -08:00
|
|
|
|
QSBNetworkManager.singleton.networkAddress = address;
|
|
|
|
|
QSBNetworkManager.singleton.StartClient();
|
2021-12-04 23:24:26 +00:00
|
|
|
|
|
|
|
|
|
if (QSBSceneManager.CurrentScene == OWScene.TitleScreen)
|
|
|
|
|
{
|
|
|
|
|
SetButtonActive(ResumeGameButton, false);
|
|
|
|
|
SetButtonActive(NewGameButton, false);
|
|
|
|
|
}
|
2021-12-08 10:59:36 +00:00
|
|
|
|
|
|
|
|
|
if (QSBSceneManager.IsInUniverse)
|
|
|
|
|
{
|
|
|
|
|
SetButtonActive(QuitButton, false);
|
|
|
|
|
}
|
2021-06-04 11:31:09 +01:00
|
|
|
|
}
|
2021-08-26 08:51:33 +01:00
|
|
|
|
|
|
|
|
|
private void OnConnected()
|
|
|
|
|
{
|
2021-12-05 14:06:43 +00:00
|
|
|
|
if (QSBCore.IsHost || !QSBCore.IsInMultiplayer)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-26 00:00:07 -08:00
|
|
|
|
QSBCore.UnityEvents.RunWhen(() => PlayerTransformSync.LocalInstance,
|
2021-12-22 22:44:31 -08:00
|
|
|
|
() => new RequestGameStateMessage().Send());
|
2021-08-27 13:02:05 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnKicked(KickReason reason)
|
|
|
|
|
{
|
2021-11-20 19:49:50 +00:00
|
|
|
|
var text = reason switch
|
2021-08-27 13:02:05 +01:00
|
|
|
|
{
|
2021-11-20 19:49:50 +00:00
|
|
|
|
KickReason.QSBVersionNotMatching => "Server refused connection as QSB version does not match.",
|
|
|
|
|
KickReason.GameVersionNotMatching => "Server refused connection as Outer Wilds version does not match.",
|
2022-01-18 17:54:41 -08:00
|
|
|
|
KickReason.GamePlatformNotMatching => "Server refused connection as Outer Wilds platform does not match. (Steam/Epic/Xbox)",
|
2021-12-07 13:35:03 +00:00
|
|
|
|
KickReason.DLCNotMatching => "Server refused connection as DLC installation state does not match.",
|
2021-12-30 16:05:02 +00:00
|
|
|
|
KickReason.InEye => "Server refused connection as game has progressed too far.",
|
2021-11-20 19:49:50 +00:00
|
|
|
|
KickReason.None => "Kicked from server. No reason given.",
|
|
|
|
|
_ => $"Kicked from server. KickReason:{reason}",
|
|
|
|
|
};
|
2022-01-17 21:04:02 +00:00
|
|
|
|
|
|
|
|
|
PopupOK += () =>
|
|
|
|
|
{
|
|
|
|
|
if (QSBSceneManager.IsInUniverse)
|
|
|
|
|
{
|
|
|
|
|
LoadManager.LoadScene(OWScene.TitleScreen, LoadManager.FadeType.ToBlack, 2f);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2021-08-27 13:02:05 +01:00
|
|
|
|
OpenInfoPopup(text, "OK");
|
|
|
|
|
|
2021-12-08 10:59:36 +00:00
|
|
|
|
SetButtonActive(DisconnectButton, false);
|
|
|
|
|
SetButtonActive(ClientButton, true);
|
|
|
|
|
SetButtonActive(HostButton, true);
|
|
|
|
|
SetButtonActive(QuitButton, true);
|
2021-08-26 08:51:33 +01:00
|
|
|
|
}
|
|
|
|
|
|
2022-01-15 23:11:40 -08:00
|
|
|
|
private void OnDisconnected(string error)
|
2021-08-26 08:51:33 +01:00
|
|
|
|
{
|
2022-01-15 23:11:40 -08:00
|
|
|
|
if (error == null)
|
2021-08-26 08:51:33 +01:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2022-01-17 21:04:02 +00:00
|
|
|
|
PopupOK += () =>
|
|
|
|
|
{
|
|
|
|
|
if (QSBSceneManager.IsInUniverse)
|
|
|
|
|
{
|
|
|
|
|
LoadManager.LoadScene(OWScene.TitleScreen, LoadManager.FadeType.ToBlack, 2f);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2022-01-15 23:11:40 -08:00
|
|
|
|
OpenInfoPopup($"Client disconnected with error!\r\n{error}", "OK");
|
2021-08-26 08:51:33 +01:00
|
|
|
|
|
2021-12-05 14:06:43 +00:00
|
|
|
|
SetButtonActive(DisconnectButton, false);
|
|
|
|
|
SetButtonActive(ClientButton, true);
|
2021-12-08 10:59:36 +00:00
|
|
|
|
SetButtonActive(QuitButton, true);
|
2021-12-05 14:06:43 +00:00
|
|
|
|
SetButtonActive(HostButton, true);
|
2022-01-18 17:53:10 -08:00
|
|
|
|
SetButtonActive(ResumeGameButton, PlayerData.LoadLoopCount() > 1);
|
2021-12-05 14:06:43 +00:00
|
|
|
|
SetButtonActive(NewGameButton, true);
|
2021-08-26 08:51:33 +01:00
|
|
|
|
}
|
2021-06-04 11:31:09 +01:00
|
|
|
|
}
|
2021-12-22 22:44:31 -08:00
|
|
|
|
}
|