Exemple #1
0
 public AINode SelectParent(AINode self, AINode last, int x, int y)
 {
     if (SelfOutRect.Left < x && x < SelfOutRect.Right + HMargen)
     {
         if (SelfOutRect.Top < y && y < SelfOutRect.Bottom)
         {
             return(this);
         }
         if (last == this && SelfOutRect.Top - VMargen < y && y < SelfOutRect.Bottom + VMargen)
         {
             return(this);
         }
     }
     foreach (var child in Children)
     {
         if (child == self)
         {
             continue;
         }
         var n = child.SelectParent(self, last, x, y);
         if (n != null)
         {
             return(n);
         }
     }
     return(null);
 }
Exemple #2
0
        XmlElement MakeXmlElement(AINode node, XmlDocument xml)
        {
            XmlElement elem = xml.CreateElement("Node");
            var        t    = allNodeTypes[node.NodeType];

            elem.SetAttribute("type", t);
            if (t == "con" || t == "bsel")
            {
                elem.SetAttribute("condition", node.GetXmlCondition());
            }
            if (t == "act")
            {
                elem.SetAttribute("action", node.GetXmlAction());
            }
            if (node.Parent != null)
            {
                var pt = allNodeTypes[node.Parent.NodeType];
                if (pt == "bsel")
                {
                    elem.SetAttribute("bselect", node.BSelectValue.ToString());
                }
                if (pt == "psel")
                {
                    elem.SetAttribute("weight", node.PSelectWeight.ToString());
                }
            }
            foreach (var n in node.Children)
            {
                var e = MakeXmlElement(n, xml);
                elem.AppendChild(e);
            }
            return(elem);
        }
Exemple #3
0
        public void Load(string filename)
        {
            XmlDocument xmlDoc = new XmlDocument();

            xmlDoc.Load(filename);
            Root = MakeNodeFromXML(xmlDoc.DocumentElement);
            Root.AutoLayout();
        }
Exemple #4
0
        public AINode AddNode(string name, NodeShapeType shape = NodeShapeType.圆角矩形)
        {
            AINode node = new AINode();

            node.NodeShape = shape;
            node.Parent    = this;
            node.MyNodePtr = Children.AddLast(node);
            return(node);
        }
Exemple #5
0
 public bool DelNode(AINode node)
 {
     foreach (var c in Children)
     {
         if (c == node)
         {
             Children.Remove(c);
             return(true);
         }
         if (c.DelNode(node))
         {
             return(true);
         }
     }
     return(false);
 }
Exemple #6
0
        public override void OnPaint(PaintEventArgs e)
        {
            AINode rootNode = new AINode();

            rootNode.SetGraphics(e.Graphics);
            rootNode.SelfOutRect.X = ClientSize.Width / 2;
            rootNode.SelfOutRect.Y = ClientSize.Height / 2;

            rootNode.AddNode("firstOne").AddNode("node1.1").AddNode("node1.1.1");
            var node2 = rootNode.AddNode("secondOne");

            node2.AddNode("2.1");
            node2.AddNode("2.2");

            rootNode.CalcNodeHeight();
            rootNode.CalcNodeWidth();
            rootNode.SelfOutRect.X = ClientSize.Width / 2 - rootNode.NodeOutRect.Width / 2;
            rootNode.SelfOutRect.Y = ClientSize.Height / 2 - rootNode.NodeOutRect.Height / 2;
            rootNode.AutoLayout();
            rootNode.DrawNode();
        }
Exemple #7
0
 public override void OnKeyDown(KeyEventArgs e)
 {
     if (CurrentSelectNode != null)
     {
         if (e.KeyCode == Keys.Enter)
         {
             if (e.Shift)
             {
                 //孩子节点
                 CurrentSelectNode = CurrentSelectNode.AddNode("子节点");
                 return;
             }
             //兄弟节点
             if (CurrentSelectNode == Root)
             {
                 return;
             }
             var node = CurrentSelectNode.Parent.AddNode("子节点");
             CurrentSelectNode = node;
         }
         else if (e.KeyCode == Keys.Delete)
         {
             //删除节点
             CurrentSelectNode.Parent.DelNode(CurrentSelectNode);
             CurrentSelectNode = null;
             CurrentMoveNode   = null;
         }
         else if (e.Alt)
         {
             if (e.KeyCode == Keys.Up)
             {
                 AINode.SwapNode(CurrentSelectNode, true);
             }
             else if (e.KeyCode == Keys.Down)
             {
                 AINode.SwapNode(CurrentSelectNode, false);
             }
         }
     }
 }
Exemple #8
0
        public static void ParseAction(AINode node, string actions)
        {
            string[] a = actions.Split(',');
            if (a.Length == 0)
            {
                return;
            }
            node.ActionType = a[0];

            if (a.Length > 1)
            {
                node.ActionParam1 = float.Parse(a[1]);
            }
            if (a.Length > 2)
            {
                node.ActionParam2 = float.Parse(a[2]);
            }
            if (a.Length > 3)
            {
                node.ActionParam2 = float.Parse(a[3]);
            }
        }
Exemple #9
0
        public static void SwapNode(AINode node, bool moveUp)
        {
            var prev = node.MyNodePtr.Previous;
            var next = node.MyNodePtr.Next;

            node.MyNodePtr.List.Remove(node.MyNodePtr);
            if (moveUp)
            {
                if (prev == null)
                {
                    return;
                }
                node.MyNodePtr = prev.List.AddBefore(prev, node);
            }
            else
            {
                if (next == null)
                {
                    return;
                }
                node.MyNodePtr = next.List.AddAfter(next, node);
            }
        }
Exemple #10
0
        AINode MakeNodeFromXML(XmlElement xml)
        {
            AINode node = new AINode();
            var    t    = xml.GetAttribute("type");

            node.NodeType = antiNodeTypes[t];
            if (t == "con" || t == "bsel")
            {
                string s = xml.GetAttribute("condition");
                ParseCondition(node, s);
            }
            if (t == "act")
            {
                string s = xml.GetAttribute("action");
                ParseAction(node, s);
            }
            if (node.Parent != null)
            {
                var pt = allNodeTypes[node.Parent.NodeType];
                if (pt == "bsel")
                {
                    node.BSelectValue = bool.Parse(xml.GetAttribute("bselect"));
                }
                if (pt == "psel")
                {
                    node.PSelectWeight = int.Parse(xml.GetAttribute("weight"));
                }
            }

            foreach (var e in xml)
            {
                AINode n = MakeNodeFromXML(e as XmlElement);
                n.MyNodePtr = node.Children.AddLast(n);
            }
            return(node);
        }
Exemple #11
0
 public void AddNode(AINode node)
 {
     node.MyNodePtr = Children.AddLast(node);
 }