Added OnSkinChanged call to ctor to avoid null styles sometimes happening.
--- /dev/null
+++ b/API/Attributes/AVOID_SaveValue.cs
@@ -1,1 +1,48 @@
+// VOID
+//
+// AVOID_SaveValue.cs
+//
+// Copyright © 2015, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+namespace VOID
+{
+ [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)]
+ public class AVOID_SaveValue : Attribute
+ {
+ public string Name
+ {
+ get;
+ private set;
+ }
+
+ public AVOID_SaveValue(string fieldName)
+ {
+ this.Name = fieldName;
+ }
+ }
+}
+
+
--- /dev/null
+++ b/API/Attributes/VOID_ScenesAttribute.cs
@@ -1,1 +1,48 @@
+// VOID
+//
+// VOID_ScenesAttribute.cs
+//
+// Copyright © 2015, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+namespace VOID
+{
+ [AttributeUsage(AttributeTargets.Class)]
+ public class VOID_ScenesAttribute : Attribute
+ {
+ public GameScenes[] ValidScenes
+ {
+ get;
+ private set;
+ }
+
+ public VOID_ScenesAttribute(params GameScenes[] validScenes)
+ {
+ this.ValidScenes = validScenes;
+ }
+ }
+}
+
+
--- /dev/null
+++ b/API/IVOID_DataValue.cs
@@ -1,1 +1,44 @@
+// VOID
+//
+// IVOID_DataValue.cs
+//
+// Copyright © 2015, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+namespace VOID
+{
+ public interface IVOID_DataValue
+ {
+ string Label { get; }
+ string Units { get; }
+ object Value { get; }
+
+ void Refresh();
+ string ValueUnitString();
+ void DoGUIHorizontal();
+ }
+}
+
+
--- /dev/null
+++ b/API/IVOID_Module.cs
@@ -1,1 +1,58 @@
+// VOID
+//
+// IVOID_Module.cs
+//
+// Copyright © 2014, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+
+namespace VOID
+{
+ public interface IVOID_Module
+ {
+ string Name { get; }
+ bool toggleActive { get; set; }
+ bool guiRunning { get; }
+ bool inValidScene { get; }
+
+ void DrawGUI();
+ void StartGUI();
+ void StopGUI();
+
+ void DrawConfigurables();
+
+ void LoadConfig();
+
+ void _SaveToConfig(KSP.IO.PluginConfiguration config);
+ }
+
+ public interface IVOID_BehaviorModule : IVOID_Module
+ {
+ void Update();
+ void FixedUpdate();
+ void OnDestroy();
+ }
+}
+
--- /dev/null
+++ b/API/IVOID_SaveValue.cs
@@ -1,1 +1,40 @@
+// VOID
+//
+// IVOID_SaveValue.cs
+//
+// Copyright © 2015, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+namespace VOID
+{
+ public interface IVOID_SaveValue
+ {
+ Type type { get; }
+ object value { get; }
+ void SetValue(object v);
+ }
+}
+
+
--- /dev/null
+++ b/API/VOIDCore.cs
@@ -1,1 +1,104 @@
+// VOID
+//
+// IVOID_Core.cs
+//
+// Copyright © 2015, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using KerbalEngineer.VesselSimulator;
+using KSP;
+using System;
+using System.Collections.Generic;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ public abstract class VOIDCore : VOID_Module, IVOID_Module
+ {
+ public const double Constant_G = 6.674e-11;
+ public const int CONFIG_VERSION = 2;
+
+ public static bool useToolbarManager;
+
+ public abstract int configVersion { get; }
+ public virtual bool configNeedsUpdate { get; set; }
+
+ public abstract int windowID { get; }
+ public abstract bool configDirty { get; set; }
+ public abstract bool powerAvailable { get; protected set; }
+
+ public abstract List<IVOID_Module> Modules { get; }
+
+ public abstract float updateTimer { get; protected set; }
+ public abstract double updatePeriod { get; }
+
+ public virtual float saveTimer { get; protected set; }
+
+ public abstract GUISkin Skin { get; }
+
+ public abstract CelestialBody HomeBody { get; }
+ public abstract List<CelestialBody> allBodies { get; }
+ public abstract List<CelestialBody> sortedBodyList { get; protected set; }
+
+ public abstract List<VesselType> allVesselTypes { get; }
+
+ public abstract Stage LastStage { get; protected set; }
+ public abstract Stage[] Stages { get; protected set; }
+
+ public virtual event VOIDEventHandler onApplicationQuit;
+
+ public virtual void OnGUI() {}
+
+ public virtual void OnApplicationQuit()
+ {
+ if (this.onApplicationQuit != null)
+ {
+ this.onApplicationQuit(this);
+ }
+ }
+
+ public override void LoadConfig()
+ {
+ var config = KSP.IO.PluginConfiguration.CreateForType<VOIDCore>(null);
+
+ useToolbarManager = config.GetValue("UseToolbarManager", useToolbarManager);
+
+ base.LoadConfig();
+ }
+
+ public abstract void SaveConfig();
+
+ public override void _SaveToConfig(KSP.IO.PluginConfiguration config)
+ {
+ config.SetValue("UseToolbarManager", useToolbarManager);
+
+ base._SaveToConfig(config);
+ }
+ }
+
+ public delegate void VOIDEventHandler(object sender);
+}
+
+
--- /dev/null
+++ b/API/VOIDMaster.cs
@@ -1,1 +1,160 @@
+// VOID
+//
+// VOIDMaster.cs
+//
+// Copyright © 2014, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+///////////////////////////////////////////////////////////////////////////////
+//
+// Much, much credit to Younata, Adammada, Nivvydaskrl and to all the authors
+// behind MechJeb, RemoteTech Relay Network, ISA MapSat, and Protractor for some
+// invaluable functions and making your nicely written code available to learn from.
+//
+///////////////////////////////////////////////////////////////////////////////
+//
+// This software uses VesselSimulator and Engineer.Extensions from Engineer Redux.
+// Engineer Redux (c) 2013 cybutek
+// Used by permission.
+//
+///////////////////////////////////////////////////////////////////////////////
+using System;
+using UnityEngine;
+using KerbalEngineer.VesselSimulator;
+using ToadicusTools;
+
+namespace VOID
+{
+ public abstract class VOIDMaster<T> : MonoBehaviour
+ where T : VOIDCore_Generic<T>, new()
+ {
+ protected T Core;
+
+ public abstract void Awake();
+
+ public virtual void Update()
+ {
+ if (this.Core != null && !this.InValidScene())
+ {
+ this.LogDebug("We have a Core but the scene is not valid for this master. Saving and disposing.");
+
+ this.Core.SaveConfig ();
+ this.Core.Dispose();
+ this.Core = null;
+ return;
+ }
+
+ if (this.Core == null && this.InValidScene())
+ {
+ this.LogDebug("We have no Core and the scene is valid for this master; re-trying Awake.");
+ this.Awake();
+ return;
+ }
+
+ this.Core.Update ();
+
+ if (this.Core.factoryReset)
+ {
+ this.LogDebug("Factory reset is true; deleting config and disposing!");
+
+ KSP.IO.File.Delete<T>("config.xml");
+ this.Core.Dispose();
+ this.Core = null;
+ }
+ }
+
+ public virtual void FixedUpdate()
+ {
+ if (this.Core == null)
+ {
+ return;
+ }
+
+ this.Core.FixedUpdate ();
+ }
+
+ public virtual void OnGUI()
+ {
+ if (this.Core == null)
+ {
+ return;
+ }
+
+ this.Core.OnGUI();
+ }
+
+ public virtual void OnDestroy()
+ {
+ if (this.Core == null)
+ {
+ return;
+ }
+
+ this.Core.OnDestroy();
+ }
+
+ public virtual void OnApplicationQuit()
+ {
+ if (this.Core == null)
+ {
+ return;
+ }
+
+ this.Core.OnApplicationQuit();
+ }
+
+ protected virtual bool InValidScene()
+ {
+ foreach (var attr in this.GetType().GetCustomAttributes(true))
+ {
+ if (attr is KSPAddon)
+ {
+ KSPAddon addonAttr = (KSPAddon)attr;
+
+ switch (addonAttr.startup)
+ {
+ case KSPAddon.Startup.EveryScene:
+ return true;
+ case KSPAddon.Startup.EditorAny:
+ return HighLogic.LoadedSceneIsEditor;
+ case KSPAddon.Startup.Flight:
+ return HighLogic.LoadedSceneIsFlight;
+ case KSPAddon.Startup.MainMenu:
+ return HighLogic.LoadedScene == GameScenes.MAINMENU;
+ case KSPAddon.Startup.SpaceCentre:
+ return HighLogic.LoadedScene == GameScenes.SPACECENTER;
+ case KSPAddon.Startup.TrackingStation:
+ return HighLogic.LoadedScene == GameScenes.TRACKSTATION;
+ default:
+ return false;
+ }
+ }
+ }
+
+ return false;
+ }
+ }
+}
+
--- /dev/null
+++ b/API/VOID_HUDModule.cs
@@ -1,1 +1,219 @@
-
+// VOID
+//
+// VOID_HUDModule.cs
+//
+// Copyright © 2014, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using KerbalEngineer.VesselSimulator;
+using KSP;
+using System;
+using System.Collections.Generic;
+using System.Text;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ public abstract class VOID_HUDModule : VOID_Module
+ {
+ [AVOID_SaveValue("colorIndex")]
+ protected VOID_SaveValue<int> _colorIndex;
+
+ protected List<Color> textColors;
+
+ [AVOID_SaveValue("positionsLocked")]
+ protected VOID_SaveValue<bool> positionsLocked;
+
+ public virtual int ColorIndex
+ {
+ get
+ {
+ return this._colorIndex;
+ }
+ set
+ {
+ if (this._colorIndex >= this.textColors.Count - 1)
+ {
+ this._colorIndex = 0;
+ return;
+ }
+
+ this._colorIndex = value;
+ }
+ }
+
+ public virtual List<HUDWindow> Windows
+ {
+ get;
+ protected set;
+ }
+
+ public VOID_HUDModule() : base()
+ {
+ this._colorIndex = 0;
+
+ this.textColors = new List<Color>();
+
+ this.textColors.Add(Color.green);
+ this.textColors.Add(Color.black);
+ this.textColors.Add(Color.white);
+ this.textColors.Add(Color.red);
+ this.textColors.Add(Color.blue);
+ this.textColors.Add(Color.yellow);
+ this.textColors.Add(Color.gray);
+ this.textColors.Add(Color.cyan);
+ this.textColors.Add(Color.magenta);
+
+ this.positionsLocked = true;
+
+ this.Windows = new List<HUDWindow>();
+ }
+
+ public override void DrawGUI()
+ {
+ VOID_Styles.labelHud.normal.textColor = textColors [ColorIndex];
+
+ GUI.skin = this.core.Skin;
+
+ if (HighLogic.LoadedSceneIsEditor ||
+ (TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate)
+ )
+ {
+ SimManager.RequestSimulation();
+ }
+
+ foreach (HUDWindow window in this.Windows)
+ {
+ window.WindowPos = GUILayout.Window(
+ this.core.windowID,
+ window.WindowPos,
+ VOID_Tools.GetWindowHandler(window.WindowFunction),
+ GUIContent.none,
+ GUIStyle.none
+ );
+ }
+ }
+
+ public override void DrawConfigurables()
+ {
+ base.DrawConfigurables();
+
+ if (GUILayout.Button (string.Intern("Change HUD color"), GUILayout.ExpandWidth (false)))
+ {
+ ++this.ColorIndex;
+ }
+
+ if (GUILayout.Button(string.Intern("Reset HUD Positions"), GUILayout.ExpandWidth(false)))
+ {
+ foreach (HUDWindow window in this.Windows)
+ {
+ window.WindowPos = new Rect(window.defaultWindowPos);
+ }
+ }
+
+ this.positionsLocked = GUILayout.Toggle(this.positionsLocked,
+ string.Intern("Lock HUD Positions"),
+ GUILayout.ExpandWidth(false));
+ }
+
+ public override void LoadConfig()
+ {
+ base.LoadConfig();
+
+ var config = KSP.IO.PluginConfiguration.CreateForType<VOID_HUDModule>();
+ config.load();
+
+ foreach (HUDWindow window in this.Windows)
+ {
+ string saveName = string.Format("{0}_{1}", this.GetType().Name, window.WindowName);
+ Rect loadedPos = config.GetValue(saveName, window.defaultWindowPos);
+
+ window.WindowPos = loadedPos;
+ }
+ }
+
+ public override void _SaveToConfig(KSP.IO.PluginConfiguration config)
+ {
+ base._SaveToConfig(config);
+
+ foreach (HUDWindow window in this.Windows)
+ {
+ string saveName = string.Format("{0}_{1}", this.GetType().Name, window.WindowName);
+ config.SetValue(saveName, window.WindowPos);
+ }
+ }
+ }
+
+ public class HUDWindow
+ {
+ public readonly Rect defaultWindowPos;
+
+ private Rect _windowPos;
+
+ public Action<int> WindowFunction
+ {
+ get;
+ private set;
+ }
+
+ public Rect WindowPos
+ {
+ get
+ {
+ return this._windowPos;
+ }
+ set
+ {
+ if (value != this._windowPos)
+ {
+ this._windowPos = value;
+
+ if (VOID_Data.Core != null)
+ {
+ VOID_Data.Core.configDirty = true;
+ }
+ }
+ }
+ }
+
+ public string WindowName
+ {
+ get;
+ private set;
+ }
+
+ private HUDWindow() {}
+
+ public HUDWindow(string name, Action<int> windowFunc, Rect defaultPos)
+ {
+ this.WindowName = name;
+ this.WindowFunction = windowFunc;
+ this.defaultWindowPos = defaultPos;
+ this.WindowPos = new Rect(this.defaultWindowPos);
+ }
+ }
+}
+
+
--- /dev/null
+++ b/API/VOID_Module.cs
@@ -1,1 +1,452 @@
-
+// VOID
+//
+// VOID_Module.cs
+//
+// Copyright © 2014, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Reflection;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ public abstract class VOID_Module : IVOID_Module
+ {
+ /*
+ * Fields
+ * */
+ [AVOID_SaveValue("Active")]
+ protected VOID_SaveValue<bool> _Active = false;
+ private GameScenes[] validScenes;
+
+ protected float lastUpdate = 0;
+
+ /*
+ * Properties
+ * */
+ protected virtual VOIDCore core
+ {
+ get
+ {
+ return VOID_Data.Core;
+ }
+ }
+
+ public virtual bool toggleActive
+ {
+ get
+ {
+ return this._Active;
+ }
+ set
+ {
+ this._Active.value = value;
+ }
+ }
+
+ public virtual bool guiRunning
+ {
+ get
+ {
+ if (
+ RenderingManager.fetch == null ||
+ RenderingManager.fetch.postDrawQueue == null ||
+ RenderingManager.fetch.postDrawQueue.Length < 4
+ )
+ {
+ return false;
+ }
+ else
+ {
+ Delegate callback = RenderingManager.fetch.postDrawQueue[3];
+ if (callback == null)
+ {
+ return false;
+ }
+
+ return callback.GetInvocationList().Contains((Callback)this.DrawGUI);
+ }
+ }
+ }
+
+ public virtual GameScenes[] ValidScenes
+ {
+ get
+ {
+ if (this.validScenes == null)
+ {
+ Tools.PostDebugMessage(this, "validScenes is null when checking inValidScene; fetching attribute.");
+ foreach (var attr in this.GetType().GetCustomAttributes(false))
+ {
+ if (attr is VOID_ScenesAttribute)
+ {
+ VOID_ScenesAttribute addonAttr = (VOID_ScenesAttribute)attr;
+
+ this.validScenes = addonAttr.ValidScenes;
+
+ Tools.PostDebugMessage("Found VOID_ScenesAttribute; validScenes set.");
+
+ break;
+ }
+ }
+
+ if (this.validScenes == null)
+ {
+ this.validScenes = new GameScenes[] { GameScenes.FLIGHT };
+ Tools.PostDebugMessage("No VOID_ScenesAttribute found; validScenes defaulted to flight.");
+ }
+ }
+
+ return this.validScenes;
+ }
+ }
+
+ public virtual bool inValidScene
+ {
+ get
+ {
+
+ Tools.PostDebugMessage(
+ this,
+ "Checking if scene is valid: LoadedScene={0}, ValidScenes={1}, inValidScene={2}",
+ Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene),
+ string.Join(", ", this.ValidScenes.Select(s => Enum.GetName(typeof(GameScenes), s)).ToArray()),
+ this.ValidScenes.Contains(HighLogic.LoadedScene)
+ );
+
+ return this.ValidScenes.Contains(HighLogic.LoadedScene);
+ }
+ }
+
+ public virtual string Name
+ {
+ get;
+ protected set;
+ }
+
+ public virtual Vessel vessel
+ {
+ get
+ {
+ return FlightGlobals.ActiveVessel;
+ }
+ }
+
+ /*
+ * Methods
+ * */
+ public void StartGUI()
+ {
+ if (!this.toggleActive || this.guiRunning)
+ {
+ return;
+ }
+
+ Tools.PostDebugMessage (string.Format("Adding {0} to the draw queue.", this.GetType().Name));
+ RenderingManager.AddToPostDrawQueue (3, this.DrawGUI);
+ }
+
+ public void StopGUI()
+ {
+ if (!this.guiRunning)
+ {
+ return;
+ }
+ Tools.PostDebugMessage (string.Format("Removing {0} from the draw queue.", this.GetType().Name));
+ RenderingManager.RemoveFromPostDrawQueue (3, this.DrawGUI);
+ }
+
+ public abstract void DrawGUI();
+
+ public virtual void DrawConfigurables() {}
+
+ public virtual void LoadConfig()
+ {
+ var config = KSP.IO.PluginConfiguration.CreateForType<VOID_Module> ();
+ config.load ();
+
+ if (this is VOIDCore)
+ {
+ int configVersion = config.GetValue("VOID_Core_configValue", 2);
+
+ if (configVersion < VOIDCore.CONFIG_VERSION)
+ {
+ ((VOIDCore)this).configNeedsUpdate = true;
+ }
+ }
+
+ foreach (var field in this.GetType().GetMembers(
+ BindingFlags.NonPublic |
+ BindingFlags.Public |
+ BindingFlags.Instance |
+ BindingFlags.FlattenHierarchy
+ ))
+ {
+ if (!(field is FieldInfo || field is PropertyInfo))
+ {
+ continue;
+ }
+
+ if (field is PropertyInfo && (field as PropertyInfo).GetIndexParameters().Length > 0)
+ {
+ continue;
+ }
+
+ object[] attrs = field.GetCustomAttributes(typeof(AVOID_SaveValue), false);
+
+ if (attrs.Length == 0) {
+ continue;
+ }
+
+ AVOID_SaveValue attr = attrs.FirstOrDefault () as AVOID_SaveValue;
+
+ string fieldName = string.Empty;
+
+ if (this is VOIDCore || this.core.configNeedsUpdate)
+ {
+ string typeName = this.GetType().Name;;
+
+ if (this is VOIDCore && ((VOIDCore)this).configNeedsUpdate)
+ {
+ if (this is VOIDCore_Flight)
+ {
+ typeName = "VOID_Core";
+ }
+ else if (this is VOIDCore_Editor)
+ {
+ typeName = "VOID_EditorCore";
+ }
+ }
+
+ fieldName = string.Format("{0}_{1}", typeName, attr.Name);
+ }
+ else
+ {
+ fieldName = string.Format(
+ "{0}_{1}_{2}",
+ this.GetType().Name,
+ Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene),
+ attr.Name
+ );
+ }
+
+ Tools.PostDebugMessage(string.Format("{0}: Loading field {1}.", this.GetType().Name, fieldName));
+
+ object fieldValue;
+
+ if (field is FieldInfo)
+ {
+ fieldValue = (field as FieldInfo).GetValue(this);
+ }
+ else
+ {
+ fieldValue = (field as PropertyInfo).GetValue(this, null);
+ }
+
+ bool convertBack = false;
+ if (fieldValue is IVOID_SaveValue)
+ {
+ fieldValue = (fieldValue as IVOID_SaveValue).value;
+ convertBack = true;
+ }
+
+ fieldValue = config.GetValue(fieldName, fieldValue);
+
+ if (convertBack)
+ {
+ Type type = typeof(VOID_SaveValue<>).MakeGenericType (fieldValue.GetType ());
+ IVOID_SaveValue convertValue = Activator.CreateInstance (type) as IVOID_SaveValue;
+ convertValue.SetValue (fieldValue);
+ fieldValue = convertValue;
+ }
+
+ if (field is FieldInfo)
+ {
+ (field as FieldInfo).SetValue(this, fieldValue);
+ }
+ else
+ {
+ (field as PropertyInfo).SetValue(this, fieldValue, null);
+ }
+
+ Tools.PostDebugMessage(string.Format("{0}: Loaded field {1}.", this.GetType().Name, fieldName));
+ }
+ }
+
+ public virtual void _SaveToConfig(KSP.IO.PluginConfiguration config)
+ {
+ foreach (var field in this.GetType().GetMembers(
+ BindingFlags.Instance |
+ BindingFlags.NonPublic |
+ BindingFlags.Public |
+ BindingFlags.FlattenHierarchy
+ ))
+ {
+ object[] attrs = field.GetCustomAttributes(typeof(AVOID_SaveValue), false);
+
+ if (attrs.Length == 0) {
+ continue;
+ }
+
+ AVOID_SaveValue attr = attrs.FirstOrDefault () as AVOID_SaveValue;
+
+ string fieldName;
+
+ if (this is VOIDCore)
+ {
+ fieldName = string.Format("{0}_{1}", this.GetType().Name, attr.Name);
+ }
+ else
+ {
+ fieldName = string.Format(
+ "{0}_{1}_{2}",
+ this.GetType().Name,
+ Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene),
+ attr.Name
+ );
+ }
+
+ object fieldValue;
+
+ if (field is FieldInfo)
+ {
+ fieldValue = (field as FieldInfo).GetValue(this);
+ }
+ else
+ {
+ fieldValue = (field as PropertyInfo).GetValue(this, null);
+ }
+
+ if (fieldValue is IVOID_SaveValue)
+ {
+ fieldValue = (fieldValue as IVOID_SaveValue).value;
+ }
+
+ config.SetValue(fieldName, fieldValue);
+
+ Tools.PostDebugMessage(string.Format("{0}: Saved field {1}.", this.GetType().Name, fieldName));
+ }
+ }
+ }
+
+ public abstract class VOID_WindowModule : VOID_Module
+ {
+ [AVOID_SaveValue("WindowPos")]
+ protected Rect WindowPos;
+ protected float defWidth;
+ protected float defHeight;
+
+ protected string inputLockName;
+
+ public VOID_WindowModule() : base()
+ {
+ this.defWidth = 250f;
+ this.defHeight = 50f;
+
+ this.inputLockName = string.Concat(this.Name, "_edlock");
+
+ this.WindowPos = new Rect(Screen.width / 2, Screen.height / 2, this.defWidth, this.defHeight);
+ }
+
+ public abstract void ModuleWindow(int _);
+
+ public override void DrawGUI()
+ {
+ GUI.skin = this.core.Skin;
+
+ Rect _Pos = this.WindowPos;
+
+ _Pos = GUILayout.Window(
+ this.core.windowID,
+ _Pos,
+ VOID_Tools.GetWindowHandler(this.ModuleWindow),
+ this.Name,
+ GUILayout.Width(this.defWidth),
+ GUILayout.Height(this.defHeight)
+ );
+
+ bool cursorInWindow = _Pos.Contains(Mouse.screenPos);
+
+ switch (HighLogic.LoadedScene)
+ {
+ case GameScenes.EDITOR:
+ if (cursorInWindow)
+ {
+ InputLockManager.SetControlLock(
+ ControlTypes.EDITOR_ICON_HOVER | ControlTypes.EDITOR_ICON_PICK |
+ ControlTypes.EDITOR_PAD_PICK_COPY | ControlTypes.EDITOR_PAD_PICK_COPY,
+ this.inputLockName
+ );
+ EditorLogic.fetch.Lock(false, false, false, this.inputLockName);
+ }
+ else
+ {
+ EditorLogic.fetch.Unlock(this.inputLockName);
+ }
+ break;
+ case GameScenes.FLIGHT:
+ if (cursorInWindow)
+ {
+ InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS, this.inputLockName);
+ }
+ else if (InputLockManager.GetControlLock(this.inputLockName) != ControlTypes.None)
+ {
+ InputLockManager.RemoveControlLock(this.inputLockName);
+ }
+ break;
+ case GameScenes.SPACECENTER:
+ if (cursorInWindow)
+ {
+ InputLockManager.SetControlLock(ControlTypes.KSC_FACILITIES, this.inputLockName);
+ }
+ else if (InputLockManager.GetControlLock(this.inputLockName) != ControlTypes.None)
+ {
+ InputLockManager.RemoveControlLock(this.inputLockName);
+ }
+ break;
+ }
+
+ if (HighLogic.LoadedSceneIsEditor)
+ {
+ _Pos = Tools.ClampRectToEditorPad(_Pos);
+ }
+ else
+ {
+ _Pos = Tools.ClampRectToScreen(_Pos);
+ }
+
+ if (_Pos != this.WindowPos)
+ {
+ this.WindowPos = _Pos;
+ this.core.configDirty = true;
+ }
+ }
+ }
+}
+
+
--- /dev/null
+++ b/API/VOID_SingletonModule.cs
@@ -1,1 +1,67 @@
+// VOID
+//
+// VOID_SingletonModule.cs
+//
+// Copyright © 2015, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using System;
+namespace VOID
+{
+ public abstract class VOID_SingletonModule<T> : VOIDCore, IVOID_Module
+ where T : VOID_Module, new()
+ {
+ #region Singleton Members
+ /*
+ * Static Members
+ * */
+ protected static bool _initialized = false;
+
+ public static bool Initialized
+ {
+ get
+ {
+ return _initialized;
+ }
+ }
+
+ protected static T _instance;
+
+ public static T Instance
+ {
+ get
+ {
+ if (_instance == null)
+ {
+ _instance = new T();
+ _initialized = true;
+ }
+ return _instance;
+ }
+ }
+ #endregion
+ }
+}
+
+
--- a/GameData/VOID/Textures/ATM_VOID.cfg
+++ b/GameData/VOID/Textures/ATM_VOID.cfg
@@ -4,9 +4,9 @@
enabled = true
OVERRIDES
{
- VOID/.*
+ VOID/Textures/.*
{
- compress = true
+ compress = false
mipmaps = false
scale = 1
max_size = 0
--- a/IVOID_Module.cs
+++ /dev/null
@@ -1,58 +1,1 @@
-// VOID
-//
-// IVOID_Module.cs
-//
-// Copyright © 2014, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-
-namespace VOID
-{
- public interface IVOID_Module
- {
- string Name { get; }
- bool toggleActive { get; set; }
- bool guiRunning { get; }
- bool inValidScene { get; }
-
- void DrawGUI();
- void StartGUI();
- void StopGUI();
-
- void DrawConfigurables();
-
- void LoadConfig();
-
- void _SaveToConfig(KSP.IO.PluginConfiguration config);
- }
-
- public interface IVOID_BehaviorModule : IVOID_Module
- {
- void Update();
- void FixedUpdate();
- void OnDestroy();
- }
-}
-
--- /dev/null
+++ b/Tools/VOID_DataValue.cs
@@ -1,1 +1,367 @@
-
+// VOID
+//
+// VOID_DataValue.cs
+//
+// Copyright © 2014, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using System;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ public class VOID_DataValue<T> : IVOID_DataValue
+ {
+ /*
+ * Static Members
+ * */
+ public static implicit operator T(VOID_DataValue<T> v)
+ {
+ return (T)v.Value;
+ }
+
+ /*
+ * Instance Members
+ * */
+ /*
+ * Fields
+ * */
+ protected T cache;
+ protected Func<T> ValueFunc;
+ protected float lastUpdate;
+
+ /*
+ * Properties
+ * */
+ public string Label { get; protected set; }
+ public string Units { get; protected set; }
+
+ object IVOID_DataValue.Value
+ {
+ get
+ {
+ return this.Value;
+ }
+ }
+
+ public T Value
+ {
+ get
+ {
+ if (
+ (VOID_Data.Core.updateTimer - this.lastUpdate > VOID_Data.Core.updatePeriod) ||
+ (this.lastUpdate > VOID_Data.Core.updateTimer)
+ )
+ {
+ this.Refresh();
+ }
+ return (T)this.cache;
+ }
+ }
+
+ /*
+ * Methods
+ * */
+ public VOID_DataValue(string Label, Func<T> ValueFunc, string Units = "")
+ {
+ this.Label = Label;
+ this.Units = Units;
+ this.ValueFunc = ValueFunc;
+ this.lastUpdate = 0;
+
+ VOID_Data.DataValues[this.GetHashCode()] = this;
+ }
+
+ public void Refresh()
+ {
+ this.cache = this.ValueFunc.Invoke ();
+ this.lastUpdate = VOID_Data.Core.updateTimer;
+ }
+
+ public T GetFreshValue()
+ {
+ this.Refresh ();
+ return (T)this.cache;
+ }
+
+ public virtual string ValueUnitString() {
+ return this.Value.ToString() + this.Units;
+ }
+
+ public virtual void DoGUIHorizontal()
+ {
+ GUILayout.BeginHorizontal (GUILayout.ExpandWidth (true));
+ GUILayout.Label (this.Label + ":");
+ GUILayout.FlexibleSpace ();
+ GUILayout.Label (this.ValueUnitString(), GUILayout.ExpandWidth (false));
+ GUILayout.EndHorizontal ();
+ }
+
+ public override int GetHashCode()
+ {
+ int hash;
+ unchecked
+ {
+ hash = 79999;
+
+ hash = hash * 104399 + this.Label.GetHashCode();
+ hash = hash * 104399 + this.ValueFunc.GetHashCode();
+ hash = hash * 104399 + this.Units.GetHashCode();
+ }
+
+ return hash;
+ }
+
+ public override string ToString()
+ {
+ return string.Format (
+ "{0}: {1}{2}",
+ this.Label,
+ this.Value.ToString (),
+ this.Units
+ );
+ }
+ }
+
+ public abstract class VOID_NumValue<T> : VOID_DataValue<T>
+ where T : IFormattable, IConvertible, IComparable
+ {
+ public static implicit operator Double(VOID_NumValue<T> v)
+ {
+ return v.ToDouble();
+ }
+
+ public static implicit operator Int32(VOID_NumValue<T> v)
+ {
+ return v.ToInt32();
+ }
+
+
+ public static implicit operator Single(VOID_NumValue<T> v)
+ {
+ return v.ToSingle();
+ }
+
+ protected IFormatProvider formatProvider;
+
+ public VOID_NumValue(string Label, Func<T> ValueFunc, string Units = "") : base(Label, ValueFunc, Units)
+ {
+ this.formatProvider = System.Globalization.CultureInfo.CurrentUICulture;
+ }
+
+ public virtual double ToDouble(IFormatProvider provider)
+ {
+ return this.Value.ToDouble(provider);
+ }
+
+ public virtual double ToDouble()
+ {
+ return this.ToDouble(this.formatProvider);
+ }
+
+ public virtual int ToInt32(IFormatProvider provider)
+ {
+ return this.Value.ToInt32(provider);
+ }
+
+ public virtual int ToInt32()
+ {
+ return this.ToInt32(this.formatProvider);
+ }
+
+ public virtual float ToSingle(IFormatProvider provider)
+ {
+ return this.Value.ToSingle(provider);
+ }
+
+ public virtual float ToSingle()
+ {
+ return this.ToSingle(this.formatProvider);
+ }
+
+ public virtual string ToString(string Format)
+ {
+ return string.Format (
+ "{0}: {1}{2}",
+ this.Label,
+ this.Value.ToString(Format, this.formatProvider),
+ this.Units
+ );
+ }
+
+ public virtual string ToSIString(int digits = 3, int MinMagnitude = 0, int MaxMagnitude = int.MaxValue)
+ {
+ return string.Format (
+ "{0}{1}",
+ Tools.MuMech_ToSI (this, digits, MinMagnitude, MaxMagnitude),
+ this.Units
+ );
+ }
+
+ public virtual string ValueUnitString(string format)
+ {
+ return this.Value.ToString(format, this.formatProvider) + this.Units;
+ }
+
+ public virtual string ValueUnitString(int digits) {
+ return Tools.MuMech_ToSI(this, digits) + this.Units;
+ }
+
+ public virtual string ValueUnitString(int digits, int MinMagnitude, int MaxMagnitude)
+ {
+ return Tools.MuMech_ToSI(this, digits, MinMagnitude, MaxMagnitude) + this.Units;
+ }
+
+ public virtual void DoGUIHorizontal(string format)
+ {
+ GUILayout.BeginHorizontal (GUILayout.ExpandWidth (true));
+ GUILayout.Label (this.Label + ":");
+ GUILayout.FlexibleSpace ();
+ GUILayout.Label (this.ValueUnitString(format), GUILayout.ExpandWidth (false));
+ GUILayout.EndHorizontal ();
+ }
+
+ public virtual int DoGUIHorizontal(int digits, bool precisionButton = true)
+ {
+ if (precisionButton)
+ {
+ return this.DoGUIHorizontalPrec(digits);
+ }
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label(this.Label + ":", GUILayout.ExpandWidth(true));
+ GUILayout.FlexibleSpace();
+ GUILayout.Label(this.ValueUnitString(digits), GUILayout.ExpandWidth(false));
+ GUILayout.EndHorizontal();
+
+ return digits;
+ }
+
+ public virtual int DoGUIHorizontalPrec(int digits)
+ {
+ double magnitude;
+ double magLimit;
+
+ magnitude = Math.Log10(Math.Abs((double)this));
+
+ magLimit = Math.Max(Math.Abs(magnitude), 3d) + 3d;
+ magLimit = Math.Round(Math.Ceiling(magLimit / 3f)) * 3d;
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label(this.Label + "ⁱ:", GUILayout.ExpandWidth(true));
+ GUILayout.FlexibleSpace();
+
+ if (magnitude >= 0)
+ {
+ GUILayout.Label(this.ValueUnitString(3, int.MinValue, (int)magnitude - digits), GUILayout.ExpandWidth(false));
+ }
+ else
+ {
+ GUILayout.Label(this.ValueUnitString(3, (int)magnitude + digits, int.MaxValue), GUILayout.ExpandWidth(false));
+ }
+ GUILayout.EndHorizontal();
+
+ if (Event.current.type == EventType.mouseUp)
+ {
+ Rect lastRect = GUILayoutUtility.GetLastRect();
+ if (lastRect.Contains(Event.current.mousePosition))
+ {
+ Tools.PostDebugMessage(string.Format("{0}: Changing digits from {1} within magLimit {2}.",
+ this.GetType().Name,
+ digits,
+ magLimit));
+
+ if (Event.current.button == 0)
+ {
+ digits = (digits + 3) % (int)magLimit;
+ }
+ else if (Event.current.button == 1)
+ {
+ digits = (digits - 3) % (int)magLimit;
+ }
+
+ if (digits < 0)
+ {
+ digits += (int)magLimit;
+ }
+
+ Tools.PostDebugMessage(string.Format("{0}: Changed digits to {1}." +
+ "\n\tNew minMagnitude: {2}, maxMagnitude: {3}" +
+ "\n\tMagnitude: {4}",
+ this.GetType().Name,
+ digits,
+ magnitude >= 0 ? int.MinValue : (int)magnitude - 4 + digits,
+ magnitude >= 0 ? (int)magnitude - digits : int.MaxValue,
+ magnitude
+ ));
+ }
+ }
+
+ return digits;
+ }
+ }
+
+ public class VOID_DoubleValue : VOID_NumValue<double>
+ {
+ public VOID_DoubleValue(string Label, Func<double> ValueFunc, string Units) : base(Label, ValueFunc, Units) {}
+ }
+
+ public class VOID_FloatValue : VOID_NumValue<float>
+ {
+ public VOID_FloatValue(string Label, Func<float> ValueFunc, string Units) : base(Label, ValueFunc, Units) {}
+ }
+
+ public class VOID_IntValue : VOID_NumValue<int>
+ {
+ public VOID_IntValue(string Label, Func<int> ValueFunc, string Units) : base(Label, ValueFunc, Units) {}
+ }
+
+ public class VOID_StrValue : VOID_DataValue<string>
+ {
+ public VOID_StrValue(string Label, Func<string> ValueFunc) : base(Label, ValueFunc, "") {}
+ }
+
+ public class VOID_Vector3dValue : VOID_DataValue<Vector3d>
+ {
+ public VOID_Vector3dValue(string Label, Func<Vector3d> ValueFunc, string Units)
+ : base(Label, ValueFunc, Units)
+ {}
+
+ public string ToString(string format)
+ {
+ return string.Format("{0}: {1}{2}",
+ this.Label,
+ this.Value.ToString(format),
+ this.Units
+ );
+ }
+
+ public string ValueUnitString(string format) {
+ return this.Value.ToString(format) + this.Units;
+ }
+ }
+}
+
+
--- /dev/null
+++ b/Tools/VOID_SaveValue.cs
@@ -1,1 +1,126 @@
+// VOID
+//
+// VOID_SaveValue.cs
+//
+// Copyright © 2014, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+using KSP;
+using System;
+using System.Collections.Generic;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ public struct VOID_SaveValue<T> : IVOID_SaveValue
+ {
+ private T _value;
+ private Type _type;
+
+ private VOIDCore Core
+ {
+ get
+ {
+ return VOID_Data.Core;
+ }
+ }
+
+ object IVOID_SaveValue.value
+ {
+ get
+ {
+ return this.value;
+ }
+ }
+
+ public T value
+ {
+ get
+ {
+ return this._value;
+ }
+ set
+ {
+ if (this.Core != null && !System.Object.Equals(this._value, value))
+ {
+ Tools.PostDebugMessage (string.Format (
+ "VOID: Dirtying config for type {0} in method {1}." +
+ "\n\t Old Value: {2}, New Value: {3}" +
+ "\n\t Object.Equals(New, Old): {4}",
+ this._type,
+ new System.Diagnostics.StackTrace().GetFrame(1).GetMethod(),
+ this._value,
+ value,
+ System.Object.Equals(this._value, value)
+ ));
+ this.Core.configDirty = true;
+ }
+ this._value = value;
+ }
+ }
+
+ public Type type
+ {
+ get
+ {
+ if (this._type == null && this._value != null)
+ {
+ this._type = this._value.GetType ();
+ }
+ return this._type;
+ }
+ set
+ {
+ this._type = value;
+ }
+ }
+
+ public void SetValue(object v)
+ {
+ this.value = (T)v;
+ }
+
+ public static implicit operator T(VOID_SaveValue<T> v)
+ {
+ return (T)v.value;
+ }
+
+ public static implicit operator VOID_SaveValue<T>(T v)
+ {
+ VOID_SaveValue<T> r = new VOID_SaveValue<T>();
+ r.type = v.GetType();
+ r.value = v;
+
+ return r;
+ }
+
+ public override string ToString()
+ {
+ return this.value.ToString();
+ }
+ }
+}
+
+
--- /dev/null
+++ b/Tools/VOID_Tools.cs
@@ -1,1 +1,1055 @@
-
+// VOID
+//
+// VOID_Tools.cs
+//
+// Copyright © 2014, toadicus
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without modification,
+// are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// 2. Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation and/or other
+// materials provided with the distribution.
+//
+// 3. Neither the name of the copyright holder nor the names of its contributors may be used
+// to endorse or promote products derived from this software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
+// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using KSP;
+using System;
+using System.Collections.Generic;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ public static partial class VOID_Tools
+ {
+ #region CelestialBody Utilities
+ public static bool hasAncestor(this CelestialBody bodyA, CelestialBody bodyB)
+ {
+ if (bodyA == null || bodyB == null)
+ {
+ return false;
+ }
+
+ while (bodyA.orbitDriver != null)
+ {
+ if (bodyA.orbit.referenceBody == bodyB)
+ {
+ return true;
+ }
+
+ bodyA = bodyA.orbit.referenceBody;
+ }
+
+ return false;
+ }
+
+ public static bool NearestRelatedParents(ref CelestialBody bodyA, ref CelestialBody bodyB)
+ {
+ if (bodyA == null || bodyB == null || bodyA.orbitDriver == null || bodyB.orbitDriver == null)
+ {
+ throw new ArgumentException(string.Concat(
+ "CelestialBody::FindRelatedParents: ",
+ "Neither body may be null, and both bodies must have orbits."
+ ));
+ }
+
+ CelestialBody a, b;
+
+ a = bodyA;
+
+ while (bodyA.orbitDriver != null)
+ {
+ b = bodyB;
+
+ while (b.orbitDriver != null)
+ {
+ if (a.orbit.referenceBody == b.orbit.referenceBody)
+ {
+ bodyA = a;
+ bodyB = b;
+ return true;
+ }
+
+ b = b.orbit.referenceBody;
+ }
+
+ a = a.orbit.referenceBody;
+ }
+
+ return false;
+ }
+ #endregion
+
+ #region VESSEL_EXTENSIONS_SCIENCE
+ public static CBAttributeMapSO.MapAttribute GetBiome(this Vessel vessel)
+ {
+ CBAttributeMapSO.MapAttribute mapAttribute;
+
+ try
+ {
+ CBAttributeMapSO BiomeMap = vessel.mainBody.BiomeMap;
+
+ double lat = vessel.latitude * Math.PI / 180d;
+ double lon = vessel.longitude * Math.PI / 180d;
+
+ mapAttribute = BiomeMap.GetAtt(lat, lon);
+
+ /*
+ lon -= Math.PI / 2d;
+
+ if (lon < 0d)
+ {
+ lon += 2d * Math.PI;
+ }
+
+ float v = (float)(lat / Math.PI) + 0.5f;
+ float u = (float)(lon / (2d * Math.PI));
+
+ Color pixelBilinear = BiomeMap.Map.GetPixelBilinear(u, v);
+ mapAttribute = BiomeMap.defaultAttribute;
+
+ if (BiomeMap.Map != null)
+ {
+ if (BiomeMap.exactSearch)
+ {
+ for (int i = 0; i < BiomeMap.Attributes.Length; ++i)
+ {
+ if (pixelBilinear == BiomeMap.Attributes[i].mapColor)
+ {
+ mapAttribute = BiomeMap.Attributes[i];
+ }
+ }
+ }
+ else
+ {
+ float zero = 0;
+ float num = 1 / zero;
+ for (int j = 0; j < BiomeMap.Attributes.Length; ++j)
+ {
+ Color mapColor = BiomeMap.Attributes[j].mapColor;
+ float sqrMagnitude = ((Vector4)(mapColor - pixelBilinear)).sqrMagnitude;
+ if (sqrMagnitude < num)
+ {
+ bool testCase = true;
+ if (BiomeMap.nonExactThreshold != -1)
+ {
+ testCase = (sqrMagnitude < BiomeMap.nonExactThreshold);
+ }
+ if (testCase)
+ {
+ mapAttribute = BiomeMap.Attributes[j];
+ num = sqrMagnitude;
+ }
+ }
+ }
+ }
+ }
+ */
+ }
+ catch (NullReferenceException)
+ {
+ mapAttribute = new CBAttributeMapSO.MapAttribute();
+ mapAttribute.name = "N/A";
+ }
+
+ return mapAttribute;
+ }
+
+ public static ExperimentSituations GetExperimentSituation(this Vessel vessel)
+ {
+ if (vessel == null)
+ {
+ return ExperimentSituations.SrfSplashed;
+ }
+
+ Vessel.Situations situation = vessel.situation;
+
+ switch (situation)
+ {
+ case Vessel.Situations.PRELAUNCH:
+ case Vessel.Situations.LANDED:
+ return ExperimentSituations.SrfLanded;
+ case Vessel.Situations.SPLASHED:
+ return ExperimentSituations.SrfSplashed;
+ case Vessel.Situations.FLYING:
+ if (vessel.altitude < (double)vessel.mainBody.scienceValues.flyingAltitudeThreshold)
+ {
+ return ExperimentSituations.FlyingLow;
+ }
+ else
+ {
+ return ExperimentSituations.FlyingHigh;
+ }
+ }
+
+ if (vessel.altitude < (double)vessel.mainBody.scienceValues.spaceAltitudeThreshold)
+ {
+ return ExperimentSituations.InSpaceLow;
+ }
+ else
+ {
+ return ExperimentSituations.InSpaceHigh;
+ }
+ }
+
+ public static string HumanString(this ExperimentSituations situation)
+ {
+ switch (situation)
+ {
+ case ExperimentSituations.FlyingHigh:
+ return "Upper Atmosphere";
+ case ExperimentSituations.FlyingLow:
+ return "Flying";
+ case ExperimentSituations.SrfLanded:
+ return "Surface";
+ case ExperimentSituations.InSpaceLow:
+ return "Near in Space";
+ case ExperimentSituations.InSpaceHigh:
+ return "High in Space";
+ case ExperimentSituations.SrfSplashed:
+ return "Splashed Down";
+ default:
+ return "Unknown";
+ }
+ }
+ #endregion
+
+ #region VESSEL_EXTENSIONS_LAT_LONG
+ public static string GetLongitudeString(this Vessel vessel, string format = "F4")
+ {
+ string dir_long = "W";
+ double v_long = vessel.longitude;
+
+ v_long = FixDegreeDomain(v_long);
+
+ if (v_long < -180d)
+ {
+ v_long += 360d;
+ }
+ if (v_long >= 180)
+ {
+ v_long -= 360d;
+ }
+
+ if (v_long > 0)
+ dir_long = "E";
+
+ return string.Format("{0}° {1}", Math.Abs(v_long).ToString(format), dir_long);
+ }
+
+ public static string GetLatitudeString(this Vessel vessel, string format = "F4")
+ {
+ string dir_lat = "S";
+ double v_lat = vessel.latitude;
+ if (v_lat > 0)
+ dir_lat = "N";
+
+ return string.Format("{0}° {1}", Math.Abs(v_lat).ToString(format), dir_lat);
+ }
+ #endregion
+
+ #region VESSEL_EXTENSIONS_GENERAL
+ public static double TrueAltitude(Vessel vessel)
+ {
+ double trueAltitude = vessel.orbit.altitude - vessel.terrainAltitude;
+
+ // HACK: This assumes that on worlds with oceans, all water is fixed at 0 m,
+ // and water covers the whole surface at 0 m.
+ if (vessel.terrainAltitude < 0 && vessel.mainBody.ocean)
+ {
+ trueAltitude = vessel.orbit.altitude;
+ }
+
+ return trueAltitude;
+ }
+
+ public static double Radius(this Vessel vessel)
+ {
+ double radius;
+
+ radius = vessel.altitude;
+
+ if (vessel.mainBody != null)
+ {
+ radius += vessel.mainBody.Radius;
+ }
+
+ return radius;
+ }
+ #endregion
+
+ #region GEOMETRY_UTILS
+ public static double FixAngleDomain(double Angle, bool Degrees = false)
+ {
+ double Extent = 2d * Math.PI;
+ if (Degrees)
+ {
+ Extent = 360d;
+ }
+
+ Angle = Angle % (Extent);
+ if (Angle < 0d)
+ {
+ Angle += Extent;
+ }
+
+ return Angle;
+ }
+
+ public static double FixDegreeDomain(double Angle)
+ {
+ return FixAngleDomain(Angle, true);
+ }
+ #endregion
+
+ private static Dictionary<int, GUI.WindowFunction> functionCache;
+ public static UnityEngine.GUI.WindowFunction GetWindowHandler(Action<int> func)
+ {
+ if (functionCache == null)
+ {
+ functionCache = new Dictionary<int, GUI.WindowFunction>();
+ }
+
+ int hashCode = func.GetHashCode();
+
+ if (!functionCache.ContainsKey(hashCode))
+ {
+ functionCache[hashCode] = delegate (int id)
+ {
+ try
+ {
+ func(id);
+ }
+ #if DEBUG
+ catch (ArgumentException)
+ #else
+ catch (ArgumentException)
+ #endif
+ {
+ Debug.LogWarning(
+ string.Format("[{0}]: ArgumentException caught during window call. This is not a bug.",
+ func.Target.GetType().Name
+ ));
+
+ /*#if DEBUG
+ Debug.LogException(ex);
+ #endif*/
+ }
+ catch (Exception ex)
+ {
+ Debug.LogError(
+ string.Format("[{0}]: {1} caught during window call.\nMessage:\n{2}\nStackTrace:\n{3}",
+ func.Target.GetType().Name,
+ ex.GetType().Name,
+ ex.Message,
+ ex.StackTrace
+ ));
+ }
+ };
+ }
+
+ return functionCache[hashCode];
+ }
+
+ /// <summary>
+ /// Formats the interval given in seconds as a human-friendly
+ /// time period in [[[[years, ]days, ]hours, ]minutes, and ]seconds.
+ ///
+ /// Uses sidereal days, since "6 hours per day" is the Kerbal standard.
+ /// </summary>
+ /// <returns>Human readable interval</returns>
+ /// <param name="seconds"></param>
+ public static string FormatInterval(double seconds)
+ {
+ return UnpackedTime.FromSeconds(seconds).FormatAsSpan();
+ }
+
+ /// <summary>
+ /// Formats the date given in seconds since epoch as a human-friendly
+ /// date in the format YY, DD, HH:MM:SS
+ /// </summary>
+ /// <returns>The date.</returns>
+ /// <param name="seconds">Seconds.</param>
+ public static string FormatDate(double seconds)
+ {
+ return UnpackedTime.FromSeconds(seconds).FormatAsDate();
+ }
+
+ public class UnpackedTime
+ {
+ public const double SecondsPerMinute = 60d;
+ public const double SecondsPerHour = 3600d;
+
+ public static double SecondsPerDay
+ {
+ get
+ {
+ if (GameSettings.KERBIN_TIME)
+ {
+ return 21600d;
+ }
+ else
+ {
+ return 86164.1d;
+ }
+ }
+ }
+
+ public static double SecondsPerYear
+ {
+ get
+ {
+ if (GameSettings.KERBIN_TIME)
+ {
+ return 9203545d;
+ }
+ else
+ {
+ return 31558149d;
+ }
+ }
+ }
+
+ public static UnpackedTime FromSeconds(double seconds)
+ {
+ UnpackedTime time = new UnpackedTime();
+
+ time.years = (int)(seconds / SecondsPerYear);
+
+ seconds %= SecondsPerYear;
+
+ time.days = (int)(seconds / SecondsPerDay);
+
+ seconds %= SecondsPerDay;
+
+ time.hours = (int)(seconds / SecondsPerHour);
+
+ seconds %= SecondsPerHour;
+
+ time.minutes = (int)(seconds / SecondsPerMinute);
+
+ seconds %= SecondsPerMinute;
+
+ time.seconds = seconds;
+
+ return time;
+ }
+
+ public static explicit operator UnpackedTime(double seconds)
+ {
+ return FromSeconds(seconds);
+ }
+
+ public static implicit operator double(UnpackedTime time)
+ {
+ return time.ToSeconds();
+ }
+
+ public static UnpackedTime operator+ (UnpackedTime lhs, UnpackedTime rhs)
+ {
+ return FromSeconds(lhs.ToSeconds() + rhs.ToSeconds());
+ }
+
+ public static UnpackedTime operator- (UnpackedTime lhs, UnpackedTime rhs)
+ {
+ return FromSeconds(lhs.ToSeconds() - rhs.ToSeconds());
+ }
+
+ public int years;
+ public int days;
+ public int hours;
+ public int minutes;
+ public double seconds;
+
+ public double ToSeconds()
+ {
+ return (double)years * SecondsPerYear +
+ (double)days * SecondsPerDay +
+ (double)hours * SecondsPerHour +
+ (double)minutes * SecondsPerMinute +
+ seconds;
+ }
+
+ public string FormatAsSpan()
+ {
+ string format_1 = "{0:D1}y {1:D1}d {2:D2}h {3:D2}m {4:00.0}s";
+ string format_2 = "{0:D1}d {1:D2}h {2:D2}m {3:00.0}s";
+ string format_3 = "{0:D2}h {1:D2}m {2:00.0}s";
+ string format_4 = "{0:D2}m {1:00.0}s";
+ string format_5 = "{0:00.0}s";
+
+ if (this.years > 0)
+ {
+ return string.Format(format_1, this.years, this.days, this.hours, this.minutes, this.seconds);
+ }
+ else if (this.days > 0)
+ {
+ return string.Format(format_2, this.days, this.hours, this.minutes, this.seconds);
+ }
+ else if (this.hours > 0)
+ {
+ return string.Format(format_3, this.hours, this.minutes, this.seconds);
+ }
+ else if (this.minutes > 0)
+ {
+ return string.Format(format_4, this.minutes, this.seconds);
+ }
+ else
+ {
+ return string.Format(format_5, this.seconds);
+ }
+ }
+
+ public string FormatAsDate()
+ {
+ string format = "Y{0:D1}, D{1:D1} {2:D2}:{3:D2}:{4:00.0}s";
+
+ return string.Format(format, years, days, hours, minutes, seconds);
+ }
+
+ public UnpackedTime(int years, int days, int hours, int minutes, double seconds)
+ {
+ this.years = years;
+ this.days = days;
+ this.hours = hours;
+ this.minutes = minutes;
+ this.seconds = seconds;
+ }
+
+ public UnpackedTime() : this(0, 0, 0, 0, 0d) {}
+ }
+
+ public static string UppercaseFirst(string s)
+ {
+ if (string.IsNullOrEmpty(s))
+ {
+ return string.Empty;
+ }
+ char[] a = s.ToCharArray();
+ a[0] = char.ToUpper(a[0]);
+ return new string(a);
+ }
+
+ //transfer angles
+ public static double Nivvy_CalcTransferPhaseAngle(double r_current, double r_target, double grav_param)
+ {
+ r_target /= 1000;
+ r_current /= 1000;
+ grav_param /= 1000000000;
+
+ double midpoint = (r_target + r_current) / 2;
+
+ double T_target = (2 * Math.PI) * Math.Sqrt((r_target * r_target * r_target) / grav_param);
+ double T_transfer = (2 * Math.PI) * Math.Sqrt((midpoint * midpoint * midpoint) / grav_param);
+ return 360 * (0.5 - (T_transfer / (2 * T_target)));
+ }
+
+ public static double Younata_DeltaVToGetToOtherBody(double mu, double r1, double r2)
+ {
+ /*
+ def deltaVToGetToOtherBody(mu, r1, r2):
+ # mu = gravity param of common orbiting body of r1 and r2
+ # (e.g. for mun to minmus, mu is kerbin's gravity param
+ # r1 = initial body's orbit radius
+ # r2 = target body's orbit radius
+
+ # return value is km/s
+ sur1 = math.sqrt(mu / r1)
+ sr1r2 = math.sqrt(float(2*r2)/float(r1+r2))
+ mult = sr1r2 - 1
+ return sur1 * mult
+ */
+ double sur1, sr1r2, mult;
+ sur1 = Math.Sqrt(mu / r1);
+ sr1r2 = Math.Sqrt((2 * r2) / (r1 + r2));
+ mult = sr1r2 - 1;
+ return sur1 * mult;
+ }
+
+ public static double Younata_DeltaVToExitSOI(double mu, double r1, double r2, double v)
+ {
+ /*
+ def deltaVToExitSOI(mu, r1, r2, v):
+ # mu = gravity param of current body
+ # r1 = current orbit radius
+ # r2 = SOI radius
+ # v = SOI exit velocity
+ foo = r2 * (v**2) - 2 * mu
+ bar = r1 * foo + (2 * r2 * mu)
+ r = r1*r2
+ return math.sqrt(bar / r)
+ */
+ double foo = r2 * (v * v) - 2 * mu;
+ double bar = r1 * foo + (2 * r2 * mu);
+ double r = r1 * r2;
+ return Math.Sqrt(bar / r);
+ }
+
+ public static double Younata_TransferBurnPoint(double r, double v, double angle, double mu)
+ {
+ /*
+ def transferBurnPoint(r, v, angle, mu):
+ # r = parking orbit radius
+ # v = ejection velocity
+ # angle = phase angle (from function phaseAngle())
+ # mu = gravity param of current body.
+ epsilon = ((v**2)/2) - (mu / r)
+ h = r * v * math.sin(angle)
+ e = math.sqrt(1 + ((2 * epsilon * h**2)/(mu**2)))
+ theta = math.acos(1.0 / e)
+ degrees = theta * (180.0 / math.pi)
+ return 180 - degrees
+ */
+ double epsilon, h, ee, theta, degrees;
+ epsilon = ((v * v) / 2) - (mu / r);
+ h = r * v * Math.Sin(angle);
+ ee = Math.Sqrt(1 + ((2 * epsilon * (h * h)) / (mu * mu)));
+ theta = Math.Acos(1.0 / ee);
+ degrees = theta * (180.0 / Math.PI);
+ return 180 - degrees;
+ // returns the ejection angle
+ }
+
+ public static double Adammada_CurrrentPhaseAngle(
+ double body_LAN,
+ double body_orbitPct,
+ double origin_LAN,
+ double origin_orbitPct
+ )
+ {
+ double angle = (body_LAN / 360 + body_orbitPct) - (origin_LAN / 360 + origin_orbitPct);
+ if (angle > 1)
+ angle = angle - 1;
+ if (angle < 0)
+ angle = angle + 1;
+ if (angle > 0.5)
+ angle = angle - 1;
+ angle = angle * 360;
+ return angle;
+ }
+
+ public static double Adammada_CurrentEjectionAngle(
+ double vessel_long,
+ double origin_rotAngle,
+ double origin_LAN,
+ double origin_orbitPct
+ )
+ {
+ //double eangle = ((FlightGlobals.ActiveVOID.vessel.longitude + orbiting.rotationAngle) - (orbiting.orbit.LAN / 360 + orbiting.orbit.orbitPercent) * 360);
+ double eangle = ((vessel_long + origin_rotAngle) - (origin_LAN / 360 + origin_orbitPct) * 360);
+
+ while (eangle < 0)
+ eangle = eangle + 360;
+ while (eangle > 360)
+ eangle = eangle - 360;
+ if (eangle < 270)
+ eangle = 90 - eangle;
+ else
+ eangle = 450 - eangle;
+ return eangle;
+ }
+
+ public static double mrenigma03_calcphase(Vessel vessel, CelestialBody target) //calculates phase angle between the current body and target body
+ {
+ Vector3d vecthis = new Vector3d();
+ Vector3d vectarget = new Vector3d();
+ vectarget = target.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
+
+ if ((vessel.mainBody.name == "Sun") || (vessel.mainBody.referenceBody.referenceBody.name == "Sun"))
+ {
+ vecthis = vessel.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
+ }
+ else
+ {
+ vecthis = vessel.mainBody.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
+ }
+
+ vecthis = Vector3d.Project(new Vector3d(vecthis.x, 0, vecthis.z), vecthis);
+ vectarget = Vector3d.Project(new Vector3d(vectarget.x, 0, vectarget.z), vectarget);
+
+ Vector3d prograde = new Vector3d();
+ prograde = Quaternion.AngleAxis(90, Vector3d.forward) * vecthis;
+
+ double phase = Vector3d.Angle(vecthis, vectarget);
+
+ if (Vector3d.Angle(prograde, vectarget) > 90)
+ phase = 360 - phase;
+
+ return (phase + 360) % 360;
+ }
+
+ public static double adjustCurrPhaseAngle(double transfer_angle, double curr_phase)
+ {
+ if (transfer_angle < 0)
+ {
+ if (curr_phase > 0)
+ return (-1 * (360 - curr_phase));
+ else if (curr_phase < 0)
+ return curr_phase;
+ }
+ else if (transfer_angle > 0)
+ {
+ if (curr_phase > 0)
+ return curr_phase;
+ else if (curr_phase < 0)
+ return (360 + curr_phase);
+ }
+ return curr_phase;
+ }
+
+ public static double adjust_current_ejection_angle(double curr_ejection)
+ {
+ //curr_ejection WILL need to be adjusted once for all transfers as it returns values ranging -180 to 180
+ // need 0-360 instead
+ //
+ // ie i have -17 in the screenshot
+ // need it to show 343
+ //
+ // do this
+ //
+ // if < 0, add curr to 360 // 360 + (-17) = 343
+ // else its good as it is
+
+ if (curr_ejection < 0)
+ return 360 + curr_ejection;
+ else
+ return curr_ejection;
+
+ }
+
+ public static double adjust_transfer_ejection_angle(double trans_ejection, double trans_phase)
+ {
+ // if transfer_phase_angle < 0 its a lower transfer
+ //180 + curr_ejection
+ // else if transfer_phase_angle > 0 its good as it is
+
+ if (trans_phase < 0)
+ return 180 + trans_ejection;
+ else
+ return trans_ejection;
+
+ }
+
+ public static void display_transfer_angles_SUN2PLANET(CelestialBody body, Vessel vessel)
+ {
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Phase angle (curr/trans):");
+ GUILayout.Label(
+ VOID_Tools.mrenigma03_calcphase(vessel, body).ToString("F3") + "° / " + VOID_Tools.Nivvy_CalcTransferPhaseAngle(
+ vessel.orbit.semiMajorAxis,
+ body.orbit.semiMajorAxis,
+ vessel.mainBody.gravParameter
+ ).ToString("F3") + "°",
+ GUILayout.ExpandWidth(false)
+ );
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Transfer velocity:");
+ GUILayout.Label(
+ (VOID_Tools.Younata_DeltaVToGetToOtherBody(
+ (vessel.mainBody.gravParameter / 1000000000),
+ (vessel.orbit.semiMajorAxis / 1000),
+ (body.orbit.semiMajorAxis / 1000)
+ ) * 1000).ToString("F2") + "m/s",
+ GUILayout.ExpandWidth(false)
+ );
+ GUILayout.EndHorizontal();
+ }
+
+ public static void display_transfer_angles_PLANET2PLANET(CelestialBody body, Vessel vessel)
+ {
+ double dv1 = VOID_Tools.Younata_DeltaVToGetToOtherBody(
+ (vessel.mainBody.referenceBody.gravParameter / 1000000000),
+ (vessel.mainBody.orbit.semiMajorAxis / 1000),
+ (body.orbit.semiMajorAxis / 1000)
+ );
+ double dv2 = VOID_Tools.Younata_DeltaVToExitSOI(
+ (vessel.mainBody.gravParameter / 1000000000),
+ (vessel.orbit.semiMajorAxis / 1000),
+ (vessel.mainBody.sphereOfInfluence / 1000),
+ Math.Abs(dv1)
+ );
+
+ double trans_ejection_angle = VOID_Tools.Younata_TransferBurnPoint(
+ (vessel.orbit.semiMajorAxis / 1000),
+ dv2,
+ (Math.PI / 2.0),
+ (vessel.mainBody.gravParameter / 1000000000)
+ );
+ double curr_ejection_angle = VOID_Tools.Adammada_CurrentEjectionAngle(
+ FlightGlobals.ActiveVessel.longitude,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.rotationAngle,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.LAN,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.orbitPercent
+ );
+
+ double trans_phase_angle = VOID_Tools.Nivvy_CalcTransferPhaseAngle(
+ vessel.mainBody.orbit.semiMajorAxis,
+ body.orbit.semiMajorAxis,
+ vessel.mainBody.referenceBody.gravParameter
+ ) % 360;
+ double curr_phase_angle = VOID_Tools.Adammada_CurrrentPhaseAngle(
+ body.orbit.LAN,
+ body.orbit.orbitPercent,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.LAN,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.orbitPercent
+ );
+
+ double adj_phase_angle = VOID_Tools.adjustCurrPhaseAngle(trans_phase_angle, curr_phase_angle);
+ double adj_trans_ejection_angle = VOID_Tools.adjust_transfer_ejection_angle(trans_ejection_angle, trans_phase_angle);
+ double adj_curr_ejection_angle = VOID_Tools.adjust_current_ejection_angle(curr_ejection_angle);
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Phase angle (curr/trans):");
+ GUILayout.Label(
+ adj_phase_angle.ToString("F3") + "° / " + trans_phase_angle.ToString("F3") + "°",
+ GUILayout.ExpandWidth(false)
+ );
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Ejection angle (curr/trans):");
+ GUILayout.Label(
+ adj_curr_ejection_angle.ToString("F3") + "° / " + adj_trans_ejection_angle.ToString("F3") + "°",
+ GUILayout.ExpandWidth(false)
+ );
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Transfer velocity:");
+ GUILayout.Label((dv2 * 1000).ToString("F2") + "m/s", GUILayout.ExpandWidth(false));
+ GUILayout.EndHorizontal();
+ }
+
+ public static void display_transfer_angles_PLANET2MOON(CelestialBody body, Vessel vessel)
+ {
+ double dv1 = VOID_Tools.Younata_DeltaVToGetToOtherBody(
+ (vessel.mainBody.gravParameter / 1000000000),
+ (vessel.orbit.semiMajorAxis / 1000),
+ (body.orbit.semiMajorAxis / 1000)
+ );
+
+ double trans_phase_angle = VOID_Tools.Nivvy_CalcTransferPhaseAngle(
+ vessel.orbit.semiMajorAxis,
+ body.orbit.semiMajorAxis,
+ vessel.mainBody.gravParameter
+ );
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Phase angle (curr/trans):");
+ GUILayout.Label(
+ VOID_Tools.mrenigma03_calcphase(vessel, body).ToString("F3") + "° / " + trans_phase_angle.ToString("F3") + "°",
+ GUILayout.ExpandWidth(false)
+ );
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Transfer velocity:");
+ GUILayout.Label((dv1 * 1000).ToString("F2") + "m/s", GUILayout.ExpandWidth(false));
+ GUILayout.EndHorizontal();
+ }
+
+ public static void display_transfer_angles_MOON2MOON(CelestialBody body, Vessel vessel)
+ {
+ double dv1 = VOID_Tools.Younata_DeltaVToGetToOtherBody(
+ (vessel.mainBody.referenceBody.gravParameter / 1000000000),
+ (vessel.mainBody.orbit.semiMajorAxis / 1000),
+ (body.orbit.semiMajorAxis / 1000)
+ );
+ double dv2 = VOID_Tools.Younata_DeltaVToExitSOI(
+ (vessel.mainBody.gravParameter / 1000000000),
+ (vessel.orbit.semiMajorAxis / 1000),
+ (vessel.mainBody.sphereOfInfluence / 1000),
+ Math.Abs(dv1)
+ );
+ double trans_ejection_angle = VOID_Tools.Younata_TransferBurnPoint(
+ (vessel.orbit.semiMajorAxis / 1000),
+ dv2,
+ (Math.PI / 2.0),
+ (vessel.mainBody.gravParameter / 1000000000)
+ );
+
+ double curr_phase_angle = VOID_Tools.Adammada_CurrrentPhaseAngle(
+ body.orbit.LAN,
+ body.orbit.orbitPercent,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.LAN,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.orbitPercent
+ );
+ double curr_ejection_angle = VOID_Tools.Adammada_CurrentEjectionAngle(
+ FlightGlobals.ActiveVessel.longitude,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.rotationAngle,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.LAN,
+ FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.orbitPercent
+ );
+
+ double trans_phase_angle = VOID_Tools.Nivvy_CalcTransferPhaseAngle(
+ vessel.mainBody.orbit.semiMajorAxis,
+ body.orbit.semiMajorAxis,
+ vessel.mainBody.referenceBody.gravParameter
+ ) % 360;
+
+ double adj_phase_angle = VOID_Tools.adjustCurrPhaseAngle(trans_phase_angle, curr_phase_angle);
+ //double adj_ejection_angle = adjustCurrEjectionAngle(trans_phase_angle, curr_ejection_angle);
+
+ //new stuff
+ //
+ double adj_trans_ejection_angle = VOID_Tools.adjust_transfer_ejection_angle(trans_ejection_angle, trans_phase_angle);
+ double adj_curr_ejection_angle = VOID_Tools.adjust_current_ejection_angle(curr_ejection_angle);
+ //
+ //
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Phase angle (curr/trans):");
+ GUILayout.Label(
+ adj_phase_angle.ToString("F3") + "° / " + trans_phase_angle.ToString("F3") + "°",
+ GUILayout.ExpandWidth(false)
+ );
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Ejection angle (curr/trans):");
+ GUILayout.Label(
+ adj_curr_ejection_angle.ToString("F3") + "° / " + adj_trans_ejection_angle.ToString("F3") + "°",
+ GUILayout.ExpandWidth(false)
+ );
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+ GUILayout.Label("Transfer velocity:");
+ GUILayout.Label((dv2 * 1000).ToString("F2") + "m/s", GUILayout.ExpandWidth(false));
+ GUILayout.EndHorizontal();
+ }
+
+ public static string get_heading_text(double heading)
+ {
+ if (heading > 348.75 || heading <= 11.25)
+ return "N";
+ else if (heading > 11.25 && heading <= 33.75)
+ return "NNE";
+ else if (heading > 33.75 && heading <= 56.25)
+ return "NE";
+ else if (heading > 56.25 && heading <= 78.75)
+ return "ENE";
+ else if (heading > 78.75 && heading <= 101.25)
+ return "E";
+ else if (heading > 101.25 && heading <= 123.75)
+ return "ESE";
+ else if (heading > 123.75 && heading <= 146.25)
+ return "SE";
+ else if (heading > 146.25 && heading <= 168.75)
+ return "SSE";
+ else if (heading > 168.75 && heading <= 191.25)
+ return "S";
+ else if (heading > 191.25 && heading <= 213.75)
+ return "SSW";
+ else if (heading > 213.75 && heading <= 236.25)
+ return "SW";
+ else if (heading > 236.25 && heading <= 258.75)
+ return "WSW";
+ else if (heading > 258.75 && heading <= 281.25)
+ return "W";
+ else if (heading > 281.25 && heading <= 303.75)
+ return "WNW";
+ else if (heading > 303.75 && heading <= 326.25)
+ return "NW";
+ else if (heading > 326.25 && heading <= 348.75)
+ return "NNW";
+ else
+ return "";
+ }
+ }
+
+ public class CBListComparer : IComparer<CelestialBody>
+ {
+ public int Compare(CelestialBody bodyA, CelestialBody bodyB)
+ {
+ Tools.PostDebugMessage(this, "got bodyA: {0} & bodyB: {1}", bodyA, bodyB);
+
+ if (bodyA == null && bodyB == null)
+ {
+ Tools.PostDebugMessage(this, "both bodies are null, returning 0");
+ return 0;
+ }
+ if (bodyA == null)
+ {
+ Tools.PostDebugMessage(this, "bodyA is null, returning -1");
+ return -1;
+ }
+ if (bodyB == null)
+ {
+ Tools.PostDebugMessage(this, "bodyB is null, returning 1");
+ return 1;
+ }
+
+ Tools.PostDebugMessage(this, "bodies are not null, carrying on");
+
+ if (object.ReferenceEquals(bodyA, bodyB))
+ {
+ Tools.PostDebugMessage(this, "bodies are equal, returning 0");
+ return 0;
+ }
+
+ Tools.PostDebugMessage(this, "bodies are not equal, carrying on");
+
+ if (bodyA.orbitDriver == null)
+ {
+ Tools.PostDebugMessage(this, "bodyA.orbit is null (bodyA is the sun, returning 1");
+ return 1;
+ }
+ if (bodyB.orbitDriver == null)
+ {
+ Tools.PostDebugMessage(this, "bodyB.orbit is null (bodyB is the sun, returning -1");
+ return -1;
+ }
+
+ Tools.PostDebugMessage(this, "orbits are not null, carrying on");
+
+ if (bodyA.orbit.referenceBody == bodyB.orbit.referenceBody)
+ {
+ Tools.PostDebugMessage(this, "bodies share a parent, comparing SMAs");
+ return -bodyA.orbit.semiMajorAxis.CompareTo(bodyB.orbit.semiMajorAxis);
+ }
+
+ Tools.PostDebugMessage(this, "orbits do not share a parent, carrying on");
+
+ if (bodyA.hasAncestor(bodyB))
+ {
+ Tools.PostDebugMessage(this, "bodyA is a moon or sub-moon of bodyB, returning -1");
+ return -1;
+ }
+ if (bodyB.hasAncestor(bodyA))
+ {
+ Tools.PostDebugMessage(this, "bodyA is a moon or sub-moon of bodyB, returning 1");
+ return 1;
+ }
+
+ Tools.PostDebugMessage(this, "bodies do not have an obvious relationship, searching for one");
+
+ if (VOID_Tools.NearestRelatedParents(ref bodyA, ref bodyB))
+ {
+ Tools.PostDebugMessage(this, "good relation {0} and {1}, comparing", bodyA.bodyName, bodyB.bodyName);
+ return this.Compare(bodyA, bodyB);
+ }
+
+ Tools.PostDebugMessage(this, "bad relation {0} and {1}, giving up", bodyA.bodyName, bodyB.bodyName);
+
+ return 0;
+ }
+ }
+}
+
--- a/VOID.csproj
+++ b/VOID.csproj
@@ -73,10 +73,7 @@
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
- <Compile Include="IVOID_Module.cs" />
- <Compile Include="VOID_Module.cs" />
<Compile Include="VOID_HUD.cs" />
- <Compile Include="VOID_SaveValue.cs" />
<Compile Include="VOID_Orbital.cs" />
<Compile Include="VOID_SurfAtmo.cs" />
<Compile Include="VOID_VesselInfo.cs" />
@@ -86,8 +83,6 @@
<Compile Include="VOID_VesselRegister.cs" />
<Compile Include="VOID_DataLogger.cs" />
<Compile Include="VOID_EditorHUD.cs" />
- <Compile Include="VOID_DataValue.cs" />
- <Compile Include="VOID_Tools.cs" />
<Compile Include="VOID_Localization.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="VOID_HUDAdvanced.cs" />
@@ -96,18 +91,26 @@
<Compile Include="VOID_StageInfo.cs" />
<Compile Include="VOID_Styles.cs" />
<Compile Include="VOID_Data.cs" />
- <Compile Include="VOID_HUDModule.cs" />
- <Compile Include="VOIDMaster.cs" />
<Compile Include="VOIDMaster_Flight.cs" />
<Compile Include="VOIDMaster_Editor.cs" />
<Compile Include="VOIDMaster_SpaceCentre.cs" />
<Compile Include="VOIDCore_SpaceCentre.cs" />
- <Compile Include="VOID_ScenesAttribute.cs" />
- <Compile Include="VOID_SingletonModule.cs" />
<Compile Include="VOIDCore_Flight.cs" />
<Compile Include="VOIDCore_Editor.cs" />
<Compile Include="VOIDCore_Generic.cs" />
- <Compile Include="VOIDCore.cs" />
+ <Compile Include="API\IVOID_Module.cs" />
+ <Compile Include="API\VOIDCore.cs" />
+ <Compile Include="API\IVOID_SaveValue.cs" />
+ <Compile Include="API\IVOID_DataValue.cs" />
+ <Compile Include="API\VOID_Module.cs" />
+ <Compile Include="Tools\VOID_Tools.cs" />
+ <Compile Include="Tools\VOID_DataValue.cs" />
+ <Compile Include="Tools\VOID_SaveValue.cs" />
+ <Compile Include="API\VOID_HUDModule.cs" />
+ <Compile Include="API\VOID_SingletonModule.cs" />
+ <Compile Include="API\Attributes\VOID_ScenesAttribute.cs" />
+ <Compile Include="API\Attributes\AVOID_SaveValue.cs" />
+ <Compile Include="API\VOIDMaster.cs" />
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
@@ -142,5 +145,10 @@
<ItemGroup>
<None Include="GameData\VOID\Textures\ATM_VOID.cfg" />
</ItemGroup>
+ <ItemGroup>
+ <Folder Include="API\" />
+ <Folder Include="Tools\" />
+ <Folder Include="API\Attributes\" />
+ </ItemGroup>
</Project>
--- a/VOIDCore.cs
+++ /dev/null
@@ -1,75 +1,1 @@
-// VOID
-//
-// IVOID_Core.cs
-//
-// Copyright © 2015, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using KerbalEngineer.VesselSimulator;
-using KSP;
-using System;
-using System.Collections.Generic;
-using UnityEngine;
-
-namespace VOID
-{
- public abstract class VOIDCore : VOID_Module, IVOID_Module
- {
- public const double Constant_G = 6.674e-11;
-
- public abstract int windowID { get; }
- public abstract bool configDirty { get; set; }
- public abstract bool powerAvailable { get; protected set; }
-
- public abstract List<IVOID_Module> Modules { get; }
-
- public abstract float updateTimer { get; protected set; }
- public abstract double updatePeriod { get; }
-
- public abstract GUISkin Skin { get; }
-
- public abstract CelestialBody HomeBody { get; }
- public abstract List<CelestialBody> allBodies { get; }
- public abstract List<CelestialBody> sortedBodyList { get; protected set; }
-
- public abstract List<VesselType> allVesselTypes { get; }
-
- public abstract Stage LastStage { get; protected set; }
- public abstract Stage[] Stages { get; protected set; }
-
- public virtual event VOIDEventHandler onApplicationQuit;
-
- public virtual void OnApplicationQuit()
- {
- if (this.onApplicationQuit != null)
- {
- this.onApplicationQuit(this);
- }
- }
- }
-
- public delegate void VOIDEventHandler(object sender);
-}
-
-
--- a/VOIDCore_Editor.cs
+++ b/VOIDCore_Editor.cs
@@ -38,57 +38,9 @@
{
public class VOIDCore_Editor : VOIDCore_Generic<VOIDCore_Editor>
{
- protected override ApplicationLauncher.AppScenes appIconVisibleScenes
- {
- get
- {
- return ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH;
- }
- }
-
public VOIDCore_Editor() : base()
{
- this._Name = "VOID Editor Core";
- }
-
- public override void Update()
- {
- this.LoadBeforeUpdate();
-
- foreach (IVOID_Module module in this.Modules)
- {
- if (EditorLogic.RootPart == null)
- {
- module.StopGUI();
- continue;
- }
- if (HighLogic.LoadedSceneIsEditor && module.toggleActive && EditorLogic.SortedShipList.Any())
- {
- module.StartGUI();
- }
- if (!HighLogic.LoadedSceneIsEditor || !module.toggleActive || !EditorLogic.SortedShipList.Any())
- {
- module.StopGUI();
- }
- }
-
- if (EditorLogic.RootPart == null || !HighLogic.LoadedSceneIsEditor)
- {
- this.StopGUI();
- return;
- }
- else if (!this.guiRunning && HighLogic.LoadedSceneIsEditor)
- {
- this.StartGUI();
- }
-
- if (EditorLogic.SortedShipList.Count > 0 && this.vesselSimActive)
- {
- Tools.PostDebugMessage(this, "Updating SimManager.");
- this.UpdateSimManager();
- }
-
- this.CheckAndSave ();
+ this.Name = "VOID Core: Editor";
}
public override void FixedUpdate() {}
--- a/VOIDCore_Flight.cs
+++ b/VOIDCore_Flight.cs
@@ -25,11 +25,30 @@
// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+using KSP;
using System;
+using UnityEngine;
namespace VOID
{
- public class VOIDCore_Flight : VOIDCore_Generic<VOIDCore_Flight> {}
+ public class VOIDCore_Flight : VOIDCore_Generic<VOIDCore_Flight>
+ {
+ public VOIDCore_Flight()
+ {
+ base.Name = "VOID Core: Flight";
+ }
+
+ public override void DrawConfigurables()
+ {
+ if (HighLogic.LoadedSceneIsFlight)
+ {
+ this.consumeResource.value = GUILayout.Toggle(this.consumeResource, "Consume Resources");
+ }
+
+ base.DrawConfigurables();
+ }
+ }
}
--- a/VOIDCore_Generic.cs
+++ b/VOIDCore_Generic.cs
@@ -1,6 +1,6 @@
// VOID
//
-// VOID_Core.cs
+// VOIDCore_Generic.cs
//
// Copyright © 2014, toadicus
// All rights reserved.
@@ -46,10 +46,8 @@
protected string VoidName = "VOID";
protected string VoidVersion;
- protected bool _factoryReset = false;
-
[AVOID_SaveValue("configValue")]
- protected VOID_SaveValue<int> configVersion = 1;
+ protected VOID_SaveValue<int> _configVersion = VOIDCore.CONFIG_VERSION;
protected List<IVOID_Module> _modules = new List<IVOID_Module>();
protected bool _modulesLoaded = false;
@@ -104,7 +102,6 @@
// Vessel Type Housekeeping
protected List<VesselType> _allVesselTypes = new List<VesselType>();
protected bool vesselTypesLoaded = false;
- public float saveTimer = 0;
protected string defaultSkin = "KSP window 2";
@@ -130,26 +127,25 @@
public override bool configDirty { get; set; }
- [AVOID_SaveValue("UseBlizzyToolbar")]
- protected VOID_SaveValue<bool> _UseToolbarManager;
internal IButton ToolbarButton;
internal ApplicationLauncherButton AppLauncherButton;
- /*
- * Events
- * */
-
- // event VOIDEventHandler onApplicationQuit;
/*
* Properties
* */
+ public override int configVersion
+ {
+ get
+ {
+ return this._configVersion;
+ }
+ }
+
public bool factoryReset
{
- get
- {
- return this._factoryReset;
- }
+ get;
+ protected set;
}
public override List<IVOID_Module> Modules
@@ -235,6 +231,7 @@
protected set;
}
+
public override double updatePeriod
{
get
@@ -291,11 +288,11 @@
{
get
{
- return _UseToolbarManager & ToolbarManager.ToolbarAvailable;
+ return useToolbarManager & ToolbarManager.ToolbarAvailable;
}
set
{
- if (this._UseToolbarManager == value)
+ if (useToolbarManager == value)
{
return;
}
@@ -316,7 +313,7 @@
this.InitializeToolbarButton();
}
- _UseToolbarManager.value = value;
+ useToolbarManager = value;
}
}
@@ -438,15 +435,21 @@
}
}
- public virtual void OnGUI()
- {
- }
-
public virtual void Update()
{
this.LoadBeforeUpdate();
- if (this.vessel != null && this.vesselSimActive)
+ if (
+ this.vesselSimActive &&
+ (
+ this.vessel != null ||
+ (
+ HighLogic.LoadedSceneIsEditor &&
+ EditorLogic.RootPart != null &&
+ EditorLogic.SortedShipList.Count > 0
+ )
+ )
+ )
{
Tools.PostDebugMessage(this, "Updating SimManager.");
this.UpdateSimManager();
@@ -459,14 +462,52 @@
foreach (IVOID_Module module in this.Modules)
{
- if (!module.guiRunning && module.toggleActive)
+ Tools.PostDebugMessage(
+ this,
+ "\n\tmodule.Name={0}" +
+ "\n\tmodule.guiRunning={1}" +
+ "\n\tmodule.toggleActive={2}" +
+ "\n\tmodule.inValidScene={3}" +
+ "\n\tthis.togglePower={4}" +
+ "\n\tthis.factoryReset={5}" +
+ "\n\tHighLogic.LoadedSceneIsEditor={6}" +
+ "\n\t(EditorLogic.RootPart != null && EditorLogic.SortedShipList.Count > 0)={7}" +
+ "\n\t(EditorLogic.RootPart == null || EditorLogic.SortedShipList.Count == 0)={8}",
+ module.Name,
+ module.guiRunning,
+ module.toggleActive,
+ module.inValidScene,
+ this.togglePower,
+ this.factoryReset,
+ HighLogic.LoadedSceneIsEditor,
+ (EditorLogic.RootPart != null && EditorLogic.SortedShipList.Count > 0),
+ (EditorLogic.RootPart == null || EditorLogic.SortedShipList.Count == 0)
+ );
+ if (
+ !module.guiRunning &&
+ module.toggleActive &&
+ module.inValidScene &&
+ (
+ !HighLogic.LoadedSceneIsEditor ||
+ (EditorLogic.RootPart != null && EditorLogic.SortedShipList.Count > 0)
+ )
+ )
{
module.StartGUI();
}
- if (module.guiRunning && !module.toggleActive ||
- !this.togglePower ||
- !module.inValidScene ||
- this.factoryReset)
+ if (
+ module.guiRunning &&
+ (
+ !module.toggleActive ||
+ !this.togglePower ||
+ !module.inValidScene ||
+ this.factoryReset ||
+ (
+ HighLogic.LoadedSceneIsEditor &&
+ (EditorLogic.RootPart == null || EditorLogic.SortedShipList.Count == 0)
+ )
+ )
+ )
{
module.StopGUI();
}
@@ -528,6 +569,8 @@
((IVOID_BehaviorModule)module).OnDestroy();
}
}
+
+ this.Dispose();
}
public void ResetGUI()
@@ -547,7 +590,7 @@
{
GUILayout.BeginVertical();
- if (this.powerAvailable || HighLogic.LoadedSceneIsEditor)
+ if (this.powerAvailable || !HighLogic.LoadedSceneIsFlight)
{
if (!HighLogic.LoadedSceneIsEditor)
{
@@ -561,7 +604,7 @@
}
}
- if (togglePower || HighLogic.LoadedSceneIsEditor)
+ if (togglePower || !HighLogic.LoadedSceneIsFlight)
{
foreach (IVOID_Module module in this.Modules)
{
@@ -593,11 +636,6 @@
public override void DrawConfigurables()
{
GUIContent _content;
-
- if (HighLogic.LoadedSceneIsFlight)
- {
- this.consumeResource.value = GUILayout.Toggle(this.consumeResource, "Consume Resources");
- }
this.UseToolbarManager = GUILayout.Toggle(this.UseToolbarManager, "Use Blizzy's Toolbar If Available");
@@ -675,7 +713,7 @@
mod.DrawConfigurables();
}
- this._factoryReset = GUILayout.Toggle(this._factoryReset, "Factory Reset");
+ this.factoryReset = GUILayout.Toggle(this.factoryReset, "Factory Reset");
}
protected void UpdateSimManager()
@@ -944,7 +982,7 @@
this.ToolbarButton.Text = this.VoidName;
this.SetIconTexture(this.powerState | this.activeState);
- this.ToolbarButton.Visibility = new GameScenesVisibility(GameScenes.EDITOR, GameScenes.FLIGHT);
+ this.ToolbarButton.Visible = true;
this.ToolbarButton.OnClick +=
(e) =>
@@ -1018,7 +1056,7 @@
}
}
- protected void CheckAndSave()
+ protected virtual void CheckAndSave()
{
this.saveTimer += Time.deltaTime;
@@ -1050,9 +1088,15 @@
}
}
- public void SaveConfig()
- {
+ public override void SaveConfig()
+ {
+ if (this.configNeedsUpdate && this is VOIDCore_Flight)
+ {
+ KSP.IO.File.Delete<T>("config.xml");
+ }
+
var config = KSP.IO.PluginConfiguration.CreateForType<T>();
+
config.load();
this._SaveToConfig(config);
@@ -1069,7 +1113,7 @@
public VOIDCore_Generic()
{
- this._Name = "VOID Core";
+ this.Name = "VOID Core";
System.Version version = this.GetType().Assembly.GetName().Version;
@@ -1082,10 +1126,13 @@
this._skinName = this.defaultSkin;
this._skinIdx = int.MinValue;
- this.VOIDIconOnInactivePath = "VOID/Textures/void_icon_light_glow";
- this.VOIDIconOnActivePath = "VOID/Textures/void_icon_dark_glow";
- this.VOIDIconOffInactivePath = "VOID/Textures/void_icon_light";
- this.VOIDIconOffActivePath = "VOID/Textures/void_icon_dark";
+ this.VOIDIconOnActivePath = "VOID/Textures/void_icon_light_glow";
+ this.VOIDIconOnInactivePath = "VOID/Textures/void_icon_dark_glow";
+ this.VOIDIconOffActivePath = "VOID/Textures/void_icon_light";
+ this.VOIDIconOffInactivePath = "VOID/Textures/void_icon_dark";
+
+ this.saveTimer = 0f;
+ this.updateTimer = 0f;
this.vesselSimActive = true;
@@ -1093,7 +1140,11 @@
this.LoadConfig();
+ this._configVersion = VOIDCore.CONFIG_VERSION;
+
this.SetIconTexture(this.powerState | this.activeState);
+
+ this.factoryReset = false;
}
public virtual void Dispose()
--- a/VOIDCore_SpaceCentre.cs
+++ b/VOIDCore_SpaceCentre.cs
@@ -31,30 +31,12 @@
{
public class VOIDCore_SpaceCentre : VOIDCore_Generic<VOIDCore_SpaceCentre>
{
- #region Static Members
- protected new static bool _initialized = false;
- public new static bool Initialized
+ public VOIDCore_SpaceCentre() : base()
{
- get
- {
- return _initialized;
- }
+ base.Name = "VOID Core: SpaceCentre";
}
- protected new static VOIDCore_SpaceCentre _instance;
- public new static VOIDCore_SpaceCentre Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new VOIDCore_SpaceCentre();
- _initialized = true;
- }
- return _instance;
- }
- }
- #endregion
+ public override void FixedUpdate() {}
}
}
--- a/VOIDMaster.cs
+++ /dev/null
@@ -1,160 +1,1 @@
-// VOID
-//
-// VOIDMaster.cs
-//
-// Copyright © 2014, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-//
-///////////////////////////////////////////////////////////////////////////////
-//
-// Much, much credit to Younata, Adammada, Nivvydaskrl and to all the authors
-// behind MechJeb, RemoteTech Relay Network, ISA MapSat, and Protractor for some
-// invaluable functions and making your nicely written code available to learn from.
-//
-///////////////////////////////////////////////////////////////////////////////
-//
-// This software uses VesselSimulator and Engineer.Extensions from Engineer Redux.
-// Engineer Redux (c) 2013 cybutek
-// Used by permission.
-//
-///////////////////////////////////////////////////////////////////////////////
-using System;
-using UnityEngine;
-using KerbalEngineer.VesselSimulator;
-using ToadicusTools;
-
-namespace VOID
-{
- public abstract class VOIDMaster<T> : MonoBehaviour
- where T : VOIDCore_Generic<T>, new()
- {
- protected T Core;
-
- public abstract void Awake();
-
- public virtual void Update()
- {
- if (this.Core != null && !this.InValidScene())
- {
- this.LogDebug("We have a Core but the scene is not valid for this master. Saving and disposing.");
-
- this.Core.SaveConfig ();
- this.Core.Dispose();
- this.Core = null;
- return;
- }
-
- if (this.Core == null && this.InValidScene())
- {
- this.LogDebug("We have no Core and the scene is valid for this master; re-trying Awake.");
- this.Awake();
- return;
- }
-
- this.Core.Update ();
-
- if (this.Core.factoryReset)
- {
- this.LogDebug("Factory reset is true; deleting config and disposing!");
-
- KSP.IO.File.Delete<T>("config.xml");
- this.Core.Dispose();
- this.Core = null;
- }
- }
-
- public virtual void FixedUpdate()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.FixedUpdate ();
- }
-
- public virtual void OnGUI()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnGUI();
- }
-
- public virtual void OnDestroy()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnDestroy();
- }
-
- public virtual void OnApplicationQuit()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnApplicationQuit();
- }
-
- protected virtual bool InValidScene()
- {
- foreach (var attr in this.GetType().GetCustomAttributes(true))
- {
- if (attr is KSPAddon)
- {
- KSPAddon addonAttr = (KSPAddon)attr;
-
- switch (addonAttr.startup)
- {
- case KSPAddon.Startup.EveryScene:
- return true;
- case KSPAddon.Startup.EditorAny:
- return HighLogic.LoadedSceneIsEditor;
- case KSPAddon.Startup.Flight:
- return HighLogic.LoadedSceneIsFlight;
- case KSPAddon.Startup.MainMenu:
- return HighLogic.LoadedScene == GameScenes.MAINMENU;
- case KSPAddon.Startup.SpaceCentre:
- return HighLogic.LoadedScene == GameScenes.SPACECENTER;
- case KSPAddon.Startup.TrackingStation:
- return HighLogic.LoadedScene == GameScenes.TRACKSTATION;
- default:
- return false;
- }
- }
- }
-
- return false;
- }
- }
-}
-
--- a/VOID_CBInfoBrowser.cs
+++ b/VOID_CBInfoBrowser.cs
@@ -56,7 +56,7 @@
public VOID_CBInfoBrowser()
{
- this._Name = "Celestial Body Information Browser";
+ this.Name = "Celestial Body Information Browser";
this.WindowPos.x = 10;
this.WindowPos.y = 85;
--- a/VOID_CareerStatus.cs
+++ b/VOID_CareerStatus.cs
@@ -143,42 +143,58 @@
{
get
{
- return (
- this.currentFunds == double.NaN ||
- this.currentScience == float.NaN ||
- this.currentReputation == float.NaN
+ Tools.PostDebugMessage(
+ this,
+ "Checking init state:" +
+ "\n\tcurrentFunds={0}" +
+ "\n\tcurrentScience={1}" +
+ "\n\tcurrentReputation={2}",
+ this.currentFunds,
+ this.currentScience,
+ this.currentReputation
);
- }
+
+ return !(
+ double.IsNaN(this.currentFunds) ||
+ float.IsNaN(this.currentScience) ||
+ float.IsNaN(this.currentReputation)
+ );
+ }
+ }
+
+ public override void DrawGUI()
+ {
+ if (Event.current.type != EventType.Layout && !this.currenciesInitialized)
+ {
+ this.initCurrencies();
+ }
+
+ base.DrawGUI();
}
public override void ModuleWindow(int _)
{
- if (!this.currenciesInitialized)
- {
- this.initCurrencies();
- }
-
GUILayout.BeginVertical();
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(VOID_Data.fundingStatus.Label);
GUILayout.FlexibleSpace();
this.fundsContent.text = VOID_Data.fundingStatus.Value;
- GUILayout.Label(this.fundsContent, GUILayout.ExpandWidth(false));
+ GUILayout.Label(this.fundsContent, GUILayout.ExpandWidth(true));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(VOID_Data.reputationStatus.Label);
GUILayout.FlexibleSpace();
this.repContent.text = VOID_Data.reputationStatus.Value;
- GUILayout.Label(this.repContent, GUILayout.ExpandWidth(false));
+ GUILayout.Label(this.repContent, GUILayout.ExpandWidth(true));
GUILayout.EndHorizontal();
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
GUILayout.Label(VOID_Data.scienceStatus.Label);
GUILayout.FlexibleSpace();
this.scienceContent.text = VOID_Data.scienceStatus.Value;
- GUILayout.Label(this.scienceContent, GUILayout.ExpandWidth(false));
+ GUILayout.Label(this.scienceContent, GUILayout.ExpandWidth(true));
GUILayout.EndHorizontal();
GUILayout.EndVertical();
@@ -207,6 +223,17 @@
private void initCurrencies()
{
+ Tools.PostDebugMessage(
+ this,
+ "Initializing currencies." +
+ "\n\tFunding.Instance={0}" +
+ "ResearchAndDevelopment.Instance={1}" +
+ "Reputation.Instance={2}",
+ Funding.Instance == null ? "NULL" : Funding.Instance.ToString(),
+ ResearchAndDevelopment.Instance == null ? "NULL" : ResearchAndDevelopment.Instance.ToString(),
+ Reputation.Instance == null ? "NULL" : Reputation.Instance.ToString()
+ );
+
this.currentFunds = Funding.Instance != null ? Funding.Instance.Funds : double.NaN;
this.currentReputation = Reputation.Instance != null ? Reputation.Instance.reputation : float.NaN;
this.currentScience = ResearchAndDevelopment.Instance != null ?
@@ -224,7 +251,7 @@
{
VOID_CareerStatus.Instance = this;
- this._Name = "Career Status";
+ this.Name = "Career Status";
GameEvents.OnFundsChanged.Add(this.onFundsChange);
GameEvents.OnReputationChanged.Add(this.onRepChange);
@@ -249,7 +276,9 @@
this.scienceContent.image = this.scienceIcon;
}
- this.initCurrencies();
+ this.currentFunds = double.NaN;
+ this.currentScience = float.NaN;
+ this.currentReputation = float.NaN;
}
~VOID_CareerStatus()
--- a/VOID_DataLogger.cs
+++ b/VOID_DataLogger.cs
@@ -454,7 +454,7 @@
public VOID_DataLogger()
{
- this._Name = "CSV Data Logger";
+ this.Name = "CSV Data Logger";
this.loggingActive = false;
this.firstWrite = true;
--- a/VOID_DataValue.cs
+++ /dev/null
@@ -1,379 +1,1 @@
-// VOID
-//
-// VOID_DataValue.cs
-//
-// Copyright © 2014, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-using ToadicusTools;
-using UnityEngine;
-
-namespace VOID
-{
- public interface IVOID_DataValue
- {
- string Label { get; }
- string Units { get; }
- object Value { get; }
-
- void Refresh();
- string ValueUnitString();
- void DoGUIHorizontal();
- }
-
- public class VOID_DataValue<T> : IVOID_DataValue
- {
- /*
- * Static Members
- * */
- public static implicit operator T(VOID_DataValue<T> v)
- {
- return (T)v.Value;
- }
-
- /*
- * Instance Members
- * */
- /*
- * Fields
- * */
- protected T cache;
- protected Func<T> ValueFunc;
- protected float lastUpdate;
-
- /*
- * Properties
- * */
- public string Label { get; protected set; }
- public string Units { get; protected set; }
-
- object IVOID_DataValue.Value
- {
- get
- {
- return (object)this.Value;
- }
- }
-
- public T Value
- {
- get
- {
- if (
- HighLogic.LoadedSceneIsEditor ||
- (VOID_Data.Core.updateTimer - this.lastUpdate > VOID_Data.Core.updatePeriod) ||
- (this.lastUpdate > VOID_Data.Core.updateTimer)
- )
- {
- this.Refresh();
- }
- return (T)this.cache;
- }
- }
-
- /*
- * Methods
- * */
- public VOID_DataValue(string Label, Func<T> ValueFunc, string Units = "")
- {
- this.Label = Label;
- this.Units = Units;
- this.ValueFunc = ValueFunc;
- this.lastUpdate = 0;
-
- VOID_Data.DataValues[this.GetHashCode()] = this;
- }
-
- public void Refresh()
- {
- this.cache = this.ValueFunc.Invoke ();
- this.lastUpdate = VOID_Data.Core.updateTimer;
- }
-
- public T GetFreshValue()
- {
- this.Refresh ();
- return (T)this.cache;
- }
-
- public virtual string ValueUnitString() {
- return this.Value.ToString() + this.Units;
- }
-
- public virtual void DoGUIHorizontal()
- {
- GUILayout.BeginHorizontal (GUILayout.ExpandWidth (true));
- GUILayout.Label (this.Label + ":");
- GUILayout.FlexibleSpace ();
- GUILayout.Label (this.ValueUnitString(), GUILayout.ExpandWidth (false));
- GUILayout.EndHorizontal ();
- }
-
- public override int GetHashCode()
- {
- int hash;
- unchecked
- {
- hash = 79999;
-
- hash = hash * 104399 + this.Label.GetHashCode();
- hash = hash * 104399 + this.ValueFunc.GetHashCode();
- hash = hash * 104399 + this.Units.GetHashCode();
- }
-
- return hash;
- }
-
- public override string ToString()
- {
- return string.Format (
- "{0}: {1}{2}",
- this.Label,
- this.Value.ToString (),
- this.Units
- );
- }
- }
-
- public abstract class VOID_NumValue<T> : VOID_DataValue<T>
- where T : IFormattable, IConvertible, IComparable
- {
- public static implicit operator Double(VOID_NumValue<T> v)
- {
- return v.ToDouble();
- }
-
- public static implicit operator Int32(VOID_NumValue<T> v)
- {
- return v.ToInt32();
- }
-
-
- public static implicit operator Single(VOID_NumValue<T> v)
- {
- return v.ToSingle();
- }
-
- protected IFormatProvider formatProvider;
-
- public VOID_NumValue(string Label, Func<T> ValueFunc, string Units = "") : base(Label, ValueFunc, Units)
- {
- this.formatProvider = System.Globalization.CultureInfo.CurrentUICulture;
- }
-
- public virtual double ToDouble(IFormatProvider provider)
- {
- return this.Value.ToDouble(provider);
- }
-
- public virtual double ToDouble()
- {
- return this.ToDouble(this.formatProvider);
- }
-
- public virtual int ToInt32(IFormatProvider provider)
- {
- return this.Value.ToInt32(provider);
- }
-
- public virtual int ToInt32()
- {
- return this.ToInt32(this.formatProvider);
- }
-
- public virtual float ToSingle(IFormatProvider provider)
- {
- return this.Value.ToSingle(provider);
- }
-
- public virtual float ToSingle()
- {
- return this.ToSingle(this.formatProvider);
- }
-
- public virtual string ToString(string Format)
- {
- return string.Format (
- "{0}: {1}{2}",
- this.Label,
- this.Value.ToString(Format, this.formatProvider),
- this.Units
- );
- }
-
- public virtual string ToSIString(int digits = 3, int MinMagnitude = 0, int MaxMagnitude = int.MaxValue)
- {
- return string.Format (
- "{0}{1}",
- Tools.MuMech_ToSI (this, digits, MinMagnitude, MaxMagnitude),
- this.Units
- );
- }
-
- public virtual string ValueUnitString(string format)
- {
- return this.Value.ToString(format, this.formatProvider) + this.Units;
- }
-
- public virtual string ValueUnitString(int digits) {
- return Tools.MuMech_ToSI(this, digits) + this.Units;
- }
-
- public virtual string ValueUnitString(int digits, int MinMagnitude, int MaxMagnitude)
- {
- return Tools.MuMech_ToSI(this, digits, MinMagnitude, MaxMagnitude) + this.Units;
- }
-
- public virtual void DoGUIHorizontal(string format)
- {
- GUILayout.BeginHorizontal (GUILayout.ExpandWidth (true));
- GUILayout.Label (this.Label + ":");
- GUILayout.FlexibleSpace ();
- GUILayout.Label (this.ValueUnitString(format), GUILayout.ExpandWidth (false));
- GUILayout.EndHorizontal ();
- }
-
- public virtual int DoGUIHorizontal(int digits, bool precisionButton = true)
- {
- if (precisionButton)
- {
- return this.DoGUIHorizontalPrec(digits);
- }
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label(this.Label + ":", GUILayout.ExpandWidth(true));
- GUILayout.FlexibleSpace();
- GUILayout.Label(this.ValueUnitString(digits), GUILayout.ExpandWidth(false));
- GUILayout.EndHorizontal();
-
- return digits;
- }
-
- public virtual int DoGUIHorizontalPrec(int digits)
- {
- double magnitude;
- double magLimit;
-
- magnitude = Math.Log10(Math.Abs((double)this));
-
- magLimit = Math.Max(Math.Abs(magnitude), 3d) + 3d;
- magLimit = Math.Round(Math.Ceiling(magLimit / 3f)) * 3d;
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label(this.Label + "ⁱ:", GUILayout.ExpandWidth(true));
- GUILayout.FlexibleSpace();
-
- if (magnitude >= 0)
- {
- GUILayout.Label(this.ValueUnitString(3, int.MinValue, (int)magnitude - digits), GUILayout.ExpandWidth(false));
- }
- else
- {
- GUILayout.Label(this.ValueUnitString(3, (int)magnitude + digits, int.MaxValue), GUILayout.ExpandWidth(false));
- }
- GUILayout.EndHorizontal();
-
- if (Event.current.type == EventType.mouseUp)
- {
- Rect lastRect = GUILayoutUtility.GetLastRect();
- if (lastRect.Contains(Event.current.mousePosition))
- {
- Tools.PostDebugMessage(string.Format("{0}: Changing digits from {1} within magLimit {2}.",
- this.GetType().Name,
- digits,
- magLimit));
-
- if (Event.current.button == 0)
- {
- digits = (digits + 3) % (int)magLimit;
- }
- else if (Event.current.button == 1)
- {
- digits = (digits - 3) % (int)magLimit;
- }
-
- if (digits < 0)
- {
- digits += (int)magLimit;
- }
-
- Tools.PostDebugMessage(string.Format("{0}: Changed digits to {1}." +
- "\n\tNew minMagnitude: {2}, maxMagnitude: {3}" +
- "\n\tMagnitude: {4}",
- this.GetType().Name,
- digits,
- magnitude >= 0 ? int.MinValue : (int)magnitude - 4 + digits,
- magnitude >= 0 ? (int)magnitude - digits : int.MaxValue,
- magnitude
- ));
- }
- }
-
- return digits;
- }
- }
-
- public class VOID_DoubleValue : VOID_NumValue<double>
- {
- public VOID_DoubleValue(string Label, Func<double> ValueFunc, string Units) : base(Label, ValueFunc, Units) {}
- }
-
- public class VOID_FloatValue : VOID_NumValue<float>
- {
- public VOID_FloatValue(string Label, Func<float> ValueFunc, string Units) : base(Label, ValueFunc, Units) {}
- }
-
- public class VOID_IntValue : VOID_NumValue<int>
- {
- public VOID_IntValue(string Label, Func<int> ValueFunc, string Units) : base(Label, ValueFunc, Units) {}
- }
-
- public class VOID_StrValue : VOID_DataValue<string>
- {
- public VOID_StrValue(string Label, Func<string> ValueFunc) : base(Label, ValueFunc, "") {}
- }
-
- public class VOID_Vector3dValue : VOID_DataValue<Vector3d>
- {
- public VOID_Vector3dValue(string Label, Func<Vector3d> ValueFunc, string Units)
- : base(Label, ValueFunc, Units)
- {}
-
- public string ToString(string format)
- {
- return string.Format("{0}: {1}{2}",
- this.Label,
- this.Value.ToString(format),
- this.Units
- );
- }
-
- public string ValueUnitString(string format) {
- return this.Value.ToString(format) + this.Units;
- }
- }
-}
-
-
--- a/VOID_EditorHUD.cs
+++ b/VOID_EditorHUD.cs
@@ -98,7 +98,7 @@
* */
public VOID_EditorHUD() : base()
{
- this._Name = "Heads-Up Display";
+ this.Name = "Heads-Up Display";
this.toggleActive = true;
--- a/VOID_HUD.cs
+++ b/VOID_HUD.cs
@@ -53,7 +53,7 @@
* */
public VOID_HUD() : base()
{
- this._Name = "Heads-Up Display";
+ this.Name = "Heads-Up Display";
this.toggleActive = true;
--- a/VOID_HUDAdvanced.cs
+++ b/VOID_HUDAdvanced.cs
@@ -72,7 +72,7 @@
* */
public VOID_HUDAdvanced() : base()
{
- this._Name = "Advanced Heads-Up Display";
+ this.Name = "Advanced Heads-Up Display";
this.toggleActive = true;
--- a/VOID_HUDModule.cs
+++ /dev/null
@@ -1,219 +1,1 @@
-// VOID
-//
-// VOID_HUDModule.cs
-//
-// Copyright © 2014, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using KerbalEngineer.VesselSimulator;
-using KSP;
-using System;
-using System.Collections.Generic;
-using System.Text;
-using ToadicusTools;
-using UnityEngine;
-
-namespace VOID
-{
- public abstract class VOID_HUDModule : VOID_Module
- {
- [AVOID_SaveValue("colorIndex")]
- protected VOID_SaveValue<int> _colorIndex;
-
- protected List<Color> textColors;
-
- [AVOID_SaveValue("positionsLocked")]
- protected VOID_SaveValue<bool> positionsLocked;
-
- public virtual int ColorIndex
- {
- get
- {
- return this._colorIndex;
- }
- set
- {
- if (this._colorIndex >= this.textColors.Count - 1)
- {
- this._colorIndex = 0;
- return;
- }
-
- this._colorIndex = value;
- }
- }
-
- public virtual List<HUDWindow> Windows
- {
- get;
- protected set;
- }
-
- public VOID_HUDModule() : base()
- {
- this._colorIndex = 0;
-
- this.textColors = new List<Color>();
-
- this.textColors.Add(Color.green);
- this.textColors.Add(Color.black);
- this.textColors.Add(Color.white);
- this.textColors.Add(Color.red);
- this.textColors.Add(Color.blue);
- this.textColors.Add(Color.yellow);
- this.textColors.Add(Color.gray);
- this.textColors.Add(Color.cyan);
- this.textColors.Add(Color.magenta);
-
- this.positionsLocked = true;
-
- this.Windows = new List<HUDWindow>();
- }
-
- public override void DrawGUI()
- {
- VOID_Styles.labelHud.normal.textColor = textColors [ColorIndex];
-
- GUI.skin = this.core.Skin;
-
- if (HighLogic.LoadedSceneIsEditor ||
- (TimeWarp.WarpMode == TimeWarp.Modes.LOW) || (TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate)
- )
- {
- SimManager.RequestSimulation();
- }
-
- foreach (HUDWindow window in this.Windows)
- {
- window.WindowPos = GUILayout.Window(
- this.core.windowID,
- window.WindowPos,
- VOID_Tools.GetWindowHandler(window.WindowFunction),
- GUIContent.none,
- GUIStyle.none
- );
- }
- }
-
- public override void DrawConfigurables()
- {
- base.DrawConfigurables();
-
- if (GUILayout.Button (string.Intern("Change HUD color"), GUILayout.ExpandWidth (false)))
- {
- ++this.ColorIndex;
- }
-
- if (GUILayout.Button(string.Intern("Reset HUD Positions"), GUILayout.ExpandWidth(false)))
- {
- foreach (HUDWindow window in this.Windows)
- {
- window.WindowPos = new Rect(window.defaultWindowPos);
- }
- }
-
- this.positionsLocked = GUILayout.Toggle(this.positionsLocked,
- string.Intern("Lock HUD Positions"),
- GUILayout.ExpandWidth(false));
- }
-
- public override void LoadConfig()
- {
- base.LoadConfig();
-
- var config = KSP.IO.PluginConfiguration.CreateForType<VOID_HUDModule>();
- config.load();
-
- foreach (HUDWindow window in this.Windows)
- {
- string saveName = string.Format("{0}_{1}", this.GetType().Name, window.WindowName);
- Rect loadedPos = config.GetValue(saveName, window.defaultWindowPos);
-
- window.WindowPos = loadedPos;
- }
- }
-
- public override void _SaveToConfig(KSP.IO.PluginConfiguration config)
- {
- base._SaveToConfig(config);
-
- foreach (HUDWindow window in this.Windows)
- {
- string saveName = string.Format("{0}_{1}", this.GetType().Name, window.WindowName);
- config.SetValue(saveName, window.WindowPos);
- }
- }
- }
-
- public class HUDWindow
- {
- public readonly Rect defaultWindowPos;
-
- private Rect _windowPos;
-
- public Action<int> WindowFunction
- {
- get;
- private set;
- }
-
- public Rect WindowPos
- {
- get
- {
- return this._windowPos;
- }
- set
- {
- if (value != this._windowPos)
- {
- this._windowPos = value;
-
- if (VOID_Data.Core != null)
- {
- VOID_Data.Core.configDirty = true;
- }
- }
- }
- }
-
- public string WindowName
- {
- get;
- private set;
- }
-
- private HUDWindow() {}
-
- public HUDWindow(string name, Action<int> windowFunc, Rect defaultPos)
- {
- this.WindowName = name;
- this.WindowFunction = windowFunc;
- this.defaultWindowPos = defaultPos;
- this.WindowPos = new Rect(this.defaultWindowPos);
- }
- }
-}
-
-
--- a/VOID_Module.cs
+++ /dev/null
@@ -1,350 +1,1 @@
-// VOID
-//
-// VOID_Module.cs
-//
-// Copyright © 2014, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-using System.Collections.Generic;
-using System.Linq;
-using System.Reflection;
-using ToadicusTools;
-using UnityEngine;
-
-namespace VOID
-{
- public abstract class VOID_Module : IVOID_Module
- {
- /*
- * Fields
- * */
- [AVOID_SaveValue("Active")]
- protected VOID_SaveValue<bool> _Active = false;
- private GameScenes[] validScenes;
-
- protected string _Name;
-
- protected float lastUpdate = 0;
-
- /*
- * Properties
- * */
- protected virtual VOIDCore core
- {
- get
- {
- return VOID_Data.Core;
- }
- }
-
- public virtual bool toggleActive
- {
- get
- {
- return this._Active;
- }
- set
- {
- this._Active.value = value;
- }
- }
-
- public virtual bool guiRunning
- {
- get
- {
- if (RenderingManager.fetch == null)
- {
- return false;
- }
- else
- {
- return RenderingManager.fetch.postDrawQueue.Contains(this.DrawGUI);
- }
- }
- }
-
- public virtual bool inValidScene
- {
- get
- {
- if (this.validScenes == null)
- {
- Tools.PostDebugMessage(this, "validScenes is null when checking inValidScene; fetching attribute.");
- foreach (var attr in this.GetType().GetCustomAttributes(false))
- {
- if (attr is VOID_ScenesAttribute)
- {
- VOID_ScenesAttribute addonAttr = (VOID_ScenesAttribute)attr;
-
- this.validScenes = addonAttr.ValidScenes;
-
- Tools.PostDebugMessage("Found VOID_ScenesAttribute; validScenes set.");
-
- break;
- }
- }
-
- if (this.validScenes == null)
- {
- this.validScenes = new GameScenes[] { GameScenes.FLIGHT };
- Tools.PostDebugMessage("No VOID_ScenesAttribute found; validScenes defaulted to flight.");
- }
- }
-
- Tools.PostDebugMessage(
- this,
- "Checking if scene is valid: LoadedScene={0}, validScenes={1}, inValidScene={2}",
- Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene),
- string.Join(", ", this.validScenes.Select(s => Enum.GetName(typeof(GameScenes), s)).ToArray()),
- this.validScenes.Contains(HighLogic.LoadedScene)
- );
-
- return this.validScenes.Contains(HighLogic.LoadedScene);
- }
- }
-
- public virtual string Name
- {
- get
- {
- return this._Name;
- }
- }
-
- public virtual Vessel vessel
- {
- get
- {
- return FlightGlobals.ActiveVessel;
- }
- }
-
- /*
- * Methods
- * */
- public void StartGUI()
- {
- if (!this.toggleActive || this.guiRunning)
- {
- return;
- }
-
- Tools.PostDebugMessage (string.Format("Adding {0} to the draw queue.", this.GetType().Name));
- RenderingManager.AddToPostDrawQueue (3, this.DrawGUI);
- }
-
- public void StopGUI()
- {
- if (!this.guiRunning)
- {
- return;
- }
- Tools.PostDebugMessage (string.Format("Removing {0} from the draw queue.", this.GetType().Name));
- RenderingManager.RemoveFromPostDrawQueue (3, this.DrawGUI);
- }
-
- public abstract void DrawGUI();
-
- public virtual void DrawConfigurables() {}
-
- public virtual void LoadConfig()
- {
- var config = KSP.IO.PluginConfiguration.CreateForType<VOID_Module> ();
- config.load ();
-
- foreach (var field in this.GetType().GetFields(
- BindingFlags.NonPublic |
- BindingFlags.Public |
- BindingFlags.Instance |
- BindingFlags.FlattenHierarchy
- ))
- {
- object[] attrs = field.GetCustomAttributes(typeof(AVOID_SaveValue), false);
-
- if (attrs.Length == 0) {
- continue;
- }
-
- AVOID_SaveValue attr = attrs.FirstOrDefault () as AVOID_SaveValue;
-
- string fieldName = string.Format("{0}_{1}", this.GetType().Name, attr.Name);
-
- Tools.PostDebugMessage(string.Format("{0}: Loading field {1}.", this.GetType().Name, fieldName));
-
- object fieldValue = field.GetValue(this);
-
- bool convertBack = false;
- if (fieldValue is IVOID_SaveValue)
- {
- fieldValue = (fieldValue as IVOID_SaveValue).AsType;
- convertBack = true;
- }
-
- fieldValue = config.GetValue(fieldName, fieldValue);
-
- if (convertBack)
- {
- Type type = typeof(VOID_SaveValue<>).MakeGenericType (fieldValue.GetType ());
- IVOID_SaveValue convertValue = Activator.CreateInstance (type) as IVOID_SaveValue;
- convertValue.SetValue (fieldValue);
- fieldValue = convertValue;
- }
-
- field.SetValue (this, fieldValue);
-
- Tools.PostDebugMessage(string.Format("{0}: Loaded field {1}.", this.GetType().Name, fieldName));
- }
- }
-
- public virtual void _SaveToConfig(KSP.IO.PluginConfiguration config)
- {
- foreach (var field in this.GetType().GetFields(
- BindingFlags.Instance |
- BindingFlags.NonPublic |
- BindingFlags.Public |
- BindingFlags.FlattenHierarchy
- ))
- {
- object[] attrs = field.GetCustomAttributes(typeof(AVOID_SaveValue), false);
-
- if (attrs.Length == 0) {
- continue;
- }
-
- AVOID_SaveValue attr = attrs.FirstOrDefault () as AVOID_SaveValue;
-
- string fieldName = string.Format("{0}_{1}", this.GetType().Name, attr.Name);
-
- object fieldValue = field.GetValue(this);
-
- if (fieldValue is IVOID_SaveValue)
- {
- fieldValue = (fieldValue as IVOID_SaveValue).AsType;
- }
-
- config.SetValue(fieldName, fieldValue);
-
- Tools.PostDebugMessage(string.Format("{0}: Saved field {1}.", this.GetType().Name, fieldName));
- }
- }
- }
-
- public abstract class VOID_WindowModule : VOID_Module
- {
- [AVOID_SaveValue("WindowPos")]
- protected Rect WindowPos;
- protected float defWidth;
- protected float defHeight;
-
- protected string inputLockName;
-
- public VOID_WindowModule() : base()
- {
- this.defWidth = 250f;
- this.defHeight = 50f;
-
- this.inputLockName = string.Concat(this.Name, "_edlock");
-
- this.WindowPos = new Rect(Screen.width / 2, Screen.height / 2, this.defWidth, this.defHeight);
- }
-
- public abstract void ModuleWindow(int _);
-
- public override void DrawGUI()
- {
- GUI.skin = this.core.Skin;
-
- Rect _Pos = this.WindowPos;
-
- _Pos = GUILayout.Window(
- this.core.windowID,
- _Pos,
- VOID_Tools.GetWindowHandler(this.ModuleWindow),
- this.Name,
- GUILayout.Width(this.defWidth),
- GUILayout.Height(this.defHeight)
- );
-
- bool cursorInWindow = _Pos.Contains(Mouse.screenPos);
-
- switch (HighLogic.LoadedScene)
- {
- case GameScenes.EDITOR:
- if (cursorInWindow)
- {
- InputLockManager.SetControlLock(
- ControlTypes.EDITOR_ICON_HOVER | ControlTypes.EDITOR_ICON_PICK |
- ControlTypes.EDITOR_PAD_PICK_COPY | ControlTypes.EDITOR_PAD_PICK_COPY,
- this.inputLockName
- );
- EditorLogic.fetch.Lock(false, false, false, this.inputLockName);
- }
- else
- {
- EditorLogic.fetch.Unlock(this.inputLockName);
- }
- break;
- case GameScenes.FLIGHT:
- if (cursorInWindow)
- {
- InputLockManager.SetControlLock(ControlTypes.CAMERACONTROLS, this.inputLockName);
- }
- else if (InputLockManager.GetControlLock(this.inputLockName) != ControlTypes.None)
- {
- InputLockManager.RemoveControlLock(this.inputLockName);
- }
- break;
- case GameScenes.SPACECENTER:
- if (cursorInWindow)
- {
- InputLockManager.SetControlLock(ControlTypes.KSC_FACILITIES, this.inputLockName);
- }
- else if (InputLockManager.GetControlLock(this.inputLockName) != ControlTypes.None)
- {
- InputLockManager.RemoveControlLock(this.inputLockName);
- }
- break;
- }
-
- if (HighLogic.LoadedSceneIsEditor)
- {
- _Pos = Tools.ClampRectToEditorPad(_Pos);
- }
- else
- {
- _Pos = Tools.ClampRectToScreen(_Pos);
- }
-
- if (_Pos != this.WindowPos)
- {
- this.WindowPos = _Pos;
- this.core.configDirty = true;
- }
- }
- }
-}
-
-
--- a/VOID_Orbital.cs
+++ b/VOID_Orbital.cs
@@ -44,7 +44,7 @@
public VOID_Orbital()
{
- this._Name = "Orbital Information";
+ this.Name = "Orbital Information";
this.WindowPos.x = Screen.width - 520f;
this.WindowPos.y = 250f;
--- a/VOID_Rendezvous.cs
+++ b/VOID_Rendezvous.cs
@@ -47,7 +47,7 @@
public VOID_Rendezvous()
{
- this._Name = "Rendezvous Information";
+ this.Name = "Rendezvous Information";
this.WindowPos.x = 845;
this.WindowPos.y = 85;
--- a/VOID_SaveValue.cs
+++ /dev/null
@@ -1,152 +1,1 @@
-// VOID
-//
-// VOID_SaveValue.cs
-//
-// Copyright © 2014, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using KSP;
-using System;
-using System.Collections.Generic;
-using ToadicusTools;
-using UnityEngine;
-
-namespace VOID
-{
- public struct VOID_SaveValue<T> : IVOID_SaveValue
- {
- private T _value;
- private Type _type;
-
- private VOIDCore Core
- {
- get
- {
- return VOID_Data.Core;
- }
- }
-
- public T value
- {
- get
- {
- return this._value;
- }
- set
- {
- if (this.Core != null && !System.Object.Equals(this._value, value))
- {
- Tools.PostDebugMessage (string.Format (
- "VOID: Dirtying config for type {0} in method {1}." +
- "\n\t Old Value: {2}, New Value: {3}" +
- "\n\t Object.Equals(New, Old): {4}",
- this._type,
- new System.Diagnostics.StackTrace().GetFrame(1).GetMethod(),
- this._value,
- value,
- System.Object.Equals(this._value, value)
- ));
- this.Core.configDirty = true;
- }
- this._value = value;
- }
- }
-
- public Type type
- {
- get
- {
- if (this._type == null && this._value != null)
- {
- this._type = this._value.GetType ();
- }
- return this._type;
- }
- set
- {
- this._type = value;
- }
- }
-
- public object AsType
- {
- get
- {
- return (T)this._value;
- }
- }
-
- public void SetValue(object v)
- {
- this.value = (T)v;
- }
-
- public static implicit operator T(VOID_SaveValue<T> v)
- {
- return (T)v.value;
- }
-
- public static implicit operator VOID_SaveValue<T>(T v)
- {
- VOID_SaveValue<T> r = new VOID_SaveValue<T>();
- r.type = v.GetType();
- r.value = v;
-
- return r;
- }
-
- public override string ToString()
- {
- return this.value.ToString();
- }
- }
-
- public interface IVOID_SaveValue
- {
- Type type { get; }
- object AsType { get; }
- void SetValue(object v);
- }
-
- [AttributeUsage(AttributeTargets.Field)]
- public class AVOID_SaveValue : Attribute
- {
- protected string _name;
-
- public string Name
- {
- get
- {
- return this._name;
- }
- }
-
- public AVOID_SaveValue(string fieldName)
- {
- this._name = fieldName;
- }
- }
-}
-
-
--- a/VOID_ScenesAttribute.cs
+++ /dev/null
@@ -1,48 +1,1 @@
-// VOID
-//
-// VOID_ScenesAttribute.cs
-//
-// Copyright © 2015, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-namespace VOID
-{
- [AttributeUsage(AttributeTargets.Class)]
- public class VOID_ScenesAttribute : Attribute
- {
- public GameScenes[] ValidScenes
- {
- get;
- private set;
- }
-
- public VOID_ScenesAttribute(params GameScenes[] validScenes)
- {
- this.ValidScenes = validScenes;
- }
- }
-}
-
-
--- a/VOID_SingletonModule.cs
+++ /dev/null
@@ -1,67 +1,1 @@
-// VOID
-//
-// VOID_SingletonModule.cs
-//
-// Copyright © 2015, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using System;
-namespace VOID
-{
- public abstract class VOID_SingletonModule<T> : VOIDCore, IVOID_Module
- where T : VOID_Module, new()
- {
- #region Singleton Members
- /*
- * Static Members
- * */
- protected static bool _initialized = false;
-
- public static bool Initialized
- {
- get
- {
- return _initialized;
- }
- }
-
- protected static T _instance;
-
- public static T Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new T();
- _initialized = true;
- }
- return _instance;
- }
- }
- #endregion
- }
-}
-
-
--- a/VOID_StageInfo.cs
+++ b/VOID_StageInfo.cs
@@ -39,7 +39,7 @@
public VOID_StageInfo() : base()
{
- this._Name = "Stage Information";
+ this.Name = "Stage Information";
this.defWidth = 200f;
this.bodyIdx = 4;
@@ -95,7 +95,7 @@
public override void ModuleWindow(int _)
{
if (
- HighLogic.LoadedSceneIsEditor ||
+ !HighLogic.LoadedSceneIsFlight ||
(TimeWarp.WarpMode == TimeWarp.Modes.LOW) ||
(TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate)
)
--- a/VOID_Styles.cs
+++ b/VOID_Styles.cs
@@ -121,6 +121,8 @@
static VOID_Styles()
{
+ OnSkinChanged();
+
Ready = false;
}
}
--- a/VOID_SurfAtmo.cs
+++ b/VOID_SurfAtmo.cs
@@ -41,7 +41,7 @@
public VOID_SurfAtmo()
{
- this._Name = "Surface & Atmospheric Information";
+ this.Name = "Surface & Atmospheric Information";
this.WindowPos.x = Screen.width - 260f;
this.WindowPos.y = 85;
--- a/VOID_TWR.cs
+++ b/VOID_TWR.cs
@@ -17,13 +17,13 @@
{
public VOID_TWR() : base()
{
- this._Name = "IP Thrust-to-Weight Ratios";
+ this.Name = "IP Thrust-to-Weight Ratios";
}
public override void ModuleWindow(int _)
{
if (
- HighLogic.LoadedSceneIsEditor ||
+ !HighLogic.LoadedSceneIsFlight ||
(TimeWarp.WarpMode == TimeWarp.Modes.LOW) ||
(TimeWarp.CurrentRate <= TimeWarp.MaxPhysicsRate)
)
--- a/VOID_Tools.cs
+++ /dev/null
@@ -1,1055 +1,1 @@
-// VOID
-//
-// VOID_Tools.cs
-//
-// Copyright © 2014, toadicus
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without modification,
-// are permitted provided that the following conditions are met:
-//
-// 1. Redistributions of source code must retain the above copyright notice,
-// this list of conditions and the following disclaimer.
-//
-// 2. Redistributions in binary form must reproduce the above copyright notice,
-// this list of conditions and the following disclaimer in the documentation and/or other
-// materials provided with the distribution.
-//
-// 3. Neither the name of the copyright holder nor the names of its contributors may be used
-// to endorse or promote products derived from this software without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
-// INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
-// DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
-// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
-// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-using KSP;
-using System;
-using System.Collections.Generic;
-using ToadicusTools;
-using UnityEngine;
-
-namespace VOID
-{
- public static partial class VOID_Tools
- {
- #region CelestialBody Utilities
- public static bool hasAncestor(this CelestialBody bodyA, CelestialBody bodyB)
- {
- if (bodyA == null || bodyB == null)
- {
- return false;
- }
-
- while (bodyA.orbitDriver != null)
- {
- if (bodyA.orbit.referenceBody == bodyB)
- {
- return true;
- }
-
- bodyA = bodyA.orbit.referenceBody;
- }
-
- return false;
- }
-
- public static bool NearestRelatedParents(ref CelestialBody bodyA, ref CelestialBody bodyB)
- {
- if (bodyA == null || bodyB == null || bodyA.orbitDriver == null || bodyB.orbitDriver == null)
- {
- throw new ArgumentException(string.Concat(
- "CelestialBody::FindRelatedParents: ",
- "Neither body may be null, and both bodies must have orbits."
- ));
- }
-
- CelestialBody a, b;
-
- a = bodyA;
-
- while (bodyA.orbitDriver != null)
- {
- b = bodyB;
-
- while (b.orbitDriver != null)
- {
- if (a.orbit.referenceBody == b.orbit.referenceBody)
- {
- bodyA = a;
- bodyB = b;
- return true;
- }
-
- b = b.orbit.referenceBody;
- }
-
- a = a.orbit.referenceBody;
- }
-
- return false;
- }
- #endregion
-
- #region VESSEL_EXTENSIONS_SCIENCE
- public static CBAttributeMapSO.MapAttribute GetBiome(this Vessel vessel)
- {
- CBAttributeMapSO.MapAttribute mapAttribute;
-
- try
- {
- CBAttributeMapSO BiomeMap = vessel.mainBody.BiomeMap;
-
- double lat = vessel.latitude * Math.PI / 180d;
- double lon = vessel.longitude * Math.PI / 180d;
-
- mapAttribute = BiomeMap.GetAtt(lat, lon);
-
- /*
- lon -= Math.PI / 2d;
-
- if (lon < 0d)
- {
- lon += 2d * Math.PI;
- }
-
- float v = (float)(lat / Math.PI) + 0.5f;
- float u = (float)(lon / (2d * Math.PI));
-
- Color pixelBilinear = BiomeMap.Map.GetPixelBilinear(u, v);
- mapAttribute = BiomeMap.defaultAttribute;
-
- if (BiomeMap.Map != null)
- {
- if (BiomeMap.exactSearch)
- {
- for (int i = 0; i < BiomeMap.Attributes.Length; ++i)
- {
- if (pixelBilinear == BiomeMap.Attributes[i].mapColor)
- {
- mapAttribute = BiomeMap.Attributes[i];
- }
- }
- }
- else
- {
- float zero = 0;
- float num = 1 / zero;
- for (int j = 0; j < BiomeMap.Attributes.Length; ++j)
- {
- Color mapColor = BiomeMap.Attributes[j].mapColor;
- float sqrMagnitude = ((Vector4)(mapColor - pixelBilinear)).sqrMagnitude;
- if (sqrMagnitude < num)
- {
- bool testCase = true;
- if (BiomeMap.nonExactThreshold != -1)
- {
- testCase = (sqrMagnitude < BiomeMap.nonExactThreshold);
- }
- if (testCase)
- {
- mapAttribute = BiomeMap.Attributes[j];
- num = sqrMagnitude;
- }
- }
- }
- }
- }
- */
- }
- catch (NullReferenceException)
- {
- mapAttribute = new CBAttributeMapSO.MapAttribute();
- mapAttribute.name = "N/A";
- }
-
- return mapAttribute;
- }
-
- public static ExperimentSituations GetExperimentSituation(this Vessel vessel)
- {
- if (vessel == null)
- {
- return ExperimentSituations.SrfSplashed;
- }
-
- Vessel.Situations situation = vessel.situation;
-
- switch (situation)
- {
- case Vessel.Situations.PRELAUNCH:
- case Vessel.Situations.LANDED:
- return ExperimentSituations.SrfLanded;
- case Vessel.Situations.SPLASHED:
- return ExperimentSituations.SrfSplashed;
- case Vessel.Situations.FLYING:
- if (vessel.altitude < (double)vessel.mainBody.scienceValues.flyingAltitudeThreshold)
- {
- return ExperimentSituations.FlyingLow;
- }
- else
- {
- return ExperimentSituations.FlyingHigh;
- }
- }
-
- if (vessel.altitude < (double)vessel.mainBody.scienceValues.spaceAltitudeThreshold)
- {
- return ExperimentSituations.InSpaceLow;
- }
- else
- {
- return ExperimentSituations.InSpaceHigh;
- }
- }
-
- public static string HumanString(this ExperimentSituations situation)
- {
- switch (situation)
- {
- case ExperimentSituations.FlyingHigh:
- return "Upper Atmosphere";
- case ExperimentSituations.FlyingLow:
- return "Flying";
- case ExperimentSituations.SrfLanded:
- return "Surface";
- case ExperimentSituations.InSpaceLow:
- return "Near in Space";
- case ExperimentSituations.InSpaceHigh:
- return "High in Space";
- case ExperimentSituations.SrfSplashed:
- return "Splashed Down";
- default:
- return "Unknown";
- }
- }
- #endregion
-
- #region VESSEL_EXTENSIONS_LAT_LONG
- public static string GetLongitudeString(this Vessel vessel, string format = "F4")
- {
- string dir_long = "W";
- double v_long = vessel.longitude;
-
- v_long = FixDegreeDomain(v_long);
-
- if (v_long < -180d)
- {
- v_long += 360d;
- }
- if (v_long >= 180)
- {
- v_long -= 360d;
- }
-
- if (v_long > 0)
- dir_long = "E";
-
- return string.Format("{0}° {1}", Math.Abs(v_long).ToString(format), dir_long);
- }
-
- public static string GetLatitudeString(this Vessel vessel, string format = "F4")
- {
- string dir_lat = "S";
- double v_lat = vessel.latitude;
- if (v_lat > 0)
- dir_lat = "N";
-
- return string.Format("{0}° {1}", Math.Abs(v_lat).ToString(format), dir_lat);
- }
- #endregion
-
- #region VESSEL_EXTENSIONS_GENERAL
- public static double TrueAltitude(Vessel vessel)
- {
- double trueAltitude = vessel.orbit.altitude - vessel.terrainAltitude;
-
- // HACK: This assumes that on worlds with oceans, all water is fixed at 0 m,
- // and water covers the whole surface at 0 m.
- if (vessel.terrainAltitude < 0 && vessel.mainBody.ocean)
- {
- trueAltitude = vessel.orbit.altitude;
- }
-
- return trueAltitude;
- }
-
- public static double Radius(this Vessel vessel)
- {
- double radius;
-
- radius = vessel.altitude;
-
- if (vessel.mainBody != null)
- {
- radius += vessel.mainBody.Radius;
- }
-
- return radius;
- }
- #endregion
-
- #region GEOMETRY_UTILS
- public static double FixAngleDomain(double Angle, bool Degrees = false)
- {
- double Extent = 2d * Math.PI;
- if (Degrees)
- {
- Extent = 360d;
- }
-
- Angle = Angle % (Extent);
- if (Angle < 0d)
- {
- Angle += Extent;
- }
-
- return Angle;
- }
-
- public static double FixDegreeDomain(double Angle)
- {
- return FixAngleDomain(Angle, true);
- }
- #endregion
-
- private static Dictionary<int, GUI.WindowFunction> functionCache;
- public static UnityEngine.GUI.WindowFunction GetWindowHandler(Action<int> func)
- {
- if (functionCache == null)
- {
- functionCache = new Dictionary<int, GUI.WindowFunction>();
- }
-
- int hashCode = func.GetHashCode();
-
- if (!functionCache.ContainsKey(hashCode))
- {
- functionCache[hashCode] = delegate (int id)
- {
- try
- {
- func(id);
- }
- #if DEBUG
- catch (ArgumentException)
- #else
- catch (ArgumentException)
- #endif
- {
- Debug.LogWarning(
- string.Format("[{0}]: ArgumentException caught during window call. This is not a bug.",
- func.Target.GetType().Name
- ));
-
- /*#if DEBUG
- Debug.LogException(ex);
- #endif*/
- }
- catch (Exception ex)
- {
- Debug.LogError(
- string.Format("[{0}]: {1} caught during window call.\nMessage:\n{2}\nStackTrace:\n{3}",
- func.Target.GetType().Name,
- ex.GetType().Name,
- ex.Message,
- ex.StackTrace
- ));
- }
- };
- }
-
- return functionCache[hashCode];
- }
-
- /// <summary>
- /// Formats the interval given in seconds as a human-friendly
- /// time period in [[[[years, ]days, ]hours, ]minutes, and ]seconds.
- ///
- /// Uses sidereal days, since "6 hours per day" is the Kerbal standard.
- /// </summary>
- /// <returns>Human readable interval</returns>
- /// <param name="seconds"></param>
- public static string FormatInterval(double seconds)
- {
- return UnpackedTime.FromSeconds(seconds).FormatAsSpan();
- }
-
- /// <summary>
- /// Formats the date given in seconds since epoch as a human-friendly
- /// date in the format YY, DD, HH:MM:SS
- /// </summary>
- /// <returns>The date.</returns>
- /// <param name="seconds">Seconds.</param>
- public static string FormatDate(double seconds)
- {
- return UnpackedTime.FromSeconds(seconds).FormatAsDate();
- }
-
- public class UnpackedTime
- {
- public const double SecondsPerMinute = 60d;
- public const double SecondsPerHour = 3600d;
-
- public static double SecondsPerDay
- {
- get
- {
- if (GameSettings.KERBIN_TIME)
- {
- return 21600d;
- }
- else
- {
- return 86164.1d;
- }
- }
- }
-
- public static double SecondsPerYear
- {
- get
- {
- if (GameSettings.KERBIN_TIME)
- {
- return 9203545d;
- }
- else
- {
- return 31558149d;
- }
- }
- }
-
- public static UnpackedTime FromSeconds(double seconds)
- {
- UnpackedTime time = new UnpackedTime();
-
- time.years = (int)(seconds / SecondsPerYear);
-
- seconds %= SecondsPerYear;
-
- time.days = (int)(seconds / SecondsPerDay);
-
- seconds %= SecondsPerDay;
-
- time.hours = (int)(seconds / SecondsPerHour);
-
- seconds %= SecondsPerHour;
-
- time.minutes = (int)(seconds / SecondsPerMinute);
-
- seconds %= SecondsPerMinute;
-
- time.seconds = seconds;
-
- return time;
- }
-
- public static explicit operator UnpackedTime(double seconds)
- {
- return FromSeconds(seconds);
- }
-
- public static implicit operator double(UnpackedTime time)
- {
- return time.ToSeconds();
- }
-
- public static UnpackedTime operator+ (UnpackedTime lhs, UnpackedTime rhs)
- {
- return FromSeconds(lhs.ToSeconds() + rhs.ToSeconds());
- }
-
- public static UnpackedTime operator- (UnpackedTime lhs, UnpackedTime rhs)
- {
- return FromSeconds(lhs.ToSeconds() - rhs.ToSeconds());
- }
-
- public int years;
- public int days;
- public int hours;
- public int minutes;
- public double seconds;
-
- public double ToSeconds()
- {
- return (double)years * SecondsPerYear +
- (double)days * SecondsPerDay +
- (double)hours * SecondsPerHour +
- (double)minutes * SecondsPerMinute +
- seconds;
- }
-
- public string FormatAsSpan()
- {
- string format_1 = "{0:D1}y {1:D1}d {2:D2}h {3:D2}m {4:00.0}s";
- string format_2 = "{0:D1}d {1:D2}h {2:D2}m {3:00.0}s";
- string format_3 = "{0:D2}h {1:D2}m {2:00.0}s";
- string format_4 = "{0:D2}m {1:00.0}s";
- string format_5 = "{0:00.0}s";
-
- if (this.years > 0)
- {
- return string.Format(format_1, this.years, this.days, this.hours, this.minutes, this.seconds);
- }
- else if (this.days > 0)
- {
- return string.Format(format_2, this.days, this.hours, this.minutes, this.seconds);
- }
- else if (this.hours > 0)
- {
- return string.Format(format_3, this.hours, this.minutes, this.seconds);
- }
- else if (this.minutes > 0)
- {
- return string.Format(format_4, this.minutes, this.seconds);
- }
- else
- {
- return string.Format(format_5, this.seconds);
- }
- }
-
- public string FormatAsDate()
- {
- string format = "Y{0:D1}, D{1:D1} {2:D2}:{3:D2}:{4:00.0}s";
-
- return string.Format(format, years, days, hours, minutes, seconds);
- }
-
- public UnpackedTime(int years, int days, int hours, int minutes, double seconds)
- {
- this.years = years;
- this.days = days;
- this.hours = hours;
- this.minutes = minutes;
- this.seconds = seconds;
- }
-
- public UnpackedTime() : this(0, 0, 0, 0, 0d) {}
- }
-
- public static string UppercaseFirst(string s)
- {
- if (string.IsNullOrEmpty(s))
- {
- return string.Empty;
- }
- char[] a = s.ToCharArray();
- a[0] = char.ToUpper(a[0]);
- return new string(a);
- }
-
- //transfer angles
- public static double Nivvy_CalcTransferPhaseAngle(double r_current, double r_target, double grav_param)
- {
- r_target /= 1000;
- r_current /= 1000;
- grav_param /= 1000000000;
-
- double midpoint = (r_target + r_current) / 2;
-
- double T_target = (2 * Math.PI) * Math.Sqrt((r_target * r_target * r_target) / grav_param);
- double T_transfer = (2 * Math.PI) * Math.Sqrt((midpoint * midpoint * midpoint) / grav_param);
- return 360 * (0.5 - (T_transfer / (2 * T_target)));
- }
-
- public static double Younata_DeltaVToGetToOtherBody(double mu, double r1, double r2)
- {
- /*
- def deltaVToGetToOtherBody(mu, r1, r2):
- # mu = gravity param of common orbiting body of r1 and r2
- # (e.g. for mun to minmus, mu is kerbin's gravity param
- # r1 = initial body's orbit radius
- # r2 = target body's orbit radius
-
- # return value is km/s
- sur1 = math.sqrt(mu / r1)
- sr1r2 = math.sqrt(float(2*r2)/float(r1+r2))
- mult = sr1r2 - 1
- return sur1 * mult
- */
- double sur1, sr1r2, mult;
- sur1 = Math.Sqrt(mu / r1);
- sr1r2 = Math.Sqrt((2 * r2) / (r1 + r2));
- mult = sr1r2 - 1;
- return sur1 * mult;
- }
-
- public static double Younata_DeltaVToExitSOI(double mu, double r1, double r2, double v)
- {
- /*
- def deltaVToExitSOI(mu, r1, r2, v):
- # mu = gravity param of current body
- # r1 = current orbit radius
- # r2 = SOI radius
- # v = SOI exit velocity
- foo = r2 * (v**2) - 2 * mu
- bar = r1 * foo + (2 * r2 * mu)
- r = r1*r2
- return math.sqrt(bar / r)
- */
- double foo = r2 * (v * v) - 2 * mu;
- double bar = r1 * foo + (2 * r2 * mu);
- double r = r1 * r2;
- return Math.Sqrt(bar / r);
- }
-
- public static double Younata_TransferBurnPoint(double r, double v, double angle, double mu)
- {
- /*
- def transferBurnPoint(r, v, angle, mu):
- # r = parking orbit radius
- # v = ejection velocity
- # angle = phase angle (from function phaseAngle())
- # mu = gravity param of current body.
- epsilon = ((v**2)/2) - (mu / r)
- h = r * v * math.sin(angle)
- e = math.sqrt(1 + ((2 * epsilon * h**2)/(mu**2)))
- theta = math.acos(1.0 / e)
- degrees = theta * (180.0 / math.pi)
- return 180 - degrees
- */
- double epsilon, h, ee, theta, degrees;
- epsilon = ((v * v) / 2) - (mu / r);
- h = r * v * Math.Sin(angle);
- ee = Math.Sqrt(1 + ((2 * epsilon * (h * h)) / (mu * mu)));
- theta = Math.Acos(1.0 / ee);
- degrees = theta * (180.0 / Math.PI);
- return 180 - degrees;
- // returns the ejection angle
- }
-
- public static double Adammada_CurrrentPhaseAngle(
- double body_LAN,
- double body_orbitPct,
- double origin_LAN,
- double origin_orbitPct
- )
- {
- double angle = (body_LAN / 360 + body_orbitPct) - (origin_LAN / 360 + origin_orbitPct);
- if (angle > 1)
- angle = angle - 1;
- if (angle < 0)
- angle = angle + 1;
- if (angle > 0.5)
- angle = angle - 1;
- angle = angle * 360;
- return angle;
- }
-
- public static double Adammada_CurrentEjectionAngle(
- double vessel_long,
- double origin_rotAngle,
- double origin_LAN,
- double origin_orbitPct
- )
- {
- //double eangle = ((FlightGlobals.ActiveVOID.vessel.longitude + orbiting.rotationAngle) - (orbiting.orbit.LAN / 360 + orbiting.orbit.orbitPercent) * 360);
- double eangle = ((vessel_long + origin_rotAngle) - (origin_LAN / 360 + origin_orbitPct) * 360);
-
- while (eangle < 0)
- eangle = eangle + 360;
- while (eangle > 360)
- eangle = eangle - 360;
- if (eangle < 270)
- eangle = 90 - eangle;
- else
- eangle = 450 - eangle;
- return eangle;
- }
-
- public static double mrenigma03_calcphase(Vessel vessel, CelestialBody target) //calculates phase angle between the current body and target body
- {
- Vector3d vecthis = new Vector3d();
- Vector3d vectarget = new Vector3d();
- vectarget = target.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
-
- if ((vessel.mainBody.name == "Sun") || (vessel.mainBody.referenceBody.referenceBody.name == "Sun"))
- {
- vecthis = vessel.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
- }
- else
- {
- vecthis = vessel.mainBody.orbit.getRelativePositionAtUT(Planetarium.GetUniversalTime());
- }
-
- vecthis = Vector3d.Project(new Vector3d(vecthis.x, 0, vecthis.z), vecthis);
- vectarget = Vector3d.Project(new Vector3d(vectarget.x, 0, vectarget.z), vectarget);
-
- Vector3d prograde = new Vector3d();
- prograde = Quaternion.AngleAxis(90, Vector3d.forward) * vecthis;
-
- double phase = Vector3d.Angle(vecthis, vectarget);
-
- if (Vector3d.Angle(prograde, vectarget) > 90)
- phase = 360 - phase;
-
- return (phase + 360) % 360;
- }
-
- public static double adjustCurrPhaseAngle(double transfer_angle, double curr_phase)
- {
- if (transfer_angle < 0)
- {
- if (curr_phase > 0)
- return (-1 * (360 - curr_phase));
- else if (curr_phase < 0)
- return curr_phase;
- }
- else if (transfer_angle > 0)
- {
- if (curr_phase > 0)
- return curr_phase;
- else if (curr_phase < 0)
- return (360 + curr_phase);
- }
- return curr_phase;
- }
-
- public static double adjust_current_ejection_angle(double curr_ejection)
- {
- //curr_ejection WILL need to be adjusted once for all transfers as it returns values ranging -180 to 180
- // need 0-360 instead
- //
- // ie i have -17 in the screenshot
- // need it to show 343
- //
- // do this
- //
- // if < 0, add curr to 360 // 360 + (-17) = 343
- // else its good as it is
-
- if (curr_ejection < 0)
- return 360 + curr_ejection;
- else
- return curr_ejection;
-
- }
-
- public static double adjust_transfer_ejection_angle(double trans_ejection, double trans_phase)
- {
- // if transfer_phase_angle < 0 its a lower transfer
- //180 + curr_ejection
- // else if transfer_phase_angle > 0 its good as it is
-
- if (trans_phase < 0)
- return 180 + trans_ejection;
- else
- return trans_ejection;
-
- }
-
- public static void display_transfer_angles_SUN2PLANET(CelestialBody body, Vessel vessel)
- {
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Phase angle (curr/trans):");
- GUILayout.Label(
- VOID_Tools.mrenigma03_calcphase(vessel, body).ToString("F3") + "° / " + VOID_Tools.Nivvy_CalcTransferPhaseAngle(
- vessel.orbit.semiMajorAxis,
- body.orbit.semiMajorAxis,
- vessel.mainBody.gravParameter
- ).ToString("F3") + "°",
- GUILayout.ExpandWidth(false)
- );
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Transfer velocity:");
- GUILayout.Label(
- (VOID_Tools.Younata_DeltaVToGetToOtherBody(
- (vessel.mainBody.gravParameter / 1000000000),
- (vessel.orbit.semiMajorAxis / 1000),
- (body.orbit.semiMajorAxis / 1000)
- ) * 1000).ToString("F2") + "m/s",
- GUILayout.ExpandWidth(false)
- );
- GUILayout.EndHorizontal();
- }
-
- public static void display_transfer_angles_PLANET2PLANET(CelestialBody body, Vessel vessel)
- {
- double dv1 = VOID_Tools.Younata_DeltaVToGetToOtherBody(
- (vessel.mainBody.referenceBody.gravParameter / 1000000000),
- (vessel.mainBody.orbit.semiMajorAxis / 1000),
- (body.orbit.semiMajorAxis / 1000)
- );
- double dv2 = VOID_Tools.Younata_DeltaVToExitSOI(
- (vessel.mainBody.gravParameter / 1000000000),
- (vessel.orbit.semiMajorAxis / 1000),
- (vessel.mainBody.sphereOfInfluence / 1000),
- Math.Abs(dv1)
- );
-
- double trans_ejection_angle = VOID_Tools.Younata_TransferBurnPoint(
- (vessel.orbit.semiMajorAxis / 1000),
- dv2,
- (Math.PI / 2.0),
- (vessel.mainBody.gravParameter / 1000000000)
- );
- double curr_ejection_angle = VOID_Tools.Adammada_CurrentEjectionAngle(
- FlightGlobals.ActiveVessel.longitude,
- FlightGlobals.ActiveVessel.orbit.referenceBody.rotationAngle,
- FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.LAN,
- FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.orbitPercent
- );
-
- double trans_phase_angle = VOID_Tools.Nivvy_CalcTransferPhaseAngle(
- vessel.mainBody.orbit.semiMajorAxis,
- body.orbit.semiMajorAxis,
- vessel.mainBody.referenceBody.gravParameter
- ) % 360;
- double curr_phase_angle = VOID_Tools.Adammada_CurrrentPhaseAngle(
- body.orbit.LAN,
- body.orbit.orbitPercent,
- FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.LAN,
- FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.orbitPercent
- );
-
- double adj_phase_angle = VOID_Tools.adjustCurrPhaseAngle(trans_phase_angle, curr_phase_angle);
- double adj_trans_ejection_angle = VOID_Tools.adjust_transfer_ejection_angle(trans_ejection_angle, trans_phase_angle);
- double adj_curr_ejection_angle = VOID_Tools.adjust_current_ejection_angle(curr_ejection_angle);
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Phase angle (curr/trans):");
- GUILayout.Label(
- adj_phase_angle.ToString("F3") + "° / " + trans_phase_angle.ToString("F3") + "°",
- GUILayout.ExpandWidth(false)
- );
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Ejection angle (curr/trans):");
- GUILayout.Label(
- adj_curr_ejection_angle.ToString("F3") + "° / " + adj_trans_ejection_angle.ToString("F3") + "°",
- GUILayout.ExpandWidth(false)
- );
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Transfer velocity:");
- GUILayout.Label((dv2 * 1000).ToString("F2") + "m/s", GUILayout.ExpandWidth(false));
- GUILayout.EndHorizontal();
- }
-
- public static void display_transfer_angles_PLANET2MOON(CelestialBody body, Vessel vessel)
- {
- double dv1 = VOID_Tools.Younata_DeltaVToGetToOtherBody(
- (vessel.mainBody.gravParameter / 1000000000),
- (vessel.orbit.semiMajorAxis / 1000),
- (body.orbit.semiMajorAxis / 1000)
- );
-
- double trans_phase_angle = VOID_Tools.Nivvy_CalcTransferPhaseAngle(
- vessel.orbit.semiMajorAxis,
- body.orbit.semiMajorAxis,
- vessel.mainBody.gravParameter
- );
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Phase angle (curr/trans):");
- GUILayout.Label(
- VOID_Tools.mrenigma03_calcphase(vessel, body).ToString("F3") + "° / " + trans_phase_angle.ToString("F3") + "°",
- GUILayout.ExpandWidth(false)
- );
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Transfer velocity:");
- GUILayout.Label((dv1 * 1000).ToString("F2") + "m/s", GUILayout.ExpandWidth(false));
- GUILayout.EndHorizontal();
- }
-
- public static void display_transfer_angles_MOON2MOON(CelestialBody body, Vessel vessel)
- {
- double dv1 = VOID_Tools.Younata_DeltaVToGetToOtherBody(
- (vessel.mainBody.referenceBody.gravParameter / 1000000000),
- (vessel.mainBody.orbit.semiMajorAxis / 1000),
- (body.orbit.semiMajorAxis / 1000)
- );
- double dv2 = VOID_Tools.Younata_DeltaVToExitSOI(
- (vessel.mainBody.gravParameter / 1000000000),
- (vessel.orbit.semiMajorAxis / 1000),
- (vessel.mainBody.sphereOfInfluence / 1000),
- Math.Abs(dv1)
- );
- double trans_ejection_angle = VOID_Tools.Younata_TransferBurnPoint(
- (vessel.orbit.semiMajorAxis / 1000),
- dv2,
- (Math.PI / 2.0),
- (vessel.mainBody.gravParameter / 1000000000)
- );
-
- double curr_phase_angle = VOID_Tools.Adammada_CurrrentPhaseAngle(
- body.orbit.LAN,
- body.orbit.orbitPercent,
- FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.LAN,
- FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.orbitPercent
- );
- double curr_ejection_angle = VOID_Tools.Adammada_CurrentEjectionAngle(
- FlightGlobals.ActiveVessel.longitude,
- FlightGlobals.ActiveVessel.orbit.referenceBody.rotationAngle,
- FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.LAN,
- FlightGlobals.ActiveVessel.orbit.referenceBody.orbit.orbitPercent
- );
-
- double trans_phase_angle = VOID_Tools.Nivvy_CalcTransferPhaseAngle(
- vessel.mainBody.orbit.semiMajorAxis,
- body.orbit.semiMajorAxis,
- vessel.mainBody.referenceBody.gravParameter
- ) % 360;
-
- double adj_phase_angle = VOID_Tools.adjustCurrPhaseAngle(trans_phase_angle, curr_phase_angle);
- //double adj_ejection_angle = adjustCurrEjectionAngle(trans_phase_angle, curr_ejection_angle);
-
- //new stuff
- //
- double adj_trans_ejection_angle = VOID_Tools.adjust_transfer_ejection_angle(trans_ejection_angle, trans_phase_angle);
- double adj_curr_ejection_angle = VOID_Tools.adjust_current_ejection_angle(curr_ejection_angle);
- //
- //
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Phase angle (curr/trans):");
- GUILayout.Label(
- adj_phase_angle.ToString("F3") + "° / " + trans_phase_angle.ToString("F3") + "°",
- GUILayout.ExpandWidth(false)
- );
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Ejection angle (curr/trans):");
- GUILayout.Label(
- adj_curr_ejection_angle.ToString("F3") + "° / " + adj_trans_ejection_angle.ToString("F3") + "°",
- GUILayout.ExpandWidth(false)
- );
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
- GUILayout.Label("Transfer velocity:");
- GUILayout.Label((dv2 * 1000).ToString("F2") + "m/s", GUILayout.ExpandWidth(false));
- GUILayout.EndHorizontal();
- }
-
- public static string get_heading_text(double heading)
- {
- if (heading > 348.75 || heading <= 11.25)
- return "N";
- else if (heading > 11.25 && heading <= 33.75)
- return "NNE";
- else if (heading > 33.75 && heading <= 56.25)
- return "NE";
- else if (heading > 56.25 && heading <= 78.75)
- return "ENE";
- else if (heading > 78.75 && heading <= 101.25)
- return "E";
- else if (heading > 101.25 && heading <= 123.75)
- return "ESE";
- else if (heading > 123.75 && heading <= 146.25)
- return "SE";
- else if (heading > 146.25 && heading <= 168.75)
- return "SSE";
- else if (heading > 168.75 && heading <= 191.25)
- return "S";
- else if (heading > 191.25 && heading <= 213.75)
- return "SSW";
- else if (heading > 213.75 && heading <= 236.25)
- return "SW";
- else if (heading > 236.25 && heading <= 258.75)
- return "WSW";
- else if (heading > 258.75 && heading <= 281.25)
- return "W";
- else if (heading > 281.25 && heading <= 303.75)
- return "WNW";
- else if (heading > 303.75 && heading <= 326.25)
- return "NW";
- else if (heading > 326.25 && heading <= 348.75)
- return "NNW";
- else
- return "";
- }
- }
-
- public class CBListComparer : IComparer<CelestialBody>
- {
- public int Compare(CelestialBody bodyA, CelestialBody bodyB)
- {
- Tools.PostDebugMessage(this, "got bodyA: {0} & bodyB: {1}", bodyA, bodyB);
-
- if (bodyA == null && bodyB == null)
- {
- Tools.PostDebugMessage(this, "both bodies are null, returning 0");
- return 0;
- }
- if (bodyA == null)
- {
- Tools.PostDebugMessage(this, "bodyA is null, returning -1");
- return -1;
- }
- if (bodyB == null)
- {
- Tools.PostDebugMessage(this, "bodyB is null, returning 1");
- return 1;
- }
-
- Tools.PostDebugMessage(this, "bodies are not null, carrying on");
-
- if (object.ReferenceEquals(bodyA, bodyB))
- {
- Tools.PostDebugMessage(this, "bodies are equal, returning 0");
- return 0;
- }
-
- Tools.PostDebugMessage(this, "bodies are not equal, carrying on");
-
- if (bodyA.orbitDriver == null)
- {
- Tools.PostDebugMessage(this, "bodyA.orbit is null (bodyA is the sun, returning 1");
- return 1;
- }
- if (bodyB.orbitDriver == null)
- {
- Tools.PostDebugMessage(this, "bodyB.orbit is null (bodyB is the sun, returning -1");
- return -1;
- }
-
- Tools.PostDebugMessage(this, "orbits are not null, carrying on");
-
- if (bodyA.orbit.referenceBody == bodyB.orbit.referenceBody)
- {
- Tools.PostDebugMessage(this, "bodies share a parent, comparing SMAs");
- return -bodyA.orbit.semiMajorAxis.CompareTo(bodyB.orbit.semiMajorAxis);
- }
-
- Tools.PostDebugMessage(this, "orbits do not share a parent, carrying on");
-
- if (bodyA.hasAncestor(bodyB))
- {
- Tools.PostDebugMessage(this, "bodyA is a moon or sub-moon of bodyB, returning -1");
- return -1;
- }
- if (bodyB.hasAncestor(bodyA))
- {
- Tools.PostDebugMessage(this, "bodyA is a moon or sub-moon of bodyB, returning 1");
- return 1;
- }
-
- Tools.PostDebugMessage(this, "bodies do not have an obvious relationship, searching for one");
-
- if (VOID_Tools.NearestRelatedParents(ref bodyA, ref bodyB))
- {
- Tools.PostDebugMessage(this, "good relation {0} and {1}, comparing", bodyA.bodyName, bodyB.bodyName);
- return this.Compare(bodyA, bodyB);
- }
-
- Tools.PostDebugMessage(this, "bad relation {0} and {1}, giving up", bodyA.bodyName, bodyB.bodyName);
-
- return 0;
- }
- }
-}
-
--- a/VOID_Transfer.cs
+++ b/VOID_Transfer.cs
@@ -41,7 +41,7 @@
public VOID_Transfer() : base()
{
- this._Name = "Transfer Angle Information";
+ this.Name = "Transfer Angle Information";
this.WindowPos.x = 475;
this.WindowPos.y = 85;
--- a/VOID_VesselInfo.cs
+++ b/VOID_VesselInfo.cs
@@ -40,7 +40,7 @@
{
public VOID_VesselInfo() : base()
{
- this._Name = "Vessel Information";
+ this.Name = "Vessel Information";
this.WindowPos.x = Screen.width - 260;
this.WindowPos.y = 450;
--- a/VOID_VesselRegister.cs
+++ b/VOID_VesselRegister.cs
@@ -60,7 +60,7 @@
public VOID_VesselRegister() : base()
{
- this._Name = "Vessel Register";
+ this.Name = "Vessel Register";
this.WindowPos.x = 845;
this.WindowPos.y = 275;