예제 #1
0
        private bool SetupEditor(Editor editor)
        {
            EditorState state = editor.CreateState();

            EditorSelection selection  = new EditorSelection();
            PhotoImageView  photo_view = MainWindow.Toplevel.PhotoView.View;

            if (Page.InPhotoView && photo_view != null)
            {
                if (photo_view.GetSelection(out selection.x, out selection.y,
                                            out selection.width, out selection.height))
                {
                    state.Selection = selection;
                }
                else
                {
                    state.Selection = null;
                }
                state.PhotoImageView = photo_view;
            }
            else
            {
                state.Selection      = null;
                state.PhotoImageView = null;
            }
            if (Page.Sidebar.Selection == null)
            {
                return(false);
            }
            state.Items = Page.Sidebar.Selection.Items;

            editor.Initialize(state);
            return(true);
        }
예제 #2
0
        private void OnSelectedNodesChanged(IChangeSet <NodeViewModel> changeset)
        {
            Change <NodeViewModel> change = changeset.First();

            NodeViewModel view = change.Item.Current;

            if (view == null)
            {
                return;
            }

            if (view.Outputs.Count > 0 && view.Outputs.Items.First().Editor is VectorValueEditorViewModel vec_model)
            {
                switch (change.Reason)
                {
                case ListChangeReason.Add:
                    EditorSelection.AddToSelection(vec_model.Value[0]);
                    break;

                case ListChangeReason.Remove:
                    EditorSelection.RemoveFromSelection(vec_model.Value[0]);
                    break;
                }
            }
            else if (view.Outputs.Items.First().Parent is CutNodeViewModel cut_model && changeset.Removes == 0)
            {
                OnUserRequestPreviewShot(cut_model.Cut);
            }
        }
        public void element_selection_select_is_straight_passthrough()
        {
            var accessor1 = ReflectionHelper.GetAccessor<GridDefinitionTester.GridDefTarget>(x => x.Name);
            var selection = new EditorSelection(a => a.Name == "Name", SlickGridEditor.Underscore);

            selection.EditorFor(accessor1).ShouldEqual(SlickGridEditor.Underscore);
        }
예제 #4
0
            protected override void AdditionalMenuItems()
            {
                Add(new MenuSeparator());

                //add before
                Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointInsertBefore123), "Insert a point before this point",
                                       () =>
                {
                    var curve    = point.Curve;
                    var settings = BGPrivateField.GetSettings(curve);
                    var index    = curve.IndexOf(point);
                    curve.AddPoint(BGNewPointPositionManager.InsertBefore(curve, index, settings.ControlType, settings.Sections), index);
                }));

                //add after
                Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGPointInsertAfter123), "Insert a point after this point",
                                       () =>
                {
                    var curve    = point.Curve;
                    var settings = BGPrivateField.GetSettings(curve);
                    var index    = curve.IndexOf(point);
                    curve.AddPoint(BGNewPointPositionManager.InsertAfter(curve, index, settings.ControlType, settings.Sections), index + 1);
                }));


                //add remove to selection
                addToSelectionItem = new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionAdd123), "Add this point to selection",
                                                        () => EditorSelection.Add(point));

                removeFromSelectionItem = new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionRemove123), "Remove this point from selection",
                                                             () => EditorSelection.Remove(point));

                Add(addToSelectionItem);
                Add(removeFromSelectionItem);
            }
예제 #5
0
        public void element_selection_select_is_straight_passthrough()
        {
            var accessor1 = ReflectionHelper.GetAccessor <GridDefinitionTester.GridDefTarget>(x => x.Name);
            var selection = new EditorSelection(a => a.Name == "Name", SlickGridEditor.Underscore);

            selection.EditorFor(accessor1).ShouldEqual(SlickGridEditor.Underscore);
        }
예제 #6
0
 public void ClearSelection()
 {
     foreach (WDOMNode node in EditorSelection.SelectedObjects)
     {
         node.IsSelected = false;
     }
     EditorSelection.ClearSelection();
 }
예제 #7
0
        public void element_selection_matches()
        {
            var accessor1 = ReflectionHelper.GetAccessor <GridDefinitionTester.GridDefTarget>(x => x.Name);
            var accessor2 = ReflectionHelper.GetAccessor <GridDefinitionTester.GridDefTarget>(x => x.IsCool);

            var selection = new EditorSelection(a => a.Name == "Name", SlickGridEditor.Underscore);

            selection.Matches(accessor1).ShouldBeTrue();
            selection.Matches(accessor2).ShouldBeFalse();
        }
예제 #8
0
 protected override void AdditionalMenuItems()
 {
     Add(new MenuSeparator());
     Add(new MenuItemButton(BGEditorUtility.LoadTexture2D(BGEditorUtility.Image.BGSelectionRemove123), "Remove this point from selection",
                            () =>
     {
         EditorSelection.Clear();
         EditorUtility.SetDirty(Overlay.Editor.Curve);
     }));
 }
 protected override void AdditionalMenuItems()
 {
     Add(new MenuSeparator());
     Add(new MenuItemButton(() => BGBinaryResources.BGSelectionRemove123, "Remove this point from selection",
                            () =>
     {
         EditorSelection.Clear();
         EditorUtility.SetDirty(Overlay.Editor.Curve);
     }));
 }
        public void element_selection_matches()
        {
            var accessor1 = ReflectionHelper.GetAccessor<GridDefinitionTester.GridDefTarget>(x => x.Name);
            var accessor2 = ReflectionHelper.GetAccessor<GridDefinitionTester.GridDefTarget>(x => x.IsCool);

            var selection = new EditorSelection(a => a.Name == "Name", SlickGridEditor.Underscore);

            selection.Matches(accessor1).ShouldBeTrue();
            selection.Matches(accessor2).ShouldBeFalse();
        }
예제 #11
0
        private void DeleteSelection()
        {
            WDOMNode[] objs_to_destroy = EditorSelection.SelectedObjects.ToArray();

            foreach (var obj in objs_to_destroy)
            {
                obj.Destroy();
            }

            EditorSelection.ClearSelection();
        }
예제 #12
0
        public void Update(WSceneView view)
        {
            UpdateSelectionGizmo(view);

            // If we have a gizmo and we're transforming it, don't check for selection change.
            if (TransformGizmo != null && TransformGizmo.IsTransforming)
            {
                return;
            }
            if (WInput.GetMouseButtonDown(0) && !WInput.GetMouseButton(1))
            {
                FRay mouseRay   = view.ProjectScreenToWorld(WInput.MousePosition);
                var  addedActor = Raycast(mouseRay);

                // Check the behaviour of this click to determine appropriate selection modification behaviour.
                // Click w/o Modifiers = Clear Selection, add result to selection
                // Click /w Ctrl = Toggle Selection State
                // Click /w Shift = Add to Selection
                bool ctrlPressed  = WInput.GetKey(Key.LeftCtrl) || WInput.GetKey(Key.RightCtrl);
                bool shiftPressed = WInput.GetKey(Key.LeftShift) || WInput.GetKey(Key.RightShift);

                if (!ctrlPressed & !shiftPressed)
                {
                    EditorSelection.ClearSelection();
                    if (addedActor != null)
                    {
                        EditorSelection.AddToSelection(addedActor);
                    }
                }
                else if (addedActor != null && (ctrlPressed && !shiftPressed))
                {
                    if (addedActor.IsSelected)
                    {
                        EditorSelection.RemoveFromSelection(addedActor);
                    }
                    else
                    {
                        EditorSelection.AddToSelection(addedActor);
                    }
                }
                else if (addedActor != null && shiftPressed)
                {
                    if (!EditorSelection.SelectedObjects.Contains(addedActor))
                    {
                        EditorSelection.AddToSelection(addedActor);
                    }
                }

                UpdateGizmoTransform();
            }

            // Add our gizmo to the renderer this frame.
            ((IRenderable)TransformGizmo).AddToRenderer(view);
        }
예제 #13
0
        private void UserControl_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
        {
            if (!bindingInitialized && this.IsVisible)
            {
                Binding binding = new Binding("AvailableEditors");
                binding.RelativeSource        = new RelativeSource(RelativeSourceMode.FindAncestor, typeof(MainWindow), 1);
                binding.NotifyOnTargetUpdated = true;
                EditorSelection.SetBinding(ItemsControl.ItemsSourceProperty, binding);

                bindingInitialized = true;
            }
        }
예제 #14
0
        private void AddTriangleToSelection(IEnumerable <CollisionTriangle> tris)
        {
            foreach (CollisionTriangle t in tris)
            {
                t.Select();
            }

            EditorSelection.AddToSelection(tris);
            EditorSelection.SelectedObjects[0].Properties.PropertyChanged += OnTriPropertyChanged;

            OnSelectionChanged();
        }
예제 #15
0
        private void AddTriangleToSelection(CollisionTriangle tri)
        {
            tri.Select();
            int prev_count = EditorSelection.SelectedObjects.Count;

            EditorSelection.AddToSelection(tri);

            if (prev_count == 1)
            {
                EditorSelection.SelectedObjects[0].Properties.PropertyChanged += OnTriPropertyChanged;
            }

            OnSelectionChanged();
        }
예제 #16
0
        public void ClearSelection()
        {
            foreach (CollisionTriangle t in EditorSelection.SelectedObjects)
            {
                t.Deselect();
            }

            if (EditorSelection.SelectedObjects.Count > 1)
            {
                EditorSelection.SelectedObjects[0].Properties.PropertyChanged -= OnTriPropertyChanged;
            }

            EditorSelection.ClearSelection();

            OnSelectionChanged();
        }
예제 #17
0
        private void SelectAll()
        {
            List <WDOMNode> actorsToSelect = new List <WDOMNode>();

            foreach (var scene in World.Map.SceneList)
            {
                var allActorsInScene = scene.GetChildrenOfType <VisibleDOMNode>();

                foreach (VisibleDOMNode actorNode in allActorsInScene)
                {
                    actorNode.IsSelected = true;
                    actorsToSelect.Add(actorNode);
                }
            }
            EditorSelection.AddToSelection(actorsToSelect);
        }
예제 #18
0
        public override void OnInspectorGUI()
        {
            EditorSelection myTarget = (EditorSelection)target;

            base.OnInspectorGUI();
            if (GUILayout.Button("Select StoneStuff"))
            {
                Selection.objects = myTarget.GetComponentsInChildren <CustomStones>().Select(item => item.gameObject).ToArray();
            }
            if (GUILayout.Button("Select Stones"))
            {
                Transform[]      stonesStuff = myTarget.GetComponentsInDirectChildren <CustomStones>().Select(item => item.transform).ToArray();
                List <Transform> stones      = new List <Transform>();
                foreach (var item in stonesStuff)
                {
                    stones.Add(item.GetComponentInDirectChildren <Transform>());
                }
                Selection.objects = stones.ToArray().Select(item => item.gameObject).ToArray();
            }
        }
예제 #19
0
        public void EditorSelectionTest()
        {
            var foo = new EditorSelection(new Position(1, 1),
                                          new Range
            {
                Start = new Position(2, 2),
                End   = new Position(3, 3)
            });

            var json   = foo.ToJson();
            var result = json.FromJson <EditorSelection>();

            Assert.AreEqual(1, result.Cursor.Line);
            Assert.AreEqual(1, result.Cursor.Character);

            Assert.AreEqual(2, result.Start.Line);
            Assert.AreEqual(2, result.Start.Character);

            Assert.AreEqual(3, result.End.Line);
            Assert.AreEqual(3, result.End.Character);
        }
예제 #20
0
        private void DeleteSelection()
        {
            WDOMNode[] entitiesToDelete;
            if (EditorSelection.SingleObjectSelected && (EditorSelection.PrimarySelectedObject is WDOMGroupNode || EditorSelection.PrimarySelectedObject is WDOMLayeredGroupNode))
            {
                // If a group and nothing else is selected, delete all children in the group.
                entitiesToDelete = EditorSelection.PrimarySelectedObject.GetChildrenOfType <SerializableDOMNode>().ToArray();
            }
            else
            {
                // Otherwise delete all selected entities.
                entitiesToDelete = EditorSelection.SelectedObjects.Where(x => x is SerializableDOMNode).ToArray();
            }

            World.UndoStack.BeginMacro($"Delete entities");
            var undoAction = new WDeleteEntitiesAction(entitiesToDelete);

            BroadcastUndoEventGenerated(undoAction);
            EditorSelection.ClearSelection();
            World.UndoStack.EndMacro();
        }
 public override void On(Vector3 position)
 {
     addToSelectionItem.Disabled      = EditorSelection.Contains(point);
     removeFromSelectionItem.Disabled = !addToSelectionItem.Disabled;
     base.On(position);
 }
예제 #22
0
        public void CreateEntity(string fourccStr)
        {
            if (fourccStr == null && !EditorSelection.SingleObjectSelected)
            {
                return;
            }

            SerializableDOMNode newNode         = null;
            WDOMNode            parentNode      = null;
            WDOMNode            selected        = EditorSelection.PrimarySelectedObject;
            WDOMNode            previousSibling = null;

            if (fourccStr != null)
            {
                // Creating an entity via the top menu.
                FourCC fourcc = FourCCConversion.GetEnumFromString(fourccStr);
                if (fourcc == FourCC.ACTR || fourcc == FourCC.SCOB || fourcc == FourCC.TRES)
                {
                    parentNode = World.Map.FocusedScene.GetChildrenOfType <WDOMLayeredGroupNode>().Find(x => x.FourCC == fourcc);
                }
                else
                {
                    parentNode = World.Map.FocusedScene.GetChildrenOfType <WDOMGroupNode>().Find(x => x.FourCC == fourcc);
                }
            }
            else if (selected is SerializableDOMNode)
            {
                // Creating an entity with an existing entity selected.
                parentNode      = selected.Parent;
                previousSibling = selected;
            }
            else
            {
                // Creating an entity with a group node selected.
                parentNode = selected;
            }

            if (parentNode is WDOMLayeredGroupNode)
            {
                WDOMLayeredGroupNode lyrNode = parentNode as WDOMLayeredGroupNode;
                Type   actorType             = null;
                string actorName             = null;

                if (lyrNode.FourCC.ToString().StartsWith("TRE"))
                {
                    // Only allow treasure chests in TRES.
                    actorName = "takara";
                    actorType = WResourceManager.GetTypeByName(actorName);
                }
                else
                {
                    WActorCreatorWindow actorCreator = new WActorCreatorWindow();

                    if (actorCreator.ShowDialog() == true && actorCreator.Descriptor != null)
                    {
                        actorName = actorCreator.Descriptor.ActorName;
                        if (actorName == "")
                        {
                            return;
                        }

                        actorType = WResourceManager.GetTypeByName(actorName);
                    }
                }

                if (actorType == null || actorType == typeof(Actor))
                {
                    return;
                }

                string   unlayedFourCC = lyrNode.FourCC.ToString();
                MapLayer layer         = ChunkHeader.FourCCToLayer(ref unlayedFourCC);
                FourCC   fourcc        = FourCCConversion.GetEnumFromString(unlayedFourCC);

                newNode = (SerializableDOMNode)Activator.CreateInstance(actorType, fourcc, World);
                newNode.SetParent(lyrNode);
                newNode.Name  = actorName;
                newNode.Layer = layer;
                newNode.PostLoad();
            }
            else if (parentNode is WDOMGroupNode)
            {
                WDOMGroupNode grpNode = parentNode as WDOMGroupNode;

                if (grpNode.FourCC == FourCC.ACTR || grpNode.FourCC == FourCC.SCOB || grpNode.FourCC == FourCC.TRES)
                {
                    return;
                }

                if (grpNode.FourCC == FourCC.TGDR || grpNode.FourCC == FourCC.TGSC || grpNode.FourCC == FourCC.TGOB)
                {
                    WActorCreatorWindow actorCreator = new WActorCreatorWindow();

                    if (actorCreator.ShowDialog() == true && actorCreator.Descriptor != null)
                    {
                        string actorName = actorCreator.Descriptor.ActorName;
                        if (actorName == "")
                        {
                            return;
                        }

                        Type actorType = WResourceManager.GetTypeByName(actorName);
                        if (actorType == typeof(Actor))
                        {
                            return;
                        }

                        newNode = (SerializableDOMNode)Activator.CreateInstance(actorType, grpNode.FourCC, World);
                        newNode.SetParent(grpNode);
                        newNode.Name = actorName;
                        newNode.PostLoad();
                    }
                }
                else
                {
                    Type newObjType = FourCCConversion.GetTypeFromEnum(grpNode.FourCC);
                    newNode = (SerializableDOMNode)Activator.CreateInstance(newObjType, grpNode.FourCC, World);
                    newNode.SetParent(grpNode);
                    newNode.Name = "New";
                    newNode.PostLoad();
                }
            }
            else
            {
                return;
            }

            if (newNode == null)
            {
                return;
            }

            newNode.Transform.Position = GetNewEntityPositionFromCamera();
            newNode.PopulateDefaultProperties();

            WDOMNode[] entitiesToCreate = { newNode };
            WDOMNode[] parents          = { newNode.Parent };
            WDOMNode[] previousSiblings = { previousSibling };

            newNode.Parent.IsExpanded = true;

            World.UndoStack.BeginMacro($"Create {newNode.Name}");
            var undoAction = new WCreateEntitiesAction(entitiesToCreate, parents, previousSiblings);

            BroadcastUndoEventGenerated(undoAction);
            EditorSelection.ClearSelection();
            EditorSelection.AddToSelection(newNode);
            World.UndoStack.EndMacro();

            OnSelectionChanged(); // Update the right sidebar to show the new entity's properties
        }
예제 #23
0
        private void PasteSelection()
        {
            WDOMNode selected = EditorSelection.PrimarySelectedObject;
            WDOMNode parent;

            if (selected is SerializableDOMNode)
            {
                parent = selected.Parent;
            }
            else if (selected is WDOMLayeredGroupNode)
            {
                parent = selected;
            }
            else if (selected is WDOMGroupNode)
            {
                parent = selected;
            }
            else
            {
                return;
            }

            JsonSerializer serial = new JsonSerializer();

            serial.Converters.Add(new StringEnumConverter());
            serial.Converters.Add(new Vector2Converter());
            serial.Converters.Add(new Vector3Converter());
            serial.Converters.Add(new QuaternionConverter());
            serial.Converters.Add(new WDOMNodeJsonConverter(World, parent));
            serial.Formatting = Formatting.Indented;

            List <SerializableDOMNode> pastedEntities;

            try
            {
                string         text   = Clipboard.GetText();
                StringReader   sr     = new StringReader(text);
                JsonTextReader reader = new JsonTextReader(sr);
                pastedEntities = serial.Deserialize <List <SerializableDOMNode> >(reader);
            } catch (Exception e)
            {
                string error = "Failed to paste entities from the clipboard.\n\nFull error:\n";
                error += e.GetType().FullName + "\n";
                error += e.Message + "\n";
                error += e.StackTrace;
                System.Windows.Forms.MessageBox.Show(
                    error,
                    "Failed to paste entities",
                    System.Windows.Forms.MessageBoxButtons.OK,
                    System.Windows.Forms.MessageBoxIcon.Error
                    );
                return;
            }

            pastedEntities = pastedEntities.Where(x => x != null).ToList(); // Remove entities that failed to convert
            if (pastedEntities.Count > 0)
            {
                WDOMNode[] entitiesToPaste = pastedEntities.ToArray();
                WDOMNode[] parents         = new WDOMNode[entitiesToPaste.Length];
                for (int i = 0; i < entitiesToPaste.Length; i++)
                {
                    parents[i] = entitiesToPaste[i].Parent;
                }

                World.UndoStack.BeginMacro($"Paste {pastedEntities.Count} entities");
                var undoAction = new WCreateEntitiesAction(entitiesToPaste, parents);
                BroadcastUndoEventGenerated(undoAction);
                EditorSelection.ClearSelection();
                EditorSelection.AddToSelection(pastedEntities);
                World.UndoStack.EndMacro();

                OnSelectionChanged(); // Update the right sidebar to show the new entity's properties
            }
            foreach (SerializableDOMNode node in pastedEntities)
            {
                node.IsSelected = true;
            }
        }
예제 #24
0
 public void SelectAll()
 {
     EditorSelection.AddToSelection(ActiveCollisionMesh.Triangles);
 }
예제 #25
0
 protected override void SetControl(BGCurvePoint.ControlTypeEnum type)
 {
     EditorSelection.SetControlTypeForSelected(type);
 }
예제 #26
0
 protected override void Delete()
 {
     EditorSelection.DeleteSelected();
 }
예제 #27
0
        public void CreateEntity(string fourccStr)
        {
            if (fourccStr == null && !EditorSelection.SingleObjectSelected)
            {
                return;
            }

            SerializableDOMNode newNode         = null;
            WDOMNode            parentNode      = null;
            WDOMNode            selected        = EditorSelection.PrimarySelectedObject;
            WDOMNode            previousSibling = null;

            if (fourccStr != null)
            {
                // Creating an entity via the top menu.
                FourCC fourcc = FourCCConversion.GetEnumFromString(fourccStr);
                if (fourcc == FourCC.ACTR || fourcc == FourCC.SCOB || fourcc == FourCC.TRES)
                {
                    parentNode = World.Map.FocusedScene.GetChildrenOfType <WDOMLayeredGroupNode>().Find(x => x.FourCC == fourcc);
                }
                else if (fourcc == FourCC.PLYR)
                {
                    WScene targetScene;
                    WScene stage = World.Map.SceneList.First(x => x is WStage);
                    var    rooms = World.Map.SceneList.Where(x => x is WRoom);
                    if (stage.GetChildrenOfType <SpawnPoint>().Count > 0)
                    {
                        // If the stage file has any spawns, then room spawns will not work. So always add to the stage in this case.
                        targetScene = stage;
                    }
                    else if (rooms.Any(x => x.GetChildrenOfType <SpawnPoint>().Count > 0))
                    {
                        // If the stage has no spawns but at least one of the rooms does, we want to add the new spawn to a room.
                        // Otherwise, if we added it to the stage, it would break all existing room spawns.
                        if (World.Map.FocusedScene is WRoom)
                        {
                            targetScene = World.Map.FocusedScene;
                        }
                        else
                        {
                            targetScene = rooms.First();
                        }
                    }
                    else
                    {
                        // Otherwise there must not be any spawns in the map yet, so just put it in the scene the player has selected.
                        targetScene = World.Map.FocusedScene;
                    }
                    parentNode = targetScene.GetChildrenOfType <WDOMGroupNode>().Find(x => x.FourCC == fourcc);
                }
                else
                {
                    parentNode = World.Map.FocusedScene.GetChildrenOfType <WDOMGroupNode>().Find(x => x.FourCC == fourcc);
                }
            }
            else if (selected is SerializableDOMNode)
            {
                // Creating an entity with an existing entity selected.
                parentNode      = selected.Parent;
                previousSibling = selected;
            }
            else
            {
                // Creating an entity with a group node selected.
                parentNode = selected;
            }

            if (parentNode is WDOMLayeredGroupNode)
            {
                WDOMLayeredGroupNode lyrNode = parentNode as WDOMLayeredGroupNode;
                Type   actorType             = null;
                string actorName             = null;

                if (lyrNode.FourCC.ToString().StartsWith("TRE"))
                {
                    // Only allow treasure chests in TRES.
                    actorName = "takara";
                    actorType = WResourceManager.GetTypeByName(actorName);
                }
                else
                {
                    WActorCreatorWindow actorCreator = new WActorCreatorWindow();

                    if (actorCreator.ShowDialog() == true && actorCreator.Descriptor != null)
                    {
                        actorName = actorCreator.Descriptor.ActorName;
                        if (actorName == "")
                        {
                            return;
                        }

                        actorType = WResourceManager.GetTypeByName(actorName);
                    }
                }

                if (actorType == null || actorType == typeof(Actor))
                {
                    return;
                }

                string   unlayedFourCC = lyrNode.FourCC.ToString();
                MapLayer layer         = ChunkHeader.FourCCToLayer(ref unlayedFourCC);
                FourCC   fourcc        = FourCCConversion.GetEnumFromString(unlayedFourCC);

                newNode = (SerializableDOMNode)Activator.CreateInstance(actorType, fourcc, World);
                newNode.SetParent(lyrNode);
                newNode.Name  = actorName;
                newNode.Layer = layer;
                newNode.PostLoad();
            }
            else if (parentNode is WDOMGroupNode)
            {
                WDOMGroupNode grpNode = parentNode as WDOMGroupNode;

                if (grpNode.FourCC == FourCC.ACTR || grpNode.FourCC == FourCC.SCOB || grpNode.FourCC == FourCC.TRES)
                {
                    return;
                }

                if (grpNode.FourCC == FourCC.TGDR || grpNode.FourCC == FourCC.TGSC || grpNode.FourCC == FourCC.TGOB)
                {
                    WActorCreatorWindow actorCreator = new WActorCreatorWindow();

                    if (actorCreator.ShowDialog() == true && actorCreator.Descriptor != null)
                    {
                        string actorName = actorCreator.Descriptor.ActorName;
                        if (actorName == "")
                        {
                            return;
                        }

                        Type actorType = WResourceManager.GetTypeByName(actorName);
                        if (actorType == typeof(Actor))
                        {
                            return;
                        }

                        newNode = (SerializableDOMNode)Activator.CreateInstance(actorType, grpNode.FourCC, World);
                        newNode.SetParent(grpNode);
                        newNode.Name = actorName;
                        newNode.PostLoad();
                    }
                }
                else if (grpNode.FourCC == FourCC.RTBL)
                {
                    RoomTableEntryNode rtbl_entry = new RoomTableEntryNode(grpNode.FourCC, World);
                    rtbl_entry.Index = grpNode.Count();
                    newNode          = rtbl_entry;
                    newNode.SetParent(grpNode);
                    newNode.PostLoad();
                }
                else
                {
                    Type newObjType = FourCCConversion.GetTypeFromEnum(grpNode.FourCC);
                    newNode = (SerializableDOMNode)Activator.CreateInstance(newObjType, grpNode.FourCC, World);
                    newNode.SetParent(grpNode);
                    newNode.Name = "New";
                    newNode.PostLoad();
                }
            }
            else
            {
                return;
            }

            if (newNode == null)
            {
                return;
            }

            newNode.Transform.Position = GetNewEntityPositionFromCamera();
            newNode.PopulateDefaultProperties();

            WDOMNode[] entitiesToCreate = { newNode };
            WDOMNode[] parents          = { newNode.Parent };
            WDOMNode[] previousSiblings = { previousSibling };

            newNode.Parent.IsExpanded = true;

            World.UndoStack.BeginMacro($"Create {newNode.Name}");
            var undoAction = new WCreateEntitiesAction(entitiesToCreate, parents, previousSiblings);

            BroadcastUndoEventGenerated(undoAction);
            EditorSelection.ClearSelection();
            EditorSelection.AddToSelection(newNode);
            World.UndoStack.EndMacro();

            World.Map.FocusedScene = parentNode.Scene; // Focus the scene the new entity was added to (in case it's not the already focused scene).

            OnSelectionChanged();                      // Update the right sidebar to show the new entity's properties
        }
예제 #28
0
        public void Update(WSceneView view)
        {
            m_View = view;
            UpdateSelectionGizmo(view);

            // Add our gizmo to the renderer this frame.
            if (TransformGizmo != null)
            {
                ((IRenderable)TransformGizmo).AddToRenderer(view);
            }

            // If we have a gizmo and we're transforming it, don't check for selection change.
            if (TransformGizmo != null && TransformGizmo.IsTransforming)
            {
                return;
            }
            if (WInput.GetMouseButtonDown(0) && !WInput.GetMouseButton(1) && !m_bOverrideSceneCamera)
            {
                FRay           mouseRay = view.ProjectScreenToWorld(WInput.MousePosition);
                BindingVector3 addedVec = Raycast(mouseRay, view.ViewCamera);

                // Check the behaviour of this click to determine appropriate selection modification behaviour.
                // Click w/o Modifiers = Clear Selection, add result to selection
                // Click /w Ctrl = Toggle Selection State
                // Click /w Shift = Add to Selection
                bool ctrlPressed  = WInput.GetKey(Key.LeftCtrl) || WInput.GetKey(Key.RightCtrl);
                bool shiftPressed = WInput.GetKey(Key.LeftShift) || WInput.GetKey(Key.RightShift);

                // Replace the previous selection with the current selection, if it's valid.
                if (!ctrlPressed & !shiftPressed)
                {
                    EditorSelection.ClearSelection();

                    if (addedVec != null)
                    {
                        EditorSelection.AddToSelection(addedVec);
                    }
                }
                else if (addedVec != null && (ctrlPressed && !shiftPressed))
                {
                    if (EditorSelection.SelectedObjects.Contains(addedVec))
                    {
                        EditorSelection.RemoveFromSelection(addedVec);
                    }
                    else
                    {
                        EditorSelection.AddToSelection(addedVec);
                    }
                }
                else if (addedVec != null && shiftPressed)
                {
                    if (!EditorSelection.SelectedObjects.Contains(addedVec))
                    {
                        EditorSelection.AddToSelection(addedVec);
                    }
                }
            }
            if (m_CopyCameraRequest != null)
            {
                m_CopyCameraRequest.RequestingCut.CopySettingsFromCamera(view.ViewCamera, m_CopyCameraRequest.IsStart);
                m_CopyCameraRequest = null;
            }
            if (WInput.GetMouseButton(1) && m_bOverrideSceneCamera)
            {
                RestoreSceneCamera(view);
            }

            UpdateGizmoTransform();
        }
예제 #29
0
        public void CreateEntity()
        {
            if (!EditorSelection.SingleObjectSelected)
            {
                return;
            }

            WDOMNode            selected = EditorSelection.PrimarySelectedObject;
            SerializableDOMNode newNode  = null;

            if (selected is SerializableDOMNode)
            {
                SerializableDOMNode origNode = selected as SerializableDOMNode;
                Type selType = selected.GetType();
                newNode = (SerializableDOMNode)Activator.CreateInstance(selType, origNode.FourCC, m_world);
                newNode.PostLoad();
                newNode.SetParent(selected.Parent);

                if (origNode.Parent is WDOMLayeredGroupNode)
                {
                    newNode.Layer = origNode.Layer;
                }
            }
            else if (selected is WDOMLayeredGroupNode)
            {
                WDOMLayeredGroupNode lyrNode = selected as WDOMLayeredGroupNode;
                Type newObjType = null;

                if (lyrNode.FourCC >= FourCC.ACTR && lyrNode.FourCC <= FourCC.ACTb)
                {
                    newObjType = typeof(Actor);
                }
                else if (lyrNode.FourCC >= FourCC.SCOB && lyrNode.FourCC <= FourCC.SCOb)
                {
                    newObjType = typeof(ScaleableObject);
                }
                else if (lyrNode.FourCC >= FourCC.TRES && lyrNode.FourCC <= FourCC.TREb)
                {
                    newObjType = typeof(TreasureChest);
                }

                string   unlayedFourCC = lyrNode.FourCC.ToString();
                MapLayer layer         = ChunkHeader.FourCCToLayer(ref unlayedFourCC);
                FourCC   enumVal       = FourCCConversion.GetEnumFromString(unlayedFourCC);

                newNode       = (SerializableDOMNode)Activator.CreateInstance(newObjType, enumVal, m_world);
                newNode.Layer = layer;
                newNode.PostLoad();
                newNode.SetParent(lyrNode);
            }
            else if (selected is WDOMGroupNode)
            {
                WDOMGroupNode grpNode = selected as WDOMGroupNode;

                if (grpNode.FourCC == FourCC.ACTR || grpNode.FourCC == FourCC.SCOB || grpNode.FourCC == FourCC.TRES)
                {
                    return;
                }

                Type newObjType = FourCCConversion.GetTypeFromEnum(grpNode.FourCC);
                newNode = (SerializableDOMNode)Activator.CreateInstance(newObjType, grpNode.FourCC, m_world);
                newNode.PostLoad();
                newNode.SetParent(grpNode);
            }
            else
            {
                return;
            }

            if (newNode != null)
            {
                EditorSelection.ClearSelection();
                EditorSelection.AddToSelection(newNode);
            }

            // ToDo: This can spawn specific classes the same way that the actor loader does.
        }