Dedicated servers can use autorestart

This commit is contained in:
Joonas Rikkonen
2017-07-24 21:21:00 +03:00
parent 379c65e07d
commit aaea8bc709
7 changed files with 88 additions and 25 deletions
@@ -327,6 +327,13 @@ namespace Barotrauma
new GUIMessageBox("", string.Join(" ", args));
}));
commands.Add(new Command("autorestart", "autorestart: Toggle autorestart on/off when hosting a server.", (string[] args) =>
{
if (GameMain.Server == null) return;
GameMain.NetLobbyScreen.ToggleAutoRestart();
NewMessage(GameMain.Server.AutoRestart ? "Automatic restart enabled." : "Automatic restart disabled.", Color.White);
}));
commands.Add(new Command("debugdraw", "debugdraw: Toggle the debug drawing mode on/off.", (string[] args) =>
{
GameMain.DebugDraw = !GameMain.DebugDraw;
@@ -44,11 +44,12 @@ namespace Barotrauma
private GUIDropDown shuttleList;
private Sprite backgroundSprite;
private GUITextBox serverMessage;
private float autoRestartTimer;
public GUITextBox ServerMessage
{
get { return serverMessage; }
@@ -154,6 +155,17 @@ namespace Barotrauma
}
}
public string AutoRestartText()
{
if (GameMain.Server != null)
{
if (!GameMain.Server.AutoRestart || GameMain.Server.ConnectedClients.Count == 0) return "";
return "Restarting in " + ToolBox.SecondsToReadableTime(Math.Max(GameMain.Server.AutoRestartTimer, 0));
}
if (autoRestartTimer == 0.0f) return "";
return "Restarting in " + ToolBox.SecondsToReadableTime(Math.Max(autoRestartTimer, 0));
}
public NetLobbyScreen()
{
@@ -596,6 +608,12 @@ namespace Barotrauma
autoRestartTimer = timer;
}
public void ToggleAutoRestart()
{
autoRestartBox.Selected = !autoRestartBox.Selected;
ToggleAutoRestart(autoRestartBox);
}
private bool ToggleAutoRestart(GUITickBox tickBox)
{
if (GameMain.Server == null) return false;