private ContextMenuChildMenu GetOrAddChildMenu(string name, ContextMenu parent) { ContextMenuChildMenu item = parent.GetChildMenu(name); if (item == null) { item = parent.AddChildMenu(name); _menus.Add(item); } return(item); }
/// <summary> /// Initializes a new instance of the <see cref="SceneTreeWindow"/> class. /// </summary> /// <param name="editor">The editor.</param> public SceneTreeWindow(Editor editor) : base(editor, true, ScrollBars.Both) { Title = "Scene"; // Create scene structure tree var root = editor.Scene.Root; root.TreeNode.Expand(); _tree = new Tree(true); _tree.AddChild(root.TreeNode); _tree.SelectedChanged += Tree_OnSelectedChanged; _tree.RightClick += Tree_OnRightClick; _tree.Parent = this; // Spawnable actors (groups with single entry are inlined without a child menu) var groups = new[] { new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Actor", typeof(EmptyActor)) } }, new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Model", typeof(ModelActor)) } }, new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Camera", typeof(Camera)) } }, new ActorsGroup { Name = "Lights", Types = new[] { new KeyValuePair <string, Type>("Point Light", typeof(PointLight)), new KeyValuePair <string, Type>("Spot Light", typeof(SpotLight)), new KeyValuePair <string, Type>("Directional Light", typeof(DirectionalLight)), } }, new ActorsGroup { Name = "Visuals", Types = new[] { new KeyValuePair <string, Type>("Environment Probe", typeof(EnvironmentProbe)), new KeyValuePair <string, Type>("Sky", typeof(Sky)), new KeyValuePair <string, Type>("Skybox", typeof(Skybox)), } }, new ActorsGroup { Name = "Physics", Types = new[] { new KeyValuePair <string, Type>("Rigid Body", typeof(RigidBody)), new KeyValuePair <string, Type>("Character Controller", typeof(CharacterController)), new KeyValuePair <string, Type>("Box Collider", typeof(BoxCollider)), new KeyValuePair <string, Type>("Sphere Collider", typeof(SphereCollider)), new KeyValuePair <string, Type>("Capsule Collider", typeof(CapsuleCollider)), new KeyValuePair <string, Type>("Mesh Collider", typeof(MeshCollider)), new KeyValuePair <string, Type>("Fixed Joint", typeof(FixedJoint)), new KeyValuePair <string, Type>("Distance Joint", typeof(DistanceJoint)), new KeyValuePair <string, Type>("Slider Joint", typeof(SliderJoint)), new KeyValuePair <string, Type>("Spherical Joint", typeof(SphericalJoint)), new KeyValuePair <string, Type>("Hinge Joint", typeof(HingeJoint)), new KeyValuePair <string, Type>("D6 Joint", typeof(D6Joint)), } }, new ActorsGroup { Name = "CSG", Types = new[] { new KeyValuePair <string, Type>("Box Brush", typeof(BoxBrush)), } }, new ActorsGroup { Name = "Volumes", Types = new[] { new KeyValuePair <string, Type>("PostFx Volume", typeof(PostFxVolume)), } }, }; // Create context menu _contextMenu = new ContextMenu(); _contextMenu.MinimumWidth = 120; _contextMenu.AddButton(1, "Duplicate"); _contextMenu.AddButton(2, "Delete"); _contextMenu.AddSeparator(); _contextMenu.AddButton(3, "Copy"); _contextMenu.AddButton(4, "Paste"); _contextMenu.AddButton(5, "Cut"); _contextMenu.AddSeparator(); _spawnMenu = _contextMenu.AddChildMenu("New"); var newActorCm = _spawnMenu.ContextMenu; for (int i = 0; i < groups.Length; i++) { var group = groups[i]; if (group.Types.Length == 1) { var button = newActorCm.AddButton(6 + i, group.Types[0].Key); button.Tag = group.Types[0].Value; } else { var groupCm = newActorCm.AddChildMenu(group.Name).ContextMenu; for (int j = 0; j < group.Types.Length; j++) { var button = groupCm.AddButton(j, group.Types[j].Key); button.Tag = group.Types[j].Value; } groupCm.OnButtonClicked += GroupCmOnButtonClicked; } } newActorCm.OnButtonClicked += ContextMenuOnButtonClicked; _contextMenu.VisibleChanged += ContextMenuOnVisibleChanged; _contextMenu.OnButtonClicked += ContextMenuOnButtonClicked; }
/// <summary> /// Initializes a new instance of the <see cref="SceneTreeWindow"/> class. /// </summary> /// <param name="editor">The editor.</param> public SceneTreeWindow(Editor editor) : base(editor, true, ScrollBars.Both) { Title = "Scene"; // Create scene structure tree var root = editor.Scene.Root; root.TreeNode.ChildrenIndent = 0; root.TreeNode.Expand(); _tree = new Tree(true); _tree.Margin = new Margin(0.0f, 0.0f, -14.0f, 0.0f); // Hide root node _tree.AddChild(root.TreeNode); _tree.SelectedChanged += Tree_OnSelectedChanged; _tree.RightClick += Tree_OnRightClick; _tree.Parent = this; // Spawnable actors (groups with single entry are inlined without a child menu) var groups = new[] { new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Actor", typeof(EmptyActor)) } }, new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Model", typeof(ModelActor)) } }, new ActorsGroup { Types = new[] { new KeyValuePair <string, Type>("Camera", typeof(Camera)) } }, new ActorsGroup { Name = "Lights", Types = new[] { new KeyValuePair <string, Type>("Directional Light", typeof(DirectionalLight)), new KeyValuePair <string, Type>("Point Light", typeof(PointLight)), new KeyValuePair <string, Type>("Spot Light", typeof(SpotLight)), new KeyValuePair <string, Type>("Sky Light", typeof(SkyLight)), } }, new ActorsGroup { Name = "Visuals", Types = new[] { new KeyValuePair <string, Type>("Environment Probe", typeof(EnvironmentProbe)), new KeyValuePair <string, Type>("Sky", typeof(Sky)), new KeyValuePair <string, Type>("Skybox", typeof(Skybox)), new KeyValuePair <string, Type>("Exponential Height Fog", typeof(ExponentialHeightFog)), new KeyValuePair <string, Type>("PostFx Volume", typeof(PostFxVolume)), new KeyValuePair <string, Type>("Decal", typeof(Decal)), } }, new ActorsGroup { Name = "Physics", Types = new[] { new KeyValuePair <string, Type>("Rigid Body", typeof(RigidBody)), new KeyValuePair <string, Type>("Character Controller", typeof(CharacterController)), new KeyValuePair <string, Type>("Box Collider", typeof(BoxCollider)), new KeyValuePair <string, Type>("Sphere Collider", typeof(SphereCollider)), new KeyValuePair <string, Type>("Capsule Collider", typeof(CapsuleCollider)), new KeyValuePair <string, Type>("Mesh Collider", typeof(MeshCollider)), new KeyValuePair <string, Type>("Fixed Joint", typeof(FixedJoint)), new KeyValuePair <string, Type>("Distance Joint", typeof(DistanceJoint)), new KeyValuePair <string, Type>("Slider Joint", typeof(SliderJoint)), new KeyValuePair <string, Type>("Spherical Joint", typeof(SphericalJoint)), new KeyValuePair <string, Type>("Hinge Joint", typeof(HingeJoint)), new KeyValuePair <string, Type>("D6 Joint", typeof(D6Joint)), } }, new ActorsGroup { Name = "Other", Types = new[] { new KeyValuePair <string, Type>("Animated Model", typeof(AnimatedModel)), new KeyValuePair <string, Type>("Bone Socket", typeof(BoneSocket)), new KeyValuePair <string, Type>("CSG Box Brush", typeof(BoxBrush)), new KeyValuePair <string, Type>("Audio Source", typeof(AudioSource)), new KeyValuePair <string, Type>("Audio Listener", typeof(AudioListener)), } }, new ActorsGroup { Name = "GUI", Types = new[] { new KeyValuePair <string, Type>("UI Control", typeof(UIControl)), new KeyValuePair <string, Type>("UI Canvas", typeof(UICanvas)), new KeyValuePair <string, Type>("Text Render", typeof(TextRender)), } }, }; // Create context menu _contextMenu = new ContextMenu(); _contextMenu.MinimumWidth = 120; _cmRename = _contextMenu.AddButton("Rename", Rename); _cmDuplicate = _contextMenu.AddButton("Duplicate", Editor.SceneEditing.Duplicate); _cmDelete = _contextMenu.AddButton("Delete", Editor.SceneEditing.Delete); _contextMenu.AddSeparator(); _cmCopy = _contextMenu.AddButton("Copy", Editor.SceneEditing.Copy); _contextMenu.AddButton("Paste", Editor.SceneEditing.Paste); _cmCut = _contextMenu.AddButton("Cut", Editor.SceneEditing.Cut); _contextMenu.AddSeparator(); _spawnMenu = _contextMenu.AddChildMenu("New"); var newActorCm = _spawnMenu.ContextMenu; for (int i = 0; i < groups.Length; i++) { var group = groups[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)); } } } _contextMenu.VisibleChanged += ContextMenuOnVisibleChanged; }