From 35b907ad15d4e169d71f1ca39d63438aae718d78 Mon Sep 17 00:00:00 2001 From: KSP-TaxiService Date: Tue, 8 Jun 2021 22:23:36 +0800 Subject: [PATCH] Changes to allow an arbitrary number of upgrades for ground stations --- src/CommNetConstellation/CNCSettings.cs | 3 +++ .../CommNetLayer/CNCCommNetHome.cs | 6 +++--- .../UI/ConstellationControlDialog.cs | 2 +- .../UI/GroundStationBuildDialog.cs | 14 +++++++------- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/CommNetConstellation/CNCSettings.cs b/src/CommNetConstellation/CNCSettings.cs index edfb55f..351f304 100644 --- a/src/CommNetConstellation/CNCSettings.cs +++ b/src/CommNetConstellation/CNCSettings.cs @@ -57,6 +57,7 @@ public class Settings public int[] GroundStationUpgradeableCosts; public double[] GroundStationUpgradeablePowers; public double[] KSCStationPowers; + public int GroundStationUpgradesCount = 0; public void postprocess() { @@ -64,6 +65,7 @@ public void postprocess() { var tokens = UpgradeableGroundStationCosts.Split(';'); GroundStationUpgradeableCosts = new int[tokens.Length]; + GroundStationUpgradesCount = tokens.Length; for (int i = 0; i < tokens.Length; i++) { int.TryParse(tokens[i], out GroundStationUpgradeableCosts[i]); @@ -73,6 +75,7 @@ public void postprocess() { var tokens = UpgradeableGroundStationPowers.Split(';'); GroundStationUpgradeablePowers = new double[tokens.Length]; + GroundStationUpgradesCount = Math.Min(tokens.Length, GroundStationUpgradesCount); for (int i = 0; i < tokens.Length; i++) { double.TryParse(tokens[i], out GroundStationUpgradeablePowers[i]); diff --git a/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs b/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs index ac64925..57d26e4 100644 --- a/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs +++ b/src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs @@ -143,11 +143,11 @@ public void replaceFrequencies(List newFreqs) } /// - /// Increment Tech Level Ground Station to max 3 + /// Increment Tech Level Ground Station to max X /// public void incrementTechLevel() { - if (this.TechLevel < 3 && !this.CommNetHome.isKSC) + if (this.TechLevel < CNCSettings.Instance.GroundStationUpgradesCount && !this.CommNetHome.isKSC) { this.TechLevel++; refresh(); @@ -171,7 +171,7 @@ public void decrementTechLevel() /// public void setTechLevel(short level) { - if (level >= 0 && level <= 3 && !this.CommNetHome.isKSC) + if (level >= 0 && level <= CNCSettings.Instance.GroundStationUpgradesCount && !this.CommNetHome.isKSC) { this.TechLevel = level; refresh(); diff --git a/src/CommNetConstellation/UI/ConstellationControlDialog.cs b/src/CommNetConstellation/UI/ConstellationControlDialog.cs index 9ff3408..57fef5d 100644 --- a/src/CommNetConstellation/UI/ConstellationControlDialog.cs +++ b/src/CommNetConstellation/UI/ConstellationControlDialog.cs @@ -925,7 +925,7 @@ private DialogGUIHorizontalLayout createGroundStationRow(CNCCommNetHome thisStat DialogGUILabel locationLabel = new DialogGUILabel(Localizer.Format("#CNC_ConstellationControl_LatitudeAndLongitude", string.Format("{0:0.0}", thisStation.latitude), string.Format("{0:0.0}", thisStation.longitude)), 80, 24);//string.Format("LAT: \nLON: ", , ) DialogGUILabel freqsLabel = new DialogGUILabel(getFreqString(thisStation.getFrequencyList()), 160, 12); DialogGUIButton buildButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Upgradebutton"), delegate { groundstationBuildClick(thisStation); }, 70, 32, false);//"Upgrade" - buildButton.OptionInteractableCondition = () => (thisStation.CommNetHome.isKSC) ? false : (thisStation.TechLevel < 3) ? true : false; + buildButton.OptionInteractableCondition = () => (thisStation.CommNetHome.isKSC) ? false : (thisStation.TechLevel < CNCSettings.Instance.GroundStationUpgradesCount) ? true : false; DialogGUIButton updateButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Editbutton"), delegate { groundstationEditClick(thisStation); }, 50, 32, false);//"Edit" DialogGUIBase[] rowGUIBase = new DialogGUIBase[] { colorImage, stationNameLabel, locationLabel, freqsLabel, buildButton, updateButton }; diff --git a/src/CommNetConstellation/UI/GroundStationBuildDialog.cs b/src/CommNetConstellation/UI/GroundStationBuildDialog.cs index 95ff8d0..42a06c7 100644 --- a/src/CommNetConstellation/UI/GroundStationBuildDialog.cs +++ b/src/CommNetConstellation/UI/GroundStationBuildDialog.cs @@ -79,7 +79,7 @@ protected override List drawContentComponents() listComponments.Add(new DialogGUISpace(10)); DialogGUIButton upgradeButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Upgradebutton"), onClickUpgrade, false);//Upgrade - upgradeButton.OptionInteractableCondition = () => this.hostStation.TechLevel < 3 ? true : false; + upgradeButton.OptionInteractableCondition = () => this.hostStation.TechLevel < CNCSettings.Instance.GroundStationUpgradesCount ? true : false; DialogGUIButton closeButton = new DialogGUIButton(Localizer.Format("#CNC_Generic_Close"), delegate { this.dismiss(); }, false);//Close DialogGUIHorizontalLayout actionGroup = new DialogGUIHorizontalLayout(true, false, 4, new RectOffset(), TextAnchor.MiddleLeft, new DialogGUIBase[] { new DialogGUIFlexibleSpace(), upgradeButton, closeButton, new DialogGUIFlexibleSpace() }); listComponments.Add(actionGroup); @@ -95,7 +95,7 @@ private string currentPowerFunc() private string nextPowerFunc() { - if(this.hostStation.TechLevel >= 3) + if(this.hostStation.TechLevel >= CNCSettings.Instance.GroundStationUpgradesCount) { return Localizer.Format("#CNC_GroundStationBuild_DSNpowerNil");//DSN Power: Nil } @@ -109,7 +109,7 @@ private string nextPowerFunc() private string costFunc() { - if(this.hostStation.TechLevel >= 3) + if(this.hostStation.TechLevel >= CNCSettings.Instance.GroundStationUpgradesCount) { return Localizer.Format("#CNC_GroundStationBuild_InvoiceNil");//Invoice: Nil } @@ -127,7 +127,7 @@ private string availableFunc() } string color = "green"; - if (this.hostStation.TechLevel < 3) + if (this.hostStation.TechLevel < CNCSettings.Instance.GroundStationUpgradesCount) { int cost = CNCSettings.Instance.GroundStationUpgradeableCosts[this.hostStation.TechLevel]; if (Funding.Instance.Funds < cost) @@ -158,7 +158,7 @@ private void onClickUpgrade() } currentTexture.uiItem.GetComponent().texture = getLevelTexture(this.hostStation.TechLevel); - nextTexture.uiItem.GetComponent().texture = getLevelTexture((short)(this.hostStation.TechLevel < 3? (this.hostStation.TechLevel + 1) : this.hostStation.TechLevel)); + nextTexture.uiItem.GetComponent().texture = getLevelTexture((short)(this.hostStation.TechLevel < CNCSettings.Instance.GroundStationUpgradesCount ? (this.hostStation.TechLevel + 1) : this.hostStation.TechLevel)); } } @@ -175,8 +175,8 @@ private Texture2D getLevelTexture(short level) case 3: return L3PicTexture; default: - CNCLog.Error("No texture found for Tech Level {0}!", level); - return null; + CNCLog.Verbose("No texture found for Tech Level {0}!", level); + return L3PicTexture; } } }