Skip to content

Commit

Permalink
Remove the permanent public freq of a ground station (overlooked), an…
Browse files Browse the repository at this point in the history
…d few UI improvements
  • Loading branch information
KSP-TaxiService committed Aug 12, 2017
1 parent 304d30a commit 8efe500
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
19 changes: 11 additions & 8 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using CommNet;
using CommNetConstellation.UI;
using System;
using System.Collections.Generic;
using UnityEngine;

Expand All @@ -8,7 +9,7 @@ namespace CommNetConstellation.CommNetLayer
/// <summary>
/// Customise the home nodes
/// </summary>
public class CNCCommNetHome : CommNetHome
public class CNCCommNetHome : CommNetHome, IComparable<CNCCommNetHome>
{
private static readonly Texture2D markTexture = UIUtils.loadImage("groundStationMark");
private static GUIStyle groundStationHeadline;
Expand All @@ -18,7 +19,7 @@ public class CNCCommNetHome : CommNetHome
[Persistent] public string ID;
[Persistent] public Color Color = Color.red;
[Persistent] protected string OptionalName = "";
[Persistent(collectionIndex = "Frequency")] public List<short> Frequencies;
[Persistent(collectionIndex = "Frequency")] public List<short> Frequencies = new List<short>();

public double altitude { get { return this.alt; } }
public double latitude { get { return this.lat; } }
Expand All @@ -30,12 +31,6 @@ public string stationName
set { this.OptionalName = value; }
}

public CNCCommNetHome()
{
this.Frequencies = new List<short>();
this.Frequencies.Add(CNCSettings.Instance.PublicRadioFrequency);
}

public void copyOf(CommNetHome stockHome)
{
CNCLog.Verbose("CommNet Home '{0}' added", stockHome.nodeName);
Expand Down Expand Up @@ -177,5 +172,13 @@ private bool IsCamDistanceToWide(Vector3d loc)
return true;
return false;
}

/// <summary>
/// Allow to be sorted easily
/// </summary>
public int CompareTo(CNCCommNetHome other)
{
return this.stationName.CompareTo(other.stationName);
}
}
}
3 changes: 2 additions & 1 deletion src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,10 @@ protected override void Start()
UnityEngine.Object.Destroy(homes[i]);
groundStations.Add(customHome);
}
groundStations.Sort();

//Apply the ground-station changes from persistent.sfs
for(int i=0; i<persistentGroundStations.Count;i++)
for (int i=0; i<persistentGroundStations.Count;i++)
{
if(groundStations.Exists(x => x.ID.Equals(persistentGroundStations[i].ID)))
{
Expand Down
4 changes: 3 additions & 1 deletion src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -357,14 +357,16 @@ protected Dictionary<short, double> buildFrequencyList(List<CNCAntennaPartInfo>
}

/// <summary>
/// Get the list of frequencies only
/// Get the *unsorted* list of frequencies only
/// </summary>
public List<short> getFrequencies()
{
List<short> freqs = new List<short>();
var itr = this.FrequencyDict.Keys.GetEnumerator();
while (itr.MoveNext())
{
freqs.Add(itr.Current);
}

return freqs;
}
Expand Down
1 change: 1 addition & 0 deletions src/CommNetConstellation/UI/ConstellationControlDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,7 @@ private DialogGUIHorizontalLayout createGroundStationRow(CNCCommNetHome thisStat

private string getFreqString(List<short> frequencies, short strongestFreq = -1)
{
frequencies.Sort();
string freqString = "Frequencies: ";

if (frequencies.Count == 0) // nothing
Expand Down
5 changes: 4 additions & 1 deletion src/CommNetConstellation/UI/VesselSetupDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public VesselSetupDialog(string title, Vessel vessel, Callback<Vessel> updateCa
0.5f, //x
0.5f, //y
500, //width
500, //height
600, //height
new DialogOptions[] {})
{
this.hostVessel = vessel;
Expand Down Expand Up @@ -62,6 +62,7 @@ protected override List<DialogGUIBase> drawContentComponents()

CNCCommNetVessel cncVessel = (CNCCommNetVessel)this.hostVessel.Connection;
List<short> vesselFrequencyList = cncVessel.getFrequencies();
vesselFrequencyList.Sort();

listComponments.Add(new DialogGUIHorizontalLayout(true, false, 0, new RectOffset(), TextAnchor.UpperCenter, new DialogGUIBase[] { new DialogGUILabel(this.description + "\n\n", false, false) }));

Expand Down Expand Up @@ -111,6 +112,8 @@ private void refreshFrequencyRows()

CNCCommNetVessel cncVessel = (CNCCommNetVessel)this.hostVessel.Connection;
List<short> vesselFrequencyList = cncVessel.getFrequencies();
vesselFrequencyList.Sort();

for (int i = 0; i < vesselFrequencyList.Count; i++)
{
frequencyRowLayout.AddChild(createFrequencyRow(vesselFrequencyList[i]));
Expand Down

0 comments on commit 8efe500

Please sign in to comment.