// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. using FlaxEditor.GUI; using FlaxEditor.GUI.Drag; using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Content.GUI { /// /// A navigation button for . /// /// public class ContentNavigationButton : NavigationButton { private DragItems _dragOverItems; /// /// Gets the target node. /// public ContentTreeNode TargetNode { get; } /// /// Initializes a new instance of the class. /// /// The target node. /// The x position. /// The y position. /// The height. public ContentNavigationButton(ContentTreeNode targetNode, float x, float y, float height) : base(x, y, height) { TargetNode = targetNode; Text = targetNode.NavButtonLabel + "/"; } /// protected override void OnClick() { // Navigate Editor.Instance.Windows.ContentWin.Navigate(TargetNode); base.OnClick(); } private DragDropEffect GetDragEffect(DragData data) { if (data is DragDataFiles) { if (TargetNode.CanHaveAssets) return DragDropEffect.Copy; } else { if (_dragOverItems.HasValidDrag) return DragDropEffect.Move; } return DragDropEffect.None; } private bool ValidateDragItem(ContentItem item) { // Reject itself and any parent return item != TargetNode.Folder && !item.Find(TargetNode.Folder) && !TargetNode.IsRoot; } /// public override DragDropEffect OnDragEnter(ref Vector2 location, DragData data) { base.OnDragEnter(ref location, data); if (_dragOverItems == null) _dragOverItems = new DragItems(ValidateDragItem); _dragOverItems.OnDragEnter(data); var result = GetDragEffect(data); _validDragOver = result != DragDropEffect.None; return result; } /// public override DragDropEffect OnDragMove(ref Vector2 location, DragData data) { base.OnDragMove(ref location, data); return GetDragEffect(data); } /// public override void OnDragLeave() { base.OnDragLeave(); _dragOverItems.OnDragLeave(); _validDragOver = false; } /// public override DragDropEffect OnDragDrop(ref Vector2 location, DragData data) { var result = DragDropEffect.None; base.OnDragDrop(ref location, data); // Check if drop element or files if (data is DragDataFiles files) { // Import files Editor.Instance.ContentImporting.Import(files.Files, TargetNode.Folder); result = DragDropEffect.Copy; } else if (_dragOverItems.HasValidDrag) { // Move items Editor.Instance.ContentDatabase.Move(_dragOverItems.Objects, TargetNode.Folder); result = DragDropEffect.Move; } _dragOverItems.OnDragDrop(); _validDragOver = false; return result; } } }