From f432e54809b5a15d874da3d49bb7e1d0492dcd4c Mon Sep 17 00:00:00 2001 From: xxSeys1 Date: Tue, 8 Apr 2025 13:44:11 +0200 Subject: [PATCH] add primitive meshes to toolbox search --- Source/Editor/Windows/ToolboxWindow.cs | 51 +++++++++++++++++++++----- 1 file changed, 41 insertions(+), 10 deletions(-) diff --git a/Source/Editor/Windows/ToolboxWindow.cs b/Source/Editor/Windows/ToolboxWindow.cs index c467658e5..1b0b04b54 100644 --- a/Source/Editor/Windows/ToolboxWindow.cs +++ b/Source/Editor/Windows/ToolboxWindow.cs @@ -101,6 +101,7 @@ namespace FlaxEditor.Windows private TextBox _searchBox; private ContainerControl _groupSearch; private Tabs _actorGroups; + private ContainerControl groupPrimitives; /// /// The editor instance. @@ -192,13 +193,13 @@ namespace FlaxEditor.Windows } // Setup primitives tabs - var groupBasicModels = CreateGroupWithList(_actorGroups, "Basic Models"); - groupBasicModels.AddChild(CreateEditorAssetItem("Cube", "Primitives/Cube.flax")); - groupBasicModels.AddChild(CreateEditorAssetItem("Sphere", "Primitives/Sphere.flax")); - groupBasicModels.AddChild(CreateEditorAssetItem("Plane", "Primitives/Plane.flax")); - groupBasicModels.AddChild(CreateEditorAssetItem("Cylinder", "Primitives/Cylinder.flax")); - groupBasicModels.AddChild(CreateEditorAssetItem("Cone", "Primitives/Cone.flax")); - groupBasicModels.AddChild(CreateEditorAssetItem("Capsule", "Primitives/Capsule.flax")); + groupPrimitives = CreateGroupWithList(_actorGroups, "Primitives"); + groupPrimitives.AddChild(CreateEditorAssetItem("Cube", "Primitives/Cube.flax")); + groupPrimitives.AddChild(CreateEditorAssetItem("Sphere", "Primitives/Sphere.flax")); + groupPrimitives.AddChild(CreateEditorAssetItem("Plane", "Primitives/Plane.flax")); + groupPrimitives.AddChild(CreateEditorAssetItem("Cylinder", "Primitives/Cylinder.flax")); + groupPrimitives.AddChild(CreateEditorAssetItem("Cone", "Primitives/Cone.flax")); + groupPrimitives.AddChild(CreateEditorAssetItem("Capsule", "Primitives/Capsule.flax")); // Created first to order specific tabs CreateGroupWithList(_actorGroups, "Lights"); @@ -346,7 +347,35 @@ namespace FlaxEditor.Windows } item.SetHighlights(highlights); } - + + // Hack primitive models into the search results + foreach (var child in groupPrimitives.Children) + { + if (child is Item primitiveAssetItem) + { + String text = primitiveAssetItem.Text; + + if (!QueryFilterHelper.Match(filterText, text, out QueryFilterHelper.Range[] ranges)) + continue; + + // Rebuild the path based on item name (it would be better to convert the drag data back to a string somehow) + string path = $"Primitives/{text}.flax"; + var item = _groupSearch.AddChild(CreateEditorAssetItem(text, path)); + + var highlights = new List(ranges.Length); + var style = Style.Current; + var font = style.FontSmall; + var textRect = item.TextRect; + for (int i = 0; i < ranges.Length; i++) + { + var start = font.GetCharPosition(text, ranges[i].StartIndex); + var end = font.GetCharPosition(text, ranges[i].EndIndex); + highlights.Add(new Rectangle(start.X + textRect.X, textRect.Y, end.X - start.X, textRect.Height)); + } + item.SetHighlights(highlights); + } + } + if (string.IsNullOrEmpty(filterText)) _groupSearch.SortChildren(); @@ -357,8 +386,10 @@ namespace FlaxEditor.Windows private Item CreateEditorAssetItem(string name, string path) { - path = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor", path); - return new Item(name, GUI.Drag.DragItems.GetDragData(path)); + string globalPath = StringUtils.CombinePaths(Globals.EngineContentFolder, "Editor", path); + Item item = new Item(name, GUI.Drag.DragItems.GetDragData(globalPath)); + item.TooltipText = $"{path}\nActor with a {name} asset."; + return item; } private Item CreateActorItem(string name, ScriptType type)