From 9006bcaea304c8cb6c9184225ff9320392a14d09 Mon Sep 17 00:00:00 2001 From: fabsgc Date: Sat, 24 Feb 2024 00:01:10 +0100 Subject: [PATCH] [Editor] New workflow to create/open/save projects --- Source/Examples/Editor/TeEditor.cpp | 19 ++--- Source/Examples/Editor/TeEditor.h | 2 +- .../Editor/Widget/TeWidgetMenuBar.cpp | 80 ++++++++++++++++--- .../Examples/Editor/Widget/TeWidgetMenuBar.h | 5 ++ 4 files changed, 80 insertions(+), 26 deletions(-) diff --git a/Source/Examples/Editor/TeEditor.cpp b/Source/Examples/Editor/TeEditor.cpp index 1750a73a..2782ce4e 100644 --- a/Source/Examples/Editor/TeEditor.cpp +++ b/Source/Examples/Editor/TeEditor.cpp @@ -79,6 +79,8 @@ #include "Project/TeProject.h" +#include + // TODO Temp for debug purpose #include "Importer/TeMeshImportOptions.h" #include "Importer/TeTextureImportOptions.h" @@ -174,6 +176,7 @@ namespace te InitializeGui(); _project = Project::Create(); + _project->SetPath(std::filesystem::absolute("Data/Project/project.json").generic_string()); } void Editor::OnShutDown() @@ -853,7 +856,7 @@ namespace te _guizmoMode = mode; } - bool Editor::NewProject() + bool Editor::NewProject(const String& path) { if (IsEditorRunning()) { @@ -861,12 +864,6 @@ namespace te return false; } - /*if (_settings.State != EditorState::Saved) - { - TE_DEBUG("You didn't save your current project"); - return false; - }*/ - DestroyRunningScene(); DestroyScene(); EditorResManager::Instance().Clear(); @@ -877,7 +874,7 @@ namespace te LoadEngineResources(); _sceneSO = SceneObject::Create("Scene"); - _settings.State = EditorState::Saved; + _settings.State = EditorState::Modified; _project = Project::Create(); @@ -892,12 +889,6 @@ namespace te return false; } - /*if (_settings.State != EditorState::Saved) - { - TE_DEBUG("You didn't save your current project"); - return false; - }*/ - SPtr options = te_shared_ptr_new(); SPtr multiResourceScene = EditorResManager::Instance().LoadAll(path, options, true); diff --git a/Source/Examples/Editor/TeEditor.h b/Source/Examples/Editor/TeEditor.h index d851638c..b15bc7d0 100644 --- a/Source/Examples/Editor/TeEditor.h +++ b/Source/Examples/Editor/TeEditor.h @@ -191,7 +191,7 @@ namespace te void SetAnimationDebug(bool debug) { _animationDebug = debug; } /** Create new project */ - bool NewProject(); + bool NewProject(const String& path); /** Open an existing project */ bool OpenProject(const String& path); diff --git a/Source/Examples/Editor/Widget/TeWidgetMenuBar.cpp b/Source/Examples/Editor/Widget/TeWidgetMenuBar.cpp index 8b6dcc04..cf7168fd 100644 --- a/Source/Examples/Editor/Widget/TeWidgetMenuBar.cpp +++ b/Source/Examples/Editor/Widget/TeWidgetMenuBar.cpp @@ -49,10 +49,10 @@ namespace te void WidgetMenuBar::Update() { if (gVirtualInput().IsButtonDown(_newBtn)) - gEditor().GetSettings().State = Editor::EditorState::Modified; + NewProject(); if (gVirtualInput().IsButtonDown(_openBtn)) - _settings.OpenProject = true; + OpenProject(); if (gVirtualInput().IsButtonDown(_saveAsBtn)) _settings.SaveProject = true; @@ -72,13 +72,13 @@ namespace te if (ImGui::MenuItem(ICON_FA_FILE_ALT " " ICON_FA_GRIP_LINES_VERTICAL " New project", "Ctrl+N")) NewProject(); - if (ImGui::MenuItem(ICON_FA_FOLDER_OPEN " " ICON_FA_GRIP_LINES_VERTICAL " Open project", "Ctrl+O", &_settings.OpenProject)) + if (ImGui::MenuItem(ICON_FA_FOLDER_OPEN " " ICON_FA_GRIP_LINES_VERTICAL " Open project", "Ctrl+O")) OpenProject(); if (ImGui::MenuItem(ICON_FA_SAVE " " ICON_FA_GRIP_LINES_VERTICAL " Save project", "Ctrl+S")) SaveProject(); - if (ImGui::MenuItem(ICON_FA_SAVE " " ICON_FA_GRIP_LINES_VERTICAL " Save project As ..", "Ctrl+Shift+S", _settings.SaveProject)) + if (ImGui::MenuItem(ICON_FA_SAVE " " ICON_FA_GRIP_LINES_VERTICAL " Save project As ..", "Ctrl+Shift+S")) SaveProjectAs(); if (ImGui::MenuItem(ICON_FA_SIGN_OUT_ALT " " ICON_FA_GRIP_LINES_VERTICAL " Quit", "Ctrl+Q")) @@ -184,9 +184,12 @@ namespace te ImGui::EndMainMenuBar(); } + ShowSavePreviousModal(); + ShowAboutWindow(); - ShowOpenProject(); ShowSaveProject(); + ShowNewProject(); + ShowOpenProject(); ShowLoadResource(); } @@ -232,6 +235,23 @@ namespace te ImGui::End(); } + void WidgetMenuBar::ShowNewProject() + { + if (_settings.NewProject) + ImGui::OpenPopup("New Project"); + + if (_fileBrowser.ShowFileDialog("New Project", ImGuiFileBrowser::DialogMode::SELECT, ImVec2(900, 450), true, "")) + { + gEditor().NewProject(_fileBrowser.Data.SelectedPath + "project.json"); + _settings.NewProject = false; + } + else + { + if (_fileBrowser.Data.IsCancelled) + _settings.NewProject = false; + } + } + void WidgetMenuBar::ShowOpenProject() { if (_settings.OpenProject) @@ -385,24 +405,62 @@ namespace te } } + void WidgetMenuBar::ShowSavePreviousModal() + { + if (_settings.SavePreviousModalNewProject || _settings.SavePreviousModalOpenProject) + ImGui::OpenPopup("Current project not saved"); + + ImGuiExt::RenderYesNo("Current project not saved", + [&]() { + if (gEditor().GetProject()->GetPath().empty()) + { + _settings.SaveProject = true; + } + else + { + gEditor().SaveProject(gEditor().GetProject()->GetPath()); + + if (_settings.SavePreviousModalNewProject) _settings.NewProject = true; + else _settings.OpenProject = true; + } + + _settings.SavePreviousModalNewProject = false; + _settings.SavePreviousModalOpenProject = false; + }, + [&]() { + if (_settings.SavePreviousModalNewProject) _settings.NewProject = true; + else _settings.OpenProject = true; + + _settings.SavePreviousModalNewProject = false; + _settings.SavePreviousModalOpenProject = false; + }, + []() {}, + "Your current project is not saved. Do you want to save it before creating a new project ?" + ); + } + void WidgetMenuBar::NewProject() { if (gEditor().GetSettings().State == Editor::EditorState::Modified) { - // TODO + _settings.SavePreviousModalNewProject = true; + } + else + { + _settings.NewProject = true; } - - gEditor().NewProject(); } void WidgetMenuBar::OpenProject() { if (gEditor().GetSettings().State == Editor::EditorState::Modified) { - // TODO + _settings.SavePreviousModalOpenProject = true; + } + else + { + _settings.OpenProject = true; } - - _settings.OpenProject = true; } void WidgetMenuBar::SaveProject() diff --git a/Source/Examples/Editor/Widget/TeWidgetMenuBar.h b/Source/Examples/Editor/Widget/TeWidgetMenuBar.h index 131ccb0f..0b467550 100644 --- a/Source/Examples/Editor/Widget/TeWidgetMenuBar.h +++ b/Source/Examples/Editor/Widget/TeWidgetMenuBar.h @@ -28,9 +28,11 @@ namespace te protected: void ShowAboutWindow(); + void ShowNewProject(); void ShowOpenProject(); void ShowSaveProject(); void ShowLoadResource(); + void ShowSavePreviousModal(); void NewProject(); void OpenProject(); void SaveProject(); @@ -41,9 +43,12 @@ namespace te struct WidgetMenubarSettings { bool AboutWindow = false; + bool NewProject = false; bool OpenProject = false; bool SaveProject = false; bool LoadResource = false; + bool SavePreviousModalNewProject = false; + bool SavePreviousModalOpenProject = false; }; protected: