Skip to content

Commit

Permalink
Version 1.0 Release
Browse files Browse the repository at this point in the history
- Deleted settings file to avoid stomping over user settings
- Added SITUATION_TEXT element
- Added new placeholder values
- Added support for Custom Text
  • Loading branch information
Zeenobit committed May 24, 2015
1 parent c22779a commit 54e0489
Show file tree
Hide file tree
Showing 13 changed files with 254 additions and 56 deletions.
7 changes: 0 additions & 7 deletions GameData/KSEA/Historian/Historian.cfg

This file was deleted.

Binary file modified GameData/KSEA/Historian/Historian.dll
Binary file not shown.
4 changes: 1 addition & 3 deletions GameData/KSEA/Historian/Layouts/Alternative.layout
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
KSEA_HISTORIAN_LAYOUT
{
Name = Alternative

{
RECTANGLE
{
Anchor = 0.0,0.5
Expand Down
8 changes: 3 additions & 5 deletions GameData/KSEA/Historian/Layouts/Default.layout
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
KSEA_HISTORIAN_LAYOUT
{
Name = Default

RECTANGLE
{
Anchor = 0.0,0.5
Size = 1.0,0.125
Size = 1.0,0.15
Position = 0.0,0.85
Color = 0.0,0.0,0.0,0.5
}
Expand All @@ -22,9 +20,9 @@ KSEA_HISTORIAN_LAYOUT
{
Anchor = 0.0,0.5
Position = 0.25,0.85
Size = 0.5,0.1
Size = 0.5,0.125
Color = 1.0,1.0,1.0,1.0
Text = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b> (<T+>)<N><size=12><Situation> @ <Body> (<Biome>, <Latitude>� <Longitude>�) </size>
Text = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b> (<T+>)<N><size=12><Situation> @ <Body> (<Biome>)<N><Custom></size>
TextAnchor = MiddleLeft
FontSize = 12
FontStyle = Normal
Expand Down
38 changes: 38 additions & 0 deletions GameData/KSEA/Historian/Layouts/Situational.layout
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
KSEA_HISTORIAN_LAYOUT
{
RECTANGLE
{
Anchor = 0.0,1.0
Size = 1.0,0.175
Position = 0.0,1.0
Color = 0.0,0.0,0.0,0.5
}

FLAG
{
Anchor = 0.0,0.0
Position = 0.02,0.05
Scale = 1,1
DefaultTexture = Squad/Flags/default
}

SITUATION_TEXT
{
Anchor = 0.0,1.0
Size = 1.0,0.175
Position = 0.025,1.0
Color = 1.0,1.0,1.0,1.0
TextAnchor = MiddleLeft
FontSize = 12
FontStyle = Normal
Default = <b><UT></b><N><T+><N><Custom>
Landed = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b><N><T+><N><size=12>Landed on <Body>'s <LandingZone><N><Custom></size>
Splashed = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b><N><T+><N><size=12>Splashed in <Body>'s Waters<N><Custom></size>
Prelaunch = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b><N><T+><N><size=12>Preparing for launch from <Body><N><Custom></size>
Flying = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b><N><T+><N><size=12>Flying at Mach <Mach> (<Speed> m/s) <Altitude> meters over <Body>'s <Biome><N><Custom></size>
SubOrbital = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b><N><T+><N><size=12>Flying in a sub-orbital trajectory <Altitude> meters over <Body><N><Custom></size>
Orbiting = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b><N><T+><N><size=12>Orbiting around <Body><N><Custom></size>
Escaping = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b><N><T+><N><size=12>Escaping from <Body><N><Custom></size>
Docked = <size=22><b><Vessel></b></size><N><size=8><N></size><b><UT></b><N><T+><N><size=12>Docked at <Body><N><Custom></size>
}
}
1 change: 1 addition & 0 deletions Source/Historian.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
<Compile Include="Historian\Picture.cs" />
<Compile Include="Historian\Rectangle.cs" />
<Compile Include="Historian\Singleton.cs" />
<Compile Include="Historian\SituationText.cs" />
<Compile Include="Historian\Text.cs" />
<Compile Include="Historian\ToolbarButton.cs" />
<Compile Include="Historian\ToolbarWrapper.cs" />
Expand Down
83 changes: 49 additions & 34 deletions Source/Historian/Configuration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,13 @@ namespace KSEA.Historian
{
public class Configuration
{
public class InvalidVersionException : Exception
{
}

private static readonly Version CurrentVersion = new Version("0.2");
private static readonly Version CurrentVersion = new Version("1.0");

private string m_Layout = "";
private bool m_EnableLauncherButton = true;
private bool m_EnableToolbarButton = true;
private string m_CustomText = "";
private bool m_PersitentCustomText = false;

public string Layout
{
Expand Down Expand Up @@ -71,6 +69,32 @@ public bool EnableToolbarButton
}
}

public string CustomText
{
get
{
return m_CustomText;
}

set
{
m_CustomText = value;
}
}

public bool PersistentCustomText
{
get
{
return m_PersitentCustomText;
}

set
{
m_PersitentCustomText = value;
}
}

public static Configuration Load(string file)
{
try
Expand All @@ -80,17 +104,15 @@ public static Configuration Load(string file)

var version = node.GetVersion("Version", new Version());

if (version != CurrentVersion)
{
Historian.Print("Version mismatch detected on configuration file.");
configuration.m_Layout = node.GetString("Layout", "Default");
configuration.m_EnableLauncherButton = node.GetBoolean("EnableLauncherButton", true);
configuration.m_EnableToolbarButton = node.GetBoolean("EnableToolbarButton", true);
configuration.m_CustomText = node.GetString("CustomText", "");
configuration.m_PersitentCustomText = node.GetBoolean("PersitentCustomText", false);

throw new InvalidVersionException();
}
else
if (version != CurrentVersion)
{
configuration.m_Layout = node.GetString("Layout", "Default");
configuration.m_EnableLauncherButton = node.GetBoolean("EnableLauncherButton", true);
configuration.m_EnableToolbarButton = node.GetBoolean("EnableToolbarButton", true);
configuration.Save(file);
}

return configuration;
Expand All @@ -99,29 +121,20 @@ public static Configuration Load(string file)
{
Historian.Print("Failed to load configuration file '{0}'. Attempting recovery ...", file);

try
{
if (File.Exists(file))
{
File.Delete(file);

var configuration = new Configuration();
configuration.m_Layout = "Default";
configuration.m_EnableLauncherButton = true;
configuration.m_EnableToolbarButton = true;
configuration.Save(file);

return configuration;
}
}
catch
if (File.Exists(file))
{
Historian.Print("Failed to overwrite invalid configuration file '{0}'.", file);
throw;
File.Delete(file);

}
}

return null;
var configuration = new Configuration();
configuration.m_Layout = "Default";
configuration.m_EnableLauncherButton = true;
configuration.m_EnableToolbarButton = true;
configuration.Save(file);

return configuration;
}
}

public void Save(string file)
Expand All @@ -135,6 +148,8 @@ public void Save(string file)
node.AddValue("Layout", m_Layout);
node.AddValue("EnableLauncherButton", m_EnableLauncherButton);
node.AddValue("EnableToolbarButton", m_EnableToolbarButton);
node.AddValue("CustomText", m_CustomText);
node.AddValue("PersitentCustomText", m_PersitentCustomText);

if (File.Exists(file))
{
Expand Down
11 changes: 8 additions & 3 deletions Source/Historian/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public Editor(Configuration configuration)
m_LauncherButton = new LauncherButton();
m_ToolbarButton = new ToolbarButton();

m_Position = new Rect(0.5f * Screen.width - 200.0f, 0.5f * Screen.height - 130.0f, 400.0f, 260.0f);
m_Position = new Rect(0.5f * Screen.width - 200.0f, 0.5f * Screen.height - 200.0f, 400.0f, 400.0f);

m_NextButtonTexture = GameDatabase.Instance.GetTexture("KSEA/Historian/Historian_Button_Next", false);
m_PreviousButtonTexture = GameDatabase.Instance.GetTexture("KSEA/Historian/Historian_Button_Previous", false);
Expand Down Expand Up @@ -92,6 +92,7 @@ private void OnWindowGUI(int id)
{
GUI.skin = HighLogic.Skin;
var historian = Historian.Instance;
var configuration = historian.GetConfiguration();

GUILayout.BeginVertical();

Expand Down Expand Up @@ -159,6 +160,12 @@ private void OnWindowGUI(int id)

GUILayout.Space(20);

GUILayout.Label("Custom Text:");
configuration.CustomText = GUILayout.TextArea(configuration.CustomText, GUILayout.Height(60));
configuration.PersistentCustomText = GUILayout.Toggle(configuration.PersistentCustomText, "Persistent Custom Text");

GUILayout.Space(20);

GUILayout.BeginHorizontal();
GUILayout.FlexibleSpace();

Expand All @@ -169,8 +176,6 @@ private void OnWindowGUI(int id)

if (GUILayout.Button("Save", GUILayout.Width(100.0f)))
{
var configuration = historian.GetConfiguration();

configuration.Layout = historian.GetCurrentLayoutName();
configuration.EnableLauncherButton = m_EnableLauncherButton;
configuration.EnableToolbarButton = m_EnableToolberButton;
Expand Down
2 changes: 2 additions & 0 deletions Source/Historian/Element.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public static IElement Create(string type)
return new Picture();
case "FLAG":
return new Flag();
case "SITUATION_TEXT":
return new SituationText();
default:
return null;
}
Expand Down
6 changes: 6 additions & 0 deletions Source/Historian/Historian.cs
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,12 @@ void Update()
}
else
{
if (!m_Configuration.PersistentCustomText)
{
m_Configuration.CustomText = "";
m_Configuration.Save(Path.Combine(PluginDirectory, "Historian.cfg"));
}

m_Active = false;
}
}
Expand Down
88 changes: 88 additions & 0 deletions Source/Historian/SituationText.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
using UnityEngine;

namespace KSEA.Historian
{
public class SituationText : Text
{
private string m_Default = "";
private string m_Landed = "";
private string m_Splashed = "";
private string m_Prelaunch = "";
private string m_Flying = "";
private string m_SubOrbital = "";
private string m_Orbiting = "";
private string m_Escaping = "";
private string m_Docked = "";

protected override void OnLoad(ConfigNode node)
{
base.OnLoad(node);

m_Default = node.GetString("Default", "");
m_Landed = node.GetString("Landed", "");
m_Splashed = node.GetString("Splashed", "");
m_Prelaunch = node.GetString("Prelaunch", "");
m_Flying = node.GetString("Flying", "");
m_SubOrbital = node.GetString("SubOrbital", "");
m_Orbiting = node.GetString("Orbiting", "");
m_Escaping = node.GetString("Escaping", "");
m_Docked = node.GetString("Docked", "");
}

protected override void OnDraw(Rect bounds)
{
var text = m_Default;
var vessel = FlightGlobals.ActiveVessel;

if (vessel != null)
{
var situation = vessel.situation;
text = ResolveText(situation);
}

SetText(text);

base.OnDraw(bounds);
}

private string ResolveText(Vessel.Situations situation)
{
switch (situation)
{
case Vessel.Situations.LANDED:

return m_Landed;

case Vessel.Situations.SPLASHED:

return m_Splashed;

case Vessel.Situations.PRELAUNCH:

return m_Prelaunch;

case Vessel.Situations.FLYING:

return m_Flying;

case Vessel.Situations.SUB_ORBITAL:

return m_SubOrbital;

case Vessel.Situations.ORBITING:

return m_Orbiting;

case Vessel.Situations.ESCAPING:

return m_Escaping;

case Vessel.Situations.DOCKED:

return m_Docked;
}

return m_Default;
}
}
}
Loading

0 comments on commit 54e0489

Please sign in to comment.