mirror of
https://github.com/antopilo/Nuake.git
synced 2026-09-15 20:08:54 +03:00
Added command buffer implementation in the editor layer
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include "ICommand.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@@ -7,11 +8,23 @@ namespace NuakeEditor
|
||||
class CommandBuffer
|
||||
{
|
||||
private:
|
||||
std::vector<ICommand> mCommands;
|
||||
|
||||
public:
|
||||
CommandBuffer();
|
||||
~CommandBuffer();
|
||||
CommandBuffer() : mCommands(std::vector<ICommand>()) {}
|
||||
|
||||
~CommandBuffer() = default;
|
||||
|
||||
void PushCommand(ICommand& command)
|
||||
{
|
||||
command.Execute();
|
||||
|
||||
mCommands.push_back(command);
|
||||
}
|
||||
|
||||
void PopCommand()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
19
Editor/src/Commands/Commands/Commands.cpp
Normal file
19
Editor/src/Commands/Commands/Commands.cpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#include "Commands.h"
|
||||
|
||||
#include <Engine.h>
|
||||
|
||||
namespace NuakeEditor
|
||||
{
|
||||
bool SaveSceneCommand::Execute()
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
bool SaveProjectCommand::Execute()
|
||||
{
|
||||
Engine::GetProject()->Save();
|
||||
Engine::GetCurrentScene()->Save();
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -1,23 +1,35 @@
|
||||
#pragma once
|
||||
|
||||
#include "../ICommand.h"
|
||||
|
||||
#include <src/Core/Core.h>
|
||||
#include <src/Scene/Scene.h>
|
||||
#include <src/Resource/Project.h>
|
||||
|
||||
|
||||
namespace NuakeEditor {
|
||||
|
||||
class SaveSceneCommand : ICommand
|
||||
using namespace Nuake;
|
||||
|
||||
class SaveSceneCommand : public ICommand
|
||||
{
|
||||
private:
|
||||
Ref<Scene> mScene;
|
||||
|
||||
public:
|
||||
void Execute() override;
|
||||
SaveSceneCommand(Ref<Scene> scene) : mScene(scene) {}
|
||||
|
||||
bool Execute() override;
|
||||
};
|
||||
|
||||
class SaveProjectCommand : ICommand
|
||||
class SaveProjectCommand : public ICommand
|
||||
{
|
||||
private:
|
||||
Ref<Project> mProject;
|
||||
|
||||
public:
|
||||
void Execute() override;
|
||||
SaveProjectCommand(Ref<Project> project) : mProject(project) {}
|
||||
|
||||
bool Execute() override;
|
||||
};
|
||||
|
||||
class SaveProjectCommand : ICommand
|
||||
{
|
||||
public:
|
||||
void Execute() override;
|
||||
};
|
||||
}
|
||||
@@ -5,7 +5,16 @@ namespace NuakeEditor
|
||||
class ICommand
|
||||
{
|
||||
public:
|
||||
virtual void Execute() = 0;
|
||||
virtual void Undo() = 0;
|
||||
ICommand() = default;
|
||||
|
||||
virtual bool Execute()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual bool Undo()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -5,9 +5,15 @@
|
||||
#include "Windows/EditorInterface.h"
|
||||
#include "Misc/GizmoDrawer.h"
|
||||
|
||||
#include "Commands/CommandBuffer.h"
|
||||
|
||||
using namespace NuakeEditor;
|
||||
|
||||
class EditorApplication : public Nuake::Application
|
||||
{
|
||||
private:
|
||||
CommandBuffer mCommandBuffer;
|
||||
|
||||
public:
|
||||
EditorApplication(const Nuake::ApplicationSpecification& specification)
|
||||
: Application(specification),
|
||||
@@ -16,6 +22,7 @@ public:
|
||||
}
|
||||
|
||||
virtual void OnInit() override;
|
||||
|
||||
// virtual void OnUpdate() override;
|
||||
virtual void OnShutdown() override;
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
|
||||
void EditorLayer::OnAttach()
|
||||
{
|
||||
m_EditorInterface = new Nuake::EditorInterface();
|
||||
m_EditorInterface = new Nuake::EditorInterface(mCommandBuffer);
|
||||
m_GizmoDrawer = new GizmoDrawer(m_EditorInterface);
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ void EditorLayer::OnUpdate()
|
||||
|
||||
auto sceneFramebuffer = GetApplication().GetWindow()->GetFrameBuffer();
|
||||
|
||||
|
||||
// Draw gizmos
|
||||
if (Ref<Nuake::Scene> currentScene = Nuake::Engine::GetCurrentScene(); currentScene)
|
||||
{
|
||||
@@ -64,6 +63,7 @@ void EditorLayer::OnUpdate()
|
||||
|
||||
m_EditorInterface->Draw();
|
||||
m_EditorInterface->Update(Nuake::Engine::GetTimestep());
|
||||
|
||||
Nuake::Engine::EndDraw();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <src/Application/Layer.h>
|
||||
#include "Commands/CommandBuffer.h"
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
@@ -9,15 +10,19 @@ namespace Nuake {
|
||||
|
||||
class GizmoDrawer;
|
||||
|
||||
using namespace NuakeEditor;
|
||||
|
||||
class EditorLayer : public Nuake::Layer
|
||||
{
|
||||
public:
|
||||
EditorLayer() : mCommandBuffer() {}
|
||||
|
||||
virtual void OnAttach() override;
|
||||
virtual void OnUpdate() override;
|
||||
virtual void OnDetach() override;
|
||||
|
||||
private:
|
||||
CommandBuffer mCommandBuffer;
|
||||
Nuake::EditorInterface* m_EditorInterface;
|
||||
GizmoDrawer* m_GizmoDrawer;
|
||||
};
|
||||
@@ -54,6 +54,7 @@
|
||||
#include <src/Resource/StaticResources.h>
|
||||
#include <src/Scripting/ScriptingEngineNet.h>
|
||||
#include <src/Threading/JobSystem.h>
|
||||
#include "../Commands/Commands/Commands.h"
|
||||
|
||||
namespace Nuake {
|
||||
|
||||
@@ -62,7 +63,8 @@ namespace Nuake {
|
||||
ImFont* boldFont;
|
||||
ImFont* EditorInterface::bigIconFont;
|
||||
|
||||
EditorInterface::EditorInterface()
|
||||
EditorInterface::EditorInterface(CommandBuffer& commandBuffer) :
|
||||
mCommandBuffer(&commandBuffer)
|
||||
{
|
||||
Logger::Log("Creating editor windows", "window", CRITICAL);
|
||||
filesystem = new FileSystemUI(this);
|
||||
@@ -2111,12 +2113,12 @@ namespace Nuake {
|
||||
}
|
||||
if (ImGui::MenuItem("Save", "CTRL+S"))
|
||||
{
|
||||
Engine::GetProject()->Save();
|
||||
Engine::GetCurrentScene()->Save();
|
||||
PushCommand(SaveProjectCommand(Engine::GetProject()));
|
||||
|
||||
Selection = EditorSelection();
|
||||
|
||||
SetStatusMessage("Project saved.");
|
||||
|
||||
Selection = EditorSelection();
|
||||
}
|
||||
if (ImGui::MenuItem("Save as...", "CTRL+SHIFT+S"))
|
||||
{
|
||||
@@ -2455,6 +2457,11 @@ namespace Nuake {
|
||||
return entityTypeName;
|
||||
}
|
||||
|
||||
void EditorInterface::PushCommand(ICommand&& command)
|
||||
{
|
||||
mCommandBuffer->PushCommand(command);
|
||||
}
|
||||
|
||||
bool EditorInterface::LoadProject(const std::string& projectPath)
|
||||
{
|
||||
FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath));
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
#include <src/Vendors/imgui/ImGuizmo.h>
|
||||
#include "src/Core/FileSystem.h"
|
||||
|
||||
|
||||
#include "../Actions/EditorSelection.h"
|
||||
#include "EditorSelectionPanel.h"
|
||||
#include "WelcomeWindow.h"
|
||||
#include "AudioWindow.h"
|
||||
#include "../Windows/TrenchbroomConfiguratorWindow.h"
|
||||
#include "../Commands/CommandBuffer.h"
|
||||
#include "../Commands/ICommand.h"
|
||||
|
||||
using namespace NuakeEditor;
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
@@ -22,6 +25,7 @@ namespace Nuake
|
||||
{
|
||||
private:
|
||||
Ref<Scene> SceneSnapshot;
|
||||
NuakeEditor::CommandBuffer* mCommandBuffer;
|
||||
|
||||
bool m_DrawGrid = false;
|
||||
bool m_DrawAxis = true;
|
||||
@@ -52,7 +56,7 @@ namespace Nuake
|
||||
EditorSelectionPanel SelectionPanel;
|
||||
TrenchbroomConfiguratorWindow m_TrenchhbroomConfigurator;
|
||||
|
||||
EditorInterface();
|
||||
EditorInterface(CommandBuffer& commandBuffer);
|
||||
|
||||
static ImFont* bigIconFont;
|
||||
void BuildFonts();
|
||||
@@ -76,5 +80,6 @@ namespace Nuake
|
||||
|
||||
private:
|
||||
std::string GetEntityTypeName(const Entity& entity) const;
|
||||
void PushCommand(ICommand&& command);
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user