Skip to content

Commit

Permalink
Keep track of selected pad on vessels
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
taniwha committed Sep 20, 2020
1 parent 00bdede commit a510e99
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Source/BuildControl.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
2 changes: 2 additions & 0 deletions Source/DisposablePad/DisposablePad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
}
Expand Down
31 changes: 31 additions & 0 deletions Source/GUI/BuildWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ public class ELBuildWindow : MonoBehaviour
static Texture2D flagTexture;

List<ELBuildControl> launchpads;
ELVesselWorkNet worknet;
DropDownList pad_list;
ELBuildControl control;

Expand Down Expand Up @@ -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<ELBuildControl.IBuilder> ();
if (pad != null) {
return pad.control;
}
}
return null;
}

void BuildPadList (Vessel v)
{
launchpads = null;
pad_list = null;
worknet = null;

if (v.isEVA) {
control = null;
Expand All @@ -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<ELBuildControl> ();
int control_index = -1;
for (int i = 0; i < pads.Count; i++) {
Expand All @@ -177,6 +206,7 @@ void BuildPadList (Vessel v)
}
if (control_index < 0) {
control_index = 0;
control = pads[0].control;
}
var pad_names = new List<string> ();
for (int ind = 0; ind < launchpads.Count; ind++) {
Expand Down Expand Up @@ -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 ();
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Pad/Launchpad.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 ()
{
}
Expand Down
2 changes: 2 additions & 0 deletions Source/Survey/SurveyStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ public string LaunchedFrom
}
}

public uint ID { get { return part.flightID; } }

public bool isBusy
{
get {
Expand Down
3 changes: 3 additions & 0 deletions Source/Workshop/VesselWorkNet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit a510e99

Please sign in to comment.