From d718c6625d1f36369836fa434ca0759187eced21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20L=C3=BCbe=C3=9F?= Date: Wed, 15 Nov 2023 16:23:22 +0100 Subject: [PATCH] Allow separators in "Create new Asset" dropdown (also changed text to just "Create new") --- .../src/EditWindows/ContentBrowserWindow.bf | 24 ++++++++++++++++++- GlitchyEditor/src/EditorLayer.bf | 2 ++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf index 25d45b4..ecd3ce2 100644 --- a/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf +++ b/GlitchyEditor/src/EditWindows/ContentBrowserWindow.bf @@ -45,7 +45,9 @@ namespace GlitchyEditor.EditWindows private typealias AssetCreatorTree = TreeNode<(StringView Name, AssetCreator Creator)>; - private AssetCreatorTree _creatorTree = new AssetCreatorTree(("Create new Asset", null)) ~ delete _; + private AssetCreatorTree _creatorTree = new AssetCreatorTree(("Create new", null)) ~ delete _; + /// The last Asset Creator that was inserted. + private AssetCreatorTree _lastInsertedAssetCreator = null; public const String s_WindowTitle = "Content Browser"; @@ -72,6 +74,7 @@ namespace GlitchyEditor.EditWindows _manager = contentManager; } + /// Registers an asset creator that will show up in the "Create new" drop down menu public void RegisterAssetCreator(AssetCreator assetCreator) { _assetCreators.Add(assetCreator); @@ -92,6 +95,17 @@ namespace GlitchyEditor.EditWindows { tree->Creator = assetCreator; } + + _lastInsertedAssetCreator = tree; + } + + /// Adds a seperator line after the asset creator that was last added. + public void InsertAssetCreatorSeparator() + { + AssetCreatorTree parent = _lastInsertedAssetCreator.Parent; + + // Separators have an empty name and no creator! + parent.AddChild(("", null)); } protected override void InternalShow() @@ -209,6 +223,14 @@ namespace GlitchyEditor.EditWindows /// Shows the menu for the given asset creator tree. private void ShowCreateContextMenu(AssetCreatorTree subtree) { + // Separators have an empty name and no creator + if (subtree->Name.IsWhiteSpace && subtree->Creator == null) + { + ImGui.Separator(); + + return; + } + if (subtree.Children.Count == 0) { if (ImGui.MenuItem(subtree->Name.ToScopeCStr!())) diff --git a/GlitchyEditor/src/EditorLayer.bf b/GlitchyEditor/src/EditorLayer.bf index 534a702..ddcc5fb 100644 --- a/GlitchyEditor/src/EditorLayer.bf +++ b/GlitchyEditor/src/EditorLayer.bf @@ -152,6 +152,8 @@ namespace GlitchyEditor } })); + Editor.Instance.ContentBrowserWindow.InsertAssetCreatorSeparator(); + Editor.Instance.ContentBrowserWindow.RegisterAssetCreator(new AssetCreator("Scene", "New Scene", ".scene", new (path) => { using (Scene newScene = CreateNewScene())