diff --git a/ArcdpsLogManager/Configuration/Settings.cs b/ArcdpsLogManager/Configuration/Settings.cs index 7152dab2..8ce55237 100644 --- a/ArcdpsLogManager/Configuration/Settings.cs +++ b/ArcdpsLogManager/Configuration/Settings.cs @@ -40,6 +40,7 @@ public static class Settings MinimumLogDurationSecondsChanged += (sender, args) => SaveToFile(); IgnoredUpdateVersionsChanged += (sender, args) => SaveToFile(); DpsReportUploadDetailedWvwChanged += (sender, args) => SaveToFile(); + PlayerAccountNamesChanged += (sender, args) => SaveToFile(); return LoadFromFile(); }); @@ -276,6 +277,19 @@ public static bool DpsReportUploadDetailedWvw } } } + + public static IReadOnlyList PlayerAccountNames + { + get => Values.PlayerAccountNames; + set + { + if (!Equals(Values.PlayerAccountNames, value)) + { + Values.PlayerAccountNames = value.ToList(); + OnPlayerAccountNamesChanged(); + } + } + } public static event EventHandler LogRootPathChanged; public static event EventHandler ShowDebugDataChanged; @@ -290,6 +304,7 @@ public static bool DpsReportUploadDetailedWvw public static event EventHandler MinimumLogDurationSecondsChanged; public static event EventHandler IgnoredUpdateVersionsChanged; public static event EventHandler DpsReportUploadDetailedWvwChanged; + public static event EventHandler PlayerAccountNamesChanged; private static void OnLogRootPathsChanged() { @@ -355,5 +370,10 @@ private static void OnDpsReportUploadDetailedWvwChanged() { DpsReportUploadDetailedWvwChanged?.Invoke(null, EventArgs.Empty); } + + private static void OnPlayerAccountNamesChanged() + { + PlayerAccountNamesChanged?.Invoke(null, EventArgs.Empty); + } } } \ No newline at end of file diff --git a/ArcdpsLogManager/Configuration/StoredSettings.cs b/ArcdpsLogManager/Configuration/StoredSettings.cs index a140138e..f284fc43 100644 --- a/ArcdpsLogManager/Configuration/StoredSettings.cs +++ b/ArcdpsLogManager/Configuration/StoredSettings.cs @@ -25,4 +25,5 @@ public class StoredSettings public int? MinimumLogDurationSeconds { get; set; } = null; public List HiddenLogListColumns { get; set; } = new List() {"Character", "Map ID", "Game Version", "arcdps Version", "Instabilities", "Scale"}; public List IgnoredUpdateVersions { get; set; } = new List(); + public List PlayerAccountNames { get; set; } = new List(); } \ No newline at end of file diff --git a/ArcdpsLogManager/Sections/WeeklyClears.cs b/ArcdpsLogManager/Sections/WeeklyClears.cs index e0e7a733..a272e029 100644 --- a/ArcdpsLogManager/Sections/WeeklyClears.cs +++ b/ArcdpsLogManager/Sections/WeeklyClears.cs @@ -1,5 +1,6 @@ using Eto.Drawing; using Eto.Forms; +using GW2Scratch.ArcdpsLogManager.Configuration; using GW2Scratch.ArcdpsLogManager.Dialogs; using GW2Scratch.ArcdpsLogManager.Logs; using GW2Scratch.ArcdpsLogManager.Sections.Clears; @@ -98,7 +99,7 @@ private DateOnly Reset private readonly List weeks = GetAllResets().Select(x => new ResetWeek(x)).ToList(); // Not set directly, instead set through UpdateFinishedLogs - private HashSet<(string AccountName, DateOnly ResetDate, IFinishableEncounter Encounter, bool ChallengeMode)> finishedEncounters; + private HashSet<(string AccountName, DateOnly ResetDate, IFinishableEncounter Encounter, bool ChallengeMode)> finishedEncounters = []; // Cached from the update, we need this to be able to construct a player selection dialog. private List logs = []; @@ -148,10 +149,13 @@ private void UpdateWeeks() public WeeklyClears(ImageProvider imageProvider) { - // TODO: Add persistence - var accounts = new ObservableCollection(); var accountFilterBox = new DropDown { Width = 350 }; - accountFilterBox.DataStore = accounts; + accountFilterBox.DataStore = Settings.PlayerAccountNames.Select(x => x.TrimStart(':')); + if (Settings.PlayerAccountNames.Count != 0) + { + accountFilterBox.SelectedIndex = 0; + AccountFilter = Settings.PlayerAccountNames[0]; + } accountFilterBox.SelectedValueChanged += (_, _) => { AccountFilter = $":{accountFilterBox.SelectedValue}"; @@ -168,12 +172,13 @@ public WeeklyClears(ImageProvider imageProvider) { var selectedAccount = selectedPlayer.AccountName; // If this name is already added, we just select it. - if (!accounts.Contains(selectedAccount)) + if (!Settings.PlayerAccountNames.Contains(selectedAccount)) { - accounts.Add(selectedAccount.TrimStart(':')); + Settings.PlayerAccountNames = Settings.PlayerAccountNames.Append(selectedAccount).ToList(); } - accountFilterBox.SelectedIndex = accounts.Count - 1; + accountFilterBox.DataStore = Settings.PlayerAccountNames.Select(x => x.TrimStart(':')); + accountFilterBox.SelectedIndex = Settings.PlayerAccountNames.Count - 1; AccountFilter = selectedAccount; removeAccountButton.Enabled = true; DataUpdated?.Invoke(this, EventArgs.Empty); @@ -184,18 +189,25 @@ public WeeklyClears(ImageProvider imageProvider) var oldIndex = accountFilterBox.SelectedIndex; if (oldIndex >= 0) { - if (accounts.Count == 1) + var newIndex = -1; + if (Settings.PlayerAccountNames.Count == 1) { - accountFilterBox.SelectedIndex = -1; AccountFilter = ""; removeAccountButton.Enabled = false; } else { - accountFilterBox.SelectedIndex = 0; - AccountFilter = $":{accounts[0]}"; + newIndex = 0; + AccountFilter = Settings.PlayerAccountNames[0]; } - accounts.RemoveAt(oldIndex); + + // We need to make a copy of the list to edit it. + var newList = Settings.PlayerAccountNames.ToList(); + newList.RemoveAt(oldIndex); + + Settings.PlayerAccountNames = newList; + accountFilterBox.DataStore = Settings.PlayerAccountNames.Select(x => x.TrimStart(':')); + accountFilterBox.SelectedIndex = newIndex; DataUpdated?.Invoke(this, EventArgs.Empty); }