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); } }
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); } }
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); }
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); }
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)); }
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); } }
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(); }
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; }
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(); }
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); }
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; }