Skip to content

Commit

Permalink
Merge pull request #29108 from bdach/daily-challenge/better-breakdown
Browse files Browse the repository at this point in the history
Improve score breakdown on daily challenge
  • Loading branch information
peppy committed Jul 26, 2024
2 parents 47eca0e + 0996f9b commit 4fa6a19
Show file tree
Hide file tree
Showing 4 changed files with 112 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Screens.OnlinePlay.DailyChallenge;
using osu.Game.Screens.OnlinePlay.DailyChallenge.Events;
Expand Down Expand Up @@ -61,6 +62,8 @@ public void TestBasicAppearance()
breakdown.AddNewScore(ev);
});
AddStep("set user score", () => breakdown.UserBestScore.Value = new MultiplayerScore { TotalScore = RNG.Next(1_000_000) });
AddStep("unset user score", () => breakdown.UserBestScore.Value = null);
}
}
}
2 changes: 2 additions & 0 deletions osu.Game/Screens/OnlinePlay/DailyChallenge/DailyChallenge.cs
Original file line number Diff line number Diff line change
Expand Up @@ -333,6 +333,8 @@ [new MatchChatDisplay(room) { RelativeSizeAxes = Axes.Both }]
}

metadataClient.MultiplayerRoomScoreSet += onRoomScoreSet;

((IBindable<MultiplayerScore?>)breakdown.UserBestScore).BindTo(leaderboard.UserBestScore);
}

private void presentScore(long id)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
{
public partial class DailyChallengeLeaderboard : CompositeDrawable
{
public IBindable<MultiplayerScore?> UserBestScore => userBestScore;
private readonly Bindable<MultiplayerScore?> userBestScore = new Bindable<MultiplayerScore?>();

public Action<long>? PresentScore { get; init; }

private readonly Room room;
Expand Down Expand Up @@ -130,7 +133,9 @@ public void RefetchScores()
request.Success += req => Schedule(() =>
{
var best = req.Scores.Select(s => s.CreateScoreInfo(scoreManager, rulesets, playlistItem, beatmap.Value.BeatmapInfo)).ToArray();
var userBest = req.UserScore?.CreateScoreInfo(scoreManager, rulesets, playlistItem, beatmap.Value.BeatmapInfo);
userBestScore.Value = req.UserScore;
var userBest = userBestScore.Value?.CreateScoreInfo(scoreManager, rulesets, playlistItem, beatmap.Value.BeatmapInfo);
cancellationTokenSource?.Cancel();
cancellationTokenSource = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,17 @@
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online.Metadata;
using osu.Game.Online.Rooms;
using osu.Game.Overlays;
using osu.Game.Screens.OnlinePlay.DailyChallenge.Events;
using osuTK;
Expand All @@ -20,6 +23,8 @@ namespace osu.Game.Screens.OnlinePlay.DailyChallenge
{
public partial class DailyChallengeScoreBreakdown : CompositeDrawable
{
public Bindable<MultiplayerScore?> UserBestScore { get; } = new Bindable<MultiplayerScore?>();

private FillFlowContainer<Bar> barsContainer = null!;

private const int bin_count = MultiplayerPlaylistItemStats.TOTAL_SCORE_DISTRIBUTION_BINS;
Expand All @@ -44,29 +49,24 @@ private void load()

for (int i = 0; i < bin_count; ++i)
{
LocalisableString? label = null;

switch (i)
{
case 2:
case 4:
case 6:
case 8:
label = @$"{100 * i}k";
break;

case 10:
label = @"1M";
break;
}

barsContainer.Add(new Bar(label)
barsContainer.Add(new Bar(100_000 * i, 100_000 * (i + 1) - 1)
{
Width = 1f / bin_count,
});
}
}

protected override void LoadComplete()
{
base.LoadComplete();

UserBestScore.BindValueChanged(_ =>
{
foreach (var bar in barsContainer)
bar.ContainsLocalUser.Value = UserBestScore.Value is not null && bar.BinStart <= UserBestScore.Value.TotalScore && UserBestScore.Value.TotalScore <= bar.BinEnd;
});
}

public void AddNewScore(NewScoreEvent newScoreEvent)
{
int targetBin = (int)Math.Clamp(Math.Floor((float)newScoreEvent.TotalScore / 100000), 0, bin_count - 1);
Expand Down Expand Up @@ -113,20 +113,34 @@ private void updateCounts()
barsContainer[i].UpdateCounts(bins[i], max);
}

private partial class Bar : CompositeDrawable
private partial class Bar : CompositeDrawable, IHasTooltip
{
private readonly LocalisableString? label;
public BindableBool ContainsLocalUser { get; } = new BindableBool();

public readonly int BinStart;
public readonly int BinEnd;

private long count;
private long max;

public Container CircularBar { get; private set; } = null!;

public Bar(LocalisableString? label = null)
private Box fill = null!;
private Box flashLayer = null!;
private OsuSpriteText userIndicator = null!;

public Bar(int binStart, int binEnd)
{
this.label = label;
BinStart = binStart;
BinEnd = binEnd;
}

[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;

[Resolved]
private OsuColour colours { get; set; } = null!;

[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
Expand All @@ -142,35 +156,83 @@ private void load(OverlayColourProvider colourProvider)
},
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Masking = true,
Child = CircularBar = new Container
Children = new Drawable[]
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Height = 0.01f,
Masking = true,
CornerRadius = 10,
Colour = colourProvider.Highlight1,
Child = new Box
CircularBar = new Container
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Height = 0.01f,
Masking = true,
CornerRadius = 10,
Children = new Drawable[]
{
fill = new Box
{
RelativeSizeAxes = Axes.Both,
},
flashLayer = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
},
}
},
userIndicator = new OsuSpriteText
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Colour = colours.Orange1,
Text = "You",
Font = OsuFont.Default.With(weight: FontWeight.Bold),
Alpha = 0,
RelativePositionAxes = Axes.Y,
Margin = new MarginPadding { Bottom = 5, },
}
}
},
});

string? label = null;

switch (BinStart)
{
case 200_000:
case 400_000:
case 600_000:
case 800_000:
label = @$"{BinStart / 1000}k";
break;

case 1_000_000:
label = @"1M";
break;
}

if (label != null)
{
AddInternal(new OsuSpriteText
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomCentre,
Text = label.Value,
Text = label,
Colour = colourProvider.Content2,
});
}
}

protected override void LoadComplete()
{
base.LoadComplete();

ContainsLocalUser.BindValueChanged(_ =>
{
fill.FadeColour(ContainsLocalUser.Value ? colours.Orange1 : colourProvider.Highlight1, 300, Easing.OutQuint);
userIndicator.FadeTo(ContainsLocalUser.Value ? 1 : 0, 300, Easing.OutQuint);
}, true);
FinishTransforms(true);
}

protected override void Update()
{
base.Update();
Expand All @@ -185,10 +247,14 @@ public void UpdateCounts(long newCount, long newMax)
count = newCount;
max = newMax;

CircularBar.ResizeHeightTo(0.01f + 0.99f * count / max, 300, Easing.OutQuint);
float height = 0.01f + 0.99f * count / max;
CircularBar.ResizeHeightTo(height, 300, Easing.OutQuint);
userIndicator.MoveToY(-height, 300, Easing.OutQuint);
if (isIncrement)
CircularBar.FlashColour(Colour4.White, 600, Easing.OutQuint);
flashLayer.FadeOutFromOne(600, Easing.OutQuint);
}

public LocalisableString TooltipText => LocalisableString.Format("{0:N0} passes in {1:N0} - {2:N0} range", count, BinStart, BinEnd);
}
}
}

0 comments on commit 4fa6a19

Please sign in to comment.