feat: added "menu" panic button
This avoids restarting the game when encountering an unknown issue.
This commit is contained in:
parent
b9a7a1c479
commit
34d9e9261e
4 changed files with 46 additions and 3 deletions
|
|
@ -1,4 +1,5 @@
|
|||
using GB.Core;
|
||||
using GB.Networking.Utils;
|
||||
using GB.Platform.Lobby;
|
||||
using UnityEngine;
|
||||
|
||||
|
|
@ -21,4 +22,11 @@ public class GBSUClient : MonoBehaviour
|
|||
GBSUGui.PushError("You are currently hosting a game! Please stop your server before attempting to join.");
|
||||
}
|
||||
}
|
||||
|
||||
// this method should be used when something has went wrong
|
||||
// because players can just use the escape menu to exit
|
||||
public static void DisconnectFromServer()
|
||||
{
|
||||
GBNetUtils.DisconnectSelf(false);
|
||||
}
|
||||
}
|
||||
|
|
@ -59,6 +59,10 @@ Set CLI arguments: -ip, -port (optionally -maplist)
|
|||
{
|
||||
Application.Quit(0);
|
||||
}
|
||||
if (GUI.Button(new Rect(320f, 45f, 55f, 30f), "Menu"))
|
||||
{
|
||||
Helper.SwitchToMenu();
|
||||
}
|
||||
if (Helper.serverip != null)
|
||||
{
|
||||
if (GUI.Button(new Rect(20f, 260f, 170f, 30f), "Host"))
|
||||
|
|
|
|||
|
|
@ -4,7 +4,6 @@ using GB.Core;
|
|||
using GB.Game;
|
||||
using HarmonyLib;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
#pragma warning disable IDE0051 // Private member is unused
|
||||
|
||||
|
|
@ -41,7 +40,7 @@ public class GBSUServer : MonoBehaviour
|
|||
AudioListener.volume = 0; // mute game audio
|
||||
|
||||
Plugin.AddServerComp(); // add custom GBSU server component
|
||||
|
||||
|
||||
RotationConfig gameConfig = GBConfigLoader.LoadRotationConfig(null); // the argument doesn't matter as we do stuff in the method
|
||||
ServerConfig serverConfig = NetConfigLoader.LoadServerConfig(); // load default server config, because it can be overridden by args like -ip and -port
|
||||
MonoSingleton<Global>.Instance.UNetManager.LaunchServer(serverConfig); // launch the server with the server config
|
||||
|
|
@ -63,7 +62,7 @@ public class GBSUServer : MonoBehaviour
|
|||
Plugin.DestroyServerComp();
|
||||
|
||||
// go back to main menu
|
||||
SceneManager.LoadScene("Menu");
|
||||
Helper.SwitchToMenu();
|
||||
}
|
||||
/*
|
||||
public string GetRemainingRoundTime()
|
||||
|
|
|
|||
|
|
@ -1,7 +1,11 @@
|
|||
using System;
|
||||
using System.IO;
|
||||
using GB.Core;
|
||||
using GB.Networking.Utils;
|
||||
using GB.Platform.Lobby;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Analytics;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace GBSU.Addons;
|
||||
public class Helper
|
||||
|
|
@ -83,4 +87,32 @@ public class Helper
|
|||
Plugin.Log.LogInfo("Set custom rotation config path at " + GameConfigPath);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SwitchToMenu()
|
||||
{
|
||||
if (hosting)
|
||||
{
|
||||
GBSUGui.PushError("Please press the Stop server button instead!");
|
||||
}
|
||||
else
|
||||
{
|
||||
// uhm, time to panic!
|
||||
|
||||
// let's begin by disconnecting if theres an active connection
|
||||
try
|
||||
{
|
||||
GBNetUtils.DisconnectSelf(false);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Plugin.Log.LogWarning("Couldn't disconnect from server:\n" + e);
|
||||
}
|
||||
|
||||
// go back to main menu
|
||||
SceneManager.LoadScene(Global.MENU_SCENE_NAME);
|
||||
|
||||
// make sure our lobby state is menu
|
||||
LobbyManager.Instance.LobbyStates.SelfState = LobbyState.Game.Menu;
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue