Editor: Prevent saving while in not in edit mode

This commit is contained in:
Simon Lübeß
2024-01-12 00:31:10 +01:00
parent 55b4be05c2
commit 6c910ab03b
+19
View File
@@ -105,6 +105,9 @@ namespace GlitchyEditor
public Project CurrentProject => _currentProject; public Project CurrentProject => _currentProject;
public bool IsProjectLoaded => _currentProject != null; public bool IsProjectLoaded => _currentProject != null;
/// Returns whether or not the current scene can be saved.
public bool CanSaveScene => _sceneState == .Edit;
[AllowAppend] [AllowAppend]
public this(String[] args, EditorContentManager contentManager) : base("Editor") public this(String[] args, EditorContentManager contentManager) : base("Editor")
@@ -1083,6 +1086,12 @@ namespace GlitchyEditor
/// Saves the scene in the file that is was loaded from or saved to last. If there is no such path (i.e. it is a new scene) the save file dialog will open. /// Saves the scene in the file that is was loaded from or saved to last. If there is no such path (i.e. it is a new scene) the save file dialog will open.
private void SaveCurrentScene() private void SaveCurrentScene()
{ {
if (!CanSaveScene)
{
Log.ClientLogger.Error("Scene can't be saved while playing the game!");
return;
}
if (SceneFilePath.IsWhiteSpace) if (SceneFilePath.IsWhiteSpace)
{ {
SaveCurrentSceneAs(); SaveCurrentSceneAs();
@@ -1108,6 +1117,12 @@ namespace GlitchyEditor
/// Opens a save file dialog and saves the scene at the user specified location. /// Opens a save file dialog and saves the scene at the user specified location.
private void SaveCurrentSceneAs() private void SaveCurrentSceneAs()
{ {
if (!CanSaveScene)
{
Log.ClientLogger.Error("Scene can't be saved while playing the game!");
return;
}
SaveFileDialog sfd = scope .(); SaveFileDialog sfd = scope .();
sfd.InitialDirectory = _currentProject.AssetsFolder; sfd.InitialDirectory = _currentProject.AssetsFolder;
@@ -1415,6 +1430,8 @@ namespace GlitchyEditor
ImGui.Separator(); ImGui.Separator();
ImGui.BeginDisabled(!CanSaveScene);
if (ImGui.MenuItem("Save Scene", "Ctrl+S")) if (ImGui.MenuItem("Save Scene", "Ctrl+S"))
SaveCurrentScene(); SaveCurrentScene();
@@ -1425,6 +1442,8 @@ namespace GlitchyEditor
ImGui.AttachTooltip("Saves the scene under the given file name."); ImGui.AttachTooltip("Saves the scene under the given file name.");
ImGui.EndDisabled();
ImGui.Separator(); ImGui.Separator();
if (ImGui.MenuItem("Create new Project...", "Ctrl+ALT+N")) if (ImGui.MenuItem("Create new Project...", "Ctrl+ALT+N"))