예제 #1
0
        private static void LoadGroupProperty(TableLayoutPanel tabPanel, Property property, int index, int maxIndex, int propertyHeight)
        {
            if (!PropertyOperateType.IsThirdPartType(property.OptType))
            {
                return;
            }

            Panel panel = new Panel
            {
                Dock    = DockStyle.Fill,
                Margin  = new Padding(0, 0, 0, 0),
                Padding = new Padding(0, 0, 0, 0),
            };

            tabPanel.Controls.Add(panel, 0, index);

            //获取组件共享的PictureBox
            PictureBox GroupPictureBox = GlobalConfig.Controller.GetPictureBox(property.GetGroupPictureBoxId());

            if (GroupPictureBox == null)
            {
                GroupPictureBox = new PictureBox
                {
                    Name        = property.GetPictureBoxId(), //TODO to make sure
                    Size        = new Size(0, 0),
                    Margin      = new Padding(0, 0, 0, 0),
                    Padding     = new Padding(0, 0, 0, 0),
                    SizeMode    = PictureBoxSizeMode.Zoom,
                    BorderStyle = BorderStyle.FixedSingle,
                    Location    = new Point(0, 0),
                    BackColor   = Color.Gray,
                    Visible     = false,
                };

                GlobalConfig.Controller.SetPictureBox(property.GetGroupPictureBoxId(), GroupPictureBox);
                GroupPictureBox.Tag = new ThirdPartApiClient(property.OptType, GroupPictureBox, maxIndex + 1);
                panel.Controls.Add(GroupPictureBox);
            }

            tabPanel.RowStyles.Add(new RowStyle(SizeType.Absolute, propertyHeight));

            Label label = new Label
            {
                Text      = property.Name,
                Location  = new Point(14, 0),
                Margin    = new Padding(0, 0, 0, 0),
                Padding   = new Padding(0, 0, 0, 0),
                Font      = new Font("微软雅黑", 10F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134))),
                Height    = 20,
                Width     = 180,
                TextAlign = ContentAlignment.MiddleLeft,
            };
            TextBox text = new TextBox
            {
                Name        = property.GetTextBoxColorID(),
                AutoSize    = false,
                Width       = 35,
                Height      = 25,
                Location    = new Point(label.Width + GlobalConfig.UiConfig.PropertyLabelMargin, 0),
                Margin      = new Padding(0, 0, 0, 0),
                BorderStyle = BorderStyle.FixedSingle,
                Tag         = property.Type
            };

            ((ThirdPartApiClient)(GroupPictureBox.Tag)).SetParam(index, text);
            panel.Controls.Add(label);
            panel.Controls.Add(text);


            if (property.Type == PropertyType.Int)
            {
                text.Text = property.DefaultValue;
                string lastText = text.Text;
                text.TextChanged += new EventHandler(delegate(object _, EventArgs b)
                {
                    if (text.Text.Trim(' ').Length == 0)
                    {
                        text.Text = lastText;
                        return;
                    }


                    int min, max;
                    bool ok = property.GetRangeAllowValue(out min, out max);

                    int textNumber;
                    if (!int.TryParse(text.Text, out textNumber))
                    {
                        if (ok)
                        {
                            MessageBox.Show(string.Format("请输入{0}-{1}的整数", min, max), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                        else
                        {
                            MessageBox.Show("请输入整数", "错误");
                        }

                        text.Text = lastText;
                        return;
                    }


                    if (ok && (textNumber < min || textNumber > max))
                    {
                        MessageBox.Show(string.Format("请输入{0}-{1}的整数", min, max), "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        text.Text = lastText;
                        return;
                    }

                    if (text.Text == lastText)
                    {
                        GlobalConfig.Project.Editer.Remove(property.Id);
                    }
                    else
                    {
                        lastText = text.Text;
                        Property propertyCopy     = property.Clone();
                        propertyCopy.DefaultValue = text.Text;
                        GlobalConfig.Project.Editer.Set(property.Id, propertyCopy);

                        ((ThirdPartApiClient)(GroupPictureBox.Tag)).Call();
                        GlobalConfig.Controller.ShowGroupOnCenterBoard(tabPanel, property.GetGroup());
                    }
                });
            }
            else if (property.Type == PropertyType.Color)
            {
                Button button = new Button
                {
                    Location  = new Point(panel.Width - 100, 0),
                    Width     = 100,
                    Height    = 26,
                    Font      = new Font("微软雅黑", 11F, FontStyle.Regular, GraphicsUnit.Point, ((byte)(134))),
                    TextAlign = ContentAlignment.MiddleCenter
                };
                if (property.DefaultValue != null && property.DefaultValue.Length > 0)
                {
                    try
                    {
                        text.BackColor = Color.FromArgb(
                            Convert.ToInt32(property.DefaultValue.Substring(2, 2), 16),
                            Convert.ToInt32(property.DefaultValue.Substring(4, 2), 16),
                            Convert.ToInt32(property.DefaultValue.Substring(6, 2), 16));
                    }
                    catch (Exception ex)
                    {
                        Console.WriteLine(ex.ToString());
                    }
                }

                button.Text   = "设置颜色";
                button.Click += new EventHandler(delegate(object _, EventArgs b)
                {
                    ColorDialog dialog = new ColorDialog();
                    if (dialog.ShowDialog() == DialogResult.OK)
                    {
                        if (dialog.Color.ToArgb() != text.BackColor.ToArgb())
                        {
                            Property propertyCopy     = property.Clone();
                            propertyCopy.DefaultValue = "0x" + dialog.Color.R.ToString("X2") + dialog.Color.G.ToString("X2") + dialog.Color.B.ToString("X2");
                            GlobalConfig.Project.Editer.Set(property.Id, propertyCopy);

                            text.BackColor = dialog.Color;
                            ((ThirdPartApiClient)(GroupPictureBox.Tag)).Call();
                            GlobalConfig.Controller.ShowGroupOnCenterBoard(tabPanel, property.GetGroup());
                        }
                        else
                        {
                            text.BackColor = dialog.Color;
                            GlobalConfig.Project.Editer.Remove(property.Id);
                        }
                    }
                });
                panel.Controls.Add(button);
            }

            if (index == maxIndex) //index 从1开始开始计数, 当是最后一个时
            {
                ((ThirdPartApiClient)(GroupPictureBox.Tag)).Call();
                GlobalConfig.Controller.ShowGroupOnCenterBoard(tabPanel, property.GetGroup());
            }
        }
        private List <PngUtil.MergeImageParams> ListGroupImageParams(TableLayoutPanel tabPanel, Group group)
        {
            List <Property> properties = GlobalConfig.Project.CarConfig.GroupIdToPropertyMapping[group.Id];
            List <PngUtil.MergeImageParams> mergeParams = new List <PngUtil.MergeImageParams>();

            foreach (Property property in properties)
            {
                if (property.Type == PropertyType.Image || property.OptType == PropertyOperateType.AlphaWhiteImageSetAlpha ||
                    property.OptType == PropertyOperateType.AlphaWhiteImageSetColor || property.OptType == PropertyOperateType.ImageFilterColor || PropertyOperateType.IsThirdPartType(property.OptType))
                {
                    Control[] pbCtl = tabPanel.Controls.Find(property.GetPictureBoxId(), true);
                    if (pbCtl.Length == 0)
                    {
                        continue;
                        Console.WriteLine("Get group property picturebox nil, property id={0}", property.Id);
                    }
                    PictureBox pb = (PictureBox)(pbCtl[0]);
                    if (!(bool)(pb).Enabled || pb.Image == null)  //checkbox 负责启用还是停用PictureBox
                    {
                        continue;
                    }

                    mergeParams.Add(new PngUtil.MergeImageParams
                    {
                        Image = ((PictureBox)pbCtl[0]).Image,
                        X     = property.GetLocation().X,
                        Y     = property.GetLocation().Y,
                    });
                }
            }
            return(mergeParams);
        }