Skip to content

Commit

Permalink
Manager: Add persistence to weekly clears
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel committed Mar 10, 2024
1 parent 8ce2adb commit 1c6627a
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 12 deletions.
20 changes: 20 additions & 0 deletions ArcdpsLogManager/Configuration/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
});
Expand Down Expand Up @@ -276,6 +277,19 @@ public static bool DpsReportUploadDetailedWvw
}
}
}

public static IReadOnlyList<string> PlayerAccountNames
{
get => Values.PlayerAccountNames;
set
{
if (!Equals(Values.PlayerAccountNames, value))
{
Values.PlayerAccountNames = value.ToList();
OnPlayerAccountNamesChanged();
}
}
}

public static event EventHandler<EventArgs> LogRootPathChanged;
public static event EventHandler<EventArgs> ShowDebugDataChanged;
Expand All @@ -290,6 +304,7 @@ public static bool DpsReportUploadDetailedWvw
public static event EventHandler<EventArgs> MinimumLogDurationSecondsChanged;
public static event EventHandler<EventArgs> IgnoredUpdateVersionsChanged;
public static event EventHandler<EventArgs> DpsReportUploadDetailedWvwChanged;
public static event EventHandler<EventArgs> PlayerAccountNamesChanged;

private static void OnLogRootPathsChanged()
{
Expand Down Expand Up @@ -355,5 +370,10 @@ private static void OnDpsReportUploadDetailedWvwChanged()
{
DpsReportUploadDetailedWvwChanged?.Invoke(null, EventArgs.Empty);
}

private static void OnPlayerAccountNamesChanged()
{
PlayerAccountNamesChanged?.Invoke(null, EventArgs.Empty);
}
}
}
1 change: 1 addition & 0 deletions ArcdpsLogManager/Configuration/StoredSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public class StoredSettings
public int? MinimumLogDurationSeconds { get; set; } = null;
public List<string> HiddenLogListColumns { get; set; } = new List<string>() {"Character", "Map ID", "Game Version", "arcdps Version", "Instabilities", "Scale"};
public List<string> IgnoredUpdateVersions { get; set; } = new List<string>();
public List<string> PlayerAccountNames { get; set; } = new List<string>();
}
36 changes: 24 additions & 12 deletions ArcdpsLogManager/Sections/WeeklyClears.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -98,7 +99,7 @@ private DateOnly Reset
private readonly List<ResetWeek> 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<LogData> logs = [];
Expand Down Expand Up @@ -148,10 +149,13 @@ private void UpdateWeeks()

public WeeklyClears(ImageProvider imageProvider)
{
// TODO: Add persistence
var accounts = new ObservableCollection<string>();
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}";
Expand All @@ -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);
Expand All @@ -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);
}
Expand Down

0 comments on commit 1c6627a

Please sign in to comment.