From 3f135c832e90a3b96fd0eca3f899b7af26bd8b36 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 27 Oct 2022 23:05:51 -0500 Subject: [PATCH 1/7] organized the "new" child context menu into categories. --- .../Windows/ContentWindow.ContextMenu.cs | 62 ++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index 7368c4efd..0bff62ab4 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. using System; +using System.Collections.Generic; using FlaxEditor.Content; using FlaxEditor.GUI.ContextMenu; using FlaxEngine; @@ -16,6 +17,40 @@ namespace FlaxEditor.Windows /// public event Action ContextMenuShow; + private readonly string _animationMenuName = "Animation"; + private readonly string _materialMenuName = "Materials"; + private readonly string _particleMenuName = "Particles"; + private readonly string _physicsMenuName = "Physics"; + + private readonly List _animationGroupNames = new List() + { + "Animation", + "Animation Graph", + "Animation Graph Function", + "Skeleton Mask", + "Scene Animation", + }; + + private readonly List _particleGroup = new List() + { + "Particle Emitter", + "Particle Emitter Function", + "Particle System", + }; + + private readonly List _materialGroup = new List() + { + "Material", + "Material Function", + "Material Instance", + }; + + private readonly List _physicsGroup = new List() + { + "Collision Data", + "Physical Material", + }; + private void ShowContextMenuForItem(ContentItem item, ref Float2 location, bool isTreeNode) { Assert.IsNull(_newElement); @@ -159,7 +194,17 @@ namespace FlaxEditor.Windows var p = Editor.ContentDatabase.Proxy[i]; if (p.CanCreate(folder)) { - c.ContextMenu.AddButton(p.Name, () => NewItem(p)); + if (_animationGroupNames.Contains(p.Name)) + AddContentProxyToMenu(c.ContextMenu, p, _animationMenuName); + else if (_particleGroup.Contains(p.Name)) + AddContentProxyToMenu(c.ContextMenu, p, _particleMenuName); + else if (_materialGroup.Contains(p.Name)) + AddContentProxyToMenu(c.ContextMenu, p, _materialMenuName); + else if (_physicsGroup.Contains(p.Name)) + AddContentProxyToMenu(c.ContextMenu, p, _physicsMenuName); + else + c.ContextMenu.AddButton(p.Name, () => NewItem(p)); + newItems++; } } @@ -178,6 +223,21 @@ namespace FlaxEditor.Windows cm.Show(this, location); } + private void AddContentProxyToMenu(ContextMenu contextMenu, ContentProxy contentProxy, string menuName) + { + var childMenu = contextMenu.GetChildMenu(menuName); + if (childMenu == null) + { + var c = contextMenu.AddChildMenu(menuName); + c.ContextMenu.AutoSort = true; + c.ContextMenu.AddButton(contentProxy.Name, () => NewItem(contentProxy)); + } + else + { + childMenu.ContextMenu.AddButton(contentProxy.Name, () => NewItem(contentProxy)); + } + } + private void OnExpandAllClicked(ContextMenuButton button) { CurrentViewFolder.Node.ExpandAll(); From 3c689a4697a7ecdb83747c988f6ed8ef65dad700 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 28 Oct 2022 08:32:52 -0500 Subject: [PATCH 2/7] removed not needed variables and fixed variable names --- .../Windows/ContentWindow.ContextMenu.cs | 25 ++++++++----------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index 0bff62ab4..c0dcc9b14 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -17,11 +17,6 @@ namespace FlaxEditor.Windows /// public event Action ContextMenuShow; - private readonly string _animationMenuName = "Animation"; - private readonly string _materialMenuName = "Materials"; - private readonly string _particleMenuName = "Particles"; - private readonly string _physicsMenuName = "Physics"; - private readonly List _animationGroupNames = new List() { "Animation", @@ -31,21 +26,21 @@ namespace FlaxEditor.Windows "Scene Animation", }; - private readonly List _particleGroup = new List() + private readonly List _particleGroupNames = new List() { "Particle Emitter", "Particle Emitter Function", "Particle System", }; - private readonly List _materialGroup = new List() + private readonly List _materialGroupNames = new List() { "Material", "Material Function", "Material Instance", }; - private readonly List _physicsGroup = new List() + private readonly List _physicsGroupNames = new List() { "Collision Data", "Physical Material", @@ -195,13 +190,13 @@ namespace FlaxEditor.Windows if (p.CanCreate(folder)) { if (_animationGroupNames.Contains(p.Name)) - AddContentProxyToMenu(c.ContextMenu, p, _animationMenuName); - else if (_particleGroup.Contains(p.Name)) - AddContentProxyToMenu(c.ContextMenu, p, _particleMenuName); - else if (_materialGroup.Contains(p.Name)) - AddContentProxyToMenu(c.ContextMenu, p, _materialMenuName); - else if (_physicsGroup.Contains(p.Name)) - AddContentProxyToMenu(c.ContextMenu, p, _physicsMenuName); + AddContentProxyToMenu(c.ContextMenu, p, "Animation"); + else if (_particleGroupNames.Contains(p.Name)) + AddContentProxyToMenu(c.ContextMenu, p, "Particles"); + else if (_materialGroupNames.Contains(p.Name)) + AddContentProxyToMenu(c.ContextMenu, p, "Materials"); + else if (_physicsGroupNames.Contains(p.Name)) + AddContentProxyToMenu(c.ContextMenu, p, "Physics"); else c.ContextMenu.AddButton(p.Name, () => NewItem(p)); From 050635b2cde5ae403598d813c699e89d757dfede Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Sun, 30 Oct 2022 14:30:32 -0500 Subject: [PATCH 3/7] changed way that the the new menu is generated. Added category name to proxies --- .../Proxy/AnimationGraphFunctionProxy.cs | 3 + .../Content/Proxy/AnimationGraphProxy.cs | 3 + Source/Editor/Content/Proxy/AnimationProxy.cs | 3 + Source/Editor/Content/Proxy/AssetProxy.cs | 5 + Source/Editor/Content/Proxy/AudioClipProxy.cs | 3 + .../Content/Proxy/CollisionDataProxy.cs | 3 + .../Editor/Content/Proxy/CubeTextureProxy.cs | 3 + Source/Editor/Content/Proxy/FontProxy.cs | 3 + .../Content/Proxy/GameplayGlobalsProxy.cs | 3 + .../Editor/Content/Proxy/IESProfileProxy.cs | 3 + Source/Editor/Content/Proxy/JsonAssetProxy.cs | 17 ++++ .../Content/Proxy/MaterialFunctionProxy.cs | 3 + .../Content/Proxy/MaterialInstanceProxy.cs | 3 + Source/Editor/Content/Proxy/MaterialProxy.cs | 3 + Source/Editor/Content/Proxy/ModelProxy.cs | 3 + .../Proxy/ParticleEmitterFunctionProxy.cs | 3 + .../Content/Proxy/ParticleEmitterProxy.cs | 3 + .../Content/Proxy/ParticleSystemProxy.cs | 3 + Source/Editor/Content/Proxy/PrefabProxy.cs | 3 + .../Content/Proxy/PreviewsCacheProxy.cs | 3 + .../Content/Proxy/SceneAnimationProxy.cs | 3 + Source/Editor/Content/Proxy/SceneProxy.cs | 3 + Source/Editor/Content/Proxy/SettingsProxy.cs | 3 + Source/Editor/Content/Proxy/ShaderProxy.cs | 3 + .../Editor/Content/Proxy/SkeletonMaskProxy.cs | 3 + .../Editor/Content/Proxy/SkinnedModelProxy.cs | 3 + .../Editor/Content/Proxy/SpriteAtlasProxy.cs | 3 + Source/Editor/Content/Proxy/TextureProxy.cs | 3 + .../Editor/Content/Proxy/VisualScriptProxy.cs | 3 + .../Editor/Modules/ContentDatabaseModule.cs | 4 +- .../Windows/ContentWindow.ContextMenu.cs | 96 +++++++++---------- 31 files changed, 149 insertions(+), 54 deletions(-) diff --git a/Source/Editor/Content/Proxy/AnimationGraphFunctionProxy.cs b/Source/Editor/Content/Proxy/AnimationGraphFunctionProxy.cs index c4ea2e09a..cb611d2f8 100644 --- a/Source/Editor/Content/Proxy/AnimationGraphFunctionProxy.cs +++ b/Source/Editor/Content/Proxy/AnimationGraphFunctionProxy.cs @@ -16,6 +16,9 @@ namespace FlaxEditor.Content /// public override string Name => "Animation Graph Function"; + /// + public override string CategoryName => "Animation"; + /// public override EditorWindow Open(Editor editor, ContentItem item) { diff --git a/Source/Editor/Content/Proxy/AnimationGraphProxy.cs b/Source/Editor/Content/Proxy/AnimationGraphProxy.cs index 3c445c104..103fee18e 100644 --- a/Source/Editor/Content/Proxy/AnimationGraphProxy.cs +++ b/Source/Editor/Content/Proxy/AnimationGraphProxy.cs @@ -15,6 +15,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Animation Graph"; + + /// + public override string CategoryName => "Animation"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/AnimationProxy.cs b/Source/Editor/Content/Proxy/AnimationProxy.cs index bda0fa98d..07b613dcb 100644 --- a/Source/Editor/Content/Proxy/AnimationProxy.cs +++ b/Source/Editor/Content/Proxy/AnimationProxy.cs @@ -18,6 +18,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Animation"; + + /// + public override string CategoryName => "Animation"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/AssetProxy.cs b/Source/Editor/Content/Proxy/AssetProxy.cs index 6516dbc37..772b00a20 100644 --- a/Source/Editor/Content/Proxy/AssetProxy.cs +++ b/Source/Editor/Content/Proxy/AssetProxy.cs @@ -22,6 +22,11 @@ namespace FlaxEditor.Content /// public abstract string TypeName { get; } + /// + /// The category name used to sort in context menus + /// + public abstract string CategoryName { get; } + /// /// Checks if this proxy supports the given asset type id at the given path. /// diff --git a/Source/Editor/Content/Proxy/AudioClipProxy.cs b/Source/Editor/Content/Proxy/AudioClipProxy.cs index 8b9ace491..f52802234 100644 --- a/Source/Editor/Content/Proxy/AudioClipProxy.cs +++ b/Source/Editor/Content/Proxy/AudioClipProxy.cs @@ -62,6 +62,9 @@ namespace FlaxEditor.Content /// public override string Name => "Audio Clip"; + + /// + public override string CategoryName => "Audio"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/CollisionDataProxy.cs b/Source/Editor/Content/Proxy/CollisionDataProxy.cs index cca8a8192..4bddbf063 100644 --- a/Source/Editor/Content/Proxy/CollisionDataProxy.cs +++ b/Source/Editor/Content/Proxy/CollisionDataProxy.cs @@ -42,6 +42,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Collision Data"; + + /// + public override string CategoryName => "Physics"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/CubeTextureProxy.cs b/Source/Editor/Content/Proxy/CubeTextureProxy.cs index d89771b13..653e71ce3 100644 --- a/Source/Editor/Content/Proxy/CubeTextureProxy.cs +++ b/Source/Editor/Content/Proxy/CubeTextureProxy.cs @@ -20,6 +20,9 @@ namespace FlaxEditor.Content /// public override string Name => "Cube Texture"; + + /// + public override string CategoryName => "Texture"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/FontProxy.cs b/Source/Editor/Content/Proxy/FontProxy.cs index 10f0d9076..bb78d5ab0 100644 --- a/Source/Editor/Content/Proxy/FontProxy.cs +++ b/Source/Editor/Content/Proxy/FontProxy.cs @@ -17,6 +17,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Font"; + + /// + public override string CategoryName => "Font"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/GameplayGlobalsProxy.cs b/Source/Editor/Content/Proxy/GameplayGlobalsProxy.cs index 7c8a7268d..60a9b78bb 100644 --- a/Source/Editor/Content/Proxy/GameplayGlobalsProxy.cs +++ b/Source/Editor/Content/Proxy/GameplayGlobalsProxy.cs @@ -15,6 +15,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Gameplay Globals"; + + /// + public override string CategoryName => "Globals"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/IESProfileProxy.cs b/Source/Editor/Content/Proxy/IESProfileProxy.cs index 55b4c8d47..8ec932106 100644 --- a/Source/Editor/Content/Proxy/IESProfileProxy.cs +++ b/Source/Editor/Content/Proxy/IESProfileProxy.cs @@ -20,6 +20,9 @@ namespace FlaxEditor.Content /// public override string Name => "IES Profile"; + + /// + public override string CategoryName => "Lighting"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/JsonAssetProxy.cs b/Source/Editor/Content/Proxy/JsonAssetProxy.cs index 3f2863f74..2f48a1b6c 100644 --- a/Source/Editor/Content/Proxy/JsonAssetProxy.cs +++ b/Source/Editor/Content/Proxy/JsonAssetProxy.cs @@ -31,6 +31,9 @@ namespace FlaxEditor.Content /// public override string Name => "Json Asset"; + + /// + public override string CategoryName => "Json Asset"; /// public override string FileExtension => Extension; @@ -165,6 +168,20 @@ namespace FlaxEditor.Content /// public override string Name { get; } = Utilities.Utils.GetPropertyNameUI(typeof(T).Name); + private string _categoryName; + + /// + public override string CategoryName => _categoryName; + + /// + /// Sets the category name + /// + /// This is the category name + public void SetCategoryName(string name) + { + _categoryName = name; + } + /// public override bool CanCreate(ContentFolder targetLocation) { diff --git a/Source/Editor/Content/Proxy/MaterialFunctionProxy.cs b/Source/Editor/Content/Proxy/MaterialFunctionProxy.cs index 702f04706..c2c317342 100644 --- a/Source/Editor/Content/Proxy/MaterialFunctionProxy.cs +++ b/Source/Editor/Content/Proxy/MaterialFunctionProxy.cs @@ -15,6 +15,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Material Function"; + + /// + public override string CategoryName => "Material"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/MaterialInstanceProxy.cs b/Source/Editor/Content/Proxy/MaterialInstanceProxy.cs index 663c191ef..ea0a73cbe 100644 --- a/Source/Editor/Content/Proxy/MaterialInstanceProxy.cs +++ b/Source/Editor/Content/Proxy/MaterialInstanceProxy.cs @@ -20,6 +20,9 @@ namespace FlaxEditor.Content /// public override string Name => "Material Instance"; + + /// + public override string CategoryName => "Material"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/MaterialProxy.cs b/Source/Editor/Content/Proxy/MaterialProxy.cs index e2e74eb14..2da83bf96 100644 --- a/Source/Editor/Content/Proxy/MaterialProxy.cs +++ b/Source/Editor/Content/Proxy/MaterialProxy.cs @@ -21,6 +21,9 @@ namespace FlaxEditor.Content /// public override string Name => "Material"; + + /// + public override string CategoryName => "Material"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/ModelProxy.cs b/Source/Editor/Content/Proxy/ModelProxy.cs index b99d15134..ed0633ce4 100644 --- a/Source/Editor/Content/Proxy/ModelProxy.cs +++ b/Source/Editor/Content/Proxy/ModelProxy.cs @@ -21,6 +21,9 @@ namespace FlaxEditor.Content /// public override string Name => "Model"; + + /// + public override string CategoryName => "Model"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/ParticleEmitterFunctionProxy.cs b/Source/Editor/Content/Proxy/ParticleEmitterFunctionProxy.cs index 24cc22690..c56e5f695 100644 --- a/Source/Editor/Content/Proxy/ParticleEmitterFunctionProxy.cs +++ b/Source/Editor/Content/Proxy/ParticleEmitterFunctionProxy.cs @@ -15,6 +15,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Particle Emitter Function"; + + /// + public override string CategoryName => "Particles"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/ParticleEmitterProxy.cs b/Source/Editor/Content/Proxy/ParticleEmitterProxy.cs index 089c614da..391670085 100644 --- a/Source/Editor/Content/Proxy/ParticleEmitterProxy.cs +++ b/Source/Editor/Content/Proxy/ParticleEmitterProxy.cs @@ -22,6 +22,9 @@ namespace FlaxEditor.Content /// public override string Name => "Particle Emitter"; + + /// + public override string CategoryName => "Particles"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/ParticleSystemProxy.cs b/Source/Editor/Content/Proxy/ParticleSystemProxy.cs index c19e84a78..b1fda9b60 100644 --- a/Source/Editor/Content/Proxy/ParticleSystemProxy.cs +++ b/Source/Editor/Content/Proxy/ParticleSystemProxy.cs @@ -46,6 +46,9 @@ namespace FlaxEditor.Content /// public override string Name => "Particle System"; + + /// + public override string CategoryName => "Particles"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/PrefabProxy.cs b/Source/Editor/Content/Proxy/PrefabProxy.cs index 64eb1d9f1..16e00069f 100644 --- a/Source/Editor/Content/Proxy/PrefabProxy.cs +++ b/Source/Editor/Content/Proxy/PrefabProxy.cs @@ -31,6 +31,9 @@ namespace FlaxEditor.Content /// public override string Name => "Prefab"; + + /// + public override string CategoryName => "Prefab"; /// public override string FileExtension => Extension; diff --git a/Source/Editor/Content/Proxy/PreviewsCacheProxy.cs b/Source/Editor/Content/Proxy/PreviewsCacheProxy.cs index b3bc6e73f..16c6ae9f2 100644 --- a/Source/Editor/Content/Proxy/PreviewsCacheProxy.cs +++ b/Source/Editor/Content/Proxy/PreviewsCacheProxy.cs @@ -15,6 +15,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Previews Cache"; + + /// + public override string CategoryName => "Previews Cache"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/SceneAnimationProxy.cs b/Source/Editor/Content/Proxy/SceneAnimationProxy.cs index 30409208e..4bebe20f6 100644 --- a/Source/Editor/Content/Proxy/SceneAnimationProxy.cs +++ b/Source/Editor/Content/Proxy/SceneAnimationProxy.cs @@ -40,6 +40,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Scene Animation"; + + /// + public override string CategoryName => "Animation"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/SceneProxy.cs b/Source/Editor/Content/Proxy/SceneProxy.cs index 7856fa064..6be481250 100644 --- a/Source/Editor/Content/Proxy/SceneProxy.cs +++ b/Source/Editor/Content/Proxy/SceneProxy.cs @@ -19,6 +19,9 @@ namespace FlaxEditor.Content /// public override string Name => "Scene"; + + /// + public override string CategoryName => "Scene"; /// public override string FileExtension => Extension; diff --git a/Source/Editor/Content/Proxy/SettingsProxy.cs b/Source/Editor/Content/Proxy/SettingsProxy.cs index 0bbd2830f..abe63f06e 100644 --- a/Source/Editor/Content/Proxy/SettingsProxy.cs +++ b/Source/Editor/Content/Proxy/SettingsProxy.cs @@ -20,6 +20,9 @@ namespace FlaxEditor.Content /// Gets the settings type. /// public Type Type => _type; + + /// + public override string CategoryName => "Settings"; /// /// Initializes a new instance of the class. diff --git a/Source/Editor/Content/Proxy/ShaderProxy.cs b/Source/Editor/Content/Proxy/ShaderProxy.cs index b65949460..76fd02897 100644 --- a/Source/Editor/Content/Proxy/ShaderProxy.cs +++ b/Source/Editor/Content/Proxy/ShaderProxy.cs @@ -14,6 +14,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Shader"; + + /// + public override string CategoryName => "Shader"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/SkeletonMaskProxy.cs b/Source/Editor/Content/Proxy/SkeletonMaskProxy.cs index 2a90820b0..d84bf3fe8 100644 --- a/Source/Editor/Content/Proxy/SkeletonMaskProxy.cs +++ b/Source/Editor/Content/Proxy/SkeletonMaskProxy.cs @@ -15,6 +15,9 @@ namespace FlaxEditor.Content { /// public override string Name => "Skeleton Mask"; + + /// + public override string CategoryName => "Animation"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/SkinnedModelProxy.cs b/Source/Editor/Content/Proxy/SkinnedModelProxy.cs index 597c69a1d..18276604e 100644 --- a/Source/Editor/Content/Proxy/SkinnedModelProxy.cs +++ b/Source/Editor/Content/Proxy/SkinnedModelProxy.cs @@ -20,6 +20,9 @@ namespace FlaxEditor.Content /// public override string Name => "Skinned Model"; + + /// + public override string CategoryName => "Model"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/SpriteAtlasProxy.cs b/Source/Editor/Content/Proxy/SpriteAtlasProxy.cs index 5184abafb..fce7e22e5 100644 --- a/Source/Editor/Content/Proxy/SpriteAtlasProxy.cs +++ b/Source/Editor/Content/Proxy/SpriteAtlasProxy.cs @@ -20,6 +20,9 @@ namespace FlaxEditor.Content /// public override string Name => "Sprite Atlas"; + + /// + public override string CategoryName => "Sprites"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/TextureProxy.cs b/Source/Editor/Content/Proxy/TextureProxy.cs index 67de33851..ce292d5b3 100644 --- a/Source/Editor/Content/Proxy/TextureProxy.cs +++ b/Source/Editor/Content/Proxy/TextureProxy.cs @@ -20,6 +20,9 @@ namespace FlaxEditor.Content /// public override string Name => "Texture"; + + /// + public override string CategoryName => "Texture"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/VisualScriptProxy.cs b/Source/Editor/Content/Proxy/VisualScriptProxy.cs index b065a4fcd..540e46945 100644 --- a/Source/Editor/Content/Proxy/VisualScriptProxy.cs +++ b/Source/Editor/Content/Proxy/VisualScriptProxy.cs @@ -24,6 +24,9 @@ namespace FlaxEditor.Content /// public override string Name => "Visual Script"; + + /// + public override string CategoryName => "Scripting"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Modules/ContentDatabaseModule.cs b/Source/Editor/Modules/ContentDatabaseModule.cs index a3ee714ae..990d42615 100644 --- a/Source/Editor/Modules/ContentDatabaseModule.cs +++ b/Source/Editor/Modules/ContentDatabaseModule.cs @@ -927,7 +927,9 @@ namespace FlaxEditor.Modules Proxy.Add(new VisualScriptProxy()); Proxy.Add(new LocalizedStringTableProxy()); Proxy.Add(new FileProxy()); - Proxy.Add(new SpawnableJsonAssetProxy()); + var pm = new SpawnableJsonAssetProxy(); + pm.SetCategoryName("Physics"); + Proxy.Add(pm); // Settings Proxy.Add(new SettingsProxy(typeof(GameSettings), Editor.Instance.Icons.GameSettings128)); diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index c0dcc9b14..7f27e0cd3 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -2,10 +2,12 @@ using System; using System.Collections.Generic; +using System.Linq; using FlaxEditor.Content; using FlaxEditor.GUI.ContextMenu; using FlaxEngine; using FlaxEngine.Assertions; +using FlaxEngine.GUI; using FlaxEngine.Json; namespace FlaxEditor.Windows @@ -17,35 +19,6 @@ namespace FlaxEditor.Windows /// public event Action ContextMenuShow; - private readonly List _animationGroupNames = new List() - { - "Animation", - "Animation Graph", - "Animation Graph Function", - "Skeleton Mask", - "Scene Animation", - }; - - private readonly List _particleGroupNames = new List() - { - "Particle Emitter", - "Particle Emitter Function", - "Particle System", - }; - - private readonly List _materialGroupNames = new List() - { - "Material", - "Material Function", - "Material Instance", - }; - - private readonly List _physicsGroupNames = new List() - { - "Collision Data", - "Physical Material", - }; - private void ShowContextMenuForItem(ContentItem item, ref Float2 location, bool isTreeNode) { Assert.IsNull(_newElement); @@ -180,6 +153,28 @@ namespace FlaxEditor.Windows cm.AddButton("New folder", NewFolder); } + // categorize the asset proxies according to their category name + Dictionary> categorizedProxyList = new Dictionary>(); + for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++) + { + var p = Editor.ContentDatabase.Proxy[i]; + if (p.CanCreate(folder)) + { + if (p is AssetProxy ap) + { + if (categorizedProxyList.ContainsKey(ap.CategoryName)) + { + categorizedProxyList.TryGetValue(ap.CategoryName, out var apList); + apList?.Add(ap); + } + else + { + categorizedProxyList.Add(ap.CategoryName, new List() {ap}); + } + } + } + } + c = cm.AddChildMenu("New"); c.ContextMenu.Tag = item; c.ContextMenu.AutoSort = true; @@ -189,17 +184,27 @@ namespace FlaxEditor.Windows var p = Editor.ContentDatabase.Proxy[i]; if (p.CanCreate(folder)) { - if (_animationGroupNames.Contains(p.Name)) - AddContentProxyToMenu(c.ContextMenu, p, "Animation"); - else if (_particleGroupNames.Contains(p.Name)) - AddContentProxyToMenu(c.ContextMenu, p, "Particles"); - else if (_materialGroupNames.Contains(p.Name)) - AddContentProxyToMenu(c.ContextMenu, p, "Materials"); - else if (_physicsGroupNames.Contains(p.Name)) - AddContentProxyToMenu(c.ContextMenu, p, "Physics"); + if (p is AssetProxy ap && categorizedProxyList.TryGetValue(ap.CategoryName, out var apList)) + { + if (apList.Contains(ap)) + { + if (apList.Count > 1) + { + var childMenu = c.ContextMenu.GetOrAddChildMenu(ap.CategoryName); + childMenu.ContextMenu.AutoSort = true; + childMenu.ContextMenu.AddButton(p.Name, () => NewItem(p)); + } + else + { + c.ContextMenu.AddButton(p.Name, () => NewItem(p)); + } + } + } else + { c.ContextMenu.AddButton(p.Name, () => NewItem(p)); - + } + newItems++; } } @@ -218,21 +223,6 @@ namespace FlaxEditor.Windows cm.Show(this, location); } - private void AddContentProxyToMenu(ContextMenu contextMenu, ContentProxy contentProxy, string menuName) - { - var childMenu = contextMenu.GetChildMenu(menuName); - if (childMenu == null) - { - var c = contextMenu.AddChildMenu(menuName); - c.ContextMenu.AutoSort = true; - c.ContextMenu.AddButton(contentProxy.Name, () => NewItem(contentProxy)); - } - else - { - childMenu.ContextMenu.AddButton(contentProxy.Name, () => NewItem(contentProxy)); - } - } - private void OnExpandAllClicked(ContextMenuButton button) { CurrentViewFolder.Node.ExpandAll(); From a1e4400994396f7dc4a7f560a4e6134f49d57cc7 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 2 Nov 2022 17:57:40 -0500 Subject: [PATCH 4/7] changed to use attribute to add items to the content context menu, this also allows users to add their own items to the CM --- .../Proxy/AnimationGraphFunctionProxy.cs | 4 +- .../Content/Proxy/AnimationGraphProxy.cs | 4 +- Source/Editor/Content/Proxy/AnimationProxy.cs | 4 +- Source/Editor/Content/Proxy/AssetProxy.cs | 5 - Source/Editor/Content/Proxy/AudioClipProxy.cs | 3 - .../Editor/Content/Proxy/CSharpScriptProxy.cs | 1 + .../Content/Proxy/CollisionDataProxy.cs | 4 +- Source/Editor/Content/Proxy/CppProxy.cs | 3 + .../Editor/Content/Proxy/CubeTextureProxy.cs | 3 - Source/Editor/Content/Proxy/FontProxy.cs | 3 - .../Content/Proxy/GameplayGlobalsProxy.cs | 4 +- .../Editor/Content/Proxy/IESProfileProxy.cs | 3 - Source/Editor/Content/Proxy/JsonAssetProxy.cs | 18 +-- .../Content/Proxy/MaterialFunctionProxy.cs | 4 +- .../Content/Proxy/MaterialInstanceProxy.cs | 4 +- Source/Editor/Content/Proxy/MaterialProxy.cs | 4 +- Source/Editor/Content/Proxy/ModelProxy.cs | 3 - .../Proxy/ParticleEmitterFunctionProxy.cs | 4 +- .../Content/Proxy/ParticleEmitterProxy.cs | 4 +- .../Content/Proxy/ParticleSystemProxy.cs | 4 +- Source/Editor/Content/Proxy/PrefabProxy.cs | 4 +- .../Content/Proxy/PreviewsCacheProxy.cs | 3 - .../Content/Proxy/SceneAnimationProxy.cs | 3 - Source/Editor/Content/Proxy/SceneProxy.cs | 4 +- Source/Editor/Content/Proxy/SettingsProxy.cs | 4 +- Source/Editor/Content/Proxy/ShaderProxy.cs | 3 - .../Editor/Content/Proxy/SkeletonMaskProxy.cs | 4 +- .../Editor/Content/Proxy/SkinnedModelProxy.cs | 3 - .../Editor/Content/Proxy/SpriteAtlasProxy.cs | 3 - Source/Editor/Content/Proxy/TextureProxy.cs | 3 - .../Editor/Content/Proxy/VisualScriptProxy.cs | 4 +- .../Editor/Modules/ContentDatabaseModule.cs | 4 +- .../Windows/ContentWindow.ContextMenu.cs | 105 ++++++++++-------- Source/Engine/Physics/PhysicalMaterial.h | 2 +- .../Attributes/Editor/ContentContextMenu.cs | 26 +++++ 35 files changed, 109 insertions(+), 152 deletions(-) create mode 100644 Source/Engine/Scripting/Attributes/Editor/ContentContextMenu.cs diff --git a/Source/Editor/Content/Proxy/AnimationGraphFunctionProxy.cs b/Source/Editor/Content/Proxy/AnimationGraphFunctionProxy.cs index cb611d2f8..a8092a162 100644 --- a/Source/Editor/Content/Proxy/AnimationGraphFunctionProxy.cs +++ b/Source/Editor/Content/Proxy/AnimationGraphFunctionProxy.cs @@ -11,14 +11,12 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Animation/Animation Graph Function")] public class AnimationGraphFunctionProxy : BinaryAssetProxy { /// public override string Name => "Animation Graph Function"; - /// - public override string CategoryName => "Animation"; - /// public override EditorWindow Open(Editor editor, ContentItem item) { diff --git a/Source/Editor/Content/Proxy/AnimationGraphProxy.cs b/Source/Editor/Content/Proxy/AnimationGraphProxy.cs index 103fee18e..7f43b8c7b 100644 --- a/Source/Editor/Content/Proxy/AnimationGraphProxy.cs +++ b/Source/Editor/Content/Proxy/AnimationGraphProxy.cs @@ -11,13 +11,11 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Animation/Animation Graph")] public class AnimationGraphProxy : BinaryAssetProxy { /// public override string Name => "Animation Graph"; - - /// - public override string CategoryName => "Animation"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/AnimationProxy.cs b/Source/Editor/Content/Proxy/AnimationProxy.cs index 07b613dcb..eb8c892ab 100644 --- a/Source/Editor/Content/Proxy/AnimationProxy.cs +++ b/Source/Editor/Content/Proxy/AnimationProxy.cs @@ -14,13 +14,11 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Animation/Animation")] public class AnimationProxy : BinaryAssetProxy { /// public override string Name => "Animation"; - - /// - public override string CategoryName => "Animation"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/AssetProxy.cs b/Source/Editor/Content/Proxy/AssetProxy.cs index 772b00a20..6516dbc37 100644 --- a/Source/Editor/Content/Proxy/AssetProxy.cs +++ b/Source/Editor/Content/Proxy/AssetProxy.cs @@ -22,11 +22,6 @@ namespace FlaxEditor.Content /// public abstract string TypeName { get; } - /// - /// The category name used to sort in context menus - /// - public abstract string CategoryName { get; } - /// /// Checks if this proxy supports the given asset type id at the given path. /// diff --git a/Source/Editor/Content/Proxy/AudioClipProxy.cs b/Source/Editor/Content/Proxy/AudioClipProxy.cs index f52802234..8b9ace491 100644 --- a/Source/Editor/Content/Proxy/AudioClipProxy.cs +++ b/Source/Editor/Content/Proxy/AudioClipProxy.cs @@ -62,9 +62,6 @@ namespace FlaxEditor.Content /// public override string Name => "Audio Clip"; - - /// - public override string CategoryName => "Audio"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/CSharpScriptProxy.cs b/Source/Editor/Content/Proxy/CSharpScriptProxy.cs index 332695695..a871d0589 100644 --- a/Source/Editor/Content/Proxy/CSharpScriptProxy.cs +++ b/Source/Editor/Content/Proxy/CSharpScriptProxy.cs @@ -12,6 +12,7 @@ namespace FlaxEditor.Content /// Context proxy object for C# script files. /// /// + [ContentContextMenu("New/C# Script")] public class CSharpScriptProxy : ScriptProxy { /// diff --git a/Source/Editor/Content/Proxy/CollisionDataProxy.cs b/Source/Editor/Content/Proxy/CollisionDataProxy.cs index 4bddbf063..b6ff2e75f 100644 --- a/Source/Editor/Content/Proxy/CollisionDataProxy.cs +++ b/Source/Editor/Content/Proxy/CollisionDataProxy.cs @@ -38,13 +38,11 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Physics/Collision Data")] class CollisionDataProxy : BinaryAssetProxy { /// public override string Name => "Collision Data"; - - /// - public override string CategoryName => "Physics"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/CppProxy.cs b/Source/Editor/Content/Proxy/CppProxy.cs index d975b8778..6581dccd2 100644 --- a/Source/Editor/Content/Proxy/CppProxy.cs +++ b/Source/Editor/Content/Proxy/CppProxy.cs @@ -75,6 +75,7 @@ namespace FlaxEditor.Content /// Context proxy object for C++ script files. /// /// + [ContentContextMenu("New/C++/C++ Script")] public class CppScriptProxy : CppProxy { /// @@ -98,6 +99,7 @@ namespace FlaxEditor.Content /// Context proxy object for C++ Json Asset files. /// /// + [ContentContextMenu("New/C++/C++ Function Library")] public class CppStaticClassProxy : CppProxy { /// @@ -115,6 +117,7 @@ namespace FlaxEditor.Content /// Context proxy object for C++ Json Asset files. /// /// + [ContentContextMenu("New/C++/C++ Json Asset")] public class CppAssetProxy : CppProxy { /// diff --git a/Source/Editor/Content/Proxy/CubeTextureProxy.cs b/Source/Editor/Content/Proxy/CubeTextureProxy.cs index 653e71ce3..d89771b13 100644 --- a/Source/Editor/Content/Proxy/CubeTextureProxy.cs +++ b/Source/Editor/Content/Proxy/CubeTextureProxy.cs @@ -20,9 +20,6 @@ namespace FlaxEditor.Content /// public override string Name => "Cube Texture"; - - /// - public override string CategoryName => "Texture"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/FontProxy.cs b/Source/Editor/Content/Proxy/FontProxy.cs index bb78d5ab0..10f0d9076 100644 --- a/Source/Editor/Content/Proxy/FontProxy.cs +++ b/Source/Editor/Content/Proxy/FontProxy.cs @@ -17,9 +17,6 @@ namespace FlaxEditor.Content { /// public override string Name => "Font"; - - /// - public override string CategoryName => "Font"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/GameplayGlobalsProxy.cs b/Source/Editor/Content/Proxy/GameplayGlobalsProxy.cs index 60a9b78bb..af391a8c4 100644 --- a/Source/Editor/Content/Proxy/GameplayGlobalsProxy.cs +++ b/Source/Editor/Content/Proxy/GameplayGlobalsProxy.cs @@ -11,13 +11,11 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Gameplay Globals")] public class GameplayGlobalsProxy : BinaryAssetProxy { /// public override string Name => "Gameplay Globals"; - - /// - public override string CategoryName => "Globals"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/IESProfileProxy.cs b/Source/Editor/Content/Proxy/IESProfileProxy.cs index 8ec932106..55b4c8d47 100644 --- a/Source/Editor/Content/Proxy/IESProfileProxy.cs +++ b/Source/Editor/Content/Proxy/IESProfileProxy.cs @@ -20,9 +20,6 @@ namespace FlaxEditor.Content /// public override string Name => "IES Profile"; - - /// - public override string CategoryName => "Lighting"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/JsonAssetProxy.cs b/Source/Editor/Content/Proxy/JsonAssetProxy.cs index 2f48a1b6c..8bfaae384 100644 --- a/Source/Editor/Content/Proxy/JsonAssetProxy.cs +++ b/Source/Editor/Content/Proxy/JsonAssetProxy.cs @@ -22,6 +22,7 @@ namespace FlaxEditor.Content /// Json assets proxy. /// /// + [ContentContextMenu("New/Json Asset")] public abstract class JsonAssetProxy : JsonAssetBaseProxy { /// @@ -31,9 +32,6 @@ namespace FlaxEditor.Content /// public override string Name => "Json Asset"; - - /// - public override string CategoryName => "Json Asset"; /// public override string FileExtension => Extension; @@ -168,20 +166,6 @@ namespace FlaxEditor.Content /// public override string Name { get; } = Utilities.Utils.GetPropertyNameUI(typeof(T).Name); - private string _categoryName; - - /// - public override string CategoryName => _categoryName; - - /// - /// Sets the category name - /// - /// This is the category name - public void SetCategoryName(string name) - { - _categoryName = name; - } - /// public override bool CanCreate(ContentFolder targetLocation) { diff --git a/Source/Editor/Content/Proxy/MaterialFunctionProxy.cs b/Source/Editor/Content/Proxy/MaterialFunctionProxy.cs index c2c317342..f8c868cb5 100644 --- a/Source/Editor/Content/Proxy/MaterialFunctionProxy.cs +++ b/Source/Editor/Content/Proxy/MaterialFunctionProxy.cs @@ -11,13 +11,11 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Material/Material Function")] public class MaterialFunctionProxy : BinaryAssetProxy { /// public override string Name => "Material Function"; - - /// - public override string CategoryName => "Material"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/MaterialInstanceProxy.cs b/Source/Editor/Content/Proxy/MaterialInstanceProxy.cs index ea0a73cbe..60ff9bc51 100644 --- a/Source/Editor/Content/Proxy/MaterialInstanceProxy.cs +++ b/Source/Editor/Content/Proxy/MaterialInstanceProxy.cs @@ -14,15 +14,13 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Material/Material Instance")] public class MaterialInstanceProxy : BinaryAssetProxy { private MaterialPreview _preview; /// public override string Name => "Material Instance"; - - /// - public override string CategoryName => "Material"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/MaterialProxy.cs b/Source/Editor/Content/Proxy/MaterialProxy.cs index 2da83bf96..68c9c81b7 100644 --- a/Source/Editor/Content/Proxy/MaterialProxy.cs +++ b/Source/Editor/Content/Proxy/MaterialProxy.cs @@ -15,15 +15,13 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Material/Material")] public class MaterialProxy : BinaryAssetProxy { private MaterialPreview _preview; /// public override string Name => "Material"; - - /// - public override string CategoryName => "Material"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/ModelProxy.cs b/Source/Editor/Content/Proxy/ModelProxy.cs index ed0633ce4..b99d15134 100644 --- a/Source/Editor/Content/Proxy/ModelProxy.cs +++ b/Source/Editor/Content/Proxy/ModelProxy.cs @@ -21,9 +21,6 @@ namespace FlaxEditor.Content /// public override string Name => "Model"; - - /// - public override string CategoryName => "Model"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/ParticleEmitterFunctionProxy.cs b/Source/Editor/Content/Proxy/ParticleEmitterFunctionProxy.cs index c56e5f695..b508bb818 100644 --- a/Source/Editor/Content/Proxy/ParticleEmitterFunctionProxy.cs +++ b/Source/Editor/Content/Proxy/ParticleEmitterFunctionProxy.cs @@ -11,13 +11,11 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Particles/Particle Emitter Function")] public class ParticleEmitterFunctionProxy : BinaryAssetProxy { /// public override string Name => "Particle Emitter Function"; - - /// - public override string CategoryName => "Particles"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/ParticleEmitterProxy.cs b/Source/Editor/Content/Proxy/ParticleEmitterProxy.cs index 391670085..be07720d2 100644 --- a/Source/Editor/Content/Proxy/ParticleEmitterProxy.cs +++ b/Source/Editor/Content/Proxy/ParticleEmitterProxy.cs @@ -15,6 +15,7 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Particles/Particle Emitter")] public class ParticleEmitterProxy : BinaryAssetProxy { private ParticleEmitterPreview _preview; @@ -22,9 +23,6 @@ namespace FlaxEditor.Content /// public override string Name => "Particle Emitter"; - - /// - public override string CategoryName => "Particles"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/ParticleSystemProxy.cs b/Source/Editor/Content/Proxy/ParticleSystemProxy.cs index b1fda9b60..38301afdf 100644 --- a/Source/Editor/Content/Proxy/ParticleSystemProxy.cs +++ b/Source/Editor/Content/Proxy/ParticleSystemProxy.cs @@ -39,6 +39,7 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Particles/Particle System")] public class ParticleSystemProxy : BinaryAssetProxy { private ParticleSystemPreview _preview; @@ -46,9 +47,6 @@ namespace FlaxEditor.Content /// public override string Name => "Particle System"; - - /// - public override string CategoryName => "Particles"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/PrefabProxy.cs b/Source/Editor/Content/Proxy/PrefabProxy.cs index 16e00069f..a4610b25a 100644 --- a/Source/Editor/Content/Proxy/PrefabProxy.cs +++ b/Source/Editor/Content/Proxy/PrefabProxy.cs @@ -15,6 +15,7 @@ namespace FlaxEditor.Content /// Content proxy for . /// /// + [ContentContextMenu("New/Prefab")] public sealed class PrefabProxy : JsonAssetBaseProxy { private PrefabPreview _preview; @@ -31,9 +32,6 @@ namespace FlaxEditor.Content /// public override string Name => "Prefab"; - - /// - public override string CategoryName => "Prefab"; /// public override string FileExtension => Extension; diff --git a/Source/Editor/Content/Proxy/PreviewsCacheProxy.cs b/Source/Editor/Content/Proxy/PreviewsCacheProxy.cs index 16c6ae9f2..b3bc6e73f 100644 --- a/Source/Editor/Content/Proxy/PreviewsCacheProxy.cs +++ b/Source/Editor/Content/Proxy/PreviewsCacheProxy.cs @@ -15,9 +15,6 @@ namespace FlaxEditor.Content { /// public override string Name => "Previews Cache"; - - /// - public override string CategoryName => "Previews Cache"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/SceneAnimationProxy.cs b/Source/Editor/Content/Proxy/SceneAnimationProxy.cs index 4bebe20f6..30409208e 100644 --- a/Source/Editor/Content/Proxy/SceneAnimationProxy.cs +++ b/Source/Editor/Content/Proxy/SceneAnimationProxy.cs @@ -40,9 +40,6 @@ namespace FlaxEditor.Content { /// public override string Name => "Scene Animation"; - - /// - public override string CategoryName => "Animation"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/SceneProxy.cs b/Source/Editor/Content/Proxy/SceneProxy.cs index 6be481250..cecd825a1 100644 --- a/Source/Editor/Content/Proxy/SceneProxy.cs +++ b/Source/Editor/Content/Proxy/SceneProxy.cs @@ -10,6 +10,7 @@ namespace FlaxEditor.Content /// Content proxy for . /// /// + [ContentContextMenu("New/Scene")] public sealed class SceneProxy : JsonAssetBaseProxy { /// @@ -19,9 +20,6 @@ namespace FlaxEditor.Content /// public override string Name => "Scene"; - - /// - public override string CategoryName => "Scene"; /// public override string FileExtension => Extension; diff --git a/Source/Editor/Content/Proxy/SettingsProxy.cs b/Source/Editor/Content/Proxy/SettingsProxy.cs index abe63f06e..651ba62d2 100644 --- a/Source/Editor/Content/Proxy/SettingsProxy.cs +++ b/Source/Editor/Content/Proxy/SettingsProxy.cs @@ -11,6 +11,7 @@ namespace FlaxEditor.Content /// Content proxy for json settings assets (e.g or ). /// /// + [ContentContextMenu("New/Settings")] public class SettingsProxy : JsonAssetProxy { private readonly Type _type; @@ -20,9 +21,6 @@ namespace FlaxEditor.Content /// Gets the settings type. /// public Type Type => _type; - - /// - public override string CategoryName => "Settings"; /// /// Initializes a new instance of the class. diff --git a/Source/Editor/Content/Proxy/ShaderProxy.cs b/Source/Editor/Content/Proxy/ShaderProxy.cs index 76fd02897..b65949460 100644 --- a/Source/Editor/Content/Proxy/ShaderProxy.cs +++ b/Source/Editor/Content/Proxy/ShaderProxy.cs @@ -14,9 +14,6 @@ namespace FlaxEditor.Content { /// public override string Name => "Shader"; - - /// - public override string CategoryName => "Shader"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/SkeletonMaskProxy.cs b/Source/Editor/Content/Proxy/SkeletonMaskProxy.cs index d84bf3fe8..ab78a1e09 100644 --- a/Source/Editor/Content/Proxy/SkeletonMaskProxy.cs +++ b/Source/Editor/Content/Proxy/SkeletonMaskProxy.cs @@ -11,13 +11,11 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Animation/Skeleton Mask")] public class SkeletonMaskProxy : BinaryAssetProxy { /// public override string Name => "Skeleton Mask"; - - /// - public override string CategoryName => "Animation"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Content/Proxy/SkinnedModelProxy.cs b/Source/Editor/Content/Proxy/SkinnedModelProxy.cs index 18276604e..597c69a1d 100644 --- a/Source/Editor/Content/Proxy/SkinnedModelProxy.cs +++ b/Source/Editor/Content/Proxy/SkinnedModelProxy.cs @@ -20,9 +20,6 @@ namespace FlaxEditor.Content /// public override string Name => "Skinned Model"; - - /// - public override string CategoryName => "Model"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/SpriteAtlasProxy.cs b/Source/Editor/Content/Proxy/SpriteAtlasProxy.cs index fce7e22e5..5184abafb 100644 --- a/Source/Editor/Content/Proxy/SpriteAtlasProxy.cs +++ b/Source/Editor/Content/Proxy/SpriteAtlasProxy.cs @@ -20,9 +20,6 @@ namespace FlaxEditor.Content /// public override string Name => "Sprite Atlas"; - - /// - public override string CategoryName => "Sprites"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/TextureProxy.cs b/Source/Editor/Content/Proxy/TextureProxy.cs index ce292d5b3..67de33851 100644 --- a/Source/Editor/Content/Proxy/TextureProxy.cs +++ b/Source/Editor/Content/Proxy/TextureProxy.cs @@ -20,9 +20,6 @@ namespace FlaxEditor.Content /// public override string Name => "Texture"; - - /// - public override string CategoryName => "Texture"; /// public override bool CanReimport(ContentItem item) diff --git a/Source/Editor/Content/Proxy/VisualScriptProxy.cs b/Source/Editor/Content/Proxy/VisualScriptProxy.cs index 540e46945..afd105131 100644 --- a/Source/Editor/Content/Proxy/VisualScriptProxy.cs +++ b/Source/Editor/Content/Proxy/VisualScriptProxy.cs @@ -15,6 +15,7 @@ namespace FlaxEditor.Content /// A asset proxy object. /// /// + [ContentContextMenu("New/Visual Script")] public class VisualScriptProxy : BinaryAssetProxy, IScriptTypesContainer { internal VisualScriptProxy() @@ -24,9 +25,6 @@ namespace FlaxEditor.Content /// public override string Name => "Visual Script"; - - /// - public override string CategoryName => "Scripting"; /// public override EditorWindow Open(Editor editor, ContentItem item) diff --git a/Source/Editor/Modules/ContentDatabaseModule.cs b/Source/Editor/Modules/ContentDatabaseModule.cs index 990d42615..a3ee714ae 100644 --- a/Source/Editor/Modules/ContentDatabaseModule.cs +++ b/Source/Editor/Modules/ContentDatabaseModule.cs @@ -927,9 +927,7 @@ namespace FlaxEditor.Modules Proxy.Add(new VisualScriptProxy()); Proxy.Add(new LocalizedStringTableProxy()); Proxy.Add(new FileProxy()); - var pm = new SpawnableJsonAssetProxy(); - pm.SetCategoryName("Physics"); - Proxy.Add(pm); + Proxy.Add(new SpawnableJsonAssetProxy()); // Settings Proxy.Add(new SettingsProxy(typeof(GameSettings), Editor.Instance.Icons.GameSettings128)); diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index 7f27e0cd3..36d3e4938 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -1,6 +1,7 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. using System; +using System.CodeDom; using System.Collections.Generic; using System.Linq; using FlaxEditor.Content; @@ -152,64 +153,78 @@ namespace FlaxEditor.Windows { cm.AddButton("New folder", NewFolder); } - - // categorize the asset proxies according to their category name - Dictionary> categorizedProxyList = new Dictionary>(); - for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++) + + // loop through each proxy and user defined json type and add them to the context menu + foreach (var type in Editor.CodeEditing.All.Get()) { - var p = Editor.ContentDatabase.Proxy[i]; + if (type.IsAbstract || !type.HasAttribute(typeof(ContentContextMenuAttribute), true)) + continue; + + ContentContextMenuAttribute attribute = null; + foreach (var typeAttribute in type.GetAttributes(true)) + { + if (typeAttribute is ContentContextMenuAttribute contentContextMenuAttribute) + { + attribute = contentContextMenuAttribute; + break; + } + } + + ContentProxy p; + if (type.Type.IsSubclassOf(typeof(ContentProxy))) + { + p = Editor.ContentDatabase.Proxy.Find(T => T.GetType() == type.Type); + } + else + { + // user can use attribute to put their own assets into the content context menu + var generic = typeof(SpawnableJsonAssetProxy<>).MakeGenericType(type.Type); + var instance = Activator.CreateInstance(generic); + dynamic obj = instance; + p = obj as AssetProxy; + } + + if (p == null) + continue; + + // create menus if (p.CanCreate(folder)) { - if (p is AssetProxy ap) + var splitPath = attribute.Path.Split('/'); + ContextMenuChildMenu childCM = null; + bool mainCM = true; + for (int i = 0; i < splitPath?.Length; i++) { - if (categorizedProxyList.ContainsKey(ap.CategoryName)) + if (i == splitPath.Length - 1) { - categorizedProxyList.TryGetValue(ap.CategoryName, out var apList); - apList?.Add(ap); + if (mainCM) + { + cm.AddButton(splitPath[i].Trim(), () => NewItem(p)); + mainCM = false; + } + else + { + childCM?.ContextMenu.AddButton(splitPath[i].Trim(), () => NewItem(p)); + childCM.ContextMenu.AutoSort = true; + } } else { - categorizedProxyList.Add(ap.CategoryName, new List() {ap}); + if (mainCM) + { + childCM = cm.GetOrAddChildMenu(splitPath[i].Trim()); + mainCM = false; + } + else + { + childCM = childCM?.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim()); + } + childCM.ContextMenu.AutoSort = true; } } } } - c = cm.AddChildMenu("New"); - c.ContextMenu.Tag = item; - c.ContextMenu.AutoSort = true; - int newItems = 0; - for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++) - { - var p = Editor.ContentDatabase.Proxy[i]; - if (p.CanCreate(folder)) - { - if (p is AssetProxy ap && categorizedProxyList.TryGetValue(ap.CategoryName, out var apList)) - { - if (apList.Contains(ap)) - { - if (apList.Count > 1) - { - var childMenu = c.ContextMenu.GetOrAddChildMenu(ap.CategoryName); - childMenu.ContextMenu.AutoSort = true; - childMenu.ContextMenu.AddButton(p.Name, () => NewItem(p)); - } - else - { - c.ContextMenu.AddButton(p.Name, () => NewItem(p)); - } - } - } - else - { - c.ContextMenu.AddButton(p.Name, () => NewItem(p)); - } - - newItems++; - } - } - c.Enabled = newItems > 0; - if (folder.CanHaveAssets) { cm.AddButton("Import file", () => diff --git a/Source/Engine/Physics/PhysicalMaterial.h b/Source/Engine/Physics/PhysicalMaterial.h index 0d8356546..b46c1a294 100644 --- a/Source/Engine/Physics/PhysicalMaterial.h +++ b/Source/Engine/Physics/PhysicalMaterial.h @@ -8,7 +8,7 @@ /// /// Physical materials are used to define the response of a physical object when interacting dynamically with the world. /// -API_CLASS() class FLAXENGINE_API PhysicalMaterial final : public ISerializable +API_CLASS(Attributes = "ContentContextMenu(\"New/Physics/Physical Material\")") class FLAXENGINE_API PhysicalMaterial final : public ISerializable { API_AUTO_SERIALIZATION(); DECLARE_SCRIPTING_TYPE_MINIMAL(PhysicalMaterial); diff --git a/Source/Engine/Scripting/Attributes/Editor/ContentContextMenu.cs b/Source/Engine/Scripting/Attributes/Editor/ContentContextMenu.cs new file mode 100644 index 000000000..ee9956ede --- /dev/null +++ b/Source/Engine/Scripting/Attributes/Editor/ContentContextMenu.cs @@ -0,0 +1,26 @@ +using System; + +namespace FlaxEngine +{ + /// + /// This attribute is used to show content items that can be created in the content browser context menu. Separate the subcontext menus with a /. + /// + [Serializable] + [AttributeUsage(AttributeTargets.Class)] + public class ContentContextMenuAttribute : Attribute + { + /// + /// The path to be used in the context menu + /// + public string Path; + + /// + /// Initializes a new instance of the class. + /// + /// The path to use to create the context menu + public ContentContextMenuAttribute(string path) + { + Path = path; + } + } +} From 7487b468d344f5341c2bc563f09a97f788381699 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Wed, 2 Nov 2022 18:37:11 -0500 Subject: [PATCH 5/7] added extra checks --- Source/Editor/Windows/ContentWindow.ContextMenu.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index 36d3e4938..db4ed13d8 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -157,9 +157,9 @@ namespace FlaxEditor.Windows // loop through each proxy and user defined json type and add them to the context menu foreach (var type in Editor.CodeEditing.All.Get()) { - if (type.IsAbstract || !type.HasAttribute(typeof(ContentContextMenuAttribute), true)) + if (type.IsAbstract || !type.HasAttribute(typeof(ContentContextMenuAttribute), true) || Editor.CodeEditing.Actors.Get().Contains(type) || Editor.CodeEditing.Scripts.Get().Contains(type)) continue; - + ContentContextMenuAttribute attribute = null; foreach (var typeAttribute in type.GetAttributes(true)) { From 2dca30305f6b38d8549a0a2fbd6b15c86a13e249 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 3 Nov 2022 08:12:40 -0500 Subject: [PATCH 6/7] added shader source and removed unused variables/includes --- Source/Editor/Content/Proxy/ShaderSourceProxy.cs | 1 + Source/Editor/Windows/ContentWindow.ContextMenu.cs | 5 ----- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/Source/Editor/Content/Proxy/ShaderSourceProxy.cs b/Source/Editor/Content/Proxy/ShaderSourceProxy.cs index 86020c997..9b2ec22d5 100644 --- a/Source/Editor/Content/Proxy/ShaderSourceProxy.cs +++ b/Source/Editor/Content/Proxy/ShaderSourceProxy.cs @@ -13,6 +13,7 @@ namespace FlaxEditor.Content /// Context proxy object for shader source files (represented by ). /// /// + [ContentContextMenu("New/Shader Source")] public class ShaderSourceProxy : ContentProxy { /// diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index db4ed13d8..aaf0bacb4 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -1,14 +1,10 @@ // Copyright (c) 2012-2022 Wojciech Figat. All rights reserved. using System; -using System.CodeDom; -using System.Collections.Generic; -using System.Linq; using FlaxEditor.Content; using FlaxEditor.GUI.ContextMenu; using FlaxEngine; using FlaxEngine.Assertions; -using FlaxEngine.GUI; using FlaxEngine.Json; namespace FlaxEditor.Windows @@ -43,7 +39,6 @@ namespace FlaxEditor.Windows // Create context menu ContextMenuButton b; - ContextMenuChildMenu c; ContextMenu cm = new ContextMenu { Tag = item From de4d3d97f211970f67a157d2a3b0613c2bb9c3bf Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 4 Nov 2022 07:10:24 -0500 Subject: [PATCH 7/7] removed not needed variable --- Source/Editor/Windows/ContentWindow.ContextMenu.cs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/Source/Editor/Windows/ContentWindow.ContextMenu.cs b/Source/Editor/Windows/ContentWindow.ContextMenu.cs index aaf0bacb4..56cba9b9e 100644 --- a/Source/Editor/Windows/ContentWindow.ContextMenu.cs +++ b/Source/Editor/Windows/ContentWindow.ContextMenu.cs @@ -175,8 +175,7 @@ namespace FlaxEditor.Windows // user can use attribute to put their own assets into the content context menu var generic = typeof(SpawnableJsonAssetProxy<>).MakeGenericType(type.Type); var instance = Activator.CreateInstance(generic); - dynamic obj = instance; - p = obj as AssetProxy; + p = instance as AssetProxy; } if (p == null)