Refine inspector layout and fix header labels
This commit is contained in:
@@ -44,7 +44,7 @@ void InspectorPanel::RenderEntity(Entity* entity) {
|
|||||||
void InspectorPanel::RenderComponent(Component* component) {
|
void InspectorPanel::RenderComponent(Component* component) {
|
||||||
if (!component) return;
|
if (!component) return;
|
||||||
|
|
||||||
const char* name = component->GetName().c_str();
|
const std::string name = component->GetName();
|
||||||
|
|
||||||
std::string headerId = name + std::string("##") + std::to_string(reinterpret_cast<uintptr_t>(component));
|
std::string headerId = name + std::string("##") + std::to_string(reinterpret_cast<uintptr_t>(component));
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,9 @@ void InspectorPanel::OnSelectionChanged(const SelectionChangedEvent& event) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void InspectorPanel::Render() {
|
void InspectorPanel::Render() {
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0.0f, 0.0f));
|
||||||
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
ImGui::Begin(m_name.c_str(), nullptr, ImGuiWindowFlags_None);
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
if (!m_selectionHandlerId && m_context) {
|
if (!m_selectionHandlerId && m_context) {
|
||||||
m_selectionHandlerId = m_context->GetEventBus().Subscribe<SelectionChangedEvent>(
|
m_selectionHandlerId = m_context->GetEventBus().Subscribe<SelectionChangedEvent>(
|
||||||
@@ -48,41 +50,43 @@ void InspectorPanel::Render() {
|
|||||||
if (gameObject) {
|
if (gameObject) {
|
||||||
RenderGameObject(gameObject);
|
RenderGameObject(gameObject);
|
||||||
} else {
|
} else {
|
||||||
|
ImGui::SetCursorPos(ImVec2(10.0f, 10.0f));
|
||||||
ImGui::Text("Object not found");
|
ImGui::Text("Object not found");
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ImGui::Text("No object selected");
|
ImGui::SetCursorPos(ImVec2(10.0f, 10.0f));
|
||||||
ImGui::TextColored(ImVec4(0.5f, 0.5f, 0.5f, 1.0f), "Select an object in Hierarchy");
|
ImGui::Text("No Selection");
|
||||||
|
ImGui::SetCursorPos(ImVec2(10.0f, 30.0f));
|
||||||
|
ImGui::TextColored(ImVec4(0.55f, 0.55f, 0.55f, 1.0f), "Select an object in Hierarchy");
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectorPanel::RenderGameObject(::XCEngine::Components::GameObject* gameObject) {
|
void InspectorPanel::RenderGameObject(::XCEngine::Components::GameObject* gameObject) {
|
||||||
char nameBuffer[256];
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
strcpy_s(nameBuffer, gameObject->GetName().c_str());
|
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10.0f, 0.0f));
|
||||||
ImGui::InputText("##Name", nameBuffer, sizeof(nameBuffer));
|
ImGui::BeginChild("InspectorContent", ImVec2(0.0f, 0.0f), false, ImGuiWindowFlags_None);
|
||||||
if (ImGui::IsItemDeactivatedAfterEdit()) {
|
ImGui::PopStyleVar();
|
||||||
UndoUtils::ExecuteSceneCommand(*m_context, "Rename Entity", [&]() {
|
|
||||||
m_context->GetSceneManager().RenameEntity(gameObject->GetID(), nameBuffer);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SameLine();
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x, 0.0f));
|
||||||
if (ImGui::Button("Add Component")) {
|
|
||||||
ImGui::OpenPopup("AddComponent");
|
|
||||||
}
|
|
||||||
|
|
||||||
RenderAddComponentPopup(gameObject);
|
|
||||||
|
|
||||||
auto components = gameObject->GetComponents<::XCEngine::Components::Component>();
|
auto components = gameObject->GetComponents<::XCEngine::Components::Component>();
|
||||||
for (auto* component : components) {
|
for (auto* component : components) {
|
||||||
RenderComponent(component, gameObject);
|
RenderComponent(component, gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (ImGui::Button("Add Component", ImVec2(-1.0f, 0.0f))) {
|
||||||
|
ImGui::OpenPopup("AddComponent");
|
||||||
|
}
|
||||||
|
RenderAddComponentPopup(gameObject);
|
||||||
|
ImGui::PopStyleVar();
|
||||||
|
|
||||||
if (m_context->GetUndoManager().HasPendingInteractiveChange() && !ImGui::IsAnyItemActive()) {
|
if (m_context->GetUndoManager().HasPendingInteractiveChange() && !ImGui::IsAnyItemActive()) {
|
||||||
m_context->GetUndoManager().FinalizeInteractiveChange();
|
m_context->GetUndoManager().FinalizeInteractiveChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ImGui::EndChild();
|
||||||
}
|
}
|
||||||
|
|
||||||
void InspectorPanel::RenderAddComponentPopup(::XCEngine::Components::GameObject* gameObject) {
|
void InspectorPanel::RenderAddComponentPopup(::XCEngine::Components::GameObject* gameObject) {
|
||||||
@@ -136,10 +140,12 @@ void InspectorPanel::RenderComponent(::XCEngine::Components::Component* componen
|
|||||||
if (!component) return;
|
if (!component) return;
|
||||||
|
|
||||||
IComponentEditor* editor = ComponentEditorRegistry::Get().FindEditor(component);
|
IComponentEditor* editor = ComponentEditorRegistry::Get().FindEditor(component);
|
||||||
|
ImGuiStyle& style = ImGui::GetStyle();
|
||||||
|
|
||||||
const char* name = component->GetName().c_str();
|
const std::string name = component->GetName();
|
||||||
|
|
||||||
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{4, 2});
|
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2{6, 4});
|
||||||
|
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(style.ItemSpacing.x, 0.0f));
|
||||||
|
|
||||||
ImGuiTreeNodeFlags flags =
|
ImGuiTreeNodeFlags flags =
|
||||||
ImGuiTreeNodeFlags_DefaultOpen |
|
ImGuiTreeNodeFlags_DefaultOpen |
|
||||||
@@ -148,9 +154,9 @@ void InspectorPanel::RenderComponent(::XCEngine::Components::Component* componen
|
|||||||
ImGuiTreeNodeFlags_FramePadding |
|
ImGuiTreeNodeFlags_FramePadding |
|
||||||
ImGuiTreeNodeFlags_AllowOverlap;
|
ImGuiTreeNodeFlags_AllowOverlap;
|
||||||
|
|
||||||
bool open = ImGui::TreeNodeEx((void*)typeid(*component).hash_code(), flags, "%s", name);
|
bool open = ImGui::TreeNodeEx((void*)typeid(*component).hash_code(), flags, "%s", name.c_str());
|
||||||
|
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar(2);
|
||||||
|
|
||||||
bool removeComponent = false;
|
bool removeComponent = false;
|
||||||
const bool canRemoveComponent = editor ? editor->CanRemove(component) : false;
|
const bool canRemoveComponent = editor ? editor->CanRemove(component) : false;
|
||||||
|
|||||||
Reference in New Issue
Block a user