Exemple #1
0
        private void createComponentRow(PropertyInfo prop, int row, PropertyFieldAttribute attr)
        {
            IList <ComponentRef> componentList = prop.GetValue(_selectedObject) as IList <ComponentRef>;
            Type comType = typeof(ComponentRef);

            for (int i = 0; i < componentList.Count; i++)
            {
                gridAddRowDef();
                CheckBox check = createCheckBox();
                check.IsChecked  = componentList[i].GetIsActive();
                check.Tag        = componentList[i];
                check.Checked   += Check_Checked;
                check.Unchecked += Check_Unchecked;
                gridAddTitle(15, componentList[i].GetName());
                gridAddEnd();
                ComponentRef          com       = componentList[i];
                List <ComponentField> fieldList = com.GetFields();
                for (int j = 0; j < fieldList.Count; j++)
                {
                    gridAddRowDef();
                    TextBlock title = gridAddTitle(30, fieldList[j].Name);
                    if ((fieldList[j].Type & ComponentFieldType.FT_FLOAT) == ComponentFieldType.FT_FLOAT ||
                        (fieldList[j].Type & ComponentFieldType.FT_INT) == ComponentFieldType.FT_INT)
                    {
                        NumberTextBox tb = createNumberTextBox();
                        tb.Text    = fieldList[j].Value;
                        tb.Tag     = fieldList[j];
                        tb._KeyUp += comNumTb__KeyUp;
                        title.Tag  = fieldList[j];
                        float value = Convert.ToSingle(fieldList[j].Value);
                        title.MouseLeftButtonDown += new MouseButtonEventHandler((object sender, MouseButtonEventArgs e) =>
                        {
                            _mouseDown = true;
                            _mousePosX = e.GetPosition(null).X;
                            title.CaptureMouse();
                        });
                        title.MouseMove += new MouseEventHandler((object sender, MouseEventArgs e) =>
                        {
                            if (_mouseDown)
                            {
                                double xPos      = e.GetPosition(null).X;
                                ComponentField f = (sender as TextBlock).Tag as ComponentField;
                                if ((f.Type & ComponentFieldType.FT_READONLY) == ComponentFieldType.FT_READONLY)
                                {
                                    return;
                                }
                                if ((f.Type & ComponentFieldType.FT_FLOAT) == ComponentFieldType.FT_FLOAT)
                                {
                                    if (xPos > _mousePosX)
                                    {
                                        value += 0.01f;
                                    }
                                    else if (xPos < _mousePosX)
                                    {
                                        value -= 0.01f;
                                    }
                                }
                                else if ((f.Type & ComponentFieldType.FT_INT) == ComponentFieldType.FT_INT)
                                {
                                    if (xPos > _mousePosX)
                                    {
                                        value += 1;
                                    }
                                    else if (xPos < _mousePosX)
                                    {
                                        value -= 1;
                                    }
                                }
                                tb.Text = value.ToString();
                                f.SetValue(tb.Text);
                                _mousePosX = xPos;
                            }
                        });
                        title.MouseLeftButtonUp += new MouseButtonEventHandler((object sender, MouseButtonEventArgs e) =>
                        {
                            _mouseDown = false;
                            _mousePosX = 0;
                            title.ReleaseMouseCapture();
                        });
                    }
                    else if (fieldList[j].Type == ComponentFieldType.FT_OBJECT)
                    {
                        TextBox tb = createTextBox(true);
                        tb.Tag    = fieldList[j];
                        tb.KeyUp += comTb_KeyUp;
                        tb.Text   = fieldList[j].Value;
                    }
                    else if (fieldList[j].Type == ComponentFieldType.FT_BOOLEAN)
                    {
                        ComboBox cb = createBoolControl();
                        cb.Tag = fieldList[j];
                        cb.SelectionChanged += comCb_SelectionChanged;
                        cb.SelectedIndex     = fieldList[j].Value == "true" ? 0 : 1;
                    }
                    else if (fieldList[j].Type == ComponentFieldType.FT_VECTOR3)
                    {
                        var      vecElement = new Vector3Control();
                        string[] vStr       = fieldList[j].Value.Split(',');
                        Vector3  vec        = new Vector3(Convert.ToSingle(vStr[0]), Convert.ToSingle(vStr[1]), Convert.ToSingle(vStr[2]));
                        vecElement.ValueObject     = vec;
                        vecElement.Margin          = new Thickness(0, 2, 2, 0);
                        vecElement.BorderThickness = new Thickness(0);
                        vecElement.Tag             = fieldList[j];
                        Grid.SetColumn(vecElement, 1);
                        Grid.SetRow(vecElement, _panelParent.RowDefinitions.Count - 1);
                        var template = (ControlTemplate)_View.Resources["validationErrorTemplate"];
                        Validation.SetErrorTemplate(vecElement, template);
                        vecElement.EnterKeyDown += VecElement_EnterKeyDown;
                        _panelParent.Children.Add(vecElement);
                    }
                    else
                    {
                        TextBox tb = createTextBox(false);
                        tb.Tag    = fieldList[j];
                        tb.KeyUp += comTb_KeyUp;
                        tb.Text   = fieldList[j].Value;
                    }
                    gridAddEnd();
                }
            }
        }