示例#1
0
        private static NodeObjectData ConvertObjectData(NodeObject nObject)
        {
            Type           dataModelType  = Services.ProjectsService.DataModelManager.GetDataModelType(nObject.GetType());
            NodeObjectData nodeObjectData = Activator.CreateInstance(dataModelType, true) as NodeObjectData;
            NodeObjectData result;

            if (nodeObjectData == null)
            {
                result = null;
            }
            else
            {
                PropertyInfo[] properties = nObject.GetType().GetProperties();
                PropertyInfo[] array      = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    PropertyInfo propertyInfo = array[i];
                    string       name         = propertyInfo.Name;
                    if (!(name == "Children"))
                    {
                        PropertyInfo property = nodeObjectData.GetType().GetProperty(name);
                        object       value    = propertyInfo.GetValue(nObject, null);
                        if (property != null && value != null)
                        {
                            object obj = value;
                            if (!property.PropertyType.Equals(propertyInfo.PropertyType))
                            {
                                obj = Activator.CreateInstance(property.PropertyType, true);
                                if (!(obj is IDataConvert))
                                {
                                    string message = string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", nObject.GetType().Name, propertyInfo.PropertyType.Name, property.PropertyType.Name);
                                    throw new InvalidCastException(message);
                                }
                                ((IDataConvert)obj).SetData(value);
                            }
                            property.SetValue(nodeObjectData, obj, null);
                        }
                    }
                }
                if (nObject.Children == null || nObject.Children.Count <= 0)
                {
                    result = nodeObjectData;
                }
                else
                {
                    nodeObjectData.Children = new List <NodeObjectData>();
                    foreach (NodeObject current in nObject.Children)
                    {
                        NodeObjectData item = GameProjectLoader.ConvertObjectData(current);
                        nodeObjectData.Children.Add(item);
                    }
                    result = nodeObjectData;
                }
            }
            return(result);
        }
示例#2
0
        public void SaveData()
        {
            int id = 1;
            FieldEditorAttibute atr;

            PropertyInfo[] props = NodeObject.GetType().GetProperties();
            foreach (PropertyInfo pi in props)
            {
                if (pi.GetCustomAttributes(typeof(FieldEditorIgnore), false).Length > 0)
                {
                    continue;
                }

                string    name   = pi.Name;
                string    tbName = "txt_" + name + "_" + id;
                Control[] ctls   = this.Controls.Find(tbName, false);
                if (ctls.Length == 0)
                {
                    continue;
                }
                Control ctl = ctls[0];

                object[] attrs = pi.GetCustomAttributes(typeof(FieldEditorAttibute), false);
                if (attrs.Length > 0)
                {
                    atr = (FieldEditorAttibute)attrs[0];
                    atr.StoreValue(ctl, pi, NodeObject);
                }
                else
                {
                    if (ctl != null)
                    {
                        if (pi.CanWrite)
                        {
                            if (pi.PropertyType.ToString().Contains("String"))
                            {
                                pi.SetValue(NodeObject, ctl.Text, null);
                            }
                        }
                    }
                }
                id += 1;
            }
        }
        private static NodeObjectData ConvertObjectData(NodeObject nObject)
        {
            NodeObjectData instance = Activator.CreateInstance(Services.ProjectsService.DataModelManager.GetDataModelType(nObject.GetType()), true) as NodeObjectData;

            if (instance == null)
            {
                return((NodeObjectData)null);
            }
            foreach (PropertyInfo property1 in nObject.GetType().GetProperties())
            {
                string name = property1.Name;
                if (!(name == "Children"))
                {
                    PropertyInfo property2  = instance.GetType().GetProperty(name);
                    object       viewObject = property1.GetValue((object)nObject, (object[])null);
                    if (property2 != (PropertyInfo)null && viewObject != null)
                    {
                        object obj = viewObject;
                        if (!property2.PropertyType.Equals(property1.PropertyType))
                        {
                            obj = Activator.CreateInstance(property2.PropertyType, true);
                            if (!(obj is IDataConvert))
                            {
                                throw new InvalidCastException(string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", (object)nObject.GetType().Name, (object)property1.PropertyType.Name, (object)property2.PropertyType.Name));
                            }
                            ((IDataConvert)obj).SetData(viewObject);
                        }
                        property2.SetValue((object)instance, obj, (object[])null);
                    }
                }
            }
            if (nObject.Children == null || nObject.Children.Count <= 0)
            {
                return(instance);
            }
            instance.Children = new List <NodeObjectData>();
            foreach (NodeObject child in (Collection <NodeObject>)nObject.Children)
            {
                NodeObjectData nodeObjectData = GameProjectLoader.ConvertObjectData(child);
                instance.Children.Add(nodeObjectData);
            }
            return(instance);
        }
示例#4
0
        public override void buildEditor(int level)
        {
            bool rdonly = false;

            this.Controls.Clear();
            if (NodeObject.GetType().GetCustomAttributes(typeof(FieldEditorIgnore), false).Length == 1)
            {
                return;
            }

            PropertyInfo[] props  = NodeObject.GetType().GetProperties();
            int            top    = 5;
            int            left   = 3;
            int            fldCol = 105;
            int            lblWth = 100;
            int            fldWth = 300 - level * (lblWth + 7);
            int            fldHtn = 20;
            int            id     = 1;
            Control        ctl    = null;

            foreach (PropertyInfo pi in props)
            {
                fldHtn = 20;
                string name = pi.Name;
                FieldEditorAttibute atr;
                string ctlName;
                object ob;
                if (pi.GetCustomAttributes(typeof(FieldEditorIgnore), false).Length > 0)
                {
                    continue;
                }
                object[] attrs = pi.GetCustomAttributes(typeof(FieldEditorAttibute), false);
                if (attrs.Length > 0)
                {
                    atr     = (FieldEditorAttibute)attrs[0];
                    ctlName = atr.ControlName;
                    //name = atr.LabelKey;
                    ob = this.GetType().Assembly.CreateInstance(ctlName);
                    if (ob == null)
                    {
                        ob = typeof(TextBox).Assembly.CreateInstance(ctlName);
                    }
                    ctl = (Control)ob;
                    if (ctl is NodeEditorBase)
                    {
                        if (ctl is NodeEditor)
                        {
                            //here the node editor is recursive
                            // and should build another editor
                            //Initialize the Component the properties value with the
                            object o = pi.GetValue(NodeObject, null);
                            ((NodeEditorBase)ctl).NodeObject = o;
                            ((NodeEditorBase)ctl).buildEditor(level + 1);
                        }
                        else
                        {
                            ((NodeEditorBase)ctl).NodeObject = NodeObject;
                        }
                    }
                    else
                    {
                        // load the control where the value is obtained from the Node Object
                        atr.loadControl(ctl, pi, NodeObject);
                        ctl.Name = "txt_" + name + "_" + id;
                    }
                    fldHtn       = ctl.Height;
                    ctl.Size     = new System.Drawing.Size(fldWth, fldHtn);
                    ctl.Location = new System.Drawing.Point(fldCol, top);
                    ctl.TabIndex = 0;
                    this.Controls.Add(ctl);
                }
                else
                {
                    // ok default editor is a textbox
                    TextBox tb = new TextBox();
                    tb.Location = new System.Drawing.Point(fldCol, top);
                    tb.Name     = "txt_" + name + "_" + id;
                    tb.Size     = new System.Drawing.Size(fldWth, tb.Height);
                    tb.TabIndex = 0;
                    if (pi.GetCustomAttributes(typeof(FieldEditorReadonly), false).Length > 0)
                    {
                        tb.ReadOnly = true;
                    }
                    if (pi.GetValue(NodeObject, null) == null)
                    {
                        tb.Text = null;
                    }
                    else
                    {
                        tb.Text = pi.GetValue(NodeObject, null).ToString();
                    }
                    this.Controls.Add(tb);
                    ctl = tb;
                }

                Label lbl = new Label();
                lbl.Location = new System.Drawing.Point(3, top);
                lbl.Size     = new System.Drawing.Size(lblWth, fldHtn);
                lbl.Name     = "lbl_" + name + "_" + id;
                lbl.Text     = name;



                this.Controls.Add(lbl);
                top += ctl.Height + 2;//25;
                id  += 1;
            }
            if (level == 0)
            {
                Button btn = new Button();
                btn.Name   = "btnSave";
                btn.Click += new EventHandler(btnSave_Click);
                btn.Text   = "Done";
                btn.Top    = top;

                this.Controls.Add(btn);
            }
            top += 25;


            this.Height = top + 10;
        }
        private static NodeObject ConvertObject(NodeObjectData objectData, GameProjectLoadResult gResult, Dictionary <int, VisualObject> objectDictionary)
        {
            NodeObject instance = Activator.CreateInstance(Services.ProjectsService.DataModelManager.GetViewModelType(objectData.GetType()), true) as NodeObject;

            if (instance == null)
            {
                return((NodeObject)null);
            }
            instance.IsAutoSize = objectData.IsAutoSize;
            foreach (PropertyAccessorHandler property1 in objectData.GetProperties())
            {
                string propertyName = property1.PropertyName;
                if (!(propertyName == "Children"))
                {
                    PropertyInfo property2 = instance.GetType().GetProperty(propertyName);
                    object       obj1      = property1.GetValue((object)objectData, (object[])null);
                    if (property2 != (PropertyInfo)null && obj1 != null)
                    {
                        object obj2 = obj1;
                        if (!property2.PropertyType.Equals(property1.PropertyType))
                        {
                            if (!(obj1 is IDataConvert))
                            {
                                throw new InvalidCastException(string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", (object)instance.GetType().Name, (object)property2.PropertyType.Name, (object)property1.PropertyType.Name));
                            }
                            obj2 = ((IDataConvert)obj1).CreateViewModel();
                        }
                        property2.SetValue((object)instance, obj2, (object[])null);
                    }
                }
            }
            if (!objectDictionary.ContainsKey(instance.ActionTag))
            {
                objectDictionary.Add(instance.ActionTag, (VisualObject)instance);
            }
            IDataInitialize dataInitialize = (IDataInitialize)objectData;

            if (dataInitialize != null)
            {
                dataInitialize.DataInitialize((VisualObject)instance);
            }
            Type type = instance.GetType();

            if (gResult.TypeIndex.ContainsKey(type))
            {
                if (instance.ObjectIndex > gResult.TypeIndex[type])
                {
                    gResult.TypeIndex[type] = instance.ObjectIndex;
                }
            }
            else
            {
                gResult.TypeIndex.Add(type, instance.ObjectIndex);
            }
            if (objectData.Children != null)
            {
                foreach (NodeObjectData child in objectData.Children)
                {
                    NodeObject nodeObject = GameProjectLoader.ConvertObject(child, gResult, objectDictionary);
                    instance.Children.Add(nodeObject);
                }
            }
            instance.IsAutoSize = false;
            return(instance);
        }
 private static void ConvertTimeLineActionData(NodeObject nObject, TimelineActionData nTimelineActionData)
 {
     foreach (NodeObject child in (Collection <NodeObject>)nObject.Children)
     {
         GameProjectLoader.ConvertTimeLineActionData(child, nTimelineActionData);
         foreach (Timeline timeline in (Collection <Timeline>)child.Timelines)
         {
             if (timeline.Frames.Count > 0)
             {
                 TimelineData timelineData = new TimelineData();
                 timelineData.ActionTag = child.ActionTag;
                 timelineData.FrameType = timeline.FrameType;
                 timelineData.Frames    = new List <FrameData>();
                 foreach (Frame orderedFrame in timeline.OrderedFrames)
                 {
                     string name1 = orderedFrame.GetType().BaseType.Name;
                     if (name1 == "Frame")
                     {
                         name1 = orderedFrame.GetType().Name;
                     }
                     string    newValue = name1 + "Data";
                     FrameData instance = Activator.CreateInstance(Type.GetType(orderedFrame.GetType().FullName.Replace("CocoStudio.Model.ViewModel", "CocoStudio.Model.DataModel").Replace(orderedFrame.GetType().Name, newValue)), true) as FrameData;
                     if (instance != null)
                     {
                         foreach (PropertyInfo property1 in orderedFrame.GetType().GetProperties())
                         {
                             string name2 = property1.Name;
                             if (!(name2 == "Children"))
                             {
                                 PropertyInfo property2  = instance.GetType().GetProperty(name2);
                                 object       viewObject = property1.GetValue((object)orderedFrame, (object[])null);
                                 if (property2 != (PropertyInfo)null && viewObject != null)
                                 {
                                     object obj = viewObject;
                                     if (!property2.PropertyType.Equals(property1.PropertyType))
                                     {
                                         obj = Activator.CreateInstance(property2.PropertyType, true);
                                         if (!(obj is IDataConvert))
                                         {
                                             throw new InvalidCastException(string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", (object)nObject.GetType().Name, (object)property1.PropertyType.Name, (object)property2.PropertyType.Name));
                                         }
                                         ((IDataConvert)obj).SetData(viewObject);
                                     }
                                     property2.SetValue((object)instance, obj, (object[])null);
                                 }
                             }
                         }
                         timelineData.Frames.Add(instance);
                     }
                 }
                 nTimelineActionData.Timelines.Add(timelineData);
             }
         }
     }
 }
示例#7
0
        private static NodeObject ConvertObject(NodeObjectData objectData, GameProjectLoadResult gResult, Dictionary <int, VisualObject> objectDictionary)
        {
            Type       viewModelType = Services.ProjectsService.DataModelManager.GetViewModelType(objectData.GetType());
            NodeObject nodeObject    = Activator.CreateInstance(viewModelType, true) as NodeObject;
            NodeObject result;

            if (nodeObject == null)
            {
                result = null;
            }
            else
            {
                nodeObject.IsAutoSize = objectData.IsAutoSize;
                PropertyAccessorHandler[] properties = objectData.GetProperties();
                PropertyAccessorHandler[] array      = properties;
                for (int i = 0; i < array.Length; i++)
                {
                    PropertyAccessorHandler propertyAccessorHandler = array[i];
                    string propertyName = propertyAccessorHandler.PropertyName;
                    if (!(propertyName == "Children"))
                    {
                        PropertyInfo property = nodeObject.GetType().GetProperty(propertyName);
                        object       obj      = propertyAccessorHandler.GetValue(objectData, null);
                        if (property != null && obj != null)
                        {
                            object value = obj;
                            if (!property.PropertyType.Equals(propertyAccessorHandler.PropertyType))
                            {
                                if (!(obj is IDataConvert))
                                {
                                    string message = string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", nodeObject.GetType().Name, property.PropertyType.Name, propertyAccessorHandler.PropertyType.Name);
                                    throw new InvalidCastException(message);
                                }
                                value = ((IDataConvert)obj).CreateViewModel();
                            }
                            property.SetValue(nodeObject, value, null);
                        }
                    }
                }
                if (!objectDictionary.ContainsKey(nodeObject.ActionTag))
                {
                    objectDictionary.Add(nodeObject.ActionTag, nodeObject);
                }
                if (objectData != null)
                {
                    ((IDataInitialize)objectData).DataInitialize(nodeObject);
                }
                Type type = nodeObject.GetType();
                if (gResult.TypeIndex.ContainsKey(type))
                {
                    if (nodeObject.ObjectIndex > gResult.TypeIndex[type])
                    {
                        gResult.TypeIndex[type] = nodeObject.ObjectIndex;
                    }
                }
                else
                {
                    gResult.TypeIndex.Add(type, nodeObject.ObjectIndex);
                }
                if (objectData.Children != null)
                {
                    foreach (NodeObjectData current in objectData.Children)
                    {
                        NodeObject item = GameProjectLoader.ConvertObject(current, gResult, objectDictionary);
                        nodeObject.Children.Add(item);
                    }
                }
                nodeObject.IsAutoSize = false;
                result = nodeObject;
            }
            return(result);
        }
示例#8
0
 private static void ConvertTimeLineActionData(NodeObject nObject, TimelineActionData nTimelineActionData)
 {
     foreach (NodeObject current in nObject.Children)
     {
         GameProjectLoader.ConvertTimeLineActionData(current, nTimelineActionData);
         foreach (Timeline current2 in current.Timelines)
         {
             if (current2.Frames.Count > 0)
             {
                 TimelineData timelineData = new TimelineData();
                 timelineData.ActionTag = current.ActionTag;
                 timelineData.FrameType = current2.FrameType;
                 timelineData.Frames    = new List <FrameData>();
                 foreach (Frame current3 in current2.OrderedFrames)
                 {
                     string name = current3.GetType().BaseType.Name;
                     if (name == "Frame")
                     {
                         name = current3.GetType().Name;
                     }
                     string    newValue  = name + "Data";
                     string    typeName  = current3.GetType().FullName.Replace("CocoStudio.Model.ViewModel", "CocoStudio.Model.DataModel").Replace(current3.GetType().Name, newValue);
                     FrameData frameData = Activator.CreateInstance(Type.GetType(typeName), true) as FrameData;
                     if (frameData != null)
                     {
                         PropertyInfo[] properties = current3.GetType().GetProperties();
                         PropertyInfo[] array      = properties;
                         for (int i = 0; i < array.Length; i++)
                         {
                             PropertyInfo propertyInfo = array[i];
                             string       name2        = propertyInfo.Name;
                             if (!(name2 == "Children"))
                             {
                                 PropertyInfo property = frameData.GetType().GetProperty(name2);
                                 object       value    = propertyInfo.GetValue(current3, null);
                                 if (property != null && value != null)
                                 {
                                     object obj = value;
                                     if (!property.PropertyType.Equals(propertyInfo.PropertyType))
                                     {
                                         obj = Activator.CreateInstance(property.PropertyType, true);
                                         if (!(obj is IDataConvert))
                                         {
                                             string message = string.Format("Property type are not same, the item is {0}, ViewType is {1}, DataType is {2}, Can use IDataConvert interface to convert.", nObject.GetType().Name, propertyInfo.PropertyType.Name, property.PropertyType.Name);
                                             throw new InvalidCastException(message);
                                         }
                                         ((IDataConvert)obj).SetData(value);
                                     }
                                     property.SetValue(frameData, obj, null);
                                 }
                             }
                         }
                         timelineData.Frames.Add(frameData);
                     }
                 }
                 nTimelineActionData.Timelines.Add(timelineData);
             }
         }
     }
 }