Unravel Engine C++ Reference
Loading...
Searching...
No Matches
inspector_panel.cpp
Go to the documentation of this file.
1#include "inspector_panel.h"
2#include "../panels_defs.h"
4
11#include <engine/ecs/scene.h>
13#include <uuid/uuid.h>
15#include <algorithm>
16#include <functional>
17
18namespace unravel
19{
20
21namespace
22{
23
24auto should_use_prefab_inspection(entt::meta_any& selected) -> bool
25{
26 if(selected.type() != entt::resolve<entt::handle>())
27 {
28 return false;
29 }
30
31 auto entity = selected.cast<entt::handle>();
32 if(!entity)
33 {
34 return false;
35 }
36
37 return true;
38}
39
45auto inspect_object_with_prefab_check(rtti::context& ctx, entt::meta_any& object) -> void
46{
47 auto& override_ctx = ctx.get_cached<prefab_override_context>();
48 auto& inspector_ctx = ctx.get_cached<inspector_context>();
49 // Check if this object should use prefab inspection
50 if(should_use_prefab_inspection(object))
51 {
52 auto entity = object.cast<entt::handle>();
53
54 if(override_ctx.begin_prefab_inspection(entity))
55 {
57 auto proxy = make_entity_proxy(object, name);
58 auto result = inspect_var(ctx, object, proxy);
59
60 override_ctx.end_prefab_inspection();
61 return;
62 }
63 }
64
65 std::string name;
66 if(object.type() == entt::resolve<entt::handle>())
67 {
68 auto entity = object.cast<entt::handle>();
70 }
71
72 // Fall back to normal inspection (empty reference)
73 auto proxy = make_entity_proxy(object, name);
74 auto result = inspect_var(ctx, object, proxy);
75
76}
77
78} // namespace
79
81{
82}
83
90
97
99{
100 auto& em = ctx.get_cached<editing_manager>();
101 auto& selected = em.get_active_selection();
102
103 if(ImGui::BeginMenuBar())
104 {
105 ImGui::PushStyleColor(ImGuiCol_Header, ImGui::GetStyleColorVec4(ImGuiCol_TabSelected));
106 ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImGui::GetStyleColorVec4(ImGuiCol_TabSelected));
107 ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImGui::GetStyleColorVec4(ImGuiCol_TabSelectedOverline));
108
109 bool locked = !!locked_object_;
110
111 if(ImGui::MenuItem(locked ? ICON_MDI_LOCK : ICON_MDI_LOCK_OPEN_VARIANT, nullptr, locked))
112 {
113 locked = !locked;
114
115 if(locked)
116 {
117 locked_object_ = selected;
118 }
119 else
120 {
121 locked_object_ = {};
122 }
123 }
124
125 ImGui::SetItemTooltipEx("%s", "Lock/Unlock Inspector");
126
127 if(ImGui::MenuItem(ICON_MDI_COGS, nullptr, debug_))
128 {
129 debug_ = !debug_;
130 }
131
132 ImGui::SetItemTooltipEx("%s", "Debug View");
133
134 ImGui::PopStyleColor(3);
135
136 ImGui::EndMenuBar();
137 }
138
139 if(debug_)
140 {
142 }
143
144 em.push_undo_stack_enabled(true);
145
146 auto selections_count = int(em.get_selections().size());
147
148 if(locked_object_)
149 {
150 inspect_object_with_prefab_check(ctx, locked_object_);
151 }
152 else if(em.get_selections().size() > 1)
153 {
154 ImGui::Text("%d Items Selected.", selections_count);
155 }
156 else if(selected)
157 {
158 inspect_object_with_prefab_check(ctx, selected);
159 }
160
161 if(debug_)
162 {
164 }
165
166 em.pop_undo_stack_enabled();
167}
168
169} // namespace unravel
static auto get_entity_name(entt::handle entity) -> std::string
Gets the entity name from tag component.
void init(rtti::context &ctx)
void draw_ui(rtti::context &ctx) override
inspector_panel(imgui_panels *parent, const char *name)
void deinit(rtti::context &ctx)
std::string name
Definition hub.cpp:33
#define ICON_MDI_LOCK_OPEN_VARIANT
#define ICON_MDI_COGS
#define ICON_MDI_LOCK
texture_job_type type
auto make_entity_proxy(entt::meta_any &var, const std::string &name) -> meta_any_proxy
Like make_proxy, but for entt::handle roots resolved by id_component UUID each access.
void pop_debug_view()
Pops debug view mode (decreases debug view counter)
void push_debug_view()
Pushes debug view mode (increases debug view counter)
auto inspect_var(rtti::context &ctx, entt::meta_any &var, const meta_any_proxy &var_proxy, const var_info &info, const entt::meta_custom &custom) -> inspect_result
Main entry point for inspecting any variable with automatic type resolution.
entt::handle entity
auto get_cached() -> T &
Definition context.hpp:49
auto add(Args &&... args) -> T &
Definition context.hpp:16
void remove()
Definition context.hpp:78
Registry for managing type-specific inspector instances.
Definition inspectors.h:19
Global context for tracking prefab override changes during inspection.
Definition inspectors.h:99