diff --git a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp index 83647da7..57c8f12a 100644 --- a/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp +++ b/SHADE_Engine/src/Editor/EditorWindow/Inspector/SHEditorInspector.cpp @@ -27,6 +27,13 @@ namespace SHADE { + template + void EnsureComponent(EntityID eid) + { + if(SHComponentManager::GetComponent_s(eid) == nullptr) + SHComponentManager::AddComponent(eid); + } + template, bool> = true> bool DrawAddComponentButton(EntityID const& eid) { @@ -48,9 +55,13 @@ namespace SHADE return selected; } - template , bool> = true, std::enable_if_t, bool> = true> + template bool DrawAddComponentWithEnforcedComponentButton(EntityID const& eid) { + // Only make sure components are passed here + static_assert(std::is_base_of_v, ""); + //(static_assert(std::is_base_of_v, ""), ...); + bool selected = false; if (!SHComponentManager::HasComponent(eid)) { @@ -58,9 +69,8 @@ namespace SHADE if(selected = ImGui::Selectable(std::format("Add {}", componentName).data()); selected) { - if(SHComponentManager::GetComponent_s(eid) == nullptr) - SHComponentManager::AddComponent(eid); - + // Ensure that all required components are present + (EnsureComponent(eid), ...); SHComponentManager::AddComponent(eid); } if(ImGui::IsItemHovered()) @@ -69,9 +79,8 @@ namespace SHADE ImGui::Text("Adds", componentName); ImGui::SameLine(); ImGui::TextColored(ImGuiColors::green, "%s", componentName); ImGui::SameLine(); ImGui::Text("to this entity", componentName); - ImGui::Text("Adds"); ImGui::SameLine(); - ImGui::TextColored(ImGuiColors::red, "%s", rttr::type::get().get_name().data()); ImGui::SameLine(); - ImGui::Text("if the entity does not already have it"); + ImGui::Text("Adds the following components if the entity does not already have it: "); + (ImGui::TextColored(ImGuiColors::red, "%s", rttr::type::get().get_name().data()), ...); ImGui::EndTooltip(); } } @@ -118,6 +127,10 @@ namespace SHADE { DrawComponent(renderableComponent); } + if (auto animatorComponent = SHComponentManager::GetComponent_s(eid)) + { + DrawComponent(animatorComponent); + } if(auto colliderComponent = SHComponentManager::GetComponent_s(eid)) { DrawComponent(colliderComponent); @@ -174,6 +187,7 @@ namespace SHADE DrawAddComponentWithEnforcedComponentButton(eid); DrawAddComponentWithEnforcedComponentButton(eid); DrawAddComponentWithEnforcedComponentButton(eid); + DrawAddComponentWithEnforcedComponentButton(eid); ImGui::EndMenu();