Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 3 additions & 24 deletions MicroEngineerProject/MicroEngineer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,31 +9,10 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BepInEx.BaseLib" Version="5.4.21" Publicize="true" />
<Reference Include="external_dlls\SpaceWarp.dll" />
<Reference Include="external_dlls\UnityEngine.dll" />
<Reference Include="external_dlls\UnityEngine.CoreModule.dll" />
<Reference Include="external_dlls\Assembly-CSharp.dll" />
<Reference Include="external_dlls\NewtonSoft.Json.dll" />
<Reference Include="UitkForKsp2">
<HintPath>external_dlls\UitkForKsp2.dll</HintPath>
</Reference>
<Reference Include="UitkForKsp2.Controls">
<HintPath>external_dlls\UitkForKsp2.Controls.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.IMGUIModule">
<HintPath>external_dlls\UnityEngine.IMGUIModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.InputLegacyModule">
<HintPath>external_dlls\UnityEngine.InputLegacyModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.TextRenderingModule">
<HintPath>external_dlls\UnityEngine.TextRenderingModule.dll</HintPath>
</Reference>
<Reference Include="UnityEngine.UIElementsModule">
<HintPath>external_dlls\UnityEngine.UIElementsModule.dll</HintPath>
</Reference>
<PackageReference Include="SpaceWarp" Version="1.4.0"/>
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.1.3" PrivateAssets="all"/>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="echo Killing task KSP2_x64.exe&#xD;&#xA;taskkill /f /fi &quot;pid gt 0&quot; /im KSP2_x64.exe&#xD;&#xA;&#xD;&#xA;echo Copying output .dll to &quot;..Kerbal Space Program 2 0.1.3.1 DEV\BepInEx\plugins\micro_engineer\&quot;&#xD;&#xA;xcopy /y &quot;$(TargetDir)$(ProjectName).dll&quot; &quot;D:\Steam\steamapps\common\Kerbal Space Program 2 0.1.3.1 DEV\BepInEx\plugins\micro_engineer\&quot;&#xD;&#xA;&#xD;&#xA;echo Copying output .pdb to &quot;..Kerbal Space Program 2 0.1.3.1 DEV\BepInEx\plugins\micro_engineer\&quot;&#xD;&#xA;xcopy /y &quot;$(TargetDir)$(ProjectName).pdb&quot; &quot;D:\Steam\steamapps\common\Kerbal Space Program 2 0.1.3.1 DEV\BepInEx\plugins\micro_engineer\&quot;&#xD;&#xA;&#xD;&#xA;echo Starting KSP2_x64.exe&#xD;&#xA;powershell &quot;start-process &quot;&quot;D:\Steam\steamapps\common\Kerbal Space Program 2 0.1.3.1 DEV\KSP2_x64.exe&quot;&quot;&quot;" />
<Exec Command="echo Killing task KSP2_x64.exe&#xD;&#xA;taskkill /f /fi &quot;pid gt 0&quot; /im KSP2_x64.exe&#xD;&#xA;&#xD;&#xA;echo Copying output .dll&#xD;&#xA;xcopy /y &quot;$(TargetDir)$(ProjectName).dll&quot; &quot;$(KSP2DIR)\BepInEx\plugins\micro_engineer\&quot;&#xD;&#xA;&#xD;&#xA;echo Copying output .pdb&#xD;&#xA;xcopy /y &quot;$(TargetDir)$(ProjectName).pdb&quot; &quot;$(KSP2DIR)\BepInEx\plugins\micro_engineer\&quot;&#xD;&#xA;&#xD;&#xA;echo Starting KSP2_x64.exe&#xD;&#xA;powershell &quot;start-process &quot;&quot;$(KSP2DIR)\KSP2_x64.exe&quot;&quot;&quot;" />
</Target>
</Project>
4 changes: 2 additions & 2 deletions MicroEngineerProject/MicroEngineer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Global
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Debug|Any CPU.ActiveCfg = Release|Any CPU
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Debug|Any CPU.Build.0 = Release|Any CPU
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
26 changes: 23 additions & 3 deletions MicroEngineerProject/MicroEngineer/Entries/BaseEntry.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BepInEx.Logging;
using Newtonsoft.Json;
using Newtonsoft.Json;

namespace MicroMod
{
Expand Down Expand Up @@ -31,6 +30,8 @@ public class BaseEntry
[JsonProperty]
public string GigaUnit;
[JsonProperty]
public AltUnit AltUnit;
[JsonProperty]
public byte NumberOfDecimalDigits;
[JsonProperty("Formatting")]
private string _formatting;
Expand Down Expand Up @@ -101,6 +102,12 @@ public virtual string ValueDisplay
if (!double.TryParse(EntryValue.ToString(), out double d))
return EntryValue.ToString(); // This case shouldn't exist, but just to be sure

if (AltUnit != null && AltUnit.IsActive)
{
return !string.IsNullOrEmpty(Formatting) ? String.Format(Formatting, d * AltUnit.Factor) :
(d * AltUnit.Factor).ToString();
}

if (Math.Abs(d) < 1) // mili
{
return !String.IsNullOrEmpty(this.MiliUnit) ? String.Format(Formatting, d * 1000) :
Expand Down Expand Up @@ -146,6 +153,9 @@ public virtual string UnitDisplay
if (!double.TryParse(EntryValue.ToString(), out double d))
return this.BaseUnit ?? ""; // This case shouldn't exist, but just to be sure

if (AltUnit != null && AltUnit.IsActive)
return AltUnit.Unit;

if (d > 0.001 && d < 1) // mili
{
return this.MiliUnit ?? this.BaseUnit ?? "";
Expand All @@ -172,5 +182,15 @@ public virtual string UnitDisplay
}

public virtual void RefreshData() { }
}
}

public class AltUnit
{
[JsonProperty]
public bool IsActive;
[JsonProperty]
public string Unit;
[JsonProperty]
public float Factor;
}
}
12 changes: 12 additions & 0 deletions MicroEngineerProject/MicroEngineer/Entries/FlightEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ public Speed()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 2;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand Down Expand Up @@ -400,6 +406,12 @@ public SoundSpeed()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 2;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using BepInEx.Logging;
using KSP.Game;
using KSP.Game;
using KSP.Sim.DeltaV;
using KSP.Sim.impl;

Expand All @@ -16,7 +15,7 @@ public TotalBurnTime_OAB()
{
Name = "Total burn time (OAB)";
Description = "Shows the total length of burn the vessel can mantain.";
EntryType = EntryType.Time;
EntryType = EntryType.Time;
Category = MicroEntryCategory.OAB;
IsDefault = true;
BaseUnit = "s";
Expand Down Expand Up @@ -105,7 +104,7 @@ public override void RefreshData()

/// <summary>
/// Calculates torque from the Center of Thrust and Center of Mass
/// </summary>
/// </summary>
public class Torque : OabStageInfoEntry
{
public Torque()
Expand Down Expand Up @@ -188,7 +187,7 @@ public override void RefreshData()

if (Utility.VesselDeltaVComponentOAB?.StageInfo == null) return;

for (int i = 0; i < Utility.VesselDeltaVComponentOAB.StageInfo.Count; i++)
for (int i = 0; i < Utility.VesselDeltaVComponentOAB.StageInfo.Count; i++)
{
var retrieved = Utility.VesselDeltaVComponentOAB.StageInfo[i];
var stage = new DeltaVStageInfo_OAB()
Expand Down
6 changes: 6 additions & 0 deletions MicroEngineerProject/MicroEngineer/Entries/OrbitalEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,12 @@ public OrbitalSpeed()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 1;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand Down
12 changes: 12 additions & 0 deletions MicroEngineerProject/MicroEngineer/Entries/SurfaceEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,12 @@ public VerticalVelocity()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 1;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand All @@ -124,6 +130,12 @@ public HorizontalVelocity()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 1;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand Down
24 changes: 24 additions & 0 deletions MicroEngineerProject/MicroEngineer/Entries/TargetEntries.cs
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ public RelativeSpeed()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 1;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand Down Expand Up @@ -284,6 +290,12 @@ public Target_Obtvelocity()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 1;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand Down Expand Up @@ -700,6 +712,12 @@ public RelativeSpeedAtCloseApproach1()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 1;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand Down Expand Up @@ -778,6 +796,12 @@ public RelativeSpeedAtCloseApproach2()
GigaUnit = "Gm/s";
NumberOfDecimalDigits = 1;
Formatting = "N";
AltUnit = new AltUnit()
{
IsActive = false,
Unit = "km/h",
Factor = (60f * 60f) / 1000f
};
}

public override void RefreshData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,13 @@ private void GameStateEntered(MessageCenterMessage obj)
}

private void GameStateLeft(MessageCenterMessage obj)
{
{
Utility.RefreshGameManager();
var maingui = Manager.Instance.Windows.OfType<MainGuiWindow>().FirstOrDefault();
var stageOab = Manager.Instance.Windows.OfType<StageInfoOabWindow>().FirstOrDefault();

if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.VehicleAssemblyBuilder || Utility.GameState.GameState == GameState.Map3DView)
{
_logger.LogDebug($"Initiating Save from GameStateLeft.");
Utility.SaveLayout();

if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.Map3DView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ public static MicroCelestialBodies Instance

public MicroCelestialBodies()
{
_logger.LogDebug("Instantiating singleton.");
InitializeBodies();
}

Expand Down Expand Up @@ -104,7 +103,7 @@ private void TryReorderBodies()
/// <returns></returns>
private List<CelestialBody> InstantiateCelestialBodies (CelestialBodyComponent cel, int level)
{
List<CelestialBody> instantiatedBodies = new();
List<CelestialBody> instantiatedBodies = new();
instantiatedBodies.Add(InstantiateCelestialBody(cel, level));

foreach (CelestialBodyComponent body in cel.orbitingBodies)
Expand Down
8 changes: 2 additions & 6 deletions MicroEngineerProject/MicroEngineer/MicroEngineerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@
using SpaceWarp.API.UI.Appbar;
using MicroEngineer.UI;
using KSP.Game;
using BepInEx.Logging;

namespace MicroMod
{
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.2.0")]
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.3.0")]
[BepInDependency(SpaceWarpPlugin.ModGuid, SpaceWarpPlugin.ModVer)]
public class MicroEngineerMod : BaseSpaceWarpPlugin
{
private static readonly ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("MicroEngineerMod");
public static MicroEngineerMod Instance { get; set; }
public string GUID;

Expand All @@ -36,7 +34,6 @@ public override void OnInitialized()
if (isOpen)
Manager.Instance.Windows.Find(w => w.GetType() == typeof(MainGuiWindow)).IsFlightActive = isOpen;
FlightSceneController.Instance.ShowGui = isOpen;
_logger.LogDebug($"Initiating Save from Appbar.RegisterAppButton.");
Utility.SaveLayout();
});

Expand All @@ -49,7 +46,6 @@ public override void OnInitialized()
if (isOpen)
Manager.Instance.Windows.Find(w => w.GetType() == typeof(StageInfoOabWindow)).IsEditorActive = isOpen;
OABSceneController.Instance.ShowGui = isOpen;
_logger.LogDebug($"Initiating Save from Appbar.RegisterOABAppButton.");
Utility.SaveLayout();
});
}
Expand All @@ -66,7 +62,7 @@ public void Update()
bool guiState = FlightSceneController.Instance.ShowGui;
FlightSceneController.Instance.ShowGui = !guiState;
Manager.Instance.Windows.Find(w => w.GetType() == typeof(MainGuiWindow)).IsFlightActive = !guiState;
}
}
else if (Utility.GameState.GameState == GameState.VehicleAssemblyBuilder)
{
bool guiState = OABSceneController.Instance.ShowGui;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
using BepInEx.Logging;
using MicroMod;
using MicroMod;
using UnityEngine;
using UnityEngine.UIElements;

namespace MicroEngineer.UI
{
public class EditWindowsController : MonoBehaviour
{
private static readonly ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("MicroEngineer.EditWindowsController");

private EditWindowsItemControl _selectedAvailableEntry;
private EditWindowsItemControl _selectedInstalledEntry;
private List<EntryWindow> _editableWindows;
Expand All @@ -22,7 +19,7 @@ public class EditWindowsController : MonoBehaviour
public Button CloseButton { get; set; }
public ScrollView AvailableScrollView { get; set; }
public ScrollView InstalledScrollView { get; set; }
public DropdownField CategoryDropdown { get; set; }
public DropdownField CategoryDropdown { get; set; }
public TextField SelectedWindow { get; set; }
public Button PreviousWindow { get; set; }
public Button NextWindow { get; set; }
Expand All @@ -47,7 +44,6 @@ private System.Collections.IEnumerator StartInitialization()
// wait for 1 frame until SelectedWindowId is set in FlightSceneController
yield return null;

_logger.LogDebug("Entering OnEnable.");
EditWindows = GetComponent<UIDocument>();
Root = EditWindows.rootVisualElement;

Expand Down Expand Up @@ -94,7 +90,7 @@ private void BuildCategoryDropdown()
{
CategoryDropdown.choices = Enum.GetNames(typeof(MicroEntryCategory)).Where(e => e != MicroEntryCategory.OAB.ToString()).ToList();
CategoryDropdown.RegisterValueChangedCallback(BuildAvailableEntries);
}
}

private void BuildAvailableEntries(ChangeEvent<string> _)
{
Expand Down Expand Up @@ -159,7 +155,7 @@ public void UnselectAvailable(EditWindowsItemControl control)
AddEntry.SetEnabled(false);
}

////////////////////// INSTALLED (RIGHT SCROLLVIEW) //////////////////////
////////////////////// INSTALLED (RIGHT SCROLLVIEW) //////////////////////

public void ResetSelectedWindow()
{
Expand Down Expand Up @@ -374,7 +370,6 @@ private void CheckIfDecimalButtonsShouldBeEnabled(BaseEntry entry, Button increa

private void RebuildFlightUI()
{
_logger.LogDebug($"Initiating Save from RebuildFlightUI.");
Utility.SaveLayout();
FlightSceneController.Instance.RebuildUI();
}
Expand Down
Loading