This commit is contained in:
2025-08-31 22:11:04 +02:00
parent df936e187d
commit 88005c2125
3 changed files with 34 additions and 37 deletions

View File

@@ -7,6 +7,7 @@ using System.Runtime.InteropServices;
using System.Windows.Forms;
using System.Threading;
using System.Text.Json;
using System.Threading.Tasks;
namespace DD2Switcher {
public class Settings {
@@ -71,8 +72,6 @@ namespace DD2Switcher {
}
}
public static void ExitSequenceMode() {
CurrentState = SequenceState.INACTIVE;
CurrentSequenceIndex = -1;
@@ -203,12 +202,11 @@ namespace DD2Switcher {
private static bool AltPressed = false;
// State handlers
private static readonly Dictionary<SequenceState, Action> stateHandlers = new Dictionary<SequenceState, Action> {
{ SequenceState.INACTIVE, HandleInactive },
{ SequenceState.WAITING_FOR_EVENT, HandleWaitingForEvent },
{ SequenceState.WAITING_TO_ADVANCE, HandleWaitingToAdvance },
{ SequenceState.ADVANCE, HandleAdvance }
};
private static readonly Dictionary<SequenceState, Action> stateHandlers =
new Dictionary<SequenceState, Action> { { SequenceState.INACTIVE, HandleInactive },
{ SequenceState.WAITING_FOR_EVENT, HandleWaitingForEvent },
{ SequenceState.WAITING_TO_ADVANCE, HandleWaitingToAdvance },
{ SequenceState.ADVANCE, HandleAdvance } };
private static void HandleInactive() {
// Inactive state - do nothing
@@ -224,18 +222,17 @@ namespace DD2Switcher {
private static void HandleWaitingToAdvance() {
// Start timer to advance after N milliseconds
Console.WriteLine($"Starting 500ms timer in WAITING_TO_ADVANCE state");
Task.Delay(500).ContinueWith(_ => {
if (CurrentState == SequenceState.WAITING_TO_ADVANCE) {
CurrentState = SequenceState.ADVANCE;
Console.WriteLine($"Timer expired, transitioning to ADVANCE state");
HandleSequenceEvent();
}
});
System.Threading.Thread.Sleep(500);
if (CurrentState == SequenceState.WAITING_TO_ADVANCE) {
CurrentState = SequenceState.ADVANCE;
Console.WriteLine($"Timer expired, transitioning to ADVANCE state");
HandleSequenceEvent();
}
}
private static void HandleAdvance() {
Console.WriteLine($"Advancing sequence from ADVANCE state");
CurrentSequenceIndex++;
Console.WriteLine($"Advanced to index {CurrentSequenceIndex}");

View File

@@ -16,7 +16,7 @@ namespace DD2Switcher {
base.Dispose(disposing);
}
#region Windows Form Designer generated code
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
@@ -31,9 +31,9 @@ namespace DD2Switcher {
this.pickButton = new System.Windows.Forms.Button();
this.untrackButton = new System.Windows.Forms.Button();
this.SuspendLayout();
//
//
// indexLabel
//
//
this.indexLabel.AutoSize = true;
this.indexLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.indexLabel.Location = new System.Drawing.Point(10, 5);
@@ -41,9 +41,9 @@ namespace DD2Switcher {
this.indexLabel.Size = new System.Drawing.Size(52, 15);
this.indexLabel.TabIndex = 0;
this.indexLabel.Text = "Index: 0";
//
//
// nameLabel
//
//
this.nameLabel.AutoSize = true;
this.nameLabel.Font = new System.Drawing.Font("Segoe UI", 9F);
this.nameLabel.Location = new System.Drawing.Point(12, 35);
@@ -51,9 +51,9 @@ namespace DD2Switcher {
this.nameLabel.Size = new System.Drawing.Size(45, 15);
this.nameLabel.TabIndex = 1;
this.nameLabel.Text = "Name: ";
//
//
// pidLabel
//
//
this.pidLabel.AutoSize = true;
this.pidLabel.Font = new System.Drawing.Font("Segoe UI", 9F);
this.pidLabel.Location = new System.Drawing.Point(12, 50);
@@ -61,9 +61,9 @@ namespace DD2Switcher {
this.pidLabel.Size = new System.Drawing.Size(28, 15);
this.pidLabel.TabIndex = 2;
this.pidLabel.Text = "PID:";
//
//
// titleLabel
//
//
this.titleLabel.AutoSize = true;
this.titleLabel.Font = new System.Drawing.Font("Segoe UI", 9F);
this.titleLabel.Location = new System.Drawing.Point(12, 20);
@@ -72,9 +72,9 @@ namespace DD2Switcher {
this.titleLabel.Size = new System.Drawing.Size(36, 15);
this.titleLabel.TabIndex = 3;
this.titleLabel.Text = "Title: ";
//
//
// firstLastLabel
//
//
this.firstLastLabel.AutoSize = true;
this.firstLastLabel.Font = new System.Drawing.Font("Segoe UI", 9F, System.Drawing.FontStyle.Bold);
this.firstLastLabel.ForeColor = System.Drawing.Color.DarkBlue;
@@ -82,9 +82,9 @@ namespace DD2Switcher {
this.firstLastLabel.Name = "firstLastLabel";
this.firstLastLabel.Size = new System.Drawing.Size(0, 15);
this.firstLastLabel.TabIndex = 4;
//
//
// pickButton
//
//
this.pickButton.Location = new System.Drawing.Point(420, 10);
this.pickButton.Name = "pickButton";
this.pickButton.Size = new System.Drawing.Size(88, 25);
@@ -92,9 +92,9 @@ namespace DD2Switcher {
this.pickButton.Text = "Pick";
this.pickButton.UseVisualStyleBackColor = true;
this.pickButton.Click += new System.EventHandler(this.pickButton_Click);
//
//
// untrackButton
//
//
this.untrackButton.Location = new System.Drawing.Point(420, 45);
this.untrackButton.Name = "untrackButton";
this.untrackButton.Size = new System.Drawing.Size(88, 25);
@@ -102,9 +102,9 @@ namespace DD2Switcher {
this.untrackButton.Text = "Untrack";
this.untrackButton.UseVisualStyleBackColor = true;
this.untrackButton.Click += new System.EventHandler(this.untrackButton_Click);
//
//
// WindowPanelForm
//
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Controls.Add(this.indexLabel);
@@ -120,7 +120,7 @@ namespace DD2Switcher {
this.PerformLayout();
}
#endregion
#endregion
private System.Windows.Forms.Label indexLabel;
private System.Windows.Forms.Label nameLabel;
@@ -130,4 +130,4 @@ namespace DD2Switcher {
private System.Windows.Forms.Button pickButton;
private System.Windows.Forms.Button untrackButton;
}
}
}

View File

@@ -23,7 +23,7 @@ namespace DD2Switcher {
nameLabel.Text = $"Name: {WindowProcess.ProcessName}";
pidLabel.Text = $"PID: {WindowProcess.Id}";
titleLabel.Text = $"Title: {WindowProcess.MainWindowTitle}";
if (IsFirst && IsLast) {
firstLastLabel.Text = "First & Last";
} else if (IsFirst) {
@@ -44,4 +44,4 @@ namespace DD2Switcher {
UntrackClicked?.Invoke(this, WindowIndex);
}
}
}
}