Skip to content

Commit

Permalink
GUI for server settings, Closes #7.
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielKinsman committed Apr 18, 2014
1 parent ce73d2c commit 5e921e1
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 4 deletions.
9 changes: 8 additions & 1 deletion server/server.cs
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,18 @@ public override void Awake()
return;
}

this.Settings = Settings.Load();
if(!this.Settings.Enabled)
{
// mod disabled, go away
Destroy(this.gameObject);
return;
}

// User has just loaded a new game
Server.instance = this;
DontDestroyOnLoad(this.gameObject);

this.Settings = Settings.Load();
this.SetupUdpClient();
this.SubscribeToEvents();
this.tcpWorker.Start();
Expand Down
4 changes: 4 additions & 0 deletions server/settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static string Path
}
}

[Persistent]
public bool Enabled;

// udp client host
[Persistent]
public string Client;
Expand All @@ -54,6 +57,7 @@ public static string Path

public Settings()
{
this.Enabled = true;
this.Client = utils.Settings.DEFAULT_CLIENT;
this.ClientPort = utils.Settings.DEFAULT_CLIENT_PORT;
this.ListenPort = utils.Settings.DEFAULT_SERVER_PORT;
Expand Down
50 changes: 47 additions & 3 deletions server/startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,29 +20,73 @@ You should have received a copy of the GNU General Public License
*/


#if DEBUG


using KSP;
using System;
using UnityEngine;

namespace StandAloneMapView.server
{
[KSPAddon(KSPAddon.Startup.MainMenu, false)]
public class Startup : utils.MonoBehaviourExtended
{
public Settings Settings;

public Startup()
{
this.LogPrefix = "samv server";
}

public override void Awake()
{
this.ShowGUI = true;
this.WindowCaption = "Stand alone map view settings";
}

public override void Start()
{
this.Settings = Settings.Load();
#if DEBUG
// Automatically load default save for quicker testing
HighLogic.SaveFolder = "default";
var game = GamePersistence.LoadGame("persistent", HighLogic.SaveFolder, true, false);
var game = GamePersistence.LoadGame("persistent",
HighLogic.SaveFolder, true, false);
game.startScene = GameScenes.SPACECENTER;
game.Start();
#endif
}

public override void DrawWindow(int id)
{
GUILayout.BeginHorizontal();
GUILayout.Label("Enabled:");
this.Settings.Enabled=Convert.ToBoolean(
GUILayout.Toggle(this.Settings.Enabled, string.Empty));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("client ip/hostname:");
this.Settings.Client = GUILayout.TextField(this.Settings.Client);
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("client udp port:");
this.Settings.ClientPort=Convert.ToInt32(
GUILayout.TextField(this.Settings.ClientPort.ToString()));
GUILayout.EndHorizontal();

GUILayout.BeginHorizontal();
GUILayout.Label("tcp listen port:");
this.Settings.ListenPort=Convert.ToInt32(
GUILayout.TextField(this.Settings.ListenPort.ToString()));
GUILayout.EndHorizontal();

if(GUILayout.Button("Save"))
this.Settings.Save();

GUI.DragWindow();
}
}
}

#endif

0 comments on commit 5e921e1

Please sign in to comment.