Skip to content

Commit

Permalink
Merge pull request #34 from Falki-git/main
Browse files Browse the repository at this point in the history
Fix OAB body dropdown sometimes not being able to select a body
  • Loading branch information
Falki-git authored Sep 10, 2023
2 parents bf1695f + 7480fc6 commit c81e546
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
4 changes: 2 additions & 2 deletions MicroEngineerProject/MicroEngineer/MicroEngineerMod.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace MicroMod
{
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.3.1")]
[BepInPlugin("com.micrologist.microengineer", "MicroEngineer", "1.3.2")]
[BepInDependency(SpaceWarpPlugin.ModGuid, SpaceWarpPlugin.ModVer)]
public class MicroEngineerMod : BaseSpaceWarpPlugin
{
Expand Down Expand Up @@ -55,7 +55,7 @@ public void Update()
Manager.Instance.Update();

// Keyboard shortcut for opening UI
if (Input.GetKey(KeyCode.LeftAlt) && Input.GetKeyDown(KeyCode.E))
if (Input.GetKey(KeyCode.LeftControl) && Input.GetKeyDown(KeyCode.E))
{
if (Utility.GameState.GameState == GameState.FlightView || Utility.GameState.GameState == GameState.Map3DView)
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using MicroMod;
using BepInEx.Logging;
using MicroMod;
using UnityEngine;
using UnityEngine.UIElements;

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

private static ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("MicroEngineer.StageInfoOABController");
private bool _lockUiRefresh;

public StageInfoOABController()
{ }

Expand Down Expand Up @@ -92,9 +96,26 @@ private void BuildStages(List<DeltaVStageInfo_OAB> stages)
MicroCelestialBodies.Instance.Bodies.Select(b => b.DisplayName).ToList(),
stage.CelestialBody.Name
);

var celestialBodyDropdown = control.Q<DropdownField>("body-dropdown");
celestialBodyDropdown.RegisterCallback<MouseDownEvent>(evt =>
{
// When user clicks on the celestialBodyDropdown control we lock stage info refresh from happening
// and unlock it again when user selects something from the dropdown.
// We do this because if VesselDeltaVCalculationMessage is triggered between the user first clicking
// on the control and selection something from it, the event will cause the UI to refresh (destroy
// and rebuild the controls) and thus the original dropdown control will no longer exist and
// celestialBody will not be selectable.
_lockUiRefresh = true;
});
// Update entry's CelestialBody at the same index as the stage
celestialBodyDropdown.RegisterValueChangedCallback(evt => StageEntry.UpdateCelestialBodyAtIndex(stage.Index, celestialBodyDropdown.value));
celestialBodyDropdown.RegisterValueChangedCallback(evt =>
{
StageEntry.UpdateCelestialBodyAtIndex(stage.Index, celestialBodyDropdown.value);
_lockUiRefresh = false;
StageEntry.RefreshData();
});

Body.Add(control);
}

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

private void HandleStageInfoChanged(List<DeltaVStageInfo_OAB> stages)
{
if (_lockUiRefresh) return;

Body.Clear();
BuildStages(stages);
}
Expand Down
2 changes: 1 addition & 1 deletion Staging/BepInEx/plugins/micro_engineer/swinfo.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Micro Engineer",
"description": "Get in-flight and VAB information about your current vessel",
"source": "https://github.com/Micrologist/MicroEngineer",
"version": "1.3.1",
"version": "1.3.2",
"version_check": "https://raw.githubusercontent.com/Micrologist/MicroEngineer/main/Staging/BepInEx/plugins/micro_engineer/swinfo.json",
"dependencies": [
{
Expand Down

0 comments on commit c81e546

Please sign in to comment.