Added new project wizard window

This commit is contained in:
Antoine Pilote
2024-08-30 21:43:37 -04:00
parent d42c2154cf
commit d46f74aa24
12 changed files with 456 additions and 43 deletions

View File

@@ -116,8 +116,8 @@ Nuake::Application* Nuake::CreateApplication(int argc, char** argv)
ApplicationSpecification specification
{
.Name = "Editor",
.WindowWidth = 1600,
.WindowHeight = 900,
.WindowWidth = 1100,
.WindowHeight = 630,
.VSync = true
};

View File

@@ -107,6 +107,7 @@ namespace Nuake {
filesystem = new FileSystemUI(this);
_WelcomeWindow = new WelcomeWindow(this);
_NewProjectWindow = new NewProjectWindow(this);
_audioWindow = new AudioWindow();
m_ProjectSettingsWindow = new ProjectSettingsWindow();
@@ -2875,6 +2876,7 @@ namespace Nuake {
bool isLoadingProject = false;
bool isLoadingProjectQueue = false;
bool EditorInterface::isCreatingNewProject = false;
UIDemoWindow m_DemoWindow;
int frameCount = 2;
@@ -2882,6 +2884,11 @@ namespace Nuake {
{
Init();
if (isCreatingNewProject && !_NewProjectWindow->HasCreatedProject())
{
_NewProjectWindow->Draw();
}
if (isLoadingProjectQueue)
{
_WelcomeWindow->LoadQueuedProject();
@@ -2889,7 +2896,7 @@ namespace Nuake {
auto window = Window::Get();
window->SetDecorated(true);
window->SetSize({ 1900, 1000 });
window->SetSize({ 1100, 1000 });
window->Maximize();
window->Center();
frameCount = 0;

View File

@@ -9,6 +9,7 @@
#include "../Actions/EditorSelection.h"
#include "EditorSelectionPanel.h"
#include "WelcomeWindow.h"
#include "NewProjectWindow.h"
#include "AudioWindow.h"
#include "../Windows/TrenchbroomConfiguratorWindow.h"
#include "../Commands/CommandBuffer.h"
@@ -18,6 +19,7 @@
#include <src/Scripting/ScriptingEngineNet.h>
#include "ProjectSettings/ProjectSettingsWindow.h"
using namespace NuakeEditor;
namespace Nuake
@@ -45,7 +47,6 @@ namespace Nuake
bool m_ShowTrenchbroomConfigurator = false;
bool m_ShowProjectSettings = false;
bool m_ShowMapImporter = false;
Vector2 m_ViewportPos = {0, 0};
Vector2 m_ViewportSize = {};
@@ -62,6 +63,9 @@ namespace Nuake
Color m_StatusBarColor = Color(0.08f, 0.08f, 0.08f, 1.0f);
public:
WelcomeWindow* _WelcomeWindow;
NewProjectWindow* _NewProjectWindow;
static bool isCreatingNewProject;
AudioWindow* _audioWindow;
FileSystemUI* filesystem;
static EditorSelection Selection;

View File

@@ -0,0 +1,361 @@
#include "NewProjectWindow.h"
#include "imgui/imgui.h"
#include "../Misc/InterfaceFonts.h"
#include <src/Resource/FontAwesome5.h>
#include <src/Rendering/Textures/TextureManager.h>
#include <src/Rendering/Textures/Texture.h>
#include <src/Scene/Entities/ImGuiHelper.h>
#include <src/Core/FileSystem.h>
#include <src/UI/ImUI.h>
#include <src/Core/Logger.h>
#include <src/Resource/Project.h>
#include <Engine.h>
#include "EditorInterface.h"
#include "FileSystemUI.h"
namespace Nuake
{
NewProjectWindow::NewProjectWindow(EditorInterface* editor) :
m_Editor(editor)
{
}
void NewProjectWindow::Draw()
{
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));
if (ImGui::Begin("NewProjectScreen", 0, ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoResize))
{
{
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 16.0f);
bool opened = ImGui::BeginChild("TemplatesView", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f, ImGui::GetContentRegionAvail().y), false, ImGuiChildFlags_AlwaysUseWindowPadding);
if (opened)
{
ImGui::PopStyleVar();
UIFont boldFont(Fonts::SubTitle);
ImGui::Text("Templates");
ImGui::Dummy(ImVec2(32, 16));
}
if (!opened)
{
ImGui::PopStyleVar();
}
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0.1, 0.1, 0.1, 0.2f));
ImGui::BeginChild("TemplateContainer", { ImGui::GetContentRegionAvail().x - 64.0f, ImGui::GetContentRegionAvail().y }, true, ImGuiChildFlags_AlwaysUseWindowPadding);
{
ImGui::Dummy({ 4, 4 });
DrawProjectTemplate(0, "Minimal", "The bare minimum required to get started in Nuake.");
ImGui::Dummy({ 4, 2 });
DrawProjectTemplate(1, "Shooter", "A Simple first person shooter game.");
ImGui::Dummy({ 4, 2 });
DrawProjectTemplate(2, "Demo", "The Nuake demo project.");
}
ImGui::EndChild();
ImGui::PopStyleColor();
ImGui::EndChild();
ImGui::PopStyleColor();
}
ImGui::SameLine();
{
ImGui::PushStyleColor(ImGuiCol_ChildBg, ImVec4(0, 0, 0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_ChildRounding, 16.0f);
bool opened = ImGui::BeginChild("ProjectSetupView", ImVec2(ImGui::GetContentRegionAvail().x, ImGui::GetContentRegionAvail().y), false);
if (opened)
{
ImGui::PopStyleVar();
{
UIFont boldFont(Fonts::SubTitle);
ImGui::Text("Project Setup");
}
ImGui::Dummy(ImVec2(32, 16));
static std::string projectTitle = "";
static bool showTitleEmptyWarning = false;
static bool showPathWarning = false;
ImGui::Text("Title");
if (showTitleEmptyWarning && projectTitle.empty())
{
ImGui::SameLine();
ImGui::TextColored({ 1.0, 0.1, 0.1, 1.0 }, ICON_FA_EXCLAMATION_TRIANGLE);
Nuake::UI::Tooltip("Title required");
}
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::InputText("##ProjectTitle", &projectTitle);
ImGui::Dummy(ImVec2(32, 16));
ImGui::Text("Description");
ImGui::TextColored(ImVec4(1, 1, 1, 0.4), "A description for your new project");
static std::string description = "";
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x);
ImGui::InputText("##ProjectDescription", &description);
ImGui::Dummy(ImVec2(32, 16));
ImGui::Text("Location");
static std::string location = "";
static bool isPathValid = Nuake::FileSystem::DirectoryExists(location, true);
if ((showPathWarning && location.empty()) || (!location.empty() && !Nuake::FileSystem::DirectoryExists(location, true)))
{
ImGui::SameLine();
ImGui::TextColored({ 1.0, 0.1, 0.1, 1.0 }, ICON_FA_EXCLAMATION_TRIANGLE);
if (location.empty())
{
Nuake::UI::Tooltip("Path required");
}
else if (!isPathValid)
{
Nuake::UI::Tooltip("Path doesn't exist");
}
}
ImGui::TextColored(ImVec4(1, 1, 1, 0.4), "A folder in which to create your new project");
std::string finalLocation = "";
static std::string projectFileName = "";
ImGui::SetNextItemWidth(ImGui::GetContentRegionAvail().x - 40.0f);
ImGui::InputText("##Location", &location); ImGui::SameLine();
if (ImGui::Button((ICON_FA_FOLDER + std::string("##folderOpen")).c_str()))
{
std::string folderPath = Nuake::FileDialog::SaveFile("Project File\0*.project");
folderPath = Nuake::String::ReplaceSlash(folderPath);
if (!folderPath.empty())
{
auto splits = Nuake::String::Split(folderPath, '/');
projectFileName = splits[splits.size() - 1];
if (!Nuake::String::EndsWith(projectFileName, ".project"))
{
projectFileName += ".project";
}
location = "";
for (int i = 0; i < splits.size() - 1; i++)
{
location += splits[i] + "/";
}
}
}
finalLocation = location;
static std::string projectParentPath = location;
projectParentPath = location;
static bool placeInFolder = false;
if (placeInFolder)
{
projectParentPath += projectTitle + "/";
}
finalLocation = projectParentPath + projectFileName;
if (!location.empty())
{
ImGui::TextColored(ImVec4(1, 1, 1, 0.4), "Project will be created at under:");
ImGui::TextColored(ImVec4(1, 1, 1, 0.4), (finalLocation).c_str());
}
ImGui::Dummy(ImVec2(32, 16));
ImGui::Text("Other");
ImGui::Checkbox("Place in empty folder", &placeInFolder);
static bool generateCsharpProject = true;
ImGui::Checkbox("Generate C# project", &generateCsharpProject);
static ImVec4 primaryColor = { 97.0f / 255.0f, 0.0f, 1.0f, 1.0f};
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, { 8, 8 });
ImGui::ColorEdit3("Accent color", &primaryColor.x, ImGuiColorEditFlags_NoInputs);
ImGui::PopStyleVar();
ImGui::Dummy({ 1, ImGui::GetContentRegionAvail().y - 42 });
ImGui::Dummy({ ImGui::GetContentRegionAvail().x - 130, 38 }); ImGui::SameLine();
if (Nuake::UI::PrimaryButton((ICON_FA_PLUS + std::string(" Create")).c_str(), Nuake::Vector2{ 120, 38 }, Nuake::Color(primaryColor.x, primaryColor.y, primaryColor.z, primaryColor.w)))
{
if (projectTitle.empty())
{
showTitleEmptyWarning = true;
}
else
{
showTitleEmptyWarning = false;
}
if (location.empty())
{
showPathWarning = true;
}
else if (Nuake::FileSystem::DirectoryExists(location, true))
{
showPathWarning = false;
}
if (!showTitleEmptyWarning && !showPathWarning)
{
// Create project
if (Nuake::String::EndsWith(finalLocation, ".project"))
{
// We need to create a folder
if (const auto& dirPath = projectParentPath; !std::filesystem::create_directory(dirPath))
{
// Should we continue?
Nuake::Logger::Log("Failed creating project directory: " + dirPath);
}
}
Nuake::FileSystem::SetRootDirectory(projectParentPath);
auto project = Nuake::Project::New(projectTitle, description, finalLocation);
Nuake::Engine::LoadProject(project);
Nuake::Engine::LoadScene(Nuake::Scene::New());
project->Settings.PrimaryColor = Nuake::Color(primaryColor.x, primaryColor.y, primaryColor.z, primaryColor.w);
project->Save();
auto window = Nuake::Window::Get();
window->SetDecorated(true);
window->Maximize();
m_Editor->filesystem->m_CurrentDirectory = Nuake::FileSystem::RootDirectory;
m_HasCreatedProject = true;
}
}
}
if (!opened)
{
ImGui::PopStyleVar();
}
ImGui::EndChild();
ImGui::PopStyleColor();
}
ImGui::End();
}
ImGui::PopStyleVar(2);
}
bool opened = true;
void NewProjectWindow::DrawProjectTemplate(uint32_t i, const std::string& title, const std::string& description)
{
opened = true;
ImGui::ShowDemoWindow(&opened);
ImGui::Dummy({ 4, 4 });
ImGui::SameLine();
opened = true;
const uint32_t itemHeight = 50;
const float cursorYStart = ImGui::GetCursorPosY();
const std::string selectableName = "##" + title;
const bool isSelected = m_SelectedTemplate == i;
//ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(10.0f / 255.f, 182.0f / 255.f, 255.f / 255.f, 1.0f));
ImDrawList* draw_list = ImGui::GetWindowDrawList();
draw_list->ChannelsSplit(2);
// Channel number is like z-order. Widgets in higher channels are rendered above widgets in lower channels.
draw_list->ChannelsSetCurrent(1);
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 8.0f);
ImGui::PushStyleColor(ImGuiCol_Header, ImVec4(0.25, 0.25, 0.5, 0.0));
ImGui::PushStyleColor(ImGuiCol_HeaderActive, ImVec4(0.25, 0.25, 0.5, 0.0));
ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImVec4(0.25, 0.25, 0.5, 0.0));
bool result = ImGui::Selectable(selectableName.c_str(), m_SelectedTemplate == i, ImGuiSelectableFlags_AllowOverlap | ImGuiSelectableFlags_AllowDoubleClick, ImVec2(ImGui::GetContentRegionAvail().x - 12, itemHeight));
ImGui::PopStyleVar();
if (result)
{
m_SelectedTemplate == i;
}
ImU32 color = IM_COL32(63, 63, 66, 128);
if (isSelected)
{
color = IM_COL32(63, 69, 79, 255);
}
else if (ImGui::IsItemHovered())
{
color = IM_COL32(20, 20, 20, 128);
}
draw_list->ChannelsSetCurrent(0);
ImVec2 p_min = ImGui::GetItemRectMin();
ImVec2 p_max = ImGui::GetItemRectMax();
ImGui::GetWindowDrawList()->AddRectFilled(p_min, p_max, color, 4.0f);
draw_list->ChannelsMerge();
ImGui::PopStyleColor(3);
if (result)
{
m_SelectedTemplate = i;
}
//ImGui::PopStyleColor();
const ImVec2 padding = ImVec2(16.0f, 0.0f);
const ImVec2 iconSize = ImVec2(50, 50.0f);
ImGui::SetCursorPos(ImVec2(padding.x / 2.0, padding.y / 2.0) + ImVec2(4, cursorYStart));
ImGui::Image((void*)Nuake::TextureManager::Get()->GetTexture("Resources/Images/cube.png")->GetID(), iconSize, ImVec2(0, 1), ImVec2(1, 0));
ImGui::SameLine();
ImGui::SetCursorPosX(padding.x + iconSize.x);
ImGui::SetCursorPosY(cursorYStart + 8.0f);
{
UIFont boldfont = UIFont(Fonts::Normal);
if (isSelected)
{
ImGui::TextColored(ImVec4(119.0f / 255.0f, 187.0f / 255.0f, 1, 255.0f), title.c_str());
}
else
{
ImGui::Text(title.c_str());
}
}
ImGui::SetCursorPosY(cursorYStart + 28.f);
{
ImGui::SetCursorPosX(padding.x + iconSize.x);
UIFont boldfont = UIFont(Fonts::Normal);
if (isSelected)
{
ImGui::TextColored(ImVec4(119.0f / 255.0f, 187.0f / 255.0f, 1, 255.0f), (ICON_FA_INFO_CIRCLE + std::string(" ") + description).c_str());
}
else
{
ImGui::TextColored(ImVec4(1, 1, 1, 0.4), (ICON_FA_INFO_CIRCLE + std::string(" ") + description).c_str());
}
}
ImGui::SetCursorPosY(cursorYStart + itemHeight + 4.0f);
}
}

View File

@@ -0,0 +1,28 @@
#pragma once
#include <string>
namespace Nuake
{
class EditorInterface;
class NewProjectWindow
{
private:
uint32_t m_SelectedTemplate = 0;
bool m_HasCreatedProject = false;
EditorInterface* m_Editor;
public:
NewProjectWindow(EditorInterface* editor);
~NewProjectWindow() = default;
void Draw();
void DrawProjectTemplate(uint32_t i, const std::string& title, const std::string& description);
bool HasCreatedProject() const
{
return m_HasCreatedProject;
}
};
}

View File

@@ -278,43 +278,46 @@ namespace Nuake
const std::string buttonLabel = std::string(ICON_FA_FOLDER_PLUS) + " New Game Project...";
if (Nuake::UI::PrimaryButton(buttonLabel.c_str(), { buttonSize.x, buttonSize.y }))
{
std::string selectedProject = FileDialog::SaveFile("Project file\0*.project");
if (!selectedProject.empty())
{
if(!String::EndsWith(selectedProject, ".project"))
selectedProject += ".project";
auto backslashSplits = String::Split(selectedProject, '\\');
auto fileName = backslashSplits[backslashSplits.size() - 1];
_Editor->isCreatingNewProject = true;
//
std::string finalPath = String::Split(selectedProject, '.')[0];
//std::string selectedProject = FileDialog::SaveFile("Project file\0*.project");
//
//if (!selectedProject.empty())
//{
// if(!String::EndsWith(selectedProject, ".project"))
// selectedProject += ".project";
//
// auto backslashSplits = String::Split(selectedProject, '\\');
// auto fileName = backslashSplits[backslashSplits.size() - 1];
if (String::EndsWith(fileName, ".project"))
{
// We need to create a folder
if (const auto& dirPath = finalPath;
!std::filesystem::create_directory(dirPath))
{
// Should we continue?
Logger::Log("Failed creating project directory: " + dirPath);
}
// std::string finalPath = String::Split(selectedProject, '.')[0];
finalPath += "\\" + fileName;
}
// if (String::EndsWith(fileName, ".project"))
// {
// // We need to create a folder
// if (const auto& dirPath = finalPath;
// !std::filesystem::create_directory(dirPath))
// {
// // Should we continue?
// Logger::Log("Failed creating project directory: " + dirPath);
// }
auto project = Project::New(String::Split(fileName, '.')[0], "no description", finalPath);
Engine::LoadProject(project);
Engine::LoadScene(Scene::New());
project->Save();
// finalPath += "\\" + fileName;
// }
auto projectPreview = ProjectPreview();
projectPreview.Name = project->Name;
projectPreview.Description = project->Description;
projectPreview.Path = project->FullPath;
projectPreview.ProjectIcon = nullptr;
_Projects.push_back(projectPreview);
}
// auto project = Project::New(String::Split(fileName, '.')[0], "no description", finalPath);
// Engine::LoadProject(project);
// Engine::LoadScene(Scene::New());
// project->Save();
// auto projectPreview = ProjectPreview();
// projectPreview.Name = project->Name;
// projectPreview.Description = project->Description;
// projectPreview.Path = project->FullPath;
// projectPreview.ProjectIcon = nullptr;
// _Projects.push_back(projectPreview);
//}
}
ImGui::PopStyleVar(2);
ImGui::Separator();

View File

@@ -99,6 +99,14 @@ namespace Nuake
return result;
}
std::string String::ReplaceSlash(const std::string& str)
{
std::string result = str;
std::replace(result.begin(), result.end(), '\\', '/');
return result;
}
std::string String::Base64Encode(const std::vector<uint8_t>& data)
{
static const char* chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
@@ -118,6 +126,7 @@ namespace Nuake
while (result.size() % 4) result.push_back('=');
return result;
}
std::vector<uint8_t> String::Base64Decode(const std::string& data)
{
static const std::string chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

View File

@@ -21,7 +21,8 @@ namespace Nuake
static float ToFloat(const std::string& string);
static std::string ToUpper(const std::string& string);
static std::string ToLower(const std::string& string);
static std::string ReplaceSlash(const std::string& str);
static std::string Base64Encode(const std::vector<uint8_t>& data);
static std::vector<uint8_t> Base64Decode(const std::string& data);
};

View File

@@ -29,6 +29,7 @@ namespace Nuake
m_Registry.emplace(Resources_Gizmos_rigidbody_png_path, CreateRef<Texture>(Resources_Gizmos_rigidbody_png, Resources_Gizmos_rigidbody_png_len));
m_Registry.emplace(Resources_Gizmos_sound_emitter_png_path, CreateRef<Texture>(Resources_Gizmos_sound_emitter_png, Resources_Gizmos_sound_emitter_png_len));
m_Registry.emplace(Resources_Images_cube_png_path, CreateRef<Texture>(Resources_Images_cube_png, Resources_Images_cube_png_len));
m_Registry.emplace(Resources_Images_nuake_logo_png_path, CreateRef<Texture>(Resources_Images_nuake_logo_png, Resources_Images_nuake_logo_png_len));
m_Registry.emplace(Resources_Images_logo_white_png_path, CreateRef<Texture>(Resources_Images_logo_white_png, Resources_Images_logo_white_png_len));
m_Registry.emplace(Resources_Images_logo_png_path, CreateRef<Texture>(Resources_Images_logo_png, Resources_Images_logo_png_len));

View File

@@ -16,9 +16,8 @@ namespace Nuake {
ImGui::End();
}
bool PrimaryButton(const std::string& name, const Vector2& size)
bool PrimaryButton(const std::string& name, const Vector2& size, Color color)
{
Color color = Color(97.0f / 255.0f, 0, 1.0f, 1.0f);
if (Nuake::Engine::GetProject())
{
color = Nuake::Engine::GetProject()->Settings.PrimaryColor;
@@ -178,7 +177,7 @@ namespace Nuake {
void Tooltip(const std::string& message)
{
ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(4, 4));
if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal))
{
ImGui::BeginTooltip();
@@ -188,7 +187,7 @@ namespace Nuake {
ImGui::EndTooltip();
}
ImGui::PopStyleVar();
ImGui::PopStyleVar(2);
}
}
}

View File

@@ -21,7 +21,7 @@ namespace Nuake
void EndWindow();
bool PrimaryButton(const std::string& name, const Vector2& size = {0, 0});
bool PrimaryButton(const std::string& name, const Vector2& size = { 0, 0 }, Color color = Color(97.0f / 255.0f, 0, 1.0f, 1.0f));
bool SecondaryButton(const std::string& name, const Vector2& size = { 0, 0 });
bool IconButton(const std::string& icon);

View File

@@ -305,8 +305,8 @@ namespace Nuake
{
const auto monitor = glfwGetPrimaryMonitor();
const GLFWvidmode* mode = glfwGetVideoMode(monitor);
Center();
SetSize({mode->width, mode->height});
Center();
glfwMaximizeWindow(m_Window);
}