Unify editor scene edit history

This commit is contained in:
2026-04-29 17:30:44 +08:00
parent 2e50c90167
commit 4a125cbe7f
8 changed files with 708 additions and 225 deletions

View File

@@ -100,10 +100,6 @@ public:
const EditorSceneComponentMutation& mutation);
bool CaptureSelectedTransformSnapshot(SceneTransformSnapshot& outSnapshot) const;
bool ApplyTransformSnapshot(const SceneTransformSnapshot& snapshot);
bool RecordTransformEdit(
const SceneTransformSnapshot& before,
const SceneTransformSnapshot& after);
bool ApplyTransformToolWorldPreview(
EditorSceneObjectId targetId,
const ::XCEngine::Math::Vector3& position,
@@ -112,16 +108,32 @@ public:
EditorSceneObjectId targetId,
const ::XCEngine::Math::Vector3& localScale);
bool CanUndoTransformEdit() const;
bool CanRedoTransformEdit() const;
bool UndoTransformEdit();
bool RedoTransformEdit();
bool BeginSceneEditTransaction(std::string_view label);
bool HasPendingSceneEditTransaction() const;
bool CommitSceneEditTransaction();
bool CancelSceneEditTransaction();
bool CanUndoSceneEdit() const;
bool CanRedoSceneEdit() const;
bool UndoSceneEdit();
bool RedoSceneEdit();
void NotifyExternalInspectorStateChanged();
private:
struct TransformEditTransaction {
SceneTransformSnapshot before = {};
SceneTransformSnapshot after = {};
struct SceneEditStateSnapshot {
std::string sceneSnapshot = {};
EditorSelectionState selection = {};
};
struct SceneEditTransaction {
std::string label = {};
SceneEditStateSnapshot before = {};
SceneEditStateSnapshot after = {};
};
struct PendingSceneEditTransaction {
std::string label = {};
SceneEditStateSnapshot before = {};
};
EditorSelectionService& SelectionService();
@@ -134,7 +146,11 @@ private:
EditorSceneComponentDescriptor ResolveSelectedComponentDescriptor(
std::string_view componentId) const;
bool SelectFirstAvailableGameObject();
void ResetTransformEditHistory();
bool CaptureSceneEditState(SceneEditStateSnapshot& outSnapshot) const;
bool RestoreSceneEditState(const SceneEditStateSnapshot& snapshot);
void ResetSceneEditHistory();
void ClearPendingSceneEditTransaction();
bool FinalizePendingSceneEditTransaction(bool& outChanged);
void IncrementInspectorRevision();
void IncrementSceneContentRevision();
@@ -142,8 +158,9 @@ private:
std::unique_ptr<EditorSceneBackend> m_backend = {};
EditorSelectionService m_ownedSelectionService = {};
EditorSelectionService* m_selectionService = &m_ownedSelectionService;
std::vector<TransformEditTransaction> m_transformUndoStack = {};
std::vector<TransformEditTransaction> m_transformRedoStack = {};
std::vector<SceneEditTransaction> m_sceneUndoStack = {};
std::vector<SceneEditTransaction> m_sceneRedoStack = {};
std::optional<PendingSceneEditTransaction> m_pendingSceneEditTransaction = {};
std::uint64_t m_inspectorRevision = 0u;
std::uint64_t m_sceneContentRevision = 0u;
};