mirror of
https://github.com/ppy/osu.git
synced 2025-02-21 18:42:56 +08:00
Move all carousel rank logic into separate classes (TopLocalRank and CarouselBeatmapRank)
This commit is contained in:
parent
133a3d3e0f
commit
1c711147f3
78
osu.Game/Online/Leaderboards/TopLocalRank.cs
Normal file
78
osu.Game/Online/Leaderboards/TopLocalRank.cs
Normal file
@ -0,0 +1,78 @@
|
|||||||
|
// 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 System;
|
||||||
|
using System.Linq;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Online.API;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Scoring;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.Leaderboards
|
||||||
|
{
|
||||||
|
public class TopLocalRank : Container
|
||||||
|
{
|
||||||
|
private readonly BeatmapInfo beatmap;
|
||||||
|
|
||||||
|
private ScoreManager scores;
|
||||||
|
private IBindable<RulesetInfo> ruleset;
|
||||||
|
private IAPIProvider api;
|
||||||
|
private UpdateableRank rank;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Raised when the top score is loaded
|
||||||
|
/// </summary>
|
||||||
|
public Action<ScoreInfo> ScoreLoaded;
|
||||||
|
|
||||||
|
public TopLocalRank(BeatmapInfo beatmap)
|
||||||
|
{
|
||||||
|
this.beatmap = beatmap;
|
||||||
|
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
|
|
||||||
|
InternalChild = rank = new UpdateableRank(null)
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(ScoreManager scores, IBindable<RulesetInfo> ruleset, IAPIProvider api)
|
||||||
|
{
|
||||||
|
this.scores = scores;
|
||||||
|
this.ruleset = ruleset;
|
||||||
|
this.api = api;
|
||||||
|
|
||||||
|
FetchAndLoadTopScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void FetchAndLoadTopScore()
|
||||||
|
{
|
||||||
|
var score = fetchTopScore();
|
||||||
|
|
||||||
|
loadTopScore(score);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void loadTopScore(ScoreInfo score)
|
||||||
|
{
|
||||||
|
Schedule(() => rank.Rank = score?.Rank);
|
||||||
|
|
||||||
|
ScoreLoaded?.Invoke(score);
|
||||||
|
}
|
||||||
|
|
||||||
|
private ScoreInfo fetchTopScore()
|
||||||
|
{
|
||||||
|
if (scores == null || beatmap == null || ruleset?.Value == null || api?.LocalUser.Value == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return scores.GetAllUsableScores()
|
||||||
|
.Where(s => s.UserID == api.LocalUser.Value.Id && s.BeatmapInfoID == beatmap.ID && s.RulesetID == ruleset.Value.ID)
|
||||||
|
.OrderByDescending(s => s.TotalScore)
|
||||||
|
.FirstOrDefault();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -7,23 +7,31 @@ using osu.Game.Scoring;
|
|||||||
|
|
||||||
namespace osu.Game.Online.Leaderboards
|
namespace osu.Game.Online.Leaderboards
|
||||||
{
|
{
|
||||||
public class UpdateableRank : ModelBackedDrawable<ScoreRank>
|
public class UpdateableRank : ModelBackedDrawable<ScoreRank?>
|
||||||
{
|
{
|
||||||
public ScoreRank Rank
|
public ScoreRank? Rank
|
||||||
{
|
{
|
||||||
get => Model;
|
get => Model;
|
||||||
set => Model = value;
|
set => Model = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UpdateableRank(ScoreRank rank)
|
public UpdateableRank(ScoreRank? rank)
|
||||||
{
|
{
|
||||||
Rank = rank;
|
Rank = rank;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Drawable CreateDrawable(ScoreRank rank) => new DrawableRank(rank)
|
protected override Drawable CreateDrawable(ScoreRank? rank)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
if (rank.HasValue)
|
||||||
Origin = Anchor.Centre,
|
{
|
||||||
};
|
return new DrawableRank(rank.Value)
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
67
osu.Game/Screens/Select/Carousel/CarouselBeatmapRank.cs
Normal file
67
osu.Game/Screens/Select/Carousel/CarouselBeatmapRank.cs
Normal file
@ -0,0 +1,67 @@
|
|||||||
|
// 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.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Rulesets;
|
||||||
|
using osu.Game.Scoring;
|
||||||
|
|
||||||
|
namespace osu.Game.Online.Leaderboards
|
||||||
|
{
|
||||||
|
public class CarouselBeatmapRank : Container
|
||||||
|
{
|
||||||
|
private const int rank_size = 20;
|
||||||
|
private readonly BeatmapInfo beatmap;
|
||||||
|
|
||||||
|
private TopLocalRank rank;
|
||||||
|
|
||||||
|
public CarouselBeatmapRank(BeatmapInfo beatmap)
|
||||||
|
{
|
||||||
|
this.beatmap = beatmap;
|
||||||
|
|
||||||
|
Height = rank_size;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(ScoreManager scores, IBindable<RulesetInfo> ruleset)
|
||||||
|
{
|
||||||
|
scores.ItemAdded += scoreChanged;
|
||||||
|
scores.ItemRemoved += scoreChanged;
|
||||||
|
ruleset.ValueChanged += _ => rulesetChanged();
|
||||||
|
|
||||||
|
rank = new TopLocalRank(beatmap)
|
||||||
|
{
|
||||||
|
ScoreLoaded = scaleDisplay
|
||||||
|
};
|
||||||
|
|
||||||
|
InternalChild = new DelayedLoadWrapper(rank)
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private void rulesetChanged()
|
||||||
|
{
|
||||||
|
rank.FetchAndLoadTopScore();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scoreChanged(ScoreInfo score)
|
||||||
|
{
|
||||||
|
if (score.BeatmapInfoID == beatmap.ID)
|
||||||
|
{
|
||||||
|
rank.FetchAndLoadTopScore();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void scaleDisplay(ScoreInfo score)
|
||||||
|
{
|
||||||
|
if (score != null)
|
||||||
|
Width = rank_size * 2;
|
||||||
|
else
|
||||||
|
Width = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -19,6 +19,7 @@ using osu.Game.Graphics;
|
|||||||
using osu.Game.Graphics.Backgrounds;
|
using osu.Game.Graphics.Backgrounds;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osu.Game.Online.Leaderboards;
|
||||||
using osu.Game.Overlays;
|
using osu.Game.Overlays;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
@ -122,10 +123,23 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
},
|
},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
starCounter = new StarCounter
|
new FillFlowContainer
|
||||||
{
|
{
|
||||||
Current = (float)beatmap.StarDifficulty,
|
Direction = FillDirection.Horizontal,
|
||||||
Scale = new Vector2(0.8f),
|
Spacing = new Vector2(4, 0),
|
||||||
|
AutoSizeAxes = Axes.Both,
|
||||||
|
Children = new Drawable[]
|
||||||
|
{
|
||||||
|
new CarouselBeatmapRank(beatmap)
|
||||||
|
{
|
||||||
|
Scale = new Vector2(0.8f)
|
||||||
|
},
|
||||||
|
starCounter = new StarCounter
|
||||||
|
{
|
||||||
|
Current = (float)beatmap.StarDifficulty,
|
||||||
|
Scale = new Vector2(0.8f),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user