mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Merge branch 'master' into select-recommended
This commit is contained in:
@ -282,46 +282,37 @@ namespace osu.Game.Screens.Select
|
||||
/// <param name="skipDifficulties">Whether to skip individual difficulties and only increment over full groups.</param>
|
||||
public void SelectNext(int direction = 1, bool skipDifficulties = true)
|
||||
{
|
||||
var visibleItems = Items.Where(s => !s.Item.Filtered.Value).ToList();
|
||||
|
||||
if (!visibleItems.Any())
|
||||
if (beatmapSets.All(s => s.Filtered.Value))
|
||||
return;
|
||||
|
||||
DrawableCarouselItem drawable = null;
|
||||
if (skipDifficulties)
|
||||
selectNextSet(direction, true);
|
||||
else
|
||||
selectNextDifficulty(direction);
|
||||
}
|
||||
|
||||
if (selectedBeatmap != null && (drawable = selectedBeatmap.Drawables.FirstOrDefault()) == null)
|
||||
// if the selected beatmap isn't present yet, we can't correctly change selection.
|
||||
// we can fix this by changing this method to not reference drawables / Items in the first place.
|
||||
return;
|
||||
private void selectNextSet(int direction, bool skipDifficulties)
|
||||
{
|
||||
var unfilteredSets = beatmapSets.Where(s => !s.Filtered.Value).ToList();
|
||||
|
||||
int originalIndex = visibleItems.IndexOf(drawable);
|
||||
int currentIndex = originalIndex;
|
||||
var nextSet = unfilteredSets[(unfilteredSets.IndexOf(selectedBeatmapSet) + direction + unfilteredSets.Count) % unfilteredSets.Count];
|
||||
|
||||
// local function to increment the index in the required direction, wrapping over extremities.
|
||||
int incrementIndex() => currentIndex = (currentIndex + direction + visibleItems.Count) % visibleItems.Count;
|
||||
if (skipDifficulties)
|
||||
select(nextSet);
|
||||
else
|
||||
select(direction > 0 ? nextSet.Beatmaps.First(b => !b.Filtered.Value) : nextSet.Beatmaps.Last(b => !b.Filtered.Value));
|
||||
}
|
||||
|
||||
while (incrementIndex() != originalIndex)
|
||||
{
|
||||
var item = visibleItems[currentIndex].Item;
|
||||
private void selectNextDifficulty(int direction)
|
||||
{
|
||||
var unfilteredDifficulties = selectedBeatmapSet.Children.Where(s => !s.Filtered.Value).ToList();
|
||||
|
||||
if (item.Filtered.Value || item.State.Value == CarouselItemState.Selected) continue;
|
||||
int index = unfilteredDifficulties.IndexOf(selectedBeatmap);
|
||||
|
||||
switch (item)
|
||||
{
|
||||
case CarouselBeatmap beatmap:
|
||||
if (skipDifficulties) continue;
|
||||
|
||||
select(beatmap);
|
||||
return;
|
||||
|
||||
case CarouselBeatmapSet set:
|
||||
if (skipDifficulties)
|
||||
select(set);
|
||||
else
|
||||
select(direction > 0 ? set.Beatmaps.First(b => !b.Filtered.Value) : set.Beatmaps.Last(b => !b.Filtered.Value));
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (index + direction < 0 || index + direction >= unfilteredDifficulties.Count)
|
||||
selectNextSet(direction, false);
|
||||
else
|
||||
select(unfilteredDifficulties[index + direction]);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -122,10 +122,24 @@ namespace osu.Game.Screens.Select.Carousel
|
||||
},
|
||||
}
|
||||
},
|
||||
starCounter = new StarCounter
|
||||
new FillFlowContainer
|
||||
{
|
||||
Current = (float)beatmap.StarDifficulty,
|
||||
Scale = new Vector2(0.8f),
|
||||
Direction = FillDirection.Horizontal,
|
||||
Spacing = new Vector2(4, 0),
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Children = new Drawable[]
|
||||
{
|
||||
new TopLocalRank(beatmap)
|
||||
{
|
||||
Scale = new Vector2(0.8f),
|
||||
Size = new Vector2(40, 20)
|
||||
},
|
||||
starCounter = new StarCounter
|
||||
{
|
||||
Current = (float)beatmap.StarDifficulty,
|
||||
Scale = new Vector2(0.8f),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
90
osu.Game/Screens/Select/Carousel/TopLocalRank.cs
Normal file
90
osu.Game/Screens/Select/Carousel/TopLocalRank.cs
Normal file
@ -0,0 +1,90 @@
|
||||
// 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.Linq;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Online.API;
|
||||
using osu.Game.Online.Leaderboards;
|
||||
using osu.Game.Rulesets;
|
||||
using osu.Game.Scoring;
|
||||
|
||||
namespace osu.Game.Screens.Select.Carousel
|
||||
{
|
||||
public class TopLocalRank : UpdateableRank
|
||||
{
|
||||
private readonly BeatmapInfo beatmap;
|
||||
|
||||
[Resolved]
|
||||
private ScoreManager scores { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private IBindable<RulesetInfo> ruleset { get; set; }
|
||||
|
||||
[Resolved]
|
||||
private IAPIProvider api { get; set; }
|
||||
|
||||
public TopLocalRank(BeatmapInfo beatmap)
|
||||
: base(null)
|
||||
{
|
||||
this.beatmap = beatmap;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
scores.ItemAdded += scoreChanged;
|
||||
scores.ItemRemoved += scoreChanged;
|
||||
ruleset.ValueChanged += _ => fetchAndLoadTopScore();
|
||||
|
||||
fetchAndLoadTopScore();
|
||||
}
|
||||
|
||||
private void scoreChanged(ScoreInfo score)
|
||||
{
|
||||
if (score.BeatmapInfoID == beatmap.ID)
|
||||
fetchAndLoadTopScore();
|
||||
}
|
||||
|
||||
private ScheduledDelegate scheduledRankUpdate;
|
||||
|
||||
private void fetchAndLoadTopScore()
|
||||
{
|
||||
var rank = fetchTopScore()?.Rank;
|
||||
scheduledRankUpdate = Schedule(() =>
|
||||
{
|
||||
Rank = rank;
|
||||
|
||||
// Required since presence is changed via IsPresent override
|
||||
Invalidate(Invalidation.Presence);
|
||||
});
|
||||
}
|
||||
|
||||
// We're present if a rank is set, or if there is a pending rank update (IsPresent = true is required for the scheduler to run).
|
||||
public override bool IsPresent => base.IsPresent && (Rank != null || scheduledRankUpdate?.Completed == false);
|
||||
|
||||
private ScoreInfo fetchTopScore()
|
||||
{
|
||||
if (scores == null || beatmap == null || ruleset?.Value == null || api?.LocalUser.Value == null)
|
||||
return null;
|
||||
|
||||
return scores.QueryScores(s => s.UserID == api.LocalUser.Value.Id && s.BeatmapInfoID == beatmap.ID && s.RulesetID == ruleset.Value.ID && !s.DeletePending)
|
||||
.OrderByDescending(s => s.TotalScore)
|
||||
.FirstOrDefault();
|
||||
}
|
||||
|
||||
protected override void Dispose(bool isDisposing)
|
||||
{
|
||||
base.Dispose(isDisposing);
|
||||
|
||||
if (scores != null)
|
||||
{
|
||||
scores.ItemAdded -= scoreChanged;
|
||||
scores.ItemRemoved -= scoreChanged;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -27,18 +27,19 @@ namespace osu.Game.Screens.Select
|
||||
}
|
||||
|
||||
protected readonly OsuSpriteText MultiplierText;
|
||||
private readonly FooterModDisplay modDisplay;
|
||||
private readonly ModDisplay modDisplay;
|
||||
private Color4 lowMultiplierColour;
|
||||
private Color4 highMultiplierColour;
|
||||
|
||||
public FooterButtonMods()
|
||||
{
|
||||
ButtonContentContainer.Add(modDisplay = new FooterModDisplay
|
||||
ButtonContentContainer.Add(modDisplay = new ModDisplay
|
||||
{
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
DisplayUnrankedText = false,
|
||||
Scale = new Vector2(0.8f)
|
||||
Scale = new Vector2(0.8f),
|
||||
ExpansionMode = ExpansionMode.AlwaysContracted,
|
||||
});
|
||||
ButtonContentContainer.Add(MultiplierText = new OsuSpriteText
|
||||
{
|
||||
@ -84,16 +85,5 @@ namespace osu.Game.Screens.Select
|
||||
else
|
||||
modDisplay.FadeOut();
|
||||
}
|
||||
|
||||
private class FooterModDisplay : ModDisplay
|
||||
{
|
||||
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => Parent?.Parent?.ReceivePositionalInputAt(screenSpacePos) ?? false;
|
||||
|
||||
public FooterModDisplay()
|
||||
{
|
||||
ExpansionMode = ExpansionMode.AlwaysContracted;
|
||||
IconsContainer.Margin = new MarginPadding();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user