Major changes to the way VOID_Core was implemented to allow a more-extensible core framework for use in multiple scenes.
--- a/.gitattributes
+++ b/.gitattributes
@@ -1,3 +1,13 @@
* text=auto
* eol=lf
+# These files are text and should be normalized (convert crlf => lf)
+*.cs text diff=csharp
+*.cfg text
+*.csproj text
+*.sln text
+
+# Images should be treated as binary
+# (binary is a macro for -text -diff)
+*.png binary
+
--- /dev/null
+++ b/GameData/VOID/Textures/ATM_VOID.cfg
@@ -1,1 +1,16 @@
+ACTIVE_TEXTURE_MANAGER_CONFIG
+{
+ folder = VOID
+ enabled = true
+ OVERRIDES
+ {
+ VOID/.*
+ {
+ compress = true
+ mipmaps = false
+ scale = 1
+ max_size = 0
+ }
+ }
+}
Binary files /dev/null and b/GameData/VOID/Textures/fundsgreen.png differ
Binary files /dev/null and b/GameData/VOID/Textures/fundsred.png differ
Binary files /dev/null and b/GameData/VOID/Textures/repgreen.png differ
Binary files /dev/null and b/GameData/VOID/Textures/repred.png differ
Binary files /dev/null and b/GameData/VOID/Textures/science.png differ
Binary files /dev/null and b/GameData/VOID/Textures/void_appIcon_dark.png differ
Binary files /dev/null and b/GameData/VOID/Textures/void_appIcon_dark_glow.png differ
Binary files /dev/null and b/GameData/VOID/Textures/void_appIcon_light.png differ
Binary files /dev/null and b/GameData/VOID/Textures/void_appIcon_light_glow.png differ
Binary files /dev/null and b/GameData/VOID/Textures/void_icon_dark.png differ
Binary files /dev/null and b/GameData/VOID/Textures/void_icon_dark_glow.png differ
Binary files /dev/null and b/GameData/VOID/Textures/void_icon_light.png differ
Binary files /dev/null and b/GameData/VOID/Textures/void_icon_light_glow.png differ
--- a/IVOID_Module.cs
+++ b/IVOID_Module.cs
@@ -35,6 +35,7 @@
string Name { get; }
bool toggleActive { get; set; }
bool guiRunning { get; }
+ bool inValidScene { get; }
void DrawGUI();
void StartGUI();
@@ -53,7 +54,5 @@
void FixedUpdate();
void OnDestroy();
}
-
- public interface IVOID_EditorModule : IVOID_Module {}
}
--- a/Properties/AssemblyInfo.cs
+++ b/Properties/AssemblyInfo.cs
@@ -39,7 +39,7 @@
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
// The form "{Major}.{Minor}.*" will automatically update the build and revision,
// and "{Major}.{Minor}.{Build}.*" will update just the revision.
-[assembly: AssemblyVersion("0.16.2.*")]
+[assembly: AssemblyVersion("0.16.4.*")]
// The following attributes are used to specify the signing key for the assembly,
// if desired. See the Mono documentation for more information about signing.
//[assembly: AssemblyDelaySign(false)]
--- a/VOID.csproj
+++ b/VOID.csproj
@@ -26,7 +26,7 @@
<ConsolePause>false</ConsolePause>
<CustomCommands>
<CustomCommands>
- <Command type="AfterBuild" command="xcopy /Y ${TargetFile} ..\..\..\Games\KSP_win\GameData\VOID\Plugins\" />
+ <Command type="AfterBuild" command="xcopy /Y ${TargetFile} ${ProjectDir}\GameData\VOID\Plugins\" />
</CustomCommands>
</CustomCommands>
</PropertyGroup>
@@ -39,7 +39,7 @@
<DefineConstants>TRACE</DefineConstants>
<CustomCommands>
<CustomCommands>
- <Command type="AfterBuild" command="xcopy /Y ${TargetFile} ..\..\..\Games\KSP_win\GameData\VOID\Plugins\" />
+ <Command type="AfterBuild" command="xcopy /Y ${TargetFile} ${ProjectDir}\GameData\VOID\Plugins\" />
</CustomCommands>
</CustomCommands>
</PropertyGroup>
@@ -54,7 +54,7 @@
<ConsolePause>false</ConsolePause>
<CustomCommands>
<CustomCommands>
- <Command type="AfterBuild" command="cp -afv ${TargetFile} /opt/games/KSP_linux/GameData/${ProjectName}/Plugins/" />
+ <Command type="AfterBuild" command="cp -afv ${TargetFile} ${ProjectDir}/GameData/${ProjectName}/Plugins/" />
</CustomCommands>
</CustomCommands>
</PropertyGroup>
@@ -67,15 +67,13 @@
<ConsolePause>false</ConsolePause>
<CustomCommands>
<CustomCommands>
- <Command type="AfterBuild" command="cp -afv ${TargetFile} /opt/games/KSP_linux/GameData/${ProjectName}/Plugins/" />
+ <Command type="AfterBuild" command="cp -afv ${TargetFile} ${ProjectDir}/GameData/${ProjectName}/Plugins/" />
</CustomCommands>
</CustomCommands>
</PropertyGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<ItemGroup>
<Compile Include="IVOID_Module.cs" />
- <Compile Include="VOIDFlightMaster.cs" />
- <Compile Include="VOID_Core.cs" />
<Compile Include="VOID_Module.cs" />
<Compile Include="VOID_HUD.cs" />
<Compile Include="VOID_SaveValue.cs" />
@@ -87,10 +85,8 @@
<Compile Include="VOID_Rendezvous.cs" />
<Compile Include="VOID_VesselRegister.cs" />
<Compile Include="VOID_DataLogger.cs" />
- <Compile Include="VOID_EditorCore.cs" />
<Compile Include="VOID_EditorHUD.cs" />
<Compile Include="VOID_DataValue.cs" />
- <Compile Include="VOIDEditorMaster.cs" />
<Compile Include="VOID_Tools.cs" />
<Compile Include="VOID_Localization.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@@ -101,6 +97,17 @@
<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" />
</ItemGroup>
<ProjectExtensions>
<MonoDevelop>
@@ -132,5 +139,8 @@
<Name>VesselSimulator</Name>
</ProjectReference>
</ItemGroup>
+ <ItemGroup>
+ <None Include="GameData\VOID\Textures\ATM_VOID.cfg" />
+ </ItemGroup>
</Project>
--- /dev/null
+++ b/VOIDCore.cs
@@ -1,1 +1,75 @@
+// 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);
+}
+
+
--- /dev/null
+++ b/VOIDCore_Editor.cs
@@ -1,1 +1,98 @@
+// VOID
+//
+// VOID_EditorCore.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.Linq;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ 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 ();
+ }
+
+ public override void FixedUpdate() {}
+ }
+}
+
+
--- /dev/null
+++ b/VOIDCore_Flight.cs
@@ -1,1 +1,35 @@
+// VOID
+//
+// VOIDCore_Flight.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 class VOIDCore_Flight : VOIDCore_Generic<VOIDCore_Flight> {}
+}
+
+
--- /dev/null
+++ b/VOIDCore_Generic.cs
@@ -1,1 +1,1128 @@
-
+// VOID
+//
+// VOID_Core.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.Linq;
+using System.Text;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ public abstract class VOIDCore_Generic<T> : VOID_SingletonModule<T>, IVOID_Module, IDisposable
+ where T : VOID_Module, new()
+ {
+ /*
+ * Fields
+ * */
+ protected string VoidName = "VOID";
+ protected string VoidVersion;
+
+ protected bool _factoryReset = false;
+
+ [AVOID_SaveValue("configValue")]
+ protected VOID_SaveValue<int> configVersion = 1;
+
+ protected List<IVOID_Module> _modules = new List<IVOID_Module>();
+ protected bool _modulesLoaded = false;
+
+ [AVOID_SaveValue("mainWindowPos")]
+ protected VOID_SaveValue<Rect> mainWindowPos = new Rect(475, 575, 10f, 10f);
+ [AVOID_SaveValue("mainGuiMinimized")]
+ protected VOID_SaveValue<bool> mainGuiMinimized = false;
+
+ [AVOID_SaveValue("configWindowPos")]
+ protected VOID_SaveValue<Rect> configWindowPos = new Rect(825, 625, 10f, 10f);
+ [AVOID_SaveValue("configWindowMinimized")]
+
+ protected VOID_SaveValue<bool> configWindowMinimized = true;
+
+ protected Texture2D VOIDIconTexture;
+ protected string VOIDIconOnActivePath;
+ protected string VOIDIconOnInactivePath;
+ protected string VOIDIconOffActivePath;
+ protected string VOIDIconOffInactivePath;
+
+ protected GUIStyle iconStyle;
+
+ protected int windowBaseID = -96518722;
+ protected int _windowID = 0;
+
+ protected bool GUIStylesLoaded = false;
+
+ protected CelestialBody _homeBody;
+
+ [AVOID_SaveValue("togglePower")]
+ public VOID_SaveValue<bool> togglePower = true;
+
+ public override bool powerAvailable { get; protected set; }
+
+ [AVOID_SaveValue("consumeResource")]
+ protected VOID_SaveValue<bool> consumeResource = false;
+
+ [AVOID_SaveValue("resourceName")]
+ protected VOID_SaveValue<string> resourceName = "ElectricCharge";
+
+ [AVOID_SaveValue("resourceRate")]
+ protected VOID_SaveValue<float> resourceRate = 0.2f;
+
+ [AVOID_SaveValue("updatePeriod")]
+ protected VOID_SaveValue<double> _updatePeriod = 1001f / 15000f;
+ protected string stringFrequency;
+
+ [AVOID_SaveValue("vesselSimActive")]
+ protected VOID_SaveValue<bool> vesselSimActive;
+
+ // Vessel Type Housekeeping
+ protected List<VesselType> _allVesselTypes = new List<VesselType>();
+ protected bool vesselTypesLoaded = false;
+ public float saveTimer = 0;
+
+ protected string defaultSkin = "KSP window 2";
+
+ [AVOID_SaveValue("defaultSkin")]
+ protected VOID_SaveValue<string> _skinName;
+ protected int _skinIdx;
+
+ protected Dictionary<string, GUISkin> validSkins;
+ protected string[] skinNames;
+ protected string[] forbiddenSkins =
+ {
+ "PlaqueDialogSkin",
+ "FlagBrowserSkin",
+ "SSUITextAreaDefault",
+ "ExperimentsDialogSkin",
+ "ExpRecoveryDialogSkin",
+ "KSP window 5",
+ "KSP window 6",
+ "PartTooltipSkin",
+ "KSCContextMenuSkin"
+ };
+ protected bool skinsLoaded = false;
+
+ 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 bool factoryReset
+ {
+ get
+ {
+ return this._factoryReset;
+ }
+ }
+
+ public override List<IVOID_Module> Modules
+ {
+ get
+ {
+ return this._modules;
+ }
+ }
+
+ public override GUISkin Skin
+ {
+ get
+ {
+ if (this.skinsLoaded)
+ {
+ try
+ {
+ return this.validSkins[this._skinName];
+ }
+ catch
+ {
+ }
+ }
+
+ return AssetBase.GetGUISkin(this.defaultSkin);
+ }
+ }
+
+ public override int windowID
+ {
+ get
+ {
+ if (this._windowID == 0)
+ {
+ this._windowID = this.windowBaseID;
+ }
+ return this._windowID++;
+ }
+ }
+
+ public override List<CelestialBody> allBodies
+ {
+ get
+ {
+ return FlightGlobals.Bodies;
+ }
+ }
+
+ public override List<CelestialBody> sortedBodyList
+ {
+ get;
+ protected set;
+ }
+
+ public override CelestialBody HomeBody
+ {
+ get
+ {
+ if (this._homeBody == null)
+ {
+ if (Planetarium.fetch != null)
+ {
+ this._homeBody = Planetarium.fetch.Home;
+ }
+ }
+
+ return this._homeBody;
+ }
+ }
+
+ public override List<VesselType> allVesselTypes
+ {
+ get
+ {
+ return this._allVesselTypes;
+ }
+ }
+
+ public override float updateTimer
+ {
+ get;
+ protected set;
+ }
+
+ public override double updatePeriod
+ {
+ get
+ {
+ return this._updatePeriod;
+ }
+ }
+
+ public override Stage[] Stages
+ {
+ get;
+ protected set;
+ }
+
+ public override Stage LastStage
+ {
+ get;
+ protected set;
+ }
+
+ protected IconState powerState
+ {
+ get
+ {
+ if (this.togglePower && this.powerAvailable)
+ {
+ return IconState.PowerOn;
+ }
+ else
+ {
+ return IconState.PowerOff;
+ }
+
+ }
+ }
+
+ protected IconState activeState
+ {
+ get
+ {
+ if (this.mainGuiMinimized)
+ {
+ return IconState.Inactive;
+ }
+ else
+ {
+ return IconState.Active;
+ }
+
+ }
+ }
+
+ protected bool UseToolbarManager
+ {
+ get
+ {
+ return _UseToolbarManager & ToolbarManager.ToolbarAvailable;
+ }
+ set
+ {
+ if (this._UseToolbarManager == value)
+ {
+ return;
+ }
+
+ if (value == false && this.ToolbarButton != null)
+ {
+ this.ToolbarButton.Destroy();
+ this.ToolbarButton = null;
+ }
+ if (value == true)
+ {
+ if (this.AppLauncherButton != null)
+ {
+ ApplicationLauncher.Instance.RemoveModApplication(this.AppLauncherButton);
+ this.AppLauncherButton = null;
+ }
+
+ this.InitializeToolbarButton();
+ }
+
+ _UseToolbarManager.value = value;
+ }
+ }
+
+ protected virtual ApplicationLauncher.AppScenes appIconVisibleScenes
+ {
+ get
+ {
+ return HighLogic.LoadedScene.ToAppScenes();
+ }
+ }
+
+ /*
+ * Methods
+ * */
+ public override void DrawGUI()
+ {
+ this._windowID = this.windowBaseID;
+
+ if (!this._modulesLoaded)
+ {
+ this.LoadModulesOfType<IVOID_Module>();
+ }
+
+ if (!this.skinsLoaded)
+ {
+ this.LoadSkins();
+ }
+
+ GUI.skin = this.Skin;
+
+ if (!this.GUIStylesLoaded)
+ {
+ this.LoadGUIStyles();
+
+ Tools.PostDebugMessage(
+ this,
+ "ToolbarAvailable: {0}, UseToobarManager: {1}",
+ ToolbarManager.ToolbarAvailable,
+ this.UseToolbarManager);
+ }
+
+ if (!this.UseToolbarManager)
+ {
+ if (this.AppLauncherButton == null)
+ {
+ Tools.PostDebugMessage(this,
+ "UseToolbarManager = false (ToolbarAvailable = {0}) and " +
+ "AppLauncherButton is null, making AppLauncher button.",
+ ToolbarManager.ToolbarAvailable
+ );
+ this.InitializeAppLauncherButton();
+ }
+ }
+ else if (this.ToolbarButton == null)
+ {
+ Tools.PostDebugMessage(this,
+ "UseToolbarManager = true (ToolbarAvailable = {0}) and " +
+ "ToolbarButton is null, making Toolbar button.",
+ ToolbarManager.ToolbarAvailable
+ );
+ this.InitializeToolbarButton();
+ }
+
+ if (!this.mainGuiMinimized)
+ {
+
+ Rect _mainWindowPos = this.mainWindowPos;
+
+ _mainWindowPos = GUILayout.Window(
+ this.windowID,
+ _mainWindowPos,
+ VOID_Tools.GetWindowHandler(this.VOIDMainWindow),
+ string.Join(" ", new string[] { this.VoidName, this.VoidVersion }),
+ GUILayout.Width(250),
+ GUILayout.Height(50)
+ );
+
+ if (HighLogic.LoadedSceneIsEditor)
+ {
+ _mainWindowPos = Tools.ClampRectToEditorPad(_mainWindowPos);
+ }
+ else
+ {
+ _mainWindowPos = Tools.ClampRectToScreen(_mainWindowPos);
+ }
+
+ if (_mainWindowPos != this.mainWindowPos)
+ {
+ this.mainWindowPos = _mainWindowPos;
+ }
+ }
+
+ if (!this.configWindowMinimized && !this.mainGuiMinimized)
+ {
+ Rect _configWindowPos = this.configWindowPos;
+
+ _configWindowPos = GUILayout.Window(
+ this.windowID,
+ _configWindowPos,
+ VOID_Tools.GetWindowHandler(this.VOIDConfigWindow),
+ string.Join(" ", new string[] { this.VoidName, "Configuration" }),
+ GUILayout.Width(250),
+ GUILayout.Height(50)
+ );
+
+ if (HighLogic.LoadedSceneIsEditor)
+ {
+ _configWindowPos = Tools.ClampRectToEditorPad(_configWindowPos);
+ }
+ else
+ {
+ _configWindowPos = Tools.ClampRectToScreen(_configWindowPos);
+ }
+
+ if (_configWindowPos != this.configWindowPos)
+ {
+ this.configWindowPos = _configWindowPos;
+ }
+ }
+ }
+
+ public virtual void OnGUI()
+ {
+ }
+
+ public virtual void Update()
+ {
+ this.LoadBeforeUpdate();
+
+ if (this.vessel != null && this.vesselSimActive)
+ {
+ Tools.PostDebugMessage(this, "Updating SimManager.");
+ this.UpdateSimManager();
+ }
+
+ if (!this.guiRunning)
+ {
+ this.StartGUI();
+ }
+
+ foreach (IVOID_Module module in this.Modules)
+ {
+ if (!module.guiRunning && module.toggleActive)
+ {
+ module.StartGUI();
+ }
+ if (module.guiRunning && !module.toggleActive ||
+ !this.togglePower ||
+ !module.inValidScene ||
+ this.factoryReset)
+ {
+ module.StopGUI();
+ }
+
+ if (module is IVOID_BehaviorModule)
+ {
+ ((IVOID_BehaviorModule)module).Update();
+ }
+ }
+
+ this.CheckAndSave();
+ this.updateTimer += Time.deltaTime;
+ }
+
+ public virtual void FixedUpdate()
+ {
+ bool newPowerState = this.powerAvailable;
+
+ if (this.togglePower && this.consumeResource &&
+ this.vessel.vesselType != VesselType.EVA &&
+ TimeWarp.deltaTime != 0)
+ {
+ float powerReceived = this.vessel.rootPart.RequestResource(
+ this.resourceName,
+ this.resourceRate * TimeWarp.fixedDeltaTime
+ );
+
+ if (powerReceived > 0)
+ {
+ newPowerState = true;
+ }
+ else
+ {
+ newPowerState = false;
+ }
+
+ if (this.powerAvailable != newPowerState)
+ {
+ this.powerAvailable = newPowerState;
+ this.SetIconTexture(this.powerState | this.activeState);
+ }
+ }
+
+ foreach (IVOID_Module module in this.Modules)
+ {
+ if (module is IVOID_BehaviorModule)
+ {
+ ((IVOID_BehaviorModule)module).FixedUpdate();
+ }
+ }
+ }
+
+ public void OnDestroy()
+ {
+ foreach (IVOID_Module module in this.Modules)
+ {
+ if (module is IVOID_BehaviorModule)
+ {
+ ((IVOID_BehaviorModule)module).OnDestroy();
+ }
+ }
+ }
+
+ public void ResetGUI()
+ {
+ this.StopGUI();
+
+ foreach (IVOID_Module module in this.Modules)
+ {
+ module.StopGUI();
+ module.StartGUI();
+ }
+
+ this.StartGUI();
+ }
+
+ public void VOIDMainWindow(int _)
+ {
+ GUILayout.BeginVertical();
+
+ if (this.powerAvailable || HighLogic.LoadedSceneIsEditor)
+ {
+ if (!HighLogic.LoadedSceneIsEditor)
+ {
+ string str = string.Intern("ON");
+ if (togglePower)
+ str = string.Intern("OFF");
+ if (GUILayout.Button("Power " + str))
+ {
+ togglePower.value = !togglePower;
+ this.SetIconTexture(this.powerState | this.activeState);
+ }
+ }
+
+ if (togglePower || HighLogic.LoadedSceneIsEditor)
+ {
+ foreach (IVOID_Module module in this.Modules)
+ {
+ module.toggleActive = GUILayout.Toggle(module.toggleActive, module.Name);
+ }
+ }
+ }
+ else
+ {
+ GUILayout.Label("-- POWER LOST --", VOID_Styles.labelRed);
+ }
+
+ this.configWindowMinimized.value = !GUILayout.Toggle(!this.configWindowMinimized, "Configuration");
+
+ GUILayout.EndVertical();
+ GUI.DragWindow();
+ }
+
+ public void VOIDConfigWindow(int _)
+ {
+ GUILayout.BeginVertical();
+
+ this.DrawConfigurables();
+
+ GUILayout.EndVertical();
+ GUI.DragWindow();
+ }
+
+ 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");
+
+ this.vesselSimActive.value = GUILayout.Toggle(this.vesselSimActive.value,
+ "Enable Engineering Calculations");
+
+ GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
+
+ GUILayout.Label("Skin:", GUILayout.ExpandWidth(false));
+
+ _content = new GUIContent();
+
+ _content.text = "◄";
+ _content.tooltip = "Select previous skin";
+ if (GUILayout.Button(_content, GUILayout.ExpandWidth(true)))
+ {
+ this._skinIdx--;
+ Tools.PostDebugMessage(string.Format(
+ "{0}: new this._skinIdx = {1} :: skin_list.Count = {2}",
+ this.GetType().Name,
+ this._skinName,
+ this.validSkins.Count
+ ));
+ }
+
+ _content.text = this.Skin.name;
+ _content.tooltip = "Current skin";
+ GUILayout.Label(_content, VOID_Styles.labelCenter, GUILayout.ExpandWidth(true));
+
+ _content.text = "►";
+ _content.tooltip = "Select next skin";
+ if (GUILayout.Button(_content, GUILayout.ExpandWidth(true)))
+ {
+ this._skinIdx++;
+ Tools.PostDebugMessage(string.Format(
+ "{0}: new this._skinIdx = {1} :: skin_list.Count = {2}",
+ this.GetType().Name,
+ this._skinName,
+ this.validSkins.Count
+ ));
+ }
+
+ this._skinIdx %= this.skinNames.Length;
+ if (this._skinIdx < 0)
+ {
+ this._skinIdx += this.skinNames.Length;
+ }
+
+ if (this._skinName != skinNames[this._skinIdx])
+ {
+ this._skinName.value = skinNames[this._skinIdx];
+ this.GUIStylesLoaded = false;
+ }
+
+ GUILayout.EndHorizontal();
+
+ GUILayout.BeginHorizontal();
+ GUILayout.Label("Update Rate (Hz):");
+ if (this.stringFrequency == null)
+ {
+ this.stringFrequency = (1f / this.updatePeriod).ToString();
+ }
+ this.stringFrequency = GUILayout.TextField(this.stringFrequency.ToString(), 5, GUILayout.ExpandWidth(true));
+
+ if (GUILayout.Button("Apply"))
+ {
+ double updateFreq = 1f / this.updatePeriod;
+ double.TryParse(stringFrequency, out updateFreq);
+ this._updatePeriod = 1 / updateFreq;
+ }
+ GUILayout.EndHorizontal();
+
+ foreach (IVOID_Module mod in this.Modules)
+ {
+ mod.DrawConfigurables();
+ }
+
+ this._factoryReset = GUILayout.Toggle(this._factoryReset, "Factory Reset");
+ }
+
+ protected void UpdateSimManager()
+ {
+ if (SimManager.ResultsReady())
+ {
+ Tools.PostDebugMessage(this, "VesselSimulator results ready, setting Stages.");
+
+ this.Stages = SimManager.Stages;
+
+ if (this.Stages != null)
+ {
+ this.LastStage = this.Stages.Last();
+ }
+
+ if (HighLogic.LoadedSceneIsEditor)
+ {
+ SimManager.Gravity = VOID_Data.KerbinGee;
+ }
+ else
+ {
+ double radius = this.vessel.Radius();
+ SimManager.Gravity = this.vessel.mainBody.gravParameter / (radius * radius);
+ }
+
+ SimManager.minSimTime = new TimeSpan(0, 0, 0, 0, (int)(this.updatePeriod * 1000d));
+
+ SimManager.TryStartSimulation();
+ }
+ #if DEBUG
+ else
+ {
+ Tools.PostDebugMessage(this, "VesselSimulator results not ready.");
+ }
+ #endif
+ }
+
+ protected void LoadModulesOfType<U>()
+ {
+ Tools.DebugLogger sb = Tools.DebugLogger.New(this);
+ sb.AppendLine("Loading modules...");
+
+ foreach (AssemblyLoader.LoadedAssembly assy in AssemblyLoader.loadedAssemblies)
+ {
+ foreach (Type loadedType in assy.assembly.GetExportedTypes())
+ {
+ if (
+ loadedType.IsInterface ||
+ loadedType.IsAbstract ||
+ !typeof(U).IsAssignableFrom(loadedType) ||
+ typeof(VOIDCore).IsAssignableFrom(loadedType)
+ )
+ {
+ continue;
+ }
+
+ sb.AppendFormat("Checking IVOID_Module type {0}...", loadedType.Name);
+
+ GameScenes[] validScenes = null;
+
+ foreach (var attr in loadedType.GetCustomAttributes(true))
+ {
+ if (attr is VOID_ScenesAttribute)
+ {
+ validScenes = ((VOID_ScenesAttribute)attr).ValidScenes;
+
+ sb.Append("VOID_ScenesAttribute found;");
+
+ break;
+ }
+ }
+
+ if (validScenes == null)
+ {
+ validScenes = new GameScenes[] { GameScenes.FLIGHT };
+
+
+ sb.Append("VOID_ScenesAttribute not found;");
+
+ }
+
+ sb.AppendFormat(
+ " validScenes set to {0}.",
+ string.Join(
+ ", ",
+ validScenes.Select(s => Enum.GetName(typeof(GameScenes), s)).ToArray()
+ )
+ );
+
+ if (!validScenes.Contains(HighLogic.LoadedScene))
+ {
+ sb.AppendFormat(" {0} not found in validScenes, skipping.",
+ Enum.GetName(typeof(GameScenes), HighLogic.LoadedScene));
+ continue;
+ }
+
+ sb.AppendFormat("Loading IVOID_Module type {0}...", loadedType.Name);
+
+ try
+ {
+ this.LoadModule(loadedType);
+ sb.AppendLine("Success.");
+ }
+ catch (Exception ex)
+ {
+ sb.AppendFormat("Failed, caught {0}\n", ex.GetType().Name);
+
+ #if DEBUG
+ Debug.LogException(ex);
+ #endif
+ }
+ }
+ }
+
+ this._modulesLoaded = true;
+
+ sb.AppendFormat("Loaded {0} modules.\n", this.Modules.Count);
+
+ sb.Print();
+ }
+
+ protected void LoadModule(Type T)
+ {
+ var existingModules = this._modules.Where(mod => mod.GetType().Name == T.Name);
+ if (existingModules.Any())
+ {
+ Tools.PostDebugMessage(string.Format(
+ "{0}: refusing to load {1}: already loaded",
+ this.GetType().Name,
+ T.Name
+ ));
+ return;
+ }
+
+ var InstanceProperty = T.GetProperty(
+ "Instance",
+ System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public
+ );
+
+ object modInstance = null;
+ IVOID_Module module;
+
+ if (InstanceProperty != null)
+ {
+ modInstance = InstanceProperty.GetValue(null, null);
+ }
+
+ if (modInstance != null)
+ {
+ module = modInstance as IVOID_Module;
+ }
+ else
+ {
+ module = Activator.CreateInstance(T) as IVOID_Module;
+ }
+
+ module.LoadConfig();
+ this._modules.Add(module);
+
+ Tools.PostDebugMessage(string.Format(
+ "{0}: loaded module {1}.",
+ this.GetType().Name,
+ T.Name
+ ));
+ }
+
+ protected void LoadSkins()
+ {
+ Tools.PostDebugMessage("AssetBase has skins: \n" +
+ string.Join("\n\t",
+ Resources.FindObjectsOfTypeAll(typeof(GUISkin))
+ .Select(s => s.ToString())
+ .ToArray()
+ )
+ );
+
+ this.validSkins = Resources.FindObjectsOfTypeAll(typeof(GUISkin))
+ .Where(s => !this.forbiddenSkins.Contains(s.name))
+ .Select(s => s as GUISkin)
+ .GroupBy(s => s.name)
+ .Select(g => g.First())
+ .ToDictionary(s => s.name);
+
+ Tools.PostDebugMessage(string.Format(
+ "{0}: loaded {1} GUISkins.",
+ this.GetType().Name,
+ this.validSkins.Count
+ ));
+
+ this.skinNames = this.validSkins.Keys.ToArray();
+ Array.Sort(this.skinNames);
+
+ int defaultIdx = int.MinValue;
+
+ for (int i = 0; i < this.skinNames.Length; i++)
+ {
+ if (this.skinNames[i] == this._skinName)
+ {
+ this._skinIdx = i;
+ }
+ if (this.skinNames[i] == this.defaultSkin)
+ {
+ defaultIdx = i;
+ }
+ if (this._skinIdx != int.MinValue && defaultIdx != int.MinValue)
+ {
+ break;
+ }
+ }
+
+ if (this._skinIdx == int.MinValue)
+ {
+ this._skinIdx = defaultIdx;
+ }
+
+ Tools.PostDebugMessage(string.Format(
+ "{0}: _skinIdx = {1}.",
+ this.GetType().Name,
+ this._skinName.ToString()
+ ));
+
+ this.skinsLoaded = true;
+ }
+
+ protected void LoadGUIStyles()
+ {
+ VOID_Styles.OnSkinChanged();
+
+ this.GUIStylesLoaded = true;
+ }
+
+ protected void LoadVesselTypes()
+ {
+ this._allVesselTypes = Enum.GetValues(typeof(VesselType)).OfType<VesselType>().ToList();
+ this.vesselTypesLoaded = true;
+ }
+
+ protected void LoadBeforeUpdate()
+ {
+ if (!this.vesselTypesLoaded)
+ {
+ this.LoadVesselTypes();
+ }
+
+ if (this.sortedBodyList == null && FlightGlobals.Bodies != null && FlightGlobals.Bodies.Count > 0)
+ {
+ this.sortedBodyList = new List<CelestialBody>(FlightGlobals.Bodies);
+ this.sortedBodyList.Sort(new CBListComparer());
+ this.sortedBodyList.Reverse();
+
+ Debug.Log(string.Format("sortedBodyList: {0}", string.Join("\n\t", this.sortedBodyList.Select(b => b.bodyName).ToArray())));
+ }
+
+ }
+
+ protected void InitializeToolbarButton()
+ {
+ // Do nothing if (the Toolbar is not available.
+ if (!ToolbarManager.ToolbarAvailable)
+ {
+ Tools.PostDebugMessage(this, "Refusing to make a ToolbarButton: ToolbarAvailable = false");
+ return;
+ }
+
+ this.ToolbarButton = ToolbarManager.Instance.add(this.VoidName, "coreToggle");
+ this.ToolbarButton.Text = this.VoidName;
+ this.SetIconTexture(this.powerState | this.activeState);
+
+ this.ToolbarButton.Visibility = new GameScenesVisibility(GameScenes.EDITOR, GameScenes.FLIGHT);
+
+ this.ToolbarButton.OnClick +=
+ (e) =>
+ {
+ this.ToggleMainWindow();
+ };
+
+ Tools.PostDebugMessage(string.Format("{0}: Toolbar Button initialized.", this.GetType().Name));
+ }
+
+ protected void InitializeAppLauncherButton()
+ {
+ if (ApplicationLauncher.Ready)
+ {
+ this.AppLauncherButton = ApplicationLauncher.Instance.AddModApplication(
+ this.ToggleMainWindow, this.ToggleMainWindow,
+ this.appIconVisibleScenes,
+ this.VOIDIconTexture
+ );
+
+ Tools.PostDebugMessage(
+ this,
+ "AppLauncherButton initialized in {0}",
+ Enum.GetName(
+ typeof(GameScenes),
+ HighLogic.LoadedScene
+ )
+ );
+ }
+ }
+
+ protected void ToggleMainWindow()
+ {
+ this.mainGuiMinimized = !this.mainGuiMinimized;
+ this.SetIconTexture(this.powerState | this.activeState);
+ }
+
+ protected void SetIconTexture(IconState state)
+ {
+ switch (state)
+ {
+ case (IconState.PowerOff | IconState.Inactive):
+ this.SetIconTexture(this.VOIDIconOffInactivePath);
+ break;
+ case (IconState.PowerOff | IconState.Active):
+ this.SetIconTexture(this.VOIDIconOffActivePath);
+ break;
+ case (IconState.PowerOn | IconState.Inactive):
+ this.SetIconTexture(this.VOIDIconOnInactivePath);
+ break;
+ case (IconState.PowerOn | IconState.Active):
+ this.SetIconTexture(this.VOIDIconOnActivePath);
+ break;
+ default:
+ throw new NotImplementedException();
+ }
+ }
+
+ protected void SetIconTexture(string texturePath)
+ {
+ if (this.ToolbarButton != null)
+ {
+ this.ToolbarButton.TexturePath = texturePath;
+ }
+
+ this.VOIDIconTexture = GameDatabase.Instance.GetTexture(texturePath.Replace("icon", "appIcon"), false);
+
+ if (this.AppLauncherButton != null)
+ {
+ this.AppLauncherButton.SetTexture(VOIDIconTexture);
+ }
+ }
+
+ protected void CheckAndSave()
+ {
+ this.saveTimer += Time.deltaTime;
+
+ if (this.saveTimer > 2f)
+ {
+ if (!this.configDirty)
+ {
+ return;
+ }
+
+ Tools.PostDebugMessage(string.Format(
+ "{0}: Time to save, checking if configDirty: {1}",
+ this.GetType().Name,
+ this.configDirty
+ ));
+
+ this.SaveConfig();
+ this.saveTimer = 0;
+ }
+ }
+
+ public override void LoadConfig()
+ {
+ base.LoadConfig();
+
+ foreach (IVOID_Module module in this.Modules)
+ {
+ module.LoadConfig();
+ }
+ }
+
+ public void SaveConfig()
+ {
+ var config = KSP.IO.PluginConfiguration.CreateForType<T>();
+ config.load();
+
+ this._SaveToConfig(config);
+
+ foreach (IVOID_Module module in this.Modules)
+ {
+ module._SaveToConfig(config);
+ }
+
+ config.save();
+
+ this.configDirty = false;
+ }
+
+ public VOIDCore_Generic()
+ {
+ this._Name = "VOID Core";
+
+ System.Version version = this.GetType().Assembly.GetName().Version;
+
+ this.VoidVersion = string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.MajorRevision);
+
+ this.powerAvailable = true;
+
+ this.toggleActive = true;
+
+ 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.vesselSimActive = true;
+
+ this.UseToolbarManager = ToolbarManager.ToolbarAvailable;
+
+ this.LoadConfig();
+
+ this.SetIconTexture(this.powerState | this.activeState);
+ }
+
+ public virtual void Dispose()
+ {
+ this.StopGUI();
+
+ if (this.AppLauncherButton != null)
+ {
+ ApplicationLauncher.Instance.RemoveModApplication(this.AppLauncherButton);
+ this.AppLauncherButton = null;
+ }
+ if (this.ToolbarButton != null)
+ {
+ this.ToolbarButton.Destroy();
+ this.ToolbarButton = null;
+ }
+
+ _instance = null;
+ _initialized = false;
+ }
+
+ protected enum IconState
+ {
+ PowerOff = 1,
+ PowerOn = 2,
+ Inactive = 4,
+ Active = 8
+ }
+ }
+}
+
+
--- /dev/null
+++ b/VOIDCore_SpaceCentre.cs
@@ -1,1 +1,61 @@
+// VOID
+//
+// VOIDCore_SpaceCentre.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 class VOIDCore_SpaceCentre : VOIDCore_Generic<VOIDCore_SpaceCentre>
+ {
+ #region Static Members
+ protected new static bool _initialized = false;
+ public new static bool Initialized
+ {
+ get
+ {
+ return _initialized;
+ }
+ }
+
+ 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
+ }
+}
+
+
--- a/VOIDEditorMaster.cs
+++ /dev/null
@@ -1,130 +1,1 @@
-// VOID
-//
-// VOIDEditorMaster.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 KerbalEngineer.VesselSimulator;
-using KSP;
-using System;
-using ToadicusTools;
-using UnityEngine;
-
-namespace VOID
-{
- [KSPAddon(KSPAddon.Startup.EditorAny, false)]
- public class VOIDEditorMaster : MonoBehaviour
- {
- protected VOID_EditorCore Core;
-
- public void Awake()
- {
- Tools.PostDebugMessage ("VOIDEditorMaster: Waking up.");
- this.Core = VOID_EditorCore.Instance;
- this.Core.ResetGUI ();
- Tools.PostDebugMessage ("VOIDEditorMaster: Awake.");
- }
-
- public void Update()
- {
- if (!HighLogic.LoadedSceneIsEditor && this.Core != null)
- {
- this.Core.SaveConfig ();
- this.Core = null;
- VOID_EditorCore.Reset();
- return;
- }
-
- if (this.Core == null)
- {
- this.Awake();
- }
-
- this.Core.Update ();
-
- if (this.Core.factoryReset)
- {
- KSP.IO.File.Delete<VOID_EditorCore>("config.xml");
- this.Core = null;
- VOID_EditorCore.Reset();
- }
- }
-
- public void FixedUpdate()
- {
- if (this.Core == null || !HighLogic.LoadedSceneIsEditor)
- {
- return;
- }
-
- this.Core.FixedUpdate ();
- }
-
- public void OnGUI()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnGUI();
- }
-
- public void OnDestroy()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnDestroy();
- }
-
- public void OnApplicationQuit()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnApplicationQuit();
- }
- }
-}
-
--- a/VOIDFlightMaster.cs
+++ /dev/null
@@ -1,129 +1,1 @@
-// VOID
-//
-// VOIDFlightMaster.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
-{
- [KSPAddon(KSPAddon.Startup.Flight, false)]
- public class VOIDFlightMaster : MonoBehaviour
- {
- protected VOID_Core Core;
-
- public void Awake()
- {
- Tools.PostDebugMessage ("VOIDFlightMaster: Waking up.");
- this.Core = (VOID_Core)VOID_Core.Instance;
- this.Core.ResetGUI ();
- Tools.PostDebugMessage ("VOIDFlightMaster: Awake.");
- }
-
- public void Update()
- {
- if (!HighLogic.LoadedSceneIsFlight && this.Core != null)
- {
- this.Core.SaveConfig ();
- this.Core = null;
- VOID_Core.Reset();
- return;
- }
-
- if (this.Core == null)
- {
- this.Awake();
- }
-
- this.Core.Update ();
-
- if (this.Core.factoryReset)
- {
- KSP.IO.File.Delete<VOID_Core>("config.xml");
- this.Core = null;
- VOID_Core.Reset();
- }
- }
-
- public void FixedUpdate()
- {
- if (this.Core == null || !HighLogic.LoadedSceneIsFlight)
- {
- return;
- }
-
- this.Core.FixedUpdate ();
- }
-
- public void OnGUI()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnGUI();
- }
-
- public void OnDestroy()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnDestroy();
- }
-
- public void OnApplicationQuit()
- {
- if (this.Core == null)
- {
- return;
- }
-
- this.Core.OnApplicationQuit();
- }
- }
-}
-
--- /dev/null
+++ b/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/VOIDMaster_Editor.cs
@@ -1,1 +1,63 @@
+// VOID
+//
+// VOIDEditorMaster.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 KerbalEngineer.VesselSimulator;
+using KSP;
+using System;
+using ToadicusTools;
+using UnityEngine;
+
+namespace VOID
+{
+ [KSPAddon(KSPAddon.Startup.EditorAny, false)]
+ public class VOIDMaster_Editor : VOIDMaster<VOIDCore_Editor>
+ {
+ public override void Awake()
+ {
+ Tools.PostDebugMessage ("VOIDEditorMaster: Waking up.");
+ this.Core = VOIDCore_Editor.Instance;
+ this.Core.ResetGUI ();
+ Tools.PostDebugMessage ("VOIDEditorMaster: Awake.");
+ }
+ }
+}
+
--- /dev/null
+++ b/VOIDMaster_Flight.cs
@@ -1,1 +1,62 @@
+// VOID
+//
+// VOIDFlightMaster.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
+{
+ [KSPAddon(KSPAddon.Startup.Flight, false)]
+ public class VOIDMaster_Flight : VOIDMaster<VOIDCore_Flight>
+ {
+ public override void Awake()
+ {
+ this.LogDebug("Waking up.");
+ this.Core = VOIDCore_Flight.Instance;
+ this.Core.ResetGUI ();
+ this.LogDebug("Awake.");
+ }
+ }
+}
+
--- /dev/null
+++ b/VOIDMaster_SpaceCentre.cs
@@ -1,1 +1,62 @@
+// VOID
+//
+// VOIDFlightMaster.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
+{
+ [KSPAddon(KSPAddon.Startup.SpaceCentre, false)]
+ public class VOIDMaster_SpaceCentre : VOIDMaster<VOIDCore_SpaceCentre>
+ {
+ public override void Awake()
+ {
+ this.LogDebug("Waking up.");
+ this.Core = VOIDCore_SpaceCentre.Instance;
+ this.Core.ResetGUI ();
+ this.LogDebug("Awake.");
+ }
+ }
+}
+
--- a/VOID_CBInfoBrowser.cs
+++ b/VOID_CBInfoBrowser.cs
@@ -368,7 +368,7 @@
GUILayout.Label(num_art_sats.ToString(), VOID_Styles.labelRight, GUILayout.ExpandWidth(true));
- double g_ASL = (VOID_Core.Constant_G * body.Mass) / (body.Radius * body.Radius);
+ double g_ASL = (VOIDCore.Constant_G * body.Mass) / (body.Radius * body.Radius);
GUILayout.Label(Tools.MuMech_ToSI(g_ASL) + "m/s²", VOID_Styles.labelRight, GUILayout.ExpandWidth(true));
--- a/VOID_CareerStatus.cs
+++ b/VOID_CareerStatus.cs
@@ -34,6 +34,7 @@
namespace VOID
{
+ [VOID_Scenes(GameScenes.FLIGHT, GameScenes.EDITOR, GameScenes.SPACECENTER)]
public class VOID_CareerStatus : VOID_WindowModule
{
public static VOID_CareerStatus Instance
@@ -67,13 +68,63 @@
private GUIContent repContent;
private GUIContent scienceContent;
+ #pragma warning disable 0414
private Texture2D fundsIconGreen;
private Texture2D fundsIconRed;
private Texture2D reputationIconGreen;
private Texture2D reputationIconRed;
private Texture2D scienceIcon;
+ #pragma warning restore 0414
public override bool toggleActive
+ {
+ get
+ {
+ return base.toggleActive && this.inValidGame;
+ }
+ set
+ {
+ base.toggleActive = this.inValidGame && value;
+ }
+ }
+
+ public double lastFundsChange
+ {
+ get;
+ private set;
+ }
+
+ public float lastRepChange
+ {
+ get;
+ private set;
+ }
+
+ public float lastScienceChange
+ {
+ get;
+ private set;
+ }
+
+ public double currentFunds
+ {
+ get;
+ private set;
+ }
+
+ public float currentReputation
+ {
+ get;
+ private set;
+ }
+
+ public float currentScience
+ {
+ get;
+ private set;
+ }
+
+ private bool inValidGame
{
get
{
@@ -81,63 +132,32 @@
{
case Game.Modes.CAREER:
case Game.Modes.SCIENCE_SANDBOX:
- return base.toggleActive;
+ return true;
default:
return false;
}
}
- set
- {
- switch (HighLogic.CurrentGame.Mode)
- {
- case Game.Modes.CAREER:
- case Game.Modes.SCIENCE_SANDBOX:
- base.toggleActive = value;
- break;
- default:
- return;
- }
- }
- }
-
- public double lastFundsChange
- {
- get;
- private set;
- }
-
- public float lastRepChange
- {
- get;
- private set;
- }
-
- public float lastScienceChange
- {
- get;
- private set;
- }
-
- public double currentFunds
- {
- get;
- private set;
- }
-
- public float currentReputation
- {
- get;
- private set;
- }
-
- public float currentScience
- {
- get;
- private set;
+ }
+
+ private bool currenciesInitialized
+ {
+ get
+ {
+ return (
+ this.currentFunds == double.NaN ||
+ this.currentScience == float.NaN ||
+ this.currentReputation == float.NaN
+ );
+ }
}
public override void ModuleWindow(int _)
{
+ if (!this.currenciesInitialized)
+ {
+ this.initCurrencies();
+ }
+
GUILayout.BeginVertical();
GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
@@ -183,6 +203,14 @@
{
this.lastScienceChange = newValue - this.currentScience;
this.currentScience = newValue;
+ }
+
+ private void initCurrencies()
+ {
+ 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 ?
+ ResearchAndDevelopment.Instance.Science : float.NaN;
}
/*
@@ -221,10 +249,7 @@
this.scienceContent.image = this.scienceIcon;
}
- 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 ?
- ResearchAndDevelopment.Instance.Science : float.NaN;
+ this.initCurrencies();
}
~VOID_CareerStatus()
--- a/VOID_Core.cs
+++ /dev/null
@@ -1,1173 +1,1 @@
-// VOID
-//
-// VOID_Core.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.Linq;
-using System.Text;
-using ToadicusTools;
-using UnityEngine;
-
-namespace VOID
-{
- public class VOID_Core : VOID_Module, IVOID_Module
- {
- #region Singleton Members
- /*
- * Static Members
- * */
- protected static bool _initialized = false;
-
- public static bool Initialized
- {
- get
- {
- return _initialized;
- }
- }
-
- protected static VOID_Core _instance;
-
- public static VOID_Core Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new VOID_Core();
- _initialized = true;
- }
- return _instance;
- }
- }
-
- public static void Reset()
- {
- _instance.StopGUI();
- _instance.Dispose();
- _instance = null;
- _initialized = false;
- }
- #endregion
-
- public static readonly double Constant_G = 6.674e-11;
-
- /*
- * Fields
- * */
- protected string VoidName = "VOID";
- protected string VoidVersion;
-
- protected bool _factoryReset = false;
-
- [AVOID_SaveValue("configValue")]
- protected VOID_SaveValue<int> configVersion = 1;
-
- protected List<IVOID_Module> _modules = new List<IVOID_Module>();
- protected bool _modulesLoaded = false;
-
- [AVOID_SaveValue("mainWindowPos")]
- protected VOID_SaveValue<Rect> mainWindowPos = new Rect(475, 575, 10f, 10f);
- [AVOID_SaveValue("mainGuiMinimized")]
- protected VOID_SaveValue<bool> mainGuiMinimized = false;
-
- [AVOID_SaveValue("configWindowPos")]
- protected VOID_SaveValue<Rect> configWindowPos = new Rect(825, 625, 10f, 10f);
- [AVOID_SaveValue("configWindowMinimized")]
-
- protected VOID_SaveValue<bool> configWindowMinimized = true;
- [AVOID_SaveValue("VOIDIconPos")]
- protected VOID_SaveValue<Rect> VOIDIconPos = new Rect(Screen.width / 2 - 200, Screen.height - 32, 32f, 32f);
-
- protected Texture2D VOIDIconTexture;
- protected string VOIDIconOnActivePath;
- protected string VOIDIconOnInactivePath;
- protected string VOIDIconOffActivePath;
- protected string VOIDIconOffInactivePath;
-
- protected bool VOIDIconLocked = true;
-
- protected GUIStyle iconStyle;
-
- protected int windowBaseID = -96518722;
- protected int _windowID = 0;
-
- protected bool GUIStylesLoaded = false;
-
- protected CelestialBody _homeBody;
-
- [AVOID_SaveValue("togglePower")]
- public VOID_SaveValue<bool> togglePower = true;
- public bool powerAvailable = true;
-
- [AVOID_SaveValue("consumeResource")]
- protected VOID_SaveValue<bool> consumeResource = false;
-
- [AVOID_SaveValue("resourceName")]
- protected VOID_SaveValue<string> resourceName = "ElectricCharge";
-
- [AVOID_SaveValue("resourceRate")]
- protected VOID_SaveValue<float> resourceRate = 0.2f;
-
- [AVOID_SaveValue("updatePeriod")]
- protected VOID_SaveValue<double> _updatePeriod = 1001f / 15000f;
- protected float _updateTimer = 0f;
- protected string stringFrequency;
-
- [AVOID_SaveValue("vesselSimActive")]
- protected VOID_SaveValue<bool> vesselSimActive;
-
- // Vessel Type Housekeeping
- protected List<VesselType> _allVesselTypes = new List<VesselType>();
- protected bool vesselTypesLoaded = false;
- public float saveTimer = 0;
-
- protected string defaultSkin = "KSP window 2";
-
- [AVOID_SaveValue("defaultSkin")]
- protected VOID_SaveValue<string> _skinName;
- protected int _skinIdx;
-
- protected Dictionary<string, GUISkin> validSkins;
- protected string[] skinNames;
- protected string[] forbiddenSkins =
- {
- "PlaqueDialogSkin",
- "FlagBrowserSkin",
- "SSUITextAreaDefault",
- "ExperimentsDialogSkin",
- "ExpRecoveryDialogSkin",
- "KSP window 5",
- "KSP window 6",
- "PartTooltipSkin",
- "KSCContextMenuSkin"
- };
- protected bool skinsLoaded = false;
-
- public bool configDirty;
-
- [AVOID_SaveValue("UseBlizzyToolbar")]
- protected VOID_SaveValue<bool> _UseToolbarManager;
- internal IButton ToolbarButton;
-
- internal ApplicationLauncherButton AppLauncherButton;
-
- /*
- * Events
- * */
- public delegate void VOIDEventHandler(object sender);
- public event VOIDEventHandler onApplicationQuit;
-
- /*
- * Properties
- * */
- public bool factoryReset
- {
- get
- {
- return this._factoryReset;
- }
- }
-
- public List<IVOID_Module> Modules
- {
- get
- {
- return this._modules;
- }
- }
-
- public GUISkin Skin
- {
- get
- {
- if (this.skinsLoaded)
- {
- try
- {
- return this.validSkins[this._skinName];
- }
- catch
- {
- }
- }
-
- return AssetBase.GetGUISkin(this.defaultSkin);
- }
- }
-
- public int windowID
- {
- get
- {
- if (this._windowID == 0)
- {
- this._windowID = this.windowBaseID;
- }
- return this._windowID++;
- }
- }
-
- public List<CelestialBody> allBodies
- {
- get
- {
- return FlightGlobals.Bodies;
- }
- }
-
- public List<CelestialBody> sortedBodyList
- {
- get;
- private set;
- }
-
- public CelestialBody HomeBody
- {
- get
- {
- if (this._homeBody == null)
- {
- if (Planetarium.fetch != null)
- {
- this._homeBody = Planetarium.fetch.Home;
- }
- }
-
- return this._homeBody;
- }
- }
-
- public List<VesselType> allVesselTypes
- {
- get
- {
- return this._allVesselTypes;
- }
- }
-
- public float updateTimer
- {
- get
- {
- return this._updateTimer;
- }
- }
-
- public double updatePeriod
- {
- get
- {
- return this._updatePeriod;
- }
- }
-
- public Stage[] Stages
- {
- get;
- protected set;
- }
-
- public Stage LastStage
- {
- get;
- protected set;
- }
-
- protected IconState powerState
- {
- get
- {
- if (this.togglePower && this.powerAvailable)
- {
- return IconState.PowerOn;
- }
- else
- {
- return IconState.PowerOff;
- }
-
- }
- }
-
- protected IconState activeState
- {
- get
- {
- if (this.mainGuiMinimized)
- {
- return IconState.Inactive;
- }
- else
- {
- return IconState.Active;
- }
-
- }
- }
-
- protected bool UseToolbarManager
- {
- get
- {
- return _UseToolbarManager & ToolbarManager.ToolbarAvailable;
- }
- set
- {
- if (this._UseToolbarManager == value)
- {
- return;
- }
-
- if (value == false && this.ToolbarButton != null)
- {
- this.ToolbarButton.Destroy();
- this.ToolbarButton = null;
- }
- if (value == true)
- {
- if (this.AppLauncherButton != null)
- {
- ApplicationLauncher.Instance.RemoveModApplication(this.AppLauncherButton);
- this.AppLauncherButton = null;
- }
-
- this.InitializeToolbarButton();
- }
-
- _UseToolbarManager.value = value;
- }
- }
-
- protected virtual ApplicationLauncher.AppScenes appIconVisibleScenes
- {
- get
- {
- return ApplicationLauncher.AppScenes.FLIGHT;
- }
- }
-
- /*
- * Methods
- * */
- public override void DrawGUI()
- {
- this._windowID = this.windowBaseID;
-
- if (!this._modulesLoaded)
- {
- this.LoadModulesOfType<IVOID_Module>();
- }
-
- if (!this.skinsLoaded)
- {
- this.LoadSkins();
- }
-
- GUI.skin = this.Skin;
-
- if (!this.GUIStylesLoaded)
- {
- this.LoadGUIStyles();
-
- Tools.PostDebugMessage(
- this,
- "ToolbarAvailable: {0}, UseToobarManager: {1}",
- ToolbarManager.ToolbarAvailable,
- this.UseToolbarManager);
- }
-
- if (!this.UseToolbarManager)
- {
- if (this.AppLauncherButton == null)
- {
- Tools.PostDebugMessage(this,
- "UseToolbarManager = false (ToolbarAvailable = {0}) and " +
- "AppLauncherButton is null, making AppLauncher button.",
- ToolbarManager.ToolbarAvailable
- );
- this.InitializeAppLauncherButton();
- }
- }
- else if (this.ToolbarButton == null)
- {
- Tools.PostDebugMessage(this,
- "UseToolbarManager = true (ToolbarAvailable = {0}) and " +
- "ToolbarButton is null, making Toolbar button.",
- ToolbarManager.ToolbarAvailable
- );
- this.InitializeToolbarButton();
- }
-
- if (!this.mainGuiMinimized)
- {
-
- Rect _mainWindowPos = this.mainWindowPos;
-
- _mainWindowPos = GUILayout.Window(
- this.windowID,
- _mainWindowPos,
- VOID_Tools.GetWindowHandler(this.VOIDMainWindow),
- string.Join(" ", new string[] { this.VoidName, this.VoidVersion }),
- GUILayout.Width(250),
- GUILayout.Height(50)
- );
-
- if (HighLogic.LoadedSceneIsEditor)
- {
- _mainWindowPos = Tools.ClampRectToEditorPad(_mainWindowPos);
- }
- else
- {
- _mainWindowPos = Tools.ClampRectToScreen(_mainWindowPos);
- }
-
- if (_mainWindowPos != this.mainWindowPos)
- {
- this.mainWindowPos = _mainWindowPos;
- }
- }
-
- if (!this.configWindowMinimized && !this.mainGuiMinimized)
- {
- Rect _configWindowPos = this.configWindowPos;
-
- _configWindowPos = GUILayout.Window(
- this.windowID,
- _configWindowPos,
- VOID_Tools.GetWindowHandler(this.VOIDConfigWindow),
- string.Join(" ", new string[] { this.VoidName, "Configuration" }),
- GUILayout.Width(250),
- GUILayout.Height(50)
- );
-
- if (HighLogic.LoadedSceneIsEditor)
- {
- _configWindowPos = Tools.ClampRectToEditorPad(_configWindowPos);
- }
- else
- {
- _configWindowPos = Tools.ClampRectToScreen(_configWindowPos);
- }
-
- if (_configWindowPos != this.configWindowPos)
- {
- this.configWindowPos = _configWindowPos;
- }
- }
- }
-
- public virtual void OnGUI()
- {
- if (Event.current.type == EventType.Repaint)
- {
- return;
- }
-
- /*
- Tools.PostDebugMessage(string.Format(
- "Event.current.type: {0}" +
- "\nthis.VOIDIconLocked: {1}" +
- "\nEvent.current.mousePosition: {2}" +
- "\nVOIDIconPos: ({3}, {4}),({5}, {6})",
- Event.current.type,
- this.VOIDIconLocked,
- Event.current.mousePosition,
- this.VOIDIconPos.value.xMin,
- this.VOIDIconPos.value.yMin,
- this.VOIDIconPos.value.xMax,
- this.VOIDIconPos.value.yMax
- ));
- */
-
- if (!this.VOIDIconLocked &&
- VOIDIconPos.value.Contains(Event.current.mousePosition)
- && Event.current.type == EventType.mouseDrag)
- {
- Tools.PostDebugMessage(string.Format(
- "Event.current.type: {0}" +
- "\ndelta.x: {1}; delta.y: {2}",
- Event.current.type,
- Event.current.delta.x,
- Event.current.delta.y
- ));
-
- Rect tmp = new Rect(VOIDIconPos);
-
- tmp.x = Event.current.mousePosition.x - tmp.width / 2;
- tmp.y = Event.current.mousePosition.y - tmp.height / 2;
-
- if (tmp.x > Screen.width - tmp.width)
- {
- tmp.x = Screen.width - tmp.width;
- }
-
- if (tmp.y > Screen.height - tmp.height)
- {
- tmp.y = Screen.height - tmp.height;
- }
-
- VOIDIconPos = tmp;
- }
- }
-
- public virtual void Update()
- {
- this.LoadBeforeUpdate();
-
- if (this.vessel != null && this.vesselSimActive)
- {
- Tools.PostDebugMessage(this, "Updating SimManager.");
- this.UpdateSimManager();
- }
-
- if (!this.guiRunning)
- {
- this.StartGUI();
- }
-
- if (!HighLogic.LoadedSceneIsFlight && this.guiRunning)
- {
- this.StopGUI();
- }
-
- foreach (IVOID_Module module in this.Modules)
- {
- if (!module.guiRunning && module.toggleActive)
- {
- module.StartGUI();
- }
- if (module.guiRunning && !module.toggleActive ||
- !this.togglePower ||
- !HighLogic.LoadedSceneIsFlight ||
- this.factoryReset)
- {
- module.StopGUI();
- }
-
- if (module is IVOID_BehaviorModule)
- {
- ((IVOID_BehaviorModule)module).Update();
- }
- }
-
- this.CheckAndSave();
- this._updateTimer += Time.deltaTime;
- }
-
- public virtual void FixedUpdate()
- {
- bool newPowerState = this.powerAvailable;
-
- if (this.togglePower && this.consumeResource &&
- this.vessel.vesselType != VesselType.EVA &&
- TimeWarp.deltaTime != 0)
- {
- float powerReceived = this.vessel.rootPart.RequestResource(
- this.resourceName,
- this.resourceRate * TimeWarp.fixedDeltaTime
- );
-
- if (powerReceived > 0)
- {
- newPowerState = true;
- }
- else
- {
- newPowerState = false;
- }
-
- if (this.powerAvailable != newPowerState)
- {
- this.powerAvailable = newPowerState;
- this.SetIconTexture(this.powerState | this.activeState);
- }
- }
-
- foreach (IVOID_Module module in this.Modules)
- {
- if (module is IVOID_BehaviorModule)
- {
- ((IVOID_BehaviorModule)module).FixedUpdate();
- }
- }
- }
-
- public void OnDestroy()
- {
- foreach (IVOID_Module module in this.Modules)
- {
- if (module is IVOID_BehaviorModule)
- {
- ((IVOID_BehaviorModule)module).OnDestroy();
- }
- }
- }
-
- public void OnApplicationQuit()
- {
- this.onApplicationQuit(this);
- }
-
- public void ResetGUI()
- {
- this.StopGUI();
-
- foreach (IVOID_Module module in this.Modules)
- {
- module.StopGUI();
- module.StartGUI();
- }
-
- this.StartGUI();
- }
-
- public void VOIDMainWindow(int _)
- {
- GUILayout.BeginVertical();
-
- if (this.powerAvailable || HighLogic.LoadedSceneIsEditor)
- {
- if (!HighLogic.LoadedSceneIsEditor)
- {
- string str = string.Intern("ON");
- if (togglePower)
- str = string.Intern("OFF");
- if (GUILayout.Button("Power " + str))
- {
- togglePower.value = !togglePower;
- this.SetIconTexture(this.powerState | this.activeState);
- }
- }
-
- if (togglePower || HighLogic.LoadedSceneIsEditor)
- {
- foreach (IVOID_Module module in this.Modules)
- {
- module.toggleActive = GUILayout.Toggle(module.toggleActive, module.Name);
- }
- }
- }
- else
- {
- GUILayout.Label("-- POWER LOST --", VOID_Styles.labelRed);
- }
-
- this.configWindowMinimized.value = !GUILayout.Toggle(!this.configWindowMinimized, "Configuration");
-
- GUILayout.EndVertical();
- GUI.DragWindow();
- }
-
- public void VOIDConfigWindow(int _)
- {
- GUILayout.BeginVertical();
-
- this.DrawConfigurables();
-
- GUILayout.EndVertical();
- GUI.DragWindow();
- }
-
- public override void DrawConfigurables()
- {
- GUIContent _content;
-
- if (HighLogic.LoadedSceneIsFlight)
- {
- this.consumeResource.value = GUILayout.Toggle(this.consumeResource, "Consume Resources");
-
- this.VOIDIconLocked = GUILayout.Toggle(this.VOIDIconLocked, "Lock Icon Position");
- }
-
- this.UseToolbarManager = GUILayout.Toggle(this.UseToolbarManager, "Use Blizzy's Toolbar If Available");
-
- this.vesselSimActive.value = GUILayout.Toggle(this.vesselSimActive.value,
- "Enable Engineering Calculations");
-
- GUILayout.BeginHorizontal(GUILayout.ExpandWidth(true));
-
- GUILayout.Label("Skin:", GUILayout.ExpandWidth(false));
-
- _content = new GUIContent();
-
- _content.text = "◄";
- _content.tooltip = "Select previous skin";
- if (GUILayout.Button(_content, GUILayout.ExpandWidth(true)))
- {
- this._skinIdx--;
- Tools.PostDebugMessage(string.Format(
- "{0}: new this._skinIdx = {1} :: skin_list.Count = {2}",
- this.GetType().Name,
- this._skinName,
- this.validSkins.Count
- ));
- }
-
- _content.text = this.Skin.name;
- _content.tooltip = "Current skin";
- GUILayout.Label(_content, VOID_Styles.labelCenter, GUILayout.ExpandWidth(true));
-
- _content.text = "►";
- _content.tooltip = "Select next skin";
- if (GUILayout.Button(_content, GUILayout.ExpandWidth(true)))
- {
- this._skinIdx++;
- Tools.PostDebugMessage(string.Format(
- "{0}: new this._skinIdx = {1} :: skin_list.Count = {2}",
- this.GetType().Name,
- this._skinName,
- this.validSkins.Count
- ));
- }
-
- this._skinIdx %= this.skinNames.Length;
- if (this._skinIdx < 0)
- {
- this._skinIdx += this.skinNames.Length;
- }
-
- if (this._skinName != skinNames[this._skinIdx])
- {
- this._skinName.value = skinNames[this._skinIdx];
- this.GUIStylesLoaded = false;
- }
-
- GUILayout.EndHorizontal();
-
- GUILayout.BeginHorizontal();
- GUILayout.Label("Update Rate (Hz):");
- if (this.stringFrequency == null)
- {
- this.stringFrequency = (1f / this.updatePeriod).ToString();
- }
- this.stringFrequency = GUILayout.TextField(this.stringFrequency.ToString(), 5, GUILayout.ExpandWidth(true));
-
- if (GUILayout.Button("Apply"))
- {
- double updateFreq = 1f / this.updatePeriod;
- double.TryParse(stringFrequency, out updateFreq);
- this._updatePeriod = 1 / updateFreq;
- }
- GUILayout.EndHorizontal();
-
- foreach (IVOID_Module mod in this.Modules)
- {
- mod.DrawConfigurables();
- }
-
- this._factoryReset = GUILayout.Toggle(this._factoryReset, "Factory Reset");
- }
-
- protected void UpdateSimManager()
- {
- if (SimManager.ResultsReady())
- {
- Tools.PostDebugMessage(this, "VesselSimulator results ready, setting Stages.");
-
- this.Stages = SimManager.Stages;
-
- if (this.Stages != null)
- {
- this.LastStage = this.Stages.Last();
- }
-
- if (HighLogic.LoadedSceneIsEditor)
- {
- SimManager.Gravity = VOID_Data.KerbinGee;
- }
- else
- {
- double radius = this.vessel.Radius();
- SimManager.Gravity = this.vessel.mainBody.gravParameter / (radius * radius);
- }
-
- SimManager.minSimTime = new TimeSpan(0, 0, 0, 0, (int)(this.updatePeriod * 1000d));
-
- SimManager.TryStartSimulation();
- }
- #if DEBUG
- else
- {
- Tools.PostDebugMessage(this, "VesselSimulator results not ready.");
- }
- #endif
- }
-
- protected void LoadModulesOfType<T>()
- {
- StringBuilder sb = new StringBuilder("Loading modules...");
- sb.AppendLine();
-
- foreach (AssemblyLoader.LoadedAssembly assy in AssemblyLoader.loadedAssemblies)
- {
- foreach (Type loadedType in assy.assembly.GetExportedTypes())
- {
- if (
- loadedType.IsInterface ||
- loadedType.IsAbstract ||
- !typeof(T).IsAssignableFrom(loadedType) ||
- this.GetType().IsAssignableFrom(loadedType)
- )
- {
- continue;
- }
-
- // HACK: This stops editor modules from loading in flight. It is a dirty hack and should be fixed.
- if (!HighLogic.LoadedSceneIsEditor && typeof(IVOID_EditorModule).IsAssignableFrom(loadedType))
- {
- continue;
- }
-
- sb.AppendFormat("Loading IVOID_Module type {0}...", loadedType.Name);
-
- try
- {
- this.LoadModule(loadedType);
- sb.AppendLine("Success.");
- }
- catch (Exception ex)
- {
- sb.AppendFormat("Failed, caught {0}", ex.GetType().Name);
- sb.AppendLine();
-
- #if DEBUG
- Debug.LogException(ex);
- #endif
- }
- }
- }
-
- this._modulesLoaded = true;
-
- sb.AppendFormat("Loaded {0} modules.", this.Modules.Count);
- sb.AppendLine();
- }
-
- protected void LoadModule(Type T)
- {
- var existingModules = this._modules.Where(mod => mod.GetType().Name == T.Name);
- if (existingModules.Any())
- {
- Tools.PostDebugMessage(string.Format(
- "{0}: refusing to load {1}: already loaded",
- this.GetType().Name,
- T.Name
- ));
- return;
- }
- IVOID_Module module = Activator.CreateInstance(T) as IVOID_Module;
- module.LoadConfig();
- this._modules.Add(module);
-
- Tools.PostDebugMessage(string.Format(
- "{0}: loaded module {1}.",
- this.GetType().Name,
- T.Name
- ));
- }
-
- protected void LoadSkins()
- {
- Tools.PostDebugMessage("AssetBase has skins: \n" +
- string.Join("\n\t",
- Resources.FindObjectsOfTypeAll(typeof(GUISkin))
- .Select(s => s.ToString())
- .ToArray()
- )
- );
-
- this.validSkins = Resources.FindObjectsOfTypeAll(typeof(GUISkin))
- .Where(s => !this.forbiddenSkins.Contains(s.name))
- .Select(s => s as GUISkin)
- .GroupBy(s => s.name)
- .Select(g => g.First())
- .ToDictionary(s => s.name);
-
- Tools.PostDebugMessage(string.Format(
- "{0}: loaded {1} GUISkins.",
- this.GetType().Name,
- this.validSkins.Count
- ));
-
- this.skinNames = this.validSkins.Keys.ToArray();
- Array.Sort(this.skinNames);
-
- int defaultIdx = int.MinValue;
-
- for (int i = 0; i < this.skinNames.Length; i++)
- {
- if (this.skinNames[i] == this._skinName)
- {
- this._skinIdx = i;
- }
- if (this.skinNames[i] == this.defaultSkin)
- {
- defaultIdx = i;
- }
- if (this._skinIdx != int.MinValue && defaultIdx != int.MinValue)
- {
- break;
- }
- }
-
- if (this._skinIdx == int.MinValue)
- {
- this._skinIdx = defaultIdx;
- }
-
- Tools.PostDebugMessage(string.Format(
- "{0}: _skinIdx = {1}.",
- this.GetType().Name,
- this._skinName.ToString()
- ));
-
- this.skinsLoaded = true;
- }
-
- protected void LoadGUIStyles()
- {
- VOID_Styles.OnSkinChanged();
-
- this.GUIStylesLoaded = true;
- }
-
- protected void LoadVesselTypes()
- {
- this._allVesselTypes = Enum.GetValues(typeof(VesselType)).OfType<VesselType>().ToList();
- this.vesselTypesLoaded = true;
- }
-
- protected void LoadBeforeUpdate()
- {
- if (!this.vesselTypesLoaded)
- {
- this.LoadVesselTypes();
- }
-
- if (this.sortedBodyList == null && FlightGlobals.Bodies != null && FlightGlobals.Bodies.Count > 0)
- {
- this.sortedBodyList = new List<CelestialBody>(FlightGlobals.Bodies);
- this.sortedBodyList.Sort(new CBListComparer());
- this.sortedBodyList.Reverse();
-
- Debug.Log(string.Format("sortedBodyList: {0}", string.Join("\n\t", this.sortedBodyList.Select(b => b.bodyName).ToArray())));
- }
-
- }
-
- protected void InitializeToolbarButton()
- {
- // Do nothing if (the Toolbar is not available.
- if (!ToolbarManager.ToolbarAvailable)
- {
- Tools.PostDebugMessage(this, "Refusing to make a ToolbarButton: ToolbarAvailable = false");
- return;
- }
-
- this.ToolbarButton = ToolbarManager.Instance.add(this.VoidName, "coreToggle");
- this.ToolbarButton.Text = this.VoidName;
- this.SetIconTexture(this.powerState | this.activeState);
-
- this.ToolbarButton.Visibility = new GameScenesVisibility(GameScenes.EDITOR, GameScenes.FLIGHT);
-
- this.ToolbarButton.OnClick +=
- (e) =>
- {
- this.ToggleMainWindow();
- };
-
- Tools.PostDebugMessage(string.Format("{0}: Toolbar Button initialized.", this.GetType().Name));
- }
-
- protected void InitializeAppLauncherButton()
- {
- if (ApplicationLauncher.Ready)
- {
- this.AppLauncherButton = ApplicationLauncher.Instance.AddModApplication(
- this.ToggleMainWindow, this.ToggleMainWindow,
- this.appIconVisibleScenes,
- this.VOIDIconTexture
- );
-
- Tools.PostDebugMessage(
- this,
- "AppLauncherButton initialized in {0}",
- Enum.GetName(
- typeof(GameScenes),
- HighLogic.LoadedScene
- )
- );
- }
- }
-
- protected void ToggleMainWindow()
- {
- this.mainGuiMinimized = !this.mainGuiMinimized;
- this.SetIconTexture(this.powerState | this.activeState);
- }
-
- protected void SetIconTexture(IconState state)
- {
- switch (state)
- {
- case (IconState.PowerOff | IconState.Inactive):
- this.SetIconTexture(this.VOIDIconOffInactivePath);
- break;
- case (IconState.PowerOff | IconState.Active):
- this.SetIconTexture(this.VOIDIconOffActivePath);
- break;
- case (IconState.PowerOn | IconState.Inactive):
- this.SetIconTexture(this.VOIDIconOnInactivePath);
- break;
- case (IconState.PowerOn | IconState.Active):
- this.SetIconTexture(this.VOIDIconOnActivePath);
- break;
- default:
- throw new NotImplementedException();
- }
- }
-
- protected void SetIconTexture(string texturePath)
- {
- if (this.ToolbarButton != null)
- {
- this.ToolbarButton.TexturePath = texturePath;
- }
-
- this.VOIDIconTexture = GameDatabase.Instance.GetTexture(texturePath.Replace("icon", "appIcon"), false);
-
- if (this.AppLauncherButton != null)
- {
- this.AppLauncherButton.SetTexture(VOIDIconTexture);
- }
- }
-
- protected void CheckAndSave()
- {
- this.saveTimer += Time.deltaTime;
-
- if (this.saveTimer > 2f)
- {
- if (!this.configDirty)
- {
- return;
- }
-
- Tools.PostDebugMessage(string.Format(
- "{0}: Time to save, checking if configDirty: {1}",
- this.GetType().Name,
- this.configDirty
- ));
-
- this.SaveConfig();
- this.saveTimer = 0;
- }
- }
-
- public override void LoadConfig()
- {
- base.LoadConfig();
-
- foreach (IVOID_Module module in this.Modules)
- {
- module.LoadConfig();
- }
- }
-
- public void SaveConfig()
- {
- var config = KSP.IO.PluginConfiguration.CreateForType<VOID_Core>();
- config.load();
-
- this._SaveToConfig(config);
-
- foreach (IVOID_Module module in this.Modules)
- {
- module._SaveToConfig(config);
- }
-
- config.save();
-
- this.configDirty = false;
- }
-
- protected VOID_Core()
- {
- this._Name = "VOID Core";
-
- System.Version version = this.GetType().Assembly.GetName().Version;
-
- this.VoidVersion = string.Format("{0}.{1}.{2}", version.Major, version.Minor, version.MajorRevision);
-
- this.toggleActive = true;
-
- 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.vesselSimActive = true;
-
- this.UseToolbarManager = false;
-
- this.LoadConfig();
-
- this.SetIconTexture(this.powerState | this.activeState);
- }
-
- public virtual void Dispose()
- {
- if (this.AppLauncherButton != null)
- {
- ApplicationLauncher.Instance.RemoveModApplication(this.AppLauncherButton);
- this.AppLauncherButton = null;
- }
- if (this.ToolbarButton != null)
- {
- this.ToolbarButton.Destroy();
- this.ToolbarButton = null;
- }
- }
-
- protected enum IconState
- {
- PowerOff = 1,
- PowerOn = 2,
- Inactive = 4,
- Active = 8
- }
- }
-}
-
-
--- a/VOID_Data.cs
+++ b/VOID_Data.cs
@@ -56,7 +56,7 @@
{
if (kerbinGee == default(double))
{
- kerbinGee = core.HomeBody.gravParameter / (core.HomeBody.Radius * core.HomeBody.Radius);
+ kerbinGee = Core.HomeBody.gravParameter / (Core.HomeBody.Radius * Core.HomeBody.Radius);
}
return kerbinGee;
@@ -67,21 +67,47 @@
#region Core Data
- public static VOID_Core core
+ public static VOIDCore Core
{
get
{
- if (HighLogic.LoadedSceneIsEditor)
- {
- return VOID_EditorCore.Instance;
- }
- else
- {
- return VOID_Core.Instance;
+ if (!CoreInitialized)
+ {
+ return null;
+ }
+
+ switch (HighLogic.LoadedScene)
+ {
+ case GameScenes.EDITOR:
+ return (VOIDCore)VOIDCore_Editor.Instance;
+ case GameScenes.FLIGHT:
+ return (VOIDCore)VOIDCore_Flight.Instance;
+ case GameScenes.SPACECENTER:
+ return (VOIDCore)VOIDCore_SpaceCentre.Instance;
+ default:
+ return null;
}
}
}
+ public static bool CoreInitialized
+ {
+ get
+ {
+ switch (HighLogic.LoadedScene)
+ {
+ case GameScenes.EDITOR:
+ return VOIDCore_Editor.Initialized;
+ case GameScenes.FLIGHT:
+ return VOIDCore_Flight.Initialized;
+ case GameScenes.SPACECENTER:
+ return VOIDCore_SpaceCentre.Initialized;
+ default:
+ return false;
+ }
+ }
+ }
+
#endregion
#region Atmosphere
@@ -89,28 +115,28 @@
public static readonly VOID_DoubleValue atmDensity =
new VOID_DoubleValue(
"Atmosphere Density",
- new Func<double>(() => core.vessel.atmDensity * 1000f),
+ new Func<double>(() => Core.vessel.atmDensity * 1000f),
"g/m³"
);
public static readonly VOID_FloatValue atmLimit =
new VOID_FloatValue(
"Atmosphere Limit",
- new Func<float>(() => core.vessel.mainBody.maxAtmosphereAltitude),
+ new Func<float>(() => Core.vessel.mainBody.maxAtmosphereAltitude),
"m"
);
public static readonly VOID_DoubleValue atmPressure =
new VOID_DoubleValue(
"Pressure",
- new Func<double>(() => core.vessel.staticPressure),
+ new Func<double>(() => Core.vessel.staticPressure),
"atm"
);
public static readonly VOID_FloatValue temperature =
new VOID_FloatValue(
"Temperature",
- new Func<float>(() => core.vessel.flightIntegrator.getExternalTemperature()),
+ new Func<float>(() => Core.vessel.flightIntegrator.getExternalTemperature()),
"°C"
);
@@ -123,7 +149,7 @@
"Heading",
delegate()
{
- double heading = core.vessel.getSurfaceHeading();
+ double heading = Core.vessel.getSurfaceHeading();
string cardinal = VOID_Tools.get_heading_text(heading);
return string.Format(
@@ -137,7 +163,7 @@
public static readonly VOID_DoubleValue vesselPitch =
new VOID_DoubleValue(
"Pitch",
- () => core.vessel.getSurfacePitch(),
+ () => Core.vessel.getSurfacePitch(),
"°"
);
@@ -203,7 +229,7 @@
public static readonly VOID_FloatValue mainThrottle =
new VOID_FloatValue(
"Throttle",
- new Func<float>(() => core.vessel.ctrlState.mainThrottle * 100f),
+ new Func<float>(() => Core.vessel.ctrlState.mainThrottle * 100f),
"%"
);
@@ -214,7 +240,7 @@
public static readonly VOID_IntValue partCount =
new VOID_IntValue(
"Parts",
- new Func<int>(() => core.vessel.Parts.Count),
+ new Func<int>(() => Core.vessel.Parts.Count),
""
);
@@ -237,12 +263,12 @@
"Resource Mass",
delegate()
{
- if (core.Stages == null || core.LastStage == null)
- {
- return double.NaN;
- }
-
- return core.LastStage.resourceMass;
+ if (Core.Stages == null || Core.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ return Core.LastStage.resourceMass;
},
"tons"
);
@@ -252,12 +278,12 @@
"Resource Mass (Stage)",
delegate()
{
- if (core.LastStage == null)
- {
- return double.NaN;
- }
-
- return core.LastStage.resourceMass;
+ if (Core.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ return Core.LastStage.resourceMass;
},
"tons"
);
@@ -267,12 +293,12 @@
"Total Mass",
delegate()
{
- if (core.Stages == null || core.LastStage == null)
- {
- return double.NaN;
- }
-
- return core.LastStage.totalMass;
+ if (Core.Stages == null || Core.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ return Core.LastStage.totalMass;
},
"tons"
);
@@ -286,9 +312,9 @@
"DeltaV (Current Stage)",
delegate()
{
- if (core.Stages == null || core.LastStage == null)
- return double.NaN;
- return core.LastStage.deltaV;
+ if (Core.Stages == null || Core.LastStage == null)
+ return double.NaN;
+ return Core.LastStage.deltaV;
},
"m/s"
);
@@ -298,9 +324,9 @@
"DeltaV (Total)",
delegate()
{
- if (core.Stages == null || core.LastStage == null)
- return double.NaN;
- return core.LastStage.totalDeltaV;
+ if (Core.Stages == null || Core.LastStage == null)
+ return double.NaN;
+ return Core.LastStage.totalDeltaV;
},
"m/s"
);
@@ -314,7 +340,7 @@
"T:W (curr/max)",
delegate()
{
- if (core.Stages == null || core.LastStage == null)
+ if (Core.Stages == null || Core.LastStage == null)
return "N/A";
return string.Format(
@@ -330,11 +356,11 @@
"Thrust (curr/max)",
delegate()
{
- if (core.Stages == null || core.LastStage == null)
+ if (Core.Stages == null || Core.LastStage == null)
return "N/A";
- double currThrust = core.LastStage.actualThrust;
- double maxThrust = core.LastStage.thrust;
+ double currThrust = Core.LastStage.actualThrust;
+ double maxThrust = Core.LastStage.thrust;
return string.Format(
"{0} / {1}",
@@ -349,12 +375,12 @@
"Stage Mass Flow",
delegate()
{
- if (core.LastStage == null)
- {
- return double.NaN;
- }
-
- double stageIsp = core.LastStage.isp;
+ if (Core.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ double stageIsp = Core.LastStage.isp;
double stageThrust = stageNominalThrust;
Tools.PostDebugMessage(typeof(VOID_Data), "calculating stageMassFlow from:\n" +
@@ -376,18 +402,18 @@
"Nominal Stage Thrust",
delegate()
{
- if (core.LastStage == null)
- {
- return double.NaN;
- }
-
- if (core.LastStage.actualThrust == 0d)
- {
- return core.LastStage.thrust;
+ if (Core.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ if (Core.LastStage.actualThrust == 0d)
+ {
+ return Core.LastStage.thrust;
}
else
{
- return core.LastStage.actualThrust;
+ return Core.LastStage.actualThrust;
}
},
"kN"
@@ -402,12 +428,12 @@
"T:W Ratio",
delegate()
{
- if (core.LastStage == null)
- {
- return double.NaN;
- }
-
- return core.LastStage.actualThrustToWeight;
+ if (Core.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ return Core.LastStage.actualThrustToWeight;
},
""
);
@@ -419,12 +445,12 @@
"T:W Ratio",
delegate()
{
- if (core.LastStage == null)
- {
- return double.NaN;
- }
-
- return core.LastStage.thrustToWeight;
+ if (Core.LastStage == null)
+ {
+ return double.NaN;
+ }
+
+ return Core.LastStage.thrustToWeight;
},
""
);
@@ -449,13 +475,13 @@
"Max T:W @ surface",
delegate()
{
- if (core.Stages == null || core.LastStage == null)
- return double.NaN;
-
- double maxThrust = core.LastStage.thrust;
- double mass = core.LastStage.totalMass;
- double gravity = (VOID_Core.Constant_G * core.vessel.mainBody.Mass) /
- (core.vessel.mainBody.Radius * core.vessel.mainBody.Radius);
+ if (Core.Stages == null || Core.LastStage == null)
+ return double.NaN;
+
+ double maxThrust = Core.LastStage.thrust;
+ double mass = Core.LastStage.totalMass;
+ double gravity = (VOIDCore.Constant_G * Core.vessel.mainBody.Mass) /
+ (Core.vessel.mainBody.Radius * Core.vessel.mainBody.Radius);
double weight = mass * gravity;
return maxThrust / weight;
@@ -468,12 +494,12 @@
"Thrust Offset",
delegate()
{
- if (core.vessel == null)
+ if (Core.vessel == null)
{
return Vector3d.zero;
}
- List<PartModule> engineModules = core.vessel.getModulesOfType<PartModule>();
+ List<PartModule> engineModules = Core.vessel.getModulesOfType<PartModule>();
Vector3d thrustPos = Vector3d.zero;
Vector3d thrustDir = Vector3d.zero;
@@ -532,13 +558,13 @@
thrustDir /= thrust;
}
- Transform vesselTransform = core.vessel.transform;
+ Transform vesselTransform = Core.vessel.transform;
thrustPos = vesselTransform.InverseTransformPoint(thrustPos);
thrustDir = vesselTransform.InverseTransformDirection(thrustDir);
Vector3d thrustOffset = VectorTools.PointDistanceToLine(
- thrustPos, thrustDir.normalized, core.vessel.findLocalCenterOfMass());
+ thrustPos, thrustDir.normalized, Core.vessel.findLocalCenterOfMass());
Tools.PostDebugMessage(typeof(VOID_Data), "vesselThrustOffset:\n" +
"\tthrustPos: {0}\n" +
@@ -548,7 +574,7 @@
thrustPos,
thrustDir.normalized,
thrustOffset,
- core.vessel.findWorldCenterOfMass()
+ Core.vessel.findWorldCenterOfMass()
);
return thrustOffset;
@@ -571,7 +597,7 @@
currentAmount = 0d;
currentRequirement = 0d;
- foreach (Part part in core.vessel.Parts)
+ foreach (Part part in Core.vessel.Parts)
{
if (part.enabled)
{
@@ -630,9 +656,9 @@
"Crew Onboard",
delegate()
{
- if (core.vessel != null)
- {
- return core.vessel.GetCrewCount();
+ if (Core.vessel != null)
+ {
+ return Core.vessel.GetCrewCount();
}
else
{
@@ -647,9 +673,9 @@
"Crew Capacity",
delegate()
{
- if (core.vessel != null)
- {
- return core.vessel.GetCrewCapacity();
+ if (Core.vessel != null)
+ {
+ return Core.vessel.GetCrewCapacity();
}
else
{
@@ -665,24 +691,24 @@
#region Location
+ public const double kscLongitude = 285.442323427289 * Math.PI / 180d;
+ public const double kscLatitude = -0.0972112860655246 * Math.PI / 180d;
+
public static readonly VOID_DoubleValue downrangeDistance =
new VOID_DoubleValue(
"Downrange Distance",
delegate()
{
- if (core.vessel == null ||
+ if (Core.vessel == null ||
Planetarium.fetch == null ||
- core.vessel.mainBody != Planetarium.fetch.Home)
- {
- return double.NaN;
- }
-
- double vesselLongitude = core.vessel.longitude * Math.PI / 180d;
- double vesselLatitude = core.vessel.latitude * Math.PI / 180d;
-
- const double kscLongitude = 285.442323427289 * Math.PI / 180d;
- const double kscLatitude = -0.0972112860655246 * Math.PI / 180d;
+ Core.vessel.mainBody != Planetarium.fetch.Home)
+ {
+ return double.NaN;
+ }
+
+ double vesselLongitude = Core.vessel.longitude * Math.PI / 180d;
+ double vesselLatitude = Core.vessel.latitude * Math.PI / 180d;
double diffLon = vesselLongitude - kscLongitude;
double diffLat = vesselLatitude - kscLatitude;
@@ -699,7 +725,7 @@
double arc = 2d * Math.Atan2(Math.Sqrt(haversine), Math.Sqrt(1d - haversine));
- return core.vessel.mainBody.Radius * arc;
+ return Core.vessel.mainBody.Radius * arc;
},
"m"
);
@@ -707,13 +733,13 @@
public static readonly VOID_StrValue surfLatitude =
new VOID_StrValue(
"Latitude",
- new Func<string>(() => VOID_Tools.GetLatitudeString(core.vessel))
+ new Func<string>(() => VOID_Tools.GetLatitudeString(Core.vessel))
);
public static readonly VOID_StrValue surfLongitude =
new VOID_StrValue(
"Longitude",
- new Func<string>(() => VOID_Tools.GetLongitudeString(core.vessel))
+ new Func<string>(() => VOID_Tools.GetLongitudeString(Core.vessel))
);
public static readonly VOID_DoubleValue trueAltitude =
@@ -721,11 +747,11 @@
"Altitude (true)",
delegate()
{
- double alt_true = core.vessel.orbit.altitude - core.vessel.terrainAltitude;
+ double alt_true = Core.vessel.orbit.altitude - Core.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 (core.vessel.terrainAltitude < 0 && core.vessel.mainBody.ocean)
- alt_true = core.vessel.orbit.altitude;
+ if (Core.vessel.terrainAltitude < 0 && Core.vessel.mainBody.ocean)
+ alt_true = Core.vessel.orbit.altitude;
return alt_true;
},
"m"
@@ -738,28 +764,28 @@
public static readonly VOID_DoubleValue geeForce =
new VOID_DoubleValue(
"G-force",
- new Func<double>(() => core.vessel.geeForce),
+ new Func<double>(() => Core.vessel.geeForce),
"gees"
);
public static readonly VOID_DoubleValue horzVelocity =
new VOID_DoubleValue(
"Horizontal speed",
- new Func<double>(() => core.vessel.horizontalSrfSpeed),
+ new Func<double>(() => Core.vessel.horizontalSrfSpeed),
"m/s"
);
public static readonly VOID_DoubleValue surfVelocity =
new VOID_DoubleValue(
"Surface velocity",
- new Func<double>(() => core.vessel.srf_velocity.magnitude),
+ new Func<double>(() => Core.vessel.srf_velocity.magnitude),
"m/s"
);
public static readonly VOID_DoubleValue vertVelocity =
new VOID_DoubleValue(
"Vertical speed",
- new Func<double>(() => core.vessel.verticalSpeed),
+ new Func<double>(() => Core.vessel.verticalSpeed),
"m/s"
);
@@ -775,9 +801,9 @@
"Angular Velocity",
delegate()
{
- if (core.vessel != null)
- {
- return core.vessel.angularVelocity.magnitude;
+ if (Core.vessel != null)
+ {
+ return Core.vessel.angularVelocity.magnitude;
}
else
{
@@ -795,14 +821,14 @@
{
get
{
- if (core.vessel == null ||
- core.vessel.patchedConicSolver == null ||
- core.vessel.patchedConicSolver.maneuverNodes == null)
+ if (Core.vessel == null ||
+ Core.vessel.patchedConicSolver == null ||
+ Core.vessel.patchedConicSolver.maneuverNodes == null)
{
return 0;
}
- return core.vessel.patchedConicSolver.maneuverNodes.Count;
+ return Core.vessel.patchedConicSolver.maneuverNodes.Count;
}
}
@@ -811,12 +837,12 @@
"Full burn time to be half done at node",
delegate()
{
- if (core.LastStage == null && upcomingManeuverNodes < 1)
+ if (Core.LastStage == null && upcomingManeuverNodes < 1)
{
return "N/A";
}
- ManeuverNode node = core.vessel.patchedConicSolver.maneuverNodes[0];
+ ManeuverNode node = Core.vessel.patchedConicSolver.maneuverNodes[0];
if ((node.UT - Planetarium.GetUniversalTime()) < 0)
{
@@ -853,12 +879,12 @@
"Full burn time to be half done at node",
delegate()
{
- if (core.LastStage == null && upcomingManeuverNodes < 1)
+ if (Core.LastStage == null && upcomingManeuverNodes < 1)
{
return "N/A";
}
- ManeuverNode node = core.vessel.patchedConicSolver.maneuverNodes[0];
+ ManeuverNode node = Core.vessel.patchedConicSolver.maneuverNodes[0];
if ((node.UT - Planetarium.GetUniversalTime()) < 0)
{
@@ -897,7 +923,7 @@
{
if (upcomingManeuverNodes > 0)
{
- return core.vessel.patchedConicSolver.maneuverNodes[0].DeltaV.magnitude;
+ return Core.vessel.patchedConicSolver.maneuverNodes[0].DeltaV.magnitude;
}
else
{
@@ -914,7 +940,7 @@
{
if (upcomingManeuverNodes > 0)
{
- return core.vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(core.vessel.orbit).magnitude;
+ return Core.vessel.patchedConicSolver.maneuverNodes[0].GetBurnVector(Core.vessel.orbit).magnitude;
}
else
{
@@ -929,7 +955,7 @@
"Total Burn Time",
delegate()
{
- if (core.LastStage == null || currManeuverDeltaV.Value == double.NaN)
+ if (Core.LastStage == null || currManeuverDeltaV.Value == double.NaN)
{
return double.NaN;
}
@@ -946,7 +972,7 @@
"Burn Time Remaining",
delegate()
{
- if (core.LastStage == null || currManeuverDVRemaining == double.NaN)
+ if (Core.LastStage == null || currManeuverDVRemaining == double.NaN)
{
return double.NaN;
}
@@ -963,7 +989,7 @@
"Half Burn Time",
delegate()
{
- if (core.LastStage == null || currManeuverDeltaV.Value == double.NaN)
+ if (Core.LastStage == null || currManeuverDeltaV.Value == double.NaN)
{
return double.NaN;
}
@@ -982,7 +1008,7 @@
{
if (upcomingManeuverNodes > 1)
{
- return core.vessel.patchedConicSolver.maneuverNodes[1].DeltaV.magnitude;
+ return Core.vessel.patchedConicSolver.maneuverNodes[1].DeltaV.magnitude;
}
else
{
@@ -1001,58 +1027,58 @@
VOID_Localization.void_primary,
delegate()
{
- if (core.vessel == null)
+ if (Core.vessel == null)
{
return string.Empty;
}
- return core.vessel.mainBody.name;
+ return Core.vessel.mainBody.name;
}
);
public static readonly VOID_DoubleValue orbitAltitude =
new VOID_DoubleValue(
"Altitude (ASL)",
- new Func<double>(() => core.vessel.orbit.altitude),
+ new Func<double>(() => Core.vessel.orbit.altitude),
"m"
);
public static readonly VOID_DoubleValue orbitVelocity =
new VOID_DoubleValue(
VOID_Localization.void_velocity,
- new Func<double>(() => core.vessel.orbit.vel.magnitude),
+ new Func<double>(() => Core.vessel.orbit.vel.magnitude),
"m/s"
);
public static readonly VOID_DoubleValue orbitApoAlt =
new VOID_DoubleValue(
VOID_Localization.void_apoapsis,
- new Func<double>(() => core.vessel.orbit.ApA),
+ new Func<double>(() => Core.vessel.orbit.ApA),
"m"
);
public static readonly VOID_DoubleValue oribtPeriAlt =
new VOID_DoubleValue(
VOID_Localization.void_periapsis,
- new Func<double>(() => core.vessel.orbit.PeA),
+ new Func<double>(() => Core.vessel.orbit.PeA),
"m"
);
public static readonly VOID_StrValue timeToApo =
new VOID_StrValue(
"Time to Apoapsis",
- new Func<string>(() => VOID_Tools.FormatInterval(core.vessel.orbit.timeToAp))
+ new Func<string>(() => VOID_Tools.FormatInterval(Core.vessel.orbit.timeToAp))
);
public static readonly VOID_StrValue timeToPeri =
new VOID_StrValue(
"Time to Periapsis",
- new Func<string>(() => VOID_Tools.FormatInterval(core.vessel.orbit.timeToPe))
+ new Func<string>(() => VOID_Tools.FormatInterval(Core.vessel.orbit.timeToPe))
);
public static readonly VOID_DoubleValue orbitInclination =
new VOID_DoubleValue(
"Inclination",
- new Func<double>(() => core.vessel.orbit.inclination),
+ new Func<double>(() => Core.vessel.orbit.inclination),
"°"
);
@@ -1061,9 +1087,9 @@
"Gravity",
delegate()
{
- double orbitRadius = core.vessel.mainBody.Radius +
- core.vessel.mainBody.GetAltitude(core.vessel.findWorldCenterOfMass());
- return (VOID_Core.Constant_G * core.vessel.mainBody.Mass) /
+ double orbitRadius = Core.vessel.mainBody.Radius +
+ Core.vessel.mainBody.GetAltitude(Core.vessel.findWorldCenterOfMass());
+ return (VOIDCore.Constant_G * Core.vessel.mainBody.Mass) /
(orbitRadius * orbitRadius);
},
"m/s²"
@@ -1072,55 +1098,55 @@
public static readonly VOID_StrValue orbitPeriod =
new VOID_StrValue(
"Period",
- new Func<string>(() => VOID_Tools.FormatInterval(core.vessel.orbit.period))
+ new Func<string>(() => VOID_Tools.FormatInterval(Core.vessel.orbit.period))
);
public static readonly VOID_DoubleValue semiMajorAxis =
new VOID_DoubleValue(
"Semi-Major Axis",
- new Func<double>(() => core.vessel.orbit.semiMajorAxis),
+ new Func<double>(() => Core.vessel.orbit.semiMajorAxis),
"m"
);
public static readonly VOID_DoubleValue eccentricity =
new VOID_DoubleValue(
"Eccentricity",
- new Func<double>(() => core.vessel.orbit.eccentricity),
+ new Func<double>(() => Core.vessel.orbit.eccentricity),
""
);
public static readonly VOID_DoubleValue meanAnomaly =
new VOID_DoubleValue(
"Mean Anomaly",
- new Func<double>(() => core.vessel.orbit.meanAnomaly * 180d / Math.PI),
+ new Func<double>(() => Core.vessel.orbit.meanAnomaly * 180d / Math.PI),
"°"
);
public static readonly VOID_DoubleValue trueAnomaly =
new VOID_DoubleValue(
"True Anomaly",
- new Func<double>(() => core.vessel.orbit.trueAnomaly),
+ new Func<double>(() => Core.vessel.orbit.trueAnomaly),
"°"
);
public static readonly VOID_DoubleValue eccAnomaly =
new VOID_DoubleValue(
"Eccentric Anomaly",
- new Func<double>(() => core.vessel.orbit.eccentricAnomaly * 180d / Math.PI),
+ new Func<double>(() => Core.vessel.orbit.eccentricAnomaly * 180d / Math.PI),
"°"
);
public static readonly VOID_DoubleValue longitudeAscNode =
new VOID_DoubleValue(
"Long. Ascending Node",
- new Func<double>(() => core.vessel.orbit.LAN),
+ new Func<double>(() => Core.vessel.orbit.LAN),
"°"
);
public static readonly VOID_DoubleValue argumentPeriapsis =
new VOID_DoubleValue(
"Argument of Periapsis",
- new Func<double>(() => core.vessel.orbit.argumentOfPeriapsis),
+ new Func<double>(() => Core.vessel.orbit.argumentOfPeriapsis),
"°"
);
@@ -1128,7 +1154,7 @@
new VOID_DoubleValue(
"Local Sidereal Longitude",
new Func<double>(() => VOID_Tools.FixDegreeDomain(
- core.vessel.longitude + core.vessel.orbit.referenceBody.rotationAngle)),
+ Core.vessel.longitude + Core.vessel.orbit.referenceBody.rotationAngle)),
"°"
);
@@ -1139,13 +1165,13 @@
public static readonly VOID_StrValue expSituation =
new VOID_StrValue(
"Situation",
- new Func<string>(() => core.vessel.GetExperimentSituation().HumanString())
+ new Func<string>(() => Core.vessel.GetExperimentSituation().HumanString())
);
public static readonly VOID_StrValue currBiome =
new VOID_StrValue(
"Biome",
- new Func<string>(() => VOID_Tools.GetBiome(core.vessel).name)
+ new Func<string>(() => VOID_Tools.GetBiome(Core.vessel).name)
);
#endregion
@@ -1155,7 +1181,7 @@
public static readonly VOID_DoubleValue terrainElevation =
new VOID_DoubleValue(
"Terrain elevation",
- new Func<double>(() => core.vessel.terrainAltitude),
+ new Func<double>(() => Core.vessel.terrainAltitude),
"m"
);
@@ -1178,4 +1204,3 @@
}
}
-
--- a/VOID_DataLogger.cs
+++ b/VOID_DataLogger.cs
@@ -101,7 +101,7 @@
if (this._fileName == null || this._fileName == string.Empty)
{
this._fileName = KSP.IO.IOUtils.GetFilePathFor(
- typeof(VOID_Core),
+ typeof(VOIDCore),
string.Format(
"{0}_{1}",
this.vessel.vesselName,
--- a/VOID_DataValue.cs
+++ b/VOID_DataValue.cs
@@ -83,8 +83,8 @@
{
if (
HighLogic.LoadedSceneIsEditor ||
- (VOID_Core.Instance.updateTimer - this.lastUpdate > VOID_Core.Instance.updatePeriod) ||
- (this.lastUpdate > VOID_Core.Instance.updateTimer)
+ (VOID_Data.Core.updateTimer - this.lastUpdate > VOID_Data.Core.updatePeriod) ||
+ (this.lastUpdate > VOID_Data.Core.updateTimer)
)
{
this.Refresh();
@@ -109,7 +109,7 @@
public void Refresh()
{
this.cache = this.ValueFunc.Invoke ();
- this.lastUpdate = VOID_Core.Instance.updateTimer;
+ this.lastUpdate = VOID_Data.Core.updateTimer;
}
public T GetFreshValue()
--- a/VOID_EditorCore.cs
+++ /dev/null
@@ -1,156 +1,1 @@
-// VOID
-//
-// VOID_EditorCore.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.Linq;
-using ToadicusTools;
-using UnityEngine;
-
-namespace VOID
-{
- public class VOID_EditorCore : VOID_Core
- {
- /*
- * Static Members
- * */
- protected new static bool _initialized = false;
- public new static bool Initialized
- {
- get
- {
- return _initialized;
- }
- }
-
- protected new static VOID_EditorCore _instance;
- public new static VOID_EditorCore Instance
- {
- get
- {
- if (_instance == null)
- {
- _instance = new VOID_EditorCore();
- _initialized = true;
- }
- return _instance;
- }
- }
-
- public new static void Reset()
- {
- if (_initialized)
- {
- _instance.StopGUI();
- _instance.Dispose();
- _instance = null;
- _initialized = false;
- }
- }
-
- protected override ApplicationLauncher.AppScenes appIconVisibleScenes
- {
- get
- {
- return ApplicationLauncher.AppScenes.VAB | ApplicationLauncher.AppScenes.SPH;
- }
- }
-
- public VOID_EditorCore() : base()
- {
- this._Name = "VOID Editor Core";
- }
-
- public override void OnGUI() {}
-
- public override void DrawGUI()
- {
- if (!this._modulesLoaded)
- {
- this.LoadModulesOfType<IVOID_EditorModule>();
- }
-
- Rect _iconPos = Tools.DockToWindow (this.VOIDIconPos, this.mainWindowPos);
-
- _iconPos = Tools.ClampRectToEditorPad (_iconPos);
-
- if (_iconPos != this.VOIDIconPos)
- {
- this.VOIDIconPos = _iconPos;
- }
-
- base.DrawGUI();
- }
-
- public override void Update()
- {
- this.LoadBeforeUpdate();
-
- foreach (IVOID_EditorModule 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 ();
- }
-
- public override void FixedUpdate() {}
- }
-}
-
-
--- a/VOID_EditorHUD.cs
+++ b/VOID_EditorHUD.cs
@@ -37,7 +37,8 @@
namespace VOID
{
- public class VOID_EditorHUD : VOID_HUDModule, IVOID_EditorModule
+ [VOID_Scenes(GameScenes.EDITOR)]
+ public class VOID_EditorHUD : VOID_HUDModule
{
/*
* Fields
--- a/VOID_HUDAdvanced.cs
+++ b/VOID_HUDAdvanced.cs
@@ -241,11 +241,22 @@
}
}
+ if (VOID_Data.upcomingManeuverNodes < 1 && this.Windows.Contains(this.rightHUD))
+ {
+ this.Windows.Remove(this.rightHUD);
+ }
+ else if (VOID_Data.upcomingManeuverNodes > 0 && !this.Windows.Contains(this.rightHUD))
+ {
+ this.Windows.Add(this.rightHUD);
+ }
+
base.DrawGUI();
}
public override void DrawConfigurables()
{
+ base.DrawConfigurables();
+
if (GUILayout.Button(string.Intern("Reset Advanced HUD Positions"), GUILayout.ExpandWidth(false)))
{
foreach (HUDWindow window in this.Windows)
--- a/VOID_HUDModule.cs
+++ b/VOID_HUDModule.cs
@@ -118,6 +118,8 @@
public override void DrawConfigurables()
{
+ base.DrawConfigurables();
+
if (GUILayout.Button (string.Intern("Change HUD color"), GUILayout.ExpandWidth (false)))
{
++this.ColorIndex;
@@ -140,7 +142,7 @@
{
base.LoadConfig();
- var config = KSP.IO.PluginConfiguration.CreateForType<VOID_Core>();
+ var config = KSP.IO.PluginConfiguration.CreateForType<VOID_HUDModule>();
config.load();
foreach (HUDWindow window in this.Windows)
@@ -188,9 +190,9 @@
{
this._windowPos = value;
- if (VOID_Data.core != null)
+ if (VOID_Data.Core != null)
{
- VOID_Data.core.configDirty = true;
+ VOID_Data.Core.configDirty = true;
}
}
}
--- a/VOID_Module.cs
+++ b/VOID_Module.cs
@@ -42,7 +42,7 @@
* */
[AVOID_SaveValue("Active")]
protected VOID_SaveValue<bool> _Active = false;
- protected bool _Running = false;
+ private GameScenes[] validScenes;
protected string _Name;
@@ -51,16 +51,11 @@
/*
* Properties
* */
- protected virtual VOID_Core core
- {
- get
- {
- if (HighLogic.LoadedSceneIsEditor)
- {
- return VOID_EditorCore.Instance as VOID_Core;
- }
-
- return VOID_Core.Instance;
+ protected virtual VOIDCore core
+ {
+ get
+ {
+ return VOID_Data.Core;
}
}
@@ -80,7 +75,54 @@
{
get
{
- return this._Running;
+ 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);
}
}
@@ -112,7 +154,6 @@
Tools.PostDebugMessage (string.Format("Adding {0} to the draw queue.", this.GetType().Name));
RenderingManager.AddToPostDrawQueue (3, this.DrawGUI);
- this._Running = true;
}
public void StopGUI()
@@ -123,7 +164,6 @@
}
Tools.PostDebugMessage (string.Format("Removing {0} from the draw queue.", this.GetType().Name));
RenderingManager.RemoveFromPostDrawQueue (3, this.DrawGUI);
- this._Running = false;
}
public abstract void DrawGUI();
@@ -132,7 +172,7 @@
public virtual void LoadConfig()
{
- var config = KSP.IO.PluginConfiguration.CreateForType<VOID_Core> ();
+ var config = KSP.IO.PluginConfiguration.CreateForType<VOID_Module> ();
config.load ();
foreach (var field in this.GetType().GetFields(
--- a/VOID_SaveValue.cs
+++ b/VOID_SaveValue.cs
@@ -39,25 +39,11 @@
private T _value;
private Type _type;
- private VOID_Core Core
+ private VOIDCore Core
{
get
{
- if (HighLogic.LoadedSceneIsEditor)
- {
- if (VOID_EditorCore.Initialized)
- {
- return VOID_EditorCore.Instance;
- }
- }
- else if (HighLogic.LoadedSceneIsFlight)
- {
- if (VOID_Core.Initialized)
- {
- return VOID_Core.Instance;
- }
- }
- return null;
+ return VOID_Data.Core;
}
}
--- /dev/null
+++ b/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/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/VOID_StageInfo.cs
+++ b/VOID_StageInfo.cs
@@ -13,6 +13,7 @@
namespace VOID
{
+ [VOID_Scenes(GameScenes.EDITOR, GameScenes.FLIGHT)]
public class VOID_StageInfo : VOID_WindowModule
{
private Table stageTable;
@@ -211,8 +212,6 @@
}
}
}
-
- public class VOID_StageInfoEditor : VOID_StageInfo, IVOID_EditorModule {}
}
--- a/VOID_TWR.cs
+++ b/VOID_TWR.cs
@@ -12,6 +12,7 @@
namespace VOID
{
+ [VOID_Scenes(GameScenes.EDITOR, GameScenes.FLIGHT)]
public class VOID_TWR : VOID_WindowModule
{
public VOID_TWR() : base()
@@ -62,8 +63,6 @@
GUI.DragWindow();
}
}
-
- public class VOID_EditorTWR : VOID_TWR, IVOID_EditorModule {}
}