mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Made not having a project loaded less crashy
This commit is contained in:
@@ -83,7 +83,7 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
public Span<String> History => _history;
|
public Span<String> History => _history;
|
||||||
|
|
||||||
public StringView CurrentDirectoryPath => _currentIndex >= 0 ? _history[_currentIndex] : "";
|
public StringView CurrentDirectoryPath => (_history.Count == 0 || _currentIndex < 0) ? "" : _history[_currentIndex];
|
||||||
|
|
||||||
public bool CanGoBack => _currentIndex > 0;
|
public bool CanGoBack => _currentIndex > 0;
|
||||||
public bool CanGoForward => (_currentIndex + 1) < _history.Count;
|
public bool CanGoForward => (_currentIndex + 1) < _history.Count;
|
||||||
@@ -92,7 +92,11 @@ namespace GlitchyEditor.EditWindows
|
|||||||
{
|
{
|
||||||
// We always defer the actual navigation to the next frame, so that the UI-rendering and updates are more robust and don't flicker for one frame
|
// We always defer the actual navigation to the next frame, so that the UI-rendering and updates are more robust and don't flicker for one frame
|
||||||
_currentIndex = _nextIndex;
|
_currentIndex = _nextIndex;
|
||||||
if (_pathToInsert != null)
|
if (String.IsNullOrWhiteSpace(_pathToInsert))
|
||||||
|
{
|
||||||
|
delete _pathToInsert;
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
if (replace)
|
if (replace)
|
||||||
{
|
{
|
||||||
@@ -341,9 +345,19 @@ namespace GlitchyEditor.EditWindows
|
|||||||
|
|
||||||
// Make sure we are in an existing directory.
|
// Make sure we are in an existing directory.
|
||||||
if (!_manager.AssetHierarchy.FileExists(CurrentDirectory))
|
if (!_manager.AssetHierarchy.FileExists(CurrentDirectory))
|
||||||
|
{
|
||||||
|
if (Directory.Exists(_manager.AssetDirectory))
|
||||||
{
|
{
|
||||||
_directoryHistory.Replace(_manager.AssetDirectory);
|
_directoryHistory.Replace(_manager.AssetDirectory);
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// If the assets directory doesn't exist (probably, because we have no project open)
|
||||||
|
// we navigate to the resources directory.
|
||||||
|
// This MUST exist, otherwise we wouldn't have managed to launch the Editor.
|
||||||
|
_directoryHistory.Replace(_manager.ResourcesDirectory);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
_directoryHistory.Update();
|
_directoryHistory.Update();
|
||||||
|
|
||||||
|
|||||||
@@ -958,6 +958,9 @@ namespace GlitchyEditor
|
|||||||
/// Creates a new scene and openes it.
|
/// Creates a new scene and openes it.
|
||||||
private void CreateAndOpenNewScene()
|
private void CreateAndOpenNewScene()
|
||||||
{
|
{
|
||||||
|
if (_currentProject == null)
|
||||||
|
return;
|
||||||
|
|
||||||
CloseCurrentScene();
|
CloseCurrentScene();
|
||||||
|
|
||||||
SceneFilePath = null;
|
SceneFilePath = null;
|
||||||
@@ -1032,6 +1035,9 @@ 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 (_currentProject == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!CanSaveScene)
|
if (!CanSaveScene)
|
||||||
{
|
{
|
||||||
Log.ClientLogger.Error("Scene can't be saved while playing the game!");
|
Log.ClientLogger.Error("Scene can't be saved while playing the game!");
|
||||||
@@ -1063,6 +1069,9 @@ 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 (_currentProject == null)
|
||||||
|
return;
|
||||||
|
|
||||||
if (!CanSaveScene)
|
if (!CanSaveScene)
|
||||||
{
|
{
|
||||||
Log.ClientLogger.Error("Scene can't be saved while playing the game!");
|
Log.ClientLogger.Error("Scene can't be saved while playing the game!");
|
||||||
@@ -1083,6 +1092,9 @@ namespace GlitchyEditor
|
|||||||
/// Opens a open file dialog and load the scene selected by the user specified.
|
/// Opens a open file dialog and load the scene selected by the user specified.
|
||||||
private void OpenScene()
|
private void OpenScene()
|
||||||
{
|
{
|
||||||
|
if (_currentProject == null)
|
||||||
|
return;
|
||||||
|
|
||||||
OpenFileDialog ofd = scope .();
|
OpenFileDialog ofd = scope .();
|
||||||
ofd.InitialDirectory = _currentProject.AssetsFolder;
|
ofd.InitialDirectory = _currentProject.AssetsFolder;
|
||||||
ofd.SetFilter("scene file (*.scene)|*.scene");
|
ofd.SetFilter("scene file (*.scene)|*.scene");
|
||||||
@@ -1400,7 +1412,9 @@ namespace GlitchyEditor
|
|||||||
{
|
{
|
||||||
ImGui.BeginMainMenuBar();
|
ImGui.BeginMainMenuBar();
|
||||||
|
|
||||||
if(ImGui.BeginMenu("File", true))
|
if (ImGui.BeginMenu("File", true))
|
||||||
|
{
|
||||||
|
using (ImGui.DisabledScope(_currentProject == null))
|
||||||
{
|
{
|
||||||
if (ImGui.MenuItem("New Scene", "Ctrl+N"))
|
if (ImGui.MenuItem("New Scene", "Ctrl+N"))
|
||||||
CreateAndOpenNewScene();
|
CreateAndOpenNewScene();
|
||||||
@@ -1421,8 +1435,8 @@ namespace GlitchyEditor
|
|||||||
|
|
||||||
ImGui.Separator();
|
ImGui.Separator();
|
||||||
|
|
||||||
ImGui.BeginDisabled(!CanSaveScene);
|
using (ImGui.DisabledScope(!CanSaveScene))
|
||||||
|
{
|
||||||
if (ImGui.MenuItem("Save Scene", "Ctrl+S"))
|
if (ImGui.MenuItem("Save Scene", "Ctrl+S"))
|
||||||
SaveCurrentScene();
|
SaveCurrentScene();
|
||||||
|
|
||||||
@@ -1432,8 +1446,8 @@ namespace GlitchyEditor
|
|||||||
SaveCurrentSceneAs();
|
SaveCurrentSceneAs();
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
|
|||||||
@@ -743,5 +743,18 @@ namespace ImGui
|
|||||||
PushStyleVar(.DockingSeparatorSize, Value);
|
PushStyleVar(.DockingSeparatorSize, Value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public struct DisabledScope : IDisposable
|
||||||
|
{
|
||||||
|
public this(bool disabled = true)
|
||||||
|
{
|
||||||
|
ImGui.BeginDisabled(disabled);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
ImGui.EndDisabled();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user