feat(Program.cs): implement automatic first and last index calculation for sequence mode

This commit is contained in:
2025-08-31 21:35:52 +02:00
parent 69fd02e331
commit 3b038b0fc9

View File

@@ -47,6 +47,23 @@ namespace DD2Switcher {
public static void StartSequenceMode() {
Console.WriteLine($"StartSequenceMode called. FirstIndex: {FirstIndex}, LastIndex: {LastIndex}");
// Compute default indices if not set by user
if (FirstIndex == -1 || LastIndex == -1) {
FirstIndex = FindFirstNonNullWindow();
LastIndex = FindLastNonNullWindow();
Console.WriteLine($"Computed default indices: FirstIndex={FirstIndex}, LastIndex={LastIndex}");
// Ensure LastIndex is different from FirstIndex if there are multiple windows
if (FirstIndex != -1 && LastIndex != -1 && FirstIndex == LastIndex) {
int nextWindow = FindNextNonNullWindow(FirstIndex + 1);
if (nextWindow != -1) {
LastIndex = nextWindow;
Console.WriteLine($"Adjusted LastIndex to: {LastIndex} (different from FirstIndex)");
}
}
}
if (FirstIndex >= 0 && LastIndex >= 0 && FirstIndex <= LastIndex) {
CurrentState = SequenceState.PROCESSING;
CurrentSequenceIndex = FirstIndex;
@@ -101,6 +118,8 @@ namespace DD2Switcher {
SequenceKeybind = settings.SequenceKeybind;
Console.WriteLine(
$"Loaded settings: First={FirstIndex}, Last={LastIndex}, Keybind={SequenceKeybind}");
} else {
Console.WriteLine("No settings file found, using defaults");
}
} catch (Exception ex) {
Console.WriteLine($"Error loading settings: {ex.Message}");
@@ -155,6 +174,16 @@ namespace DD2Switcher {
LastIndex = FindLastNonNullWindow();
Console.WriteLine($"Set default LastIndex to: {LastIndex}");
}
// Ensure LastIndex is different from FirstIndex if there are multiple windows
if (FirstIndex != -1 && LastIndex != -1 && FirstIndex == LastIndex) {
// Find the next non-null window after FirstIndex
int nextWindow = FindNextNonNullWindow(FirstIndex + 1);
if (nextWindow != -1) {
LastIndex = nextWindow;
Console.WriteLine($"Adjusted LastIndex to: {LastIndex} (different from FirstIndex)");
}
}
}
public static void UpdateSequenceHotkey(Keys newKey) {
@@ -175,6 +204,10 @@ namespace DD2Switcher {
SaveSettings();
}
public static void SaveFirstLastIndices() {
SaveSettings();
}
// Static properties for first/last selection persistence
public static int FirstIndex { get; set; } = -1;
public static int LastIndex { get; set; } = -1;
@@ -371,10 +404,6 @@ namespace DD2Switcher {
PushHistory(firstNullIndex);
ActiveIndex = firstNullIndex;
Console.WriteLine($"Added {process.ProcessName} to tracked windows at index {firstNullIndex}");
// Set default first/last indices if not set
SetDefaultFirstLastIndices();
SaveSettings();
}
private static void TrackProcess() {