Various fixes to prefab tree view. Scrolling like scene view, disable scrolling on renaming, can open CM anywhere in tree panel.

This commit is contained in:
Chandler Cox
2022-10-29 09:14:08 -05:00
parent 91663f0202
commit 40a04bc5d6
5 changed files with 79 additions and 13 deletions

View File

@@ -9,6 +9,8 @@ using FlaxEditor.GUI.Drag;
using FlaxEditor.GUI.Tree;
using FlaxEditor.Scripting;
using FlaxEditor.Utilities;
using FlaxEditor.Windows;
using FlaxEditor.Windows.Assets;
using FlaxEngine;
using FlaxEngine.GUI;
using Object = FlaxEngine.Object;
@@ -265,7 +267,7 @@ namespace FlaxEditor.SceneGraph.GUI
/// <summary>
/// Starts the actor renaming action.
/// </summary>
public void StartRenaming()
public void StartRenaming(EditorWindow window)
{
// Block renaming during scripts reload
if (Editor.Instance.ProgressReporting.CompileScripts.IsActive)
@@ -273,16 +275,22 @@ namespace FlaxEditor.SceneGraph.GUI
Select();
// Disable scrolling of scene view
Editor.Instance.Windows.SceneWin.ScrollingOnSceneTreeView(false);
// Disable scrolling of view
if (window is SceneTreeWindow)
(window as SceneTreeWindow).ScrollingOnSceneTreeView(false);
else if (window is PrefabWindow)
(window as PrefabWindow).ScrollingOnTreeView(false);
// Start renaming the actor
var dialog = RenamePopup.Show(this, HeaderRect, _actorNode.Name, false);
dialog.Renamed += OnRenamed;
dialog.Closed += popup =>
{
// Enable scrolling of scene view
Editor.Instance.Windows.SceneWin.ScrollingOnSceneTreeView(true);
// Enable scrolling of view
if (window is SceneTreeWindow)
(window as SceneTreeWindow).ScrollingOnSceneTreeView(true);
else if (window is PrefabWindow)
(window as PrefabWindow).ScrollingOnTreeView(true);
};
}
@@ -290,9 +298,6 @@ namespace FlaxEditor.SceneGraph.GUI
{
using (new UndoBlock(ActorNode.Root.Undo, Actor, "Rename"))
Actor.Name = renamePopup.Text;
// Enable scrolling of scene view
Editor.Instance.Windows.SceneWin.ScrollingOnSceneTreeView(true);
}
/// <inheritdoc />

View File

@@ -153,6 +153,9 @@ namespace FlaxEditor.Windows.Assets
{
OnPasteAction(pasteAction);
}
// Scroll to new selected node
ScrollToSelectedNode();
}
/// <summary>
@@ -180,6 +183,9 @@ namespace FlaxEditor.Windows.Assets
{
OnPasteAction(pasteAction);
}
// Scroll to new selected node
ScrollToSelectedNode();
}
private void OnPasteAction(PasteActorsAction pasteAction)
@@ -328,6 +334,9 @@ namespace FlaxEditor.Windows.Assets
}, action2.ActionString);
action.Do();
Undo.AddAction(action);
_treePanel.PerformLayout();
_treePanel.PerformLayout();
}
}
}

View File

@@ -67,7 +67,7 @@ namespace FlaxEditor.Windows.Assets
private DragHandlers _dragHandlers;
public SceneTreePanel(PrefabWindow window)
: base(ScrollBars.Vertical)
: base(ScrollBars.None)
{
_window = window;
Offsets = Margin.Zero;
@@ -310,7 +310,7 @@ namespace FlaxEditor.Windows.Assets
{
if (selection.Count != 0)
Select(actor);
actor.TreeNode.StartRenaming();
actor.TreeNode.StartRenaming(this);
}
}

View File

@@ -23,6 +23,7 @@ namespace FlaxEditor.Windows.Assets
private readonly SplitPanel _split1;
private readonly SplitPanel _split2;
private readonly TextBox _searchBox;
private readonly Panel _treePanel;
private readonly PrefabTree _tree;
private readonly PrefabWindowViewport _viewport;
private readonly CustomEditorPresenter _propertiesEditor;
@@ -132,17 +133,26 @@ namespace FlaxEditor.Windows.Assets
};
_searchBox.TextChanged += OnSearchBoxTextChanged;
_treePanel = new Panel()
{
AnchorPreset = AnchorPresets.StretchAll,
Offsets = new Margin(0.0f, 0.0f, headerPanel.Bottom, 0.0f),
ScrollBars = ScrollBars.Both,
IsScrollable = true,
Parent = sceneTreePanel,
};
// Prefab structure tree
Graph = new LocalSceneGraph(new CustomRootNode(this));
_tree = new PrefabTree
{
Y = headerPanel.Bottom,
Margin = new Margin(0.0f, 0.0f, -16.0f, 0.0f), // Hide root node
IsScrollable = true,
};
_tree.AddChild(Graph.Root.TreeNode);
_tree.SelectedChanged += OnTreeSelectedChanged;
_tree.RightClick += OnTreeRightClick;
_tree.Parent = sceneTreePanel;
_tree.Parent = _treePanel;
headerPanel.Parent = sceneTreePanel;
// Prefab viewport
@@ -192,6 +202,32 @@ namespace FlaxEditor.Windows.Assets
InputActions.Add(options => options.Rename, Rename);
InputActions.Add(options => options.FocusSelection, _viewport.FocusSelection);
}
/// <summary>
/// Enables or disables vertical and horizontal scrolling on the tree panel.
/// </summary>
/// <param name="enabled">The state to set scrolling to</param>
public void ScrollingOnTreeView(bool enabled)
{
if (_treePanel.VScrollBar != null)
_treePanel.VScrollBar.ThumbEnabled = enabled;
if (_treePanel.HScrollBar != null)
_treePanel.HScrollBar.ThumbEnabled = enabled;
}
/// <summary>
/// Scrolls to the selected node in the tree.
/// </summary>
public void ScrollToSelectedNode()
{
// Scroll to node
var nodeSelection = _tree.Selection;
if (nodeSelection.Count != 0)
{
var scrollControl = nodeSelection[nodeSelection.Count - 1];
_treePanel.ScrollViewTo(scrollControl);
}
}
private void OnSearchBoxTextChanged()
{
@@ -211,6 +247,22 @@ namespace FlaxEditor.Windows.Assets
PerformLayout();
}
/// <inheritdoc />
public override bool OnMouseUp(Float2 location, MouseButton button)
{
if (base.OnMouseUp(location, button))
return true;
if (button == MouseButton.Right && _treePanel.ContainsPoint(ref location))
{
_tree.Deselect();
var locationCM = location + _searchBox.BottomLeft;
ShowContextMenu(Parent, ref locationCM);
return true;
}
return false;
}
private void OnScriptsReloadBegin()
{
_isScriptsReloading = true;

View File

@@ -249,7 +249,7 @@ namespace FlaxEditor.Windows
{
if (selection.Count != 0)
Editor.SceneEditing.Select(actor);
actor.TreeNode.StartRenaming();
actor.TreeNode.StartRenaming(this);
}
}