From aded4bfdeb65e4996cb2347ff38b564137f48db6 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Fri, 27 Sep 2024 17:49:44 -0500 Subject: [PATCH 1/2] Add context to object referece control to narrow finding actors and scripts --- .../Editors/FlaxObjectRefEditor.cs | 10 ++++++-- Source/Editor/GUI/Popups/ActorSearchPopup.cs | 23 ++++++++++++++----- Source/Editor/GUI/Popups/ScriptSearchPopup.cs | 23 ++++++++++++++----- .../Editor/GUI/Timeline/Tracks/ActorTrack.cs | 2 +- 4 files changed, 43 insertions(+), 15 deletions(-) diff --git a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs index fd367d21f..ffc9b2b14 100644 --- a/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs +++ b/Source/Editor/CustomEditors/Editors/FlaxObjectRefEditor.cs @@ -38,6 +38,11 @@ namespace FlaxEditor.CustomEditors.Editors private DragScripts _dragScripts; private DragHandlers _dragHandlers; + /// + /// The presenter using this control. + /// + public IPresenterOwner PresenterContext; + /// /// Gets or sets the allowed objects type (given type and all sub classes). Must be type of any subclass. /// @@ -152,7 +157,7 @@ namespace FlaxEditor.CustomEditors.Editors Value = actor; RootWindow.Focus(); Focus(); - }); + }, PresenterContext); } else { @@ -161,7 +166,7 @@ namespace FlaxEditor.CustomEditors.Editors Value = script; RootWindow.Focus(); Focus(); - }); + }, PresenterContext); } } @@ -491,6 +496,7 @@ namespace FlaxEditor.CustomEditors.Editors if (!HasDifferentTypes) { _element = layout.Custom(); + _element.CustomControl.PresenterContext = Presenter.Owner; _element.CustomControl.Type = Values.Type.Type != typeof(object) || Values[0] == null ? Values.Type : TypeUtils.GetObjectType(Values[0]); _element.CustomControl.ValueChanged += () => SetValue(_element.CustomControl.Value); } diff --git a/Source/Editor/GUI/Popups/ActorSearchPopup.cs b/Source/Editor/GUI/Popups/ActorSearchPopup.cs index 2c327b685..7be17db98 100644 --- a/Source/Editor/GUI/Popups/ActorSearchPopup.cs +++ b/Source/Editor/GUI/Popups/ActorSearchPopup.cs @@ -1,6 +1,8 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; +using FlaxEditor.Windows; +using FlaxEditor.Windows.Assets; using FlaxEngine; using FlaxEngine.GUI; @@ -55,18 +57,26 @@ namespace FlaxEditor.GUI private IsValidDelegate _isValid; private Action _selected; - private ActorSearchPopup(IsValidDelegate isValid, Action selected) + private ActorSearchPopup(IsValidDelegate isValid, Action selected, CustomEditors.IPresenterOwner context) { _isValid = isValid; _selected = selected; ItemClicked += OnItemClicked; - // TODO: use async thread to search scenes - for (int i = 0; i < Level.ScenesCount; i++) + if (context is PropertiesWindow propertiesWindow || context == null) { - Find(Level.GetScene(i)); + // TODO: use async thread to search scenes + for (int i = 0; i < Level.ScenesCount; i++) + { + Find(Level.GetScene(i)); + } } + else if (context is PrefabWindow prefabWindow) + { + Find(prefabWindow.Graph.MainActor); + } + SortItems(); } @@ -98,10 +108,11 @@ namespace FlaxEditor.GUI /// The show target location. /// Event called to check if a given actor item is valid to be used. /// Event called on actor item pick. + /// The presenter owner context (i.e. PrefabWindow, PropertiesWindow). /// The dialog. - public static ActorSearchPopup Show(Control showTarget, Float2 showTargetLocation, IsValidDelegate isValid, Action selected) + public static ActorSearchPopup Show(Control showTarget, Float2 showTargetLocation, IsValidDelegate isValid, Action selected, CustomEditors.IPresenterOwner context) { - var popup = new ActorSearchPopup(isValid, selected); + var popup = new ActorSearchPopup(isValid, selected, context); popup.Show(showTarget, showTargetLocation); return popup; } diff --git a/Source/Editor/GUI/Popups/ScriptSearchPopup.cs b/Source/Editor/GUI/Popups/ScriptSearchPopup.cs index 93c860275..a6414bb86 100644 --- a/Source/Editor/GUI/Popups/ScriptSearchPopup.cs +++ b/Source/Editor/GUI/Popups/ScriptSearchPopup.cs @@ -1,6 +1,8 @@ // Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; +using FlaxEditor.Windows; +using FlaxEditor.Windows.Assets; using FlaxEngine; using FlaxEngine.GUI; using FlaxEngine.Utilities; @@ -66,18 +68,26 @@ namespace FlaxEditor.GUI private IsValidDelegate _isValid; private Action