diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index a741ba1a..e7381279 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -33,6 +33,7 @@ EditorSelectionPanel::EditorSelectionPanel() REGISTER_TYPE_DRAWER(Vector3, EditorSelectionPanel::DrawFieldTypeVector3); REGISTER_TYPE_DRAWER(std::string, EditorSelectionPanel::DrawFieldTypeString); REGISTER_TYPE_DRAWER(ResourceFile, EditorSelectionPanel::DrawFieldTypeResourceFile); + REGISTER_TYPE_DRAWER(DynamicItemList, EditorSelectionPanel::DrawFieldTypeDynamicItemList); } void EditorSelectionPanel::ResolveFile(Ref file) @@ -783,3 +784,57 @@ void EditorSelectionPanel::DrawFieldTypeResourceFile(entt::meta_data& field, ent } } +void EditorSelectionPanel::DrawFieldTypeDynamicItemList(entt::meta_data& field, entt::meta_any& component) +{ + auto propDisplayName = field.prop(HashedName::DisplayName); + const char* displayName = *propDisplayName.value().try_cast(); + if (displayName != nullptr) + { + ImGui::Text(displayName); + ImGui::TableNextColumn(); + + auto fieldVal = field.get(component); + auto fieldValPtr = fieldVal.try_cast(); + if (fieldValPtr == nullptr) + { + ImGui::Text("ERR"); + } + + const auto& items = fieldValPtr->items; + const int index = fieldValPtr->index; + + // Check first to see if we are within the bounds + std::string selectedStr = ""; + if (index >= 0 || index < items.size()) + { + selectedStr = items[index]; + } + + std::string controlName = std::string("##") + displayName; + if (ImGui::BeginCombo(controlName.c_str(), selectedStr.c_str())) + { + for (int i = 0; i < items.size(); i++) + { + bool isSelected = (index == i); + std::string name = items[i]; + + if (name.empty()) + { + name = "Empty"; + } + + if (ImGui::Selectable(name.c_str(), isSelected)) + { + field.set(component, i); + } + + if (isSelected) + { + ImGui::SetItemDefaultFocus(); + } + } + ImGui::EndCombo(); + } + } +} + diff --git a/Editor/src/Windows/EditorSelectionPanel.h b/Editor/src/Windows/EditorSelectionPanel.h index 7bb92e3d..acc7b2a8 100644 --- a/Editor/src/Windows/EditorSelectionPanel.h +++ b/Editor/src/Windows/EditorSelectionPanel.h @@ -99,4 +99,5 @@ private: void DrawFieldTypeVector3(entt::meta_data& field, entt::meta_any& component); void DrawFieldTypeString(entt::meta_data& field, entt::meta_any& component); void DrawFieldTypeResourceFile(entt::meta_data& field, entt::meta_any& component); + void DrawFieldTypeDynamicItemList(entt::meta_data& field, entt::meta_any& component); }; \ No newline at end of file diff --git a/Nuake/src/Scene/Components/FieldTypes.h b/Nuake/src/Scene/Components/FieldTypes.h index da5acaa7..0d5e0c70 100644 --- a/Nuake/src/Scene/Components/FieldTypes.h +++ b/Nuake/src/Scene/Components/FieldTypes.h @@ -10,7 +10,7 @@ namespace Nuake struct ResourceFile { - ResourceFile() {} + ResourceFile() = default; ResourceFile(const Ref& inFile) : file(inFile) {} bool Exist(); @@ -18,4 +18,10 @@ namespace Nuake Ref file = nullptr; }; + + struct DynamicItemList + { + std::vector items; + int index = -1; + }; }