Exemplo n.º 1
0
        protected Component CreateComponent(TreeNodeAdv baseNode, Type cmpType)
        {
            GameObjectNode baseObjNode = baseNode == null ? null : baseNode.Tag as GameObjectNode;
            GameObject baseObj = baseObjNode == null ? null : baseObjNode.Obj;

            UndoRedoManager.BeginMacro();

            // There is no GameObject? Create one!
            if (baseObj == null)
            {
                baseObj = this.CreateGameObject(baseNode, cmpType.Name);
                baseObjNode = this.FindNode(baseObj);
            }
            // There already is such Component? Return it.
            else
            {
                Component existingComponent = baseObj.GetComponent(cmpType);
                if (existingComponent != null) return existingComponent;
            }

            // Create Components
            CreateComponentAction action = new CreateComponentAction(baseObj, cmpType);
            UndoRedoManager.Do(action);
            UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromFirst);

            return action.Result.LastOrDefault();
        }
Exemplo n.º 2
0
        private void copyHereToolStripMenuItem_Click(object sender, EventArgs e)
        {
            GameObject[] draggedObj = this.tempDropData as GameObject[];
            Component[] draggedComp = this.tempDropData as Component[];
            GameObject dropObj = (this.tempDropTarget is GameObjectNode) ? (this.tempDropTarget as GameObjectNode).Obj : null;

            if (draggedObj != null)
            {
                UndoRedoManager.BeginMacro();
                CloneGameObjectAction cloneAction = new CloneGameObjectAction(draggedObj);
                UndoRedoManager.Do(cloneAction);
                UndoRedoManager.Do(new SetGameObjectParentAction(dropObj, cloneAction.Result));
                UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromFirst);

                // Deselect dragged nodes
                foreach (GameObject dragObj in draggedObj)
                {
                    TreeNodeAdv dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(dragObj)));
                    dragObjViewNode.IsSelected = false;
                }
                // Select new nodes
                foreach (GameObject dragObjClone in cloneAction.Result)
                {
                    TreeNodeAdv dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(dragObjClone)));
                    dragObjViewNode.IsSelected = true;
                    this.objectView.EnsureVisible(dragObjViewNode);
                }
            }
            else if (draggedComp != null)
            {
                // Clone Components
                CreateComponentAction cloneAction = new CreateComponentAction(dropObj, draggedComp.Select(c => c.Clone()));
                UndoRedoManager.Do(cloneAction);

                // Deselect dragged nodes
                foreach (Component dragObj in draggedComp)
                {
                    TreeNodeAdv dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(dragObj)));
                    dragObjViewNode.IsSelected = false;
                }
                // Select new nodes
                foreach (Component dragObjClone in cloneAction.Result)
                {
                    TreeNodeAdv dragObjViewNode = this.objectView.FindNode(this.objectModel.GetPath(this.FindNode(dragObjClone)));
                    dragObjViewNode.IsSelected = true;
                    this.objectView.EnsureVisible(dragObjViewNode);
                }
            }
        }
Exemplo n.º 3
0
        private void objectView_DragDrop(object sender, DragEventArgs e)
        {
            this.objectView.BeginUpdate();

            bool effectMove = (e.Effect & DragDropEffects.Move) != DragDropEffects.None;
            bool effectCopy = (e.Effect & DragDropEffects.Copy) != DragDropEffects.None;
            DataObject data = e.Data as DataObject;
            if (data != null)
            {
                ConvertOperation convertOp = new ConvertOperation(data, ConvertOperation.Operation.All);
                this.tempDropTarget = this.DragDropGetTargetNode();
                if (data.ContainsGameObjectRefs())
                {
                    this.tempDropData = data.GetGameObjectRefs();

                    // Display context menu if both moving and copying are availabled
                    if (effectMove && effectCopy)
                        this.contextMenuDragMoveCopy.Show(this, this.PointToClient(new Point(e.X, e.Y)));
                    else if (effectCopy)
                        this.copyHereToolStripMenuItem_Click(this, null);
                    else if (effectMove)
                        this.moveHereToolStripMenuItem_Click(this, null);
                }
                else if (data.ContainsComponentRefs())
                {
                    this.tempDropData = data.GetComponentRefs();

                    // Display context menu if both moving and copying are availabled
                    if (effectMove && effectCopy)
                        this.contextMenuDragMoveCopy.Show(this, this.PointToClient(new Point(e.X, e.Y)));
                    else if (effectCopy)
                        this.copyHereToolStripMenuItem_Click(this, null);
                    else if (effectMove)
                        this.moveHereToolStripMenuItem_Click(this, null);
                }
                else if (this.tempDropTarget != null && convertOp.CanPerform<Component>())
                {
                    GameObject dropObj = null;
                    if (this.tempDropTarget is GameObjectNode)
                        dropObj = (this.tempDropTarget as GameObjectNode).Obj;
                    else
                        dropObj = (this.tempDropTarget as ComponentNode).Component.GameObj;

                    var componentQuery = convertOp.Perform<Component>();
                    if (componentQuery != null)
                    {
                        // Create Components
                        CreateComponentAction createAction = new CreateComponentAction(dropObj, componentQuery.Where(c => c.GameObj == null));
                        UndoRedoManager.BeginMacro();
                        UndoRedoManager.Do(new DeleteComponentAction(componentQuery.Select(c => dropObj.GetComponent(c.GetType())).NotNull()));
                        UndoRedoManager.Do(createAction);
                        UndoRedoManager.EndMacro(UndoRedoManager.MacroDeriveName.FromLast);

                        bool selCleared = false;
                        foreach (Component newComponent in createAction.Result)
                        {
                            NodeBase dataNode = this.FindNode(newComponent);
                            if (dataNode == null) continue;
                            TreeNodeAdv viewNode = this.objectView.FindNode(this.objectModel.GetPath(dataNode));
                            if (viewNode == null) continue;
                            if (!selCleared)
                            {
                                this.objectView.ClearSelection();
                                selCleared = true;
                            }
                            viewNode.IsSelected = true;
                            this.objectView.EnsureVisible(viewNode);
                        }
                    }
                }
                else if (convertOp.CanPerform<GameObject>())
                {
                    GameObject dropObj = (this.tempDropTarget is GameObjectNode) ? (this.tempDropTarget as GameObjectNode).Obj : null;
                    var gameObjQuery = convertOp.Perform<GameObject>();
                    if (gameObjQuery != null)
                    {
                        CreateGameObjectAction action = new CreateGameObjectAction(dropObj, gameObjQuery);
                        UndoRedoManager.Do(action);

                        bool selCleared = false;
                        foreach (GameObject newObj in action.Result)
                        {
                            NodeBase dataNode = this.FindNode(newObj);
                            if (dataNode == null) continue;
                            TreeNodeAdv viewNode = this.objectView.FindNode(this.objectModel.GetPath(dataNode));
                            if (viewNode == null) continue;
                            if (!selCleared)
                            {
                                this.objectView.ClearSelection();
                                selCleared = true;
                            }
                            viewNode.IsSelected = true;
                            this.objectView.EnsureVisible(viewNode);
                        }
                    }
                }
            }

            this.objectView.EndUpdate();
        }