Skip to content
This repository was archived by the owner on Feb 28, 2025. It is now read-only.

Commit d2e8cc2

Browse files
authored
Merge pull request #32 from Falki-git/dev
Doble-clicking a speed entry changes to an alternate unit (km/h)
2 parents 34503ce + c49bc29 commit d2e8cc2

24 files changed

+145
-119
lines changed

MicroEngineerProject/MicroEngineer.csproj

Lines changed: 3 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,10 @@
99
</PropertyGroup>
1010
<ItemGroup>
1111
<PackageReference Include="BepInEx.BaseLib" Version="5.4.21" Publicize="true" />
12-
<Reference Include="external_dlls\SpaceWarp.dll" />
13-
<Reference Include="external_dlls\UnityEngine.dll" />
14-
<Reference Include="external_dlls\UnityEngine.CoreModule.dll" />
15-
<Reference Include="external_dlls\Assembly-CSharp.dll" />
16-
<Reference Include="external_dlls\NewtonSoft.Json.dll" />
17-
<Reference Include="UitkForKsp2">
18-
<HintPath>external_dlls\UitkForKsp2.dll</HintPath>
19-
</Reference>
20-
<Reference Include="UitkForKsp2.Controls">
21-
<HintPath>external_dlls\UitkForKsp2.Controls.dll</HintPath>
22-
</Reference>
23-
<Reference Include="UnityEngine.IMGUIModule">
24-
<HintPath>external_dlls\UnityEngine.IMGUIModule.dll</HintPath>
25-
</Reference>
26-
<Reference Include="UnityEngine.InputLegacyModule">
27-
<HintPath>external_dlls\UnityEngine.InputLegacyModule.dll</HintPath>
28-
</Reference>
29-
<Reference Include="UnityEngine.TextRenderingModule">
30-
<HintPath>external_dlls\UnityEngine.TextRenderingModule.dll</HintPath>
31-
</Reference>
32-
<Reference Include="UnityEngine.UIElementsModule">
33-
<HintPath>external_dlls\UnityEngine.UIElementsModule.dll</HintPath>
34-
</Reference>
12+
<PackageReference Include="SpaceWarp" Version="1.4.0"/>
13+
<PackageReference Include="KerbalSpaceProgram2.GameLibs" Version="0.1.3" PrivateAssets="all"/>
3514
</ItemGroup>
3615
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
37-
<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;" />
16+
<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;" />
3817
</Target>
3918
</Project>

MicroEngineerProject/MicroEngineer.sln

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,8 @@ Global
1111
Release|Any CPU = Release|Any CPU
1212
EndGlobalSection
1313
GlobalSection(ProjectConfigurationPlatforms) = postSolution
14-
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Debug|Any CPU.ActiveCfg = Release|Any CPU
15-
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Debug|Any CPU.Build.0 = Release|Any CPU
14+
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15+
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Debug|Any CPU.Build.0 = Debug|Any CPU
1616
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Release|Any CPU.ActiveCfg = Release|Any CPU
1717
{2CD77478-E170-4D5C-91CA-0ABB24A30E5A}.Release|Any CPU.Build.0 = Release|Any CPU
1818
EndGlobalSection

MicroEngineerProject/MicroEngineer/Entries/BaseEntry.cs

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using BepInEx.Logging;
2-
using Newtonsoft.Json;
1+
using Newtonsoft.Json;
32

43
namespace MicroMod
54
{
@@ -31,6 +30,8 @@ public class BaseEntry
3130
[JsonProperty]
3231
public string GigaUnit;
3332
[JsonProperty]
33+
public AltUnit AltUnit;
34+
[JsonProperty]
3435
public byte NumberOfDecimalDigits;
3536
[JsonProperty("Formatting")]
3637
private string _formatting;
@@ -101,6 +102,12 @@ public virtual string ValueDisplay
101102
if (!double.TryParse(EntryValue.ToString(), out double d))
102103
return EntryValue.ToString(); // This case shouldn't exist, but just to be sure
103104

105+
if (AltUnit != null && AltUnit.IsActive)
106+
{
107+
return !string.IsNullOrEmpty(Formatting) ? String.Format(Formatting, d * AltUnit.Factor) :
108+
(d * AltUnit.Factor).ToString();
109+
}
110+
104111
if (Math.Abs(d) < 1) // mili
105112
{
106113
return !String.IsNullOrEmpty(this.MiliUnit) ? String.Format(Formatting, d * 1000) :
@@ -146,6 +153,9 @@ public virtual string UnitDisplay
146153
if (!double.TryParse(EntryValue.ToString(), out double d))
147154
return this.BaseUnit ?? ""; // This case shouldn't exist, but just to be sure
148155

156+
if (AltUnit != null && AltUnit.IsActive)
157+
return AltUnit.Unit;
158+
149159
if (d > 0.001 && d < 1) // mili
150160
{
151161
return this.MiliUnit ?? this.BaseUnit ?? "";
@@ -172,5 +182,15 @@ public virtual string UnitDisplay
172182
}
173183

174184
public virtual void RefreshData() { }
175-
}
185+
}
186+
187+
public class AltUnit
188+
{
189+
[JsonProperty]
190+
public bool IsActive;
191+
[JsonProperty]
192+
public string Unit;
193+
[JsonProperty]
194+
public float Factor;
195+
}
176196
}

MicroEngineerProject/MicroEngineer/Entries/FlightEntries.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,12 @@ public Speed()
1818
GigaUnit = "Gm/s";
1919
NumberOfDecimalDigits = 2;
2020
Formatting = "N";
21+
AltUnit = new AltUnit()
22+
{
23+
IsActive = false,
24+
Unit = "km/h",
25+
Factor = (60f * 60f) / 1000f
26+
};
2127
}
2228

2329
public override void RefreshData()
@@ -400,6 +406,12 @@ public SoundSpeed()
400406
GigaUnit = "Gm/s";
401407
NumberOfDecimalDigits = 2;
402408
Formatting = "N";
409+
AltUnit = new AltUnit()
410+
{
411+
IsActive = false,
412+
Unit = "km/h",
413+
Factor = (60f * 60f) / 1000f
414+
};
403415
}
404416

405417
public override void RefreshData()

MicroEngineerProject/MicroEngineer/Entries/OabStageInfoEntries.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using BepInEx.Logging;
2-
using KSP.Game;
1+
using KSP.Game;
32
using KSP.Sim.DeltaV;
43
using KSP.Sim.impl;
54

@@ -16,7 +15,7 @@ public TotalBurnTime_OAB()
1615
{
1716
Name = "Total burn time (OAB)";
1817
Description = "Shows the total length of burn the vessel can mantain.";
19-
EntryType = EntryType.Time;
18+
EntryType = EntryType.Time;
2019
Category = MicroEntryCategory.OAB;
2120
IsDefault = true;
2221
BaseUnit = "s";
@@ -105,7 +104,7 @@ public override void RefreshData()
105104

106105
/// <summary>
107106
/// Calculates torque from the Center of Thrust and Center of Mass
108-
/// </summary>
107+
/// </summary>
109108
public class Torque : OabStageInfoEntry
110109
{
111110
public Torque()
@@ -188,7 +187,7 @@ public override void RefreshData()
188187

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

191-
for (int i = 0; i < Utility.VesselDeltaVComponentOAB.StageInfo.Count; i++)
190+
for (int i = 0; i < Utility.VesselDeltaVComponentOAB.StageInfo.Count; i++)
192191
{
193192
var retrieved = Utility.VesselDeltaVComponentOAB.StageInfo[i];
194193
var stage = new DeltaVStageInfo_OAB()

MicroEngineerProject/MicroEngineer/Entries/OrbitalEntries.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@ public OrbitalSpeed()
170170
GigaUnit = "Gm/s";
171171
NumberOfDecimalDigits = 1;
172172
Formatting = "N";
173+
AltUnit = new AltUnit()
174+
{
175+
IsActive = false,
176+
Unit = "km/h",
177+
Factor = (60f * 60f) / 1000f
178+
};
173179
}
174180

175181
public override void RefreshData()

MicroEngineerProject/MicroEngineer/Entries/SurfaceEntries.cs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,12 @@ public VerticalVelocity()
9999
GigaUnit = "Gm/s";
100100
NumberOfDecimalDigits = 1;
101101
Formatting = "N";
102+
AltUnit = new AltUnit()
103+
{
104+
IsActive = false,
105+
Unit = "km/h",
106+
Factor = (60f * 60f) / 1000f
107+
};
102108
}
103109

104110
public override void RefreshData()
@@ -124,6 +130,12 @@ public HorizontalVelocity()
124130
GigaUnit = "Gm/s";
125131
NumberOfDecimalDigits = 1;
126132
Formatting = "N";
133+
AltUnit = new AltUnit()
134+
{
135+
IsActive = false,
136+
Unit = "km/h",
137+
Factor = (60f * 60f) / 1000f
138+
};
127139
}
128140

129141
public override void RefreshData()

MicroEngineerProject/MicroEngineer/Entries/TargetEntries.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,12 @@ public RelativeSpeed()
126126
GigaUnit = "Gm/s";
127127
NumberOfDecimalDigits = 1;
128128
Formatting = "N";
129+
AltUnit = new AltUnit()
130+
{
131+
IsActive = false,
132+
Unit = "km/h",
133+
Factor = (60f * 60f) / 1000f
134+
};
129135
}
130136

131137
public override void RefreshData()
@@ -284,6 +290,12 @@ public Target_Obtvelocity()
284290
GigaUnit = "Gm/s";
285291
NumberOfDecimalDigits = 1;
286292
Formatting = "N";
293+
AltUnit = new AltUnit()
294+
{
295+
IsActive = false,
296+
Unit = "km/h",
297+
Factor = (60f * 60f) / 1000f
298+
};
287299
}
288300

289301
public override void RefreshData()
@@ -700,6 +712,12 @@ public RelativeSpeedAtCloseApproach1()
700712
GigaUnit = "Gm/s";
701713
NumberOfDecimalDigits = 1;
702714
Formatting = "N";
715+
AltUnit = new AltUnit()
716+
{
717+
IsActive = false,
718+
Unit = "km/h",
719+
Factor = (60f * 60f) / 1000f
720+
};
703721
}
704722

705723
public override void RefreshData()
@@ -778,6 +796,12 @@ public RelativeSpeedAtCloseApproach2()
778796
GigaUnit = "Gm/s";
779797
NumberOfDecimalDigits = 1;
780798
Formatting = "N";
799+
AltUnit = new AltUnit()
800+
{
801+
IsActive = false,
802+
Unit = "km/h",
803+
Factor = (60f * 60f) / 1000f
804+
};
781805
}
782806

783807
public override void RefreshData()

MicroEngineerProject/MicroEngineer/Managers/MessageManager.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,14 +92,13 @@ private void GameStateEntered(MessageCenterMessage obj)
9292
}
9393

9494
private void GameStateLeft(MessageCenterMessage obj)
95-
{
95+
{
9696
Utility.RefreshGameManager();
9797
var maingui = Manager.Instance.Windows.OfType<MainGuiWindow>().FirstOrDefault();
9898
var stageOab = Manager.Instance.Windows.OfType<StageInfoOabWindow>().FirstOrDefault();
9999

100100
if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.VehicleAssemblyBuilder || Utility.GameState.GameState == GameState.Map3DView)
101101
{
102-
_logger.LogDebug($"Initiating Save from GameStateLeft.");
103102
Utility.SaveLayout();
104103

105104
if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.Map3DView)

MicroEngineerProject/MicroEngineer/Managers/MicroCelestialBodies.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public static MicroCelestialBodies Instance
2424

2525
public MicroCelestialBodies()
2626
{
27-
_logger.LogDebug("Instantiating singleton.");
2827
InitializeBodies();
2928
}
3029

@@ -104,7 +103,7 @@ private void TryReorderBodies()
104103
/// <returns></returns>
105104
private List<CelestialBody> InstantiateCelestialBodies (CelestialBodyComponent cel, int level)
106105
{
107-
List<CelestialBody> instantiatedBodies = new();
106+
List<CelestialBody> instantiatedBodies = new();
108107
instantiatedBodies.Add(InstantiateCelestialBody(cel, level));
109108

110109
foreach (CelestialBodyComponent body in cel.orbitingBodies)

0 commit comments

Comments
 (0)