add NameComponent and rework level and inspector windows
This commit is contained in:
parent
e48605b8d3
commit
d6ecfb3476
|
|
@ -4,6 +4,7 @@
|
|||
#include <NazaraEditor/Core/Application/Action.hpp>
|
||||
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
|
||||
#include <NazaraEditor/Core/Application/Level.hpp>
|
||||
#include <NazaraEditor/Core/Components/NameComponent.hpp>
|
||||
#include <NazaraEditor/Core/UI/Window.hpp>
|
||||
#include <NazaraEditor/Core/Reflection/Math.hpp>
|
||||
#include <NazaraEditor/Core/Reflection/Core.hpp>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,37 @@
|
|||
#pragma once
|
||||
|
||||
#include <NazaraEditor/Core/Config.hpp>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
enum EditorEntityFlags : uint64_t
|
||||
{
|
||||
EditorEntityFlags_None = 0,
|
||||
|
||||
EditorEntityFlags_Hidden = 1 << 1,
|
||||
};
|
||||
|
||||
class NAZARAEDITOR_CORE_API EditorNameComponent
|
||||
{
|
||||
public:
|
||||
EditorNameComponent() = default;
|
||||
EditorNameComponent(const EditorNameComponent&) = delete;
|
||||
EditorNameComponent(EditorNameComponent&&) = default;
|
||||
~EditorNameComponent() = default;
|
||||
|
||||
EditorNameComponent& operator=(const EditorNameComponent&) = delete;
|
||||
EditorNameComponent& operator=(EditorNameComponent&&) = default;
|
||||
|
||||
void SetName(const std::string& name) { m_name = name; }
|
||||
const std::string& GetName() const { return m_name; }
|
||||
|
||||
void SetFlags(const uint64_t flags) { m_flags = flags; }
|
||||
uint64_t GetFlags() const { return m_flags; }
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
uint64_t m_flags;
|
||||
};
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@
|
|||
#include <vector>
|
||||
#include <string>
|
||||
#include <imgui.h>
|
||||
#include <imgui_stdlib.h>
|
||||
|
||||
namespace Nz
|
||||
{
|
||||
|
|
@ -44,6 +45,18 @@ namespace Nz
|
|||
inline void End(Color&) {}
|
||||
}
|
||||
|
||||
namespace EditorImgui
|
||||
{
|
||||
inline bool Begin(std::string& obj, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
ImGui::InputText(name.c_str(), &obj);
|
||||
Tooltip(tooltip);
|
||||
return false;
|
||||
}
|
||||
|
||||
inline void End(std::string&) {}
|
||||
}
|
||||
|
||||
// Wrapper for array values
|
||||
template <typename T>
|
||||
struct ArrayEntry
|
||||
|
|
@ -126,8 +139,7 @@ namespace Nz
|
|||
{
|
||||
inline bool Begin(entt::handle& /*obj*/, const std::string& name, const std::string& /*tooltip*/)
|
||||
{
|
||||
std::string n = "Entity " + name;
|
||||
return ImGui::TreeNode(n.c_str());
|
||||
return ImGui::TreeNode(name.c_str());
|
||||
}
|
||||
|
||||
inline void End(entt::handle&) {
|
||||
|
|
|
|||
|
|
@ -5,12 +5,33 @@
|
|||
|
||||
namespace Nz
|
||||
{
|
||||
template <>
|
||||
class TypeReflect<EditorNameComponent>
|
||||
{
|
||||
public:
|
||||
template <typename TPropertyEnumerator>
|
||||
static void Reflect(TPropertyEnumerator& p, EditorNameComponent& obj)
|
||||
{
|
||||
p.AddProperty([&obj]() { return obj.GetName(); }, [&obj](const std::string& v) { obj.SetName(v); }, "Name", "Entity Name");
|
||||
}
|
||||
};
|
||||
|
||||
namespace EditorImgui
|
||||
{
|
||||
inline bool Begin(Nz::EditorNameComponent& /*obj*/, const std::string& /*name*/, const std::string& /*tooltip*/) { return true; }
|
||||
|
||||
inline void End(Nz::EditorNameComponent& /*obj*/) { }
|
||||
}
|
||||
|
||||
template <typename TPropertyDetail>
|
||||
struct EditorPropertyInspector
|
||||
{
|
||||
template <typename T>
|
||||
void AddProperty(T& prop, const std::string& name, const std::string& tooltip);
|
||||
|
||||
template <typename T>
|
||||
void AddPropertyNoWrapper(T& prop, const std::string& name, const std::string& tooltip);
|
||||
|
||||
/*template <typename T, typename U, typename V>
|
||||
void AddProperty(T& parent, V(U::* Getter)() const, void(U::*Setter(const V&))(), const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -12,4 +12,10 @@ namespace Nz
|
|||
}
|
||||
}
|
||||
|
||||
template <typename TPropertyDetail>
|
||||
template <typename T> void EditorPropertyInspector<TPropertyDetail>::AddPropertyNoWrapper(T& prop, const std::string& name, const std::string& tooltip)
|
||||
{
|
||||
TypeReflect<T>::Reflect(*this, prop);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -42,7 +42,7 @@ namespace Nz
|
|||
|
||||
inline bool Begin(Nz::LightComponent& /*obj*/, const std::string& /*name*/, const std::string& /*tooltip*/)
|
||||
{
|
||||
return ImGui::TreeNode("LightComponent");
|
||||
return ImGui::TreeNodeEx("LightComponent", ImGuiTreeNodeFlags_Framed);
|
||||
}
|
||||
|
||||
inline void End(Nz::LightComponent&) {
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ namespace Nz
|
|||
{
|
||||
inline bool Begin(Nz::NodeComponent& /*obj*/, const std::string& /*name*/, const std::string& /*tooltip*/)
|
||||
{
|
||||
return ImGui::TreeNode("NodeComponent");
|
||||
return ImGui::TreeNodeEx("NodeComponent", ImGuiTreeNodeFlags_Framed);
|
||||
}
|
||||
|
||||
inline void End(Nz::NodeComponent& /*obj*/) {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ namespace NzEditor
|
|||
return;
|
||||
|
||||
Nz::EditorPropertyInspector<Nz::EditorRenderer> enumerator;
|
||||
enumerator.AddProperty(m_currentEntity, "", "");
|
||||
enumerator.AddPropertyNoWrapper(m_currentEntity, "", "");
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
#include <NazaraEditor/Editor/UI/LevelWindow.hpp>
|
||||
|
||||
#include <NazaraEditor/Editor/Application.hpp>
|
||||
#include <NazaraEditor/Core.hpp>
|
||||
|
||||
namespace NzEditor
|
||||
{
|
||||
|
|
@ -22,9 +23,11 @@ namespace NzEditor
|
|||
std::function<void(Nz::Node*)> drawHierarchy = [&](Nz::Node* c)
|
||||
{
|
||||
entt::handle entity = m_nodeToEntity[c];
|
||||
std::ostringstream oss;
|
||||
oss << "(" << (uint32_t)entity.entity() << ")";
|
||||
if (Nz::EditorImgui::Begin(entity, oss.str(), ""))
|
||||
Nz::EditorNameComponent* nameComponent = entity.try_get<Nz::EditorNameComponent>();
|
||||
if (nameComponent->GetFlags() & Nz::EditorEntityFlags_Hidden)
|
||||
return;
|
||||
|
||||
if (Nz::EditorImgui::Begin(entity, nameComponent->GetName(), ""))
|
||||
{
|
||||
for (auto& child : c->GetChilds())
|
||||
drawHierarchy(child);
|
||||
|
|
|
|||
|
|
@ -40,6 +40,9 @@ int WinMain(int argc, char* argv[])
|
|||
entt::meta<Nz::LightComponent>()
|
||||
.type(entt::type_hash<Nz::LightComponent>::value())
|
||||
.func<&Nz::ReflectComponent<Nz::EditorPropertyInspector<Nz::EditorRenderer>, Nz::LightComponent>>(entt::hashed_string("Reflect"));
|
||||
entt::meta<Nz::EditorNameComponent>()
|
||||
.type(entt::type_hash<Nz::EditorNameComponent>::value())
|
||||
.func<&Nz::ReflectComponent<Nz::EditorPropertyInspector<Nz::EditorRenderer>, Nz::EditorNameComponent>>(entt::hashed_string("Reflect"));
|
||||
|
||||
entt::handle entity = app.CreateEntity();
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue