/// <summary> /// This is specific code for the Pipboy/Quickboy/Power armor color picker. /// </summary> /// <param name="colorDialog">This dialog opens when "Pick color" button has been clicked.</param> /// <param name="preview">A picture box whose BackColor property gets set.</param> public static void LinkColor(Button pickColor, Button resetColor, ColorDialog colorDialog, ColorPreview preview, ITweak <Color> tweak) { SetValueActions.Add(() => preview.BackColor = tweak.GetValue()); preview.BackColorChanged += (object sender, EventArgs e) => { tweak.SetValue(preview.BackColor); }; pickColor.Click += (object sender, EventArgs e) => { colorDialog.Color = tweak.GetValue(); if (colorDialog.ShowDialog() == DialogResult.OK) { preview.BackColor = colorDialog.Color; tweak.SetValue(colorDialog.Color); } }; resetColor.Click += (object sender, EventArgs e) => { tweak.ResetValue(); preview.BackColor = tweak.GetValue(); }; }
// TODO: This needs to be refined: public static void LinkTweak <T>(ComboBox comboBox, T[] associatedValues, ITweak <T> tweak) { // TODO: This could potentially crash the tool on load: if (comboBox.Items.Count != associatedValues.Length) { throw new ArgumentException("LinkTweak: comboBox has to have as many items as associatedValues has!"); } SetValueActions.Add(() => { int index = Array.IndexOf(associatedValues, tweak.GetValue()); int defaultIndex = Array.IndexOf(associatedValues, tweak.DefaultValue); if (index > -1) { comboBox.SelectedIndex = index; } else if (defaultIndex > -1) { comboBox.SelectedIndex = defaultIndex; } else { throw new ArgumentException("LinkTweak: Couldn't assign a value to comboBox."); } }); comboBox.SelectionChangeCommitted += (object sender, EventArgs e) => { tweak.SetValue(associatedValues[comboBox.SelectedIndex]); }; }
public static void LinkTweak(RadioButton radioButtonTrue, RadioButton radioButtonFalse, ITweak <bool> tweak) { SetValueActions.Add(() => { if (tweak.GetValue()) { radioButtonTrue.Checked = true; } else { radioButtonFalse.Checked = true; } }); radioButtonTrue.MouseClick += (object sender, MouseEventArgs e) => { if (radioButtonTrue.Checked) { tweak.SetValue(true); } }; radioButtonFalse.MouseClick += (object sender, MouseEventArgs e) => { if (radioButtonFalse.Checked) { tweak.SetValue(false); } }; }
public static void LinkSize(NumericUpDown width, NumericUpDown height, ITweak <Size> tweak) { SetValueActions.Add(() => { Size size = tweak.GetValue(); width.Value = size.Width; height.Value = size.Height; }); EventHandler sizeChanged = (object sender, EventArgs e) => { Size newSize = new Size( Convert.ToInt32(width.Value), Convert.ToInt32(height.Value) ); tweak.SetValue(newSize); }; width.ValueChanged += sizeChanged; height.ValueChanged += sizeChanged; }
// TODO: This needs to be refined: public static void LinkTweak(Dictionary <string, RadioButton> radioButtons, ITweak <string> tweak) { SetValueActions.Add(() => { RadioButton radioButton; if (radioButtons.TryGetValue(tweak.GetValue(), out radioButton)) { radioButton.Checked = true; } }); // I have a really bad feeling about this: foreach (var pair in radioButtons) { pair.Value.MouseClick += (object sender, MouseEventArgs e) => { if (pair.Value.Checked) { tweak.SetValue(pair.Key); } }; } }
public static void LinkTweak(TextBox textBox, ITweak <string> tweak) { SetValueActions.Add(() => textBox.Text = tweak.GetValue()); textBox.TextChanged += (object sender, EventArgs e) => tweak.SetValue(textBox.Text); }
public static void LinkTweak(TrackBar slider, ITweak <int> tweak) { SetValueActions.Add(() => slider.Value = Utils.Clamp(tweak.GetValue(), Convert.ToInt32(slider.Minimum), Convert.ToInt32(slider.Maximum))); slider.ValueChanged += (object sender, EventArgs e) => tweak.SetValue(slider.Value); }
public static void LinkTweak(NumericUpDown num, ITweak <float> tweak) { SetValueActions.Add(() => num.Value = Convert.ToDecimal(Utils.Clamp(tweak.GetValue(), Convert.ToSingle(num.Minimum), Convert.ToSingle(num.Maximum)))); num.ValueChanged += (object sender, EventArgs e) => tweak.SetValue(Convert.ToSingle(num.Value)); }
public static void LinkTweak(ComboBox comboBox, ITweak <int> tweak) { SetValueActions.Add(() => comboBox.SelectedIndex = tweak.GetValue()); comboBox.SelectionChangeCommitted += (object sender, EventArgs e) => tweak.SetValue(comboBox.SelectedIndex); }
public static void LinkTweakNegated(CheckBox checkBox, ITweak <bool> tweak) { SetValueActions.Add(() => checkBox.Checked = !tweak.GetValue()); checkBox.MouseClick += (object sender, MouseEventArgs e) => tweak.SetValue(!checkBox.Checked); }
/// <summary> /// Loads the resource list from the associated *.ini file. /// </summary> public void LoadFromINI() { this.resourceList = ResourceList.ToList(tweak.GetValue()); }