mirror of
https://github.com/ppy/osu.git
synced 2024-12-15 01:52:55 +08:00
Update Scoreboard Refresh Method for deleting individual scores
This commit is contained in:
parent
d1fcadc700
commit
531ac16743
@ -58,8 +58,6 @@ namespace osu.Game.Online.Leaderboards
|
|||||||
|
|
||||||
private DialogOverlay dialogOverlay;
|
private DialogOverlay dialogOverlay;
|
||||||
|
|
||||||
public Action RefreshAction { get; set; }
|
|
||||||
|
|
||||||
public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true)
|
public LeaderboardScore(ScoreInfo score, int rank, bool allowHighlight = true)
|
||||||
{
|
{
|
||||||
this.score = score;
|
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
|
public MenuItem[] ContextMenuItems
|
||||||
{
|
{
|
||||||
get
|
get
|
||||||
{
|
{
|
||||||
return (this.allowHighlight) ? null : new MenuItem[]
|
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))
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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]
|
[BackgroundDependencyLoader]
|
||||||
private void load(ScoreManager scoreManager)
|
private void load(ScoreManager scoreManager)
|
||||||
{
|
{
|
||||||
|
@ -19,8 +19,10 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
{
|
{
|
||||||
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>
|
public class BeatmapLeaderboard : Leaderboard<BeatmapLeaderboardScope, ScoreInfo>
|
||||||
{
|
{
|
||||||
|
|
||||||
public Action<ScoreInfo> ScoreSelected;
|
public Action<ScoreInfo> ScoreSelected;
|
||||||
|
|
||||||
|
|
||||||
[Resolved]
|
[Resolved]
|
||||||
private RulesetStore rulesets { get; set; }
|
private RulesetStore rulesets { get; set; }
|
||||||
|
|
||||||
@ -103,6 +105,8 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
{
|
{
|
||||||
ScoreSelected = s => ScoreSelected?.Invoke(s)
|
ScoreSelected = s => ScoreSelected?.Invoke(s)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
scoreManager.ItemRemoved += deleteLocalScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Reset()
|
protected override void Reset()
|
||||||
@ -111,6 +115,16 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
TopScore = null;
|
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 bool IsOnlineScope => Scope != BeatmapLeaderboardScope.Local;
|
||||||
|
|
||||||
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
|
protected override APIRequest FetchScores(Action<IEnumerable<ScoreInfo>> scoresCallback)
|
||||||
@ -188,9 +202,16 @@ namespace osu.Game.Screens.Select.Leaderboards
|
|||||||
|
|
||||||
return new LeaderboardScore(model, index, IsOnlineScope)
|
return new LeaderboardScore(model, index, IsOnlineScope)
|
||||||
{
|
{
|
||||||
Action = () => ScoreSelected?.Invoke(model),
|
Action = () => ScoreSelected?.Invoke(model)
|
||||||
RefreshAction = () => this.RefreshScores()
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deleteLocalScore(ScoreInfo score)
|
||||||
|
{
|
||||||
|
if (score == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
Schedule(() => this.RefreshScores());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
59
osu.Game/Screens/Select/LocalScoreDeleteDialog.cs
Normal file
59
osu.Game/Screens/Select/LocalScoreDeleteDialog.cs
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user