Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add an option to view all calculated scores in Leaderboard screen #207

Merged
merged 1 commit into from
Jul 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions PerformanceCalculatorGUI/Components/LeaderboardTable.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,10 @@
public LeaderboardTable(int page, IReadOnlyList<LeaderboardUser> rankings)
: base(page, rankings)
{
Padding = new MarginPadding { Horizontal = 5 };
}

protected override RankingsTableColumn[] CreateAdditionalHeaders() => new[]

Check notice on line 34 in PerformanceCalculatorGUI/Components/LeaderboardTable.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Use collection expression in PerformanceCalculatorGUI\Components\LeaderboardTable.cs on line 34
{
new RankingsTableColumn("New PP", Anchor.Centre, new Dimension(GridSizeMode.AutoSize), true),
new RankingsTableColumn("Live PP", Anchor.Centre, new Dimension(GridSizeMode.AutoSize)),
Expand All @@ -46,7 +47,7 @@
return background;
}

protected sealed override Drawable[] CreateAdditionalContent(LeaderboardUser item) => new Drawable[]

Check notice on line 50 in PerformanceCalculatorGUI/Components/LeaderboardTable.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Use collection expression in PerformanceCalculatorGUI\Components\LeaderboardTable.cs on line 50
{
new FillFlowContainer
{
Expand Down Expand Up @@ -93,7 +94,7 @@
{
private readonly decimal difference;

public DifferenceText(decimal difference)

Check notice on line 97 in PerformanceCalculatorGUI/Components/LeaderboardTable.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Convert into primary constructor in PerformanceCalculatorGUI\Components\LeaderboardTable.cs on line 97
{
this.difference = difference;
}
Expand Down
104 changes: 93 additions & 11 deletions PerformanceCalculatorGUI/Screens/LeaderboardScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API.Requests;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
Expand All @@ -25,8 +26,22 @@

namespace PerformanceCalculatorGUI.Screens
{
public class UserLeaderboardData
{
public decimal LivePP { get; set; }
public decimal LocalPP { get; set; }

public List<ExtendedScore> Scores { get; set; }
}

public partial class LeaderboardScreen : PerformanceCalculatorScreen
{
public enum Tabs
{
Players,
Scores
}

[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Green);

Expand All @@ -35,11 +50,13 @@ public partial class LeaderboardScreen : PerformanceCalculatorScreen
private StatefulButton calculationButton;
private VerboseLoadingLayer loadingLayer;

private OsuScrollContainer leaderboardContainer;
private Container players;
private FillFlowContainer scores;
private OsuTabControl<Tabs> tabs;

private CancellationTokenSource calculationCancellatonToken;

public override bool ShouldShowConfirmationDialogOnSwitch => leaderboardContainer.Count > 0;
public override bool ShouldShowConfirmationDialogOnSwitch => players.Count > 0;

[Resolved]
private NotificationDisplay notificationDisplay { get; set; }
Expand All @@ -57,6 +74,7 @@ public partial class LeaderboardScreen : PerformanceCalculatorScreen
private SettingsManager configManager { get; set; }

private const int settings_height = 40;
private const int tabs_height = 20;

public LeaderboardScreen()
{
Expand Down Expand Up @@ -129,9 +147,38 @@ private void load()
},
new Drawable[]
{
leaderboardContainer = new OsuScrollContainer
new Container
{
RelativeSizeAxes = Axes.Both
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
tabs = new OsuTabControl<Tabs>
{
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Height = tabs_height,
Width = 145,
IsSwitchable = true
},
new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
players = new Container
{
RelativeSizeAxes = Axes.Both
},
scores = new FillFlowContainer
{
Margin = new MarginPadding { Top = tabs_height },
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
}
}
}
}
}
},
}
Expand All @@ -141,6 +188,28 @@ private void load()
RelativeSizeAxes = Axes.Both
}
};

scores.Hide();

tabs.Current.ValueChanged += e =>
{
switch (e.NewValue)
{
case Tabs.Players:
{
scores.Hide();
players.Show();
break;
}

case Tabs.Scores:
{
scores.Show();
players.Hide();
break;
}
}
};
}

protected override void Dispose(bool isDisposing)
Expand All @@ -160,7 +229,8 @@ private void calculate()
loadingLayer.Show();
calculationButton.State.Value = ButtonState.Loading;

leaderboardContainer.Clear();
players.Clear();
scores.Clear();

calculationCancellatonToken = new CancellationTokenSource();
var token = calculationCancellatonToken.Token;
Expand All @@ -172,6 +242,7 @@ private void calculate()
var leaderboard = await apiManager.GetJsonFromApi<GetTopUsersResponse>($"rankings/{ruleset.Value.ShortName}/performance?cursor[page]={pageTextBox.Value.Value - 1}");

var calculatedPlayers = new List<LeaderboardUser>();
var calculatedScores = new List<ExtendedScore>();

for (int i = 0; i < playerAmountTextBox.Value.Value; i++)
{
Expand All @@ -191,13 +262,23 @@ private void calculate()
LivePP = playerData.LivePP,
Difference = playerData.LocalPP - playerData.LivePP
});

calculatedScores.AddRange(playerData.Scores);
}

Schedule(() =>
{
var leaderboardTable = new LeaderboardTable(pageTextBox.Value.Value, calculatedPlayers.OrderByDescending(x => x.LocalPP).ToList());
var leaderboardTable = new LeaderboardTable(pageTextBox.Value.Value, calculatedPlayers.OrderByDescending(x => x.LocalPP).ToList())
{
Margin = new MarginPadding { Top = tabs_height }
};
LoadComponent(leaderboardTable);
leaderboardContainer.Add(leaderboardTable);
players.Add(leaderboardTable);

foreach (var calculatedScore in calculatedScores.OrderByDescending(x => x.PerformanceAttributes.Total))
{
scores.Add(new ExtendedProfileScore(calculatedScore));
}
});
}, token).ContinueWith(t =>
{
Expand All @@ -213,10 +294,10 @@ private void calculate()
}, token);
}

private async Task<UserCardData> calculatePlayer(UserStatistics player, CancellationToken token)
private async Task<UserLeaderboardData> calculatePlayer(UserStatistics player, CancellationToken token)
{
if (token.IsCancellationRequested)
return new UserCardData();
return new UserLeaderboardData();

var plays = new List<ExtendedScore>();

Expand Down Expand Up @@ -278,10 +359,11 @@ private async Task<UserCardData> calculatePlayer(UserStatistics player, Cancella
var playcountBonusPP = (totalLivePP - nonBonusLivePP);
totalLocalPP += playcountBonusPP;

return new UserCardData
return new UserLeaderboardData
{
LivePP = totalLivePP,
LocalPP = totalLocalPP
LocalPP = totalLocalPP,
Scores = plays
};
}
}
Expand Down
Loading