Files
OpenEngine/editor/include/panels/scene_hierarchy.hpp
Erris e69764e149 cleanup and removing nasty segv upon entity deletion
+ Fixing bug where clicking an entity in the hierarchy didn't update the
stats
2026-02-24 18:10:39 +01:00

53 lines
1.6 KiB
C++

#ifndef SCENE_HIERARCHY_HPP
#define SCENE_HIERARCHY_HPP
#include <entt/core/fwd.hpp>
#include <entt/entity/fwd.hpp>
#include <open_engine.hpp>
namespace OpenEngine {
using ComponentDrawer = std::function<void(entt::registry&, entt::entity)>;
struct ComponentUI {
std::string name;
std::function<void(entt::registry&, entt::entity)> draw_func;
std::function<void(entt::registry&, entt::entity)> remove_func;
};
class SceneHierarchy
{
public:
SceneHierarchy() = default;
SceneHierarchy(const Ref<Scene>& scene);
void Init(const Ref<Scene>& scene);
void OnImGuiRender();
Entity GetSelectedEntity() const { return selected_context; };
void SetSelectedEntity(Entity entity) { selected_context = entity; };
private:
void DrawEntityNode(Entity& entity);
void DrawComponents(Entity& entity);
private:
template<typename T>
static void RegisterDrawer(const std::string& name, std::function<void(entt::registry&, entt::entity)> func) {
drawers[entt::type_id<T>().hash()] = {
name,
func,
[](entt::registry& reg, entt::entity ent) { reg.remove<T>(ent); }
};
}
inline static std::map<entt::id_type, ComponentUI> drawers;
Ref<Scene> scene;
Entity selected_context, renamed_entity;
double last_selected_time = 10.0;
};
}
#endif // SCENE_HIERARCHY_HPP