Create ISceneManager interface and fix GetSceneManager return type
- Created ISceneManager interface with Editor需要的 SceneManager 方法 - SceneManager now implements ISceneManager - IEditorContext::GetSceneManager() now returns ISceneManager& instead of void* - Removed SceneManager::GetSceneManagerConcrete() method - Updated HierarchyPanel and InspectorPanel to use ISceneManager interface
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "EventBus.h"
|
||||
#include "SelectionManager.h"
|
||||
#include "IProjectManager.h"
|
||||
#include "ISceneManager.h"
|
||||
#include "Managers/SceneManager.h"
|
||||
#include "Managers/ProjectManager.h"
|
||||
#include <string>
|
||||
@@ -30,11 +31,7 @@ public:
|
||||
return *m_selectionManager;
|
||||
}
|
||||
|
||||
void* GetSceneManager() override {
|
||||
return m_sceneManager.get();
|
||||
}
|
||||
|
||||
SceneManager& GetSceneManagerConcrete() {
|
||||
ISceneManager& GetSceneManager() override {
|
||||
return *m_sceneManager;
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Editor {
|
||||
class EventBus;
|
||||
class ISelectionManager;
|
||||
class IProjectManager;
|
||||
class ISceneManager;
|
||||
|
||||
class IEditorContext {
|
||||
public:
|
||||
@@ -16,7 +17,7 @@ public:
|
||||
|
||||
virtual EventBus& GetEventBus() = 0;
|
||||
virtual ISelectionManager& GetSelectionManager() = 0;
|
||||
virtual void* GetSceneManager() = 0;
|
||||
virtual ISceneManager& GetSceneManager() = 0;
|
||||
virtual IProjectManager& GetProjectManager() = 0;
|
||||
|
||||
virtual void SetProjectPath(const std::string& path) = 0;
|
||||
|
||||
29
editor/src/Core/ISceneManager.h
Normal file
29
editor/src/Core/ISceneManager.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
#include <cstdint>
|
||||
#include <XCEngine/Components/GameObject.h>
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
class ISceneManager {
|
||||
public:
|
||||
virtual ~ISceneManager() = default;
|
||||
|
||||
virtual ::XCEngine::Components::GameObject* CreateEntity(const std::string& name, ::XCEngine::Components::GameObject* parent = nullptr) = 0;
|
||||
virtual void DeleteEntity(::XCEngine::Components::GameObject::ID id) = 0;
|
||||
virtual void RenameEntity(::XCEngine::Components::GameObject::ID id, const std::string& newName) = 0;
|
||||
virtual ::XCEngine::Components::GameObject* GetEntity(::XCEngine::Components::GameObject::ID id) = 0;
|
||||
virtual const std::vector<::XCEngine::Components::GameObject*>& GetRootEntities() const = 0;
|
||||
virtual void CopyEntity(::XCEngine::Components::GameObject::ID id) = 0;
|
||||
virtual ::XCEngine::Components::GameObject::ID PasteEntity(::XCEngine::Components::GameObject::ID parent = 0) = 0;
|
||||
virtual ::XCEngine::Components::GameObject::ID DuplicateEntity(::XCEngine::Components::GameObject::ID id) = 0;
|
||||
virtual void MoveEntity(::XCEngine::Components::GameObject::ID id, ::XCEngine::Components::GameObject::ID newParent) = 0;
|
||||
virtual bool HasClipboardData() const = 0;
|
||||
virtual void CreateDemoScene() = 0;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
@@ -14,13 +14,14 @@
|
||||
#include <XCEngine/Scene/Scene.h>
|
||||
|
||||
#include "Core/ISelectionManager.h"
|
||||
#include "Core/ISceneManager.h"
|
||||
|
||||
namespace XCEngine {
|
||||
namespace Editor {
|
||||
|
||||
class ISelectionManager;
|
||||
|
||||
class SceneManager {
|
||||
class SceneManager : public ISceneManager {
|
||||
public:
|
||||
SceneManager();
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#include "HierarchyPanel.h"
|
||||
#include "Core/IEditorContext.h"
|
||||
#include "Core/ISceneManager.h"
|
||||
#include <XCEngine/Core/Math/Vector3.h>
|
||||
#include <XCEngine/Core/Math/Quaternion.h>
|
||||
#include <imgui.h>
|
||||
@@ -15,8 +16,8 @@ HierarchyPanel::~HierarchyPanel() {
|
||||
}
|
||||
|
||||
void HierarchyPanel::OnAttach() {
|
||||
auto* sceneManager = static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||
sceneManager->CreateDemoScene();
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
sceneManager.CreateDemoScene();
|
||||
}
|
||||
|
||||
void HierarchyPanel::Render() {
|
||||
@@ -32,7 +33,7 @@ void HierarchyPanel::Render() {
|
||||
|
||||
ImGui::BeginChild("EntityList");
|
||||
|
||||
auto& sceneManager = *static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
auto rootEntities = sceneManager.GetRootEntities();
|
||||
SortEntities(const_cast<std::vector<::XCEngine::Components::GameObject*>&>(rootEntities));
|
||||
|
||||
@@ -56,7 +57,7 @@ void HierarchyPanel::Render() {
|
||||
if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("ENTITY_PTR")) {
|
||||
::XCEngine::Components::GameObject* sourceGameObject = *(::XCEngine::Components::GameObject**)payload->Data;
|
||||
if (sourceGameObject && sourceGameObject->GetParent() != nullptr) {
|
||||
auto& sceneManager = *static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
sceneManager.MoveEntity(sourceGameObject->GetID(), 0);
|
||||
}
|
||||
}
|
||||
@@ -108,7 +109,7 @@ 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) {
|
||||
static_cast<SceneManager*>(m_context->GetSceneManager())->RenameEntity(gameObject->GetID(), m_renameBuffer);
|
||||
m_context->GetSceneManager().RenameEntity(gameObject->GetID(), m_renameBuffer);
|
||||
}
|
||||
m_renaming = false;
|
||||
m_renamingEntity = nullptr;
|
||||
@@ -116,7 +117,7 @@ void HierarchyPanel::RenderEntity(::XCEngine::Components::GameObject* gameObject
|
||||
|
||||
if (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)) {
|
||||
if (strlen(m_renameBuffer) > 0) {
|
||||
static_cast<SceneManager*>(m_context->GetSceneManager())->RenameEntity(gameObject->GetID(), m_renameBuffer);
|
||||
m_context->GetSceneManager().RenameEntity(gameObject->GetID(), m_renameBuffer);
|
||||
}
|
||||
m_renaming = false;
|
||||
m_renamingEntity = nullptr;
|
||||
@@ -161,7 +162,7 @@ void HierarchyPanel::RenderEntity(::XCEngine::Components::GameObject* gameObject
|
||||
}
|
||||
|
||||
void HierarchyPanel::RenderContextMenu(::XCEngine::Components::GameObject* gameObject) {
|
||||
auto& sceneManager = *static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
auto& selectionManager = m_context->GetSelectionManager();
|
||||
|
||||
if (ImGui::BeginMenu("Create")) {
|
||||
@@ -213,7 +214,7 @@ void HierarchyPanel::RenderContextMenu(::XCEngine::Components::GameObject* gameO
|
||||
}
|
||||
|
||||
void HierarchyPanel::RenderCreateMenu(::XCEngine::Components::GameObject* parent) {
|
||||
auto& sceneManager = *static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
auto& selectionManager = m_context->GetSelectionManager();
|
||||
|
||||
if (ImGui::MenuItem("Empty Object")) {
|
||||
@@ -256,7 +257,7 @@ void HierarchyPanel::RenderCreateMenu(::XCEngine::Components::GameObject* parent
|
||||
}
|
||||
|
||||
void HierarchyPanel::HandleDragDrop(::XCEngine::Components::GameObject* gameObject) {
|
||||
auto& sceneManager = *static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
|
||||
if (ImGui::BeginDragDropSource(ImGuiDragDropFlags_None)) {
|
||||
ImGui::SetDragDropPayload("ENTITY_PTR", &gameObject, sizeof(::XCEngine::Components::GameObject*));
|
||||
@@ -297,7 +298,7 @@ void HierarchyPanel::HandleDragDrop(::XCEngine::Components::GameObject* gameObje
|
||||
}
|
||||
|
||||
void HierarchyPanel::HandleKeyboardShortcuts() {
|
||||
auto& sceneManager = *static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
auto& selectionManager = m_context->GetSelectionManager();
|
||||
|
||||
::XCEngine::Components::GameObject* selectedGameObject = sceneManager.GetEntity(selectionManager.GetSelectedEntity());
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
#include "InspectorPanel.h"
|
||||
#include "Core/EditorContext.h"
|
||||
#include "Managers/SceneManager.h"
|
||||
#include "Core/ISceneManager.h"
|
||||
#include "UI/UI.h"
|
||||
#include <XCEngine/Debug/Logger.h>
|
||||
#include <imgui.h>
|
||||
@@ -38,8 +38,8 @@ void InspectorPanel::Render() {
|
||||
m_selectedEntityId = m_context->GetSelectionManager().GetSelectedEntity();
|
||||
|
||||
if (m_selectedEntityId) {
|
||||
auto* sceneManager = static_cast<SceneManager*>(m_context->GetSceneManager());
|
||||
auto* gameObject = sceneManager->GetEntity(m_selectedEntityId);
|
||||
auto& sceneManager = m_context->GetSceneManager();
|
||||
auto* gameObject = sceneManager.GetEntity(m_selectedEntityId);
|
||||
if (gameObject) {
|
||||
RenderGameObject(gameObject);
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user