feat(Program.cs): add sequence timer delay setting to customize delay between sequence steps

This commit is contained in:
2025-08-31 22:40:16 +02:00
parent f4524161ac
commit 32758cf062
2 changed files with 61 additions and 12 deletions

View File

@@ -12,6 +12,7 @@ using System.Threading.Tasks;
namespace DD2Switcher {
public class Settings {
public Keys SequenceKeybind { get; set; } = Keys.F1;
public int SequenceTimerDelay { get; set; } = 100;
}
internal static class Program {
@@ -89,7 +90,9 @@ namespace DD2Switcher {
Console.WriteLine($"Read JSON: {json}");
var settings = JsonSerializer.Deserialize<Settings>(json);
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 {
Console.WriteLine($"Settings file does not exist at: {settingsPath}");
Console.WriteLine("Using default settings");
@@ -100,12 +103,13 @@ namespace DD2Switcher {
}
}
private static void SaveSettings() {
public static void SaveSettings() {
try {
var settings = new Settings { SequenceKeybind = SequenceKeybind };
var settings =
new Settings { SequenceKeybind = SequenceKeybind, SequenceTimerDelay = SequenceTimerDelay };
string json = JsonSerializer.Serialize(settings, new JsonSerializerOptions { WriteIndented = true });
File.WriteAllText(settingsPath, json);
Console.WriteLine($"Saved settings: Keybind={SequenceKeybind}");
Console.WriteLine($"Saved settings: Keybind={SequenceKeybind}, TimerDelay={SequenceTimerDelay}");
} catch (Exception ex) {
Console.WriteLine($"Error saving settings: {ex.Message}");
}
@@ -191,6 +195,7 @@ namespace DD2Switcher {
public static SequenceState CurrentState { get; set; } = SequenceState.INACTIVE;
public static int CurrentSequenceIndex { get; set; } = -1;
public static Keys SequenceKeybind { get; set; } = Keys.F1;
public static int SequenceTimerDelay { get; set; } = 100;
private static int sequenceHotkeyId = -1;
private static int ActiveIndex = -1;
private static bool AltPressed = false;
@@ -216,14 +221,16 @@ namespace DD2Switcher {
private static void HandleWaitingToAdvance() {
// Start timer to advance after N milliseconds
Console.WriteLine($"Starting 60ms timer in WAITING_TO_ADVANCE state");
Task.Delay(60).ContinueWith(_ => {
if (CurrentState == SequenceState.WAITING_TO_ADVANCE) {
CurrentState = SequenceState.ADVANCE;
Console.WriteLine($"Timer expired, transitioning to ADVANCE state");
HandleSequenceEvent();
}
});
Console.WriteLine($"Starting {SequenceTimerDelay}ms timer in WAITING_TO_ADVANCE state");
Task.Delay(SequenceTimerDelay)
.ContinueWith(
_ => {
if (CurrentState == SequenceState.WAITING_TO_ADVANCE) {
CurrentState = SequenceState.ADVANCE;
Console.WriteLine($"Timer expired, transitioning to ADVANCE state");
HandleSequenceEvent();
}
});
}
private static void HandleAdvance() {

View File

@@ -13,6 +13,8 @@ namespace DD2Switcher {
private FlowLayoutPanel windowsPanel;
private Label sequenceKeybindLabel;
private TextBox sequenceKeybindTextBox;
private Label sequenceTimerDelayLabel;
private NumericUpDown sequenceTimerDelayNumericUpDown;
public SettingsForm() {
InitializeComponent();
@@ -27,9 +29,12 @@ namespace DD2Switcher {
this.sequenceTab = new System.Windows.Forms.TabPage();
this.sequenceKeybindTextBox = new System.Windows.Forms.TextBox();
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.windowsTab.SuspendLayout();
this.sequenceTab.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.sequenceTimerDelayNumericUpDown)).BeginInit();
this.SuspendLayout();
//
// tabControl
@@ -66,6 +71,8 @@ namespace DD2Switcher {
//
// sequenceTab
//
this.sequenceTab.Controls.Add(this.sequenceTimerDelayNumericUpDown);
this.sequenceTab.Controls.Add(this.sequenceTimerDelayLabel);
this.sequenceTab.Controls.Add(this.sequenceKeybindTextBox);
this.sequenceTab.Controls.Add(this.sequenceKeybindLabel);
this.sequenceTab.Location = new System.Drawing.Point(4, 22);
@@ -94,6 +101,27 @@ namespace DD2Switcher {
this.sequenceKeybindLabel.TabIndex = 0;
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
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
@@ -111,6 +139,7 @@ namespace DD2Switcher {
this.windowsTab.ResumeLayout(false);
this.sequenceTab.ResumeLayout(false);
this.sequenceTab.PerformLayout();
((System.ComponentModel.ISupportInitialize)(this.sequenceTimerDelayNumericUpDown)).EndInit();
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) {
Console.WriteLine("SettingsForm closing - saving keybind");
try {