Skip to content

Commit

Permalink
Changes to allow an arbitrary number of upgrades for ground stations
Browse files Browse the repository at this point in the history
  • Loading branch information
KSP-TaxiService committed Jun 8, 2021
1 parent 4122e2c commit 35b907a
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
3 changes: 3 additions & 0 deletions src/CommNetConstellation/CNCSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,13 +57,15 @@ public class Settings
public int[] GroundStationUpgradeableCosts;
public double[] GroundStationUpgradeablePowers;
public double[] KSCStationPowers;
public int GroundStationUpgradesCount = 0;

public void postprocess()
{
if (UpgradeableGroundStationCosts != String.Empty)
{
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]);
Expand All @@ -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]);
Expand Down
6 changes: 3 additions & 3 deletions src/CommNetConstellation/CommNetLayer/CNCCommNetHome.cs
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,11 @@ public void replaceFrequencies(List<short> newFreqs)
}

/// <summary>
/// Increment Tech Level Ground Station to max 3
/// Increment Tech Level Ground Station to max X
/// </summary>
public void incrementTechLevel()
{
if (this.TechLevel < 3 && !this.CommNetHome.isKSC)
if (this.TechLevel < CNCSettings.Instance.GroundStationUpgradesCount && !this.CommNetHome.isKSC)
{
this.TechLevel++;
refresh();
Expand All @@ -171,7 +171,7 @@ public void decrementTechLevel()
/// </summary>
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();
Expand Down
2 changes: 1 addition & 1 deletion src/CommNetConstellation/UI/ConstellationControlDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };
Expand Down
14 changes: 7 additions & 7 deletions src/CommNetConstellation/UI/GroundStationBuildDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected override List<DialogGUIBase> 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);
Expand All @@ -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
}
Expand All @@ -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
}
Expand All @@ -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)
Expand Down Expand Up @@ -158,7 +158,7 @@ private void onClickUpgrade()
}

currentTexture.uiItem.GetComponent<RawImage>().texture = getLevelTexture(this.hostStation.TechLevel);
nextTexture.uiItem.GetComponent<RawImage>().texture = getLevelTexture((short)(this.hostStation.TechLevel < 3? (this.hostStation.TechLevel + 1) : this.hostStation.TechLevel));
nextTexture.uiItem.GetComponent<RawImage>().texture = getLevelTexture((short)(this.hostStation.TechLevel < CNCSettings.Instance.GroundStationUpgradesCount ? (this.hostStation.TechLevel + 1) : this.hostStation.TechLevel));
}
}

Expand All @@ -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;
}
}
}
Expand Down

0 comments on commit 35b907a

Please sign in to comment.