コード例 #1
0
 public CategoryCommand(DGNode node, DGFlag newValue)
 {
     this.mNode     = node;
     this.mOldValue = node.mCategory;
     this.mNewValue = newValue;
     this.mLabel    = "Change DG Node Category";
 }
コード例 #2
0
ファイル: AnchorPoint.cs プロジェクト: Nofasar/s3pi-wrappers
        public AnchorPoint(DGNode owner, float dirX, float dirY)
        {
            if (owner == null)
            {
                throw new ArgumentNullException("owner");
            }
            this.Edges = new List <DGEdge>();

            this.mOwner = owner;
            this.SetParent(owner);

            this.mDirX = dirX;
            this.mDirY = dirY;

            this.UpdateBoundingBox();
        }
コード例 #3
0
            public void Undo()
            {
                AnchorPoint ap = this.mNode.mSliceAnchors[this.mSliceIndex];

                RandomNode.Slice slice
                    = this.mNode.mRandomNode.Slices[this.mSliceIndex];
                if (this.bAdd)
                {
                    ap.Edges.RemoveAt(this.mTargetIndex);
                    slice.Targets.RemoveAt(this.mTargetIndex);
                }
                else
                {
                    ap.Edges.Insert(this.mTargetIndex, this.mEdge);
                    DGNode node = this.mEdge.DstNode;
                    if (node == this.mNode)
                    {
                        node = this.mEdge.SrcNode;
                    }
                    slice.Targets.Insert(this.mTargetIndex, node.DGN);
                }
            }
コード例 #4
0
        public bool AsyncDriftTowardsCenter()
        {
            if (this.mDGraph.NodeCount == 0)
            {
                return(false);
            }
            int i;
            // Calculate the net bounding box of all dg nodes
            DGNode     node = this.mDGraph.NodeAt(0);
            RectangleF nbox = node.ChildrenBoundingBox();

            nbox.Offset(node.X, node.Y);
            RectangleF bbox = nbox;

            for (i = this.mDGraph.NodeCount - 1; i >= 1; i--)
            {
                node = this.mDGraph.NodeAt(i);
                if (!node.MouseGrabbed)
                {
                    nbox = node.ChildrenBoundingBox();
                    nbox.Offset(node.X, node.Y);
                    bbox = RectangleF.Union(bbox, nbox);
                }
            }
            // Calculate the center of the net bounding box
            float x = bbox.X + bbox.Width / 2;
            float y = bbox.Y + bbox.Height / 2;

            // Calculate the ideal position of this center
            nbox = this.mScene.BoundingBox;
            nbox.Offset(-this.X, -this.Y);
            float dx, dy;

            if (bbox.Width / 2 > nbox.Right)
            {
                dx = nbox.Right - bbox.Width / 2 - x;
            }
            else if (bbox.Width / -2 < nbox.X)
            {
                dx = nbox.X + bbox.Width / 2 - x;
            }
            else
            {
                dx = -x;
            }
            if (bbox.Height / 2 > nbox.Bottom)
            {
                dy = nbox.Bottom - bbox.Height / 2 - y;
            }
            else if (bbox.Height / -2 < nbox.Y)
            {
                dy = nbox.Y + bbox.Height / 2 - y;
            }
            else
            {
                dy = -y;
            }
            if (dx * dx < 0.01f && dy * dy < 0.01f)
            {
                return(false);
            }
            // Drift the net bounding box's center towards origin
            for (i = this.mDGraph.NodeCount - 1; i >= 0; i--)
            {
                node = this.mDGraph.NodeAt(i);
                if (!node.MouseGrabbed)
                {
                    node.SetPosition(node.X + 0.1f * dx, node.Y + 0.1f * dy);
                }
            }
            return(true);
        }
コード例 #5
0
        private DGNode InitDGN(DGNode src, DecisionGraphNode dgn)
        {
            int    i;
            DGNode dst = null;

            for (i = this.mDGraph.NodeCount - 1; i >= 0; i--)
            {
                dst = this.mDGraph.NodeAt(i);
                if (dst.DGN == dgn)
                {
                    break;
                }
            }
            if (i < 0)
            {
                int                 j;
                DGEdge              edge;
                AnchorPoint         ap;
                DecisionGraphNode[] dgns;
                DGMulticastNode     dgmcn = null;
                switch (dgn.ChunkType)
                {
                case NextStateNode.ResourceType:
                    NextStateNode nsn = dgn as NextStateNode;
                    dst = new DGSnSnNode(nsn, this);
                    this.mDGraph.AddNode(dst);
                    dst.SetParent(this);
                    break;

                case RandomNode.ResourceType:
                    RandomNode rand = dgn as RandomNode;
                    DGRandNode dgrn = new DGRandNode(rand, this);
                    this.mDGraph.AddNode(dgrn);
                    dgrn.SetParent(this);
                    List <RandomNode.Slice> slices = rand.Slices;
                    if (slices.Count > 0)
                    {
                        for (i = 0; i < slices.Count; i++)
                        {
                            ap   = dgrn.GetSliceAnchor(i);
                            dgns = slices[i].Targets.ToArray();
                            for (j = 0; j < dgns.Length; j++)
                            {
                                dst  = this.InitDGN(dgrn, dgns[j]);
                                edge = new DGEdge(dgrn, dst, false);
                                ap.Edges.Add(edge);
                                dst.EntryAnchor.Edges.Add(edge);
                                this.mDGraph.AddEdge(edge);
                                edge.SetParent(this);
                            }
                        }
                    }
                    dst = dgrn;
                    break;

                case SelectOnDestinationNode.ResourceType:
                    SelectOnDestinationNode sodn
                        = dgn as SelectOnDestinationNode;
                    DGSoDnNode dgsodn
                        = new DGSoDnNode(sodn, this);
                    this.mDGraph.AddNode(dgsodn);
                    dgsodn.SetParent(this);
                    if (sodn.CaseCount > 0)
                    {
                        SelectOnDestinationNode.Case[] cases = sodn.Cases;
                        for (i = 0; i < cases.Length; i++)
                        {
                            ap   = dgsodn.GetCaseAnchorAt(i);
                            dgns = cases[i].Targets;
                            for (j = 0; j < dgns.Length; j++)
                            {
                                dst  = this.InitDGN(dgsodn, dgns[j]);
                                edge = new DGEdge(dgsodn, dst, false);
                                ap.Edges.Add(edge);
                                dst.EntryAnchor.Edges.Add(edge);
                                this.mDGraph.AddEdge(edge);
                                edge.SetParent(this);
                            }
                        }
                    }
                    dst = dgsodn;
                    break;

                case SelectOnParameterNode.ResourceType:
                    SelectOnParameterNode sopn
                        = dgn as SelectOnParameterNode;
                    DGSoPnNode dgsopn
                        = new DGSoPnNode(sopn, this);
                    this.mDGraph.AddNode(dgsopn);
                    dgsopn.SetParent(this);
                    if (sopn.CaseCount > 0)
                    {
                        SelectOnParameterNode.Case[] cases = sopn.Cases;
                        for (i = 0; i < cases.Length; i++)
                        {
                            ap   = dgsopn.GetCaseAnchorAt(i);
                            dgns = cases[i].Targets;
                            for (j = 0; j < dgns.Length; j++)
                            {
                                dst  = this.InitDGN(dgsopn, dgns[j]);
                                edge = new DGEdge(dgsopn, dst, false);
                                ap.Edges.Add(edge);
                                dst.EntryAnchor.Edges.Add(edge);
                                this.mDGraph.AddEdge(edge);
                                edge.SetParent(this);
                            }
                        }
                    }
                    dst = dgsopn;
                    break;

                case CreatePropNode.ResourceType:
                    CreatePropNode cpn   = dgn as CreatePropNode;
                    DGPropNode     dgcpn = new DGPropNode(cpn, this);
                    this.mDGraph.AddNode(dgcpn);
                    dgcpn.SetParent(this);
                    dgmcn = dgcpn;
                    break;

                case ActorOperationNode.ResourceType:
                    ActorOperationNode aon   = dgn as ActorOperationNode;
                    DGAcOpNode         dgaon = new DGAcOpNode(aon, this);
                    this.mDGraph.AddNode(dgaon);
                    dgaon.SetParent(this);
                    dgmcn = dgaon;
                    break;

                case StopAnimationNode.ResourceType:
                    StopAnimationNode san   = dgn as StopAnimationNode;
                    DGStopNode        dgsan = new DGStopNode(san, this);
                    this.mDGraph.AddNode(dgsan);
                    dgsan.SetParent(this);
                    dgmcn = dgsan;
                    break;

                case PlayAnimationNode.ResourceType:
                    PlayAnimationNode pan   = dgn as PlayAnimationNode;
                    DGPlayNode        dgpan = new DGPlayNode(pan, this);
                    this.mDGraph.AddNode(dgpan);
                    dgpan.SetParent(this);
                    dgmcn = dgpan;
                    break;
                }
                if (dgmcn != null)
                {
                    MulticastDecisionGraphNode mcn
                        = dgn as MulticastDecisionGraphNode;
                    if (mcn.TargetCount > 0)
                    {
                        ap   = dgmcn.TargetAnchor;
                        dgns = mcn.Targets;
                        for (i = 0; i < dgns.Length; i++)
                        {
                            dst  = this.InitDGN(dgmcn, dgns[i]);
                            edge = new DGEdge(dgmcn, dst, false);
                            ap.Edges.Add(edge);
                            dst.EntryAnchor.Edges.Add(edge);
                            this.mDGraph.AddEdge(edge);
                            edge.SetParent(this);
                        }
                    }
                    dst = dgmcn;
                }
            }
            return(dst);
        }