Beispiel #1
0
        private void Expand(TreeNode node, BTPath btPath)
        {
            var behavior = btPath.Path[btPath.Path.Count - 1];

            foreach (var child in behavior.TypeLink.OrderBy(n => n.BehaviorName))
            {
                AddNode(btPath, child, node.Nodes);
            }

            for (int i = 0; i < behavior.ChildLink.Count; i++)
            {
                var child = behavior.ChildLink[i];
                AddNode(btPath, child, node.Nodes, i < behavior.Param.Count ? behavior.Param[i] : null);
            }
        }
Beispiel #2
0
        private static BTPath ExtendPath(BTPath btPath, Behavior behavior)
        {
            var newBTPath = new BTPath { Path = new List<Behavior>() };
            if (btPath.Path != null)
                newBTPath.Path.AddRange(btPath.Path);
            newBTPath.Path.Add(behavior);

            while (true)
            {
                var newBehavior = Analyzer.HideNodes(btPath, behavior);
                if (newBehavior == null)
                    return newBTPath;

                behavior = newBehavior;
                newBTPath.Path.Add(behavior);
            }
        }
Beispiel #3
0
        public static Behavior HideNodes(BTPath btPath, Behavior nextBehavior)
        {
            string characterTemplate = null;

            foreach (var behavior in btPath.Path)
            {
                if (behavior.BehaviorName.Contains("::"))
                {
                    var newTemplate = GetCharacterTemplate(behavior);

                    if (newTemplate != "")
                        characterTemplate = newTemplate;
                }
            }

            return GetReplacementNode(nextBehavior, characterTemplate);
        }
Beispiel #4
0
        private TreeNode AddNode(BTPath btPath, Behavior behavior, TreeNodeCollection treeNodeCollection, string param = null)
        {
            var font = behaviorTreeView.Font;

            var newBTPath = ExtendPath(btPath, behavior);

            behavior = newBTPath.Path[newBTPath.Path.Count - 1];

            var nodeLabel = NodeLabel(behavior, param);
            var newNode   = treeNodeCollection.Add(behavior.Key, nodeLabel);

            newNode.Tag = newBTPath;

            if (behavior.Annotations.Contains("HasSelectAbility"))
            {
                newNode.ForeColor = Color.Black;
            }
            //else if (behavior.Annotations.Contains("HasUpdateBestTarget"))
            //    newNode.ForeColor = Color.DarkRed;
            else if (behavior.Annotations.Contains("HasAction"))
            {
                if (behavior.Annotations.Contains("ConditionValued"))
                {
                    newNode.ForeColor = Color.DarkCyan;
                }
                else
                {
                    newNode.ForeColor = Color.DarkGreen;
                }
            }
            else
            {
                newNode.ForeColor = Color.Blue;
            }

            if (!Analyzer.ShouldShow(newBTPath))
            {
                font = new Font(font, FontStyle.Strikeout);
            }

            newNode.NodeFont = font;

            return(newNode);
        }
Beispiel #5
0
        static public Behavior HideNodes(BTPath btPath, Behavior nextBehavior)
        {
            string characterTemplate = null;

            foreach (var behavior in btPath.Path)
            {
                if (behavior.BehaviorName.Contains("::"))
                {
                    var newTemplate = GetCharacterTemplate(behavior);

                    if (newTemplate != "")
                    {
                        characterTemplate = newTemplate;
                    }
                }
            }

            return(GetReplacementNode(nextBehavior, characterTemplate));
        }
Beispiel #6
0
        private static BTPath ExtendPath(BTPath btPath, Behavior behavior)
        {
            var newBTPath = new BTPath {
                Path = new List <Behavior>()
            };

            if (btPath.Path != null)
            {
                newBTPath.Path.AddRange(btPath.Path);
            }
            newBTPath.Path.Add(behavior);

            while (true)
            {
                var newBehavior = Analyzer.HideNodes(btPath, behavior);
                if (newBehavior == null)
                {
                    return(newBTPath);
                }

                behavior = newBehavior;
                newBTPath.Path.Add(behavior);
            }
        }
Beispiel #7
0
        private void UpdateBehaviorTreeView()
        {
            behaviorTreeView.BeginUpdate();
            behaviorTreeView.Nodes.Clear();

            var rootKeys = new HashSet<string>(BT.Roots().Select(r => r.Key));
            foreach (var key in PublicRoots)
                rootKeys.Add(key);

            foreach (var key in rootKeys.OrderByDescending(k => PublicRoots.Contains(k)).ThenBy(k => k))
            {
                Behavior root;
                if (BT.Tree.TryGetValue(key, out root))
                {
                    var btPath = new BTPath { Path = new List<Behavior>() };
                    var newNode = AddNode(btPath, root, behaviorTreeView.Nodes);
                    btPath.Path.Add(root);
                    Expand(newNode, btPath);

                    if (expandedPaths.Contains(newNode.Tag.ToString()))
                        newNode.Expand();
                }
            }
            behaviorTreeView.EndUpdate();

            if (configParser.Errors.Count > 0 || analyzer.Errors.Count > 0)
            {
                errorListBox.BeginUpdate();
                errorListBox.Items.Clear();

                foreach (var error in configParser.Errors)
                    errorListBox.Items.Add(error);
                foreach (var error in analyzer.Errors)
                    errorListBox.Items.Add(error);

                errorListBox.EndUpdate();

                errorListBox.Show();
                errorLabel.Show();
            }
            else
            {
                errorListBox.Hide();
                errorLabel.Hide();
            }

            overviewTooltipStatuslabel.Text = string.Format("{0} files, {1} nodes", layers.Count(l => l.Enabled),
                BT.Tree.Count);

            expandedPaths.Clear();
        }
Beispiel #8
0
        private void Expand(TreeNode node, BTPath btPath)
        {
            var behavior = btPath.Path[btPath.Path.Count - 1];
            foreach (var child in behavior.TypeLink.OrderBy(n => n.BehaviorName))
            {
                AddNode(btPath, child, node.Nodes);
            }

            for (int i = 0; i < behavior.ChildLink.Count; i++)
            {
                var child = behavior.ChildLink[i];
                AddNode(btPath, child, node.Nodes, i < behavior.Param.Count ? behavior.Param[i] : null);
            }
        }
Beispiel #9
0
        private TreeNode AddNode(BTPath btPath, Behavior behavior, TreeNodeCollection treeNodeCollection, string param = null)
        {
            var font = behaviorTreeView.Font;

            var newBTPath = ExtendPath(btPath, behavior);
            behavior = newBTPath.Path[newBTPath.Path.Count - 1];

            var nodeLabel = NodeLabel(behavior, param);
            var newNode = treeNodeCollection.Add(behavior.Key, nodeLabel);
            newNode.Tag = newBTPath;

            if (behavior.Annotations.Contains("HasSelectAbility"))
                newNode.ForeColor = Color.Black;
            //else if (behavior.Annotations.Contains("HasUpdateBestTarget"))
            //    newNode.ForeColor = Color.DarkRed;
            else if (behavior.Annotations.Contains("HasAction"))
            {
                if (behavior.Annotations.Contains("ConditionValued"))
                    newNode.ForeColor = Color.DarkCyan;
                else
                    newNode.ForeColor = Color.DarkGreen;
            }
            else
                newNode.ForeColor = Color.Blue;

            if (!Analyzer.ShouldShow(newBTPath))
                font = new Font(font, FontStyle.Strikeout);

            newNode.NodeFont = font;

            return newNode;
        }
Beispiel #10
0
        private void UpdateBehaviorTreeView()
        {
            behaviorTreeView.BeginUpdate();
            behaviorTreeView.Nodes.Clear();

            var rootKeys = new HashSet <string>(BT.Roots().Select(r => r.Key));

            foreach (var key in PublicRoots)
            {
                rootKeys.Add(key);
            }

            foreach (var key in rootKeys.OrderByDescending(k => PublicRoots.Contains(k)).ThenBy(k => k))
            {
                Behavior root;
                if (BT.Tree.TryGetValue(key, out root))
                {
                    var btPath = new BTPath {
                        Path = new List <Behavior>()
                    };
                    var newNode = AddNode(btPath, root, behaviorTreeView.Nodes);
                    btPath.Path.Add(root);
                    Expand(newNode, btPath);

                    if (expandedPaths.Contains(newNode.Tag.ToString()))
                    {
                        newNode.Expand();
                    }
                }
            }
            behaviorTreeView.EndUpdate();

            if (configParser.Errors.Count > 0 || analyzer.Errors.Count > 0)
            {
                errorListBox.BeginUpdate();
                errorListBox.Items.Clear();

                foreach (var error in configParser.Errors)
                {
                    errorListBox.Items.Add(error);
                }
                foreach (var error in analyzer.Errors)
                {
                    errorListBox.Items.Add(error);
                }

                errorListBox.EndUpdate();

                errorListBox.Show();
                errorLabel.Show();
            }
            else
            {
                errorListBox.Hide();
                errorLabel.Hide();
            }

            overviewTooltipStatuslabel.Text = string.Format("{0} files, {1} nodes", layers.Count(l => l.Enabled),
                                                            BT.Tree.Count);

            expandedPaths.Clear();
        }
Beispiel #11
0
        static public bool ShouldShow(BTPath btPath)
        {
            string           characterTemplate          = null;
            HashSet <string> knownTrue                  = new HashSet <string>();
            HashSet <string> knownFalse                 = new HashSet <string>();
            HashSet <string> excludedCharacterTemplates = new HashSet <string>();

            for (int index = 0; index < btPath.Path.Count; index++)
            {
                var  behavior = btPath.Path[index];
                bool isLast   = index == btPath.Path.Count - 1;
                if (behavior.BehaviorName.Contains("::"))
                {
                    var newTemplate = GetCharacterTemplate(behavior);

                    if (newTemplate == "")
                    {
                        // If this is the child of a '::' node, add knownFalse for the other cases.
                        if (index + 1 < btPath.Path.Count)
                        {
                            foreach (var child in behavior.TypeLink)
                            {
                                if (child == btPath.Path[index + 1])
                                {
                                    continue;
                                }
                                excludedCharacterTemplates.Add(GetCharacterTemplate(child));
                            }
                        }
                    }
                    else
                    {
                        if (isLast && ((characterTemplate != null && characterTemplate != newTemplate) || excludedCharacterTemplates.Contains(newTemplate)))
                        {
                            return(false);
                        }

                        if (characterTemplate == null)
                        {
                            characterTemplate = newTemplate;
                        }
                    }
                }

                if (!isLast)
                {
                    if (behavior.TypeLink.Contains(btPath.Path[index + 1]))
                    {
                        continue;
                    }

                    switch (behavior.NodeType.ToLowerInvariant())
                    {
                    case "selector":
                        foreach (var child in behavior.ChildLink)
                        {
                            if (child == btPath.Path[index + 1])
                            {
                                break;
                            }

                            ShouldShowHandleSequence(child, knownFalse, knownTrue);
                        }
                        break;

                    case "sequence":
                        foreach (var child in behavior.ChildLink)
                        {
                            if (child == btPath.Path[index + 1])
                            {
                                break;
                            }

                            ShouldShowHandleSequence(child, knownTrue, knownFalse);
                        }
                        break;
                    }
                }
                else
                {
                    return(ShouldShow(behavior, knownTrue, knownFalse, characterTemplate));
                }
            }

            return(true);
        }
Beispiel #12
0
        public static bool ShouldShow(BTPath btPath)
        {
            string characterTemplate = null;
            HashSet<string> knownTrue = new HashSet<string>();
            HashSet<string> knownFalse = new HashSet<string>();
            HashSet<string> excludedCharacterTemplates = new HashSet<string>();

            for (int index = 0; index < btPath.Path.Count; index++)
            {
                var behavior = btPath.Path[index];
                bool isLast = index == btPath.Path.Count - 1;
                if (behavior.BehaviorName.Contains("::"))
                {
                    var newTemplate = GetCharacterTemplate(behavior);

                    if (newTemplate == "")
                    {
                        // If this is the child of a '::' node, add knownFalse for the other cases.
                        if (index + 1 < btPath.Path.Count)
                        {
                            foreach (var child in behavior.TypeLink)
                            {
                                if (child == btPath.Path[index + 1])
                                    continue;
                                excludedCharacterTemplates.Add(GetCharacterTemplate(child));
                            }
                        }
                    }
                    else
                    {
                        if (isLast && ((characterTemplate != null && characterTemplate != newTemplate) || excludedCharacterTemplates.Contains(newTemplate)))
                            return false;

                        if (characterTemplate == null)
                            characterTemplate = newTemplate;
                    }
                }

                if (!isLast)
                {
                    if (behavior.TypeLink.Contains(btPath.Path[index + 1]))
                        continue;

                    switch (behavior.NodeType.ToLowerInvariant())
                    {
                        case "selector":
                            foreach (var child in behavior.ChildLink)
                            {
                                if (child == btPath.Path[index + 1])
                                    break;

                                ShouldShowHandleSequence(child, knownFalse, knownTrue);
                            }
                            break;

                        case "sequence":
                            foreach (var child in behavior.ChildLink)
                            {
                                if (child == btPath.Path[index + 1])
                                    break;

                                ShouldShowHandleSequence(child, knownTrue, knownFalse);
                            }
                            break;
                    }
                }
                else
                {
                    return ShouldShow(behavior, knownTrue, knownFalse, characterTemplate);
                }
            }

            return true;
        }