Skip to content

Commit ac1688e

Browse files
committed
Fix total ASL deltav values in OAB not being calculated
1 parent 59c0cfe commit ac1688e

File tree

5 files changed

+36
-12
lines changed

5 files changed

+36
-12
lines changed

MicroEngineerProject/MicroEngineer/UI/Controllers/StageInfoOABController.cs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public class StageInfoOABController : MonoBehaviour
2424
private static ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("MicroEngineer.StageInfoOABController");
2525
private bool _lockUiRefresh;
2626

27+
private double _totalDeltaVASL;
28+
private double _totalDeltaVVac;
29+
2730
public StageInfoOABController()
2831
{ }
2932

@@ -97,6 +100,9 @@ private void BuildStages(List<DeltaVStageInfo_OAB> stages)
97100
stage.CelestialBody.Name
98101
);
99102

103+
_totalDeltaVASL += stage.DeltaVASL;
104+
_totalDeltaVVac += stage.DeltaVVac;
105+
100106
var celestialBodyDropdown = control.Q<DropdownField>("body-dropdown");
101107
celestialBodyDropdown.RegisterCallback<MouseDownEvent>(evt =>
102108
{
@@ -132,27 +138,44 @@ private void HandleStageInfoChanged(List<DeltaVStageInfo_OAB> stages)
132138
if (_lockUiRefresh) return;
133139

134140
Body.Clear();
141+
TotalAslDeltaVContainer.Clear();
142+
_totalDeltaVASL = 0;
143+
TotalVacDeltaVContainer.Clear();
144+
_totalDeltaVVac = 0;
145+
TotalBurnTimeContainer.Clear();
135146
BuildStages(stages);
147+
SetTotalValues();
136148
}
137149

138150
private void BuildFooter()
151+
{
152+
Footer = Root.Q<VisualElement>("footer");
153+
TotalAslDeltaVContainer = Root.Q<VisualElement>("asl-dv-container");
154+
TotalVacDeltaVContainer = Root.Q<VisualElement>("vac-dv-container");
155+
TotalBurnTimeContainer = Root.Q<VisualElement>("burn-time-container");
156+
157+
SetTotalValues();
158+
}
159+
160+
private void SetTotalValues()
139161
{
140162
BaseEntry entry;
141163
VisualElement control;
142164

143-
Footer = Root.Q<VisualElement>("footer");
144-
145-
TotalAslDeltaVContainer = Root.Q<VisualElement>("asl-dv-container");
146165
entry = StageInfoOABWindow.Entries.Find(e => e is TotalDeltaVASL_OAB);
147-
control = new BaseEntryControl(entry);
166+
// total deltav from stock stage info is wrong because it doesn't take into account different bodies.
167+
// so here we'll sum up values for all calculated stages and won't subscribe to automatic value changes
168+
entry.EntryValue = _totalDeltaVASL;
169+
control = new BaseEntryControl(entry, false);
148170
TotalAslDeltaVContainer.Add(control);
149-
150-
TotalVacDeltaVContainer = Root.Q<VisualElement>("vac-dv-container");
171+
151172
entry = StageInfoOABWindow.Entries.Find(e => e is TotalDeltaVVac_OAB);
152-
control = new BaseEntryControl(entry);
173+
// total deltav from stock stage info is wrong because it doesn't take into account different bodies.
174+
// so here we'll sum up values for all calculated stages and won't subscribe to automatic value changes
175+
entry.EntryValue = _totalDeltaVVac;
176+
control = new BaseEntryControl(entry, false);
153177
TotalVacDeltaVContainer.Add(control);
154178

155-
TotalBurnTimeContainer = Root.Q<VisualElement>("burn-time-container");
156179
entry = StageInfoOABWindow.Entries.Find(e => e is TotalBurnTime_OAB);
157180
control = new TimeEntryControl(entry);
158181
TotalBurnTimeContainer.Add(control);

MicroEngineerProject/MicroEngineer/UI/Controls/BaseEntryControl.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,15 @@ public string Unit
4040
set => UnitLabel.text = value;
4141
}
4242

43-
public BaseEntryControl(BaseEntry entry) : this()
43+
public BaseEntryControl(BaseEntry entry, bool subscribeToValueChanges = true) : this()
4444
{
4545
EntryName = entry.Name;
4646
Value = entry.ValueDisplay;
4747
Unit = entry.UnitDisplay;
4848

4949
// When entry's value changes, update value and unit labels
50-
entry.OnEntryValueChanged += HandleEntryValueChanged;
50+
if (subscribeToValueChanges)
51+
entry.OnEntryValueChanged += HandleEntryValueChanged;
5152

5253
// Handle alternate units
5354
if (entry.AltUnit != null)
Binary file not shown.
Binary file not shown.

Staging/BepInEx/plugins/micro_engineer/swinfo.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
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.4.0",
8+
"version": "1.5.0",
99
"version_check": "https://raw.githubusercontent.com/Micrologist/MicroEngineer/main/Staging/BepInEx/plugins/micro_engineer/swinfo.json",
1010
"dependencies": [
1111
{
@@ -24,7 +24,7 @@
2424
}
2525
],
2626
"ksp2_version": {
27-
"min": "0.1.4",
27+
"min": "0.1.5",
2828
"max": "*"
2929
}
3030
}

0 commit comments

Comments
 (0)