Spring – Rev 2
?pathlinks?
using System;
using System.ComponentModel;
using System.Drawing;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using Spring.Properties;
namespace Spring.Settings
{
public partial class SettingsForm : Form
{
#region Public Enums, Properties and Fields
public BindingList<string> WhitelistBinding { get; set; }
#endregion
#region Private Delegates, Events, Enums, Properties, Indexers and Fields
private Region PanelRegion { get; set; }
private Graphics PanelGraphics { get; set; }
private SolidBrush PanelSolidColorBrush { get; set; }
private RectangleF PanelBounds { get; }
private Configuration.Configuration Configuration { get; }
#endregion
#region Constructors, Destructors and Finalizers
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && components != null)
{
PanelRegion?.Dispose();
PanelRegion = null;
PanelGraphics?.Dispose();
PanelGraphics = null;
PanelSolidColorBrush?.Dispose();
PanelSolidColorBrush = null;
components.Dispose();
}
base.Dispose(disposing);
}
public SettingsForm(Configuration.Configuration springConfiguration) : this()
{
Configuration = springConfiguration;
WhitelistBinding = new BindingList<string>(Configuration.HUD.WhiteList.Whitelist);
windowWhiteListListBox.DataSource = WhitelistBinding;
enableWindowWhiteListCheckBox.DataBindings.Add(nameof(enableWindowWhiteListCheckBox.Checked),
Configuration.HUD,
nameof(Configuration.HUD.EnableWhiteList),
false,
DataSourceUpdateMode.OnPropertyChanged);
fuzzTrackBar.DataBindings.Add(nameof(fuzzTrackBar.Value),
Configuration.Spring,
nameof(Configuration.Spring.Fuzz),
false,
DataSourceUpdateMode.OnPropertyChanged);
textBox2.Text = Configuration.Spring.Fuzz.ToString();
hudColorLabel.DataBindings.Add(nameof(hudColorLabel.BackColor),
Configuration.HUD,
nameof(Configuration.HUD.Color),
false,
DataSourceUpdateMode.OnPropertyChanged);
enableHudCheckBox.DataBindings.Add(nameof(enableHudCheckBox.Checked),
Configuration.HUD,
nameof(Configuration.HUD.Enable),
false,
DataSourceUpdateMode.OnPropertyChanged);
enableKeyboardCheckbox.DataBindings.Add(nameof(enableKeyboardCheckbox.Checked),
Configuration.Spring.Charge,
nameof(Configuration.Spring.Charge.Keyboard),
false,
DataSourceUpdateMode.OnPropertyChanged);
useRelativeMouseMovementCheckbox.DataBindings.Add(nameof(useRelativeMouseMovementCheckbox.Checked),
Configuration.Spring.Discharge,
nameof(Configuration.Spring.Discharge.UseRelativeMouseMovement),
false,
DataSourceUpdateMode.OnPropertyChanged);
enableMouseMoveCheckBox.DataBindings.Add(nameof(enableMouseMoveCheckBox.Checked),
Configuration.Spring.Charge,
nameof(Configuration.Spring.Charge.MouseMove),
false,
DataSourceUpdateMode.OnPropertyChanged);
enableMouseClickCheckBox.DataBindings.Add(nameof(enableMouseClickCheckBox.Checked),
Configuration.Spring.Charge,
nameof(Configuration.Spring.Charge.MouseClick),
false,
DataSourceUpdateMode.OnPropertyChanged);
chargeDelayTrackBar.DataBindings.Add(nameof(chargeDelayTrackBar.Value),
Configuration.Spring.Charge,
nameof(Configuration.Spring.Charge.ChargeSeconds),
false,
DataSourceUpdateMode.OnPropertyChanged);
textBox3.Text = Configuration.Spring.Charge.ChargeSeconds.ToString();
maximumRepeatsTrackBar.DataBindings.Add(nameof(maximumRepeatsTrackBar.Value),
Configuration.Spring.Charge,
nameof(Configuration.Spring.Charge.MaximumRepeats),
false,
DataSourceUpdateMode.OnPropertyChanged);
textBox1.Text = Configuration.Spring.Charge.MaximumRepeats.ToString();
}
private SettingsForm()
{
InitializeComponent();
PanelGraphics = hudPostionPanel.CreateGraphics();
PanelBounds = PanelGraphics.VisibleClipBounds;
PanelSolidColorBrush = new SolidBrush(hudPostionPanel.BackColor);
PanelRegion = new Region(PanelBounds);
}
#endregion
#region Event Handlers
private void SettingsForm_Load(object sender, EventArgs e)
{
Utilities.WindowState.FormTracker.Track(this);
}
private void ListBox1_SelectedIndexChanged(object sender, EventArgs e)
{
var listBox = (ListBox) sender;
var item = listBox.SelectedItem;
if (item == null)
{
return;
}
whiteListEntryTextBox.Text = item.ToString();
}
private void Button2_Click(object sender, EventArgs e)
{
var text = whiteListEntryTextBox.Text;
if (string.IsNullOrEmpty(text))
{
return;
}
try
{
var _ = new Regex(text, RegexOptions.Compiled);
}
catch
{
return;
}
if (!WhitelistBinding.Contains(text))
{
WhitelistBinding.Add(text);
}
}
private void Button3_Click(object sender, EventArgs e)
{
var item = windowWhiteListListBox.SelectedItem;
if (item == null)
{
return;
}
var text = item.ToString();
if (string.IsNullOrEmpty(text))
{
return;
}
if (WhitelistBinding.Contains(text))
{
WhitelistBinding.Remove(text);
}
}
private void Button1_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
Configuration.HUD.Color = colorDialog1.Color;
hudColorLabel.BackColor = colorDialog1.Color;
}
private void SpringSettingsForm_Shown(object sender, EventArgs e)
{
var x = Configuration.HUD.Position.X * PanelBounds.Width / 100f;
var y = Configuration.HUD.Position.Y * PanelBounds.Height / 100f;
PanelGraphics.FillRegion(PanelSolidColorBrush, PanelRegion);
PanelGraphics.DrawIcon(Resources.x,
(int) (x - Resources.x.Width / 2f),
(int) (y - Resources.x.Height / 2f));
}
private void HUDPositionPanel_MouseClick(object sender, MouseEventArgs e)
{
var x = e.Location.X;
var y = e.Location.Y;
Configuration.HUD.Position.X = (int) (100f * x / PanelBounds.Width);
Configuration.HUD.Position.Y = (int) (100f * y / PanelBounds.Height);
PanelGraphics.FillRegion(PanelSolidColorBrush, PanelRegion);
PanelGraphics.DrawIcon(Resources.x,
(int) (x - Resources.x.Width / 2f),
(int) (y - Resources.x.Height / 2f));
}
private void HUDColorLabel_Click(object sender, EventArgs e)
{
if (colorDialog1.ShowDialog() != DialogResult.OK)
{
return;
}
Configuration.HUD.Color = colorDialog1.Color;
hudColorLabel.BackColor = colorDialog1.Color;
}
private void TabControl1_SelectedIndexChanged(object sender, EventArgs e)
{
var x = Configuration.HUD.Position.X * PanelBounds.Width / 100f;
var y = Configuration.HUD.Position.Y * PanelBounds.Height / 100f;
PanelGraphics.FillRegion(PanelSolidColorBrush, PanelRegion);
PanelGraphics.DrawIcon(Resources.x,
(int) (x - Resources.x.Width / 2f),
(int) (y - Resources.x.Height / 2f));
}
private void FuzzTrackBar_Scroll(object sender, EventArgs e)
{
var trackBar = (TrackBar) sender;
textBox2.Text = trackBar.Value.ToString();
}
private void TextBox2_TextChanged(object sender, EventArgs e)
{
var textBox = (TextBox) sender;
if (!int.TryParse(textBox.Text, out var value) ||
value < fuzzTrackBar.Minimum ||
value > fuzzTrackBar.Maximum)
{
return;
}
fuzzTrackBar.Value = value;
}
private void MaximumRepeatsTrackBar_Scroll(object sender, EventArgs e)
{
var trackBar = (TrackBar) sender;
textBox1.Text = trackBar.Value.ToString();
}
private void TextBox3_TextChanged(object sender, EventArgs e)
{
var textBox = (TextBox) sender;
if (!int.TryParse(textBox.Text, out var value) ||
value < chargeDelayTrackBar.Minimum ||
value > chargeDelayTrackBar.Maximum)
{
return;
}
chargeDelayTrackBar.Value = value;
}
private void ChargeDelayTrackBar_Scroll(object sender, EventArgs e)
{
var trackBar = (TrackBar) sender;
textBox3.Text = trackBar.Value.ToString();
}
private void TextBox1_TextChanged(object sender, EventArgs e)
{
var textBox = (TextBox) sender;
if (!int.TryParse(textBox.Text, out var value) ||
value < maximumRepeatsTrackBar.Minimum ||
value > maximumRepeatsTrackBar.Maximum)
{
return;
}
maximumRepeatsTrackBar.Value = value;
}
#endregion
}
}