This commit is contained in:
seerge
2023-03-05 19:59:07 +01:00
parent 5038ff2315
commit 52b07843a2
6 changed files with 108 additions and 102 deletions

View File

@@ -1,11 +1,8 @@
using System.Diagnostics.Metrics;
namespace GHelper
namespace GHelper
{
public partial class Keyboard : Form
{
Dictionary<string, string> customActions = new Dictionary<string, string>
{
{"","--------------" },
@@ -16,82 +13,56 @@ namespace GHelper
{"custom", "Custom"}
};
private void SetKeyCombo(ComboBox combo, TextBox txbox, string name)
{
if (name == "m4")
customActions[""] = "Performance";
if (name == "fnf4")
{
customActions[""] = "Aura";
customActions.Remove("aura");
}
combo.DropDownStyle = ComboBoxStyle.DropDownList;
combo.DataSource = new BindingSource(customActions, null);
combo.DisplayMember = "Value";
combo.ValueMember = "Key";
string action = Program.config.getConfigString(name);
combo.SelectedValue = (action is not null) ? action : "";
if (combo.SelectedValue is null) combo.SelectedValue = "";
combo.SelectedValueChanged += delegate
{
if (combo.SelectedValue is not null)
Program.config.setConfig(name, combo.SelectedValue.ToString());
};
txbox.Text = Program.config.getConfigString(name + "_custom");
txbox.TextChanged += delegate
{
Program.config.setConfig(name + "_custom", txbox.Text);
};
}
public Keyboard()
{
InitializeComponent();
comboM3.DropDownStyle = ComboBoxStyle.DropDownList;
comboM3.DataSource = new BindingSource(customActions, null);
comboM3.DisplayMember = "Value";
comboM3.ValueMember = "Key";
customActions[""] = "Performance";
comboM4.DropDownStyle = ComboBoxStyle.DropDownList;
comboM4.DataSource = new BindingSource(customActions, null);
comboM4.DisplayMember = "Value";
comboM4.ValueMember = "Key";
comboM3.SelectedValueChanged += ComboM3_SelectedValueChanged;
comboM4.SelectedValueChanged += ComboM4_SelectedValueChanged;
textM3.TextChanged += TextM3_TextChanged;
textM4.TextChanged += TextM4_TextChanged;
SetKeyCombo(comboM3, textM3, "m3");
SetKeyCombo(comboM4, textM4, "m4");
SetKeyCombo(comboFNF4, textFNF4, "fnf4");
Shown += Keyboard_Shown;
}
private void TextM3_TextChanged(object? sender, EventArgs e)
{
if (sender is null) return;
TextBox tb = (TextBox)sender;
Program.config.setConfig("m3_custom", tb.Text);
}
private void TextM4_TextChanged(object? sender, EventArgs e)
{
if (sender is null) return;
TextBox tb = (TextBox)sender;
Program.config.setConfig("m4_custom", tb.Text);
}
private void ComboKeyChanged(object? sender, string name = "m3")
{
if (sender is null) return;
ComboBox cmb = (ComboBox)sender;
if (cmb.SelectedValue is not null)
Program.config.setConfig(name, cmb.SelectedValue.ToString());
}
private void ComboM4_SelectedValueChanged(object? sender, EventArgs e)
{
ComboKeyChanged(sender, "m4");
}
private void ComboM3_SelectedValueChanged(object? sender, EventArgs e)
{
ComboKeyChanged(sender, "m3");
}
private void Keyboard_Shown(object? sender, EventArgs e)
{
Top = Program.settingsForm.Top;
Left = Program.settingsForm.Left - Width - 5;
string m3 = Program.config.getConfigString("m3");
string m4 = Program.config.getConfigString("m4");
comboM3.SelectedValue = (m3 is not null) ? m3 : "";
comboM4.SelectedValue = (m4 is not null) ? m4 : "";
if (comboM3.SelectedValue is null) comboM3.SelectedValue = "";
if (comboM4.SelectedValue is null) comboM4.SelectedValue = "";
textM3.Text = Program.config.getConfigString("m3_custom");
textM4.Text = Program.config.getConfigString("m4_custom");
}
}
}