From 3becc1e25b32934fc129b3a3c8ee68a971c230cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Sun, 18 Jun 2023 16:05:03 +0200 Subject: [PATCH] fixed Settings-File not being created and start of Recent-Projects-Menu --- .gitignore | 1 + GlitchyEditor/src/EditorLayer.bf | 34 +++++++++++++++++++++++++++++++- GlitchyEngine/src/Settings.bf | 5 +++++ 3 files changed, 39 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 8c74175..9deba33 100644 --- a/.gitignore +++ b/.gitignore @@ -7,3 +7,4 @@ vendor/directx imgui.ini GlitchyEditor/resources/scripts/ScriptCore.dll GlitchyEditor/resources/scripts/ScriptCore.pdb +GlitchyEditor/settings.bon diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index ec9fb9b..726eb82 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -70,6 +70,14 @@ namespace GlitchyEditor SceneState _sceneState = .Edit; bool _isPaused = false; + append List<(String Name, String Path)> _recentProjectPaths = .() ~ { + for (var item in _) + { + delete item.Name; + delete item.Path; + } + }; + /// Gets or sets the path of the current scene. public StringView SceneFilePath { @@ -623,6 +631,23 @@ namespace GlitchyEditor SetReference!(_activeScene, _editorScene); } + private void DrawOpenRecentProjectMenu() + { + int i = 0; + + for (let (name, path) in _recentProjectPaths) + { + i++; + if (i >= 10) + break; + + if (ImGui.MenuItem(scope $"{i}: {name} ({path})")) + { + LoadSceneFile(path); + } + } + } + private void DrawMainMenuBar() { ImGui.BeginMainMenuBar(); @@ -635,11 +660,18 @@ namespace GlitchyEditor if (ImGui.MenuItem("Save", "Ctrl+S")) SaveScene(); - if (ImGui.MenuItem("Save as...", "Ctrl+Shift+N")) + if (ImGui.MenuItem("Save as...", "Ctrl+Shift+S")) SaveSceneAs(); if (ImGui.MenuItem("Open...", "Ctrl+O")) OpenScene(); + + if (ImGui.BeginMenu("Open Recent")) + { + DrawOpenRecentProjectMenu(); + + ImGui.EndMenu(); + } ImGui.Separator(); diff --git a/GlitchyEngine/src/Settings.bf b/GlitchyEngine/src/Settings.bf index 639eed8..c5ff25d 100644 --- a/GlitchyEngine/src/Settings.bf +++ b/GlitchyEngine/src/Settings.bf @@ -67,6 +67,11 @@ namespace GlitchyEngine { Settings settings = Application.Get().Settings; + if (!File.Exists("./settings.bon")) + { + settings.Save(); + } + var result = Bon.DeserializeFromFile(ref settings, "./settings.bon"); if (result case .Err)