Ejemplo n.º 1
0
        /// <summary>
        /// Creates a new NodeTag and an instance of the node for the defaults.
        /// </summary>
        /// <param name="type">The type of the node in the node explorer.</param>
        /// <param name="nodetype">The type of the node which will be added to the behaviour tree.</param>
        /// <param name="filename">The filename of the behaviour we want to load. Use string.Empty if the node is not a behaviour.</param>
        public NodeTag(NodeTagType type, Type nodetype, string filename)
        {
            if ((type == NodeTagType.BehaviorFolder || type == NodeTagType.NodeFolder) && nodetype != null)
            {
                throw new Exception(Resources.ExceptionWrongNodeTagType);
            }

            _type     = type;
            _nodetype = nodetype;
            _filename = filename;

            if (nodetype == null)
            {
                _defaults = null;
            }
            else
            {
                //if(!nodetype.IsSubclassOf(typeof(DefaultObject)))
                //	throw new Exception(Resources.ExceptionNotImplementDefaultObject);

                if (nodetype.IsSubclassOf(typeof(Events.Event)) && type != NodeTagType.Event)
                {
                    throw new Exception(Resources.ExceptionWrongNodeTagType);
                }

                if (nodetype.IsSubclassOf(typeof(Nodes.Node)) && type != NodeTagType.Node && type != NodeTagType.Behavior)
                {
                    throw new Exception(Resources.ExceptionWrongNodeTagType);
                }

                _defaults = type == NodeTagType.Event ? (DefaultObject)Brainiac.Design.Events.Event.Create(nodetype, null) : (DefaultObject)Nodes.Node.Create(nodetype);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Adds this NodeGroup to the TreeView of the node explorer.
        /// </summary>
        /// <param name="pool">The TreeNodeCollection the group and its sub-groups and childrens will be added.</param>
        public void Register(TreeNodeCollection pool)
        {
            // check if this NodeGroup already exists in the node explorer
            TreeNode tnode = null;

            foreach (TreeNode node in pool)
            {
                if (node.Text == _name)
                {
                    tnode = node;
                    break;
                }
            }

            // create a new group if it does not yet exist
            if (tnode == null)
            {
                tnode     = new TreeNode(_name, (int)_icon, (int)_icon);
                tnode.Tag = new NodeTag(NodeTagType.NodeFolder, null, string.Empty);
                pool.Add(tnode);
            }

            // add the nodes which will be shown in this group
            foreach (Type item in _items)
            {
                NodeTagType ntt = NodeTagType.Node;

                if (item.IsSubclassOf(typeof(Attachments.Attachment)))
                {
                    ntt = NodeTagType.Attachment;
                }

                NodeTag nodetag = new NodeTag(ntt, item, string.Empty);

                TreeNode inode = new TreeNode(nodetag.Defaults.Label, (int)_icon, (int)_icon);
                inode.Tag         = nodetag;
                inode.ToolTipText = nodetag.Defaults.Description;

                tnode.Nodes.Add(inode);
            }

            // add any sub-group
            foreach (NodeGroup group in _children)
            {
                group.Register(tnode.Nodes);
            }
        }
        /// <summary>
        /// Adds all tree nodes in the pool and its children of a specific type to a list.
        /// </summary>
        /// <param name="pool">The pool you want to search.</param>
        /// <param name="list">The list the tree nodes are added to.</param>
        /// <param name="type">The type of nodes you want to get.</param>
        private void AddChildNodes(TreeNodeCollection pool, List<TreeNode> list, NodeTagType type)
        {
            foreach(TreeNode node in pool)
            {
                if(((NodeTag)node.Tag).Type ==type)
                    list.Add(node);

                AddChildNodes(node.Nodes, list, type);
            }
        }
Ejemplo n.º 4
0
        private TreeNode getNodeGroup(TreeNodeCollection list, string name, string root, NodeTagType nodeTagType)
        {
            // search for an existing behavior group
            foreach (TreeNode node in list)
                if (node.Text == name)
                    return node;

            // create a new group
            TreeNode newnode = new TreeNode(name, (int)NodeIcon.FolderClosed, (int)NodeIcon.FolderClosed);
            newnode.Tag = new NodeTag(nodeTagType, null, root);
            list.Add(newnode);

            return newnode;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Creates a new NodeTag and an instance of the node for the defaults.
        /// </summary>
        /// <param name="type">The type of the node in the node explorer.</param>
        /// <param name="nodetype">The type of the node which will be added to the behaviour tree.</param>
        /// <param name="filename">The filename of the behaviour we want to load. Use string.Empty if the node is not a behaviour.</param>
        public NodeTag(NodeTagType type, Type nodetype, string filename)
        {
            if((type ==NodeTagType.BehaviorFolder || type ==NodeTagType.NodeFolder) && nodetype !=null)
                throw new Exception(Resources.ExceptionWrongNodeTagType);

            _type= type;
            _nodetype= nodetype;
            _filename= filename;

            if(nodetype ==null)
            {
                _defaults= null;
            }
            else
            {
                //if(!nodetype.IsSubclassOf(typeof(DefaultObject)))
                //	throw new Exception(Resources.ExceptionNotImplementDefaultObject);

                if(nodetype.IsSubclassOf(typeof(Events.Event)) && type !=NodeTagType.Event)
                    throw new Exception(Resources.ExceptionWrongNodeTagType);

                if(nodetype.IsSubclassOf(typeof(Nodes.Node)) && type !=NodeTagType.Node && type !=NodeTagType.Behavior)
                    throw new Exception(Resources.ExceptionWrongNodeTagType);

                _defaults=type ==NodeTagType.Event ? (DefaultObject)Brainiac.Design.Events.Event.Create(nodetype, null) : (DefaultObject)Nodes.Node.Create(nodetype);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Creates a new NodeTag and an instance of the node for the defaults.
        /// </summary>
        /// <param name="type">The type of the node in the node explorer.</param>
        /// <param name="nodetype">The type of the node which will be added to the behaviour tree.</param>
        /// <param name="filename">The filename of the behaviour we want to load. Use string.Empty if the node is not a behaviour.</param>
        public NodeTag(NodeTagType type, Type nodetype, string filename)
        {
            if ((type == NodeTagType.BehaviorFolder || type == NodeTagType.PrefabFolder || type == NodeTagType.NodeFolder) && nodetype != null)
            { throw new Exception(Resources.ExceptionWrongNodeTagType); }

            _type = type;
            _nodetype = nodetype;

            if (nodetype == null) {
                _defaults = null;

            } else {
                //if(!nodetype.IsSubclassOf(typeof(DefaultObject)))
                //	throw new Exception(Resources.ExceptionNotImplementDefaultObject);

                if (nodetype.IsSubclassOf(typeof(Attachments.Attachment)) && type != NodeTagType.Attachment)
                { throw new Exception(Resources.ExceptionWrongNodeTagType); }

                if (nodetype.IsSubclassOf(typeof(Nodes.Node)) && type != NodeTagType.Node && type != NodeTagType.Behavior && type != NodeTagType.Prefab)
                { throw new Exception(Resources.ExceptionWrongNodeTagType); }

                switch (type) {
                    case NodeTagType.Attachment:
                        _defaults = (DefaultObject)Behaviac.Design.Attachments.Attachment.Create(nodetype, null);
                        break;

                    default:
                        _defaults = (DefaultObject)Nodes.Node.Create(nodetype);
                        break;
                }
            }

            Filename = filename;
        }