public override object FromStringValue(List <Nodes.Node.ErrorCheck> result, DefaultObject node, object parentObject, Type type, string str)
        {
            if (type != typeof(RightValueDef))
            {
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);
            }

            if (str.Length == 0 ||
                str.Length == 2 && str == "\"\"")
            {
                return(null);
            }

            if (!str.StartsWith("const"))
            {
                int pos = str.IndexOf('(');

                if (pos < 0)
                {
                    VariableDef var = DesignerPropertyEnum.parsePropertyVar(result, node, str);

                    return(new RightValueDef(var));
                }
                else
                {
                    Nodes.Behavior behavior  = node.Behavior as Nodes.Behavior;
                    AgentType      agentType = (behavior != null) ? behavior.AgentType : null;

                    string    valueClass = VariableDef.kSelfMethod;
                    MethodDef method     = DesignerMethodEnum.parseMethodString(result, node, agentType, this.MethodType, str);

                    if (method == null)
                    {
                        string className = Plugin.GetClassName(str);
                        method     = DesignerMethodEnum.parseMethodString(result, node, Plugin.GetInstanceAgentType(className, behavior, null), this.MethodType, str);
                        valueClass = className + VariableDef.kMethod;
                    }

                    string instanceName = Plugin.GetInstanceName(str);

                    if (!string.IsNullOrEmpty(instanceName))
                    {
                        valueClass = instanceName + VariableDef.kMethod;
                    }

                    return(new RightValueDef(method, valueClass));
                }
            }
            else
            {
                VariableDef var = this.parseConstVar(result, node, parentObject, str);

                if (var != null)
                {
                    return(new RightValueDef(var));
                }
            }

            return(null);
        }
Пример #2
0
        protected static VariableDef setProperty(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, string propertyName, string arrayIndexStr, string valueType)
        {
            if (agentType != null)
            {
                IList <PropertyDef> properties = agentType.GetProperties();
                foreach (PropertyDef p in properties)
                {
                    if (p.Name == propertyName
#if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
#endif
                        )
                    {
                        PropertyDef prop = p.Clone();
                        prop.Owner = valueType;

                        VariableDef v = new VariableDef(prop, valueType);

                        if (v != null && !string.IsNullOrEmpty(arrayIndexStr))
                        {
                            v.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex");
                            v.ArrayIndexElement.IsArrayIndex = true;
                            DesignerMethodEnum.parseParam(result, node, null, v.ArrayIndexElement, arrayIndexStr);
                        }

                        return(v);
                    }
                }
            }

            return(null);
        }
        public override object FromStringValue(NodeTag.DefaultObject node, object parentObject, Type type, string str)
        {
            if (type != typeof(RightValueDef))
            {
                throw new Exception(Resources.ExceptionDesignerAttributeInvalidType);
            }

            if (str.Length == 0 ||
                str.Length == 2 && str == "\"\"")
            {
                return(null);
            }

            if (!str.StartsWith("const"))
            {
                int pos = str.IndexOf('(');
                if (pos < 0)
                {
                    VariableDef var = this.parsePropertyVar(node, str);

                    return(new RightValueDef(var));
                }
                else
                {
                    //Ship::Getter(100,50,50)
                    Behaviac.Design.Nodes.Behavior behavior = node.Behavior as Behaviac.Design.Nodes.Behavior;

                    string    valueClass = VariableDef.kSelfMethod;
                    MethodDef method     = DesignerMethodEnum.parseMethodString(node, behavior.AgentType, this.MethodType, str);
                    if (method == null)
                    {
                        string className = Plugin.GetClassName(str);
                        method     = DesignerMethodEnum.parseMethodString(node, Plugin.GetInstanceAgentType(className), this.MethodType, str);
                        valueClass = className + VariableDef.kMethod;
                    }

                    //Debug.Check(method != null);

                    string instanceName = Plugin.GetInstanceName(str);
                    if (!string.IsNullOrEmpty(instanceName))
                    {
                        valueClass = instanceName + VariableDef.kMethod;
                    }

                    return(new RightValueDef(method, valueClass));
                }
            }
            else
            {
                VariableDef var = this.parseConstVar(node, parentObject, str);

                if (var != null)
                {
                    return(new RightValueDef(var));
                }
            }

            return(null);
        }
        private List <MethodDef> getMethods()
        {
            List <MethodDef> methods = new List <MethodDef>();

            Behaviac.Design.Attachments.Attach evt      = _object as Behaviac.Design.Attachments.Attach;
            Behaviac.Design.Nodes.BaseNode     baseNode = (evt != null) ? evt.Node : _object as Behaviac.Design.Nodes.BaseNode;

            if (baseNode == null)
            {
                baseNode = this._root;
            }

            Behaviac.Design.Nodes.Behavior behavior = null;

            if (baseNode != null)
            {
                behavior = baseNode.Behavior as Behaviac.Design.Nodes.Behavior;
            }

            AgentType agentType = null;

            if (behavior != null && behavior.AgentType != null)
            {
                agentType = behavior.AgentType;
            }

            object        action = _property.Property.GetValue(_object, null);
            RightValueDef varRV  = action as RightValueDef;

            if (varRV != null && Plugin.IsInstanceName(varRV.ValueClassReal))
            {
                agentType = Plugin.GetInstanceAgentType(varRV.ValueClassReal);
            }

            if (agentType != null)
            {
                DesignerRightValueEnum enumAttRV  = _property.Attribute as DesignerRightValueEnum;
                DesignerMethodEnum     attrMethod = _property.Attribute as DesignerMethodEnum;
                MethodType             methodType = attrMethod != null ? attrMethod.MethodType : MethodType.Getter;

                if (enumAttRV != null)
                {
                    methodType = enumAttRV.MethodType;
                }

                IList <MethodDef> actions = agentType.GetMethods(methodType);
                foreach (MethodDef actionType in actions)
                {
                    if (Plugin.IsCompatibleType(this.FilterType, actionType.ReturnType, false))
                    {
                        methods.Add(actionType);
                    }
                }
            }

            return(methods);
        }
        private List <MethodDef> getMethods()
        {
            List <MethodDef> methods = new List <MethodDef>();

            if (typeComboBox.SelectedIndex > -1)
            {
                Nodes.Behavior behavior  = GetBehavior();
                AgentType      agentType = Plugin.GetInstanceAgentType(_currentNames[typeComboBox.SelectedIndex], behavior, _agentType);

                if (agentType != null)
                {
                    // get the linked method to filter
                    MethodDef            linkedMethod = null;
                    bool                 linkBroken;
                    DesignerPropertyInfo linkedProp = _property.Attribute.GetLinkedProperty(_object, out linkBroken);
                    object               prop       = linkedProp.GetValue(_object);

                    if (prop != null && prop is MethodDef)
                    {
                        linkedMethod = prop as MethodDef;
                    }

                    DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum;
#if USE_NOOP
                    IList <MethodDef> methods = new List <MethodDef>();
                    methods.Add(MethodDef.Noop);

                    IList <MethodDef> agentMethods = agentType.GetMethods(attrMethod.MethodType, ValueTypes.All, linkedMethod);

                    foreach (MethodDef m in agentMethods)
                    {
                        methods.Add(m);
                    }
#else
                    if (attrMethod != null)
                    {
                        methods.AddRange(agentType.GetMethods(attrMethod.MethodType, attrMethod.MethodReturnType, linkedMethod));
                    }
                    else
                    {
                        DesignerRightValueEnum attrMethodRV = _property.Attribute as DesignerRightValueEnum;

                        if (attrMethodRV != null)
                        {
                            methods.AddRange(agentType.GetMethods(attrMethodRV.MethodType, ValueTypes.All, linkedMethod));
                        }
                    }
#endif//#if USE_NOOP
                }
            }

            return(methods);
        }
Пример #6
0
        private void valueComboBox_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (!_valueWasAssigned ||
                typeComboBox.SelectedIndex < 0 || typeComboBox.SelectedIndex >= _currentNames.Count ||
                valueComboBox.SelectedIndex < 0 || valueComboBox.SelectedIndex >= _methods.Count)
            {
                return;
            }

            MethodDef m_ = _methods[valueComboBox.SelectedIndex] as MethodDef;
            MethodDef m  = new MethodDef(m_);

            m.Owner = _currentNames[typeComboBox.SelectedIndex];

            DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum;

            if (attrMethod != null)
            {
                if ((attrMethod.MethodType & MethodType.AllowNullMethod) == MethodType.AllowNullMethod &&
                    attrMethod.HasFlags(DesignerProperty.DesignerFlags.BeValid) &&
                    attrMethod.Display == DesignerProperty.DisplayMode.List)
                {
                    object oldValue = _property.Property.GetValue(_object, null);

                    if (oldValue == null)
                    {
                        Nodes.Node n = this._object as Nodes.Node;

                        if (n != null)
                        {
                            //n.AddSubItem(new NodeViewData.SubItemProperty(n, _property, attrMethod));
                            n.DoSubItemAdded(_property);
                        }
                    }
                }

                _property.Property.SetValue(_object, m, null);
            }
            else
            {
                object        propertyMember = _property.Property.GetValue(_object, null);
                RightValueDef oldvarRV       = propertyMember as RightValueDef;

                RightValueDef v = new RightValueDef(m, oldvarRV.ValueClass);

                _property.Property.SetValue(_object, m, null);
            }

            OnValueChanged(_property);

            this.RereshProperty(true, _property);
        }
        public override void SetProperty(DesignerPropertyInfo property, object obj)
        {
            base.SetProperty(property, obj);

            _resetMethods = false;

            DesignerMethodEnum enumAtt = property.Attribute as DesignerMethodEnum;

            if (enumAtt != null && property.Property.PropertyType == null)
            {
                throw new Exception(string.Format(Resources.ExceptionDesignerAttributeExpectedEnum, property.Property.Name));
            }

            Behaviac.Design.Attachments.Attach evt      = obj as Behaviac.Design.Attachments.Attach;
            Behaviac.Design.Nodes.BaseNode     baseNode = (evt != null) ? evt.Node : obj as Behaviac.Design.Nodes.BaseNode;
            Behaviac.Design.Nodes.Behavior     behavior = (baseNode != null) ? baseNode.Behavior as Behaviac.Design.Nodes.Behavior : null;

            if (behavior == null && this._root != null)
            {
                behavior = this._root.Behavior as Behaviac.Design.Nodes.Behavior;
            }

            _agentType = (behavior != null) ? behavior.AgentType : null;

            object    action    = property.Property.GetValue(obj, null);
            MethodDef method    = action as MethodDef;
            int       typeIndex = -1;

            if (method != null)
            {
                typeIndex = getTypeIndex(method.Owner);
            }

            if (typeIndex < 0)
            {
                typeIndex = 0;
            }

            // Keep only one type for efficiency.
            _currentNames.Clear();
            _currentNames.Add(_names[typeIndex]);

            this.typeComboBox.Items.Clear();
            this.typeComboBox.Items.Add(_types[typeIndex]);
            this.typeComboBox.SelectedIndex = 0;
        }
Пример #8
0
        private static VariableDef createVariable(List <Nodes.Node.ErrorCheck> result, DefaultObject node, AgentType agentType, string instacneName, string propertyName)
        {
            List <string> tokens = DesignerPropertyEnum.SplitTokens(propertyName);

            Debug.Check(tokens.Count > 0);
            string arrayIndexStr = null;

            if (tokens.Count > 1)
            {
                propertyName  = tokens[0] + "[]";
                arrayIndexStr = tokens[1];
            }

            Nodes.Behavior behavior = node.Behavior as Nodes.Behavior;
            agentType = Plugin.GetInstanceAgentType(instacneName, behavior, agentType);

            if (agentType != null)
            {
                IList <PropertyDef> properties = agentType.GetProperties();

                foreach (PropertyDef p in properties)
                {
                    if (p.Name == propertyName
#if BEHAVIAC_NAMESPACE_FIX
                        || p.Name.EndsWith(propertyName)
#endif
                        )
                    {
                        VariableDef v = new VariableDef(p, instacneName);

                        if (v != null && !string.IsNullOrEmpty(arrayIndexStr))
                        {
                            v.ArrayIndexElement = new MethodDef.Param("ArrayIndex", typeof(int), "int", "ArrayIndex", "ArrayIndex");
                            v.ArrayIndexElement.IsArrayIndex = true;
                            DesignerMethodEnum.parseParam(result, node, null, v.ArrayIndexElement, arrayIndexStr);
                        }

                        return(v);
                    }
                }
            }

            return(null);
        }
        private List <MethodDef> getMethods()
        {
            List <MethodDef> methods = new List <MethodDef>();

            Nodes.Behavior behavior  = GetBehavior();
            AgentType      agentType = (behavior != null) ? behavior.AgentType : null;

            object      action = _property.Property.GetValue(_object, null);
            VariableDef var    = action as VariableDef;

            Debug.Check(var == null);

            RightValueDef varRV = action as RightValueDef;

            if (varRV != null && Plugin.IsInstanceName(varRV.ValueClassReal, behavior))
            {
                agentType = Plugin.GetInstanceAgentType(varRV.ValueClassReal, behavior, agentType);
            }

            if (agentType != null)
            {
                DesignerRightValueEnum enumAttRV  = _property.Attribute as DesignerRightValueEnum;
                DesignerMethodEnum     attrMethod = _property.Attribute as DesignerMethodEnum;
                MethodType             methodType = attrMethod != null ? attrMethod.MethodType : MethodType.Getter;

                if (enumAttRV != null)
                {
                    methodType = enumAttRV.MethodType;
                }

                IList <MethodDef> actions = agentType.GetMethods(true, methodType);

                foreach (MethodDef actionType in actions)
                {
                    if (Plugin.IsCompatibleType(this.ValueType, this.FilterType, actionType.ReturnType, false))
                    {
                        methods.Add(actionType);
                    }
                }
            }

            return(methods);
        }
Пример #10
0
        private void updateStructProperties(object owner)
        {
            IList <DesignerPropertyInfo> properties = DesignerProperty.GetDesignerProperties(_structProperty.Type, DesignerProperty.SortByDisplayOrder);

            List <string> categories = new List <string>();

            foreach (DesignerPropertyInfo property in properties)
            {
                if (!categories.Contains(property.Attribute.CategoryResourceString))
                {
                    categories.Add(property.Attribute.CategoryResourceString);
                }
            }
            categories.Sort();

            UIObject uiObj = owner as UIObject;

            if (uiObj != null)
            {
                uiPolicy = uiObj.CreateUIPolicy();
                uiPolicy.Initialize(uiObj);
            }

            foreach (string category in categories)
            {
                if (categories.Count > 1)
                {
                    propertyGrid.AddCategory(Plugin.GetResourceString(category), true);
                }

                foreach (DesignerPropertyInfo property in properties)
                {
                    if (property.Attribute.CategoryResourceString == category)
                    {
                        if (uiPolicy != null && !uiPolicy.ShouldAddProperty(property))
                        {
                            continue;
                        }

                        object             member         = property.GetValue(owner);
                        Type               type           = property.Attribute.GetEditorType(member);
                        DesignerMethodEnum propertyMethod = property.Attribute as DesignerMethodEnum;

                        if (propertyMethod != null)
                        {
                            if ((propertyMethod.MethodType & MethodType.Task) == MethodType.Task)
                            {
                                type = typeof(DesignerMethodEnumEditor);
                            }
                        }

                        string displayName = property.Attribute.DisplayName;

                        if (uiPolicy != null)
                        {
                            displayName = uiPolicy.GetLabel(property);
                        }

                        Label label = propertyGrid.AddProperty(displayName, type, property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnly));
                        label.BackColor   = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56)))));
                        label.MouseEnter += new EventHandler(label_MouseEnter);

                        if (type != null)
                        {
                            DesignerPropertyEditor editor = (DesignerPropertyEditor)label.Tag;
                            editor.SetRootNode(this._node);
                            editor.SetProperty(property, owner);
                            editor.ValueWasAssigned();
                            editor.MouseEnter      += editor_MouseEnter;
                            editor.ValueWasChanged += editor_ValueWasChanged;

                            if (uiPolicy != null)
                            {
                                uiPolicy.AddEditor(editor);
                            }
                        }

                        MethodDef method = null;

                        if (propertyMethod != null)
                        {
                            if (propertyMethod.MethodType != MethodType.Status)
                            {
                                method = member as MethodDef;
                            }
                        }
                        else
                        {
                            DesignerRightValueEnum propertyRV = property.Attribute as DesignerRightValueEnum;

                            if (propertyRV != null)
                            {
                                RightValueDef rv = member as RightValueDef;

                                if (rv != null && rv.IsMethod)
                                {
                                    method = rv.Method;
                                }
                            }
                        }

                        if (property.Attribute != null)
                        {
                            if (method != null)
                            {
                                if (property.Attribute.HasFlags(DesignerProperty.DesignerFlags.NoDisplayOnProperty))
                                {
                                    //don't dipslay on the property panel
                                }
                                else
                                {
                                    bool bReadonly = property.Attribute.HasFlags(DesignerProperty.DesignerFlags.ReadOnlyParams);

                                    createParamEditor(owner, method, true, bReadonly);
                                }
                            }
                            else
                            {
                                MethodDef.Param arrayIndexElement = null;

                                if (member is VariableDef)
                                {
                                    VariableDef var = member as VariableDef;
                                    arrayIndexElement = var.ArrayIndexElement;
                                }
                                else if (member is RightValueDef)
                                {
                                    RightValueDef varRV = member as RightValueDef;

                                    if (varRV.Var != null)
                                    {
                                        arrayIndexElement = varRV.Var.ArrayIndexElement;
                                    }
                                }

                                if (arrayIndexElement != null)
                                {
                                    createArrayIndexEditor(owner, "    ", arrayIndexElement);
                                }
                            }
                        }
                    }
                }
            }

            if (uiPolicy != null)
            {
                uiPolicy.Update(null, new DesignerPropertyInfo());
            }

            if (properties.Count > 0)
            {
                propertyGrid.UpdateSizes();
                propertyGrid.PropertiesVisible(true, true);
            }
        }
        private void setValueComboBox()
        {
            if (_methods.Count == 0)
            {
                return;
            }

            if (string.IsNullOrEmpty(valueComboBox.Text))
            {
                foreach (MethodDef md in _methods)
                {
                    if (!valueComboBox.Items.Contains(md.DisplayName))
                    {
                        valueComboBox.Items.Add(md.DisplayName);
                    }
                }
            }
            else
            {
                int index = -1;

                for (int i = 0; i < _methods.Count; ++i)
                {
                    if (valueComboBox.Text == _methods[i].DisplayName)
                    {
                        index = i;
                        break;
                    }
                }

                if (index > -1)
                {
                    for (int i = index - 1; i >= 0; --i)
                    {
                        if (!valueComboBox.Items.Contains(_methods[i].DisplayName))
                        {
                            valueComboBox.Items.Insert(0, _methods[i].DisplayName);
                        }
                    }

                    for (int i = index + 1; i < _methods.Count; ++i)
                    {
                        if (!valueComboBox.Items.Contains(_methods[i].DisplayName))
                        {
                            valueComboBox.Items.Add(_methods[i].DisplayName);
                        }
                    }
                }
            }

            object             action     = _property.Property.GetValue(_object, null);
            DesignerMethodEnum attrMethod = _property.Attribute as DesignerMethodEnum;

            if (attrMethod != null)
            {
                MethodDef method = action as MethodDef;

                if (method != null && this.valueComboBox.Text != method.DisplayName)
                {
                    this.valueComboBox.Text = method.DisplayName;
                }
            }
            else
            {
                DesignerRightValueEnum attrMethodRV = _property.Attribute as DesignerRightValueEnum;

                if (attrMethodRV != null)
                {
                    RightValueDef method = action as RightValueDef;

                    if (method != null && this.valueComboBox.Text != method.Method.DisplayName)
                    {
                        Debug.Check(method.IsMethod);
                        this.valueComboBox.Text = method.Method.DisplayName;
                    }
                }
            }
        }
Пример #12
0
        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);
            }
        }