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

Commit bc1f1d4

Browse files
committed
Add alternate units to speed entries
1 parent 526d83e commit bc1f1d4

File tree

10 files changed

+101
-12
lines changed

10 files changed

+101
-12
lines changed

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/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/MicroEngineerMod.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
namespace MicroMod
1212
{
13-
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.2.0")]
13+
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.3.0")]
1414
[BepInDependency(SpaceWarpPlugin.ModGuid, SpaceWarpPlugin.ModVer)]
1515
public class MicroEngineerMod : BaseSpaceWarpPlugin
1616
{

MicroEngineerProject/MicroEngineer/UI/Controls/BaseEntryControl.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using MicroMod;
2+
using UnityEngine;
23
using UnityEngine.UIElements;
34

45
namespace MicroEngineer.UI
@@ -11,6 +12,8 @@ public class BaseEntryControl : VisualElement
1112
public static string UssValueClassName = UssClassName + "__value";
1213
public static string UssUnitClassName = UssClassName + "__unit";
1314

15+
private float _timeOfLastClick;
16+
1417
public Label NameLabel;
1518
public Label ValueLabel;
1619
public Label UnitLabel;
@@ -45,6 +48,10 @@ public BaseEntryControl(BaseEntry entry) : this()
4548

4649
// When entry's value changes, update value and unit labels
4750
entry.OnEntryValueChanged += HandleEntryValueChanged;
51+
52+
// Handle alternate units
53+
if (entry.AltUnit != null)
54+
this.RegisterCallback<MouseDownEvent>(_ => ToggleAltUnit(entry), TrickleDown.TrickleDown);
4855
}
4956

5057
public BaseEntryControl(string name, string value) : this()
@@ -117,5 +124,13 @@ public void HandleEntryValueChanged(string value, string unit)
117124
if (Unit != unit)
118125
Unit = unit;
119126
}
127+
128+
public void ToggleAltUnit(BaseEntry entry)
129+
{
130+
if (Time.time - _timeOfLastClick < 0.5f)
131+
entry.AltUnit.IsActive = !entry.AltUnit.IsActive;
132+
133+
_timeOfLastClick = Time.time;
134+
}
120135
}
121136
}

MicroEngineerProject/MicroEngineer/Utilities/Utility.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static class Utility
1818
public static VesselComponent ActiveVessel;
1919
public static ManeuverNodeData CurrentManeuver;
2020
public static string LayoutPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MicroLayout.json");
21-
public static int CurrentLayoutVersion = 13;
21+
public static int CurrentLayoutVersion = 14;
2222
private static ManualLogSource Logger = BepInEx.Logging.Logger.CreateLogSource("MicroEngineer.Utility");
2323
public static GameStateConfiguration GameState;
2424
public static MessageCenter MessageCenter;
@@ -147,7 +147,7 @@ public static void LoadLayout(List<BaseWindow> windows)
147147
Logger.LogInfo("LoadLayout successful.");
148148
Logger.LogDebug($"Finished loading. MainGui.IsFlightActive: {MainGui.IsFlightActive}.");
149149
}
150-
catch (FileNotFoundException ex)
150+
catch (FileNotFoundException)
151151
{
152152
Logger.LogWarning($"MicroLayout.json file was not found at the expected location during LoadLayout. This is normal if this mod was just installed. Window states and positions will keep their default values.");
153153

Staging/BepInEx/plugins/micro_engineer/swinfo.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
{
2-
"spec": "1.2",
3-
"mod_id": "micro_engineer",
2+
"spec": "1.3",
3+
"mod_id": "com.micrologist.microengineer",
44
"author": "Micrologist, Falki",
55
"name": "Micro Engineer",
66
"description": "Get in-flight and VAB information about your current vessel",
77
"source": "https://github.com/Micrologist/MicroEngineer",
8-
"version": "1.2.1",
8+
"version": "1.3.0",
99
"version_check": "https://raw.githubusercontent.com/Micrologist/MicroEngineer/main/Staging/BepInEx/plugins/micro_engineer/swinfo.json",
1010
"dependencies": [
1111
{
12-
"id": "SpaceWarp",
12+
"id": "com.github.x606.spacewarp",
1313
"version": {
1414
"min": "1.3.0.3",
1515
"max": "*"

0 commit comments

Comments
 (0)