2024-06-03 20:29:15 +08:00
|
|
|
// 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;
|
2024-07-26 20:31:21 +08:00
|
|
|
using osu.Framework.Bindables;
|
2024-06-03 20:29:15 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2024-07-26 19:47:41 +08:00
|
|
|
using osu.Framework.Graphics.Cursor;
|
2024-06-03 20:29:15 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2024-06-27 16:44:28 +08:00
|
|
|
using osu.Game.Online.Metadata;
|
2024-07-26 20:31:21 +08:00
|
|
|
using osu.Game.Online.Rooms;
|
2024-06-03 20:29:15 +08:00
|
|
|
using osu.Game.Overlays;
|
2024-06-04 21:36:30 +08:00
|
|
|
using osu.Game.Screens.OnlinePlay.DailyChallenge.Events;
|
2024-06-03 20:29:15 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.OnlinePlay.DailyChallenge
|
|
|
|
{
|
|
|
|
public partial class DailyChallengeScoreBreakdown : CompositeDrawable
|
|
|
|
{
|
2024-07-26 20:31:21 +08:00
|
|
|
public Bindable<MultiplayerScore?> UserBestScore { get; } = new Bindable<MultiplayerScore?>();
|
|
|
|
|
2024-06-03 20:29:15 +08:00
|
|
|
private FillFlowContainer<Bar> barsContainer = null!;
|
|
|
|
|
2024-07-28 12:22:58 +08:00
|
|
|
// we're always present so that we can update while hidden, but we don't want tooltips to be displayed, therefore directly use alpha comparison here.
|
|
|
|
public override bool PropagatePositionalInputSubTree => base.PropagatePositionalInputSubTree && Alpha > 0;
|
|
|
|
|
2024-06-27 16:44:28 +08:00
|
|
|
private const int bin_count = MultiplayerPlaylistItemStats.TOTAL_SCORE_DISTRIBUTION_BINS;
|
2024-06-03 20:29:15 +08:00
|
|
|
private long[] bins = new long[bin_count];
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load()
|
|
|
|
{
|
|
|
|
InternalChildren = new Drawable[]
|
|
|
|
{
|
|
|
|
new SectionHeader("Score breakdown"),
|
|
|
|
barsContainer = new FillFlowContainer<Bar>
|
|
|
|
{
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Height = 0.9f,
|
|
|
|
Padding = new MarginPadding { Top = 35 },
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
for (int i = 0; i < bin_count; ++i)
|
|
|
|
{
|
2024-07-26 19:47:41 +08:00
|
|
|
barsContainer.Add(new Bar(100_000 * i, 100_000 * (i + 1) - 1)
|
2024-06-03 20:29:15 +08:00
|
|
|
{
|
|
|
|
Width = 1f / bin_count,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-26 20:31:21 +08:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2024-06-04 21:36:30 +08:00
|
|
|
public void AddNewScore(NewScoreEvent newScoreEvent)
|
2024-06-03 20:29:15 +08:00
|
|
|
{
|
2024-06-04 21:36:30 +08:00
|
|
|
int targetBin = (int)Math.Clamp(Math.Floor((float)newScoreEvent.TotalScore / 100000), 0, bin_count - 1);
|
2024-06-03 20:29:15 +08:00
|
|
|
bins[targetBin] += 1;
|
|
|
|
updateCounts();
|
|
|
|
|
|
|
|
var text = new OsuSpriteText
|
|
|
|
{
|
2024-06-04 21:36:30 +08:00
|
|
|
Text = newScoreEvent.TotalScore.ToString(@"N0"),
|
2024-06-03 20:29:15 +08:00
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Font = OsuFont.Default.With(size: 30),
|
|
|
|
RelativePositionAxes = Axes.X,
|
|
|
|
X = (targetBin + 0.5f) / bin_count - 0.5f,
|
|
|
|
Alpha = 0,
|
|
|
|
};
|
|
|
|
AddInternal(text);
|
|
|
|
|
|
|
|
Scheduler.AddDelayed(() =>
|
|
|
|
{
|
|
|
|
float startY = ToLocalSpace(barsContainer[targetBin].CircularBar.ScreenSpaceDrawQuad.TopLeft).Y;
|
|
|
|
text.FadeInFromZero()
|
|
|
|
.ScaleTo(new Vector2(0.8f), 500, Easing.OutElasticHalf)
|
|
|
|
.MoveToY(startY)
|
|
|
|
.MoveToOffset(new Vector2(0, -50), 2500, Easing.OutQuint)
|
|
|
|
.FadeOut(2500, Easing.OutQuint)
|
|
|
|
.Expire();
|
|
|
|
}, 150);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void SetInitialCounts(long[] counts)
|
|
|
|
{
|
|
|
|
if (counts.Length != bin_count)
|
|
|
|
throw new ArgumentException(@"Incorrect number of bins.", nameof(counts));
|
|
|
|
|
|
|
|
bins = counts;
|
|
|
|
updateCounts();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateCounts()
|
|
|
|
{
|
2024-06-04 21:36:30 +08:00
|
|
|
long max = Math.Max(bins.Max(), 1);
|
2024-06-03 20:29:15 +08:00
|
|
|
for (int i = 0; i < bin_count; ++i)
|
|
|
|
barsContainer[i].UpdateCounts(bins[i], max);
|
|
|
|
}
|
|
|
|
|
2024-07-26 19:47:41 +08:00
|
|
|
private partial class Bar : CompositeDrawable, IHasTooltip
|
2024-06-03 20:29:15 +08:00
|
|
|
{
|
2024-07-26 20:31:21 +08:00
|
|
|
public BindableBool ContainsLocalUser { get; } = new BindableBool();
|
|
|
|
|
|
|
|
public readonly int BinStart;
|
|
|
|
public readonly int BinEnd;
|
2024-06-03 20:29:15 +08:00
|
|
|
|
|
|
|
private long count;
|
|
|
|
private long max;
|
|
|
|
|
|
|
|
public Container CircularBar { get; private set; } = null!;
|
|
|
|
|
2024-07-26 20:31:21 +08:00
|
|
|
private Box fill = null!;
|
|
|
|
private Box flashLayer = null!;
|
|
|
|
private OsuSpriteText userIndicator = null!;
|
|
|
|
|
2024-07-26 19:47:41 +08:00
|
|
|
public Bar(int binStart, int binEnd)
|
2024-06-03 20:29:15 +08:00
|
|
|
{
|
2024-07-26 20:45:39 +08:00
|
|
|
BinStart = binStart;
|
|
|
|
BinEnd = binEnd;
|
2024-06-03 20:29:15 +08:00
|
|
|
}
|
|
|
|
|
2024-07-26 20:31:21 +08:00
|
|
|
[Resolved]
|
|
|
|
private OverlayColourProvider colourProvider { get; set; } = null!;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; } = null!;
|
|
|
|
|
2024-06-03 20:29:15 +08:00
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OverlayColourProvider colourProvider)
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
AddInternal(new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Padding = new MarginPadding
|
|
|
|
{
|
|
|
|
Bottom = 20,
|
|
|
|
Horizontal = 3,
|
|
|
|
},
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Origin = Anchor.BottomCentre,
|
2024-07-26 20:31:21 +08:00
|
|
|
Children = new Drawable[]
|
2024-06-03 20:29:15 +08:00
|
|
|
{
|
2024-07-26 20:31:21 +08:00
|
|
|
CircularBar = new Container
|
2024-06-03 20:29:15 +08:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2024-07-26 20:31:21 +08:00
|
|
|
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, },
|
2024-06-03 20:29:15 +08:00
|
|
|
}
|
2024-07-26 20:31:21 +08:00
|
|
|
},
|
2024-06-03 20:29:15 +08:00
|
|
|
});
|
|
|
|
|
2024-07-26 19:47:41 +08:00
|
|
|
string? label = null;
|
|
|
|
|
2024-07-26 20:31:21 +08:00
|
|
|
switch (BinStart)
|
2024-07-26 19:47:41 +08:00
|
|
|
{
|
|
|
|
case 200_000:
|
|
|
|
case 400_000:
|
|
|
|
case 600_000:
|
|
|
|
case 800_000:
|
2024-07-26 20:31:21 +08:00
|
|
|
label = @$"{BinStart / 1000}k";
|
2024-07-26 19:47:41 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case 1_000_000:
|
|
|
|
label = @"1M";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2024-06-03 20:29:15 +08:00
|
|
|
if (label != null)
|
|
|
|
{
|
|
|
|
AddInternal(new OsuSpriteText
|
|
|
|
{
|
|
|
|
Anchor = Anchor.BottomLeft,
|
|
|
|
Origin = Anchor.BottomCentre,
|
2024-07-26 19:47:41 +08:00
|
|
|
Text = label,
|
2024-06-03 20:29:15 +08:00
|
|
|
Colour = colourProvider.Content2,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-07-26 20:31:21 +08:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2024-06-03 20:29:15 +08:00
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
2024-06-25 14:43:52 +08:00
|
|
|
CircularBar.CornerRadius = Math.Min(CircularBar.DrawHeight / 2, CircularBar.DrawWidth / 4);
|
2024-06-03 20:29:15 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public void UpdateCounts(long newCount, long newMax)
|
|
|
|
{
|
|
|
|
bool isIncrement = newCount > count;
|
|
|
|
|
|
|
|
count = newCount;
|
|
|
|
max = newMax;
|
|
|
|
|
2024-07-26 20:31:21 +08:00
|
|
|
float height = 0.01f + 0.99f * count / max;
|
|
|
|
CircularBar.ResizeHeightTo(height, 300, Easing.OutQuint);
|
|
|
|
userIndicator.MoveToY(-height, 300, Easing.OutQuint);
|
2024-06-03 20:29:15 +08:00
|
|
|
if (isIncrement)
|
2024-07-26 20:31:21 +08:00
|
|
|
flashLayer.FadeOutFromOne(600, Easing.OutQuint);
|
2024-06-03 20:29:15 +08:00
|
|
|
}
|
2024-07-26 19:47:41 +08:00
|
|
|
|
2024-07-26 20:31:21 +08:00
|
|
|
public LocalisableString TooltipText => LocalisableString.Format("{0:N0} passes in {1:N0} - {2:N0} range", count, BinStart, BinEnd);
|
2024-06-03 20:29:15 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|