mirror of
https://github.com/enduro2d/enduro2d.git
synced 2025-12-16 14:08:59 +07:00
basic hierarchy and inspector widgets impl
This commit is contained in:
@@ -6,6 +6,78 @@
|
|||||||
|
|
||||||
#include "hierarchy_widget.hpp"
|
#include "hierarchy_widget.hpp"
|
||||||
|
|
||||||
|
#include <enduro2d/high/editor.hpp>
|
||||||
|
#include <enduro2d/high/gobject.hpp>
|
||||||
|
#include <enduro2d/high/node.hpp>
|
||||||
|
#include <enduro2d/high/world.hpp>
|
||||||
|
|
||||||
|
#include <enduro2d/high/components/actor.hpp>
|
||||||
|
#include <enduro2d/high/components/named.hpp>
|
||||||
|
#include <enduro2d/high/components/scene.hpp>
|
||||||
|
|
||||||
|
namespace
|
||||||
|
{
|
||||||
|
using namespace e2d;
|
||||||
|
|
||||||
|
void show_tree_for_node(const const_node_iptr& root) {
|
||||||
|
const gobject owner = root ? root->owner() : gobject();
|
||||||
|
if ( !owner ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const str basic_name = owner.component<scene>().exists()
|
||||||
|
? "Scene"
|
||||||
|
: "Node";
|
||||||
|
|
||||||
|
const str component_name = owner.component<named>()
|
||||||
|
? owner.component<named>()->name()
|
||||||
|
: str();
|
||||||
|
|
||||||
|
const str tree_node_name = component_name.empty()
|
||||||
|
? basic_name
|
||||||
|
: strings::rformat("%0(%1)", basic_name, component_name);
|
||||||
|
|
||||||
|
ImGui::PushID(root.get());
|
||||||
|
E2D_DEFER([](){ ImGui::PopID(); });
|
||||||
|
|
||||||
|
ImGuiTreeNodeFlags tree_node_flags =
|
||||||
|
ImGuiTreeNodeFlags_OpenOnArrow |
|
||||||
|
ImGuiTreeNodeFlags_OpenOnDoubleClick;
|
||||||
|
|
||||||
|
if ( !root->has_children() ) {
|
||||||
|
tree_node_flags |= ImGuiTreeNodeFlags_Leaf;
|
||||||
|
}
|
||||||
|
|
||||||
|
editor& e = the<editor>();
|
||||||
|
|
||||||
|
if ( e.selection() == owner ) {
|
||||||
|
tree_node_flags |= ImGuiTreeNodeFlags_Selected;
|
||||||
|
}
|
||||||
|
|
||||||
|
const bool tree_node_opened =
|
||||||
|
ImGui::TreeNodeEx(tree_node_name.c_str(), tree_node_flags);
|
||||||
|
|
||||||
|
if ( ImGui::IsItemClicked() ) {
|
||||||
|
e.select(owner);
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( tree_node_opened ) {
|
||||||
|
E2D_DEFER([](){ ImGui::TreePop(); });
|
||||||
|
|
||||||
|
root->for_each_child([](const const_node_iptr& child){
|
||||||
|
show_tree_for_node(child);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void show_tree_for_all_scenes(const ecs::registry& owner) {
|
||||||
|
owner.for_joined_components<scene, actor>(
|
||||||
|
[](const ecs::const_entity&, const scene&, const actor& a){
|
||||||
|
show_tree_for_node(a.node());
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
namespace e2d::dbgui_widgets
|
namespace e2d::dbgui_widgets
|
||||||
{
|
{
|
||||||
hierarchy_widget::hierarchy_widget() {
|
hierarchy_widget::hierarchy_widget() {
|
||||||
@@ -14,6 +86,16 @@ namespace e2d::dbgui_widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool hierarchy_widget::show() {
|
bool hierarchy_widget::show() {
|
||||||
|
if ( !modules::is_initialized<editor>() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !modules::is_initialized<world>() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
show_tree_for_all_scenes(the<world>().registry());
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,6 +6,10 @@
|
|||||||
|
|
||||||
#include "inspector_widget.hpp"
|
#include "inspector_widget.hpp"
|
||||||
|
|
||||||
|
#include <enduro2d/high/editor.hpp>
|
||||||
|
#include <enduro2d/high/gobject.hpp>
|
||||||
|
#include <enduro2d/high/inspector.hpp>
|
||||||
|
|
||||||
namespace e2d::dbgui_widgets
|
namespace e2d::dbgui_widgets
|
||||||
{
|
{
|
||||||
inspector_widget::inspector_widget() {
|
inspector_widget::inspector_widget() {
|
||||||
@@ -14,6 +18,17 @@ namespace e2d::dbgui_widgets
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool inspector_widget::show() {
|
bool inspector_widget::show() {
|
||||||
|
if ( !modules::is_initialized<editor>() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ( !modules::is_initialized<inspector>() ) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
gobject go = the<editor>().selection();
|
||||||
|
the<inspector>().show_inspector_for(go);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user