private void setParName(TextBox nameTextBox)
        {
            int    rowIndex = getRowIndex(null, nameTextBox, null, null, null);
            string newName  = nameTextBox.Text.Trim();

            nameTextBox.Text = newName;
            if (!string.IsNullOrEmpty(newName) && _rootNode.Pars[rowIndex].Name != newName)
            {
                UndoManager.PreSave();

                Plugin.ResetPar(_rootNode, _rootNode.Pars[rowIndex], newName);
                _rootNode.Pars[rowIndex].Name = newName;

                PropertiesDock.UpdatePropertyGrids();
                _rootNode.OnPropertyValueChanged(true);

                UndoManager.Save((Nodes.Behavior)_rootNode);

                UndoManager.PostSave();

                BehaviorTreeView behaviorTreeView = BehaviorTreeViewDock.LastFocused.BehaviorTreeView;
                if (behaviorTreeView != null)
                {
                    behaviorTreeView.Redraw();
                }
            }
        }
        private void selectRowNode(DataGridViewRow row)
        {
            Debug.Check(row != null);
            if (row != null)
            {
                row.Selected = true;

                string           behaviorFilename = (string)row.Cells["BehaviorFilename"].Value;
                BehaviorTreeView behaviorTreeView = UIUtilities.ShowBehaviorTree(behaviorFilename);

                if (behaviorTreeView != null)
                {
                    string       nodeId = (string)row.Cells["NodeId"].Value;
                    NodeViewData nvd    = behaviorTreeView.RootNodeView.FindNodeViewData(nodeId);

                    if (nvd != null)
                    {
                        behaviorTreeView.SelectedNode = nvd;
                        //if (behaviorTreeView.ClickNode != null)
                        //    behaviorTreeView.ClickNode(nvd);
                        behaviorTreeView.Invalidate();
                    }
                }
            }
        }
        private static void showPlanning(FrameStatePool.PlanningProcess planning)
        {
            BehaviorTreeView view = UIUtilities.ShowPlanning(planning);

            if (view != null)
            {
                view.ClickNode += new BehaviorTreeView.ClickNodeEventDelegate(Planning_ClikcNode);
            }
        }
Exemple #4
0
        public static BehaviorTreeView ShowPlanning(FrameStatePool.PlanningProcess planning)
        {
            string behaviorFilename = FileManagers.FileManager.GetFullPath(planning._behaviorTree);

            if (!File.Exists(behaviorFilename))
            {
                return(null);
            }

            string planningName = string.Format("PLanning_{0}_{1}", planning._frame, planning._index);

            Dictionary <string, BehaviorNode> list_plannings = null;

            if (!_agent_plannings.ContainsKey(planning._agentFullName))
            {
                list_plannings = new Dictionary <string, BehaviorNode>();
                _agent_plannings.Add(planning._agentFullName, list_plannings);
            }
            else
            {
                list_plannings = _agent_plannings[planning._agentFullName];
            }

            BehaviorNode behavior = null;

            if (!list_plannings.ContainsKey(planningName))
            {
                Plugin.PlanningProcess = planning;
                behavior = BehaviorManager.Instance.LoadBehavior(behaviorFilename, true);
                Behavior b = behavior as Behavior;
                b.PlanningProcess      = planning;
                Plugin.PlanningProcess = null;

                b.PlanIsCollapseFailedBranch = Behavior.kPlanIsCollapseFailedBranch;

                list_plannings.Add(planningName, behavior);
                behavior.Filename      = planningName;
                ((Node)behavior).Label = planningName;
            }
            else
            {
                behavior = list_plannings[planningName];
            }

            Debug.Check(behavior is Node);

            BehaviorTreeList behaviorTreeList = BehaviorManager.Instance as BehaviorTreeList;

            Debug.Check(behaviorTreeList != null);
            behaviorTreeList.ShowNode(behavior as Node);

            BehaviorTreeView view = BehaviorTreeViewDock.GetBehaviorTreeView(behavior);

            return(view);
        }
Exemple #5
0
        private List <Nodes.Node> GetRootNodes(FindRange findRange)
        {
            List <Nodes.Node> rootNodes = new List <Nodes.Node>();

            switch (findRange)
            {
            case FindRange.CurrentFile:
                if (BehaviorTreeViewDock.LastFocused != null)
                {
                    BehaviorTreeView behaviorTreeView = BehaviorTreeViewDock.LastFocused.BehaviorTreeView;

                    if (behaviorTreeView != null && behaviorTreeView.RootNodeView != null)
                    {
                        rootNodes.Add(behaviorTreeView.RootNodeView.Node);
                    }
                }

                break;

            case FindRange.AllOpenFiles:
                foreach (BehaviorTreeViewDock dock in BehaviorTreeViewDock.Instances)
                {
                    BehaviorTreeView behaviorTreeView = dock.BehaviorTreeView;

                    if (behaviorTreeView != null && behaviorTreeView.RootNodeView != null)
                    {
                        rootNodes.Add(behaviorTreeView.RootNodeView.Node);
                    }
                }

                break;

            case FindRange.EntireWorkspace:
                BehaviorTreeList behaviorTreeList = BehaviorManager.Instance as BehaviorTreeList;

                if (behaviorTreeList != null)
                {
                    foreach (Nodes.BehaviorNode behavior in behaviorTreeList.GetAllBehaviors())
                    {
                        if (behavior != null && behavior is Nodes.Node)
                        {
                            rootNodes.Add((Nodes.Node)behavior);
                        }
                    }
                }

                break;
            }

            return(rootNodes);
        }
Exemple #6
0
        public static void ShowObject(ObjectPair obj)
        {
            BehaviorTreeList behaviorTreeList = BehaviorManager.Instance as BehaviorTreeList;

            if (behaviorTreeList == null)
            {
                return;
            }

            Nodes.Node             node   = null;
            Attachments.Attachment attach = null;

            if (obj.Obj is Nodes.Node)
            {
                node = (Nodes.Node)obj.Obj;
            }
            else if (obj.Obj is Attachments.Attachment)
            {
                attach = (Attachments.Attachment)obj.Obj;
                node   = attach.Node;
            }

            if (node != null)
            {
                behaviorTreeList.ShowNode(node, obj.Root);

                if (BehaviorTreeViewDock.LastFocused != null)
                {
                    BehaviorTreeView behaviorTreeView = BehaviorTreeViewDock.LastFocused.BehaviorTreeView;

                    if (behaviorTreeView != null)
                    {
                        behaviorTreeView.SelectedNodePending       = node;
                        behaviorTreeView.SelectedAttachmentPending = attach;

                        behaviorTreeView.Refresh();
                    }
                }
            }
        }
Exemple #7
0
        /// <summary>
        /// Show the behavior tree view with highlights.
        /// </summary>
        /// <param name="agentFullname">The fullname of an agent instance, as the format of "agnetType::instanceName".</param>
        /// <param name="frame">The current frame when connecting or playing.</param>
        public static BehaviorNode ShowBehaviorTree(string agentFullname, int frame, List <string> highlightNodeIds, List <string> updatedNodeIds, HighlightBreakPoint highlightBreakPoint, Dictionary <string, FrameStatePool.NodeProfileInfos.ProfileInfo> profileInfos)
        {
            string behaviorFilename = (highlightBreakPoint != null) ? highlightBreakPoint.BehaviorFilename : FrameStatePool.GetBehaviorFilename(agentFullname, frame);

            if (!string.IsNullOrEmpty(behaviorFilename))
            {
                BehaviorTreeView behaviorTreeView = ShowBehaviorTree(behaviorFilename);
                if (behaviorTreeView != null)
                {
                    if (!Settings.Default.ShowProfilingInfo)
                    {
                        profileInfos = null;
                    }

                    behaviorTreeView.SetHighlights(highlightNodeIds, updatedNodeIds, highlightBreakPoint, profileInfos);
                    //behaviorTreeView.Focus();

                    return(behaviorTreeView.RootNode);
                }
            }

            return(null);
        }
Exemple #8
0
        /// <summary>
        /// Handles when a behaviour is supposed to be presented to the user.
        /// </summary>
        /// <param name="node">The behaviour which will be presented to the user.</param>
        private BehaviorTreeViewDock behaviorTreeList_ShowBehavior(BehaviorNode node)
        {
            // check if there is a tab for the behaviour
            BehaviorTreeViewDock dock = BehaviorTreeViewDock.GetBehaviorTreeViewDock(node);
            BehaviorTreeView control = (dock == null) ? null : dock.BehaviorTreeView;

            if (control == null)
            {
                control = new BehaviorTreeView();
                control.Dock = DockStyle.Fill;
                control.RootNode = node;
                control.BehaviorTreeList = behaviorTreeList;

                control.ClickNode += new BehaviorTreeView.ClickNodeEventDelegate(control_ClickNode);
                control.ClickEvent += new BehaviorTreeView.ClickEventEventDelegate(control_ClickEvent);

                dock = new BehaviorTreeViewDock();
                dock.Text = ((Node)node).Label;
                dock.TabText = ((Node)node).Label;
                dock.BehaviorTreeView = control;
                dock.Activated += new EventHandler(dock_Activated);
                dock.FormClosed += new FormClosedEventHandler(dock_FormClosed);
                dock.Show(dockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Document);

                dock.ToolTipText = FileManagers.FileManager.GetRelativePath(node.Filename);
            }

            dock.Focus();
            dock.MakeFocused();

            return dock;
        }
Exemple #9
0
        private void setMembers()
        {
            _methods.Clear();
            _properties.Clear();
            this.memberListBox.Items.Clear();

            if (this.instanceComboBox.SelectedIndex > -1 && this.memberTypeComboBox.SelectedIndex > -1)
            {
                AgentType agentType = null;

                // self
                if (this.instanceComboBox.SelectedIndex == 0)
                {
                    BehaviorTreeView focusedView = (BehaviorTreeViewDock.LastFocused != null) ? BehaviorTreeViewDock.LastFocused.BehaviorTreeView : null;
                    if (focusedView != null && focusedView.RootNode != null)
                    {
                        agentType = focusedView.RootNode.AgentType;
                    }
                }
                // global
                else
                {
                    agentType = Plugin.InstanceNames[this.instanceComboBox.SelectedIndex - 1].agentType_;
                }

                if (agentType != null)
                {
                    string filter = !string.IsNullOrEmpty(memberFilterTextBox.Text) ? memberFilterTextBox.Text.ToLowerInvariant() : string.Empty;

                    // method
                    if (this.memberTypeComboBox.SelectedIndex == 0 || this.memberTypeComboBox.SelectedIndex == 2)
                    {
                        IList <MethodDef> methods = agentType.GetMethods(MethodType.Method);
                        foreach (MethodDef m in methods)
                        {
                            string methodName = m.DisplayName.ToLowerInvariant();
                            if (memberFilterCheckBox.Checked && methodName.StartsWith(filter) ||
                                !memberFilterCheckBox.Checked && methodName.Contains(filter))
                            {
                                _methods.Add(m);
                                this.memberListBox.Items.Add(m.DisplayName + "()");
                            }
                        }
                    }

                    // property
                    if (this.memberTypeComboBox.SelectedIndex == 1 || this.memberTypeComboBox.SelectedIndex == 2)
                    {
                        IList <PropertyDef> properties = agentType.GetProperties();
                        foreach (PropertyDef p in properties)
                        {
                            string propName = p.DisplayName.ToLowerInvariant();
                            if (memberFilterCheckBox.Checked && propName.StartsWith(filter) ||
                                !memberFilterCheckBox.Checked && propName.Contains(filter))
                            {
                                _properties.Add(p);
                                this.memberListBox.Items.Add(p.DisplayName);
                            }
                        }
                    }
                }
            }

            this.memberCountLabel.Text = this.memberListBox.Items.Count.ToString();
        }
Exemple #10
0
        public static void ShowErrorDialog(ref ErrorCheckDialog errorDialog, BehaviorTreeList behaviorTreeList, BehaviorTreeView behaviorTreeView, Form owner, string title, List <Node.ErrorCheck> result)
        {
            // store the old position of the check dialogue and close it
            if (errorDialog != null)
            {
                errorDialog.Close();
            }

            // prepare the new dialogue
            errorDialog                  = new ErrorCheckDialog();
            errorDialog.Owner            = owner;
            errorDialog.BehaviorTreeList = behaviorTreeList;
            errorDialog.BehaviorTreeView = behaviorTreeView;
            errorDialog.Text             = title;

            // add the errors to the check dialogue
            foreach (Node.ErrorCheck check in result)
            {
                BehaviorNode behavior = check.Node != null ? check.Node.Behavior : null;

                // group the errors by the behaviour their occured in

                // get the group for the error's behaviour
                ListViewGroup group = null;

                foreach (ListViewGroup grp in errorDialog.listView.Groups)
                {
                    if (grp.Tag == behavior)
                    {
                        group = grp;
                        break;
                    }
                }

                // if there is no group, create it
                if (group == null)
                {
                    group     = new ListViewGroup(behavior != null ? ((Node)behavior).Label : "Error");
                    group.Tag = behavior;
                    errorDialog.listView.Groups.Add(group);
                }

                // create an item for the error in the group
                ListViewItem item = new ListViewItem(check.Description);
                item.Group = group;
                item.Tag   = check.Node;

                switch (check.Level)
                {
                case (ErrorCheckLevel.Message):
                    item.ImageIndex = 0;
                    break;

                case (ErrorCheckLevel.Warning):
                    item.ImageIndex = 1;
                    break;

                case (ErrorCheckLevel.Error):
                    item.ImageIndex = 2;
                    break;
                }

                errorDialog.listView.Items.Add(item);
            }

            // if no errors were found, tell the user so
            if (result.Count < 1)
            {
                errorDialog.listView.Items.Add(new ListViewItem("No Errors.", (int)ErrorCheckLevel.Message));
            }

            // show the dialogue
            errorDialog.Show();
        }
Exemple #11
0
        public static void ShowErrorDialog(ref ErrorCheckDialog errorDialog, BehaviorTreeList behaviorTreeList, BehaviorTreeView behaviorTreeView, Form owner, string title, List<Node.ErrorCheck> result)
        {
            // store the old position of the check dialogue and close it
            if (errorDialog != null)
            {
                errorDialog.Close();
            }

            // prepare the new dialogue
            errorDialog = new ErrorCheckDialog();
            errorDialog.Owner = owner;
            errorDialog.BehaviorTreeList = behaviorTreeList;
            errorDialog.BehaviorTreeView = behaviorTreeView;
            errorDialog.Text = title;

            // add the errors to the check dialogue
            foreach (Node.ErrorCheck check in result)
            {
                BehaviorNode behavior = check.Node != null ? check.Node.Behavior : null;

                // group the errors by the behaviour their occured in

                // get the group for the error's behaviour
                ListViewGroup group = null;
                foreach (ListViewGroup grp in errorDialog.listView.Groups)
                {
                    if (grp.Tag == behavior)
                    {
                        group = grp;
                        break;
                    }
                }

                // if there is no group, create it
                if (group == null)
                {
                    group = new ListViewGroup(behavior != null ? ((Node)behavior).Label : "Error");
                    group.Tag = behavior;
                    errorDialog.listView.Groups.Add(group);
                }

                // create an item for the error in the group
                ListViewItem item = new ListViewItem(check.Description);
                item.Group = group;
                item.Tag = check.Node;

                switch (check.Level)
                {
                    case (ErrorCheckLevel.Message):
                        item.ImageIndex = 0;
                        break;

                    case (ErrorCheckLevel.Warning):
                        item.ImageIndex = 1;
                        break;

                    case (ErrorCheckLevel.Error):
                        item.ImageIndex = 2;
                        break;
                }

                errorDialog.listView.Items.Add(item);
            }

            // if no errors were found, tell the user so
            if (result.Count < 1)
            {
                errorDialog.listView.Items.Add(new ListViewItem("No Errors.", (int)ErrorCheckLevel.Message));
            }

            // show the dialogue
            errorDialog.Show();
        }
        private void editSelectedPar(int rowIndex)
        {
            if (rowIndex < 0 || _rootNode == null)
            {
                return;
            }

            ParInfo par = _rootNode.Pars[rowIndex];

            List <Node.ErrorCheck> result = new List <Node.ErrorCheck>();

            Plugin.CheckPar(_rootNode, par, ref result);

            using (ParSettingsDialog parSettingsDialog = new ParSettingsDialog())
            {
                par.ParameterSet -= parameter_ParameterSet;
                parSettingsDialog.SetPar(par, _rootNode, false);

                Type   preType = par.Type;
                string preName = par.Name;

                if (DialogResult.OK == parSettingsDialog.ShowDialog())
                {
                    UndoManager.PreSave();

                    ParInfo curPar  = parSettingsDialog.GetPar();
                    Type    curType = curPar.Type;
                    string  curName = curPar.Name;

                    if (preType != curType)
                    {
                        // If this par is used by others
                        if (result.Count > 0)
                        {
                            string info = string.Format("Par {0} is used in some nodes. Are you sure change its type?", preName);
                            if (DialogResult.Cancel == MessageBox.Show(info, "Warning", MessageBoxButtons.OKCancel))
                            {
                                par.ParameterSet += parameter_ParameterSet;
                                return;
                            }
                        }

                        Plugin.ResetPar(_rootNode, par, string.Empty);
                    }
                    else if (preName != curName)
                    {
                        Plugin.ResetPar(_rootNode, par, curName);
                    }

                    par.Copy(curPar);

                    if (preType != curType)
                    {
                        RowControl rowControl = _rowControls[rowIndex];
                        rowControl.DefaultValueEditor = createValueEditor(rowIndex, curType);
                    }

                    par.ParameterSet += parameter_ParameterSet;
                    par.OnValueChanged();

                    PropertiesDock.UpdatePropertyGrids();
                    _rootNode.OnPropertyValueChanged(true);

                    UndoManager.Save((Nodes.Behavior)_rootNode);

                    UndoManager.PostSave();

                    BehaviorTreeView behaviorTreeView = BehaviorTreeViewDock.LastFocused.BehaviorTreeView;
                    if (behaviorTreeView != null)
                    {
                        behaviorTreeView.Redraw();
                    }
                }
                else
                {
                    par.ParameterSet += parameter_ParameterSet;
                }
            }
        }
 private static void setPanModeUI(BehaviorTreeView view)
 {
     view.altDragButton.Image = IsPanMode ? Resources.Transform_move1 : Resources.Transform_move2;
     view.toolTip.SetToolTip(view.altDragButton, IsPanMode ? Resources.PanMode : Resources.NormalMode);
 }