private void update() { if (_arrayProperty != null) { textBox.Text = DesignerArray.RetrieveDisplayValue(_arrayProperty.ItemList); button.Enabled = true; } else if (_structProperty != null) { //textBox.Text = "(Multiple properties)"; MethodDef method = null; Nodes.Action action = this._object as Nodes.Action; if (action != null) { method = action.Method; } textBox.Text = DesignerPropertyUtility.RetrieveDisplayValue(_structProperty.Owner, method, _structProperty.Name, _structProperty.ElmentIndexInArray); button.Enabled = true; } else { textBox.Text = "null"; //textBox.Text = DesignerPropertyUtility.RetrieveDisplayValue(_property, null, null); button.Enabled = false; } }
private void buildPropertyGrid(int selectedIndex = 0) { propertyGrid.PropertiesVisible(false, false); propertyGrid.ClearProperties(); if (_arrayProperty != null) { _selectedLabel = null; if (_arrayProperty.ItemList.Count > 0) { Type editorType = Plugin.InvokeEditorType(_arrayProperty.ItemType); Debug.Check(editorType != null); for (int index = 0; index < _arrayProperty.ItemList.Count; index++) { createArrayPropertyEditor(index, editorType, index == selectedIndex); } propertyGrid.UpdateSizes(); propertyGrid.PropertiesVisible(true, false); } } else if (_structProperty != null) { downButton.Visible = false; upButton.Visible = false; appendButton.Visible = false; insertButton.Visible = false; removeButton.Visible = false; //tableLayoutPanel.SetRowSpan(propertyGrid, tableLayoutPanel.RowCount - 1); //tableLayoutPanel.SetColumnSpan(propertyGrid, tableLayoutPanel.ColumnCount); Nodes.Action action = this._object as Nodes.Action; if (action == null) { updateStructProperties(_structProperty.Owner); } else { MethodDef method = action.Method; if (method != null) { this.createParamEditor(_structProperty, action); } } } }
public static bool parseParam(List <Nodes.Node.ErrorCheck> result, DefaultObject node, MethodDef method, MethodDef.Param par, string param) { string propName = null; if (param[0] == '\"') { param = param.Substring(1, param.Length - 2); } else if (param[0] == '{') //struct { //to set it as action.Method is used in the following parsing Nodes.Action action = node as Nodes.Action; if (action != null && action.Method == null) { action.Method = method; } } else { string noStaticParam = param.Replace("static ", ""); int index = noStaticParam.IndexOf(" "); if (index >= 0) { propName = noStaticParam.Substring(index + 1); } } bool bOk = false; if (propName != null) { VariableDef var = setParameter(result, node, propName); if (var != null) { par.Value = var; bOk = true; } } else { bOk = Plugin.InvokeTypeParser(result, par.Type, param, (object value) => par.Value = value, node, par.Name); } return(bOk); }
protected override void GenerateMember(Node node, StringWriter stream, string indent) { base.GenerateMember(node, stream, indent); Nodes.Action action = node as Nodes.Action; if (action == null) { return; } if (action.Method != null && !isNullMethod(action.Method)) { MethodCsExporter.GenerateClassMember(action.Method, stream, indent, "method"); } }
protected override void GenerateConstructor(Node node, StringWriter stream, string indent, string className) { base.GenerateConstructor(node, stream, indent, className); Nodes.Action action = node as Nodes.Action; if (action == null) { return; } if (action.Method != null) { MethodCppExporter.GenerateClassConstructor(node, action.Method, stream, indent, "method"); } }
public static bool parseParam(List <Nodes.Node.ErrorCheck> result, DefaultObject node, MethodDef method, MethodDef.Param par, string param) { string[] tokens = null; if (param[0] == '\"') { param = param.Substring(1, param.Length - 2); } else if (param[0] == '{') { //struct //to set it as action.Method is used in the following parsing Nodes.Action action = node as Nodes.Action; if (action != null) { action.Method = method; } } else { tokens = param.Split(' '); } bool bOk = false; if (tokens != null && tokens.Length > 1) { //par VariableDef var = setParameter(result, node, tokens[tokens.Length - 1]); if (var != null) { par.Value = var; bOk = true; } } else { bOk = Plugin.InvokeTypeParser(result, par.Type, param, (object value) => par.Value = value, node, par.Name); } return(bOk); }
void createParamEditor(DesignerStructPropertyInfo structParam, Nodes.Action action) { MethodDef method = action.Method; if (method != null) { List <MethodDef.Param> parameters = method.GetParams(structParam); if (parameters != null && parameters.Count > 0) { foreach (MethodDef.Param p in parameters) { Type editorType = null; if (structParam.ElmentIndexInArray != -1) { object member = p.Value; editorType = p.Attribute.GetEditorType(member); } else { editorType = typeof(DesignerParameterComboEnumEditor); } string arugmentsName = " " + p.DisplayName; Label label = propertyGrid.AddProperty(arugmentsName, editorType, p.Attribute != null ? p.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly) : false); label.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))); label.MouseEnter += label_MouseEnter; DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag; editor.Enabled = true; //editor.SetRootNode(this._node); editor.SetParameter(p, action, false); editor.MouseEnter += new EventHandler(editor_MouseEnter); editor.ValueWasAssigned(); editor.ValueWasChanged += editor_ValueWasChanged; } { propertyGrid.UpdateSizes(); propertyGrid.PropertiesVisible(true, true); } } } }
protected override void GenerateConstructor(Node node, StringWriter stream, string indent, string className) { base.GenerateConstructor(node, stream, indent, className); Nodes.Action action = node as Nodes.Action; if (action == null) { return; } stream.WriteLine("{0}\t\t\tthis.m_resultOption = {1};", indent, getResultOptionStr(action.ResultOption)); if (action.Method != null && !isNullMethod(action.Method)) { MethodCsExporter.GenerateClassConstructor(node, action.Method, stream, indent, "method"); } }
public static MethodDef parseMethodString(NodeTag.DefaultObject node, AgentType agentType, MethodType methodType, string str) { try { if (agentType != null) { int pos = str.IndexOf('('); if (pos < 0) { return(null); } string ownerName = agentType.ToString(); int pointIndex = str.IndexOf('.'); if (pointIndex > -1 && pointIndex < pos) { ownerName = str.Substring(0, pointIndex); str = str.Substring(pointIndex + 1, str.Length - pointIndex - 1); agentType = Plugin.GetInstanceAgentType(ownerName, agentType); //if (agentType == node.Behavior.AgentType) // ownerName = VariableDef.kSelf; pos = str.IndexOf('('); } IList <MethodDef> actions = agentType.GetMethods(methodType); string actionName = str.Substring(0, pos); foreach (MethodDef actionTypeIt in actions) { if (actionTypeIt.Name == actionName #if BEHAVIAC_NAMESPACE_FIX || actionTypeIt.Name.EndsWith(actionName) #endif ) { MethodDef method = new MethodDef(actionTypeIt); method.Owner = ownerName; List <string> paras = parseParams(str.Substring(pos + 1, str.Length - pos - 2)); //Debug.Check((paras.Count == actionTypeIt.Params.Count)); //if (paras.Count == actionTypeIt.Params.Count) { for (int i = 0; i < paras.Count; ++i) { string param = paras[i]; string[] tokens = null; if (param[0] == '\"') { param = param.Substring(1, param.Length - 2); } else if (param[0] == '{') { //struct //to set it as action.Method is used in the following parsing Nodes.Action action = node as Nodes.Action; if (action != null) { action.Method = method; } } else { tokens = param.Split(' '); } if (i < method.Params.Count) { MethodDef.Param par = method.Params[i]; if (tokens != null && tokens.Length > 1) { //par VariableDef var = setParameter(node, tokens[tokens.Length - 1]); if (var != null) { par.Value = var; } //else // throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } else { bool bOk = Plugin.InvokeTypeParser(par.Type, param, (object value) => par.Value = value, node, par.Name); if (!bOk) { throw new Exception(string.Format(Resources.ExceptionDesignerAttributeIllegalFloatValue, str)); } } } else { break; } } } return(method); } } } } catch (Exception) { System.Windows.Forms.MessageBox.Show(str, Resources.LoadError, System.Windows.Forms.MessageBoxButtons.OK); } return(null); }
protected override void GenerateMethod(Node node, StringWriter stream, string indent) { base.GenerateMethod(node, stream, indent); Nodes.Action action = node as Nodes.Action; if (action == null) { return; } stream.WriteLine("{0}\t\tprotected override EBTStatus update_impl(behaviac.Agent pAgent, behaviac.EBTStatus childStatus)", indent); stream.WriteLine("{0}\t\t{{", indent); string resultStatus = getResultOptionStr(action.ResultOption); if (action.Method != null && !isNullMethod(action.Method)) { string nativeReturnType = DataCsExporter.GetGeneratedNativeType(action.Method.NativeReturnType); string method = MethodCsExporter.GenerateCode(node, action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method"); if ("behaviac.EBTStatus" == nativeReturnType) { resultStatus = "result"; stream.WriteLine("{0}\t\t\t{1} result = {2};", indent, nativeReturnType, method); MethodCsExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method"); } else { if (("void" == nativeReturnType) || (EBTStatus.BT_INVALID != action.ResultOption) || action.ResultFunctor == null) { stream.WriteLine("{0}\t\t\t{1};", indent, method); } else { stream.WriteLine("{0}\t\t\t{1} result = {2};", indent, nativeReturnType, method); } MethodCsExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method"); if (EBTStatus.BT_INVALID != action.ResultOption) { resultStatus = getResultOptionStr(action.ResultOption); } else if (Plugin.IsMatchedStatusMethod(action.Method, action.ResultFunctor)) { if ("void" == nativeReturnType) { resultStatus = MethodCsExporter.GenerateCode(node, action.ResultFunctor, stream, indent + "\t\t\t", string.Empty, string.Empty, "functor"); } else { string agentName = "pAgent"; if (action.ResultFunctor.Owner != VariableDef.kSelf && (!action.ResultFunctor.IsPublic || !action.ResultFunctor.IsStatic)) { string instanceName = action.ResultFunctor.Owner.Replace("::", "."); agentName = "pAgent_functor"; stream.WriteLine("{0}behaviac.Agent {1} = behaviac.Utils.GetParentAgent(pAgent, \"{2}\");", indent, agentName, instanceName); //stream.WriteLine("{0}Debug.Check(!System.Object.ReferenceEquals({1}, null) || Utils.IsStaticClass(\"{2}\"));", indent, agentName, instanceName); } if (action.ResultFunctor.IsPublic) { string className = action.ResultFunctor.ClassName.Replace("::", "."); if (action.ResultFunctor.IsStatic) { resultStatus = string.Format("{0}.{1}(result)", className, action.ResultFunctor.BasicName); } else { resultStatus = string.Format("(({0}){1}).{2}(result)", className, agentName, action.ResultFunctor.BasicName); } } else { resultStatus = string.Format("AgentMetaVisitor.ExecuteMethod({0}, \"{1}\", new object[] {{ result }})", agentName, action.ResultFunctor.BasicName); } } resultStatus = string.Format("(EBTStatus){0}", resultStatus); } } } stream.WriteLine("{0}\t\t\treturn {1};", indent, resultStatus); stream.WriteLine("{0}\t\t}}", indent); }
protected override bool ShouldGenerateClass(Node node) { Nodes.Action action = node as Nodes.Action; return(action != null); }
private static void parseStringValue(List <Nodes.Node.ErrorCheck> result, DefaultObject node, object obj, Type type, string paramName, string str, int startIndex, int endIndex) { string propertyName = string.Empty; string propertyValue = string.Empty; try { if (startIndex >= endIndex) { return; } if (!string.IsNullOrEmpty(str)) { if (startIndex < str.Length && str[startIndex] == '{') { startIndex++; if (endIndex < str.Length && str[endIndex] == '}') { endIndex--; } } } int valueIndex = getProperty(str, startIndex, endIndex, out propertyName, out propertyValue); //if (propertyName == "code") //{ // Debug.Check(true); //} if (valueIndex >= 0) { Debug.Check(!string.IsNullOrEmpty(propertyName)); DesignerPropertyInfo property; if (getPropertyInfo(type, propertyName, out property)) { // Primitive type if (string.IsNullOrEmpty(propertyValue) || propertyValue[0] != '{') { MethodDef.Param parParam = null; Nodes.Action action = node as Nodes.Action; if (action != null) { MethodDef method = action.Method; if (method != null) { string pn = ""; if (paramName == null) { pn = propertyName; } parParam = method.GetParam(pn, type, obj, property); } } bool bParamFromStruct = false; string[] tokens = Plugin.Split(propertyValue, ' '); if (tokens != null && tokens.Length > 1) { //par if (parParam != null) { int propertyNameIndex = 1; if (tokens.Length == 2) { propertyNameIndex = 1; } else if (tokens.Length == 3) { Debug.Check(tokens[0] == "static"); propertyNameIndex = 2; } else { Debug.Check(false); } parParam.Value = DesignerMethodEnum.setParameter(result, node, tokens[propertyNameIndex]); bParamFromStruct = true; } } if (!bParamFromStruct) { property.SetValueFromString(result, obj, propertyValue, node); if (parParam != null && parParam.Value == null) { parParam.Value = property.GetValue(obj); } } } // Struct type else { object member = property.GetValue(obj); Debug.Check(member != null); string structStr = str.Substring(valueIndex + 1, propertyValue.Length - 2); parseStringValue(result, node, member, member.GetType(), paramName, structStr, 0, structStr.Length - 1); } } // Parse next property parseStringValue(result, node, obj, type, paramName, str, valueIndex + propertyValue.Length + 1, str.Length - 1); } } catch (Exception ex) { string msg = string.Format("{0}\n{1}:{2}", ex.Message, propertyName, propertyValue); MessageBox.Show(msg, Resources.LoadError, MessageBoxButtons.OK); } }
protected override void GenerateMethod(Node node, StringWriter stream, string indent) { base.GenerateMethod(node, stream, indent); Nodes.Action action = node as Nodes.Action; if (action == null) { return; } stream.WriteLine("{0}\t\tvirtual EBTStatus update_impl(Agent* pAgent, EBTStatus childStatus)", indent); stream.WriteLine("{0}\t\t{{", indent); stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(pAgent);", indent); stream.WriteLine("{0}\t\t\tBEHAVIAC_UNUSED_VAR(childStatus);", indent); string resultStatus = "BT_SUCCESS"; if (action.Method != null) { string method = MethodCppExporter.GenerateCode(node, action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method"); if ("behaviac::EBTStatus" == action.Method.NativeReturnType) { stream.WriteLine("{0}\t\t\t{1} result = {2};", indent, action.Method.NativeReturnType, method); resultStatus = "result"; MethodCppExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method"); } else { if (("void" == action.Method.NativeReturnType) || (EBTStatus.BT_INVALID != action.ResultOption) || action.ResultFunctor == null) { stream.WriteLine("{0}\t\t\t{1};", indent, method); } else { stream.WriteLine("{0}\t\t\t{1} result = {2};", indent, action.Method.NativeReturnType, method); } MethodCppExporter.PostGenerateCode(action.Method, stream, indent + "\t\t\t", string.Empty, string.Empty, "method"); if (EBTStatus.BT_INVALID != action.ResultOption) { resultStatus = action.ResultOption.ToString(); } else if (Plugin.IsMatchedStatusMethod(action.Method, action.ResultFunctor)) { if ("void" == action.Method.NativeReturnType) { resultStatus = MethodCppExporter.GenerateCode(node, action.ResultFunctor, stream, indent + "\t\t\t", string.Empty, string.Empty, "functor"); } else { string agentName = "pAgent"; if (action.ResultFunctor.Owner != VariableDef.kSelf) { agentName = "pAgent_functor"; stream.WriteLine("{0}Agent* {1} = Agent::GetInstance(pAgent, \"{2}\");", indent, agentName, action.ResultFunctor.Owner); stream.WriteLine("{0}BEHAVIAC_ASSERT({1});", indent, agentName); } resultStatus = string.Format("(({0}*){1})->{2}(result)", action.ResultFunctor.ClassName, agentName, action.ResultFunctor.Name); } } } } stream.WriteLine("{0}\t\t\treturn {1};", indent, resultStatus); stream.WriteLine("{0}\t\t}}", indent); }