Пример #1
0
        void CreateTextBox(int row, Type T, string name)
        {
            if (T.Equals(typeof(System.Int32)))
            {
                ModTextBox <int> txt = new ModTextBox <int>(
                    0, name, 0, panel, row, null, false);

                textBoxes.Add(txt);
            }
            else if (T.Equals(typeof(String)))
            {
                bool     findPath = false;
                string[] ext      = null;

                if (name.Contains("Filepath"))
                {
                    findPath = true;

                    ext = new string[]
                    {
                        ".Png", ".Jpg", ".Tga", ".Xnb"
                    };
                }

                ModTextBox <string> txt = new ModTextBox <string>(
                    "", name, 0, panel, row, ext, findPath);

                textBoxes.Add(txt);
            }
            else if (T.Equals(typeof(Single)))
            {
                ModTextBox <float> txt = new ModTextBox <float>(
                    0.0f, name, 0, panel, row, null, false);

                textBoxes.Add(txt);
            }
            else if (T.Equals(typeof(bool)))
            {
                ModTextBox <bool> txt = new ModTextBox <bool>(
                    false, name, 0, panel, row, null, false);

                textBoxes.Add(txt);
            }
            else if (T.Equals(typeof(Vector3)))
            {
                GroupedTextBox <float> txt = new GroupedTextBox <float>(
                    "", name, new float[] { 0, 0, 0 },
                    new string[] { "X", "Y", "Z" }, 0, panel, row);

                textBoxes.Add(txt);
            }
            else if (T.Equals(typeof(Vector2)))
            {
                GroupedTextBox <float> txt = new GroupedTextBox <float>(
                    "", name, new float[] { 0, 0 },
                    new string[] { "X", "Y" }, 0, panel, row);

                textBoxes.Add(txt);
            }
            else if (T.Equals(typeof(Vector4)))
            {
                GroupedTextBox <float> txt = new GroupedTextBox <float>(
                    "", name, new float[] { 0, 0, 0, 0 },
                    new string[] { "X", "Y", "Z", "W" }, 0, panel, row);

                textBoxes.Add(txt);
            }
            else if (T.Equals(typeof(Color)))
            {
                GroupedTextBox <byte> txt = new GroupedTextBox <byte>(
                    "", name, new byte[] { 0, 0, 0, 0 },
                    new string[] { "R", "G", "B", "A" }, 0, panel, row);

                textBoxes.Add(txt);
            }
        }
Пример #2
0
        public virtual void Create()
        {
            string name = PropertyHelper.GetTypeName(obj.ObjectType);

            ConstructorInfo[] ctors = AssemblyManager.GetType(obj.ObjectType).GetConstructors();
            ConstructorInfo   info  = null;

            if (obj.Parameters != null)
            {
                for (int i = 0; i < ctors.Length; i++)
                {
                    if (ctors[i].GetParameters().Length == obj.Parameters.Length)
                    {
                        info = ctors[i];
                    }
                }
            }
            else
            {
                if (ctors.Length > 1)
                {
                    int max = 0;

                    for (int i = 0; i < ctors.Length; i++)
                    {
                        if (ctors[i].GetParameters().Length > max)
                        {
                            info = ctors[i];
                            max  = info.GetParameters().Length;
                        }
                    }

                    obj.Parameters = new object[max];
                }
                else
                {
                    info           = ctors[0];
                    obj.Parameters = new object[info.GetParameters().Length];
                }
            }

            ParameterInfo[] param = info.GetParameters();

            for (int i = 0; i < param.Length; i++)
            {
                string paramName = PropertyHelper.GetName(param[i].Name);

                Type t = param[i].ParameterType;

                if (t == typeof(bool))
                {
                    table.Controls.Add(ControlCreator.CreateLabel(paramName, DockStyle.Left), 0, maxRow);

                    bool val = false;

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            val = (bool)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = val;
                        }
                    }
                    catch { }

                    ctrls.Add(new ModCheckBox("", val, i, table,
                                              maxRow, paramName));

                    maxRow++;
                }
                else if (t == typeof(string))
                {
                    table.Controls.Add(ControlCreator.CreateLabel(paramName, DockStyle.Left), 0, maxRow);

                    string val = "";

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            val = (string)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = val;
                        }
                    }
                    catch { }

                    if (paramName.Contains("Filepath"))
                    {
                        ModTextBox <string> txt = new ModTextBox <string>(
                            val, "", i, table, maxRow, new string[] { ".xnb" }, true);

                        ctrls.Add(txt);
                    }
                    else
                    {
                        ModTextBox <string> txt = new ModTextBox <string>(
                            val, i, table, maxRow);

                        ctrls.Add(txt);
                    }

                    maxRow++;
                }
                else if (t == typeof(Int32))
                {
                    table.Controls.Add(ControlCreator.CreateLabel(paramName, DockStyle.Left), 0, maxRow);

                    int val = 0;

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            val = (int)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = val;
                        }
                    }
                    catch { }

                    ctrls.Add(new ModTextBox <int>(
                                  val, i, table, maxRow));

                    maxRow++;
                }
                else if (t == typeof(Single))
                {
                    table.Controls.Add(ControlCreator.CreateLabel(paramName, DockStyle.Left), 0, maxRow);

                    float val = 0.0f;

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            val = (float)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = val;
                        }
                    }
                    catch { }

                    ctrls.Add(new ModTextBox <float>(
                                  val, i, table, maxRow));

                    maxRow++;
                }
                else if (t == typeof(Vector2))
                {
                    Vector2 vec = Vector2.Zero;

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            vec = (Vector2)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = vec;
                        }
                    }
                    catch { }

                    float[] array = new float[]
                    {
                        vec.X, vec.Y
                    };

                    string[] names = new string[]
                    {
                        "X", "Y"
                    };

                    GroupedTextBox <float> group = new GroupedTextBox <float>(
                        paramName, "", array, names, i, table, maxRow);

                    ctrls.Add(group);

                    maxRow = group.MaxRow;
                }
                else if (t == typeof(Vector3))
                {
                    Vector3 vec = Vector3.Zero;

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            vec = (Vector3)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = vec;
                        }
                    }
                    catch { }

                    float[] array = new float[]
                    {
                        vec.X, vec.Y, vec.Z
                    };

                    string[] names = new string[]
                    {
                        "X", "Y", "Z"
                    };

                    GroupedTextBox <float> group = new GroupedTextBox <float>(
                        paramName, "", array, names, i, table, maxRow);

                    ctrls.Add(group);

                    maxRow = group.MaxRow;
                }
                else if (t == typeof(Vector4))
                {
                    Vector4 vec = Vector4.Zero;

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            vec = (Vector4)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = vec;
                        }
                    }
                    catch { }

                    float[] array = new float[]
                    {
                        vec.X, vec.Y, vec.Z, vec.W
                    };

                    string[] names = new string[]
                    {
                        "X", "Y", "Z", "W"
                    };

                    GroupedTextBox <float> group = new GroupedTextBox <float>(
                        paramName, "", array, names, i, table, maxRow);

                    ctrls.Add(group);

                    maxRow = group.MaxRow;
                }
                else if (t == typeof(Microsoft.Xna.Framework.Color))
                {
                    Microsoft.Xna.Framework.Color col =
                        Microsoft.Xna.Framework.Color.White;

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            col = (Microsoft.Xna.Framework.Color)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = col;
                        }
                    }
                    catch { }

                    byte[] array = new byte[]
                    {
                        col.R, col.G, col.B, col.A
                    };

                    string[] names = new string[]
                    {
                        "R", "G", "B", "A"
                    };

                    GroupedTextBox <byte> group = new GroupedTextBox <byte>(
                        paramName, "", array, names, i, table, maxRow);

                    ctrls.Add(group);

                    maxRow = group.MaxRow;
                }
                else if (t == typeof(Microsoft.Xna.Framework.Rectangle))
                {
                    Microsoft.Xna.Framework.Rectangle rect =
                        Microsoft.Xna.Framework.Rectangle.Empty;

                    try
                    {
                        if (obj.Parameters[i] != null)
                        {
                            rect = (Microsoft.Xna.Framework.Rectangle)obj.Parameters[i];
                        }
                        else
                        {
                            obj.Parameters[i] = rect;
                        }
                    }
                    catch { }

                    int[] array = new int[]
                    {
                        rect.X, rect.Y, rect.Width, rect.Height
                    };

                    string[] names = new string[]
                    {
                        "X", "Y", "Width", "Height"
                    };

                    GroupedTextBox <int> group = new GroupedTextBox <int>(
                        paramName, "", array, names, i, table, maxRow);

                    ctrls.Add(group);

                    maxRow = group.MaxRow;
                }
            }
        }