From f2f4c3b0367305337fd6c76c8b5c77dec16a24d7 Mon Sep 17 00:00:00 2001 From: SweetId <2630750+SweetId@users.noreply.github.com> Date: Mon, 16 Oct 2023 21:14:26 -0400 Subject: [PATCH] add NewLevel action --- include/NazaraEditor/Core.hpp | 1 + .../Actions/EditorAction_Level_New.hpp | 15 ++++++++ .../Core/Application/BaseApplication.hpp | 7 ++-- include/NazaraEditor/Editor/Application.hpp | 3 +- .../Actions/EditorAction_Level_New.cpp | 10 ++++++ .../Core/Application/BaseApplication.cpp | 9 +++++ src/NazaraEditor/Editor/Application.cpp | 35 +++++++++++++++++++ src/NazaraEditor/Editor/main.cpp | 8 +++++ 8 files changed, 84 insertions(+), 4 deletions(-) create mode 100644 include/NazaraEditor/Core/Application/Actions/EditorAction_Level_New.hpp create mode 100644 src/NazaraEditor/Core/Application/Actions/EditorAction_Level_New.cpp diff --git a/include/NazaraEditor/Core.hpp b/include/NazaraEditor/Core.hpp index 329f27d..bb8f7ce 100644 --- a/include/NazaraEditor/Core.hpp +++ b/include/NazaraEditor/Core.hpp @@ -3,6 +3,7 @@ #include #include #include +#include #include #include #include diff --git a/include/NazaraEditor/Core/Application/Actions/EditorAction_Level_New.hpp b/include/NazaraEditor/Core/Application/Actions/EditorAction_Level_New.hpp new file mode 100644 index 0000000..4cfd1b9 --- /dev/null +++ b/include/NazaraEditor/Core/Application/Actions/EditorAction_Level_New.hpp @@ -0,0 +1,15 @@ +#pragma once + +#include + +namespace Nz +{ + class NAZARAEDITOR_CORE_API EditorAction_Level_New final + : public EditorAction + { + EDITORACTION_BODY(EditorAction_Level_New, false); + + public: + void Execute() override; + }; +} \ No newline at end of file diff --git a/include/NazaraEditor/Core/Application/BaseApplication.hpp b/include/NazaraEditor/Core/Application/BaseApplication.hpp index 30df376..ad39178 100644 --- a/include/NazaraEditor/Core/Application/BaseApplication.hpp +++ b/include/NazaraEditor/Core/Application/BaseApplication.hpp @@ -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); diff --git a/include/NazaraEditor/Editor/Application.hpp b/include/NazaraEditor/Editor/Application.hpp index 3882b43..4608e83 100644 --- a/include/NazaraEditor/Editor/Application.hpp +++ b/include/NazaraEditor/Editor/Application.hpp @@ -7,6 +7,7 @@ namespace NzEditor class Application : public Nz::EditorBaseApplication { - + public: + virtual bool NewLevel() override; }; } \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/Actions/EditorAction_Level_New.cpp b/src/NazaraEditor/Core/Application/Actions/EditorAction_Level_New.cpp new file mode 100644 index 0000000..3075370 --- /dev/null +++ b/src/NazaraEditor/Core/Application/Actions/EditorAction_Level_New.cpp @@ -0,0 +1,10 @@ +#include +#include + +namespace Nz +{ + void EditorAction_Level_New::Execute() + { + Nz::EditorBaseApplication::Instance()->NewLevel(); + } +} \ No newline at end of file diff --git a/src/NazaraEditor/Core/Application/BaseApplication.cpp b/src/NazaraEditor/Core/Application/BaseApplication.cpp index 17818e5..77611e5 100644 --- a/src/NazaraEditor/Core/Application/BaseApplication.cpp +++ b/src/NazaraEditor/Core/Application/BaseApplication.cpp @@ -81,6 +81,15 @@ namespace Nz bool bRes = m_level.CreateNewLevel(); if (bRes) { + // configure camera + auto camera = CreateEntity("Camera"); + auto& cmp = camera.get(); + //cmp.SetFlags(EditorEntityFlags_Hidden); + + auto& cameraComponent = camera.emplace(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; diff --git a/src/NazaraEditor/Editor/Application.cpp b/src/NazaraEditor/Editor/Application.cpp index e69de29..3b1aaf3 100644 --- a/src/NazaraEditor/Editor/Application.cpp +++ b/src/NazaraEditor/Editor/Application.cpp @@ -0,0 +1,35 @@ +#include + +namespace NzEditor +{ + bool Application::NewLevel() + { + bool bResult = EditorBaseApplication::NewLevel(); + if (!bResult) + return false; + + { + auto directional = CreateEntity("SunLight"); + Nz::LightComponent& lightComponent = directional.emplace(); + Nz::DirectionalLight& light = lightComponent.AddLight(); + light.UpdateRotation(Nz::EulerAnglesf(-45.f, 0.f, 0.f)); + } + { + auto cube = CreateEntity("Cube"); + Nz::GraphicsComponent& graphicsComponent = cube.emplace(); + + std::shared_ptr 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 boxMat = Nz::MaterialInstance::Instantiate(Nz::MaterialType::Phong); + boxMat->DisablePass("ShadowPass"); + boxMat->UpdatePassesStates([&](Nz::RenderStates& states) + { + states.frontFace = Nz::FrontFace::Clockwise; + }); + std::shared_ptr boxModel = std::make_shared(std::move(boxMesh)); + boxModel->SetMaterial(0, std::move(boxMat)); + graphicsComponent.AttachRenderable(boxModel); + } + return true; + } +} \ No newline at end of file diff --git a/src/NazaraEditor/Editor/main.cpp b/src/NazaraEditor/Editor/main.cpp index e967703..5e24ea1 100644 --- a/src/NazaraEditor/Editor/main.cpp +++ b/src/NazaraEditor/Editor/main.cpp @@ -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({ + .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({ .description = "Clears log output", .path = "Clear",