diff --git a/Pulsar4X/Pulsar4X.Client/Interface/Displays/ComponentDesignDisplay.cs b/Pulsar4X/Pulsar4X.Client/Interface/Displays/ComponentDesignDisplay.cs index 7fabb573f..e701bf8da 100644 --- a/Pulsar4X/Pulsar4X.Client/Interface/Displays/ComponentDesignDisplay.cs +++ b/Pulsar4X/Pulsar4X.Client/Interface/Displays/ComponentDesignDisplay.cs @@ -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); } @@ -628,10 +632,30 @@ private void GuiHintOrdnanceSelection(ComponentDesignProperty property, GlobalUI private void GuiHintFuelTypeSelection(ComponentDesignProperty property, GlobalUIState uiState) { - var cargoTypesToDisplay = new Dictionary(); - var keys = new List(); + + var cargoTypesToDisplay = GetFuelTypes(property, uiState); var names = new List(); + 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 GetFuelTypes(ComponentDesignProperty property, GlobalUIState uiState) + { + var cargoTypesToDisplay = new List(); + foreach(string cargoType in property.GuidDictionary.Keys) { var fuelType = property.GuidDictionary[cargoType].StrResult; @@ -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)