private void RootNode_WasSaved(Nodes.BehaviorNode root) { if (root == _behaviorTreeView.RootNode) { Text = TabText = ((Nodes.Node)root).Label; } }
internal static PropertiesDock CreateFloatDock(Nodes.BehaviorNode rootBehavior, object node) { PropertiesDock newDock = null; // Ignore the first one. for (int i = 1; i < __propertyGrids.Count; ++i) { if (__propertyGrids[i].SelectedObject == node) { newDock = __propertyGrids[i]; break; } } if (newDock == null) { newDock = new PropertiesDock(); newDock.Show(MainWindow.Instance.DockPanel, WeifenLuo.WinFormsUI.Docking.DockState.Float); } else { newDock.Show(); } newDock._rootBehavior = rootBehavior; newDock.SelectedObject = node; return(newDock); }
/// <summary> /// Creates a new exporter. /// </summary> /// <param name="node">The behaviour hich will be exported.</param> /// <param name="outputFolder">The folder we want to export the behaviour to.</param> /// <param name="filename">The relative filename we want to export to. You have to add your file extension.</param> public Exporter(Nodes.BehaviorNode node, string outputFolder, string filename, List <string> includedFilenames = null) { _node = node; _outputFolder = outputFolder; _filename = filename; _includedFilenames = includedFilenames; }
private void restoreBehavior(Nodes.BehaviorNode source, bool dirty) { Debug.Check(source != null && _behavior != null); if (source != null && _behavior != null) { try { _behavior.Restore((Nodes.BehaviorNode)source.Clone()); if (dirty) { // dirty this behavior to save it ((Nodes.Node)_behavior).OnPropertyValueChanged(true); } if (_behavior.IsPrefab) { resetAllPrefabInstances(_behavior); } } catch (Exception) { } } }
public void Save(Nodes.BehaviorNode behavior) { try { Debug.Check(_behavior == behavior && behavior != null); if (_undoDataArray.Count > _index + 1) { _undoDataArray.RemoveRange(_index + 1, _undoDataArray.Count - _index - 1); } _undoDataArray.Add(new UndoData(behavior)); _index = _undoDataArray.Count - 1; if (_undoDataArray.Count > 1) { _behavior.TriggerWasModified(_behavior as Nodes.Node); if (_behavior.IsPrefab) { resetAllPrefabInstances(_behavior); } } } catch (Exception) { } }
/// <summary> /// Creates a new exporter. /// </summary> /// <param name="node">The behaviour hich will be exported.</param> /// <param name="outputFolder">The folder we want to export the behaviour to.</param> /// <param name="filename">The relative filename we want to export to. You have to add your file extension.</param> public Exporter(Nodes.BehaviorNode node, string outputFolder, string filename, List<string> includedFilenames = null) { _node = node; _outputFolder = outputFolder; _filename = filename; _includedFilenames = includedFilenames; }
/// <summary> /// Returns a file manager which can be used to save or load a behaviour. /// </summary> /// <param name="filename">The name of the file we want to load or we want to save to.</param> /// <param name="node">The behaviour we want to load or save.</param> /// <returns>Returns the file manager which will be created.</returns> public FileManagers.FileManager Create(string filename, Nodes.BehaviorNode node) { object[] prms = new object[2] { filename, node }; return((FileManagers.FileManager)_type.InvokeMember(string.Empty, System.Reflection.BindingFlags.CreateInstance, null, null, prms)); }
/// <summary> /// Creates a new file manager. /// </summary> /// <param name="filename">The filename we want to load from or save to.</param> /// <param name="node">The behaviour we want to save. For loading use null.</param> public FileManager(string filename, Nodes.BehaviorNode node) { Debug.Check(Path.IsPathRooted(filename)); _filename = filename; _behavior = node; }
private void RootNode_WasModified(Nodes.BehaviorNode root, Nodes.Node node) { if (root == _behaviorTreeView.RootNode) { Text = TabText = "*" + ((Nodes.Node)root).Label; } }
private void resetAllPrefabInstances(Nodes.BehaviorNode prefabBehavior) { string relativeFilename = FileManagers.FileManager.GetRelativePath(prefabBehavior.Filename); Debug.Check(Behaviac.Design.BehaviorManager.Instance != null); IList <Nodes.BehaviorNode> openedBehaviors = Behaviac.Design.BehaviorManager.Instance.GetAllOpenedBehaviors(); foreach (Nodes.BehaviorNode behavior in openedBehaviors) { if (prefabBehavior != behavior) { bool reset = ((Nodes.Node)prefabBehavior).ResetPrefabInstances(relativeFilename, (Nodes.Node)behavior); if (reset) { UndoManager.Save(behavior); if (ModifyNodeHandler != null) { ModifyNodeHandler(behavior, true); } } } } }
public UndoData(Nodes.BehaviorNode behavior) { Debug.Check(behavior != null && behavior is Nodes.Node); if (behavior != null) { _behavior = (Nodes.BehaviorNode)behavior.Clone(); } }
public void Save(Nodes.BehaviorNode behavior, Nodes.BehaviorNode rootBehavior, Nodes.BehaviorNode referencedBehavior1, Nodes.BehaviorNode referencedBehavior2) { try { Debug.Check(_behavior == behavior && behavior != null); if (_undoDataArray.Count > _index + 1) { _undoDataArray.RemoveRange(_index + 1, _undoDataArray.Count - _index - 1); } _undoDataArray.Add(new UndoData(behavior, rootBehavior, referencedBehavior1, referencedBehavior2)); _index = _undoDataArray.Count - 1; if (_undoDataArray.Count > 1) { if (referencedBehavior1 != null && referencedBehavior2 != null) { referencedBehavior1.IsModified = true; if (referencedBehavior2 != referencedBehavior1) { referencedBehavior2.IsModified = true; } else if (referencedBehavior1 == _behavior) { restoreReferenceBehaviors(_behavior); } } else if (referencedBehavior1 != null) { referencedBehavior1.IsModified = true; if (referencedBehavior1 == _behavior) { restoreReferenceBehaviors(_behavior); } } else if (referencedBehavior2 != null) { referencedBehavior2.IsModified = true; if (referencedBehavior2 == _behavior) { restoreReferenceBehaviors(_behavior); } } else { _behavior.IsModified = true; restoreReferenceBehaviors(_behavior); } } } catch (Exception) { } }
public static void Save(Nodes.BehaviorNode behavior) { if (_saveCount > 1) { return; } Debug.Check(behavior != null); saveBehavior(behavior); }
/// <summary> /// Returns whether a behaviour was checked to be saved or not. /// </summary> /// <param name="node">The behaviour you want to check.</param> /// <returns>Returns true if the user wants the behaviour to be saved.</returns> internal bool IsSelected(Nodes.BehaviorNode node) { foreach (object obj in behaviorListBox.CheckedItems) { if (node == obj) { return(true); } } return(false); }
public static bool SetExpandedNode(NodeViewData nvd, bool isExpanded) { Debug.Check(nvd != null && nvd.Node != null); Nodes.BehaviorNode behavior = nvd.Node.Behavior; if (behavior != null && !string.IsNullOrEmpty(behavior.Filename)) { return(SetExpandedNode(behavior.RelativePath, nvd.Node.Id.ToString(), isExpanded)); } return(false); }
internal static BehaviorTreeView GetBehaviorTreeView(Nodes.BehaviorNode node) { foreach (BehaviorTreeViewDock dock in __instances) { if (dock.BehaviorTreeView.RootNode == node) { return(dock.BehaviorTreeView); } } return(null); }
public static void OnBehaviorSaved(Nodes.BehaviorNode behavior) { Debug.Check(behavior != null); string behaviorFilename = behavior.Filename; if (!string.IsNullOrEmpty(behaviorFilename) && _undoDataDict.ContainsKey(behaviorFilename)) { UndoQueue undoQueue = _undoDataDict[behaviorFilename]; undoQueue.OnBehaviorSaved(); } }
public static bool HasSetExpandedNodes(NodeViewData nvd) { Debug.Check(nvd != null && nvd.Node != null); Nodes.BehaviorNode behavior = nvd.Node.Behavior; string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; if (!string.IsNullOrEmpty(filename) && _expandedNodeDict.ContainsKey(filename)) { return(true); } return(false); }
internal static bool InspectObject(Nodes.BehaviorNode rootBehavior, object obj, bool byForce = true) { if (__propertyGrids.Count < 1) { return(false); } if (byForce && Plugin.EditMode == EditModes.Design || __propertyGrids[0].SelectedObject != obj) { __propertyGrids[0]._rootBehavior = rootBehavior; __propertyGrids[0].SelectedObject = obj; } return(true); }
internal static void CloseBehaviorTreeViewDock(Nodes.BehaviorNode node) { foreach (BehaviorTreeViewDock dock in __instances) { if (dock.BehaviorTreeView.RootNode == node) { dock.Hide(); dock.Close(); __instances.Remove(dock); break; } } }
private static void saveBehavior(Nodes.BehaviorNode behavior, Nodes.BehaviorNode rootBehavior, Nodes.BehaviorNode referencedBehavior1, Nodes.BehaviorNode referencedBehavior2) { string behaviorFilename = behavior.Filename; if (!string.IsNullOrEmpty(behaviorFilename)) { if (!_undoDataDict.ContainsKey(behaviorFilename)) { _undoDataDict[behaviorFilename] = new UndoQueue(behavior); } UndoQueue undoQueue = _undoDataDict[behaviorFilename]; undoQueue.Save(behavior, rootBehavior, referencedBehavior1, referencedBehavior2); } }
/// <summary> /// Creates a new file manager. /// </summary> /// <param name="filename">The filename we want to load from or save to.</param> /// <param name="node">The behaviour we want to save. For loading use null.</param> public FileManager(string filename, Nodes.BehaviorNode node) { if (filename.Length > 0) { if (filename.StartsWith("http://")) { _filename = filename; } else { _filename = Path.GetFullPath(filename); } } _node = node; }
private void restoreBehavior(Nodes.BehaviorNode source, bool dirty) { Debug.Check(source != null && _behavior != null); try { _behavior.Restore((Nodes.BehaviorNode)source.Clone()); if (dirty) { // dirty this behavior to save it ((Nodes.Node)_behavior).OnPropertyValueChanged(true); } restoreReferenceBehaviors(_behavior); } catch (Exception) { } }
private void listView_DoubleClick(object sender, EventArgs e) { // check if there is an item selected if (listView.SelectedItems.Count < 1) { return; } // check if this item has a node connected to it. The no-errors message doesn't Nodes.BehaviorNode node = (Nodes.BehaviorNode)listView.SelectedItems[0].Tag; if (node == null) { return; } // show the behaviour and select the node. NodeViewData nvd = _behaviorTreeList.ShowNode((Nodes.Node)node); _behaviorTreeView.SelectedNode = nvd; }
public UndoData(Nodes.BehaviorNode behavior, Nodes.BehaviorNode rootBehavior, Nodes.BehaviorNode referencedBehavior1, Nodes.BehaviorNode referencedBehavior2) { Debug.Check(behavior != null && behavior is Nodes.Node); int referCount = 0; if (referencedBehavior1 != null && referencedBehavior1 != behavior) { referCount++; } if (referencedBehavior2 != null && referencedBehavior2 != behavior) { referCount++; } _behavior = (referCount == 2) ? behavior : (Nodes.BehaviorNode)behavior.Clone(); _rootBehavior = rootBehavior; _referencedBehavior1 = referencedBehavior1; _referencedBehavior2 = referencedBehavior2; }
public override object Clone() { // Clone the hierarchy. Nodes.BehaviorNode behavior = (Nodes.BehaviorNode) this.CloneBranch(); // Set the agent type. behavior.AgentType = this.AgentType; // Clone the file manager. if (this.FileManager != null) { behavior.FileManager = (FileManagers.FileManager) this.FileManager.Clone(); behavior.FileManager.Behavior = behavior; } else { behavior.Filename = this.Filename; } return(behavior); }
public static void Save(Nodes.BehaviorNode behavior, Nodes.BehaviorNode referencedBehavior1 = null, Nodes.BehaviorNode referencedBehavior2 = null) { if (_saveCount > 1) { return; } Debug.Check(behavior != null); if (referencedBehavior1 != null && referencedBehavior1 != behavior) { saveBehavior(referencedBehavior1, behavior, null, null); } if (referencedBehavior2 != null && referencedBehavior2 != behavior && referencedBehavior2 != referencedBehavior1) { saveBehavior(referencedBehavior2, behavior, null, null); } saveBehavior(behavior, behavior, referencedBehavior1, referencedBehavior2); }
public static bool IsExpandedNode(NodeViewData nvd) { Debug.Check(nvd != null && nvd.Node != null); bool defaultExpanded = !(nvd.Node is Nodes.ReferencedBehavior); if (defaultExpanded) { foreach (NodeViewData child in nvd.Children) { if (!child.CanBeExpanded()) { defaultExpanded = false; break; } } } Nodes.BehaviorNode behavior = nvd.Node.Behavior; string filename = (behavior != null) && !string.IsNullOrEmpty(behavior.Filename) ? behavior.RelativePath : string.Empty; if (!string.IsNullOrEmpty(filename) && _expandedNodeDict.ContainsKey(filename)) { Dictionary <string, bool> expandedNodes = _expandedNodeDict[filename]; string id = nvd.Node.Id.ToString(); if (!expandedNodes.ContainsKey(id)) { return(defaultExpanded); } return(expandedNodes[id]); } else { defaultExpanded = true; } return(defaultExpanded); }
public NodeViewDataReferencedBehavior(NodeViewData parent, Nodes.BehaviorNode rootBehavior, Nodes.ReferencedBehaviorNode node) : base(parent, rootBehavior, (Node)node) { }
private void editMember(int selectedMemberIndex, bool resetMemberSelectedIndex) { int index = this.typeListBox.SelectedIndex; int memberIndex = selectedMemberIndex; if (index > -1 && memberIndex > -1) { // agent if (index < Plugin.AgentTypes.Count) { AgentType agent = Plugin.AgentTypes[index]; MemberItem item = this.memberListBox.Items[memberIndex] as MemberItem; bool bEdit = false; if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Property) { PropertyDef prop = getPropertyByIndex(memberIndex); if (prop != null && this._metaPropertyPanel != null) { bool canBeEdit = prop.IsCustomized | prop.IsPar; if (prop.IsPar) { //don't allow to edit automatically added "_$local_task_param_$_0" if (prop.IsAddedAutomatically) { canBeEdit = false; } } Nodes.Behavior root = getCurrentRootNode() as Nodes.Behavior; PropertyDef curProp = this._metaPropertyPanel.GetProperty(); Debug.Check(curProp != null); if (prop.IsMember && !prop.IsChangeableType) { prop.IsExportedButAlsoCustomized = curProp.IsExportedButAlsoCustomized; bEdit = true; } else if ((prop.IsChangeableType || canBeEdit) && (curProp.Name == prop.Name || checkMembersInWorkspace(agent, false, null, curProp))) { if (curProp.IsPar || curProp.IsPar != prop.IsPar) { _isParDirtyBehavior = root; } if (curProp.Type != prop.Type) { resetMembersInWorkspace(agent, true, null, curProp); } else if (curProp.Name != prop.Name) { resetMembersInWorkspace(agent, false, null, curProp); } if (Plugin.IsArrayType(prop.Type)) { PropertyDef elementProperty = agent.GetPropertyByName(prop.BasicName + "[]"); if (elementProperty != null && elementProperty.IsArrayElement) { elementProperty.SetArrayElement(curProp); } } prop.CopyFrom(curProp); item.DisplayName = getPrefixString(prop) + prop.DisplayName; bEdit = true; if (curProp.IsPar != prop.IsPar) { bEdit = false; Workspace.Current.IsBlackboardDirty = true; this.memberListBox.Items.RemoveAt(memberIndex); if (curProp.IsPar) { if (agent.RemoveProperty(prop)) { if (root != null) { root.LocalVars.Add(curProp as ParInfo); UndoManager.Save(root); } int lastParIndex = getLastParIndex(); this.memberListBox.Items.Insert(lastParIndex, new MemberItem(Par_Str + curProp.DisplayName, curProp)); if (resetMemberSelectedIndex) this.memberListBox.SelectedIndex = lastParIndex; } } else { if (root != null && root.LocalVars.Remove(prop as ParInfo)) { UndoManager.Save(root); } agent.RemoveProperty(prop); agent.AddProperty(curProp); this.memberListBox.Items.Add(new MemberItem(Customized_Str + curProp.DisplayName, curProp)); if (resetMemberSelectedIndex) this.memberListBox.SelectedIndex = this.memberListBox.Items.Count - 1; } BehaviorTreeViewDock.RefreshAll(); PropertiesDock.UpdatePropertyGrids(); } else { if (curProp.IsPar) { if (root != null) { UndoManager.Save(root); } } } } } } else if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Method || this.memberTypeComboBox.SelectedIndex == (int)MemberType.Task) { MethodDef method = getMethodByIndex(memberIndex); if (method != null && this._metaMethodPanel != null) { MethodDef curMethod = this._metaMethodPanel.GetMethod(); Debug.Check(curMethod != null); if ((method.IsChangeableType || method.IsCustomized) && checkMembersInWorkspace(agent, false, curMethod, null)) { resetMembersInWorkspace(agent, false, curMethod, null); method.CopyFrom(curMethod); item.DisplayName = getPrefixString(method) + method.DisplayName; bEdit = true; } } } if (bEdit) { _lastSelectedType = ""; Workspace.Current.IsBlackboardDirty = true; // update the memberListBox this.memberListBox.Items.RemoveAt(memberIndex); this.memberListBox.Items.Insert(memberIndex, item); if (resetMemberSelectedIndex) this.memberListBox.SelectedIndex = memberIndex; BehaviorTreeViewDock.RefreshAll(); PropertiesDock.UpdatePropertyGrids(); } } else { bool bEdit = false; if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Property) { // enum if (index - Plugin.AgentTypes.Count < CustomizedTypeManager.Instance.Enums.Count) { if (this._editEnumMemberPanel != null) { CustomizedEnum.CustomizedEnumMember enumMember = this._editEnumMemberPanel.GetEnumMember(); Debug.Check(enumMember != null); CustomizedEnum customizedEnum = CustomizedTypeManager.Instance.Enums[index - Plugin.AgentTypes.Count]; customizedEnum.Members[memberIndex] = enumMember; this.memberListBox.Items[memberIndex] = Customized_Str + enumMember.DisplayName; bEdit = true; _lastSelectedType = customizedEnum.Name; // refresh the workspace to load the type save(true); } } // struct else { if (this._metaPropertyPanel != null) { Workspace.Current.IsBlackboardDirty = true; PropertyDef prop = this._metaPropertyPanel.GetProperty(); Debug.Check(prop != null); CustomizedStruct customizedStruct = CustomizedTypeManager.Instance.Structs[index - Plugin.AgentTypes.Count - CustomizedTypeManager.Instance.Enums.Count]; customizedStruct.Properties[memberIndex] = prop; this.memberListBox.Items[memberIndex] = Customized_Str + prop.DisplayName; bEdit = true; _lastSelectedType = customizedStruct.Name; // refresh the workspace to load the type save(true); } } } if (bEdit) { Workspace.Current.IsBlackboardDirty = true; BehaviorTreeViewDock.RefreshAll(); PropertiesDock.UpdatePropertyGrids(); } } } }
private void swapTwoProperties(int index1, int index2) { int index = this.typeListBox.SelectedIndex; if (index > -1 && index1 > -1 && index1 < this.memberListBox.Items.Count && index2 > -1 && index2 < this.memberListBox.Items.Count) { AgentType agent = Plugin.AgentTypes[index]; bool swapSucceeded = false; if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Property) { PropertyDef prop1 = getPropertyByIndex(index1); PropertyDef prop2 = getPropertyByIndex(index2); if (prop1 != null && prop2 != null) { swapSucceeded = agent.SwapTwoProperties(prop1, prop2); if (swapSucceeded && prop1.IsPar) { if (prop1.IsPar && prop2.IsPar) { Nodes.BehaviorNode root = getCurrentRootNode(); if (root != null) { Nodes.Node node = (Nodes.Node)root; ParInfo prePar = node.LocalVars[index2]; node.LocalVars[index2] = node.LocalVars[index1]; node.LocalVars[index1] = prePar; UndoManager.Save(root); _isParDirtyBehavior = root; } } } } } else if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Method || this.memberTypeComboBox.SelectedIndex == (int)MemberType.Task) { MethodDef method1 = getMethodByIndex(index1); MethodDef method2 = getMethodByIndex(index2); if (method1 != null && method2 != null) { swapSucceeded = agent.SwapTwoMethods(method1, method2); } } if (swapSucceeded) { object preItem = this.memberListBox.Items[index2]; this.memberListBox.Items[index2] = this.memberListBox.Items[index1]; this.memberListBox.Items[index1] = preItem; this.memberListBox.SelectedIndex = index2; Workspace.Current.IsBlackboardDirty = true; } } }
private void save(bool refreshWorkspace = false) { if (!refreshWorkspace) { apply(true, this.typeListBox.SelectedIndex, this.memberListBox.SelectedIndex, true); } bool isBlackboardDirty = Workspace.Current.IsBlackboardDirty; Workspace.SaveExtraMeta(Workspace.Current); Workspace.SaveCustomMeta(Workspace.Current); if (_isParDirtyBehavior != null) { Nodes.BehaviorNode root = getCurrentRootNode(); if (root != null && _isParDirtyBehavior == root && root.IsModified) { BehaviorTreeViewDock dock = getCurrentBehaviorTreeDock(); if (dock.BehaviorTreeView.Save(false)) { _isParDirtyBehavior = null; } } } // save the export path string wsFilename = Workspace.Current.FileName.Replace('/', '\\'); string exportFolder = this.exportTypeTextBox.Text.Replace('/', '\\'); exportFolder = Workspace.MakeRelative(exportFolder, wsFilename, true, true); exportFolder = exportFolder.Replace('\\', '/'); Workspace.Current.SetExportInfo(Plugin.SourceLanguage, Workspace.Current.ShouldBeExported(Plugin.SourceLanguage), Workspace.Current.ExportedUnifiedFile(Plugin.SourceLanguage), exportFolder); Workspace.SaveWorkspaceFile(Workspace.Current); if (refreshWorkspace && isBlackboardDirty) { // refresh the meta Debug.Check(Workspace.Current != null); MainWindow.Instance.SetWorkspace(Workspace.Current.FileName, false, true); } PropertiesDock.InspectObject(null, null); }
private void addMember() { int index = this.typeListBox.SelectedIndex; if (index > -1) { // agent if (index < Plugin.AgentTypes.Count) { AgentType agent = Plugin.AgentTypes[index]; if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Property) { Nodes.Behavior root = getCurrentRootNode() as Nodes.Behavior; MetaPropertyDialog propertyDialog = new MetaPropertyDialog(true, agent, null, null, root != null); if (DialogResult.OK == propertyDialog.ShowDialog()) { PropertyDef prop = propertyDialog.GetProperty(); Debug.Check(prop != null); if (agent.AddProperty(prop)) { Workspace.Current.IsBlackboardDirty = true; if (prop.IsPar) { if (root != null) { root.LocalVars.Add(prop as ParInfo); UndoManager.Save(root); _isParDirtyBehavior = root; } int lastParIndex = getLastParIndex(); this.memberListBox.Items.Insert(lastParIndex, new MemberItem(Par_Str + prop.DisplayName, prop)); this.memberListBox.SelectedIndex = lastParIndex; } else { this.memberListBox.Items.Add(new MemberItem(Customized_Str + prop.DisplayName, prop)); this.memberListBox.SelectedIndex = this.memberListBox.Items.Count - 1; } _lastSelectedType = ""; } } } else if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Method || this.memberTypeComboBox.SelectedIndex == (int)MemberType.Task) { MetaMethodDialog methodDialog = new MetaMethodDialog(agent, null, (MemberType)this.memberTypeComboBox.SelectedIndex); if (DialogResult.OK == methodDialog.ShowDialog()) { MethodDef method = methodDialog.GetMethod(); Debug.Check(method != null); if (agent.AddMethod(method)) { Workspace.Current.IsBlackboardDirty = true; this.memberListBox.Items.Add(new MemberItem(Customized_Str + method.DisplayName, method)); this.memberListBox.SelectedIndex = this.memberListBox.Items.Count - 1; _lastSelectedType = ""; } } } } else { if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Property) { // enum if (index - Plugin.AgentTypes.Count < CustomizedTypeManager.Instance.Enums.Count) { CustomizedEnum customizedEnum = CustomizedTypeManager.Instance.Enums[index - Plugin.AgentTypes.Count]; EditEnumMemberDialog enumMemberDialog = new EditEnumMemberDialog(customizedEnum, null); if (DialogResult.OK == enumMemberDialog.ShowDialog()) { Workspace.Current.IsBlackboardDirty = true; CustomizedEnum.CustomizedEnumMember enumMember = enumMemberDialog.GetEnumMember(); Debug.Check(enumMember != null); customizedEnum.Members.Add(enumMember); this.memberListBox.Items.Add(Customized_Str + enumMember.DisplayName); this.memberListBox.SelectedIndex = this.memberListBox.Items.Count - 1; _lastSelectedType = customizedEnum.Name; // refresh the workspace to load the type save(true); } } // struct else { CustomizedStruct customizedStruct = CustomizedTypeManager.Instance.Structs[index - Plugin.AgentTypes.Count - CustomizedTypeManager.Instance.Enums.Count]; MetaPropertyDialog propertyDialog = new MetaPropertyDialog(true, null, customizedStruct, null, false); if (DialogResult.OK == propertyDialog.ShowDialog()) { Workspace.Current.IsBlackboardDirty = true; PropertyDef prop = propertyDialog.GetProperty(); Debug.Check(prop != null); customizedStruct.Properties.Add(prop); this.memberListBox.Items.Add(Customized_Str + prop.DisplayName); this.memberListBox.SelectedIndex = this.memberListBox.Items.Count - 1; _lastSelectedType = customizedStruct.Name; // refresh the workspace to load the type save(true); } } } } } }
private void removeSelectedMember() { int index = this.typeListBox.SelectedIndex; int memberIndex = this.memberListBox.SelectedIndex; if (index > -1 && memberIndex > -1) { // agent if (index < Plugin.AgentTypes.Count) { AgentType agent = Plugin.AgentTypes[index]; bool bRemoved = false; if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Property) { PropertyDef prop = getPropertyByIndex(memberIndex); if (prop != null) { prop.OldName = prop.Name; } if (prop != null && (prop.IsCustomized || prop.IsPar) && !prop.IsAddedAutomatically && checkMembersInWorkspace(agent, true, null, prop) && agent.RemoveProperty(prop)) { bRemoved = true; this.memberListBox.Items.RemoveAt(memberIndex); if (prop.IsPar) { Nodes.BehaviorNode root = getCurrentRootNode(); if (root != null && ((Nodes.Node)root).LocalVars.Remove(prop as ParInfo)) { UndoManager.Save(root); _isParDirtyBehavior = root; } } if (memberIndex >= this.memberListBox.Items.Count) { memberIndex = this.memberListBox.Items.Count - 1; } this.memberListBox.SelectedIndex = memberIndex; resetMembersInWorkspace(agent, true, null, prop); } } else if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Method || this.memberTypeComboBox.SelectedIndex == (int)MemberType.Task) { MethodDef method = getMethodByIndex(memberIndex); if (method != null) { method.OldName = method.Name; } if (method != null && method.IsCustomized && checkMembersInWorkspace(agent, true, method, null) && agent.RemoveMethod(method)) { bRemoved = true; this.memberListBox.Items.RemoveAt(memberIndex); if (memberIndex >= this.memberListBox.Items.Count) { memberIndex = this.memberListBox.Items.Count - 1; } this.memberListBox.SelectedIndex = memberIndex; resetMembersInWorkspace(agent, true, method, null); } } if (bRemoved) { setDescription(); _lastSelectedType = ""; Workspace.Current.IsBlackboardDirty = true; BehaviorTreeViewDock.RefreshAll(); PropertiesDock.UpdatePropertyGrids(); } } else { if (this.memberTypeComboBox.SelectedIndex == (int)MemberType.Property) { // enum if (index - Plugin.AgentTypes.Count < CustomizedTypeManager.Instance.Enums.Count) { CustomizedEnum customizedEnum = CustomizedTypeManager.Instance.Enums[index - Plugin.AgentTypes.Count]; customizedEnum.Members.RemoveAt(memberIndex); _lastSelectedType = customizedEnum.Name; } // struct else { CustomizedStruct customizedStruct = CustomizedTypeManager.Instance.Structs[index - Plugin.AgentTypes.Count - CustomizedTypeManager.Instance.Enums.Count]; customizedStruct.Properties.RemoveAt(memberIndex); _lastSelectedType = customizedStruct.Name; } this.memberListBox.Items.RemoveAt(memberIndex); if (memberIndex >= this.memberListBox.Items.Count) { memberIndex = this.memberListBox.Items.Count - 1; } this.memberListBox.SelectedIndex = memberIndex; setDescription(); Workspace.Current.IsBlackboardDirty = true; BehaviorTreeViewDock.RefreshAll(); PropertiesDock.UpdatePropertyGrids(); // refresh the workspace to load the type save(true); } } } }
public UndoData(Nodes.BehaviorNode behavior) { Debug.Check(behavior != null && behavior is Nodes.Node); _behavior = (Nodes.BehaviorNode)behavior.Clone(); }
/// <summary> /// Creates a new file manager. /// </summary> /// <param name="filename">The filename we want to load from or save to.</param> /// <param name="node">The behaviour we want to save. For loading use null.</param> public FileManager(string filename, Nodes.BehaviorNode node) { _filename= Path.GetFullPath(filename); _node= node; }
/// <summary> /// Creates a new exporter. /// </summary> /// <param name="node">The behaviour hich will be exported.</param> /// <param name="outputFolder">The folder we want to export the behaviour to.</param> /// <param name="filename">The relative filename we want to export to. You have to add your file extension.</param> public Exporter(Nodes.BehaviorNode node, string outputFolder, string filename) { _outputFolder= outputFolder; _filename= filename; _node= node; }
public NodeViewDataReferencedBehavior(NodeViewData parent, Nodes.BehaviorNode rootBehavior, Nodes.ReferencedBehaviorNode node, Pen borderPen, Brush backgroundBrush, string label, string description) : base(parent, rootBehavior, (Node)node, borderPen, backgroundBrush, label, description) { }
/// <summary> /// Resets the loaded behaviour. This must be done before every user triggered loading process. /// </summary> public static void ResetLoadedBehavior() { _loadedBehavior= null; }
/// <summary> /// Creates an instance of an exporter which will be used to export a behaviour. /// To export the behaviour, the Export() method must be called. /// </summary> /// <param name="node">The behaviour you want to export.</param> /// <param name="outputFolder">The folder you want to export the behaviour to.</param> /// <param name="filename">The relative filename you want to export the behaviour to.</param> /// <returns>Returns the created exporter.</returns> public Exporters.Exporter Create(Nodes.BehaviorNode node, string outputFolder, string filename) { object[] prms = new object[] { node, outputFolder, filename }; return((Exporters.Exporter)_type.InvokeMember(string.Empty, System.Reflection.BindingFlags.CreateInstance, null, null, prms)); }
private void save(bool refreshWorkspace = false) { if (!refreshWorkspace) { apply(true, this.typeListBox.SelectedIndex, this.memberListBox.SelectedIndex, true); } bool isBlackboardDirty = Workspace.Current.IsBlackboardDirty; Workspace.SaveCustomMeta(Workspace.Current); if (_isParDirtyBehavior != null) { Nodes.BehaviorNode root = getCurrentRootNode(); if (root != null && _isParDirtyBehavior == root && root.IsModified) { BehaviorTreeViewDock dock = getCurrentBehaviorTreeDock(); if (dock.BehaviorTreeView.Save(false)) { _isParDirtyBehavior = null; } } } if (refreshWorkspace && isBlackboardDirty) { // refresh the meta Debug.Check(Workspace.Current != null); MainWindow.Instance.SetWorkspace(Workspace.Current.FileName, false, true); } }
public UndoData(Nodes.BehaviorNode behavior, Nodes.BehaviorNode rootBehavior, Nodes.BehaviorNode referencedBehavior1, Nodes.BehaviorNode referencedBehavior2) { Debug.Check(behavior != null && behavior is Nodes.Node); int referCount = 0; if (referencedBehavior1 != null && referencedBehavior1 != behavior) referCount++; if (referencedBehavior2 != null && referencedBehavior2 != behavior) referCount++; _behavior = (referCount == 2) ? behavior : (Nodes.BehaviorNode)behavior.Clone(); _rootBehavior = rootBehavior; _referencedBehavior1 = referencedBehavior1; _referencedBehavior2 = referencedBehavior2; }
/// <summary> /// Creates a new file manager. /// </summary> /// <param name="filename">The filename we want to load from or save to.</param> /// <param name="node">The behaviour we want to save. For loading use null.</param> public FileManager(string filename, Nodes.BehaviorNode node) { if (filename.Length > 0) { if (filename.StartsWith ("http://")) { _filename=filename; } else{ _filename = Path.GetFullPath(filename); } } _node= node; }
public UndoQueue(Nodes.BehaviorNode behavior) { Debug.Check(behavior != null); _behavior = behavior; }