From 05b43865886089973e506dc03cddf29e082cbe1f Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Fri, 13 Oct 2023 20:50:05 -0400 Subject: [PATCH] add GraphicsComponent reflection and factorize code --- .../NazaraEditor/Core/Reflection/Graphics.hpp | 32 ++++++++----------- .../Core/Reflection/Reflection.hpp | 13 ++++++++ src/NazaraEditor/Editor/main.cpp | 3 ++ 3 files changed, 30 insertions(+), 18 deletions(-) diff --git a/include/NazaraEditor/Core/Reflection/Graphics.hpp b/include/NazaraEditor/Core/Reflection/Graphics.hpp index 652053f..b121051 100644 --- a/include/NazaraEditor/Core/Reflection/Graphics.hpp +++ b/include/NazaraEditor/Core/Reflection/Graphics.hpp @@ -47,6 +47,16 @@ namespace Nz } }; + template <> + class TypeReflect + { + public: + template + static void Reflect(TPropertyEnumerator& p, GraphicsComponent& obj) + { + p.AddProperty([&obj]() { return obj.IsVisible(); }, [&obj](bool v) { obj.Show(v); }, "Is Visible", "Toggles mesh visibility"); + } + }; namespace EditorImgui { @@ -57,23 +67,9 @@ namespace Nz inline void End(Nz::LightComponent::LightEntry&) { } - - inline bool Begin(Nz::LightComponent& /*obj*/, const std::string& /*name*/, const std::string& /*tooltip*/) - { - return ImGui::TreeNodeEx("LightComponent", ImGuiTreeNodeFlags_Framed); - } - - inline void End(Nz::LightComponent&) { - ImGui::TreePop(); - } - - inline bool Begin(Nz::CameraComponent& /*obj*/, const std::string& /*name*/, const std::string& /*tooltip*/) - { - return ImGui::TreeNodeEx("CameraComponent", ImGuiTreeNodeFlags_Framed); - } - - inline void End(Nz::CameraComponent&) { - ImGui::TreePop(); - } } + + COMPONENT_IMGUI_FUNCS(LightComponent); + COMPONENT_IMGUI_FUNCS(CameraComponent); + COMPONENT_IMGUI_FUNCS(GraphicsComponent); } \ No newline at end of file diff --git a/include/NazaraEditor/Core/Reflection/Reflection.hpp b/include/NazaraEditor/Core/Reflection/Reflection.hpp index 3f18097..38754d9 100644 --- a/include/NazaraEditor/Core/Reflection/Reflection.hpp +++ b/include/NazaraEditor/Core/Reflection/Reflection.hpp @@ -24,4 +24,17 @@ namespace Nz } } } + +#define COMPONENT_IMGUI_FUNCS(ComponentType) \ +namespace EditorImgui \ +{ \ + inline bool Begin(Nz::ComponentType& /*obj*/, const std::string& /*name*/, const std::string& /*tooltip*/) \ + { \ + return ImGui::TreeNodeEx(#ComponentType, ImGuiTreeNodeFlags_Framed); \ + } \ + \ + inline void End(Nz::ComponentType&) { \ + ImGui::TreePop(); \ + } \ +} } \ No newline at end of file diff --git a/src/NazaraEditor/Editor/main.cpp b/src/NazaraEditor/Editor/main.cpp index ce5a14b..b549d31 100644 --- a/src/NazaraEditor/Editor/main.cpp +++ b/src/NazaraEditor/Editor/main.cpp @@ -43,6 +43,9 @@ int WinMain(int argc, char* argv[]) entt::meta() .type(entt::type_hash::value()) .func<&Nz::ReflectComponent, Nz::LightComponent>>(entt::hashed_string("Reflect")); + entt::meta() + .type(entt::type_hash::value()) + .func<&Nz::ReflectComponent, Nz::GraphicsComponent>>(entt::hashed_string("Reflect")); entt::meta() .type(entt::type_hash::value()) .func<&Nz::ReflectComponent, Nz::EditorNameComponent>>(entt::hashed_string("Reflect"));