2026-03-20 17:08:06 +08:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <unordered_map>
|
|
|
|
|
#include <vector>
|
|
|
|
|
#include <memory>
|
|
|
|
|
#include <optional>
|
|
|
|
|
|
2026-03-20 17:28:06 +08:00
|
|
|
#include <XCEngine/Core/Event.h>
|
2026-03-24 18:38:01 +08:00
|
|
|
#include <XCEngine/Components/GameObject.h>
|
|
|
|
|
#include <XCEngine/Scene/Scene.h>
|
2026-03-20 17:28:06 +08:00
|
|
|
|
2026-03-20 17:08:06 +08:00
|
|
|
namespace UI {
|
|
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
class EditorSceneManager {
|
2026-03-20 17:08:06 +08:00
|
|
|
public:
|
2026-03-24 18:38:01 +08:00
|
|
|
static EditorSceneManager& Get() {
|
|
|
|
|
static EditorSceneManager instance;
|
2026-03-20 17:08:06 +08:00
|
|
|
return instance;
|
|
|
|
|
}
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
XCEngine::Components::GameObject* CreateEntity(const std::string& name, XCEngine::Components::GameObject* parent = nullptr);
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
XCEngine::Components::GameObject* GetEntity(XCEngine::Components::GameObject::ID id) {
|
|
|
|
|
return m_scene ? m_scene->Find(std::to_string(id)) : nullptr;
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
const XCEngine::Components::GameObject* GetEntity(XCEngine::Components::GameObject::ID id) const {
|
|
|
|
|
return m_scene ? m_scene->Find(std::to_string(id)) : nullptr;
|
2026-03-20 17:08:06 +08:00
|
|
|
}
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
const std::vector<XCEngine::Components::GameObject*>& GetRootEntities() const {
|
2026-03-20 17:08:06 +08:00
|
|
|
return m_rootEntities;
|
|
|
|
|
}
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
void DeleteEntity(XCEngine::Components::GameObject::ID id);
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
void RenameEntity(XCEngine::Components::GameObject::ID id, const std::string& newName) {
|
|
|
|
|
if (auto* entity = GetEntity(id)) {
|
|
|
|
|
entity->SetName(newName);
|
2026-03-20 17:08:06 +08:00
|
|
|
OnEntityChanged.Invoke(id);
|
|
|
|
|
}
|
|
|
|
|
}
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
void CopyEntity(XCEngine::Components::GameObject::ID id);
|
|
|
|
|
XCEngine::Components::GameObject::ID PasteEntity(XCEngine::Components::GameObject::ID parent = 0);
|
|
|
|
|
XCEngine::Components::GameObject::ID DuplicateEntity(XCEngine::Components::GameObject::ID id);
|
|
|
|
|
void MoveEntity(XCEngine::Components::GameObject::ID id, XCEngine::Components::GameObject::ID newParent);
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-20 17:08:06 +08:00
|
|
|
void CreateDemoScene();
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-20 17:08:06 +08:00
|
|
|
bool HasClipboardData() const { return m_clipboard.has_value(); }
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
XCEngine::Core::Event<XCEngine::Components::GameObject::ID> OnEntityCreated;
|
|
|
|
|
XCEngine::Core::Event<XCEngine::Components::GameObject::ID> OnEntityDeleted;
|
|
|
|
|
XCEngine::Core::Event<XCEngine::Components::GameObject::ID> OnEntityChanged;
|
2026-03-20 17:28:06 +08:00
|
|
|
XCEngine::Core::Event<> OnSceneChanged;
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-20 17:08:06 +08:00
|
|
|
private:
|
2026-03-24 18:38:01 +08:00
|
|
|
EditorSceneManager() = default;
|
|
|
|
|
|
|
|
|
|
struct ClipboardData {
|
|
|
|
|
std::string name;
|
|
|
|
|
std::vector<std::unique_ptr<XCEngine::Components::Component>> components;
|
|
|
|
|
std::vector<ClipboardData> children;
|
|
|
|
|
};
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
ClipboardData CopyEntityRecursive(const XCEngine::Components::GameObject* entity);
|
|
|
|
|
XCEngine::Components::GameObject::ID PasteEntityRecursive(const ClipboardData& data, XCEngine::Components::GameObject::ID parent);
|
2026-03-20 19:43:17 +08:00
|
|
|
|
2026-03-24 18:38:01 +08:00
|
|
|
XCEngine::Components::Scene* m_scene = nullptr;
|
|
|
|
|
std::vector<XCEngine::Components::GameObject*> m_rootEntities;
|
2026-03-20 17:08:06 +08:00
|
|
|
std::optional<ClipboardData> m_clipboard;
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-20 17:28:06 +08:00
|
|
|
}
|