Esempio n. 1
0
        /// <summary>
        /// Creates the context menu for the current objects selection.
        /// </summary>
        /// <returns>The context menu.</returns>
        private ContextMenu CreateContextMenu()
        {
            // Prepare

            bool hasSthSelected        = Selection.Count > 0;
            bool isSingleActorSelected = Selection.Count == 1 && Selection[0] is ActorNode;
            bool isRootSelected        = isSingleActorSelected && Selection[0] == Graph.Main;
            bool hasPrefabLink         = isSingleActorSelected && (Selection[0] as ActorNode).HasPrefabLink;

            // Create popup

            var contextMenu = new ContextMenu
            {
                MinimumWidth = 120
            };

            // Basic editing options

            var b = contextMenu.AddButton("Rename", Rename);

            b.Enabled = isSingleActorSelected;

            b         = contextMenu.AddButton("Duplicate", Duplicate);
            b.Enabled = hasSthSelected && !isRootSelected;

            b         = contextMenu.AddButton("Delete", Delete);
            b.Enabled = hasSthSelected && !isRootSelected;

            contextMenu.AddSeparator();
            b         = contextMenu.AddButton("Copy", Copy);
            b.Enabled = hasSthSelected;

            b.Enabled = hasSthSelected;
            contextMenu.AddButton("Paste", Paste);

            b         = contextMenu.AddButton("Cut", Cut);
            b.Enabled = hasSthSelected && !isRootSelected;

            b         = contextMenu.AddButton("Set Root", SetRoot);
            b.Enabled = isSingleActorSelected && !isRootSelected && hasPrefabLink && Editor.Internal_CanSetToRoot(FlaxEngine.Object.GetUnmanagedPtr(Asset), FlaxEngine.Object.GetUnmanagedPtr(((ActorNode)Selection[0]).Actor));

            // Prefab options

            contextMenu.AddSeparator();

            b         = contextMenu.AddButton("Create Prefab", () => Editor.Prefabs.CreatePrefab(Selection));
            b.Enabled = isSingleActorSelected &&
                        (Selection[0] as ActorNode).CanCreatePrefab &&
                        Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets;

            b         = contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab);
            b.Enabled = hasPrefabLink;

            // 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)
                {
                    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++)
                    {
                        var type = group.Types[j].Value;
                        groupCm.AddButton(group.Types[j].Key, () => Spawn(type));
                    }
                }
            }

            // Custom options
            bool showCustomNodeOptions = Editor.SceneEditing.Selection.Count == 1;

            if (!showCustomNodeOptions && Editor.SceneEditing.Selection.Count != 0)
            {
                showCustomNodeOptions = true;
                for (int i = 1; i < Editor.SceneEditing.Selection.Count; i++)
                {
                    if (Editor.SceneEditing.Selection[0].GetType() != Editor.SceneEditing.Selection[i].GetType())
                    {
                        showCustomNodeOptions = false;
                        break;
                    }
                }
            }
            if (showCustomNodeOptions)
            {
                Editor.SceneEditing.Selection[0].OnContextMenu(contextMenu);
            }
            ContextMenuShow?.Invoke(contextMenu);

            return(contextMenu);
        }
        /// <summary>
        /// Creates the context menu for the current objects selection and the current Editor state.
        /// </summary>
        /// <returns>The context menu.</returns>
        private ContextMenu CreateContextMenu()
        {
            // Prepare

            bool hasSthSelected        = Editor.SceneEditing.HasSthSelected;
            bool isSingleActorSelected = Editor.SceneEditing.SelectionCount == 1 && Editor.SceneEditing.Selection[0] is ActorNode;
            bool canEditScene          = Editor.StateMachine.CurrentState.CanEditScene && Level.IsAnySceneLoaded;

            // Create popup

            var contextMenu = new ContextMenu
            {
                MinimumWidth = 120
            };

            // Expand/collapse

            var b = contextMenu.AddButton("Expand All", OnExpandAllClicked);

            b.Enabled = hasSthSelected;

            b         = contextMenu.AddButton("Collapse All", OnCollapseAllClicked);
            b.Enabled = hasSthSelected;

            if (hasSthSelected)
            {
                contextMenu.AddButton(Editor.Windows.EditWin.IsPilotActorActive ? "Stop piloting actor" : "Pilot actor", Editor.UI.PilotActor);
            }

            contextMenu.AddSeparator();

            // Basic editing options

            b         = contextMenu.AddButton("Rename", Rename);
            b.Enabled = isSingleActorSelected;

            b         = contextMenu.AddButton("Duplicate", Editor.SceneEditing.Duplicate);
            b.Enabled = hasSthSelected;

            if (isSingleActorSelected)
            {
                var convertMenu    = contextMenu.AddChildMenu("Convert");
                var convertActorCm = convertMenu.ContextMenu;
                for (int i = 0; i < SpawnActorsGroups.Length; i++)
                {
                    var group = SpawnActorsGroups[i];

                    if (group.Types.Length == 1)
                    {
                        var type = group.Types[0].Value;
                        convertActorCm.AddButton(group.Types[0].Key, () => Editor.SceneEditing.Convert(type));
                    }
                    else
                    {
                        var groupCm = convertActorCm.AddChildMenu(group.Name).ContextMenu;
                        for (int j = 0; j < group.Types.Length; j++)
                        {
                            var type = group.Types[j].Value;
                            groupCm.AddButton(group.Types[j].Key, () => Editor.SceneEditing.Convert(type));
                        }
                    }
                }
            }
            b         = contextMenu.AddButton("Delete", Editor.SceneEditing.Delete);
            b.Enabled = hasSthSelected;

            contextMenu.AddSeparator();

            b = contextMenu.AddButton("Copy", Editor.SceneEditing.Copy);

            b.Enabled = hasSthSelected;
            contextMenu.AddButton("Paste", Editor.SceneEditing.Paste);

            b         = contextMenu.AddButton("Cut", Editor.SceneEditing.Cut);
            b.Enabled = canEditScene;

            // Prefab options

            contextMenu.AddSeparator();

            b         = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab);
            b.Enabled = isSingleActorSelected &&
                        ((ActorNode)Editor.SceneEditing.Selection[0]).CanCreatePrefab &&
                        Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets;

            bool hasPrefabLink = canEditScene && isSingleActorSelected && (Editor.SceneEditing.Selection[0] as ActorNode).HasPrefabLink;

            if (hasPrefabLink)
            {
                contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab);
                contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks);
            }

            // Spawning actors options

            contextMenu.AddSeparator();

            var spawnMenu  = contextMenu.AddChildMenu("New");
            var newActorCm = spawnMenu.ContextMenu;

            for (int i = 0; i < SpawnActorsGroups.Length; i++)
            {
                var group = SpawnActorsGroups[i];

                if (group.Types.Length == 1)
                {
                    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++)
                    {
                        var type = group.Types[j].Value;
                        groupCm.AddButton(group.Types[j].Key, () => Spawn(type));
                    }
                }
            }

            // Custom options

            bool showCustomNodeOptions = Editor.SceneEditing.Selection.Count == 1;

            if (!showCustomNodeOptions && Editor.SceneEditing.Selection.Count != 0)
            {
                showCustomNodeOptions = true;
                for (int i = 1; i < Editor.SceneEditing.Selection.Count; i++)
                {
                    if (Editor.SceneEditing.Selection[0].GetType() != Editor.SceneEditing.Selection[i].GetType())
                    {
                        showCustomNodeOptions = false;
                        break;
                    }
                }
            }
            if (showCustomNodeOptions)
            {
                Editor.SceneEditing.Selection[0].OnContextMenu(contextMenu);
            }

            ContextMenuShow?.Invoke(contextMenu);

            return(contextMenu);
        }
Esempio n. 3
0
        private void ShowContextMenuForItem(ContentItem item, ref Vector2 location, bool isTreeNode)
        {
            Assert.IsNull(_newElement);

            // Cache data
            bool          isValidElement = item != null;
            var           proxy          = Editor.ContentDatabase.GetProxy(item);
            ContentFolder folder         = null;
            bool          isFolder       = false;

            if (isValidElement)
            {
                isFolder = item.IsFolder;
                folder   = isFolder ? (ContentFolder)item : item.ParentFolder;
            }
            else
            {
                folder = CurrentViewFolder;
            }
            Assert.IsNotNull(folder);
            bool isRootFolder = CurrentViewFolder == _root.Folder;

            // Create context menu
            ContextMenuButton    b;
            ContextMenuChildMenu c;
            ContextMenu          cm = new ContextMenu();

            cm.Tag = item;
            if (isTreeNode)
            {
                b         = cm.AddButton("Expand All", OnExpandAllClicked);
                b.Enabled = CurrentViewFolder.Node.ChildrenCount != 0;

                b         = cm.AddButton("Collapse All", OnCollapseAllClicked);
                b.Enabled = CurrentViewFolder.Node.ChildrenCount != 0;

                cm.AddSeparator();
            }
            if (isValidElement)
            {
                b         = cm.AddButton("Open", () => Open(item));
                b.Enabled = proxy != null || isFolder;

                cm.AddButton("Show in explorer", () => Application.StartProcess(System.IO.Path.GetDirectoryName(item.Path)));

                if (item.HasDefaultThumbnail == false)
                {
                    cm.AddButton("Refresh thumbnail", item.RefreshThumbnail);
                }

                if (!isFolder)
                {
                    b         = cm.AddButton("Reimport", ReimportSelection);
                    b.Enabled = proxy != null && proxy.CanReimport(item);

                    if (item is BinaryAssetItem binaryAsset)
                    {
                        string importPath;
                        if (!binaryAsset.GetImportPath(out importPath))
                        {
                            string importLocation = System.IO.Path.GetDirectoryName(importPath);
                            if (!string.IsNullOrEmpty(importLocation) && System.IO.Directory.Exists(importLocation))
                            {
                                cm.AddButton("Show import location", () => Application.StartProcess(importLocation));
                            }
                        }
                    }

                    if (Editor.CanExport(item.Path))
                    {
                        b = cm.AddButton("Export", ExportSelection);
                    }
                }

                cm.AddButton("Delete", () => Delete(item));

                cm.AddSeparator();

                b         = cm.AddButton("Clone", _view.Duplicate);
                b.Enabled = !isFolder;

                cm.AddButton("Copy", _view.Copy);

                cm.AddButton("Paste", _view.Paste);
                b.Enabled = _view.CanPaste();

                cm.AddButton("Rename", () => Rename(item));

                // Custom options
                ContextMenuShow?.Invoke(cm, item);
                proxy?.OnContentWindowContextMenu(cm, item);

                cm.AddButton("Copy name to Clipboard", () => Application.ClipboardText = item.NamePath);

                cm.AddButton("Copy path to Clipboard", () => Application.ClipboardText = item.Path);
            }
            else
            {
                cm.AddButton("Show in explorer", () => Application.StartProcess(CurrentViewFolder.Path));

                b         = cm.AddButton("Paste", _view.Paste);
                b.Enabled = _view.CanPaste();

                cm.AddButton("Refresh", () => Editor.ContentDatabase.RefreshFolder(CurrentViewFolder, true));

                cm.AddButton("Refresh all thumbnails", RefreshViewItemsThumbnails);
            }

            cm.AddSeparator();

            if (!isRootFolder)
            {
                cm.AddButton("New folder", NewFolder);
            }

            c = cm.AddChildMenu("New");
            c.ContextMenu.Tag = item;
            int newItems = 0;

            for (int i = 0; i < Editor.ContentDatabase.Proxy.Count; i++)
            {
                var p = Editor.ContentDatabase.Proxy[i];
                if (p.CanCreate(folder))
                {
                    c.ContextMenu.AddButton(p.Name, () => NewItem(p));
                    newItems++;
                }
            }
            c.Enabled = newItems > 0;

            if (folder.CanHaveAssets)
            {
                cm.AddButton("Import file", () =>
                {
                    _view.ClearSelection();
                    Editor.ContentImporting.ShowImportFileDialog(CurrentViewFolder);
                });
            }

            // Show it
            cm.Show(this, location);
        }
Esempio n. 4
0
        /// <summary>
        /// Creates the context menu for the current objects selection.
        /// </summary>
        /// <returns>The context menu.</returns>
        private ContextMenu CreateContextMenu()
        {
            // Prepare

            bool hasSthSelected        = Selection.Count > 0;
            bool isSingleActorSelected = Selection.Count == 1 && Selection[0] is ActorNode;
            bool isRootSelected        = isSingleActorSelected && Selection[0] == Graph.Main;

            // Create popup

            var contextMenu = new ContextMenu();

            contextMenu.MinimumWidth = 120;

            // Basic editing options

            var b = contextMenu.AddButton("Rename", Rename);

            b.Enabled = isSingleActorSelected;

            b         = contextMenu.AddButton("Duplicate", Duplicate);
            b.Enabled = hasSthSelected && !isRootSelected;

            b         = contextMenu.AddButton("Delete", Delete);
            b.Enabled = hasSthSelected && !isRootSelected;

            contextMenu.AddSeparator();
            b         = contextMenu.AddButton("Copy", Copy);
            b.Enabled = hasSthSelected;

            b.Enabled = hasSthSelected;
            contextMenu.AddButton("Paste", Paste);

            b         = contextMenu.AddButton("Cut", Cut);
            b.Enabled = hasSthSelected && !isRootSelected;

            // Prefab options

            contextMenu.AddSeparator();

            b         = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab);
            b.Enabled = isSingleActorSelected &&
                        (Selection[0] as ActorNode).CanCreatePrefab &&
                        Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets;

            bool hasPrefabLink = isSingleActorSelected && (Selection[0] as ActorNode).HasPrefabLink;

            b         = contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab);
            b.Enabled = hasPrefabLink;

            // 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)
                {
                    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++)
                    {
                        var type = group.Types[j].Value;
                        groupCm.AddButton(group.Types[j].Key, () => Spawn(type));
                    }
                }
            }

            // Custom options

            ContextMenuShow?.Invoke(contextMenu);

            return(contextMenu);
        }
        /// <summary>
        /// Creates the context menu for the current objects selection and the current Editor state.
        /// </summary>
        /// <returns>The context menu.</returns>
        private ContextMenu CreateContextMenu()
        {
            // Prepare

            bool hasSthSelected        = Editor.SceneEditing.HasSthSelected;
            bool isSingleActorSelected = Editor.SceneEditing.SelectionCount == 1 && Editor.SceneEditing.Selection[0] is ActorNode;
            bool canEditScene          = Editor.StateMachine.CurrentState.CanEditScene && SceneManager.IsAnySceneLoaded;

            // Create popup

            var contextMenu = new ContextMenu();

            contextMenu.MinimumWidth = 120;

            // Expand/collapse

            var b = contextMenu.AddButton("Expand All", OnExpandAllClicked);

            b.Enabled = hasSthSelected;

            b         = contextMenu.AddButton("Collapse All", OnCollapseAllClicked);
            b.Enabled = hasSthSelected;

            contextMenu.AddSeparator();

            // Basic editing options

            b         = contextMenu.AddButton("Rename", Rename);
            b.Enabled = isSingleActorSelected;

            b         = contextMenu.AddButton("Duplicate", Editor.SceneEditing.Duplicate);
            b.Enabled = hasSthSelected;

            b         = contextMenu.AddButton("Delete", Editor.SceneEditing.Delete);
            b.Enabled = hasSthSelected;

            contextMenu.AddSeparator();
            b = contextMenu.AddButton("Copy", Editor.SceneEditing.Copy);

            b.Enabled = hasSthSelected;
            contextMenu.AddButton("Paste", Editor.SceneEditing.Paste);

            b         = contextMenu.AddButton("Cut", Editor.SceneEditing.Cut);
            b.Enabled = canEditScene;

            // Prefab options

            contextMenu.AddSeparator();

            b         = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab);
            b.Enabled = isSingleActorSelected &&
                        (Editor.SceneEditing.Selection[0] as ActorNode).CanCreatePrefab &&
                        Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets;

            bool hasPrefabLink = canEditScene && isSingleActorSelected && (Editor.SceneEditing.Selection[0] as ActorNode).HasPrefabLink;

            b         = contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab);
            b.Enabled = hasPrefabLink;

            b         = contextMenu.AddButton("Break Prefab Link", Editor.Prefabs.BreakLinks);
            b.Enabled = hasPrefabLink;

            // Spawning actors options

            contextMenu.AddSeparator();
            var spawnMenu  = contextMenu.AddChildMenu("New");
            var newActorCm = spawnMenu.ContextMenu;

            for (int i = 0; i < SpawnActorsGroups.Length; i++)
            {
                var group = SpawnActorsGroups[i];

                if (group.Types.Length == 1)
                {
                    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++)
                    {
                        var type = group.Types[j].Value;
                        groupCm.AddButton(group.Types[j].Key, () => Spawn(type));
                    }
                }
            }

            // Custom options

            ContextMenuShow?.Invoke(contextMenu);

            return(contextMenu);
        }