private int InitializePropertyFragment(string component, MetaProperty property, Type editorType, int y)
        {
            if (property == null || editorType == null)
            {
                return(y);
            }

            string propertyPath = "components/" + component + "/" + property.Name;

            if (m_goData == null || !m_goData.ContainsKey(propertyPath))
            {
                return(y);
            }

            try
            {
                object           obj      = PropertyEditorsManager.Instance.CreatePropertyEditor(editorType, m_goData, propertyPath, property.ValueType);
                MetroUserControl editor   = obj as MetroUserControl;
                IEditorJsonValue jvEditor = obj as IEditorJsonValue;
                if (editor != null && jvEditor != null)
                {
                    jvEditor.Text             = property.Name;
                    jvEditor.JsonDefaultValue = property.DefaultValue;
                    jvEditor.UpdateEditorValue();
                    editor.Top    = y;
                    editor.Width  = Width;
                    editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    Controls.Add(editor);
                    jvEditor.EditorJsonValueChangedCallback = this;
                    m_editors.Add(jvEditor);
                    y = editor.Bottom + DEFAULT_SEPARATOR;
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }
                ErrorPropertyEditor editor = new ErrorPropertyEditor(property.Name, ex.Message);
                editor.Tag    = string.Format("{0}\n{1}\n\nStack trace:\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace);
                editor.Top    = y;
                editor.Width  = Width;
                editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                Controls.Add(editor);
                y = editor.Bottom + DEFAULT_SEPARATOR;
            }

            return(y);
        }
Exemple #2
0
            private void InitializeComponent(ItemEditorInfo[] metaEditors, ItemEditorInfo[] propertyEditors, string id, string meta, string tags)
            {
                IsProxyEditor = true;

                m_subProperties["id"]   = Newtonsoft.Json.JsonConvert.SerializeObject(id);
                m_subProperties["tags"] = string.IsNullOrEmpty(tags) ? "null" : Newtonsoft.Json.JsonConvert.SerializeObject(tags.Split('|'));

                MetroButton applyButton = new MetroButton();

                MetroSkinManager.ApplyMetroStyle(applyButton);
                applyButton.Text   = "Apply";
                applyButton.Width  = Width - 20;
                applyButton.Top    = Height;
                applyButton.Left   = 10;
                applyButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                applyButton.Click += new EventHandler(applyButton_Click);
                Controls.Add(applyButton);
                Height += applyButton.Height + DEFAULT_SEPARATOR;

                MetroButton removeButton = new MetroButton();

                MetroSkinManager.ApplyMetroStyle(removeButton);
                removeButton.Text   = "Remove";
                removeButton.Width  = Width - 20;
                removeButton.Top    = Height;
                removeButton.Left   = 10;
                removeButton.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                removeButton.Click += new EventHandler(removeButton_Click);
                Controls.Add(removeButton);
                Height += removeButton.Height + DEFAULT_SEPARATOR;

                m_idEditor        = new String_PropertyEditor(m_subProperties, "id");
                m_idEditor.Width  = Width - 20;
                m_idEditor.Top    = Height;
                m_idEditor.Left   = 10;
                m_idEditor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                Controls.Add(m_idEditor);
                m_idEditor.EditorJsonValueChangedCallback = this;
                Height += m_idEditor.Height + DEFAULT_SEPARATOR;

                if (metaEditors != null && metaEditors.Length > 0)
                {
                    string[] metaParts      = string.IsNullOrEmpty(meta) ? null : meta.Split('|');
                    int      metaPartsIndex = 0;
                    foreach (ItemEditorInfo info in metaEditors)
                    {
                        if (metaParts != null && metaPartsIndex < metaParts.Length)
                        {
                            m_subProperties[info.property] = Newtonsoft.Json.JsonConvert.SerializeObject(metaParts[metaPartsIndex]);
                        }
                        metaPartsIndex++;
                        try
                        {
                            object           obj      = Activator.CreateInstance(info.editorType, m_subProperties, info.property);
                            MetroUserControl editor   = obj as MetroUserControl;
                            IEditorJsonValue jvEditor = obj as IEditorJsonValue;
                            if (editor != null && jvEditor != null)
                            {
                                jvEditor.Text = info.property;
                                jvEditor.UpdateEditorValue();
                                editor.Top    = Height;
                                editor.Width  = Width - 20;
                                editor.Left   = 10;
                                editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                                Controls.Add(editor);
                                jvEditor.EditorJsonValueChangedCallback = this;
                                m_metaEditors.Add(new KeyValuePair <string, IEditorJsonValue>(info.property, jvEditor));
                                Height += editor.Height + DEFAULT_SEPARATOR;
                            }
                        }
                        catch (Exception ex)
                        {
                            while (ex.InnerException != null)
                            {
                                ex = ex.InnerException;
                            }
                            ErrorPropertyEditor editor = new ErrorPropertyEditor(info.property, ex.Message);
                            editor.Tag    = string.Format("{0}\n{1}\n\nStack trace:\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace);
                            editor.Top    = Height;
                            editor.Width  = Width - 20;
                            editor.Left   = 10;
                            editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                            Controls.Add(editor);
                            Height += editor.Height + DEFAULT_SEPARATOR;
                        }
                    }
                }

                if (propertyEditors != null && propertyEditors.Length > 0)
                {
                    foreach (ItemEditorInfo info in propertyEditors)
                    {
                        m_subProperties[info.property] = "null";
                        try
                        {
                            object           obj      = Activator.CreateInstance(info.editorType, m_subProperties, info.property);
                            MetroUserControl editor   = obj as MetroUserControl;
                            IEditorJsonValue jvEditor = obj as IEditorJsonValue;
                            if (editor != null && jvEditor != null)
                            {
                                jvEditor.Text = info.property;
                                jvEditor.UpdateEditorValue();
                                editor.Top    = Height;
                                editor.Width  = Width - 20;
                                editor.Left   = 10;
                                editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                                Controls.Add(editor);
                                jvEditor.EditorJsonValueChangedCallback = this;
                                m_propertyEditors.Add(new KeyValuePair <string, IEditorJsonValue>(info.property, jvEditor));
                                Height += editor.Height + DEFAULT_SEPARATOR;
                            }
                        }
                        catch (Exception ex)
                        {
                            while (ex.InnerException != null)
                            {
                                ex = ex.InnerException;
                            }
                            ErrorPropertyEditor editor = new ErrorPropertyEditor(info.property, ex.Message);
                            editor.Tag    = string.Format("{0}\n{1}\n\nStack trace:\n{2}", ex.GetType().Name, ex.Message, ex.StackTrace);
                            editor.Top    = Height;
                            editor.Width  = Width - 20;
                            editor.Left   = 10;
                            editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                            Controls.Add(editor);
                            Height += editor.Height + DEFAULT_SEPARATOR;
                        }
                    }
                }

                m_tagsEditor        = new Tags_PropertyEditor(m_subProperties, "tags");
                m_tagsEditor.Width  = Width - 20;
                m_tagsEditor.Top    = Height;
                m_tagsEditor.Left   = 10;
                m_tagsEditor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                Controls.Add(m_tagsEditor);
                m_tagsEditor.EditorJsonValueChangedCallback = this;
                Height += m_tagsEditor.Height;

                UpdateJsonValue();
                UpdateProperties();
            }
        private int InitializeComponentFragment(string component, int y)
        {
            if (string.IsNullOrEmpty(component))
            {
                return(y);
            }

            MetaComponent meta = MetaComponentsManager.Instance.FindMetaComponent(component);

            if (meta == null)
            {
                return(y);
            }

            MetroButton componentButton = new MetroButton();

            MetroSkinManager.ApplyMetroStyle(componentButton);
            componentButton.Text       = component;
            componentButton.FontWeight = MetroButtonWeight.Bold;
            componentButton.Top        = y + DEFAULT_SEPARATOR + DEFAULT_SEPARATOR + DEFAULT_SEPARATOR;
            componentButton.Width      = Width;
            componentButton.Anchor     = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
            componentButton.Click     += new EventHandler(componentButton_Click);
            Controls.Add(componentButton);
            y = componentButton.Bottom + DEFAULT_SEPARATOR;

            if (meta.FunctionalityTriggers != null && meta.FunctionalityTriggers.Count > 0)
            {
                MetroLabel label = new MetroLabel();
                MetroSkinManager.ApplyMetroStyle(label);
                label.Text       = "Functionality Triggers";
                label.FontWeight = MetroLabelWeight.Bold;
                label.FontSize   = MetroLabelSize.Small;
                label.Top        = y;
                label.Width      = Width;
                label.Anchor     = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                Controls.Add(label);
                y = label.Bottom;

                foreach (string func in meta.FunctionalityTriggers)
                {
                    MetroButton btn = new MetroButton();
                    MetroSkinManager.ApplyMetroStyle(btn);
                    btn.Tag    = meta.Name;
                    btn.Text   = func;
                    btn.Top    = y;
                    btn.Width  = Width - 20;
                    btn.Left   = 10;
                    btn.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    btn.Click += new EventHandler(triggerFunctionality_Click);
                    Controls.Add(btn);
                    y = btn.Bottom + DEFAULT_SEPARATOR;
                }
            }

            List <MetaProperty> props = MetaComponentsManager.Instance.GetFlattenPropertiesOf(meta);

            if (props == null || props.Count == 0)
            {
                return(y);
            }

            foreach (MetaProperty p in props)
            {
                Type t = PropertyEditorsManager.Instance.FindPropertyEditor(p.ValueType);
                if (t == null)
                {
                    string msg = string.Format("Property editor for type: \"{0}\" not found!", p.ValueType);
                    ErrorPropertyEditor editor = new ErrorPropertyEditor(p.Name, msg);
                    editor.UpdateEditorValue();
                    editor.Top    = y;
                    editor.Width  = Width;
                    editor.Anchor = AnchorStyles.Top | AnchorStyles.Left | AnchorStyles.Right;
                    Controls.Add(editor);
                    y = editor.Bottom + DEFAULT_SEPARATOR;
                }
                else
                {
                    y = InitializePropertyFragment(component, p, t, y);
                }
            }

            return(y);
        }