Merge pull request #49 from antopilo/feature/NK-144-splash-screen
NK-144 Added splash screen
This commit is contained in:
@@ -41,6 +41,8 @@
|
||||
#include "../Misc/InterfaceFonts.h"
|
||||
|
||||
#include "WelcomeWindow.h"
|
||||
#include "LoadingSplash.h"
|
||||
|
||||
#include "src/Rendering/SceneRenderer.h"
|
||||
#include <dependencies/glfw/include/GLFW/glfw3.h>
|
||||
#include <src/Rendering/Buffers/Framebuffer.h>
|
||||
@@ -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();
|
||||
|
||||
51
Editor/src/Windows/LoadingSplash.cpp
Normal file
51
Editor/src/Windows/LoadingSplash.cpp
Normal file
@@ -0,0 +1,51 @@
|
||||
#include "LoadingSplash.h"
|
||||
|
||||
#include "../Misc/InterfaceFonts.h"
|
||||
|
||||
#include <src/Core/Maths.h>
|
||||
#include "src/Window.h"
|
||||
|
||||
|
||||
#include <src/Vendors/imgui/imgui.h>
|
||||
|
||||
#include <dependencies/glfw/include/GLFW/glfw3.h>
|
||||
#include <src/Rendering/Textures/TextureManager.h>
|
||||
|
||||
|
||||
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();
|
||||
}
|
||||
29
Editor/src/Windows/LoadingSplash.h
Normal file
29
Editor/src/Windows/LoadingSplash.h
Normal file
@@ -0,0 +1,29 @@
|
||||
#pragma once
|
||||
#include <src/Core/Core.h>
|
||||
#include <src/Rendering/Textures/Texture.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace Nuake
|
||||
{
|
||||
class Texture;
|
||||
}
|
||||
|
||||
class LoadingSplash
|
||||
{
|
||||
private:
|
||||
const std::string NUAKE_LOGO_PATH = "resources/Images/logo_white.png";
|
||||
Ref<Nuake::Texture> _NuakeLogo;
|
||||
|
||||
public:
|
||||
static LoadingSplash& LoadingSplash::Get()
|
||||
{
|
||||
static LoadingSplash instance;
|
||||
return instance;
|
||||
}
|
||||
|
||||
LoadingSplash();
|
||||
~LoadingSplash() = default;
|
||||
|
||||
void Draw();
|
||||
};
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,13 +41,15 @@ namespace Nuake
|
||||
|
||||
uint32_t SelectedProject = 0;
|
||||
std::vector<ProjectPreview> _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);
|
||||
|
||||
@@ -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<Scene> 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();
|
||||
|
||||
@@ -22,7 +22,8 @@ namespace Nuake
|
||||
std::string m_Title;
|
||||
uint32_t m_Width;
|
||||
uint32_t m_Height;
|
||||
|
||||
Vector2 m_Position;
|
||||
|
||||
Ref<FrameBuffer> m_Framebuffer;
|
||||
Ref<Scene> 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<Scene> GetScene();
|
||||
bool SetScene(Ref<Scene> scene);
|
||||
|
||||
@@ -59,6 +64,7 @@ namespace Nuake
|
||||
void SetWindowIcon(const std::string& path);
|
||||
void SetVSync(bool enabled);
|
||||
|
||||
void SetDecorated(bool enabled);
|
||||
private:
|
||||
void InitImgui();
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user