Skip to content

Commit

Permalink
[Editor] New workflow to create/open/save projects
Browse files Browse the repository at this point in the history
  • Loading branch information
fabsgc committed Feb 23, 2024
1 parent 73f0f9f commit 9006bca
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 26 deletions.
19 changes: 5 additions & 14 deletions Source/Examples/Editor/TeEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@

#include "Project/TeProject.h"

#include <filesystem>

// TODO Temp for debug purpose
#include "Importer/TeMeshImportOptions.h"
#include "Importer/TeTextureImportOptions.h"
Expand Down Expand Up @@ -174,6 +176,7 @@ namespace te
InitializeGui();

_project = Project::Create();
_project->SetPath(std::filesystem::absolute("Data/Project/project.json").generic_string());
}

void Editor::OnShutDown()
Expand Down Expand Up @@ -853,20 +856,14 @@ namespace te
_guizmoMode = mode;
}

bool Editor::NewProject()
bool Editor::NewProject(const String& path)
{
if (IsEditorRunning())
{
TE_DEBUG("You can't open a project while editor is running");
return false;
}

/*if (_settings.State != EditorState::Saved)
{
TE_DEBUG("You didn't save your current project");
return false;
}*/

DestroyRunningScene();
DestroyScene();
EditorResManager::Instance().Clear();
Expand All @@ -877,7 +874,7 @@ namespace te
LoadEngineResources();

_sceneSO = SceneObject::Create("Scene");
_settings.State = EditorState::Saved;
_settings.State = EditorState::Modified;

_project = Project::Create();

Expand All @@ -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<ProjectImportOptions> options = te_shared_ptr_new<ProjectImportOptions>();
SPtr<MultiResource> multiResourceScene = EditorResManager::Instance().LoadAll(path, options, true);

Expand Down
2 changes: 1 addition & 1 deletion Source/Examples/Editor/TeEditor.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
80 changes: 69 additions & 11 deletions Source/Examples/Editor/Widget/TeWidgetMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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"))
Expand Down Expand Up @@ -184,9 +184,12 @@ namespace te
ImGui::EndMainMenuBar();
}

ShowSavePreviousModal();

ShowAboutWindow();
ShowOpenProject();
ShowSaveProject();
ShowNewProject();
ShowOpenProject();
ShowLoadResource();
}

Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions Source/Examples/Editor/Widget/TeWidgetMenuBar.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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:
Expand Down

0 comments on commit 9006bca

Please sign in to comment.