From 0b87dd1585e314032f0488f2d35e261f089bd807 Mon Sep 17 00:00:00 2001 From: Antoine Pilote Date: Sun, 23 Jul 2023 00:47:10 -0400 Subject: [PATCH] Added splash screen --- Editor/src/Windows/EditorInterface.cpp | 33 +++++++++++++++++ Editor/src/Windows/LoadingSplash.cpp | 51 ++++++++++++++++++++++++++ Editor/src/Windows/LoadingSplash.h | 29 +++++++++++++++ Editor/src/Windows/WelcomeWindow.cpp | 43 +++++++++++++--------- Editor/src/Windows/WelcomeWindow.h | 4 +- Nuake/src/Window.cpp | 28 ++++++++++++++ Nuake/src/Window.h | 8 +++- 7 files changed, 176 insertions(+), 20 deletions(-) create mode 100644 Editor/src/Windows/LoadingSplash.cpp create mode 100644 Editor/src/Windows/LoadingSplash.h diff --git a/Editor/src/Windows/EditorInterface.cpp b/Editor/src/Windows/EditorInterface.cpp index ebbbb444..bb8afb2f 100644 --- a/Editor/src/Windows/EditorInterface.cpp +++ b/Editor/src/Windows/EditorInterface.cpp @@ -41,6 +41,8 @@ #include "../Misc/InterfaceFonts.h" #include "WelcomeWindow.h" +#include "LoadingSplash.h" + #include "src/Rendering/SceneRenderer.h" #include #include @@ -1505,10 +1507,41 @@ namespace Nuake { } } + bool isLoadingProject = false; + bool isLoadingProjectQueue = false; + + int frameCount = 2; void EditorInterface::Draw() { Init(); + if (isLoadingProjectQueue) + { + _WelcomeWindow->LoadQueuedProject(); + isLoadingProjectQueue = false; + + auto& window = Window::Get(); + window->SetDecorated(true); + window->SetSize({ 1900, 1000 }); + window->Center(); + frameCount = 0; + return; + } + + if (_WelcomeWindow->IsProjectQueued() && frameCount > 0) + { + // draw splash + LoadingSplash::Get().Draw(); + + frameCount--; + if (frameCount == 0) + { + isLoadingProjectQueue = true; + } + + return; + } + if (!Engine::GetProject()) { _WelcomeWindow->Draw(); diff --git a/Editor/src/Windows/LoadingSplash.cpp b/Editor/src/Windows/LoadingSplash.cpp new file mode 100644 index 00000000..14fb642a --- /dev/null +++ b/Editor/src/Windows/LoadingSplash.cpp @@ -0,0 +1,51 @@ +#include "LoadingSplash.h" + +#include "../Misc/InterfaceFonts.h" + +#include +#include "src/Window.h" + + +#include + +#include +#include + + +LoadingSplash::LoadingSplash() +{ + _NuakeLogo = Nuake::TextureManager::Get()->GetTexture(NUAKE_LOGO_PATH); + + Nuake::Window::Get()->SetDecorated(false); + Nuake::Window::Get()->SetSize({ 640, 480 }); + Nuake::Window::Get()->Center(); +} + +void LoadingSplash::Draw() +{ + using namespace Nuake; + + // Make viewport fullscreen + ImGuiViewport* viewport = ImGui::GetMainViewport(); + ImGui::SetNextWindowPos(viewport->Pos); + ImGui::SetNextWindowSize(viewport->Size); + ImGui::SetNextWindowViewport(viewport->ID); + + ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f); + ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(32.0f, 32.0f)); + ImGui::Begin("Welcome Screen", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize); + { + // Draw Nuake logo + { + const Vector2 logoSize = _NuakeLogo->GetSize(); + const ImVec2 imguiSize = ImVec2(logoSize.x, logoSize.y); + ImGui::Image((ImTextureID)_NuakeLogo->GetID(), imguiSize, ImVec2(0, 1), ImVec2(1, 0)); + } + + ImGui::Text("LOADING SCENE..."); + } + + ImGui::End(); + ImGui::PopStyleVar(); + ImGui::PopStyleVar(); +} \ No newline at end of file diff --git a/Editor/src/Windows/LoadingSplash.h b/Editor/src/Windows/LoadingSplash.h new file mode 100644 index 00000000..5f36f8ea --- /dev/null +++ b/Editor/src/Windows/LoadingSplash.h @@ -0,0 +1,29 @@ +#pragma once +#include +#include + +#include + +namespace Nuake +{ + class Texture; +} + +class LoadingSplash +{ +private: + const std::string NUAKE_LOGO_PATH = "resources/Images/logo_white.png"; + Ref _NuakeLogo; + +public: + static LoadingSplash& LoadingSplash::Get() + { + static LoadingSplash instance; + return instance; + } + + LoadingSplash(); + ~LoadingSplash() = default; + + void Draw(); +}; \ No newline at end of file diff --git a/Editor/src/Windows/WelcomeWindow.cpp b/Editor/src/Windows/WelcomeWindow.cpp index 43b400e6..19cd126d 100644 --- a/Editor/src/Windows/WelcomeWindow.cpp +++ b/Editor/src/Windows/WelcomeWindow.cpp @@ -82,6 +82,30 @@ namespace Nuake _NuakeLogo = TextureManager::Get()->GetTexture(NUAKE_LOGO_PATH); } + void WelcomeWindow::LoadQueuedProject() + { + auto project = Project::New(); + auto projectFileData = FileSystem::ReadFile(queuedProjectPath, true); + try + { + project->Deserialize(projectFileData); + project->FullPath = queuedProjectPath; + + Engine::LoadProject(project); + + _Editor->filesystem->m_CurrentDirectory = Nuake::FileSystem::RootDirectory; + } + catch (std::exception exception) + { + Logger::Log("Error loading project: " + queuedProjectPath, "editor", CRITICAL); + Logger::Log(exception.what()); + return; + } + + queuedProjectPath = ""; + Engine::GetCurrentWindow()->SetTitle("Nuake Engine - Editing " + project->Name); + } + void WelcomeWindow::Draw() { // Make viewport fullscreen @@ -257,24 +281,7 @@ namespace Nuake std::string projectPath = _Projects[SelectedProject].Path; FileSystem::SetRootDirectory(FileSystem::GetParentPath(projectPath)); - auto project = Project::New(); - auto projectFileData = FileSystem::ReadFile(projectPath, true); - try - { - project->Deserialize(projectFileData); - project->FullPath = projectPath; - - Engine::LoadProject(project); - - _Editor->filesystem->m_CurrentDirectory = Nuake::FileSystem::RootDirectory; - } - catch (std::exception exception) - { - Logger::Log("Error loading project: " + projectPath, "editor", CRITICAL); - Logger::Log(exception.what()); - } - - Engine::GetCurrentWindow()->SetTitle("Nuake Engine - Editing " + project->Name); + queuedProjectPath = projectPath; } } } diff --git a/Editor/src/Windows/WelcomeWindow.h b/Editor/src/Windows/WelcomeWindow.h index 3117fcec..6594f560 100644 --- a/Editor/src/Windows/WelcomeWindow.h +++ b/Editor/src/Windows/WelcomeWindow.h @@ -41,13 +41,15 @@ namespace Nuake uint32_t SelectedProject = 0; std::vector _Projects; - + std::string queuedProjectPath; public: WelcomeWindow(Nuake::EditorInterface* editor); ~WelcomeWindow() = default; void Draw(); + bool IsProjectQueued() const { return !queuedProjectPath.empty(); }; + void LoadQueuedProject(); private: void DrawRecentProjectsSection(); void DrawProjectItem(const uint32_t projectPreview); diff --git a/Nuake/src/Window.cpp b/Nuake/src/Window.cpp index 2cbf8180..02151a32 100644 --- a/Nuake/src/Window.cpp +++ b/Nuake/src/Window.cpp @@ -180,6 +180,12 @@ namespace Nuake glfwSetWindowSize(m_Window, size.x, size.y); } + void Window::SetPosition(const Vector2& position) + { + m_Position = position; + glfwSetWindowPos(m_Window, position.x, position.y); + } + void Window::SetMonitor(int monitorIdx) { int monitorCount; @@ -193,6 +199,23 @@ namespace Nuake } } + void Window::Center() + { + const int windowWidth = 640; + const int windowHeight = 360; + + // Get the primary monitor's video mode + const GLFWvidmode* mode = glfwGetVideoMode(glfwGetPrimaryMonitor()); + + // Calculate the position to center the window + const int xPos = (mode->width - m_Width) / 2; + const int yPos = (mode->height - m_Height) / 2; + + // Set the window's position + Nuake::Window::Get()->SetSize({ m_Width, m_Height }); + Nuake::Window::Get()->SetPosition({ xPos, yPos }); + } + Ref Window::GetScene() { return m_Scene; @@ -228,6 +251,11 @@ namespace Nuake glfwSwapInterval(enabled ? 0 : 1); } + void Window::SetDecorated(bool enabled) + { + glfwSetWindowAttrib(m_Window, GLFW_DECORATED, enabled); + } + void Window::InitImgui() { ImGui::CreateContext(); diff --git a/Nuake/src/Window.h b/Nuake/src/Window.h index 3c8c892e..1905beb6 100644 --- a/Nuake/src/Window.h +++ b/Nuake/src/Window.h @@ -22,7 +22,8 @@ namespace Nuake std::string m_Title; uint32_t m_Width; uint32_t m_Height; - + Vector2 m_Position; + Ref m_Framebuffer; Ref m_Scene; @@ -48,8 +49,12 @@ namespace Nuake Vector2 GetSize() const; void SetSize(const Vector2& size); + void SetPosition(const Vector2& position); + void SetMonitor(int monitor); + void Center(); + Ref GetScene(); bool SetScene(Ref scene); @@ -59,6 +64,7 @@ namespace Nuake void SetWindowIcon(const std::string& path); void SetVSync(bool enabled); + void SetDecorated(bool enabled); private: void InitImgui(); };