Skip to content

Commit

Permalink
Manager: Add UI for account selection to weekly clears
Browse files Browse the repository at this point in the history
  • Loading branch information
Sejsel committed Mar 9, 2024
1 parent 4ff3abf commit 3ac395c
Showing 1 changed file with 63 additions and 21 deletions.
84 changes: 63 additions & 21 deletions ArcdpsLogManager/Sections/WeeklyClears.cs
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
using DebounceThrottle;
using Eto.Drawing;
using Eto.Forms;
using GW2Scratch.ArcdpsLogManager.Dialogs;
using GW2Scratch.ArcdpsLogManager.Logs;
using GW2Scratch.ArcdpsLogManager.Sections.Clears;
using GW2Scratch.EVTCAnalytics.GameData;
using GW2Scratch.EVTCAnalytics.GameData.Encounters;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Threading.Tasks;

Expand Down Expand Up @@ -70,8 +71,6 @@ public class WeeklyClears : DynamicLayout
])
];

private readonly DebounceDispatcher debounceDispatcher = new DebounceDispatcher(200);

private string accountFilter = "";

private string AccountFilter
Expand Down Expand Up @@ -101,6 +100,9 @@ private DateOnly Reset
// Not set directly, instead set through UpdateFinishedLogs
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 = [];

private void UpdateFinishedLogs(HashSet<(string AccountName, DateOnly ResetDate, IFinishableEncounter Encounter, bool ChallengeMode)> finished)
{
finishedEncounters = finished;
Expand Down Expand Up @@ -146,16 +148,57 @@ private void UpdateWeeks()

public WeeklyClears(ImageProvider imageProvider)
{
var accountFilterBox = new TextBox();
accountFilterBox.TextBinding.Bind(this, x => x.AccountFilter);
accountFilterBox.TextChanged += (_, _) =>
// TODO: Add persistence
var accounts = new ObservableCollection<string>();
var accountFilterBox = new DropDown { Width = 350 };
accountFilterBox.DataStore = accounts;
accountFilterBox.SelectedValueChanged += (_, _) =>
{
debounceDispatcher.Debounce(() =>
Application.Instance.InvokeAsync(() =>
AccountFilter = $":{accountFilterBox.SelectedValue}";
DataUpdated?.Invoke(this, EventArgs.Empty);
};

var addNewAccountButton = new Button { Text = "Add account" };
var removeAccountButton = new Button { Text = "Remove", Enabled = accountFilterBox.SelectedIndex != -1 };
addNewAccountButton.Click += (_, _) =>
{
var dialog = new PlayerSelectDialog(null, null, null, null, imageProvider, null, logs);
var selectedPlayer = dialog.ShowDialog(this);
if (selectedPlayer != null)
{
var selectedAccount = selectedPlayer.AccountName;
// If this name is already added, we just select it.
if (!accounts.Contains(selectedAccount))
{
DataUpdated?.Invoke(this, EventArgs.Empty);
})
);
accounts.Add(selectedAccount.TrimStart(':'));
}

accountFilterBox.SelectedIndex = accounts.Count - 1;
AccountFilter = selectedAccount;
removeAccountButton.Enabled = true;
DataUpdated?.Invoke(this, EventArgs.Empty);
}
};
removeAccountButton.Click += (_, _) =>
{
var oldIndex = accountFilterBox.SelectedIndex;
if (oldIndex >= 0)
{
if (accounts.Count == 1)
{
accountFilterBox.SelectedIndex = -1;
AccountFilter = "";
removeAccountButton.Enabled = false;
}
else
{
accountFilterBox.SelectedIndex = 0;
AccountFilter = $":{accounts[0]}";
}
accounts.RemoveAt(oldIndex);

DataUpdated?.Invoke(this, EventArgs.Empty);
}
};

var tables = new List<TableLayout>();
Expand Down Expand Up @@ -350,6 +393,7 @@ void UpdateChallengeModeCheckbox()
}

weekGrid.DataStore = weeks;
weekGrid.SelectedRow = 0;

weekGrid.SelectionChanged += (_, _) =>
{
Expand All @@ -358,18 +402,15 @@ void UpdateChallengeModeCheckbox()

DataUpdated += (_, _) =>
{
// To do this properly, we would need to use SelectableFilterCollection
// and update/remove the data within (without replacing it fully).
// For now, we try this simplistic approach and see if it's good enough
// (likely not).
weekGrid.UnselectAll();
weekGrid.DataStore = weeks;
weekGrid.ReloadData(Eto.Forms.Range.FromLength(0, weeks.Count));
};

// TODO: A better UI for this
AddRow(accountFilterBox);
// TODO: In the same row, add checkboxes for categories to show
BeginVertical(spacing: new Size(10, 10));
BeginVertical(padding: new Padding(0, 2), spacing: new Size(10, 10));
{
AddRow(accountFilterBox, addNewAccountButton, removeAccountButton, null);
// TODO: add checkboxes for categories to show
}
EndBeginVertical(spacing: new Size(10, 10));
{
BeginScrollable();
BeginHorizontal();
Expand All @@ -388,6 +429,7 @@ void UpdateChallengeModeCheckbox()

public void UpdateDataFromLogs(IEnumerable<LogData> logs)
{
this.logs = logs.ToList();
Task.Run(() =>
{
var logsByAccountNameWeek = new Dictionary<(string accountName, DateOnly resetDate), List<LogData>>();
Expand Down

0 comments on commit 3ac395c

Please sign in to comment.