From 287389d73eccfd222484366be6d2fc069cbfef32 Mon Sep 17 00:00:00 2001 From: arthomnix Date: Fri, 3 Apr 2026 02:07:56 +0100 Subject: [PATCH] don't let the game process keyboard events if our input is focused --- OemLoader/MainWindow.cs | 9 +++++++-- OemLoader/ProgramPatch.cs | 12 +++++++++++- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/OemLoader/MainWindow.cs b/OemLoader/MainWindow.cs index 31b442b..c542bef 100644 --- a/OemLoader/MainWindow.cs +++ b/OemLoader/MainWindow.cs @@ -6,6 +6,8 @@ namespace OemLoader; public class MainWindow(string title) { + public static bool Typing { get; private set; } + private readonly ImInputString _filename = new(short.MaxValue); private List? _oem; private string? _errorMessage; @@ -16,7 +18,7 @@ public class MainWindow(string title) if (Program.ControlledVehicle is null || _oem is null) return; if (_oem.First().Epoch > time || time > _oem.Last().Epoch) return; - var l = _oem.TakeWhile(line => line.Epoch < time).Last(); + var l = _oem.TakeWhile(line => line.Epoch <= time).Last(); var orb = l.AsOrbit(Program.ControlledVehicle.Parent, Program.ControlledVehicle.Orbit.OrbitLineColor); var dt = (time - OemLoader.KsaEpoch).TotalSeconds - Universe.GetElapsedSeconds(); @@ -34,6 +36,7 @@ public class MainWindow(string title) if (ImGui.Begin(title, ref ProgramPatch.WindowOpen)) { ImGui.InputTextWithHint("OEM file path", "/home/user/ephemeris.asc", _filename); + if (ImGui.Button("Load OEM file")) { try @@ -66,7 +69,7 @@ public class MainWindow(string title) var maxTicks = _oem.Last().Epoch.Ticks; unsafe { - fixed (long* pTicks = &_sliderTicks) ImGui.SliderScalar( + fixed (long *pTicks = &_sliderTicks) ImGui.SliderScalar( "Time", ImGuiDataType.U64, pTicks, @@ -82,6 +85,8 @@ public class MainWindow(string title) GoToTime(sliderTime); } } + + Typing = ImGui.IsWindowFocused() && ImGui.GetIO().WantCaptureKeyboard; } ImGui.End(); } diff --git a/OemLoader/ProgramPatch.cs b/OemLoader/ProgramPatch.cs index 82a12a1..dd1e4ea 100644 --- a/OemLoader/ProgramPatch.cs +++ b/OemLoader/ProgramPatch.cs @@ -13,9 +13,10 @@ internal static class ProgramPatch private static void DrawMenuItem() { - ImGuiHelper.DrawMenuItem("Ephemeris loader", ref WindowOpen); + ImGuiHelper.DrawMenuItem("Ephemeris Loader", ref WindowOpen); } + // Add an entry for our window to the View menu [UsedImplicitly] [HarmonyPatch(nameof(Program.DrawMenuBar))] [HarmonyTranspiler] @@ -38,4 +39,13 @@ internal static class ProgramPatch return matcher.InstructionEnumeration(); } + + // Don't allow the game to process keyboard inputs further if the text input in our window is focused + [UsedImplicitly] + [HarmonyPatch(nameof(Program.OnKey))] + [HarmonyPrefix] + private static bool OnKeyPrefix() + { + return !MainWindow.Typing; + } } \ No newline at end of file -- 2.51.2