Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve daily challenge event feed #29055

Merged
merged 4 commits into from
Jul 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using osu.Framework.Extensions.ObjectExtensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Testing;
using osu.Framework.Utils;
using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays;
Expand All @@ -17,14 +18,14 @@ namespace osu.Game.Tests.Visual.DailyChallenge
{
public partial class TestSceneDailyChallengeEventFeed : OsuTestScene
{
private DailyChallengeEventFeed feed = null!;

[Cached]
private OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Plum);

[Test]
public void TestBasicAppearance()
[SetUpSteps]
public void SetUpSteps()
{
DailyChallengeEventFeed feed = null!;

AddStep("create content", () => Children = new Drawable[]
{
new Box
Expand All @@ -35,22 +36,28 @@ public void TestBasicAppearance()
feed = new DailyChallengeEventFeed
{
RelativeSizeAxes = Axes.Both,
Height = 0.3f,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
});

AddSliderStep("adjust width", 0.1f, 1, 1, width =>
{
if (feed.IsNotNull())
feed.Width = width;
});
AddSliderStep("adjust height", 0.1f, 1, 1, height =>
AddSliderStep("adjust height", 0.1f, 1, 0.3f, height =>
{
if (feed.IsNotNull())
feed.Height = height;
});
}

AddStep("add normal score", () =>
[Test]
public void TestBasicAppearance()
{
AddRepeatStep("add normal score", () =>
{
var ev = new NewScoreEvent(1, new APIUser
{
Expand All @@ -60,9 +67,9 @@ public void TestBasicAppearance()
}, RNG.Next(1_000_000), null);

feed.AddNewScore(ev);
});
}, 50);

AddStep("add new user best", () =>
AddRepeatStep("add new user best", () =>
{
var ev = new NewScoreEvent(1, new APIUser
{
Expand All @@ -75,9 +82,9 @@ public void TestBasicAppearance()
testScore.TotalScore = RNG.Next(1_000_000);

feed.AddNewScore(ev);
});
}, 50);

AddStep("add top 10 score", () =>
AddRepeatStep("add top 10 score", () =>
{
var ev = new NewScoreEvent(1, new APIUser
{
Expand All @@ -87,6 +94,25 @@ public void TestBasicAppearance()
}, RNG.Next(1_000_000), RNG.Next(1, 10));

feed.AddNewScore(ev);
}, 50);
}

[Test]
public void TestMassAdd()
{
AddStep("add 1000 scores at once", () =>
{
for (int i = 0; i < 1000; i++)
{
var ev = new NewScoreEvent(1, new APIUser
{
Id = 2,
Username = "peppy",
CoverUrl = "https://osu.ppy.sh/images/headers/profile-covers/c3.jpg",
}, RNG.Next(1_000_000), null);

feed.AddNewScore(ev);
}
});
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Utils;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
Expand All @@ -22,6 +23,8 @@ public partial class DailyChallengeEventFeed : CompositeDrawable

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

private readonly Queue<NewScoreEvent> newScores = new Queue<NewScoreEvent>();

[BackgroundDependencyLoader]
private void load()
{
Expand All @@ -47,24 +50,33 @@ private void load()

public void AddNewScore(NewScoreEvent newScoreEvent)
{
var row = new NewScoreEventRow(newScoreEvent)
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
PresentScore = PresentScore,
};
flow.Add(row);
row.Delay(15000).Then().FadeOut(300, Easing.OutQuint).Expire();
newScores.Enqueue(newScoreEvent);

// ensure things don't get too out-of-hand.
if (newScores.Count > 25)
newScores.Dequeue();
}

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

while (newScores.TryDequeue(out var newScore))
{
flow.Add(new NewScoreEventRow(newScore)
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
PresentScore = PresentScore,
});
}

for (int i = 0; i < flow.Count; ++i)
{
var row = flow[i];

row.Alpha = Interpolation.ValueAt(Math.Clamp(row.Y + flow.DrawHeight, 0, flow.DrawHeight), 0f, 1f, 0, flow.DrawHeight, Easing.Out);

if (row.Y < -flow.DrawHeight)
{
row.RemoveAndDisposeImmediately();
Expand Down
Loading