add NewLevel action

This commit is contained in:
SweetId 2023-10-16 21:14:26 -04:00
parent 8dd179e784
commit f2f4c3b036
8 changed files with 84 additions and 4 deletions

View File

@ -3,6 +3,7 @@
#include <NazaraEditor/Core/Core.hpp>
#include <NazaraEditor/Core/Application/Action.hpp>
#include <NazaraEditor/Core/Application/ActionStack.hpp>
#include <NazaraEditor/Core/Application/Actions/EditorAction_Level_New.hpp>
#include <NazaraEditor/Core/Application/Actions/EditorAction_Log_Clear.hpp>
#include <NazaraEditor/Core/Application/Actions/EditorAction_Log_CopyToClipboard.hpp>
#include <NazaraEditor/Core/Application/BaseApplication.hpp>

View File

@ -0,0 +1,15 @@
#pragma once
#include <NazaraEditor/Core/Application/Action.hpp>
namespace Nz
{
class NAZARAEDITOR_CORE_API EditorAction_Level_New final
: public EditorAction
{
EDITORACTION_BODY(EditorAction_Level_New, false);
public:
void Execute() override;
};
}

View File

@ -39,10 +39,11 @@ namespace Nz
void SetResourceFolder(const std::filesystem::path& path) { m_resourceFolder = path; }
std::filesystem::path GetResourceFolder() const { return m_resourceFolder; }
Nz::Level& GetLevel();
bool NewLevel();
bool CloseLevel();
bool OpenLevel(const std::filesystem::path& path);
virtual bool NewLevel();
virtual bool CloseLevel() { return false; }
virtual bool OpenLevel(const std::filesystem::path& /*path*/) { return false; }
entt::handle CreateEntity(const std::string& name);

View File

@ -7,6 +7,7 @@ namespace NzEditor
class Application
: public Nz::EditorBaseApplication
{
public:
virtual bool NewLevel() override;
};
}

View File

@ -0,0 +1,10 @@
#include <NazaraEditor/Core/Application/Actions/EditorAction_Level_New.hpp>
#include <NazaraEditor/Core/Application/BaseApplication.hpp>
namespace Nz
{
void EditorAction_Level_New::Execute()
{
Nz::EditorBaseApplication::Instance()->NewLevel();
}
}

View File

@ -81,6 +81,15 @@ namespace Nz
bool bRes = m_level.CreateNewLevel();
if (bRes)
{
// configure camera
auto camera = CreateEntity("Camera");
auto& cmp = camera.get<Nz::EditorNameComponent>();
//cmp.SetFlags(EditorEntityFlags_Hidden);
auto& cameraComponent = camera.emplace<Nz::CameraComponent>(m_windowSwapchain.get(), Nz::ProjectionType::Perspective);
cameraComponent.UpdateFOV(70.f);
cameraComponent.UpdateClearColor(Nz::Color(0.46f, 0.48f, 0.84f, 1.f));
OnLevelChanged(m_level);
}
return bRes;

View File

@ -0,0 +1,35 @@
#include <NazaraEditor/Editor/Application.hpp>
namespace NzEditor
{
bool Application::NewLevel()
{
bool bResult = EditorBaseApplication::NewLevel();
if (!bResult)
return false;
{
auto directional = CreateEntity("SunLight");
Nz::LightComponent& lightComponent = directional.emplace<Nz::LightComponent>();
Nz::DirectionalLight& light = lightComponent.AddLight<Nz::DirectionalLight>();
light.UpdateRotation(Nz::EulerAnglesf(-45.f, 0.f, 0.f));
}
{
auto cube = CreateEntity("Cube");
Nz::GraphicsComponent& graphicsComponent = cube.emplace<Nz::GraphicsComponent>();
std::shared_ptr<Nz::GraphicalMesh> boxMesh = Nz::GraphicalMesh::Build(Nz::Primitive::Box(Nz::Vector3f(4.f), Nz::Vector3ui::Zero(), Nz::Matrix4f::Scale(Nz::Vector3f(-1.f)), Nz::Rectf(0.f, 0.f, 2.f, 2.f)));
std::shared_ptr<Nz::MaterialInstance> boxMat = Nz::MaterialInstance::Instantiate(Nz::MaterialType::Phong);
boxMat->DisablePass("ShadowPass");
boxMat->UpdatePassesStates([&](Nz::RenderStates& states)
{
states.frontFace = Nz::FrontFace::Clockwise;
});
std::shared_ptr<Nz::Model> boxModel = std::make_shared<Nz::Model>(std::move(boxMesh));
boxModel->SetMaterial(0, std::move(boxMat));
graphicsComponent.AttachRenderable(boxModel);
}
return true;
}
}

View File

@ -46,6 +46,14 @@ int WinMain(int argc, char* argv[])
Nz::TextureParams texParams;
texParams.renderDevice = Nz::Graphics::Instance()->GetRenderDevice();
texParams.loadFormat = Nz::PixelFormat::RGBA8_SRGB;
app.RegisterAction<Nz::EditorAction_Level_New>({
.description = "Create new level",
.path = "File|Level|New",
.category = "General",
.shortcut = Nz::Shortcut::Create(Nz::Keyboard::VKey::N, true, true),
.icon = Nz::Texture::LoadFromFile(app.GetResourceFolder() / "file_new.png", texParams)
});
app.RegisterAction<Nz::EditorAction_Log_Clear>({
.description = "Clears log output",
.path = "Clear",