Added Welcome screen
Fixed for c++ 20
This commit is contained in:
antopilo
2022-06-23 20:43:32 -04:00
parent 511e5dfb16
commit 7ba865ef14
9 changed files with 311 additions and 144 deletions

View File

@@ -115,52 +115,6 @@ int main()
glEnable(GL_DEPTH_TEST);
GuizmoShader->Bind();
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
auto camView = currentScene->m_Registry.view<Nuake::TransformComponent, Nuake::CameraComponent>();
for (auto e : camView) {
auto [transformComponent, cam] = camView.get<Nuake::TransformComponent, Nuake::CameraComponent>(e);
Nuake::Vector3 cameraPos = currentScene->m_EditorCamera->GetTranslation();
Nuake::Vector3 position = transformComponent.GlobalTranslation;
Nuake::Vector3 look = normalize(cameraPos - position);
Nuake::Vector3 right = glm::cross(currentScene->m_EditorCamera->GetUp(), look);
Nuake::Vector3 up2 = currentScene->m_EditorCamera->GetUp();
Nuake::Matrix4 transform = glm::identity<Nuake::Matrix4>();
transform[0] = Nuake::Vector4(right, 0);
transform[1] = Nuake::Vector4(up2, 0);
transform[2] = Nuake::Vector4(look, 0);
transform = glm::translate(transform, position);
GuizmoShader->SetUniformMat4f("model", transform);
GuizmoShader->SetUniformMat4f("view", currentScene->m_EditorCamera->GetTransform());
GuizmoShader->SetUniformMat4f("projection", currentScene->m_EditorCamera->GetPerspective());
camTexture->Bind(2);
GuizmoShader->SetUniform1i("gizmo_texture", 2);
Nuake::Renderer::DrawQuad(transformComponent.GetGlobalTransform());
}
auto view = currentScene->m_Registry.view<Nuake::TransformComponent, Nuake::LightComponent>();
for (auto e : view) {
auto [transformComponent, light] = view.get<Nuake::TransformComponent, Nuake::LightComponent>(e);
GuizmoShader->SetUniformMat4f("model", transformComponent.GetGlobalTransform());
GuizmoShader->SetUniformMat4f("view", currentScene->m_EditorCamera->GetTransform());
GuizmoShader->SetUniformMat4f("projection", currentScene->m_EditorCamera->GetPerspective());
lightTexture->Bind(2);
GuizmoShader->SetUniform1i("gizmo_texture", 2);
Nuake::Renderer::DrawQuad(transformComponent.GetGlobalTransform());
}
glEnable(GL_CULL_FACE);
GuizmoShader->Unbind();
ditherShader->Bind();
ditherShader->SetUniformMat4f("u_View", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetTransform());
ditherShader->SetUniformMat4f("u_Projection", Nuake::Engine::GetCurrentScene()->m_EditorCamera->GetPerspective());

View File

@@ -32,14 +32,13 @@ public:
Ref<Nuake::File> nuakeFile = Nuake::FileSystem::GetFile(path);
component.mWrenScript = CreateRef<Nuake::WrenScript>(nuakeFile, true);
auto& modules = component.mWrenScript->GetModules();
auto modules = component.mWrenScript->GetModules();
}
ImGui::EndDragDropTarget();
}
component.Script = path;
//
//ImGuiHelper::DrawVec3("Translation", &component.Translation);
ImGui::TableNextColumn();

View File

@@ -52,6 +52,7 @@ namespace Nuake {
EditorInterface::EditorInterface()
{
filesystem = new FileSystemUI(this);
_WelcomeWindow = new WelcomeWindow(this);
}
void EditorInterface::Init()
@@ -1502,15 +1503,11 @@ namespace Nuake {
Ref<Scene> SceneSnapshot;
WelcomeWindow window = WelcomeWindow();
void EditorInterface::Draw()
{
Init();
auto flags = ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_AlwaysAutoResize;
if (ImGui::BeginPopupModal("Welcome", NULL, flags))
{
ImGui::Text("Welcome to Nuake Engine");
@@ -1533,7 +1530,7 @@ namespace Nuake {
if (!Engine::GetProject())
{
ImGui::OpenPopup("Welcome");
_WelcomeWindow->Draw();
return;
}

View File

@@ -6,17 +6,13 @@
#include "../Actions/EditorSelection.h"
#include "EditorSelectionPanel.h"
#include "WelcomeWindow.h"
namespace Nuake {
class Material;
class FileSystemUI;
class EditorInterface
{
private:
FileSystemUI* filesystem;
bool m_DrawGrid = false;
bool m_ShowImGuiDemo = false;
bool m_DebugCollisions = false;
@@ -29,6 +25,8 @@ namespace Nuake {
bool m_IsMaterialSelected = false;
public:
WelcomeWindow* _WelcomeWindow;
FileSystemUI* filesystem;
EditorSelection Selection;
EditorSelectionPanel SelectionPanel;

View File

@@ -1,83 +1,264 @@
#include "WelcomeWindow.h"
#include <src/Vendors/imgui/imgui.h>
#include <src/Vendors/imgui/imgui.h>
#include "../Misc/InterfaceFonts.h"
#include <src/Core/FileSystem.h>
#include <src/Resource/Project.h>
#include <Engine.h>
#include <src/Core/Logger.h>
#include <json/json.hpp>
#include <string>
#include <vector>
#include "EditorInterface.h"
void WelcomeWindow::Draw()
#include "FileSystemUI.h"
#include <future>
namespace Nuake
{
std::vector<std::string> projects = {
"C:/Dev/Nuake-DemoProject/test.project"
};
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->GetWorkPos());
ImGui::SetNextWindowSize(viewport->GetWorkSize());
ImGui::SetNextWindowViewport(viewport->ID);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(32.0f, 32.0f));
ImGui::Begin("AL:SDAL:SKd", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize);
ProjectPreview::ProjectPreview(const std::string& path)
{
{
UIFont boldfont = UIFont(Fonts::Title);
std::string text = "Nuake Engine";
auto windowWidth = ImGui::GetWindowSize().x;
auto textWidth = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
ImGui::Text(text.c_str());
}
{
UIFont boldfont = UIFont(Fonts::SubTitle);
std::string text = "An IdTech inspired game engine";
auto windowWidth = ImGui::GetWindowSize().x;
auto textWidth = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
ImGui::Text(text.c_str());
}
ImGui::Separator();
{
UIFont boldfont = UIFont(Fonts::SubTitle);
ImGui::Text("Projects recently opened");
}
ImVec2 projectsWindowSize = ImGui::GetContentRegionAvail();
projectsWindowSize.x *= 0.6f;
int idx = 0;
ImGui::BeginChild("Projects", projectsWindowSize, true);
{
for (int i = 0; i < 6; i++)
{
float cursorY = ImGui::GetCursorPosY();
std::string selectableName = "##My new project" + std::to_string(i);
ImGui::Selectable(selectableName.c_str(), false, 0, ImVec2(ImGui::GetContentRegionAvailWidth(), 100));
ImGui::SetCursorPosY(cursorY);
{
UIFont boldfont = UIFont(Fonts::LargeBold);
ImGui::Text("Name of project");
}
{
UIFont boldfont = UIFont(Fonts::Bold);
ImGui::Text("last modified on 10/20/2022");
}
{
UIFont boldfont = UIFont(Fonts::Normal);
ImGui::TextWrapped("Description lajsflkahjfklashklashgkASDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDlashglkashlkghalskghaslghaslkghaklsg");
//ImGui::Text("Description lajsflkahjfklashklashgklashglkashlkghalskghaslghaslkghaklsg");
}
ImGui::SetCursorPosY(cursorY + 100);
}
}
ImGui::EndChild();
Path = path;
ReadProjectFile();
}
ImGui::End();
ImGui::PopStyleVar();
ImGui::PopStyleVar();
}
void ProjectPreview::ReadProjectFile()
{
std::string projectFile = Nuake::FileSystem::ReadFile(Path);
if (projectFile != "")
{
nlohmann::json projectJson = nlohmann::json::parse(projectFile);
Name = projectJson["Name"];
Description = projectJson["Description"];
}
else
{
Name = Path;
Description = "Error read project file";
}
}
json ProjectPreview::Serialize()
{
BEGIN_SERIALIZE();
j["Path"] = this->Path;
END_SERIALIZE();
}
bool ProjectPreview::Deserialize(const std::string& str)
{
BEGIN_DESERIALIZE(str);
if (!j.contains("Path"))
return false;
Path = j["Path"];
ReadProjectFile();
return true;
}
WelcomeWindow::WelcomeWindow(Nuake::EditorInterface* editor) : _Editor(editor)
{
_Projects = std::vector<ProjectPreview>();
ParseRecentFile();
}
void WelcomeWindow::Draw()
{
ImGuiViewport* viewport = ImGui::GetMainViewport();
ImGui::SetNextWindowPos(viewport->GetWorkPos());
ImGui::SetNextWindowSize(viewport->GetWorkSize());
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);
{
{
UIFont boldfont = UIFont(Fonts::Title);
std::string text = "Nuake Engine";
auto windowWidth = ImGui::GetWindowSize().x;
auto textWidth = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
ImGui::Text(text.c_str());
}
{
UIFont boldfont = UIFont(Fonts::SubTitle);
std::string text = "An IdTech inspired game engine";
auto windowWidth = ImGui::GetWindowSize().x;
auto textWidth = ImGui::CalcTextSize(text.c_str()).x;
ImGui::SetCursorPosX((windowWidth - textWidth) * 0.5f);
ImGui::Text(text.c_str());
}
ImGui::Separator();
{
UIFont boldfont = UIFont(Fonts::SubTitle);
ImGui::Text("Projects recently opened");
}
ImVec2 projectsWindowSize = ImGui::GetContentRegionAvail();
projectsWindowSize.x *= 0.6f;
ImGui::BeginChild("Projects", projectsWindowSize, true);
{
const uint32_t itemHeight = 120;
for (uint32_t i = 0; i < std::size(_Projects); i++)
{
ProjectPreview& project = _Projects[i];
float cursorYStart = ImGui::GetCursorPosY();
std::string selectableName = "##" + std::to_string(i);
bool isSelected = SelectedProject == i;
if (ImGui::Selectable(selectableName.c_str(), isSelected, ImGuiSelectableFlags_AllowItemOverlap, ImVec2(ImGui::GetContentRegionAvailWidth(), itemHeight)))
{
SelectedProject = i;
}
ImGui::SetCursorPosY(cursorYStart);
{
UIFont boldfont = UIFont(Fonts::LargeBold);
ImGui::Text(project.Name.c_str());
}
{
UIFont boldfont = UIFont(Fonts::Bold);
ImGui::Text(project.Description.c_str());
}
ImGui::SetCursorPosY(cursorYStart + itemHeight);
}
if (ImGui::Button("Import an existing project", ImVec2(ImGui::GetContentRegionAvailWidth(), itemHeight)))
{
std::string path = FileDialog::OpenFile("*.project");
if (path != "")
{
bool alreadyContainsProject = false;
for (auto& p : _Projects)
{
if (p.Path == path)
alreadyContainsProject = true;
}
if (!alreadyContainsProject)
{
_Projects.push_back(ProjectPreview(path));
}
}
}
}
ImGui::EndChild();
ImGui::SameLine();
if (ImGui::BeginChild("Controls", ImGui::GetContentRegionAvail(), true))
{
ImVec2 buttonSize = ImVec2(ImGui::GetContentRegionAvailWidth(), 58);
if (ImGui::Button("New Project", buttonSize))
{
std::string selectedProject = FileDialog::SaveFile("Project file\0*.project");
if (selectedProject == "") // Hit cancel
return;
auto pathSplit = String::Split(selectedProject, '/');
auto projectFileName = pathSplit[pathSplit.size() - 1];
Ref<Project> project = Project::New(projectFileName, "no description", selectedProject + ".project");
Engine::LoadProject(project);
Engine::LoadScene(Scene::New());
project->Save();
auto projectPreview = ProjectPreview();
projectPreview.Name = project->Name;
projectPreview.Description = project->Description;
projectPreview.Path = project->FullPath;
_Projects.push_back(projectPreview);
}
ImGui::Separator();
if (SelectedProject != -1)
{
if (ImGui::Button("Load Project", buttonSize))
{
assert(SelectedProject < std::size(_Projects));
using namespace Nuake;
SaveRecentFile();
std::string projectPath = _Projects[SelectedProject].Path;
FileSystem::SetRootDirectory(projectPath + "/../");
auto project = Project::New();
auto projectFileData = FileSystem::ReadFile(projectPath, true);
if (!project->Deserialize(projectFileData))
{
Logger::Log("Error loading project: " + projectPath, CRITICAL);
return;
}
project->FullPath = projectPath;
Engine::LoadProject(project);
Engine::GetCurrentWindow()->SetTitle("Nuake Engine - Editing " + project->Name);
}
if (ImGui::Button("Remove Project"))
{
_Projects.erase(_Projects.begin() + SelectedProject);
}
}
}
ImGui::EndChild();
}
ImGui::End();
ImGui::PopStyleVar();
ImGui::PopStyleVar();
}
void WelcomeWindow::ParseRecentFile()
{
if (!FileSystem::FileExists(_RecentProjectFilePath))
{
FileSystem::BeginWriteFile(_RecentProjectFilePath);
FileSystem::WriteLine(_RecentProjectFileDefaultContent);
FileSystem::EndWriteFile();
}
std::string content = Nuake::FileSystem::ReadFile(_RecentProjectFilePath);
if (content != "")
{
nlohmann::json j = nlohmann::json::parse(content);
for (auto& project : j["Projects"])
{
auto projectPreview = ProjectPreview();
projectPreview.Deserialize(project.dump());
_Projects.push_back(projectPreview);
}
}
}
void WelcomeWindow::SaveRecentFile()
{
std::string str;
BEGIN_SERIALIZE();
for (uint32_t i = 0; i < std::size(_Projects); i++)
{
ProjectPreview& project = _Projects[i];
j["Projects"][i] = project.Serialize();
}
FileSystem::BeginWriteFile(_RecentProjectFilePath);
FileSystem::WriteLine(j.dump(4));
FileSystem::EndWriteFile();
}
}

View File

@@ -1,9 +1,46 @@
#pragma once
#include <src/Resource/Serializable.h>
#include <string>
#include <vector>
namespace Nuake
{
class ProjectPreview : ISerializable
{
public:
std::string Name;
std::string Path;
std::string Description;
class WelcomeWindow {
public:
int SelectedProject = 0;
ProjectPreview(const std::string& path);
ProjectPreview() = default;
~ProjectPreview() = default;
void Draw();
};
json Serialize() override;
bool Deserialize(const std::string& data) override;
private:
void ReadProjectFile();
};
class EditorInterface;
class WelcomeWindow
{
private:
const std::string _RecentProjectFilePath = "recent.json";
const std::string _RecentProjectFileDefaultContent = "{ \"Projects\": [ ] }";
std::vector<ProjectPreview> _Projects;
uint32_t SelectedProject = 0;
EditorInterface* _Editor;
public:
WelcomeWindow(Nuake::EditorInterface* editor);
~WelcomeWindow() = default;
void Draw();
private:
void ParseRecentFile();
void SaveRecentFile();
};
}

View File

@@ -38,10 +38,10 @@ namespace Nuake
private:
static RenderList m_RenderList;
public:
static VertexArray* Renderer::QuadVertexArray;
static VertexBuffer* Renderer::QuadVertexBuffer;
static VertexArray* Renderer::CubeVertexArray;
static VertexBuffer* Renderer::CubeVertexBuffer;
static VertexArray* QuadVertexArray;
static VertexBuffer* QuadVertexBuffer;
static VertexArray* CubeVertexArray;
static VertexBuffer* CubeVertexBuffer;
static Shader* m_Shader;
static Shader* m_ShadowmapShader;
@@ -73,8 +73,6 @@ namespace Nuake
static void RegisterLight(TransformComponent transform, LightComponent light);
static void RegisterDeferredLight(TransformComponent transform, LightComponent light);
// Debug
static void DrawLine(Vector3 start, Vector3 end, Color color, Matrix4 transform = Matrix4());
static void DrawDebugLine(glm::vec3 start, glm::vec3 end, glm::vec4 color);

View File

@@ -17,6 +17,10 @@ namespace Nuake {
for (auto& e : entities)
{
WrenScriptComponent& wren = entities.get<WrenScriptComponent>(e);
if (!wren.mWrenScript)
continue;
wren.mWrenScript->Build(wren.mModule, true);
if (!wren.mWrenScript->HasCompiledSuccesfully())
@@ -29,7 +33,6 @@ namespace Nuake {
return true;
}
void ScriptingSystem::Update(Timestep ts)
{
if (!Engine::IsPlayMode)

View File

@@ -116,7 +116,7 @@ namespace Nuake
Props[type] = prop;
}
PropValue& GetProp(PropType type)
PropValue GetProp(PropType type)
{
if (Props.find(type) != Props.end())
return Props[type];