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 sorting controls on Profile screen, add calculation cancellation with Esc key #214

Merged
merged 3 commits into from
Aug 31, 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
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

public PerformanceAttributes PerformanceAttributes { get; }

public ExtendedScore(SoloScoreInfo score, double livePP, PerformanceAttributes attributes)

Check notice on line 43 in PerformanceCalculatorGUI/Components/ExtendedProfileScore.cs

View workflow job for this annotation

GitHub Actions / Code Quality

Convert into primary constructor in PerformanceCalculatorGUI\Components\ExtendedProfileScore.cs on line 43
{
SoloScore = score;
PerformanceAttributes = attributes;
Expand Down Expand Up @@ -80,7 +80,7 @@

private const float performance_background_shear = 0.45f;

protected readonly ExtendedScore Score;
public readonly ExtendedScore Score;

[Resolved]
private OsuColour colours { get; set; }
Expand Down
12 changes: 12 additions & 0 deletions PerformanceCalculatorGUI/Components/ProfileSortCriteria.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

namespace PerformanceCalculatorGUI.Components
{
public enum ProfileSortCriteria
{
Live,
Difference,
Local
}
}
92 changes: 87 additions & 5 deletions PerformanceCalculatorGUI/Screens/ProfileScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input.Events;
using osu.Framework.Logging;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterfaceV2;
Expand All @@ -19,9 +20,11 @@
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osuTK.Graphics;
using osuTK.Input;
using PerformanceCalculatorGUI.Components;
using PerformanceCalculatorGUI.Components.TextBoxes;
using PerformanceCalculatorGUI.Configuration;
using ButtonState = PerformanceCalculatorGUI.Components.ButtonState;

namespace PerformanceCalculatorGUI.Screens
{
Expand All @@ -35,7 +38,7 @@ public partial class ProfileScreen : PerformanceCalculatorScreen

private GridContainer layout;

private FillFlowContainer scores;
private FillFlowContainer<ExtendedProfileScore> scores;

private LabelledTextBox usernameTextBox;
private Container userPanelContainer;
Expand All @@ -45,6 +48,9 @@ public partial class ProfileScreen : PerformanceCalculatorScreen

private CancellationTokenSource calculationCancellatonToken;

private OverlaySortTabControl<ProfileSortCriteria> sortingTabControl;
private readonly Bindable<ProfileSortCriteria> sorting = new Bindable<ProfileSortCriteria>(ProfileSortCriteria.Local);

[Resolved]
private NotificationDisplay notificationDisplay { get; set; }

Expand Down Expand Up @@ -78,7 +84,13 @@ private void load()
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[] { new Dimension() },
RowDimensions = new[] { new Dimension(GridSizeMode.Absolute, username_container_height), new Dimension(GridSizeMode.Absolute), new Dimension() },
RowDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, username_container_height),
new Dimension(GridSizeMode.Absolute),
new Dimension(GridSizeMode.AutoSize),
new Dimension()
},
Content = new[]
{
new Drawable[]
Expand Down Expand Up @@ -128,11 +140,30 @@ private void load()
}
},
new Drawable[]
{
new Container
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Children = new Drawable[]
{
sortingTabControl = new OverlaySortTabControl<ProfileSortCriteria>
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
Margin = new MarginPadding { Right = 22 },
Current = { BindTarget = sorting },
Alpha = 0
}
}
}
},
new Drawable[]
{
new OsuScrollContainer(Direction.Vertical)
{
RelativeSizeAxes = Axes.Both,
Child = scores = new FillFlowContainer
Child = scores = new FillFlowContainer<ExtendedProfileScore>
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Expand All @@ -149,6 +180,7 @@ private void load()
};

usernameTextBox.OnCommit += (_, _) => { calculateProfile(usernameTextBox.Current.Value); };
sorting.ValueChanged += e => { updateSorting(e.NewValue); };

if (RuntimeInfo.IsDesktop)
HotReloadCallbackReceiver.CompilationFinished += _ => Schedule(() => { calculateProfile(currentUser); });
Expand Down Expand Up @@ -191,7 +223,16 @@ private void calculateProfile(string username)
RelativeSizeAxes = Axes.X
});

layout.RowDimensions = new[] { new Dimension(GridSizeMode.Absolute, username_container_height), new Dimension(GridSizeMode.AutoSize), new Dimension() };
sortingTabControl.Alpha = 1.0f;
sortingTabControl.Current.Value = ProfileSortCriteria.Local;

layout.RowDimensions = new[]
{
new Dimension(GridSizeMode.Absolute, username_container_height),
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension()
};
});

if (token.IsCancellationRequested)
Expand Down Expand Up @@ -284,7 +325,7 @@ private void calculateProfile(string username)
loadingLayer.Hide();
calculationButton.State.Value = ButtonState.Done;
});
}, token);
}, TaskContinuationOptions.None);
}

protected override void Dispose(bool isDisposing)
Expand All @@ -295,5 +336,46 @@ protected override void Dispose(bool isDisposing)
calculationCancellatonToken?.Dispose();
calculationCancellatonToken = null;
}

protected override bool OnKeyDown(KeyDownEvent e)
{
if (e.Key == Key.Escape && !calculationCancellatonToken.IsCancellationRequested)
{
calculationCancellatonToken?.Cancel();
}

return base.OnKeyDown(e);
}

private void updateSorting(ProfileSortCriteria sortCriteria)
{
if (!scores.Children.Any())
return;

ExtendedProfileScore[] sortedScores;

switch (sortCriteria)
{
case ProfileSortCriteria.Live:
sortedScores = scores.Children.OrderByDescending(x => x.Score.LivePP).ToArray();
break;

case ProfileSortCriteria.Local:
sortedScores = scores.Children.OrderByDescending(x => x.Score.PerformanceAttributes.Total).ToArray();
break;

case ProfileSortCriteria.Difference:
sortedScores = scores.Children.OrderByDescending(x => x.Score.PerformanceAttributes.Total - x.Score.LivePP).ToArray();
break;

default:
throw new ArgumentOutOfRangeException(nameof(sortCriteria), sortCriteria, null);
}

for (int i = 0; i < sortedScores.Length; i++)
{
scores.SetLayoutPosition(sortedScores[i], i);
}
}
}
}
Loading