From 8efe500a3f2129a336178fc75a5e2b851dc9f873 Mon Sep 17 00:00:00 2001 From: KSP-TaxiService Date: Sat, 12 Aug 2017 15:06:32 +0800 Subject: [PATCH] Remove the permanent public freq of a ground station (overlooked), and few UI improvements --- .../CommNetLayer/CNCCommNetHome.cs | 19 +++++++++++-------- .../CommNetLayer/CNCCommNetScenario.cs | 3 ++- .../CommNetLayer/CNCCommNetVessel.cs | 4 +++- .../UI/ConstellationControlDialog.cs | 1 + .../UI/VesselSetupDialog.cs | 5 ++++- 5 files changed, 21 insertions(+), 11 deletions(-) diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs index dd6f644..afbc2cf 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs @@ -1,5 +1,6 @@ using CommNet; using CommNetConstellation.UI; +using System; using System.Collections.Generic; using UnityEngine; @@ -8,7 +9,7 @@ namespace CommNetConstellation.CommNetLayer /// /// Customise the home nodes /// - public class CNCCommNetHome : CommNetHome + public class CNCCommNetHome : CommNetHome, IComparable { private static readonly Texture2D markTexture = UIUtils.loadImage("groundStationMark"); private static GUIStyle groundStationHeadline; @@ -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 Frequencies; + [Persistent(collectionIndex = "Frequency")] public List Frequencies = new List(); public double altitude { get { return this.alt; } } public double latitude { get { return this.lat; } } @@ -30,12 +31,6 @@ public string stationName set { this.OptionalName = value; } } - public CNCCommNetHome() - { - this.Frequencies = new List(); - this.Frequencies.Add(CNCSettings.Instance.PublicRadioFrequency); - } - public void copyOf(CommNetHome stockHome) { CNCLog.Verbose("CommNet Home '{0}' added", stockHome.nodeName); @@ -177,5 +172,13 @@ private bool IsCamDistanceToWide(Vector3d loc) return true; return false; } + + /// + /// Allow to be sorted easily + /// + public int CompareTo(CNCCommNetHome other) + { + return this.stationName.CompareTo(other.stationName); + } } } diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs index 77b3bf0..3409b3a 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetScenario.cs @@ -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 x.ID.Equals(persistentGroundStations[i].ID))) { diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs index d07e4d4..998fc6b 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetVessel.cs @@ -357,14 +357,16 @@ protected Dictionary buildFrequencyList(List } /// - /// Get the list of frequencies only + /// Get the *unsorted* list of frequencies only /// public List getFrequencies() { List freqs = new List(); var itr = this.FrequencyDict.Keys.GetEnumerator(); while (itr.MoveNext()) + { freqs.Add(itr.Current); + } return freqs; } diff --git a/src/CommNetConstellation/UI/ConstellationControlDialog.cs b/src/CommNetConstellation/UI/ConstellationControlDialog.cs index f431d7e..0fa4f14 100644 --- a/src/CommNetConstellation/UI/ConstellationControlDialog.cs +++ b/src/CommNetConstellation/UI/ConstellationControlDialog.cs @@ -489,6 +489,7 @@ private DialogGUIHorizontalLayout createGroundStationRow(CNCCommNetHome thisStat private string getFreqString(List frequencies, short strongestFreq = -1) { + frequencies.Sort(); string freqString = "Frequencies: "; if (frequencies.Count == 0) // nothing diff --git a/src/CommNetConstellation/UI/VesselSetupDialog.cs b/src/CommNetConstellation/UI/VesselSetupDialog.cs index 718721a..49423de 100644 --- a/src/CommNetConstellation/UI/VesselSetupDialog.cs +++ b/src/CommNetConstellation/UI/VesselSetupDialog.cs @@ -27,7 +27,7 @@ public VesselSetupDialog(string title, Vessel vessel, Callback updateCa 0.5f, //x 0.5f, //y 500, //width - 500, //height + 600, //height new DialogOptions[] {}) { this.hostVessel = vessel; @@ -62,6 +62,7 @@ protected override List drawContentComponents() CNCCommNetVessel cncVessel = (CNCCommNetVessel)this.hostVessel.Connection; List 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) })); @@ -111,6 +112,8 @@ private void refreshFrequencyRows() CNCCommNetVessel cncVessel = (CNCCommNetVessel)this.hostVessel.Connection; List vesselFrequencyList = cncVessel.getFrequencies(); + vesselFrequencyList.Sort(); + for (int i = 0; i < vesselFrequencyList.Count; i++) { frequencyRowLayout.AddChild(createFrequencyRow(vesselFrequencyList[i]));