void System.Windows.Markup.IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.Control = ((ARK_Server_Manager.AnnotatedSlider)(target));
                return;

            case 2:
                this.Slider = ((System.Windows.Controls.Slider)(target));

            #line 291 "..\..\AnnotatedSlider.xaml"
                this.Slider.ValueChanged += new System.Windows.RoutedPropertyChangedEventHandler <double>(this.Slider_ValueChanged);

            #line default
            #line hidden
                return;

            case 3:
                this.Text = ((System.Windows.Controls.TextBox)(target));
                return;
            }
            this._contentLoaded = true;
        }
Exemplo n.º 2
0
        /// <summary>
        /// Function to add controls and events for an option
        /// </summary>
        /// <param name="MainForm_Control">The form object for the main form.</param>
        /// <param name="TabTarget">The TabPage object for the TabPage to target.</param>
        /// <param name="setting">The setting to apply as controls.</param>
        /// <param name="Position">The coords where the setting should be placed.</param>
        public void AddConfigOption(Form MainForm_Control, TabPage TabTarget, Setting setting, Point Position)
        {
            Control InputElement;

            // Define the control for saving the setting
            Button SaveSettingButton = new Button
            {
                Name     = "Save" + setting.ConfigName + "Button",
                Location = new Point(TabTarget.Width - 72, Position.Y - 3),
                Image    = Bitmap.FromHicon(SystemIcons.Application.Handle),
                Size     = new Size(30, 25),
                Enabled  = false
            };

            // Define the control for making the input

            switch (setting.InputType)
            {
            case "bool":     // Boolean input
                CheckBox InputElementCheckBox = new CheckBox();
                InputElementCheckBox.Name            = setting.ConfigName + "CheckBox";
                InputElementCheckBox.CheckedChanged += (s, e) => { };
                if (setting.value == null)
                {
                    InputElementCheckBox.Checked = setting.DefaultValue;
                }
                else if (setting.DefaultValue == null)
                {
                    InputElementCheckBox.Checked = false;
                }
                else
                {
                    InputElementCheckBox.Checked = setting.value;
                }
                InputElement = InputElementCheckBox;

                InputElementCheckBox.CheckedChanged += (s, e) => { SaveSettingButton.Enabled = true; };

                SaveSettingButton.Click += (s, e) => {
                    setting.value = InputElementCheckBox.Checked;
                    if (!setting.Save())
                    {
                        MessageBox.Show("Could not save bool setting.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        SaveSettingButton.Enabled = false;
                    }
                };

                break;

            case "slider":     // Integer input
                ElementHost InputElementTrackBar          = new ElementHost();
                ARK_Server_Manager.AnnotatedSlider Slider = new ARK_Server_Manager.AnnotatedSlider
                {
                    Maximum    = Convert.ToSingle(setting.Range[1]),
                    Minimum    = Convert.ToSingle(setting.Range[0]),
                    Value      = 1,
                    Background = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromRgb(0xFF, 0xFF, 0xFF))
                };

                if (setting.value == null && setting.DefaultValue != null)
                {
                    Slider.Value = setting.DefaultValue;
                }
                else if (setting.DefaultValue == null)
                {
                    Slider.Value = 0;
                }
                else
                {
                    Slider.Value = setting.value;
                }
                Slider.ValueChanged += (s, e) => { SaveSettingButton.Enabled = true; };
                dynamic HostedElement = MainForm_Control.Controls[setting.ConfigName + "TrackBar"];
                InputElementTrackBar.Child  = Slider;
                InputElementTrackBar.Name   = setting.ConfigName + "TrackBar";
                InputElementTrackBar.Height = 25;
                InputElement = InputElementTrackBar;
                InputElement = InputElementTrackBar;

                SaveSettingButton.Click += (s, e) => {
                    setting.value = Slider.Value;
                    if (!setting.Save())
                    {
                        MessageBox.Show("Could not save int setting.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        SaveSettingButton.Enabled = false;
                    }
                };

                break;

            default:     // Text input or unidentified input
                TextBox InputElementTextBox = new TextBox();
                InputElementTextBox.Name = setting.ConfigName + "TextBox";
                if (setting.value == null)
                {
                    InputElementTextBox.Text = setting.DefaultValue.ToString();
                }
                else if (setting.DefaultValue == null)
                {
                    InputElementTextBox.Text = "";
                }
                else
                {
                    InputElementTextBox.Text = setting.value;
                }
                InputElementTextBox.TextChanged += (s, e) => { };
                InputElement = InputElementTextBox;

                InputElementTextBox.TextChanged += (s, e) => { SaveSettingButton.Enabled = true; };

                SaveSettingButton.Click += (s, e) => {
                    setting.value = InputElementTextBox.Text;
                    if (!setting.Save())
                    {
                        MessageBox.Show("Could not save string setting.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    }
                    else
                    {
                        SaveSettingButton.Enabled = false;
                    }
                };

                break;
            }

            // Define the controls for setting name and saving the setting

            Label SettingNameLabel = new Label
            {
                Name     = setting.ConfigName + "Label",
                Location = Position,
                Text     = setting.Name
            };

            SettingNameLabel.Font = new Font(SettingNameLabel.Font.Name, 9.25F, SettingNameLabel.Font.Style, SettingNameLabel.Font.Unit);
            Position.X           += SettingNameLabel.Width;

            InputElement.Font = new Font(InputElement.Font.Name, 10.25F, InputElement.Font.Style, InputElement.Font.Unit);

            InputElement.Location = new Point(Position.X, SettingNameLabel.Location.Y - (InputElement.Height - SettingNameLabel.Height) / 2 - 2);
            InputElement.Width    = TabTarget.Width - 186;


            // Define the control for choosing between syncing setting with cluster
            Button SelectSyncButton = new Button
            {
                Name     = "SyncSelect" + setting.ConfigName + "Button",
                Location = new Point(TabTarget.Width - 40, Position.Y - 3),
                Image    = Bitmap.FromHicon(SystemIcons.Error.Handle),
                Size     = new Size(30, 25)
            };

            // Switch between syncing
            SelectSyncButton.Click += (s, e) => {
            };


            // Add the controls for the setting here
            void AddToLayout()
            {
                TabTarget.Controls.Add(InputElement);
                TabTarget.Controls.Add(SettingNameLabel);
                TabTarget.Controls.Add(SaveSettingButton);
                TabTarget.Controls.Add(SelectSyncButton);
            }

            //InputElement.Width = TabTarget.Width - PaddingLeft;


            if (TabTarget.InvokeRequired)
            {
                MainForm_Control.Invoke(new MethodInvoker(delegate
                {
                    AddToLayout();
                }));
            }
            else
            {
                AddToLayout();
            }
        }