mirror of
https://github.com/aharabada/glitchy-engine-beef.git
synced 2026-09-05 13:01:52 +00:00
Implemented "Open recent Project" menu entry
+ Clean up handle -> asset map when chaning Asset or Resource directory
This commit is contained in:
@@ -28,7 +28,7 @@ class AssetFile
|
||||
|
||||
private String _path;
|
||||
private String _identifier;
|
||||
private String _assetConfigPath;
|
||||
private String _assetConfigPath ~ delete _;
|
||||
|
||||
private AssetConfig _assetConfig ~ delete _;
|
||||
|
||||
@@ -53,7 +53,7 @@ class AssetFile
|
||||
{
|
||||
String identifierBuffer = append String(identifier);
|
||||
String pathBuffer = append String(path);
|
||||
String configPathBuffer = append String(path.Length + ConfigFileExtension.Length);
|
||||
String configPathBuffer = new String(path.Length + ConfigFileExtension.Length);
|
||||
|
||||
_identifier = identifierBuffer;
|
||||
_path = pathBuffer;
|
||||
|
||||
@@ -250,6 +250,10 @@ class AssetHierarchy
|
||||
_resourcesDirectoryNode?.ForEach(scope (node) => {
|
||||
_pathToAssetNode.Remove(node->Path);
|
||||
_identifierToAssetNode.Remove(node->Identifier);
|
||||
|
||||
let handle = node->AssetFile?.AssetConfig?.AssetHandle;
|
||||
if (handle != null)
|
||||
_handleToAssetNode.Remove(handle.Value);
|
||||
});
|
||||
_assetRootNode.RemoveChild(_resourcesDirectoryNode);
|
||||
DeleteTreeAndChildren!(_resourcesDirectoryNode);
|
||||
@@ -283,11 +287,18 @@ class AssetHierarchy
|
||||
/// Sets path to the directory that contains the game assets.
|
||||
public void SetAssetsDirectory(StringView fileName)
|
||||
{
|
||||
if (AssetsDirectory == fileName)
|
||||
return;
|
||||
|
||||
AssetsDirectory = fileName;
|
||||
|
||||
_assetsDirectoryNode?.ForEach(scope (node) => {
|
||||
_pathToAssetNode.Remove(node->Path);
|
||||
_identifierToAssetNode.Remove(node->Identifier);
|
||||
|
||||
let handle = node->AssetFile?.AssetConfig?.AssetHandle;
|
||||
if (handle != null)
|
||||
_handleToAssetNode.Remove(handle.Value);
|
||||
});
|
||||
_assetRootNode.RemoveChild(_assetsDirectoryNode);
|
||||
DeleteTreeAndChildren!(_assetsDirectoryNode);
|
||||
|
||||
@@ -705,6 +705,12 @@ namespace GlitchyEditor
|
||||
|
||||
UpdateWindowTitle();
|
||||
|
||||
if (Directory.Exists(project.WorkspacePath))
|
||||
{
|
||||
Application.Instance.Settings.EditorSettings.LastOpenedProject = project.WorkspacePath;
|
||||
Application.Instance.Settings.Save();
|
||||
}
|
||||
|
||||
return .Ok;
|
||||
}
|
||||
|
||||
@@ -1174,6 +1180,32 @@ namespace GlitchyEditor
|
||||
}
|
||||
}
|
||||
|
||||
private void ShowOpenRecentProjectMenu()
|
||||
{
|
||||
let recentProjects = Application.Instance.Settings.EditorSettings.RecentProjects;
|
||||
|
||||
if (recentProjects == null)
|
||||
return;
|
||||
|
||||
int i = 0;
|
||||
|
||||
for (let workspacePath in recentProjects)
|
||||
{
|
||||
i++;
|
||||
|
||||
if (!Directory.Exists(workspacePath))
|
||||
{
|
||||
delete workspacePath;
|
||||
@workspacePath.Remove();
|
||||
}
|
||||
|
||||
if (ImGui.MenuItem(scope $"{i}: {workspacePath}"))
|
||||
{
|
||||
LoadAndOpenProject(workspacePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void DrawMainMenuBar()
|
||||
{
|
||||
ImGui.BeginMainMenuBar();
|
||||
@@ -1219,6 +1251,7 @@ namespace GlitchyEditor
|
||||
|
||||
if (ImGui.BeginMenu("Open recent project"))
|
||||
{
|
||||
ShowOpenRecentProjectMenu();
|
||||
ImGui.EndMenu();
|
||||
}
|
||||
|
||||
|
||||
@@ -37,9 +37,51 @@ class EditorSettings
|
||||
|
||||
[Setting("Editor", "Switch to Editor on pause", "If checked the editor will automatically switch to the \"Editor\" window when the game is being paused."), BonInclude]
|
||||
public bool SwitchToEditorOnPause = false;
|
||||
|
||||
[BonInclude]
|
||||
private List<String> _recentProjects ~ DeleteContainerAndItems!(_);
|
||||
|
||||
//
|
||||
//public readonly List<String> RecentProjects = new .() ~ delete _;
|
||||
/// Gets or sets the path of the Project that was last open.
|
||||
public StringView LastOpenedProject
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_recentProjects == null || _recentProjects.Count == 0)
|
||||
return "";
|
||||
|
||||
return _recentProjects[0];
|
||||
}
|
||||
set
|
||||
{
|
||||
if (_recentProjects == null)
|
||||
_recentProjects = new List<String>();
|
||||
|
||||
// Remove duplicates
|
||||
for (var entry in _recentProjects)
|
||||
{
|
||||
if (entry == value)
|
||||
{
|
||||
delete entry;
|
||||
@entry.Remove();
|
||||
}
|
||||
}
|
||||
|
||||
_recentProjects.Insert(0, new String(value));
|
||||
|
||||
if (_recentProjects.Count > 10)
|
||||
{
|
||||
// We only store 10 entries, delete the rest
|
||||
for (int i = 10; i < _recentProjects.Count; i++)
|
||||
{
|
||||
delete _recentProjects[i];
|
||||
}
|
||||
|
||||
_recentProjects.Count = 10;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public List<String> RecentProjects => _recentProjects;
|
||||
|
||||
public void Apply()
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user