1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-16 18:32:59 +08:00

Add OnScoreChange event

For use in scrolling system on a later PR
This commit is contained in:
iiSaLMaN 2019-07-30 12:32:12 +03:00
parent 6233dc22e0
commit 4874746525

View File

@ -18,6 +18,12 @@ namespace osu.Game.Screens.Play
{ {
public class InGameScoreContainer : FillFlowContainer<InGameScoreItem> public class InGameScoreContainer : FillFlowContainer<InGameScoreItem>
{ {
/// <summary>
/// Called once an item's score has changed.
/// Useful for doing calculations on what score to show or hide next. (scrolling system)
/// </summary>
public event Action OnScoreChange;
/// <summary> /// <summary>
/// Whether to declare a new position for un-positioned players. /// Whether to declare a new position for un-positioned players.
/// Must be disabled for online leaderboards with top 50 scores only. /// Must be disabled for online leaderboards with top 50 scores only.
@ -64,12 +70,12 @@ namespace osu.Game.Screens.Play
Add(scoreItem); Add(scoreItem);
SetLayoutPosition(scoreItem, position ?? maxPosition + 1); SetLayoutPosition(scoreItem, position ?? maxPosition + 1);
updateScores(); reorderPositions();
return scoreItem; return scoreItem;
} }
private void updateScores() private void reorderPositions()
{ {
var orderedByScore = this.OrderByDescending(i => i.TotalScore).ToList(); var orderedByScore = this.OrderByDescending(i => i.TotalScore).ToList();
var orderedPositions = this.OrderByDescending(i => i.ScorePosition.HasValue).ThenBy(i => i.ScorePosition).Select(i => i.ScorePosition).ToList(); var orderedPositions = this.OrderByDescending(i => i.ScorePosition.HasValue).ThenBy(i => i.ScorePosition).Select(i => i.ScorePosition).ToList();
@ -82,6 +88,13 @@ namespace osu.Game.Screens.Play
orderedByScore[i].ScorePosition = DeclareNewPosition ? newPosition : orderedPositions[i]; orderedByScore[i].ScorePosition = DeclareNewPosition ? newPosition : orderedPositions[i];
} }
} }
private void updateScores()
{
reorderPositions();
OnScoreChange?.Invoke();
}
} }
public class InGameScoreItem : CompositeDrawable public class InGameScoreItem : CompositeDrawable