Editor: 更新编辑器面板和UI控件系统
- 添加新的UI控件系统(Core.h, ScalarControls.h, VectorControls.h, UI.h) - 更新SceneManager支持场景层级管理 - 优化SelectionManager选择管理 - 改进InspectorPanel/GameViewPanel/HierarchyPanel等面板 - 更新RHI文档说明Vulkan实现计划
This commit is contained in:
@@ -4,10 +4,11 @@
|
||||
#include <imgui.h>
|
||||
#include <cstring>
|
||||
|
||||
namespace UI {
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
HierarchyPanel::HierarchyPanel() : Panel("Hierarchy") {
|
||||
SceneManager::Get().CreateDemoScene();
|
||||
EditorSceneManager::Get().CreateDemoScene();
|
||||
|
||||
m_selectionHandlerId = SelectionManager::Get().OnSelectionChanged.Subscribe([this](uint64_t) {
|
||||
});
|
||||
@@ -30,7 +31,7 @@ void HierarchyPanel::Render() {
|
||||
|
||||
ImGui::BeginChild("EntityList");
|
||||
|
||||
for (auto* entity : SceneManager::Get().GetRootEntities()) {
|
||||
for (auto* entity : EditorSceneManager::Get().GetRootEntities()) {
|
||||
RenderEntity(entity, filter);
|
||||
}
|
||||
|
||||
@@ -48,9 +49,9 @@ void HierarchyPanel::Render() {
|
||||
ImGui::InvisibleButton("##DragTarget", ImVec2(-1, -1));
|
||||
if (ImGui::BeginDragDropTarget()) {
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("ENTITY_PTR")) {
|
||||
XCEngine::Components::GameObject* sourceEntity = *(XCEngine::Components::GameObject**)payload->Data;
|
||||
::XCEngine::Components::GameObject* sourceEntity = *(::XCEngine::Components::GameObject**)payload->Data;
|
||||
if (sourceEntity && sourceEntity->GetParent() != nullptr) {
|
||||
SceneManager::Get().MoveEntity(sourceEntity->GetID(), 0);
|
||||
EditorSceneManager::Get().MoveEntity(sourceEntity->GetID(), 0);
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
@@ -66,7 +67,7 @@ void HierarchyPanel::RenderSearchBar() {
|
||||
ImGui::InputTextWithHint("##Search", "Search...", m_searchBuffer, sizeof(m_searchBuffer));
|
||||
}
|
||||
|
||||
void HierarchyPanel::RenderEntity(XCEngine::Components::GameObject* entity, const std::string& filter) {
|
||||
void HierarchyPanel::RenderEntity(::XCEngine::Components::GameObject* entity, const std::string& filter) {
|
||||
if (!entity) return;
|
||||
|
||||
if (!filter.empty() && !PassesFilter(entity, filter)) {
|
||||
@@ -94,7 +95,7 @@ void HierarchyPanel::RenderEntity(XCEngine::Components::GameObject* entity, cons
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
if (ImGui::InputText("##Rename", m_renameBuffer, sizeof(m_renameBuffer), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
if (strlen(m_renameBuffer) > 0) {
|
||||
SceneManager::Get().RenameEntity(entity->GetID(), m_renameBuffer);
|
||||
EditorSceneManager::Get().RenameEntity(entity->GetID(), m_renameBuffer);
|
||||
}
|
||||
m_renaming = false;
|
||||
m_renamingEntity = nullptr;
|
||||
@@ -102,7 +103,7 @@ void HierarchyPanel::RenderEntity(XCEngine::Components::GameObject* entity, cons
|
||||
|
||||
if (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)) {
|
||||
if (strlen(m_renameBuffer) > 0) {
|
||||
SceneManager::Get().RenameEntity(entity->GetID(), m_renameBuffer);
|
||||
EditorSceneManager::Get().RenameEntity(entity->GetID(), m_renameBuffer);
|
||||
}
|
||||
m_renaming = false;
|
||||
m_renamingEntity = nullptr;
|
||||
@@ -139,8 +140,8 @@ void HierarchyPanel::RenderEntity(XCEngine::Components::GameObject* entity, cons
|
||||
ImGui::PopID();
|
||||
}
|
||||
|
||||
void HierarchyPanel::RenderContextMenu(XCEngine::Components::GameObject* entity) {
|
||||
auto& sceneManager = SceneManager::Get();
|
||||
void HierarchyPanel::RenderContextMenu(::XCEngine::Components::GameObject* entity) {
|
||||
auto& sceneManager = EditorSceneManager::Get();
|
||||
auto& selectionManager = SelectionManager::Get();
|
||||
|
||||
if (ImGui::BeginMenu("Create")) {
|
||||
@@ -181,8 +182,8 @@ void HierarchyPanel::RenderContextMenu(XCEngine::Components::GameObject* entity)
|
||||
}
|
||||
}
|
||||
|
||||
void HierarchyPanel::RenderCreateMenu(XCEngine::Components::GameObject* parent) {
|
||||
auto& sceneManager = SceneManager::Get();
|
||||
void HierarchyPanel::RenderCreateMenu(::XCEngine::Components::GameObject* parent) {
|
||||
auto& sceneManager = EditorSceneManager::Get();
|
||||
auto& selectionManager = SelectionManager::Get();
|
||||
|
||||
if (ImGui::MenuItem("Empty Object")) {
|
||||
@@ -194,7 +195,7 @@ void HierarchyPanel::RenderCreateMenu(XCEngine::Components::GameObject* parent)
|
||||
|
||||
if (ImGui::MenuItem("Camera")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Camera", parent);
|
||||
newEntity->AddComponent<XCEngine::Components::TransformComponent>();
|
||||
newEntity->AddComponent<::XCEngine::Components::TransformComponent>();
|
||||
selectionManager.SetSelectedEntity(newEntity);
|
||||
}
|
||||
|
||||
@@ -207,37 +208,39 @@ void HierarchyPanel::RenderCreateMenu(XCEngine::Components::GameObject* parent)
|
||||
|
||||
if (ImGui::MenuItem("Cube")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Cube", parent);
|
||||
newEntity->AddComponent<XCEngine::Components::TransformComponent>();
|
||||
newEntity->AddComponent<::XCEngine::Components::TransformComponent>();
|
||||
selectionManager.SetSelectedEntity(newEntity);
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Sphere")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Sphere", parent);
|
||||
newEntity->AddComponent<XCEngine::Components::TransformComponent>();
|
||||
newEntity->AddComponent<::XCEngine::Components::TransformComponent>();
|
||||
selectionManager.SetSelectedEntity(newEntity);
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Plane")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Plane", parent);
|
||||
newEntity->AddComponent<XCEngine::Components::TransformComponent>();
|
||||
newEntity->AddComponent<::XCEngine::Components::TransformComponent>();
|
||||
selectionManager.SetSelectedEntity(newEntity);
|
||||
}
|
||||
}
|
||||
|
||||
void HierarchyPanel::HandleDragDrop(XCEngine::Components::GameObject* entity) {
|
||||
void HierarchyPanel::HandleDragDrop(::XCEngine::Components::GameObject* entity) {
|
||||
auto& sceneManager = EditorSceneManager::Get();
|
||||
|
||||
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
|
||||
m_dragSource = entity;
|
||||
ImGui::SetDragDropPayload("ENTITY_PTR", &entity, sizeof(XCEngine::Components::GameObject*));
|
||||
ImGui::SetDragDropPayload("ENTITY_PTR", &entity, sizeof(::XCEngine::Components::GameObject*));
|
||||
ImGui::Text("%s", entity->GetName().c_str());
|
||||
ImGui::EndDragDropSource();
|
||||
}
|
||||
|
||||
if (ImGui::BeginDragDropTarget()) {
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("ENTITY_PTR")) {
|
||||
XCEngine::Components::GameObject* sourceEntity = *(XCEngine::Components::GameObject**)payload->Data;
|
||||
::XCEngine::Components::GameObject* sourceEntity = *(::XCEngine::Components::GameObject**)payload->Data;
|
||||
if (sourceEntity != entity && sourceEntity != nullptr) {
|
||||
bool isValidMove = true;
|
||||
XCEngine::Components::GameObject* checkParent = entity;
|
||||
::XCEngine::Components::GameObject* checkParent = entity;
|
||||
while (checkParent != nullptr) {
|
||||
if (checkParent == sourceEntity) {
|
||||
isValidMove = false;
|
||||
@@ -256,10 +259,10 @@ void HierarchyPanel::HandleDragDrop(XCEngine::Components::GameObject* entity) {
|
||||
}
|
||||
|
||||
void HierarchyPanel::HandleKeyboardShortcuts() {
|
||||
auto& sceneManager = SceneManager::Get();
|
||||
auto& sceneManager = EditorSceneManager::Get();
|
||||
auto& selectionManager = SelectionManager::Get();
|
||||
|
||||
XCEngine::Components::GameObject* selectedEntity = selectionManager.GetSelectedEntity();
|
||||
::XCEngine::Components::GameObject* selectedEntity = selectionManager.GetSelectedEntity();
|
||||
|
||||
if (ImGui::IsWindowFocused()) {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Delete)) {
|
||||
@@ -300,7 +303,7 @@ void HierarchyPanel::HandleKeyboardShortcuts() {
|
||||
}
|
||||
}
|
||||
|
||||
bool HierarchyPanel::PassesFilter(XCEngine::Components::GameObject* entity, const std::string& filter) {
|
||||
bool HierarchyPanel::PassesFilter(::XCEngine::Components::GameObject* entity, const std::string& filter) {
|
||||
if (!entity) return false;
|
||||
|
||||
if (entity->GetName().find(filter) != std::string::npos) {
|
||||
@@ -317,3 +320,4 @@ bool HierarchyPanel::PassesFilter(XCEngine::Components::GameObject* entity, cons
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user