Exemple #1
0
        // 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]);
            };
        }
Exemple #2
0
        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;
        }
Exemple #3
0
        // 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);
                    }
                };
            }
        }
Exemple #4
0
        /// <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();
            };
        }
Exemple #5
0
 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);
 }
Exemple #6
0
 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);
 }
Exemple #7
0
 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));
 }
Exemple #8
0
 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);
 }
Exemple #9
0
 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);
         }
     };
 }
Exemple #10
0
 public TweakItemViewModel(ITweak tweak)
 {
     RawTweak         = tweak;
     Name.Text        = tweak.TweakTitle;
     Description.Text = tweak.TweakDescription;
 }
Exemple #11
0
 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 *.ini file.
 /// </summary>
 /// <param name="iniFile"></param>
 /// <param name="section"></param>
 /// <param name="key"></param>
 /// <returns></returns>
 public static ResourceList FromTweak(ITweak <string> tweak)
 {
     return(new ResourceList(tweak));
 }
 /// <summary>
 /// Associate a value in an *.ini file to save to and load from.
 /// </summary>
 /// <param name="tweak"></param>
 public void AssociateTweak(ITweak <string> tweak)
 {
     this.tweak = tweak;
 }
 /// <summary>
 /// Associates the *.ini value and loads the resource list.
 /// </summary>
 /// <param name="iniFile"></param>
 /// <param name="section"></param>
 /// <param name="key"></param>
 private ResourceList(ITweak <string> tweak)
 {
     AssociateTweak(tweak);
     LoadFromINI();
 }
Exemple #15
0
 public static void Log(this ITweak tweak, string message)
 {
     Plugin.Log($"[{tweak.Name}] " + message);
 }
Exemple #16
0
 public static void Log(this ITweak tweak, string format, params object[] args)
 {
     Plugin.Log($"[{tweak.Name}] " + format, args);
 }