diff --git a/Editor/src/Windows/EditorSelectionPanel.cpp b/Editor/src/Windows/EditorSelectionPanel.cpp index e7381279..17ba5726 100644 --- a/Editor/src/Windows/EditorSelectionPanel.cpp +++ b/Editor/src/Windows/EditorSelectionPanel.cpp @@ -597,6 +597,8 @@ void EditorSelectionPanel::DrawComponent(const Nuake::Entity& entity, entt::meta void EditorSelectionPanel::DrawComponentContent(entt::meta_any& component) { entt::meta_type componentMeta = component.type(); + + // Draw component bound data for (auto [fst, dataType] : componentMeta.data()) { const ComponentFieldTrait fieldTraits = dataType.traits(); @@ -622,6 +624,33 @@ void EditorSelectionPanel::DrawComponentContent(entt::meta_any& component) ImGui::TableNextRow(); } + + // Draw any actions bound to the component + for (auto [fst, funcMeta] : componentMeta.func()) + { + ImGui::TableSetColumnIndex(0); + + const ComponentFuncTrait funcTraits = funcMeta.traits(); + if ((funcTraits & ComponentFuncTrait::Action) == ComponentFuncTrait::Action) + { + ImGui::TableNextColumn(); + + std::string funcDisplayName = ""; + auto prop = funcMeta.prop(HashedName::DisplayName).value(); + if (prop) + { + funcDisplayName = std::string(*prop.try_cast()); + } + + std::string buttonName = funcDisplayName; + if (UI::SecondaryButton(buttonName.c_str())) + { + entt::meta_any result = funcMeta.invoke(component); + } + + ImGui::TableNextRow(); + } + } } void EditorSelectionPanel::DrawFieldTypeFloat(entt::meta_data& field, entt::meta_any& component) diff --git a/Nuake/src/Core/Object/Object.h b/Nuake/src/Core/Object/Object.h index c8594ed4..2cad7125 100644 --- a/Nuake/src/Core/Object/Object.h +++ b/Nuake/src/Core/Object/Object.h @@ -22,6 +22,7 @@ namespace Nuake { NK_HASHED_STATIC_STR(GetComponentName) NK_HASHED_STATIC_STR(AddToEntity) + NK_HASHED_STATIC_STR(ActionName) }; struct HashedFieldPropName @@ -45,6 +46,13 @@ namespace Nuake InspectorExposed = 1 << 0, }; + enum class ComponentFuncTrait : uint16_t + { + None = 0, + // Exposes the component to be added via the inspector + Action = 1 << 0, + }; + enum class ComponentFieldTrait : uint16_t { None = 0, @@ -61,6 +69,7 @@ namespace Nuake } NK_ENUM_BITWISE_IMPL(ComponentTypeTrait); + NK_ENUM_BITWISE_IMPL(ComponentFuncTrait); NK_ENUM_BITWISE_IMPL(ComponentFieldTrait); } @@ -145,4 +154,13 @@ public: { \ static_assert((std::is_enum_v && ...), "All arguments must be of enum class type"); \ return ComponentFactory.traits((enums | ...)); \ + } \ + \ + template \ + static void BindAction(const char* funcName, const char* actionName) \ + { \ + ComponentFactory \ + .func(entt::hashed_string(funcName)) \ + .prop(HashedName::DisplayName, actionName); \ + SetFlags(ComponentFuncTrait::Action); \ } diff --git a/Nuake/src/Scene/Components/FieldTypes.cpp b/Nuake/src/Scene/Components/FieldTypes.cpp index 10d5f91d..c9ff4278 100644 --- a/Nuake/src/Scene/Components/FieldTypes.cpp +++ b/Nuake/src/Scene/Components/FieldTypes.cpp @@ -16,3 +16,13 @@ std::string Nuake::ResourceFile::GetRelativePath() return ""; } + +std::string Nuake::ResourceFile::GetAbsolutePath() +{ + if (Exist()) + { + return file->GetAbsolutePath(); + } + + return ""; +} diff --git a/Nuake/src/Scene/Components/FieldTypes.h b/Nuake/src/Scene/Components/FieldTypes.h index 0d5e0c70..5d4174e6 100644 --- a/Nuake/src/Scene/Components/FieldTypes.h +++ b/Nuake/src/Scene/Components/FieldTypes.h @@ -15,6 +15,7 @@ namespace Nuake bool Exist(); std::string GetRelativePath(); + std::string GetAbsolutePath(); Ref file = nullptr; };