コード例 #1
0
        protected override bool CanBeAdoptedBy(BaseNode parent)
        {
            if (base.CanBeAdoptedBy(parent))
            {
                // check if there is a Method node on the parent path
                while (parent != null)
                {
                    if (parent is Nodes.Method)
                        return true;

                    parent = parent.Parent;
                }

                parent = this.Parent;
                while (parent != null)
                {
                    if (parent is Nodes.Method)
                        return true;

                    parent = parent.Parent;
                }
            }

            return false;
        }
コード例 #2
0
 /// <summary>
 /// Creates a new subitem used to visualise a connected child on the node.
 /// </summary>
 /// <param name="connector">The connector we want to visualise.</param>
 /// <param name="child">The child represented by the subitem. Can be null.</param>
 /// <param name="index">The index of the child in the connector. Also a null child has an index!</param>
 public SubItemConnector(Connector connector, BaseNode child, int index)
     : base(null, null, __font, Brushes.White, Alignment.Right, true)
 {
     _connector = connector;
     _child = child;
     _index = index;
 }
コード例 #3
0
            public override bool AddChild(BaseNode node) {
                // check if we we may add the node
                if (_children.Count >= _maxCount || _isReadOnly)
                { return false; }

                node._parentConnector = this;
                _children.Add(node);
                _connectedChildren.RequiresRebuild();

                if (node is NodeViewData)
                { AddSubItem(node); }

                return true;
            }
コード例 #4
0
            public override bool AddChild(BaseNode node) {
                // check if we can accept the node
                if (_child == null && !_isReadOnly) {
                    node._parentConnector = this;
                    _child = node;
                    _connectedChildren.RequiresRebuild();

                    if (node is NodeViewData)
                    { AddSubItem(node); }

                    return true;
                }

                return false;
            }
コード例 #5
0
ファイル: Method.cs プロジェクト: 675492062/behaviac
        public override bool CanAdopt(BaseNode child)
        {
            if (base.CanAdopt(child))
            {
                return child is Sequence ||
                    child is Selector ||
                    child is Parallel ||
                    child is DecoratorLoop ||
                    child is Action ||
                    child is DecoratorIterator || 
                    child is Behaviac.Design.Nodes.ReferencedBehavior ||
                    child is Behaviac.Design.Nodes.Behavior;
            }

            return false;
        }
コード例 #6
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
        /// <summary>
        /// Returns if the given node is the parent of this node and it is its last child.
        /// </summary>
        /// <param name="node">The parent we want to check if this is its last child.</param>
        /// <returns>Returns true if this node is the last child of the given node.</returns>
        public bool IsLastChildOf(BaseNode parent) {
            if (parent == null || parent.Children.Count < 1)
            { return false; }

            return parent.Children[parent.Children.Count - 1] == this;
        }
コード例 #7
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
        /// <summary>
        /// Checks if this node can by adopted by the given one.
        /// </summary>
        /// <param name="parent">The node which can adopt this one.</param>
        /// <returns>Returns true if this node can by adopted by the given parent.</returns>
        protected virtual bool CanBeAdoptedBy(BaseNode parent) {
            if (parent != null) {
                if (this is Behavior)
                    return true;

                if (this.IsFSM)
                    return (parent.IsFSM || parent.Children.Count == 0);
                else
                    return !parent.IsFSM;
            }

            return false;
        }
コード例 #8
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
        /// <summary>
        /// Replace the children of this node from the source node.
        /// </summary>

        public void ReplaceChildren(BaseNode source) {
            _children = source._children;
            foreach(BaseNode child in _children) {
                child._parent = this;
            }

            _fsmNodes = source._fsmNodes;
            foreach(BaseNode child in _fsmNodes) {
                child._parent = this;
            }
        }
コード例 #9
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
        /// <summary>
        /// Returns if any of the node's parents is a given node.
        /// </summary>
        /// <param name="parent">The node we want to check if it is a ancestor of this node.</param>
        /// <returns>Returns true if this node is a descendant of the given node.</returns>
        public bool HasParent(BaseNode parent) {
            if (_parent == null)
            { return false; }

            if (_parent == parent)
            { return true; }

            return _parent.HasParent(parent);
        }
コード例 #10
0
            /// <summary>
            /// Removes a connector subitem for a child.
            /// </summary>
            /// <param name="child">The child whose connector subitem we want to remove.</param>
            protected void RemoveSubItem(BaseNode child)
            {
                if (!(_connectedChildren.Owner is NodeViewData))
                    throw new Exception(Resources.ExceptionIsNotNodeViewData);

                int firstIndex;
                List<NodeViewData.SubItemConnector> subitems = CollectSubItems(out firstIndex);

                // find the connector subitem for this child...
                for (int i = 0; i < subitems.Count; ++i)
                {
                    NodeViewData.SubItemConnector subitem = subitems[i];

                    // when we found it...
                    if (subitem.Child == child)
                    {
                        // remove the subitem
                        ((NodeViewData)_connectedChildren.Owner).RemoveSubItem(subitem);

                        // if we do not fullfil the minimum count, re add it at the end and clear the child
                        if (subitems.Count - 1 < _minCount)
                        {
                            subitem.Child = null;
                            ((NodeViewData)_connectedChildren.Owner).AddSubItem(subitem, firstIndex + subitems.Count - 1);
                        }

                        // update stored indices on connector subitems
                        RebuildSubItemIndices();

                        return;
                    }
                }

                throw new Exception(Resources.ExceptionSubItemIsNoChild);
            }
コード例 #11
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
        public virtual bool AddFSMNode(BaseNode node) {
            if (node != null && node.IsFSM) {
                node._parent = this;
                _fsmNodes.Add(node);
                return true;
            }

            return false;
        }
コード例 #12
0
ファイル: BaseNode.cs プロジェクト: P79N6A/behaviac3.6
 /// <summary>
 /// Gets a connector of the node by a child connected to it.
 /// </summary>
 /// <param name="child">The child of the connector we are looking for.</param>
 /// <returns>Returns null if no connector could be found.</returns>
 public Connector GetConnector(BaseNode child)
 {
     return(_children.GetConnector(child));
 }
コード例 #13
0
 /// <summary>
 /// Checks if a node can be adopted by this one.
 /// </summary>
 /// <param name="child">The node we want to adopt.</param>
 /// <returns>Returns true if this node can adopt the given child.</returns>
 public bool CanAdoptNode(BaseNode child) {
     Connector connector = (child != null && child.ParentConnector != null) ? GetConnector(child.ParentConnector.Identifier) : null;
     return (connector != null) ? connector.AcceptsChild(child) : false;
 }
コード例 #14
0
ファイル: BaseNode.cs プロジェクト: P79N6A/behaviac3.6
 public virtual Attachments.Attachment CreateStartCondition(BaseNode owner)
 {
     return(null);
 }
コード例 #15
0
ファイル: BaseNode.cs プロジェクト: P79N6A/behaviac3.6
 public virtual bool RemoveFSMNode(BaseNode node)
 {
     Debug.Check(node != null && node.IsFSM);
     return(_fsmNodes.Remove(node));
 }
コード例 #16
0
ファイル: Task.cs プロジェクト: yueding/behaviac
 //can only added to the 'Behavior'
 protected override bool CanBeAdoptedBy(BaseNode parent)
 {
     return(base.CanBeAdoptedBy(parent) && (parent is Behavior));
 }
コード例 #17
0
 /// <summary>
 /// Creates a new instance to store all available connectors on an node.
 /// </summary>
 /// <param name="owner">The node this instance belongs to.</param>
 public ConnectedChildren(BaseNode owner)
 {
     _owner = owner;
 }
コード例 #18
0
            /// <summary>
            /// Checks if a node can be adopted by this one.
            /// </summary>
            /// <param name="child">The node we want to adopt.</param>
            /// <returns>Returns true if this node can adopt the given child.</returns>
            public bool CanAdoptNode(BaseNode child)
            {
                Connector connector = (child != null && child.ParentConnector != null) ? GetConnector(child.ParentConnector.Identifier) : null;

                return((connector != null) ? connector.AcceptsChild(child) : false);
            }
コード例 #19
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
        /// <summary>
        /// Checks if the children of a node can be adopted by this one.
        /// </summary>
        /// <param name="node">The node we want to adopt its children.</param>
        /// <returns>Returns true if this node can adopt the children of the given node.</returns>
        public bool CanAdoptChildren(BaseNode node) {
            foreach(Connector connector in node.Connectors) {
                if (connector.ChildCount > 0) {
                    // Get the connector to adapt those children
                    Connector conn = GetConnector(connector.Identifier);

                    // Check if this connector accepts those children
                    if (conn == null || !conn.AcceptsChildren(connector)) {
                        return false;
                    }
                }
            }

            return true;
        }
コード例 #20
0
ファイル: BaseNode.cs プロジェクト: P79N6A/behaviac3.6
 /// <summary>
 /// Checks if a new node can be adopted by this one.
 /// </summary>
 /// <param name="child">The node we want to adopt.</param>
 /// <returns>Returns true if this node can adopt the given child.</returns>
 public virtual bool CanAdopt(BaseNode child)
 {
     return(child != null && child.CanBeAdoptedBy(this));
 }
コード例 #21
0
 public override int GetChildIndex(BaseNode node)
 {
     return(_child == node ? 0 : -1);
 }
コード例 #22
0
ファイル: BaseNode.cs プロジェクト: P79N6A/behaviac3.6
 /// <summary>
 /// Checks if an existing node can be adopted by this one.
 /// </summary>
 /// <param name="child">The node we want to adopt.</param>
 /// <returns>Returns true if this node can adopt the given child.</returns>
 public bool CanAdoptNode(BaseNode child)
 {
     return(CanAdopt(child) && _children.CanAdoptNode(child));
 }
コード例 #23
0
 /// <summary>
 /// Gets the index of a child.
 /// </summary>
 /// <param name="node">The child whose index we want to have.</param>
 /// <returns>Returns -1 if the child could not be found.</returns>
 public abstract int GetChildIndex(BaseNode node);
コード例 #24
0
 public override bool CanAdopt(BaseNode child)
 {
     return(false);
 }
コード例 #25
0
ファイル: StateBase.cs プロジェクト: pjkui/behaviac
 public override Attachment CreateStartCondition(BaseNode owner)
 {
     return Attachment.Create(typeof(PluginBehaviac.Events.StartCondition), owner as Node);
 }
コード例 #26
0
 public override bool AddChild(BaseNode node, int index)
 {
     // we only have one child, the index does not matter to us
     return(AddChild(node));
 }
コード例 #27
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
 public virtual bool RemoveFSMNode(BaseNode node) {
     Debug.Check(node != null && node.IsFSM);
     return _fsmNodes.Remove(node);
 }
コード例 #28
0
 /// <summary>
 /// Adds a child to this connector on a given position.
 /// </summary>
 /// <param name="node">The node we want to add.</param>
 /// <param name="index">The position we want to add the node at.</param>
 /// <returns>Returns false if the connector does not allow any more nodes to be added.</returns>
 public abstract bool AddChild(BaseNode node, int index);
コード例 #29
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
 /// <summary>
 /// Gets a connector of the node by a child connected to it.
 /// </summary>
 /// <param name="child">The child of the connector we are looking for.</param>
 /// <returns>Returns null if no connector could be found.</returns>
 public Connector GetConnector(BaseNode child) {
     return _children.GetConnector(child);
 }
コード例 #30
0
 /// <summary>
 /// Adds a child to this connector.
 /// </summary>
 /// <param name="node">The node we want to add.</param>
 /// <returns>Returns false if the connector does not allow any more nodes to be added.</returns>
 public abstract bool AddChild(BaseNode node);
コード例 #31
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
        /// <summary>
        /// Returns if a given noe is a sibling of this node.
        /// </summary>
        /// <param name="sibling">The assumed sibling we want to check.</param>
        /// <returns>Returns true if the given node is a sibling of this node.</returns>
        public bool IsSibling(BaseNode sibling) {
            if (_parent == null)
            { return false; }

            return _parent.Children.Contains(sibling);
        }
コード例 #32
0
ファイル: BehaviorTreeView.cs プロジェクト: Just4F/behaviac
        private bool AdoptNodeByAncestor(BaseNode target, BaseNode node) {
            if (target != null && target.CanAdopt(node)) {
                target = target.Parent;

                // check if there is a Method node on the parent path
                while (target != null) {
                    if (target is Nodes.Method) {
                        return target.CanAdopt(node);
                    }

                    target = target.Parent;
                }

                return true;
            }

            return false;
        }
コード例 #33
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
 /// <summary>
 /// Checks if a new node can be adopted by this one.
 /// </summary>
 /// <param name="child">The node we want to adopt.</param>
 /// <returns>Returns true if this node can adopt the given child.</returns>
 public virtual bool CanAdopt(BaseNode child) {
     return child != null && child.CanBeAdoptedBy(this);
 }
コード例 #34
0
ファイル: Task.cs プロジェクト: 675492062/behaviac
 //can only added to the 'Behavior'
 protected override bool CanBeAdoptedBy(BaseNode parent) {
     return base.CanBeAdoptedBy(parent) && (parent is Behavior);
 }
コード例 #35
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
 /// <summary>
 /// Checks if an existing node can be adopted by this one.
 /// </summary>
 /// <param name="child">The node we want to adopt.</param>
 /// <returns>Returns true if this node can adopt the given child.</returns>
 public bool CanAdoptNode(BaseNode child) {
     return CanAdopt(child) && _children.CanAdoptNode(child);
 }
コード例 #36
0
ファイル: DecoratorWeight.cs プロジェクト: Just4F/behaviac
 protected override bool CanBeAdoptedBy(BaseNode parent)
 {
     return base.CanBeAdoptedBy(parent) && (parent is SelectorProbability);
 }
コード例 #37
0
ファイル: BaseNode.cs プロジェクト: pjkui/behaviac
 public virtual Attachments.Attachment CreateStartCondition(BaseNode owner) {
     return null;
 }
コード例 #38
0
            public override void ClearChildrenInternal()
            {
                _child = null;

                _connectedChildren.RequiresRebuild();
            }
コード例 #39
0
ファイル: WaitState.cs プロジェクト: wuzhen/behaviac
 protected override bool CanBeAdoptedBy(BaseNode parent)
 {
     return base.CanBeAdoptedBy(parent) && (parent is Behavior) && (parent.IsFSM || (parent.Children.Count == 0)) && (parent.FSMNodes.Count == 0);
 }
コード例 #40
0
 /// <summary>
 /// Removes a child from this connector.
 /// </summary>
 /// <param name="node">The child we want to remove.</param>
 /// <returns>Returns false if the connector is read-only.</returns>
 public abstract bool RemoveChild(BaseNode node);
コード例 #41
0
ファイル: Task.cs プロジェクト: 675492062/behaviac
        //can only accept multiple methods or only one other type of node
        public override bool CanAdopt(BaseNode child) {
            if (base.CanAdopt(child)) {
                // 1. the 1st child, to accept it anyway
                if (this.Children.Count == 0) {
                    return true;
                }

                // 2. only accept it if the newly added one is a Method and the existing Children are all Method
                if (child is Nodes.Method) {
                    // insert a Method before a none-method node
                    if (this.Children.Count == 1) {
                        return true;
                    }

                    int count = 0;

                    for (int i = 0; i < this.Children.Count; ++i) {
                        BaseNode c = this.Children[i];
                        bool isMethod = c is Method;

                        if (isMethod) {
                            count++;
                        }
                    }

                    // all children are method, accept any node, (a Method will be automatically added if it is not a method)
                    if (count == this.Children.Count) {
                        return true;
                    }
                }
            }

            return false;
        }
コード例 #42
0
            /// <summary>
            /// Adds a connector subitem for a given child.
            /// </summary>
            /// <param name="child">The child we want to add a connecor subitem for.</param>
            protected void AddSubItem(BaseNode child)
            {
                if (!(_connectedChildren.Owner is NodeViewData))
                    throw new Exception(Resources.ExceptionIsNotNodeViewData);

                int firstIndex;
                List<NodeViewData.SubItemConnector> subitems = CollectSubItems(out firstIndex);

                // check if there is a connector subitem with child due to the minimum count
                foreach (NodeViewData.SubItemConnector subitem in subitems)
                {
                    if (subitem.Child == null)
                    {
                        // simply reuse the connector subitem
                        subitem.Child = child;
                        return;
                    }
                }

                // add a new connector subitem
                ((NodeViewData)_connectedChildren.Owner).AddSubItem(new NodeViewData.SubItemConnector(this, child, subitems.Count), firstIndex + subitems.Count);
            }
コード例 #43
0
            /// <summary>
            /// Gets a connector by one of its children.
            /// </summary>
            /// <param name="child">The child whose connector we are looking for.</param>
            /// <returns>Returns null if no connector could be found.</returns>
            public Connector GetConnector(BaseNode child) {
                foreach(Connector connector in _connectors) {
                    for (int i = 0; i < connector.ChildCount; ++i) {
                        if (connector.GetChild(i) == child)
                        { return connector; }
                    }
                }

                return null;
            }
コード例 #44
0
            /// <summary>
            /// Adds a connector subitem for a given child at a given position.
            /// </summary>
            /// <param name="child">The child we want to add a connector subitem for.</param>
            /// <param name="index">The position we want to add the subitem at.</param>
            protected void AddSubItem(BaseNode child, int index)
            {
                if (!(_connectedChildren.Owner is NodeViewData))
                    throw new Exception(Resources.ExceptionIsNotNodeViewData);

                int firstIndex;
                List<NodeViewData.SubItemConnector> subitems = CollectSubItems(out firstIndex);

                // we want to add inside the minimum count it can be that there is a connector subitem which has no child (due to minimum count)
                if (index < _minCount)
                {
                    foreach (NodeViewData.SubItemConnector subitem in subitems)
                    {
                        if (subitem.Child == null)
                        {
                            // if there is a free connector subitem we drop it so we can add a new one for our child
                            ((NodeViewData)_connectedChildren.Owner).RemoveSubItem(subitem);
                            break;
                        }
                    }
                }

                // add a connector subitem for the child
                ((NodeViewData)_connectedChildren.Owner).AddSubItem(new NodeViewData.SubItemConnector(this, child, subitems.Count), firstIndex + index);

                RebuildSubItemIndices();
            }
コード例 #45
0
 /// <summary>
 /// Creates a new instance to store all available connectors on an node.
 /// </summary>
 /// <param name="owner">The node this instance belongs to.</param>
 public ConnectedChildren(BaseNode owner) {
     _owner = owner;
 }
コード例 #46
0
 /// <summary>
 /// Removes a child from this connector.
 /// </summary>
 /// <param name="node">The child we want to remove.</param>
 /// <returns>Returns false if the connector is read-only.</returns>
 public abstract bool RemoveChild(BaseNode node);