Пример #1
0
        public void SelectModule(IRandomizerModule nodeTag)
        {
            if (_suspendLevels > 0)
            {
                return;
            }

            ModuleSelected?.Invoke(this, nodeTag);
        }
Пример #2
0
        private void PopulateList(IRandomizerModule module)
        {
            if (module == null)
            {
                return;
            }

            ListValueControls = Enumerable.Empty <Control>();

            var valueControlList = new List <Control>();

            List.SuspendLayout();
            List.Controls.Clear();
            List.Controls.AddRange(module.Parameters
                                   .OrderBy(p => p.Name)
                                   .Select(p =>
            {
                var panel = new TableLayoutPanel
                {
                    AutoSize     = true,
                    ColumnCount  = 3,
                    ColumnStyles =
                    {
                        new ColumnStyle(SizeType.AutoSize),
                        new ColumnStyle(SizeType.AutoSize),
                        new ColumnStyle(SizeType.Percent, 100)
                    },
                    Dock      = DockStyle.Top,
                    Margin    = new Padding(0, 5, 0, 5),
                    Padding   = new Padding(0),
                    RowCount  = 2,
                    RowStyles =
                    {
                        new RowStyle(SizeType.AutoSize),
                        new RowStyle(SizeType.AutoSize)
                    }
                };

                var nameLabel = new Label
                {
                    AutoSize = true,
                    Dock     = DockStyle.Top,
                    Margin   = new Padding(0),
                    Padding  = new Padding(0, 4, 0, 0),
                    Text     = p.Name ?? Resources.MissingParameterNameText
                };

                var enableCheckBox = new CheckBox
                {
                    AutoCheck  = false,
                    AutoSize   = true,
                    Padding    = new Padding(0, 4, 0, 0),
                    Margin     = new Padding(0),
                    ThreeState = true,
                    CheckState = MapEnableTypeToCheckState(p.EnableType),
                    Tag        = p
                };

                enableCheckBox.Click += (sender, args) =>
                                        enableCheckBox.CheckState = GetNextCheckState(enableCheckBox.CheckState);

                enableCheckBox.CheckStateChanged += (sender, args) =>
                                                    _controller.SetParameterEnableType(p, MapCheckStateToEnableType(enableCheckBox.CheckState));

                nameLabel.MouseDown += (sender, args) =>
                {
                    if (args.Button == MouseButtons.Left)
                    {
                        enableCheckBox.CheckState = GetNextCheckState(enableCheckBox.CheckState);
                    }
                };

                Control nameValue;

                if (p.Type == typeof(int))
                {
                    var numeric = new NumericUpDown
                    {
                        Maximum = int.MaxValue,
                        Minimum = int.MinValue,
                        Margin  = new Padding(0),
                        Padding = new Padding(0),
                        Tag     = p
                    };
                    valueControlList.Add(numeric);
                    numeric.TextChanged += (sender, args) => _controller.SetParameterValue(p, (int)numeric.Value);

                    nameValue = numeric;
                }
                else if (p.Type == typeof(bool))
                {
                    enableCheckBox.CheckStateChanged += (sender, args) =>
                                                        SetParameterValueFromCheckState(p, enableCheckBox.CheckState);

                    nameValue = new Panel {
                        Visible = false
                    };
                }
                else
                {
                    var text = new TextBox
                    {
                        Padding = new Padding(0, 0, 0, 0),
                        Margin  = new Padding(0),
                        Tag     = p
                    };
                    valueControlList.Add(text);
                    text.TextChanged += (sender, args) => _controller.SetParameterValue(p, text.Text);

                    nameValue = text;
                }

                var descriptionLabel = new Label
                {
                    AutoSize  = true,
                    Dock      = DockStyle.Top,
                    ForeColor = SystemColors.ControlDarkDark,
                    Margin    = new Padding(0),
                    Padding   = new Padding(0),
                    Text      = p.Description ?? Resources.MissingDescriptionNameText
                };

                panel.Controls.AddRange(new[] { enableCheckBox, nameLabel, nameValue, descriptionLabel });
                panel.SetColumnSpan(descriptionLabel, 3);

                return((Control)panel);
            })
                                   .ToArray());

            ListLabel.Text = module.Name;
            List.ResumeLayout();

            ListValueControls = valueControlList;

            UpdateList();
        }