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

Commit c81e546

Browse files
authored
Merge pull request #34 from Falki-git/main
Fix OAB body dropdown sometimes not being able to select a body
2 parents bf1695f + 7480fc6 commit c81e546

File tree

3 files changed

+28
-5
lines changed

3 files changed

+28
-5
lines changed

MicroEngineerProject/MicroEngineer/MicroEngineerMod.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace MicroMod
1111
{
12-
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.3.1")]
12+
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.3.2")]
1313
[BepInDependency(SpaceWarpPlugin.ModGuid, SpaceWarpPlugin.ModVer)]
1414
public class MicroEngineerMod : BaseSpaceWarpPlugin
1515
{
@@ -55,7 +55,7 @@ public void Update()
5555
Manager.Instance.Update();
5656

5757
// Keyboard shortcut for opening UI
58-
if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.E))
58+
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.E))
5959
{
6060
if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.Map3DView)
6161
{

MicroEngineerProject/MicroEngineer/UI/Controllers/StageInfoOABController.cs

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using MicroMod;
1+
using BepInEx.Logging;
2+
using MicroMod;
23
using UnityEngine;
34
using UnityEngine.UIElements;
45

@@ -20,6 +21,9 @@ public class StageInfoOABController : MonoBehaviour
2021
public VisualElement TotalVacDeltaVContainer { get; set; }
2122
public VisualElement TotalBurnTimeContainer { get; set; }
2223

24+
private static ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("MicroEngineer.StageInfoOABController");
25+
private bool _lockUiRefresh;
26+
2327
public StageInfoOABController()
2428
{ }
2529

@@ -92,9 +96,26 @@ private void BuildStages(List<DeltaVStageInfo_OAB> stages)
9296
MicroCelestialBodies.Instance.Bodies.Select(b => b.DisplayName).ToList(),
9397
stage.CelestialBody.Name
9498
);
99+
95100
var celestialBodyDropdown = control.Q<DropdownField>("body-dropdown");
101+
celestialBodyDropdown.RegisterCallback<MouseDownEvent>(evt =>
102+
{
103+
// When user clicks on the celestialBodyDropdown control we lock stage info refresh from happening
104+
// and unlock it again when user selects something from the dropdown.
105+
// We do this because if VesselDeltaVCalculationMessage is triggered between the user first clicking
106+
// on the control and selection something from it, the event will cause the UI to refresh (destroy
107+
// and rebuild the controls) and thus the original dropdown control will no longer exist and
108+
// celestialBody will not be selectable.
109+
_lockUiRefresh = true;
110+
});
96111
// Update entry's CelestialBody at the same index as the stage
97-
celestialBodyDropdown.RegisterValueChangedCallback(evt => StageEntry.UpdateCelestialBodyAtIndex(stage.Index, celestialBodyDropdown.value));
112+
celestialBodyDropdown.RegisterValueChangedCallback(evt =>
113+
{
114+
StageEntry.UpdateCelestialBodyAtIndex(stage.Index, celestialBodyDropdown.value);
115+
_lockUiRefresh = false;
116+
StageEntry.RefreshData();
117+
});
118+
98119
Body.Add(control);
99120
}
100121

@@ -108,6 +129,8 @@ private void BuildStages(List<DeltaVStageInfo_OAB> stages)
108129

109130
private void HandleStageInfoChanged(List<DeltaVStageInfo_OAB> stages)
110131
{
132+
if (_lockUiRefresh) return;
133+
111134
Body.Clear();
112135
BuildStages(stages);
113136
}

Staging/BepInEx/plugins/micro_engineer/swinfo.json

Lines changed: 1 addition & 1 deletion
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.3.1",
8+
"version": "1.3.2",
99
"version_check": "https://raw.githubusercontent.com/Micrologist/MicroEngineer/main/Staging/BepInEx/plugins/micro_engineer/swinfo.json",
1010
"dependencies": [
1111
{

0 commit comments

Comments
 (0)