From a510e990cc8736b15c30fa0c3c694d649289b266 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Mon, 21 Sep 2020 08:39:23 +0900 Subject: [PATCH] Keep track of selected pad on vessels Bases and stations with multiple pads could get confusing due to the first pad in the parts list being selected every time a vessel switch occurred (eg, every time a build is finalized). --- Source/BuildControl.cs | 2 ++ Source/DisposablePad/DisposablePad.cs | 2 ++ Source/GUI/BuildWindow.cs | 31 +++++++++++++++++++++++++++ Source/Pad/Launchpad.cs | 2 ++ Source/Survey/SurveyStation.cs | 2 ++ Source/Workshop/VesselWorkNet.cs | 3 +++ 6 files changed, 42 insertions(+) diff --git a/Source/BuildControl.cs b/Source/BuildControl.cs index e5463968..c8c0e885 100644 --- a/Source/BuildControl.cs +++ b/Source/BuildControl.cs @@ -50,6 +50,8 @@ public interface IBuilder string Name { get; set; } string LandedAt { get; } string LaunchedFrom { get; } + + uint ID { get; } } public IBuilder builder { get; private set; } diff --git a/Source/DisposablePad/DisposablePad.cs b/Source/DisposablePad/DisposablePad.cs index 9b9d7064..1c92fe8a 100644 --- a/Source/DisposablePad/DisposablePad.cs +++ b/Source/DisposablePad/DisposablePad.cs @@ -106,6 +106,8 @@ public string Name public string LandedAt { get { return ""; } } public string LaunchedFrom { get { return ""; } } + public uint ID { get { return part.flightID; } } + public void PadSelection_start () { } diff --git a/Source/GUI/BuildWindow.cs b/Source/GUI/BuildWindow.cs index 7408cb90..13f91202 100644 --- a/Source/GUI/BuildWindow.cs +++ b/Source/GUI/BuildWindow.cs @@ -48,6 +48,7 @@ public class ELBuildWindow : MonoBehaviour static Texture2D flagTexture; List launchpads; + ELVesselWorkNet worknet; DropDownList pad_list; ELBuildControl control; @@ -154,10 +155,34 @@ public static void SaveSettings (ConfigNode node) node.AddValue ("link_lfo_sliders", link_lfo_sliders); } + static ELVesselWorkNet FindWorkNet (Vessel v) + { + for (int i = 0; i < v.vesselModules.Count; i++) { + var worknet = v.vesselModules[i] as ELVesselWorkNet; + if (worknet != null) { + return worknet; + } + } + return null; + } + + static ELBuildControl FindControl (Vessel v, uint id) + { + Part part = v[id]; + if (part != null) { + var pad = part.FindModuleImplementing (); + if (pad != null) { + return pad.control; + } + } + return null; + } + void BuildPadList (Vessel v) { launchpads = null; pad_list = null; + worknet = null; if (v.isEVA) { control = null; @@ -167,6 +192,10 @@ void BuildPadList (Vessel v) if (pads.Count < 1) { control = null; } else { + worknet = FindWorkNet (v); + if (worknet != null) { + control = FindControl (v, worknet.selectedPad); + } launchpads = new List (); int control_index = -1; for (int i = 0; i < pads.Count; i++) { @@ -177,6 +206,7 @@ void BuildPadList (Vessel v) } if (control_index < 0) { control_index = 0; + control = pads[0].control; } var pad_names = new List (); for (int ind = 0; ind < launchpads.Count; ind++) { @@ -424,6 +454,7 @@ void Select_Pad (ELBuildControl selected_pad) control.builder.Highlight (false); } control = selected_pad; + worknet.selectedPad = control.builder.ID; pad_list.SelectItem (launchpads.IndexOf (control)); UpdateGUIState (); } diff --git a/Source/Pad/Launchpad.cs b/Source/Pad/Launchpad.cs index 53b7a0d3..105344fa 100644 --- a/Source/Pad/Launchpad.cs +++ b/Source/Pad/Launchpad.cs @@ -120,6 +120,8 @@ public string Name public string LandedAt { get { return ""; } } public string LaunchedFrom { get { return ""; } } + public uint ID { get { return part.flightID; } } + public void PadSelection_start () { } diff --git a/Source/Survey/SurveyStation.cs b/Source/Survey/SurveyStation.cs index 212b20b2..9f92c8a9 100644 --- a/Source/Survey/SurveyStation.cs +++ b/Source/Survey/SurveyStation.cs @@ -135,6 +135,8 @@ public string LaunchedFrom } } + public uint ID { get { return part.flightID; } } + public bool isBusy { get { diff --git a/Source/Workshop/VesselWorkNet.cs b/Source/Workshop/VesselWorkNet.cs index fda0b36f..c2056853 100644 --- a/Source/Workshop/VesselWorkNet.cs +++ b/Source/Workshop/VesselWorkNet.cs @@ -35,6 +35,9 @@ public class ELVesselWorkNet : VesselModule public double lastUpdate; public double Productivity { get; private set; } + [KSPField (isPersistant = true)] + public uint selectedPad; + public void ForceProductivityUpdate() { forceProductivityUpdate = true;