From 2268bf7bff85723a7c8cb7e8adc1bf899a0eb003 Mon Sep 17 00:00:00 2001 From: Robin Leroy Date: Sat, 15 Feb 2025 18:09:38 +0100 Subject: [PATCH] Per-frame hiding. --- ksp_plugin_adapter/ksp_plugin_adapter.cs | 8 ++-- ksp_plugin_adapter/main_window.cs | 49 ++++++++++++++++++------ 2 files changed, 42 insertions(+), 15 deletions(-) diff --git a/ksp_plugin_adapter/ksp_plugin_adapter.cs b/ksp_plugin_adapter/ksp_plugin_adapter.cs index 3cca8cc6ef..8e94102227 100644 --- a/ksp_plugin_adapter/ksp_plugin_adapter.cs +++ b/ksp_plugin_adapter/ksp_plugin_adapter.cs @@ -285,8 +285,9 @@ internal readonly ReferenceFrameSelector private readonly MainWindow main_window_; public bool show_celestial_trajectory(CelestialBody celestial) { - return main_window_.show_unpinned_celestials || - plotting_frame_selector_.pinned[celestial]; + return plotting_frame_selector_.pinned[celestial] || + !main_window_.frames_that_hide_unpinned_celestials.Contains( + plotting_frame_selector_.FrameParameters()); } public event Action LockClearing; @@ -352,7 +353,8 @@ public bool show_celestial_trajectory(CelestialBody celestial) { map_node_pool_ = new MapNodePool( this, visibility_modifiers: () => new MapNodePool.VisibilityModifiers( - show_unpinned: main_window_.show_unpinned_markers, + show_unpinned: !main_window_.frames_that_hide_unpinned_markers + .Contains(plotting_frame_selector_.FrameParameters()), can_hover: !ManœuvreMarker.has_interacting_marker) ); flight_planner_ = new FlightPlanner(this, PredictedVessel); diff --git a/ksp_plugin_adapter/main_window.cs b/ksp_plugin_adapter/main_window.cs index 3a4486538f..6b554b1138 100644 --- a/ksp_plugin_adapter/main_window.cs +++ b/ksp_plugin_adapter/main_window.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using KSP.Localization; @@ -47,8 +48,14 @@ public void SelectActiveVesselTarget(MapObject map_object, } } - public bool show_unpinned_markers { get; private set; } = true; - public bool show_unpinned_celestials { get; private set; } = true; + public HashSet frames_that_hide_unpinned_markers { + get; + private set; + } = new HashSet(); + public HashSet frames_that_hide_unpinned_celestials { + get; + private set; + } = new HashSet(); public bool selecting_active_vessel_target { get; private set; } = false; @@ -218,22 +225,40 @@ protected override void RenderWindowContents(int window_id) { if (adapter_.PluginRunning()) { plotting_frame_selector_.RenderButton(); using (new UnityEngine.GUILayout.HorizontalScope()) { - if (UnityEngine.GUILayout.Button( - L10N.CacheFormat("#Principia_MainWindow_Declutter"), - GUILayoutWidth(5))) { - show_unpinned_markers = false; - show_unpinned_celestials = false; - } UnityEngine.GUILayout.Label( L10N.CacheFormat("#Principia_MainWindow_Declutter_Show")); - show_unpinned_markers = UnityEngine.GUILayout.Toggle( + var plotting_frame_parameters = + plotting_frame_selector_.FrameParameters(); + bool show_unpinned_markers = + !frames_that_hide_unpinned_markers.Contains( + plotting_frame_parameters); + if (show_unpinned_markers != UnityEngine.GUILayout.Toggle( show_unpinned_markers, L10N.CacheFormat( - "#Principia_MainWindow_Declutter_UnpinnedMarkers")); - show_unpinned_celestials = UnityEngine.GUILayout.Toggle( + "#Principia_MainWindow_Declutter_UnpinnedMarkers"))) { + if (show_unpinned_markers) { + frames_that_hide_unpinned_markers.Remove( + plotting_frame_parameters); + } else { + frames_that_hide_unpinned_markers.Add( + plotting_frame_parameters); + } + } + bool show_unpinned_celestials = + !frames_that_hide_unpinned_celestials.Contains( + plotting_frame_parameters); + if (show_unpinned_celestials != UnityEngine.GUILayout.Toggle( show_unpinned_celestials, L10N.CacheFormat( - "#Principia_MainWindow_Declutter_UnpinnedCelestials")); + "#Principia_MainWindow_Declutter_UnpinnedCelestials"))) { + if (show_unpinned_celestials) { + frames_that_hide_unpinned_celestials.Remove( + plotting_frame_parameters); + } else { + frames_that_hide_unpinned_celestials.Add( + plotting_frame_parameters); + } + } } using (new UnityEngine.GUILayout.HorizontalScope()) { flight_planner_.RenderButton();