Refactor new editor scene viewport tools

This commit is contained in:
2026-04-18 18:55:19 +08:00
parent b8e84001fa
commit f544b2792b
17 changed files with 3414 additions and 14 deletions

View File

@@ -0,0 +1,148 @@
#include "Features/Scene/SceneEditCommandRoute.h"
#include "Scene/EditorSceneRuntime.h"
#include <utility>
namespace XCEngine::UI::Editor::App {
namespace {
UIEditorHostCommandEvaluationResult BuildEvaluationResult(
bool executable,
std::string message) {
UIEditorHostCommandEvaluationResult result = {};
result.executable = executable;
result.message = std::move(message);
return result;
}
UIEditorHostCommandDispatchResult BuildDispatchResult(
bool commandExecuted,
std::string message) {
UIEditorHostCommandDispatchResult result = {};
result.commandExecuted = commandExecuted;
result.message = std::move(message);
return result;
}
} // namespace
void SceneEditCommandRoute::BindSceneRuntime(EditorSceneRuntime* sceneRuntime) {
m_sceneRuntime = sceneRuntime;
}
UIEditorHostCommandEvaluationResult SceneEditCommandRoute::EvaluateEditCommand(
std::string_view commandId) const {
if (m_sceneRuntime == nullptr) {
return BuildEvaluationResult(false, "Scene runtime is unavailable.");
}
if (commandId == "edit.undo") {
return m_sceneRuntime->CanUndoTransformEdit()
? BuildEvaluationResult(true, "Undo the last scene transform edit.")
: BuildEvaluationResult(false, "Scene transform history is empty.");
}
if (commandId == "edit.redo") {
return m_sceneRuntime->CanRedoTransformEdit()
? BuildEvaluationResult(true, "Redo the last scene transform edit.")
: BuildEvaluationResult(false, "Scene redo history is empty.");
}
if (!m_sceneRuntime->HasSceneSelection()) {
return BuildEvaluationResult(false, "Select a scene object first.");
}
const std::string selectedName =
m_sceneRuntime->GetSelectedDisplayName().empty()
? std::string("GameObject")
: m_sceneRuntime->GetSelectedDisplayName();
if (commandId == "edit.delete") {
return BuildEvaluationResult(
true,
"Delete scene object '" + selectedName + "'.");
}
if (commandId == "edit.duplicate") {
return BuildEvaluationResult(
true,
"Duplicate scene object '" + selectedName + "'.");
}
if (commandId == "edit.rename") {
return BuildEvaluationResult(
false,
"Scene viewport does not expose inline rename yet.");
}
if (commandId == "edit.cut" ||
commandId == "edit.copy" ||
commandId == "edit.paste") {
return BuildEvaluationResult(
false,
"Scene clipboard transfer has no bound owner in the current shell.");
}
return BuildEvaluationResult(false, "Scene does not expose this edit command.");
}
UIEditorHostCommandDispatchResult SceneEditCommandRoute::DispatchEditCommand(
std::string_view commandId) {
const UIEditorHostCommandEvaluationResult evaluation =
EvaluateEditCommand(commandId);
if (!evaluation.executable) {
return BuildDispatchResult(false, evaluation.message);
}
if (m_sceneRuntime == nullptr) {
return BuildDispatchResult(false, "Scene runtime is unavailable.");
}
if (commandId == "edit.undo") {
return m_sceneRuntime->UndoTransformEdit()
? BuildDispatchResult(true, "Undid the last scene transform edit.")
: BuildDispatchResult(false, "Scene transform history is empty.");
}
if (commandId == "edit.redo") {
return m_sceneRuntime->RedoTransformEdit()
? BuildDispatchResult(true, "Redid the last scene transform edit.")
: BuildDispatchResult(false, "Scene redo history is empty.");
}
const std::string selectedItemId = m_sceneRuntime->GetSelectedItemId();
const std::string selectedName =
m_sceneRuntime->GetSelectedDisplayName().empty()
? std::string("GameObject")
: m_sceneRuntime->GetSelectedDisplayName();
if (selectedItemId.empty()) {
return BuildDispatchResult(false, "Select a scene object first.");
}
if (commandId == "edit.delete") {
return m_sceneRuntime->DeleteGameObject(selectedItemId)
? BuildDispatchResult(
true,
"Deleted scene object '" + selectedName + "'.")
: BuildDispatchResult(
false,
"Failed to delete the selected scene object.");
}
if (commandId == "edit.duplicate") {
return !m_sceneRuntime->DuplicateGameObject(selectedItemId).empty()
? BuildDispatchResult(
true,
"Duplicated scene object '" + selectedName + "'.")
: BuildDispatchResult(
false,
"Failed to duplicate the selected scene object.");
}
return BuildDispatchResult(false, "Scene does not expose this edit command.");
}
} // namespace XCEngine::UI::Editor::App