From 2a7dcff5c46bdcd18804611b6d913ce328f3c822 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 21 Nov 2024 20:24:16 -0600 Subject: [PATCH 1/3] Fix scene tree menu options being enabled when not supposed to be --- Source/Editor/SceneGraph/Actors/SceneNode.cs | 1 + Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs | 12 ++++++------ 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/Source/Editor/SceneGraph/Actors/SceneNode.cs b/Source/Editor/SceneGraph/Actors/SceneNode.cs index f0938492f..bb5998ef4 100644 --- a/Source/Editor/SceneGraph/Actors/SceneNode.cs +++ b/Source/Editor/SceneGraph/Actors/SceneNode.cs @@ -81,6 +81,7 @@ namespace FlaxEditor.SceneGraph.Actors if (Level.ScenesCount > 1) contextMenu.AddButton("Unload all but this scene", OnUnloadAllButSelectedScene).LinkTooltip("Unloads all of the active scenes except for the selected scene.").Enabled = Editor.Instance.StateMachine.CurrentState.CanChangeScene; + contextMenu.MaximumItemsInViewCount += 3; base.OnContextMenu(contextMenu, window); } diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index 2cbe56a27..75dab7828 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -55,9 +55,9 @@ namespace FlaxEditor.Windows b = contextMenu.AddButton("Rename", inputOptions.Rename, Rename); b = contextMenu.AddButton("Duplicate", inputOptions.Duplicate, Editor.SceneEditing.Duplicate); - b.Enabled = hasSthSelected; + b.Enabled = hasSthSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).CanDuplicate; - if (isSingleActorSelected) + if (isSingleActorSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).Actor is not Scene) { var convertMenu = contextMenu.AddChildMenu("Convert"); convertMenu.ContextMenu.AutoSort = true; @@ -117,24 +117,24 @@ namespace FlaxEditor.Windows } } b = contextMenu.AddButton("Delete", inputOptions.Delete, Editor.SceneEditing.Delete); - b.Enabled = hasSthSelected; + b.Enabled = hasSthSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).CanDelete; contextMenu.AddSeparator(); b = contextMenu.AddButton("Copy", inputOptions.Copy, Editor.SceneEditing.Copy); + b.Enabled = hasSthSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).CanCopyPaste; - b.Enabled = hasSthSelected; contextMenu.AddButton("Paste", inputOptions.Paste, Editor.SceneEditing.Paste); b = contextMenu.AddButton("Cut", inputOptions.Cut, Editor.SceneEditing.Cut); - b.Enabled = canEditScene; + b.Enabled = canEditScene && ((ActorNode)Editor.SceneEditing.Selection[0]).CanCopyPaste; // Create option contextMenu.AddSeparator(); b = contextMenu.AddButton("Parent to new Actor", inputOptions.GroupSelectedActors, Editor.SceneEditing.CreateParentForSelectedActors); - b.Enabled = canEditScene && hasSthSelected; + b.Enabled = canEditScene && hasSthSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).Actor is not Scene; b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab); b.Enabled = isSingleActorSelected && From 27044da099669d393ba29f7a662f07bda1f1c342 Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 21 Nov 2024 20:29:38 -0600 Subject: [PATCH 2/3] Small optimization. --- .../Windows/SceneTreeWindow.ContextMenu.cs | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index 75dab7828..b4a52d394 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -52,12 +52,12 @@ namespace FlaxEditor.Windows contextMenu.AddSeparator(); // Basic editing options - + var firstSelection = (ActorNode)Editor.SceneEditing.Selection[0]; b = contextMenu.AddButton("Rename", inputOptions.Rename, Rename); b = contextMenu.AddButton("Duplicate", inputOptions.Duplicate, Editor.SceneEditing.Duplicate); - b.Enabled = hasSthSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).CanDuplicate; + b.Enabled = hasSthSelected && firstSelection.CanDuplicate; - if (isSingleActorSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).Actor is not Scene) + if (isSingleActorSelected && firstSelection.Actor is not Scene) { var convertMenu = contextMenu.AddChildMenu("Convert"); convertMenu.ContextMenu.AutoSort = true; @@ -117,31 +117,31 @@ namespace FlaxEditor.Windows } } b = contextMenu.AddButton("Delete", inputOptions.Delete, Editor.SceneEditing.Delete); - b.Enabled = hasSthSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).CanDelete; + b.Enabled = hasSthSelected && firstSelection.CanDelete; contextMenu.AddSeparator(); b = contextMenu.AddButton("Copy", inputOptions.Copy, Editor.SceneEditing.Copy); - b.Enabled = hasSthSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).CanCopyPaste; + b.Enabled = hasSthSelected && firstSelection.CanCopyPaste; contextMenu.AddButton("Paste", inputOptions.Paste, Editor.SceneEditing.Paste); b = contextMenu.AddButton("Cut", inputOptions.Cut, Editor.SceneEditing.Cut); - b.Enabled = canEditScene && ((ActorNode)Editor.SceneEditing.Selection[0]).CanCopyPaste; + b.Enabled = canEditScene && firstSelection.CanCopyPaste; // Create option contextMenu.AddSeparator(); b = contextMenu.AddButton("Parent to new Actor", inputOptions.GroupSelectedActors, Editor.SceneEditing.CreateParentForSelectedActors); - b.Enabled = canEditScene && hasSthSelected && ((ActorNode)Editor.SceneEditing.Selection[0]).Actor is not Scene; + b.Enabled = canEditScene && hasSthSelected && firstSelection.Actor is not Scene; b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab); b.Enabled = isSingleActorSelected && - ((ActorNode)Editor.SceneEditing.Selection[0]).CanCreatePrefab && + firstSelection.CanCreatePrefab && Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets; - bool hasPrefabLink = canEditScene && isSingleActorSelected && (Editor.SceneEditing.Selection[0] as ActorNode).HasPrefabLink; + bool hasPrefabLink = canEditScene && isSingleActorSelected && firstSelection.HasPrefabLink; if (hasPrefabLink) { contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab); From 7330101206005ab2a8f6706bb42b1eddc501404b Mon Sep 17 00:00:00 2001 From: Chandler Cox Date: Thu, 21 Nov 2024 20:52:34 -0600 Subject: [PATCH 3/3] Fix errors --- .../Windows/SceneTreeWindow.ContextMenu.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs index b4a52d394..a107a72f5 100644 --- a/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs +++ b/Source/Editor/Windows/SceneTreeWindow.ContextMenu.cs @@ -52,12 +52,13 @@ namespace FlaxEditor.Windows contextMenu.AddSeparator(); // Basic editing options - var firstSelection = (ActorNode)Editor.SceneEditing.Selection[0]; + var firstSelection = hasSthSelected ? Editor.SceneEditing.Selection[0] as ActorNode : null; b = contextMenu.AddButton("Rename", inputOptions.Rename, Rename); + b.Enabled = hasSthSelected; b = contextMenu.AddButton("Duplicate", inputOptions.Duplicate, Editor.SceneEditing.Duplicate); - b.Enabled = hasSthSelected && firstSelection.CanDuplicate; + b.Enabled = hasSthSelected && (firstSelection != null ? firstSelection.CanDuplicate : true); - if (isSingleActorSelected && firstSelection.Actor is not Scene) + if (isSingleActorSelected && firstSelection?.Actor is not Scene) { var convertMenu = contextMenu.AddChildMenu("Convert"); convertMenu.ContextMenu.AutoSort = true; @@ -117,31 +118,31 @@ namespace FlaxEditor.Windows } } b = contextMenu.AddButton("Delete", inputOptions.Delete, Editor.SceneEditing.Delete); - b.Enabled = hasSthSelected && firstSelection.CanDelete; + b.Enabled = hasSthSelected && (firstSelection != null ? firstSelection.CanDelete : true); contextMenu.AddSeparator(); b = contextMenu.AddButton("Copy", inputOptions.Copy, Editor.SceneEditing.Copy); - b.Enabled = hasSthSelected && firstSelection.CanCopyPaste; + b.Enabled = hasSthSelected && (firstSelection != null ? firstSelection.CanCopyPaste : true); contextMenu.AddButton("Paste", inputOptions.Paste, Editor.SceneEditing.Paste); b = contextMenu.AddButton("Cut", inputOptions.Cut, Editor.SceneEditing.Cut); - b.Enabled = canEditScene && firstSelection.CanCopyPaste; + b.Enabled = canEditScene && hasSthSelected && (firstSelection != null ? firstSelection.CanCopyPaste : true); // Create option contextMenu.AddSeparator(); b = contextMenu.AddButton("Parent to new Actor", inputOptions.GroupSelectedActors, Editor.SceneEditing.CreateParentForSelectedActors); - b.Enabled = canEditScene && hasSthSelected && firstSelection.Actor is not Scene; + b.Enabled = canEditScene && hasSthSelected && firstSelection?.Actor is not Scene; b = contextMenu.AddButton("Create Prefab", Editor.Prefabs.CreatePrefab); b.Enabled = isSingleActorSelected && - firstSelection.CanCreatePrefab && + (firstSelection != null ? firstSelection.CanCreatePrefab : false) && Editor.Windows.ContentWin.CurrentViewFolder.CanHaveAssets; - bool hasPrefabLink = canEditScene && isSingleActorSelected && firstSelection.HasPrefabLink; + bool hasPrefabLink = canEditScene && isSingleActorSelected && (firstSelection != null ? firstSelection.HasPrefabLink : false); if (hasPrefabLink) { contextMenu.AddButton("Select Prefab", Editor.Prefabs.SelectPrefab);