Ejemplo n.º 1
0
        private void setMaterial(MT2 m)
        {
            lstSamplersAndTexCoordSources.Items.Clear();

            txtMaterialName.Text = m.Name;
            cboBaseMaterial.Text = m.BasedOffOf;

            setUIFromObject((MT2)Activator.CreateInstance(m.GetType()));
            setUIFromObject(m);

            //foreach (Sampler sampler in m.Defaults.Samplers)
            //{
            //}
        }
        private void setUIFromObject(MT2 m)
        {
            foreach (var property in m.GetType().GetProperties())
            {
                if (property.CanRead)
                {
                    object[] attributes = property.GetCustomAttributes(true);
                    bool     bRequired  = attributes.Any(a => a.GetType() == typeof(Required));

                    switch (property.PropertyType.ToString().Split('.').Last())
                    {
                    case "Vector3":
                        break;

                    case "Single":
                        NumericUpDown nud = (this.Controls.Find("nud" + property.Name, true).FirstOrDefault() as NumericUpDown);
                        if (nud == null)
                        {
                            nud = (NumericUpDown)controlWithTag(property.Name, this).First();
                        }
                        nud.Value = (Decimal)(Single)property.GetValue(m, null);
                        break;

                    case "Troolean":
                    {
                        CheckBox chk = (this.Controls.Find("chk" + property.Name, true).FirstOrDefault() as CheckBox);
                        if (chk == null)
                        {
                            chk = chkNoSortAlpha;
                        }
                        Troolean value = (Troolean)property.GetValue(m, null);
                        if (value != Troolean.Unset)
                        {
                            chk.Checked = (value == Troolean.True);
                        }
                    }
                    break;

                    case "String":
                    {
                        TextBox txt = (this.Controls.Find("txt" + property.Name, true).FirstOrDefault() as TextBox);
                        if (txt == null)
                        {
                            txt = (TextBox)controlWithTag(property.Name, this).FirstOrDefault();
                        }
                        if (txt == null)
                        {
                            Console.WriteLine("Couldn't find txt{0}", property.Name);
                            continue;
                        }

                        txt.Text = (string)property.GetValue(m, null);
                        setTextBoxState(txt);
                    }
                    break;

                    default:
                        Console.WriteLine("[{2}] {0} = {1}", property.Name, property.GetValue(m, null), property.PropertyType.ToString());
                        break;
                    }
                }
            }
        }