feat(Program.cs): add sequence timer delay setting to customize delay between sequence steps
This commit is contained in:
@@ -12,6 +12,7 @@ using System.Threading.Tasks;
|
|||||||
namespace DD2Switcher {
|
namespace DD2Switcher {
|
||||||
public class Settings {
|
public class Settings {
|
||||||
public Keys SequenceKeybind { get; set; } = Keys.F1;
|
public Keys SequenceKeybind { get; set; } = Keys.F1;
|
||||||
|
public int SequenceTimerDelay { get; set; } = 100;
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static class Program {
|
internal static class Program {
|
||||||
@@ -89,7 +90,9 @@ namespace DD2Switcher {
|
|||||||
Console.WriteLine($"Read JSON: {json}");
|
Console.WriteLine($"Read JSON: {json}");
|
||||||
var settings = JsonSerializer.Deserialize<Settings>(json);
|
var settings = JsonSerializer.Deserialize<Settings>(json);
|
||||||
SequenceKeybind = settings.SequenceKeybind;
|
SequenceKeybind = settings.SequenceKeybind;
|
||||||
Console.WriteLine($"Loaded settings: Keybind={SequenceKeybind} (First/Last indices NOT loaded)");
|
SequenceTimerDelay = settings.SequenceTimerDelay;
|
||||||
|
Console.WriteLine(
|
||||||
|
$"Loaded settings: Keybind={SequenceKeybind}, TimerDelay={SequenceTimerDelay} (First/Last indices NOT loaded)");
|
||||||
} else {
|
} else {
|
||||||
Console.WriteLine($"Settings file does not exist at: {settingsPath}");
|
Console.WriteLine($"Settings file does not exist at: {settingsPath}");
|
||||||
Console.WriteLine("Using default settings");
|
Console.WriteLine("Using default settings");
|
||||||
@@ -100,12 +103,13 @@ namespace DD2Switcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void SaveSettings() {
|
public static void SaveSettings() {
|
||||||
try {
|
try {
|
||||||
var settings = new Settings { SequenceKeybind = SequenceKeybind };
|
var settings =
|
||||||
|
new Settings { SequenceKeybind = SequenceKeybind, SequenceTimerDelay = SequenceTimerDelay };
|
||||||
string json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true });
|
string json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true });
|
||||||
File.WriteAllText(settingsPath, json);
|
File.WriteAllText(settingsPath, json);
|
||||||
Console.WriteLine($"Saved settings: Keybind={SequenceKeybind}");
|
Console.WriteLine($"Saved settings: Keybind={SequenceKeybind}, TimerDelay={SequenceTimerDelay}");
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
Console.WriteLine($"Error saving settings: {ex.Message}");
|
Console.WriteLine($"Error saving settings: {ex.Message}");
|
||||||
}
|
}
|
||||||
@@ -191,6 +195,7 @@ namespace DD2Switcher {
|
|||||||
public static SequenceState CurrentState { get; set; } = SequenceState.INACTIVE;
|
public static SequenceState CurrentState { get; set; } = SequenceState.INACTIVE;
|
||||||
public static int CurrentSequenceIndex { get; set; } = -1;
|
public static int CurrentSequenceIndex { get; set; } = -1;
|
||||||
public static Keys SequenceKeybind { get; set; } = Keys.F1;
|
public static Keys SequenceKeybind { get; set; } = Keys.F1;
|
||||||
|
public static int SequenceTimerDelay { get; set; } = 100;
|
||||||
private static int sequenceHotkeyId = -1;
|
private static int sequenceHotkeyId = -1;
|
||||||
private static int ActiveIndex = -1;
|
private static int ActiveIndex = -1;
|
||||||
private static bool AltPressed = false;
|
private static bool AltPressed = false;
|
||||||
@@ -216,14 +221,16 @@ namespace DD2Switcher {
|
|||||||
|
|
||||||
private static void HandleWaitingToAdvance() {
|
private static void HandleWaitingToAdvance() {
|
||||||
// Start timer to advance after N milliseconds
|
// Start timer to advance after N milliseconds
|
||||||
Console.WriteLine($"Starting 60ms timer in WAITING_TO_ADVANCE state");
|
Console.WriteLine($"Starting {SequenceTimerDelay}ms timer in WAITING_TO_ADVANCE state");
|
||||||
Task.Delay(60).ContinueWith(_ => {
|
Task.Delay(SequenceTimerDelay)
|
||||||
if (CurrentState == SequenceState.WAITING_TO_ADVANCE) {
|
.ContinueWith(
|
||||||
CurrentState = SequenceState.ADVANCE;
|
_ => {
|
||||||
Console.WriteLine($"Timer expired, transitioning to ADVANCE state");
|
if (CurrentState == SequenceState.WAITING_TO_ADVANCE) {
|
||||||
HandleSequenceEvent();
|
CurrentState = SequenceState.ADVANCE;
|
||||||
}
|
Console.WriteLine($"Timer expired, transitioning to ADVANCE state");
|
||||||
});
|
HandleSequenceEvent();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void HandleAdvance() {
|
private static void HandleAdvance() {
|
||||||
|
@@ -13,6 +13,8 @@ namespace DD2Switcher {
|
|||||||
private FlowLayoutPanel windowsPanel;
|
private FlowLayoutPanel windowsPanel;
|
||||||
private Label sequenceKeybindLabel;
|
private Label sequenceKeybindLabel;
|
||||||
private TextBox sequenceKeybindTextBox;
|
private TextBox sequenceKeybindTextBox;
|
||||||
|
private Label sequenceTimerDelayLabel;
|
||||||
|
private NumericUpDown sequenceTimerDelayNumericUpDown;
|
||||||
|
|
||||||
public SettingsForm() {
|
public SettingsForm() {
|
||||||
InitializeComponent();
|
InitializeComponent();
|
||||||
@@ -27,9 +29,12 @@ namespace DD2Switcher {
|
|||||||
this.sequenceTab = new System.Windows.Forms.TabPage();
|
this.sequenceTab = new System.Windows.Forms.TabPage();
|
||||||
this.sequenceKeybindTextBox = new System.Windows.Forms.TextBox();
|
this.sequenceKeybindTextBox = new System.Windows.Forms.TextBox();
|
||||||
this.sequenceKeybindLabel = new System.Windows.Forms.Label();
|
this.sequenceKeybindLabel = new System.Windows.Forms.Label();
|
||||||
|
this.sequenceTimerDelayNumericUpDown = new System.Windows.Forms.NumericUpDown();
|
||||||
|
this.sequenceTimerDelayLabel = new System.Windows.Forms.Label();
|
||||||
this.tabControl.SuspendLayout();
|
this.tabControl.SuspendLayout();
|
||||||
this.windowsTab.SuspendLayout();
|
this.windowsTab.SuspendLayout();
|
||||||
this.sequenceTab.SuspendLayout();
|
this.sequenceTab.SuspendLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.sequenceTimerDelayNumericUpDown)).BeginInit();
|
||||||
this.SuspendLayout();
|
this.SuspendLayout();
|
||||||
//
|
//
|
||||||
// tabControl
|
// tabControl
|
||||||
@@ -66,6 +71,8 @@ namespace DD2Switcher {
|
|||||||
//
|
//
|
||||||
// sequenceTab
|
// sequenceTab
|
||||||
//
|
//
|
||||||
|
this.sequenceTab.Controls.Add(this.sequenceTimerDelayNumericUpDown);
|
||||||
|
this.sequenceTab.Controls.Add(this.sequenceTimerDelayLabel);
|
||||||
this.sequenceTab.Controls.Add(this.sequenceKeybindTextBox);
|
this.sequenceTab.Controls.Add(this.sequenceKeybindTextBox);
|
||||||
this.sequenceTab.Controls.Add(this.sequenceKeybindLabel);
|
this.sequenceTab.Controls.Add(this.sequenceKeybindLabel);
|
||||||
this.sequenceTab.Location = new System.Drawing.Point(4, 22);
|
this.sequenceTab.Location = new System.Drawing.Point(4, 22);
|
||||||
@@ -94,6 +101,27 @@ namespace DD2Switcher {
|
|||||||
this.sequenceKeybindLabel.TabIndex = 0;
|
this.sequenceKeybindLabel.TabIndex = 0;
|
||||||
this.sequenceKeybindLabel.Text = "Sequence Keybind:";
|
this.sequenceKeybindLabel.Text = "Sequence Keybind:";
|
||||||
//
|
//
|
||||||
|
// sequenceTimerDelayLabel
|
||||||
|
//
|
||||||
|
this.sequenceTimerDelayLabel.AutoSize = true;
|
||||||
|
this.sequenceTimerDelayLabel.Location = new System.Drawing.Point(20, 50);
|
||||||
|
this.sequenceTimerDelayLabel.Name = "sequenceTimerDelayLabel";
|
||||||
|
this.sequenceTimerDelayLabel.Size = new System.Drawing.Size(100, 13);
|
||||||
|
this.sequenceTimerDelayLabel.TabIndex = 2;
|
||||||
|
this.sequenceTimerDelayLabel.Text = "Timer Delay (ms):";
|
||||||
|
//
|
||||||
|
// sequenceTimerDelayNumericUpDown
|
||||||
|
//
|
||||||
|
this.sequenceTimerDelayNumericUpDown.Location = new System.Drawing.Point(126, 47);
|
||||||
|
this.sequenceTimerDelayNumericUpDown.Name = "sequenceTimerDelayNumericUpDown";
|
||||||
|
this.sequenceTimerDelayNumericUpDown.Size = new System.Drawing.Size(111, 20);
|
||||||
|
this.sequenceTimerDelayNumericUpDown.TabIndex = 3;
|
||||||
|
this.sequenceTimerDelayNumericUpDown.Minimum = 10;
|
||||||
|
this.sequenceTimerDelayNumericUpDown.Maximum = 10000;
|
||||||
|
this.sequenceTimerDelayNumericUpDown.Value = Program.SequenceTimerDelay;
|
||||||
|
this.sequenceTimerDelayNumericUpDown.ValueChanged +=
|
||||||
|
new System.EventHandler(this.sequenceTimerDelayNumericUpDown_ValueChanged);
|
||||||
|
//
|
||||||
// SettingsForm
|
// SettingsForm
|
||||||
//
|
//
|
||||||
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
|
||||||
@@ -111,6 +139,7 @@ namespace DD2Switcher {
|
|||||||
this.windowsTab.ResumeLayout(false);
|
this.windowsTab.ResumeLayout(false);
|
||||||
this.sequenceTab.ResumeLayout(false);
|
this.sequenceTab.ResumeLayout(false);
|
||||||
this.sequenceTab.PerformLayout();
|
this.sequenceTab.PerformLayout();
|
||||||
|
((System.ComponentModel.ISupportInitialize)(this.sequenceTimerDelayNumericUpDown)).EndInit();
|
||||||
this.ResumeLayout(false);
|
this.ResumeLayout(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -259,6 +288,19 @@ namespace DD2Switcher {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void sequenceTimerDelayNumericUpDown_ValueChanged(object sender, EventArgs e) {
|
||||||
|
Console.WriteLine(
|
||||||
|
$"sequenceTimerDelayNumericUpDown_ValueChanged called with value: {sequenceTimerDelayNumericUpDown.Value}");
|
||||||
|
try {
|
||||||
|
int newDelay = (int)sequenceTimerDelayNumericUpDown.Value;
|
||||||
|
Program.SequenceTimerDelay = newDelay;
|
||||||
|
Program.SaveSettings();
|
||||||
|
Console.WriteLine($"Timer delay updated to: {newDelay}ms");
|
||||||
|
} catch (Exception ex) {
|
||||||
|
Console.WriteLine($"Error updating timer delay: {ex.Message}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e) {
|
private void SettingsForm_FormClosing(object sender, FormClosingEventArgs e) {
|
||||||
Console.WriteLine("SettingsForm closing - saving keybind");
|
Console.WriteLine("SettingsForm closing - saving keybind");
|
||||||
try {
|
try {
|
||||||
|
Reference in New Issue
Block a user