Skip to content

Commit

Permalink
Component Designer now shows the correct dropdown for engine fuels wh…
Browse files Browse the repository at this point in the history
…en selecting an already designed engine.
  • Loading branch information
se5a committed Dec 16, 2024
1 parent 096f7f6 commit 790de0d
Showing 1 changed file with 35 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ public void SetFromComponent(ComponentDesign component, GlobalUIState state)
var tprop = _componentDesigner.ComponentDesignProperties[ptup.propName];
if (tprop.GuiHint == GuiHint.GuiFuelTypeSelection)
{
//tprop.SetValueFromInput();
var cargoTypesToDisplay = GetFuelTypes(tprop, state);
var strfuel = (string)ptup.propValue;
var index = cargoTypesToDisplay.FindIndex(item => item.UniqueID == strfuel);
tprop.SetValueFromString((string)ptup.propValue);
tprop.ListSelection = index;
}
if (ptup.propValue is string)
else if (ptup.propValue is string)
{
tprop.SetValueFromString((string)ptup.propValue);
}
Expand Down Expand Up @@ -628,10 +632,30 @@ private void GuiHintOrdnanceSelection(ComponentDesignProperty property, GlobalUI

private void GuiHintFuelTypeSelection(ComponentDesignProperty property, GlobalUIState uiState)
{
var cargoTypesToDisplay = new Dictionary<int, ICargoable>();
var keys = new List<int>();

var cargoTypesToDisplay = GetFuelTypes(property, uiState);
var names = new List<string>();
foreach (var cargoType in cargoTypesToDisplay)
{
names.Add(cargoType.Name);
}

string[] arrayNames = names.ToArray();

Title(property.Name, property.Description);

var sizeAvailable = ImGui.GetContentRegionAvail();
ImGui.SetNextItemWidth(sizeAvailable.X);
if(ImGui.Combo("###cargotypeselection", ref property.ListSelection, arrayNames, arrayNames.Length))
{
property.SetValueFromString(cargoTypesToDisplay[property.ListSelection].UniqueID);
}
}

List<ICargoable> GetFuelTypes(ComponentDesignProperty property, GlobalUIState uiState)
{
var cargoTypesToDisplay = new List<ICargoable>();

foreach(string cargoType in property.GuidDictionary.Keys)
{
var fuelType = property.GuidDictionary[cargoType].StrResult;
Expand All @@ -640,29 +664,17 @@ private void GuiHintFuelTypeSelection(ComponentDesignProperty property, GlobalUI
foreach(var cargo in cargos)
{
if(cargo.Value is ProcessedMaterial
&& ((ProcessedMaterial)cargo.Value).Formulas != null
&& ((ProcessedMaterial)cargo.Value).Formulas.ContainsKey("ExhaustVelocity")
&& ((ProcessedMaterial)cargo.Value).Formulas["ExhaustVelocity"].IsNotNullOrEmpty()
&& ((ProcessedMaterial)cargo.Value).Formulas.ContainsKey("FuelType")
&& ((ProcessedMaterial)cargo.Value).Formulas["FuelType"] == fuelType)
&& ((ProcessedMaterial)cargo.Value).Formulas != null
&& ((ProcessedMaterial)cargo.Value).Formulas.ContainsKey("ExhaustVelocity")
&& ((ProcessedMaterial)cargo.Value).Formulas["ExhaustVelocity"].IsNotNullOrEmpty()
&& ((ProcessedMaterial)cargo.Value).Formulas.ContainsKey("FuelType")
&& ((ProcessedMaterial)cargo.Value).Formulas["FuelType"] == fuelType)
{
cargoTypesToDisplay.Add(cargo.Key, cargo.Value);
keys.Add(cargo.Key);
names.Add(cargo.Value.Name);
cargoTypesToDisplay.Add(cargo.Value);
}
}
}

string[] arrayNames = names.ToArray();

Title(property.Name, property.Description);

var sizeAvailable = ImGui.GetContentRegionAvail();
ImGui.SetNextItemWidth(sizeAvailable.X);
if(ImGui.Combo("###cargotypeselection", ref property.ListSelection, arrayNames, arrayNames.Length))
{
property.SetValueFromString(cargoTypesToDisplay[keys[property.ListSelection]].UniqueID);
}
return cargoTypesToDisplay;
}

private void GuiHintTextSelectionFormula(ComponentDesignProperty property)
Expand Down

0 comments on commit 790de0d

Please sign in to comment.