diff --git a/ScriptCore/Editor/EntityEditor.cs b/ScriptCore/Editor/EntityEditor.cs index 05ba826..8183b6f 100644 --- a/ScriptCore/Editor/EntityEditor.cs +++ b/ScriptCore/Editor/EntityEditor.cs @@ -650,17 +650,11 @@ internal class EntityEditor { if (reference == null) { - if (ImGui.BeginCombo("##Create", "Create instance...", ImGuiComboFlags.HeightSmall | ImGuiComboFlags.NoArrowButton)) - { - foreach (Type t in TypeExtension.FindDerivedTypes(fieldType)) - { - if (ImGui.Selectable(t.Name)) - { - newValue = ActivatorExtension.CreateInstanceSafe(t); - } - } + Type? selectedType = ShowTypeDropdown("##Create", "Create instance...", fieldType); - ImGui.EndCombo(); + if (selectedType != null) + { + newValue = ActivatorExtension.CreateInstanceSafe(selectedType); } } else @@ -690,6 +684,40 @@ internal class EntityEditor return newValue; } + /// + /// Shows a dropdown of all types that can be assigned to the given baseType. + /// + /// The label of the combo box. + /// The preview value that will be shown in the combo box. + /// The base type of the types that can be selected. + /// The selected type; or if no type was selected. + private static Type? ShowTypeDropdown(string label, string? previewValue, Type baseType) + { + Type? selectedType = null; + + if (ImGui.BeginCombo(label, previewValue, ImGuiComboFlags.HeightSmall | ImGuiComboFlags.NoArrowButton)) + { + foreach (Type t in TypeExtension.FindDerivedTypes(baseType)) + { + if (t.IsGenericType) + { + // TODO: Generic types + } + else + { + if (ImGui.Selectable(t.Name)) + { + selectedType = t; + } + } + } + + ImGui.EndCombo(); + } + + return selectedType; + } + private static object? ShowComponentDropTarget(string fieldName, Type fieldType, object? currentValue, IEnumerable? attributes) { object? newValue = DidNotChange;