Refactor new editor scene viewport tools
This commit is contained in:
148
new_editor/app/Features/Scene/SceneEditCommandRoute.cpp
Normal file
148
new_editor/app/Features/Scene/SceneEditCommandRoute.cpp
Normal 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
|
||||
Reference in New Issue
Block a user