1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 23:12:56 +08:00

Update Scoreboard Refresh Method for deleting individual scores

This commit is contained in:
Willy Tu 2019-12-18 19:22:42 -08:00
parent d1fcadc700
commit 531ac16743
4 changed files with 90 additions and 27 deletions

View File

@ -58,8 +58,6 @@ namespace osu.Game.Online.Leaderboards
private DialogOverlay dialogOverlay;
public Action RefreshAction { get; set; }
public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true)
{
this.score = score;
@ -370,13 +368,20 @@ namespace osu.Game.Online.Leaderboards
}
}
private void deleteLocalScore(ScoreInfo score)
{
if (score == null || score.ID <= 0) return;
dialogOverlay?.Push(new LocalScoreDeleteDialog(score));
}
public MenuItem[] ContextMenuItems
{
get
{
return (this.allowHighlight) ? null : new MenuItem[]
{
new OsuMenuItem("Delete", MenuItemType.Destructive, () => dialogOverlay?.Push(new BeatmapClearScoresDialog(this.score, () => Schedule(this.RefreshAction))))
new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteLocalScore(this.score))
};
}
}

View File

@ -39,28 +39,6 @@ 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 = (() => scoreManager.Delete(score)) + onCompletion
},
new PopupDialogCancelButton
{
Text = @"No, I'm still attached.",
},
};
}
[BackgroundDependencyLoader]
private void load(ScoreManager scoreManager)
{

View File

@ -19,8 +19,10 @@ namespace osu.Game.Screens.Select.Leaderboards
{
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>
{
public Action<ScoreInfo> ScoreSelected;
[Resolved]
private RulesetStore rulesets { get; set; }
@ -103,6 +105,8 @@ namespace osu.Game.Screens.Select.Leaderboards
{
ScoreSelected = s => ScoreSelected?.Invoke(s)
});
scoreManager.ItemRemoved += deleteLocalScore;
}
protected override void Reset()
@ -111,6 +115,16 @@ namespace osu.Game.Screens.Select.Leaderboards
TopScore = null;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (scoreManager != null)
{
scoreManager.ItemRemoved -= deleteLocalScore;
}
}
protected override bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local;
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
@ -188,9 +202,16 @@ namespace osu.Game.Screens.Select.Leaderboards
return new LeaderboardScore(model, index, IsOnlineScope)
{
Action = () => ScoreSelected?.Invoke(model),
RefreshAction = () => this.RefreshScores()
Action = () => ScoreSelected?.Invoke(model)
};
}
private void deleteLocalScore(ScoreInfo score)
{
if (score == null)
return;
Schedule(() => this.RefreshScores());
}
}
}

View File

@ -0,0 +1,59 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation;
using osu.Game.Overlays.Dialog;
using osu.Game.Scoring;
using System;
using System.Threading.Tasks;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Logging;
namespace osu.Game.Screens.Select
{
public class LocalScoreDeleteDialog : PopupDialog
{
private ScoreManager scoreManager;
public LocalScoreDeleteDialog (ScoreInfo score)
{
try{
string accuracy = string.Format(score?.Accuracy % 1 == 0 ? @"{0:P0}" : @"{0:P2}", score?.Accuracy);
BodyText = $@"{score} {Environment.NewLine} Rank: {score.Rank} - Max Combo: {score.MaxCombo} - {accuracy}";
Icon = FontAwesome.Solid.Eraser;
HeaderText = @"Clearing this local score. Are you sure?";
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"Yes. Please.",
Action = () => scoreManager.Delete(score)
},
new PopupDialogCancelButton
{
Text = @"No, I'm still attached.",
},
};
} catch (Exception e){
Logger.Error(e, "ScoreInfo cannot be null!");
HeaderText = $@"ScoreInfo cannot be null!";
Icon = FontAwesome.Solid.Ambulance;
Buttons = new PopupDialogButton[]
{
new PopupDialogCancelButton
{
Text = @"OK, thanks.",
},
};
}
}
[BackgroundDependencyLoader]
private void load(ScoreManager scoreManager)
{
this.scoreManager = scoreManager;
}
}
}