Merge branch 'master' into 1.5

# Conflicts:
#	Source/Engine/Serialization/Stream.cpp
This commit is contained in:
Wojtek Figat
2022-11-21 15:51:57 +01:00
62 changed files with 391 additions and 351 deletions

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;
@@ -246,24 +246,53 @@ namespace FlaxEditor.Windows.Assets
// Spawning actors options
contextMenu.AddSeparator();
var spawnMenu = contextMenu.AddChildMenu("New");
var newActorCm = spawnMenu.ContextMenu;
for (int i = 0; i < SceneTreeWindow.SpawnActorsGroups.Length; i++)
{
var group = SceneTreeWindow.SpawnActorsGroups[i];
if (group.Types.Length == 1)
// Go through each actor and add it to the context menu if it has the ActorContextMenu attribute
foreach (var actorType in Editor.CodeEditing.Actors.Get())
{
if (actorType.IsAbstract)
continue;
ActorContextMenuAttribute attribute = null;
foreach (var e in actorType.GetAttributes(true))
{
var type = group.Types[0].Value;
newActorCm.AddButton(group.Types[0].Key, () => Spawn(type));
}
else
{
var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu;
for (int j = 0; j < group.Types.Length; j++)
if (e is ActorContextMenuAttribute actorContextMenuAttribute)
{
var type = group.Types[j].Value;
groupCm.AddButton(group.Types[j].Key, () => Spawn(type));
attribute = actorContextMenuAttribute;
break;
}
}
if (attribute == null)
continue;
var splitPath = attribute.Path.Split('/');
ContextMenuChildMenu childCM = null;
bool mainCM = true;
for (int i = 0; i < splitPath?.Length; i++)
{
if (i == splitPath.Length - 1)
{
if (mainCM)
{
contextMenu.AddButton(splitPath[i].Trim(), () => Spawn(actorType.Type));
mainCM = false;
}
else
{
childCM?.ContextMenu.AddButton(splitPath[i].Trim(), () => Spawn(actorType.Type));
childCM.ContextMenu.AutoSort = true;
}
}
else
{
if (mainCM)
{
childCM = contextMenu.GetOrAddChildMenu(splitPath[i].Trim());
mainCM = false;
}
else
{
childCM = childCM?.ContextMenu.GetOrAddChildMenu(splitPath[i].Trim());
}
childCM.ContextMenu.AutoSort = true;
}
}
}
@@ -310,7 +339,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,28 @@ 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;
}
if (button == MouseButton.Left && _treePanel.ContainsPoint(ref location))
{
_tree.Deselect();
return true;
}
return false;
}
private void OnScriptsReloadBegin()
{
_isScriptsReloading = true;