1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 04:53:12 +08:00

Implemented delete local score individually. Currently does not refresh the score screen after the delete is compelete.

This commit is contained in:
Willy Tu 2019-12-16 19:25:28 -08:00
parent 866d1f44eb
commit bef9637fdf
4 changed files with 53 additions and 28 deletions

View File

@ -12,6 +12,7 @@ using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Threading; using osu.Framework.Threading;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online.API; using osu.Game.Online.API;
using osuTK; using osuTK;
@ -180,10 +181,14 @@ namespace osu.Game.Online.Leaderboards
{ {
new Drawable[] new Drawable[]
{ {
scrollContainer = new OsuScrollContainer new OsuContextMenuContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false, Child = scrollContainer = new OsuScrollContainer
{
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
}
} }
}, },
new Drawable[] new Drawable[]

View File

@ -14,11 +14,12 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites; using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Rulesets.UI; using osu.Game.Rulesets.UI;
using osu.Game.Screens.Select;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Users.Drawables; using osu.Game.Users.Drawables;
using osuTK; using osuTK;
@ -28,7 +29,7 @@ using osu.Game.Online.API;
namespace osu.Game.Online.Leaderboards namespace osu.Game.Online.Leaderboards
{ {
public class LeaderboardScore : OsuClickableContainer public class LeaderboardScore : OsuClickableContainer, IHasContextMenu
{ {
public const float HEIGHT = 60; public const float HEIGHT = 60;
@ -53,6 +54,8 @@ namespace osu.Game.Online.Leaderboards
private FillFlowContainer<ModIcon> modsContainer; private FillFlowContainer<ModIcon> modsContainer;
private List<ScoreComponentLabel> statisticsLabels; private List<ScoreComponentLabel> statisticsLabels;
private DialogOverlay dialogOverlay;
public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true) public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true)
{ {
@ -65,9 +68,10 @@ namespace osu.Game.Online.Leaderboards
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(IAPIProvider api, OsuColour colour) private void load(IAPIProvider api, OsuColour colour, DialogOverlay overlay)
{ {
var user = score.User; var user = score.User;
dialogOverlay = overlay;
statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList(); statisticsLabels = GetStatistics(score).Select(s => new ScoreComponentLabel(s)).ToList();
@ -230,28 +234,9 @@ namespace osu.Game.Online.Leaderboards
}, },
}; };
Add(
new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[] {
new ContextMenuArea{
RelativeSizeAxes = Axes.Both
}
}
}
);
innerAvatar.OnLoadComplete += d => d.FadeInFromZero(200); innerAvatar.OnLoadComplete += d => d.FadeInFromZero(200);
} }
private class ContextMenuArea : Drawable, IHasContextMenu
{
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("Delete", MenuItemType.Destructive),
};
}
public override void Show() public override void Show()
{ {
foreach (var d in new[] { avatar, nameLabel, scoreLabel, scoreRank, flagBadgeContainer, modsContainer }.Concat(statisticsLabels)) foreach (var d in new[] { avatar, nameLabel, scoreLabel, scoreRank, flagBadgeContainer, modsContainer }.Concat(statisticsLabels))
@ -381,5 +366,10 @@ namespace osu.Game.Online.Leaderboards
Value = value; Value = value;
} }
} }
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new BeatmapClearScoresDialog(this.score, null)))
};
} }
} }

View File

@ -39,6 +39,32 @@ namespace osu.Game.Screens.Select
}; };
} }
public BeatmapClearScoresDialog(ScoreInfo score, Action onCompletion)
{
string accuracy = string.Format(score?.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score?.Accuracy);
BodyText = $@"{score?.Beatmap?.Metadata?.Artist} - {score?.Beatmap?.Metadata?.Title} {Environment.NewLine} {score?.User} - Rank: {score?.Rank} - Max Combo: {score?.MaxCombo} - {accuracy} - {score?.Date.Date.ToShortDateString()}";
Icon = FontAwesome.Solid.Eraser;
HeaderText = @"Clearing this local score. Are you sure?";
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"Yes. Please.",
Action = () =>
{
Task.Run(() => scoreManager.Delete(score))
.ContinueWith(_ => onCompletion);
}
},
new PopupDialogCancelButton
{
Text = @"No, I'm still attached.",
},
};
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(ScoreManager scoreManager) private void load(ScoreManager scoreManager)
{ {

View File

@ -182,9 +182,13 @@ namespace osu.Game.Screens.Select.Leaderboards
return req; return req;
} }
protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index) => new LeaderboardScore(model, index, IsOnlineScope) protected override LeaderboardScore CreateDrawableScore(ScoreInfo model, int index){
{ model.Beatmap = beatmap;
Action = () => ScoreSelected?.Invoke(model)
}; return new LeaderboardScore(model, index, IsOnlineScope)
{
Action = () => ScoreSelected?.Invoke(model)
};
}
} }
} }