docs: 更新 containers 和 threading 模块文档
- containers: 更新 string 类的多个方法文档 - threading: 更新 mutex 和 task-group 方法文档
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
#include "Core/IEditorContext.h"
|
||||
#include "Core/ISceneManager.h"
|
||||
#include "Core/ISelectionManager.h"
|
||||
#include "Core/IUndoManager.h"
|
||||
#include "Core/EditorEvents.h"
|
||||
#include "Core/EventBus.h"
|
||||
#include "Utils/UndoUtils.h"
|
||||
#include <XCEngine/Core/Math/Vector3.h>
|
||||
#include <XCEngine/Core/Math/Quaternion.h>
|
||||
#include <XCEngine/Components/CameraComponent.h>
|
||||
@@ -73,16 +75,19 @@ void HierarchyPanel::Render() {
|
||||
::XCEngine::Components::GameObject* sourceGameObject = *(::XCEngine::Components::GameObject**)payload->Data;
|
||||
if (sourceGameObject && sourceGameObject->GetParent() != nullptr) {
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
auto* srcTransform = sourceGameObject->GetTransform();
|
||||
Math::Vector3 worldPos = srcTransform->GetPosition();
|
||||
Math::Quaternion worldRot = srcTransform->GetRotation();
|
||||
Math::Vector3 worldScale = srcTransform->GetScale();
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Reparent Entity", [&]() {
|
||||
auto* srcTransform = sourceGameObject->GetTransform();
|
||||
Math::Vector3 worldPos = srcTransform->GetPosition();
|
||||
Math::Quaternion worldRot = srcTransform->GetRotation();
|
||||
Math::Vector3 worldScale = srcTransform->GetScale();
|
||||
|
||||
sceneManager.MoveEntity(sourceGameObject->GetID(), 0);
|
||||
sceneManager.MoveEntity(sourceGameObject->GetID(), 0);
|
||||
|
||||
srcTransform->SetPosition(worldPos);
|
||||
srcTransform->SetRotation(worldRot);
|
||||
srcTransform->SetScale(worldScale);
|
||||
srcTransform->SetPosition(worldPos);
|
||||
srcTransform->SetRotation(worldRot);
|
||||
srcTransform->SetScale(worldScale);
|
||||
sceneManager.MarkSceneDirty();
|
||||
});
|
||||
}
|
||||
}
|
||||
ImGui::EndDragDropTarget();
|
||||
@@ -133,7 +138,9 @@ void HierarchyPanel::RenderEntity(::XCEngine::Components::GameObject* gameObject
|
||||
ImGui::SetNextItemWidth(-1);
|
||||
if (ImGui::InputText("##Rename", m_renameBuffer, sizeof(m_renameBuffer), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)) {
|
||||
if (strlen(m_renameBuffer) > 0) {
|
||||
m_context->GetSceneManager().RenameEntity(gameObject->GetID(), m_renameBuffer);
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Rename Entity", [&]() {
|
||||
m_context->GetSceneManager().RenameEntity(gameObject->GetID(), m_renameBuffer);
|
||||
});
|
||||
}
|
||||
m_renaming = false;
|
||||
m_renamingEntity = nullptr;
|
||||
@@ -141,7 +148,9 @@ void HierarchyPanel::RenderEntity(::XCEngine::Components::GameObject* gameObject
|
||||
|
||||
if (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)) {
|
||||
if (strlen(m_renameBuffer) > 0) {
|
||||
m_context->GetSceneManager().RenameEntity(gameObject->GetID(), m_renameBuffer);
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Rename Entity", [&]() {
|
||||
m_context->GetSceneManager().RenameEntity(gameObject->GetID(), m_renameBuffer);
|
||||
});
|
||||
}
|
||||
m_renaming = false;
|
||||
m_renamingEntity = nullptr;
|
||||
@@ -195,15 +204,19 @@ void HierarchyPanel::RenderContextMenu(::XCEngine::Components::GameObject* gameO
|
||||
}
|
||||
|
||||
if (gameObject != nullptr && ImGui::MenuItem("Create Child")) {
|
||||
auto* child = sceneManager.CreateEntity("GameObject", gameObject);
|
||||
selectionManager.SetSelectedEntity(child->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Create Child", [&]() {
|
||||
auto* child = sceneManager.CreateEntity("GameObject", gameObject);
|
||||
selectionManager.SetSelectedEntity(child->GetID());
|
||||
});
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (gameObject != nullptr && gameObject->GetParent() != nullptr) {
|
||||
if (ImGui::MenuItem("Detach from Parent")) {
|
||||
sceneManager.MoveEntity(gameObject->GetID(), 0);
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Reparent Entity", [&]() {
|
||||
sceneManager.MoveEntity(gameObject->GetID(), 0);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -217,7 +230,9 @@ void HierarchyPanel::RenderContextMenu(::XCEngine::Components::GameObject* gameO
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Delete", "Delete")) {
|
||||
sceneManager.DeleteEntity(gameObject->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Delete Entity", [&]() {
|
||||
sceneManager.DeleteEntity(gameObject->GetID());
|
||||
});
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
@@ -227,11 +242,22 @@ void HierarchyPanel::RenderContextMenu(::XCEngine::Components::GameObject* gameO
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Paste", "Ctrl+V", false, sceneManager.HasClipboardData())) {
|
||||
sceneManager.PasteEntity(gameObject->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Paste Entity", [&]() {
|
||||
const uint64_t newId = sceneManager.PasteEntity(gameObject->GetID());
|
||||
if (newId != 0) {
|
||||
selectionManager.SetSelectedEntity(newId);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Duplicate", "Ctrl+D")) {
|
||||
uint64_t newId = sceneManager.DuplicateEntity(gameObject->GetID());
|
||||
uint64_t newId = 0;
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Duplicate Entity", [&]() {
|
||||
newId = sceneManager.DuplicateEntity(gameObject->GetID());
|
||||
if (newId != 0) {
|
||||
selectionManager.SetSelectedEntity(newId);
|
||||
}
|
||||
});
|
||||
if (newId != 0) {
|
||||
}
|
||||
}
|
||||
@@ -242,39 +268,53 @@ void HierarchyPanel::RenderCreateMenu(::XCEngine::Components::GameObject* parent
|
||||
auto& selectionManager = m_context->GetSelectionManager();
|
||||
|
||||
if (ImGui::MenuItem("Empty Object")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("GameObject", parent);
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Create Entity", [&]() {
|
||||
auto* newEntity = sceneManager.CreateEntity("GameObject", parent);
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
});
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::MenuItem("Camera")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Camera", parent);
|
||||
newEntity->AddComponent<::XCEngine::Components::CameraComponent>();
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Create Camera", [&]() {
|
||||
auto* newEntity = sceneManager.CreateEntity("Camera", parent);
|
||||
newEntity->AddComponent<::XCEngine::Components::CameraComponent>();
|
||||
sceneManager.MarkSceneDirty();
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Light")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Light", parent);
|
||||
newEntity->AddComponent<::XCEngine::Components::LightComponent>();
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Create Light", [&]() {
|
||||
auto* newEntity = sceneManager.CreateEntity("Light", parent);
|
||||
newEntity->AddComponent<::XCEngine::Components::LightComponent>();
|
||||
sceneManager.MarkSceneDirty();
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
});
|
||||
}
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
if (ImGui::MenuItem("Cube")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Cube", parent);
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Create Cube", [&]() {
|
||||
auto* newEntity = sceneManager.CreateEntity("Cube", parent);
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Sphere")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Sphere", parent);
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Create Sphere", [&]() {
|
||||
auto* newEntity = sceneManager.CreateEntity("Sphere", parent);
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
});
|
||||
}
|
||||
|
||||
if (ImGui::MenuItem("Plane")) {
|
||||
auto* newEntity = sceneManager.CreateEntity("Plane", parent);
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Create Plane", [&]() {
|
||||
auto* newEntity = sceneManager.CreateEntity("Plane", parent);
|
||||
selectionManager.SetSelectedEntity(newEntity->GetID());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -302,16 +342,19 @@ void HierarchyPanel::HandleDragDrop(::XCEngine::Components::GameObject* gameObje
|
||||
}
|
||||
|
||||
if (isValidMove) {
|
||||
auto* srcTransform = sourceGameObject->GetTransform();
|
||||
Math::Vector3 worldPos = srcTransform->GetPosition();
|
||||
Math::Quaternion worldRot = srcTransform->GetRotation();
|
||||
Math::Vector3 worldScale = srcTransform->GetScale();
|
||||
|
||||
sceneManager.MoveEntity(sourceGameObject->GetID(), gameObject->GetID());
|
||||
|
||||
srcTransform->SetPosition(worldPos);
|
||||
srcTransform->SetRotation(worldRot);
|
||||
srcTransform->SetScale(worldScale);
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Reparent Entity", [&]() {
|
||||
auto* srcTransform = sourceGameObject->GetTransform();
|
||||
Math::Vector3 worldPos = srcTransform->GetPosition();
|
||||
Math::Quaternion worldRot = srcTransform->GetRotation();
|
||||
Math::Vector3 worldScale = srcTransform->GetScale();
|
||||
|
||||
sceneManager.MoveEntity(sourceGameObject->GetID(), gameObject->GetID());
|
||||
|
||||
srcTransform->SetPosition(worldPos);
|
||||
srcTransform->SetRotation(worldRot);
|
||||
srcTransform->SetScale(worldScale);
|
||||
sceneManager.MarkSceneDirty();
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -328,7 +371,9 @@ void HierarchyPanel::HandleKeyboardShortcuts() {
|
||||
if (ImGui::IsWindowFocused()) {
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_Delete)) {
|
||||
if (selectedGameObject != nullptr) {
|
||||
sceneManager.DeleteEntity(selectedGameObject->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Delete Entity", [&]() {
|
||||
sceneManager.DeleteEntity(selectedGameObject->GetID());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,13 +396,23 @@ void HierarchyPanel::HandleKeyboardShortcuts() {
|
||||
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_V)) {
|
||||
if (sceneManager.HasClipboardData()) {
|
||||
sceneManager.PasteEntity(selectedGameObject ? selectedGameObject->GetID() : 0);
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Paste Entity", [&]() {
|
||||
const uint64_t newId = sceneManager.PasteEntity(selectedGameObject ? selectedGameObject->GetID() : 0);
|
||||
if (newId != 0) {
|
||||
selectionManager.SetSelectedEntity(newId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
if (ImGui::IsKeyPressed(ImGuiKey_D)) {
|
||||
if (selectedGameObject != nullptr) {
|
||||
sceneManager.DuplicateEntity(selectedGameObject->GetID());
|
||||
UndoUtils::ExecuteSceneCommand(*m_context, "Duplicate Entity", [&]() {
|
||||
const uint64_t newId = sceneManager.DuplicateEntity(selectedGameObject->GetID());
|
||||
if (newId != 0) {
|
||||
selectionManager.SetSelectedEntity(newId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user