private string CreateParameters(Skill.Editor.AI.ParameterDataCollection parameters) { StringBuilder result = new StringBuilder(); result.Append("new Skill.Framework.AI.BehaviorParameterCollection( new Skill.Framework.AI.BehaviorParameter[] { "); foreach (var p in parameters) { switch (p.Type) { case ParameterType.Int: result.Append(string.Format("new Skill.Framework.AI.BehaviorParameter(\"{0}\",{1}),", p.Name, p.Value)); break; case ParameterType.Bool: result.Append(string.Format("new Skill.Framework.AI.BehaviorParameter(\"{0}\",{1}),", p.Name, p.Value.ToString().ToLower())); break; case ParameterType.Float: result.Append(string.Format("new Skill.Framework.AI.BehaviorParameter(\"{0}\",{1}f),", p.Name, p.Value)); break; case ParameterType.String: result.Append(string.Format("new Skill.Framework.AI.BehaviorParameter(\"{0}\",\"{1}\"),", p.Name, p.Value)); break; } } result.Append("} )"); return(result.ToString()); }
public void Match(ParameterDataCollection difinition) { foreach (var p in difinition) { bool found = false; foreach (var item in this) { if (item.Name == p.Name) { found = true; break; } } if (!found) { this.Add(new ParameterData() { Name = p.Name, Type = p.Type, Value = p.Value }); } } int index = 0; while (index < this.Count) { var mp = this[index]; bool found = false; foreach (var item in difinition) { if (item.Name == mp.Name) { found = true; break; } } if (!found) { this.Remove(mp); continue; } index++; } }
public void MatchParameters() { List <BehaviorData> list = new List <BehaviorData>(); if (States != null) { foreach (var s in States) { CreateList(list, s); } } if (ExtraBehaviors != null) {// add extra behaviors foreach (var b in ExtraBehaviors) { if (!list.Contains(b)) { list.Add(b); } } } foreach (var b in list) { for (int i = 0; i < b.Count; i++) { if (b[i] is IParameterData) { ParameterDataCollection parameters = b.GetParameters(i); if (parameters != null) { ParameterDataCollection difinitions = ((IParameterData)b[i]).ParameterDifinition; parameters.Match(difinitions); } } } } }
public ParameterEditor(IBehaviorItem item, ParameterDataCollection dataDifinition, ParameterDataCollection data) { _Item = item; _DataDifinition = dataDifinition; _Data = data; this._RefreshStyle = true; this.RowDefinitions.Add(16, Skill.Framework.UI.GridUnitType.Pixel); // title this.RowDefinitions.Add(1, Skill.Framework.UI.GridUnitType.Star); // list this.RowDefinitions.Add(16, Skill.Framework.UI.GridUnitType.Pixel); // buttons _Title = new Framework.UI.Label { Row = 0, Text = "Parameters" }; this.Controls.Add(_Title); _FieldsList = new Skill.Framework.UI.ListBox() { Row = 1 }; _FieldsList.DisableFocusable(); _FieldsList.BackgroundVisible = true; this.Controls.Add(_FieldsList); _ButtonsPanel = new Framework.UI.Grid() { Row = 2 }; _ButtonsPanel.ColumnDefinitions.Add(1, Skill.Framework.UI.GridUnitType.Star); _ButtonsPanel.ColumnDefinitions.Add(20, Skill.Framework.UI.GridUnitType.Pixel); _ButtonsPanel.ColumnDefinitions.Add(20, Skill.Framework.UI.GridUnitType.Pixel); this.Controls.Add(_ButtonsPanel); _BtnAddImage = new Framework.UI.Image() { Column = 1 }; _ButtonsPanel.Controls.Add(_BtnAddImage); _BtnAdd = new UI.IntPopup() { Column = 1 }; _BtnAdd.Options.Add(new UI.PopupOption(1, "float")); _BtnAdd.Options.Add(new UI.PopupOption(2, "int")); _BtnAdd.Options.Add(new UI.PopupOption(3, "bool")); _BtnAdd.Options.Add(new UI.PopupOption(4, "string")); _ButtonsPanel.Controls.Add(_BtnAdd); _BtnRemove = new Framework.UI.Button() { Column = 2, IsEnabled = false }; _ButtonsPanel.Controls.Add(_BtnRemove); _BtnAdd.OptionChanged += _BtnAdd_OptionChanged; _BtnRemove.Click += _BtnRemove_Click; _FieldsList.SelectionChanged += _FieldsList_SelectionChanged; Rebuild(); }
public void Load(XmlElement e) { this.Name = e.GetAttributeValueAsString("Name", this.Name); this.DefaultState = e.GetAttributeValueAsString("DefaultState", DefaultDestinationState); this.ExpandMethods = e.GetAttributeValueAsBoolean("ExpandMethods", false); this.ExtraBehaviors = null; List <BehaviorData> list = new List <BehaviorData>(); XmlElement behaviorsElement = e["Behaviors"]; if (behaviorsElement != null) { foreach (var behaviorElement in behaviorsElement) { BehaviorData behavior = CreateBehaviorFrom(behaviorElement); if (behavior != null) { behavior.Load(behaviorElement); list.Add(behavior); } } } List <BehaviorTreeStateData> states = new List <BehaviorTreeStateData>(); foreach (var b in list) { if (b.BehaviorType == Skill.Framework.AI.BehaviorType.Composite && ((CompositeData)b).CompositeType == Skill.Framework.AI.CompositeType.State) { states.Add(b as BehaviorTreeStateData); } } // load hierarchy XmlElement hierarchy = e["Hierarchy"]; if (hierarchy != null) { foreach (var behaviorChildrenElement in hierarchy) { int behaviorId = behaviorChildrenElement.GetAttributeValueAsInt("Id", -2); BehaviorData behavior = FindById(list, behaviorId); if (behavior != null) { foreach (var containerElement in behaviorChildrenElement) { int childId = containerElement.GetAttributeValueAsInt("ChildId", -2); BehaviorData child = FindById(list, childId); if (child != null) { XmlElement parametersElement = containerElement[ParameterDataCollection.ElementName]; if (parametersElement != null) { ParameterDataCollection parameters = new ParameterDataCollection(); parameters.Load(parametersElement); behavior.Add(child, parameters); } else { behavior.Add(child); } } } } } } foreach (var b in list) { b.FixParameters(); } if (states.Count > 0) { this.States = states.ToArray(); } else { // try to load as previouse version format int rootId = e.GetAttributeValueAsInt("RootId", 0); BehaviorData root = FindById(list, rootId); if (root != null && root.BehaviorType == Skill.Framework.AI.BehaviorType.Composite && ((CompositeData)root).CompositeType == Skill.Framework.AI.CompositeType.Priority) { PrioritySelectorData ps = root as PrioritySelectorData; BehaviorTreeStateData state = new BehaviorTreeStateData(); state.Comment = ps.Comment; state.Concurrency = ps.Concurrency; state.Id = ps.Id; state.Name = ps.Name; state.Priority = ps.Priority; state.Weight = ps.Weight; foreach (var child in ps) { state.Add(child); } this.States = new BehaviorTreeStateData[] { state }; DefaultState = state.Name; } else { this.States = new BehaviorTreeStateData[] { new BehaviorTreeStateData() { Name = DefaultDestinationState } }; } } List <BehaviorData> extra = new List <BehaviorData>(); foreach (var b in list) { if (!IsInHierarchy(b)) { extra.Add(b); } } if (extra.Count > 0) { ExtraBehaviors = extra.ToArray(); } }
public ParameterDifinitionEditor(ListItem owner, ParameterDataCollection data) { this._OwnerListItem = owner; this._Data = data; this.RowDefinitions.Add(24, GridUnitType.Pixel); // title this.RowDefinitions.Add(18, GridUnitType.Pixel); // header this.RowDefinitions.Add(1, GridUnitType.Star); // items this.RowDefinitions.Add(20, GridUnitType.Pixel); // buttons Skill.Editor.UI.DropShadowLabel title = new UI.DropShadowLabel() { Text = "Parameter Difinition", Height = 20, Margin = new Thickness(0, 0, 0, 4) }; this.Controls.Add(title); _HeaderBg = new Box() { Row = 1, Style = (GUIStyle)"RL Header" }; this.Controls.Add(_HeaderBg); _Header = new Grid() { Row = 1 }; _Header.ColumnDefinitions.Add(1, GridUnitType.Star); _Header.ColumnDefinitions.Add(2, GridUnitType.Star); _Header.ColumnDefinitions.Add(2, GridUnitType.Star); _Header.Controls.Add(new Label() { Column = 0, Text = "Type" }); _Header.Controls.Add(new Label() { Column = 1, Text = "Name" }); _Header.Controls.Add(new Label() { Column = 2, Text = "Default Value" }); this.Controls.Add(_Header); _LbItems = new Framework.UI.ListBox() { Row = 2 }; _LbItems.DisableFocusable(); _LbItems.BackgroundVisible = true; _LbItems.Background.Style = (GUIStyle)"RL Background"; this.Controls.Add(_LbItems); _PnlButtons = new Grid() { Row = 3 }; _PnlButtons.ColumnDefinitions.Add(1, GridUnitType.Star); _PnlButtons.ColumnDefinitions.Add(20, GridUnitType.Pixel); // btn add _PnlButtons.ColumnDefinitions.Add(20, GridUnitType.Pixel); // btn remove this.Controls.Add(_PnlButtons); _BtnAdd = new Button { Column = 1 }; _PnlButtons.Controls.Add(_BtnAdd); _BtnRemove = new Button() { Column = 2, IsEnabled = false }; _PnlButtons.Controls.Add(_BtnRemove); _LbItems.SelectionChanged += _LbItems_SelectionChanged; _BtnAdd.Click += _BtnAdd_Click; _BtnRemove.Click += _BtnRemove_Click; for (int i = 0; i < _Data.Count; i++) { ParameterItem item = new ParameterItem(_OwnerListItem, _Data[i]); _LbItems.Items.Add(item); } }
public ConditionData() : base("NewCondition") { ParameterDifinition = new ParameterDataCollection(); }