Skip to content

Commit

Permalink
Add coloring to preset names that aren't researched yet
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Jul 2, 2023
1 parent a17ccf2 commit bbf0605
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions Source/ModuleROHeatshield.cs
Original file line number Diff line number Diff line change
Expand Up @@ -363,18 +363,39 @@ public bool PurchaseConfig(PartUpgradeHandler.Upgrade upgd)
return false;
}

private void UpdatePresetsList(string[] options)
private void UpdatePresetsList(string[] presetNames)
{
BaseField bf = Fields[nameof(heatShieldType)];

if (options.Length == 0) { options = new string[] { "NONE" }; }
var dispValues = RP1Found && HighLogic.LoadedScene != GameScenes.LOADING ?
presetNames.Select(p => ConstructColoredPresetTitle(p)).ToArray() : presetNames;

if (presetNames.Length == 0)
{
presetNames = dispValues = new string[] { "NONE" };
}

var uiControlEditor = bf.uiControlEditor as UI_ChooseOption;
uiControlEditor.display = uiControlEditor.options = options;
uiControlEditor.options = presetNames;
uiControlEditor.display = dispValues;

Debug.Log($"[ROHeatshields] available presets on part {part.name}: " + string.Join(",", uiControlEditor.options));
}

private string ConstructColoredPresetTitle(string presetName)
{
if (HighLogic.LoadedScene == GameScenes.LOADING)
return presetName;

string partTech = part.partInfo.TechRequired;
if (string.IsNullOrEmpty(partTech) || ResearchAndDevelopment.GetTechnologyState(partTech) != RDTech.State.Available)
return $"<color=orange>{presetName}</color>";

PartUpgradeHandler.Upgrade upgrade = PartUpgradeManager.Handler.GetUpgrade(presetName);
bool isTechAvailable = upgrade == null || ResearchAndDevelopment.GetTechnologyState(upgrade.techRequired) == RDTech.State.Available;
return isTechAvailable ? presetName : $"<color=orange>{presetName}</color>";
}

private void EnsureBestAvailableConfigSelected()
{
if (IsConfigUnlocked(heatShieldType)) return;
Expand Down Expand Up @@ -460,7 +481,7 @@ public virtual bool Validate(out string validationError, out bool canBeResolved,
if (IsConfigUnlocked(heatShieldType)) return true;

PartUpgradeHandler.Upgrade upgd = PartUpgradeManager.Handler.GetUpgrade(heatShieldType);
if(upgd != null)
if (upgd != null)
techToResolve = upgd.techRequired;
if (PartUpgradeManager.Handler.IsAvailableToUnlock(heatShieldType))
{
Expand Down

0 comments on commit bbf0605

Please sign in to comment.