Animation WIP merge #321
|
@ -27,6 +27,13 @@
|
|||
|
||||
namespace SHADE
|
||||
{
|
||||
template<typename Component>
|
||||
void EnsureComponent(EntityID eid)
|
||||
{
|
||||
if(SHComponentManager::GetComponent_s<Component>(eid) == nullptr)
|
||||
SHComponentManager::AddComponent<Component>(eid);
|
||||
}
|
||||
|
||||
template<typename ComponentType, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true>
|
||||
bool DrawAddComponentButton(EntityID const& eid)
|
||||
{
|
||||
|
@ -48,9 +55,13 @@ namespace SHADE
|
|||
return selected;
|
||||
}
|
||||
|
||||
template <typename ComponentType, typename EnforcedComponent, std::enable_if_t<std::is_base_of_v<SHComponent, ComponentType>, bool> = true, std::enable_if_t<std::is_base_of_v<SHComponent, EnforcedComponent>, bool> = true>
|
||||
template <typename ComponentType, typename ... EnforcedComponents>
|
||||
bool DrawAddComponentWithEnforcedComponentButton(EntityID const& eid)
|
||||
{
|
||||
// Only make sure components are passed here
|
||||
static_assert(std::is_base_of_v<SHComponent, ComponentType>, "");
|
||||
//(static_assert(std::is_base_of_v<SHComponent, EnforcedComponents>, ""), ...);
|
||||
|
||||
bool selected = false;
|
||||
if (!SHComponentManager::HasComponent<ComponentType>(eid))
|
||||
{
|
||||
|
@ -58,9 +69,8 @@ namespace SHADE
|
|||
|
||||
if(selected = ImGui::Selectable(std::format("Add {}", componentName).data()); selected)
|
||||
{
|
||||
if(SHComponentManager::GetComponent_s<EnforcedComponent>(eid) == nullptr)
|
||||
SHComponentManager::AddComponent<EnforcedComponent>(eid);
|
||||
|
||||
// Ensure that all required components are present
|
||||
(EnsureComponent<EnforcedComponents>(eid), ...);
|
||||
SHComponentManager::AddComponent<ComponentType>(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<EnforcedComponent>().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<EnforcedComponents>().get_name().data()), ...);
|
||||
ImGui::EndTooltip();
|
||||
}
|
||||
}
|
||||
|
@ -118,6 +127,10 @@ namespace SHADE
|
|||
{
|
||||
DrawComponent(renderableComponent);
|
||||
}
|
||||
if (auto animatorComponent = SHComponentManager::GetComponent_s<SHAnimatorComponent>(eid))
|
||||
{
|
||||
DrawComponent(animatorComponent);
|
||||
}
|
||||
if(auto colliderComponent = SHComponentManager::GetComponent_s<SHColliderComponent>(eid))
|
||||
{
|
||||
DrawComponent(colliderComponent);
|
||||
|
@ -174,6 +187,7 @@ namespace SHADE
|
|||
DrawAddComponentWithEnforcedComponentButton<SHRigidBodyComponent, SHTransformComponent>(eid);
|
||||
DrawAddComponentWithEnforcedComponentButton<SHColliderComponent, SHTransformComponent>(eid);
|
||||
DrawAddComponentWithEnforcedComponentButton<SHTextRenderableComponent, SHTransformComponent>(eid);
|
||||
DrawAddComponentWithEnforcedComponentButton<SHAnimatorComponent, SHTransformComponent, SHRenderable>(eid);
|
||||
|
||||
|
||||
ImGui::EndMenu();
|
||||
|
|
Loading…
Reference in New Issue