Skip to content

Commit

Permalink
Update button text to include downloaded beatmaps and collection status
Browse files Browse the repository at this point in the history
  • Loading branch information
Layendan committed Feb 10, 2025
1 parent d4c69f0 commit f9bda05
Showing 1 changed file with 34 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Beatmaps;
using osu.Game.Collections;
using osu.Game.Database;
Expand All @@ -17,6 +20,10 @@ namespace osu.Game.Screens.OnlinePlay.Playlists
public partial class AddPlaylistToCollectionButton : RoundedButton
{
private readonly Room room;
private readonly Bindable<int> downloadedBeatmapsCount = new Bindable<int>(0);
private readonly Bindable<bool> collectionExists = new Bindable<bool>(false);
private IDisposable? beatmapSubscription;
private IDisposable? collectionSubscription;

[Resolved]
private RealmAccess realmAccess { get; set; } = null!;
Expand All @@ -27,7 +34,7 @@ public partial class AddPlaylistToCollectionButton : RoundedButton
public AddPlaylistToCollectionButton(Room room)
{
this.room = room;
Text = "Add Maps to Collection";
Text = formatButtonText(downloadedBeatmapsCount.Value, collectionExists.Value);
}

[BackgroundDependencyLoader]
Expand All @@ -41,8 +48,7 @@ private void load()
return;
}

string filter = string.Join(" OR ", room.Playlist.Select(item => $"(OnlineID == {item.Beatmap.OnlineID})").Distinct());
var beatmaps = realmAccess.Realm.All<BeatmapInfo>().Filter(filter).ToList();
var beatmaps = realmAccess.Realm.All<BeatmapInfo>().Filter(formatFilterQuery(room.Playlist)).ToList();

var collection = realmAccess.Realm.All<BeatmapCollection>().FirstOrDefault(c => c.Name == room.Name);

Expand All @@ -64,5 +70,30 @@ private void load()
}
};
}

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

beatmapSubscription = realmAccess.RegisterForNotifications(r => r.All<BeatmapInfo>().Filter(formatFilterQuery(room.Playlist)), (sender, _) => downloadedBeatmapsCount.Value = sender.Count);

Check failure on line 78 in osu.Game/Screens/OnlinePlay/Playlists/AddPlaylistToCollectionButton.cs

View workflow job for this annotation

GitHub Actions / Results

osu.Game.Tests.Visual.Playlists.TestScenePlaylistsLoungeSubScreen ► TestEnteringRoomTakesLeaseOnSelection

Failed test found in: TestResults-Linux-MultiThreaded.trx Error: System.AggregateException : One or more errors occurred. (Invalid predicate: '': syntax error, unexpected end of file) ----> System.ArgumentException : Invalid predicate: '': syntax error, unexpected end of file
Raw output
System.AggregateException : One or more errors occurred. (Invalid predicate: '': syntax error, unexpected end of file)
  ----> System.ArgumentException : Invalid predicate: '': syntax error, unexpected end of file
   at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at osu.Framework.Extensions.TaskExtensions.WaitSafely(Task task)
   at osu.Framework.Testing.TestScene.UseTestSceneRunnerAttribute.AfterTest(ITest test)
   at NUnit.Framework.Internal.Commands.TestActionCommand.<>c__DisplayClass0_0.<.ctor>b__1(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__1()
   at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
--ArgumentException
   at Realms.CollectionHandleBase.GetFilteredResults(String query, QueryArgument[] arguments)
   at Realms.RealmCollectionBase`1.GetFilteredResults(String query, QueryArgument[] arguments)
   at osu.Game.Screens.OnlinePlay.Playlists.AddPlaylistToCollectionButton.<LoadComplete>b__15_0(Realm r) in /home/runner/work/osu/osu/osu.Game/Screens/OnlinePlay/Playlists/AddPlaylistToCollectionButton.cs:line 78
   at osu.Game.Database.RealmAccess.<>c__DisplayClass36_0`1.<RegisterForNotifications>b__0(Realm realm) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 555
   at osu.Game.Database.RealmAccess.registerSubscription(Func`2 action) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 682
   at osu.Game.Database.RealmAccess.<>c__DisplayClass38_0.<RegisterCustomSubscription>b__0(Object _) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 639
   at osu.Framework.Threading.ScheduledDelegate.RunTaskInternal()
   at osu.Framework.Threading.Scheduler.Update()
   at osu.Framework.Threading.GameThreadSynchronizationContext.Send(SendOrPostCallback callback, Object state)
   at osu.Game.Database.RealmAccess.RegisterCustomSubscription(Func`2 action) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 639
   at osu.Game.Database.RealmAccess.RegisterForNotifications[T](Func`2 query, NotificationCallbackDelegate`1 callback) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 563
   at osu.Game.Screens.OnlinePlay.Playlists.AddPlaylistToCollectionButton.LoadComplete() in /home/runner/work/osu/osu/osu.Game/Screens/OnlinePlay/Playlists/AddPlaylistToCollectionButton.cs:line 78
   at osu.Framework.Graphics.Drawable.loadComplete()
   at osu.Framework.Graphics.Drawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Platform.GameHost.UpdateFrame()
   at osu.Framework.Threading.GameThread.processFrame()
--- End of stack trace from previous location ---
   at osu.Framework.Platform.GameHost.<>c__DisplayClass143_0.<abortExecutionFromException>b__0()
   at osu.Framework.Threading.ScheduledDelegate.RunTaskInternal()
   at osu.Framework.Threading.Scheduler.Update()
   at osu.Framework.Threading.GameThread.processFrame()
   at osu.Framework.Platform.ThreadRunner.RunMainLoop()
   at osu.Framework.Platform.GameHost.windowUpdate()
   at osu.Framework.Platform.GameHost.Run(Game game)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

Check failure on line 78 in osu.Game/Screens/OnlinePlay/Playlists/AddPlaylistToCollectionButton.cs

View workflow job for this annotation

GitHub Actions / Results

osu.Game.Tests.Visual.Playlists.TestScenePlaylistsLoungeSubScreen ► TestEnteringRoomTakesLeaseOnSelection

Failed test found in: TestResults-Linux-MultiThreaded.trx TestResults-Linux-MultiThreaded.trx TestResults-Linux-MultiThreaded.trx TestResults-Linux-MultiThreaded.trx TestResults-Linux-MultiThreaded.trx TestResults-Linux-MultiThreaded.trx TestResults-Linux-MultiThreaded.trx Error: System.AggregateException : One or more errors occurred. (Invalid predicate: '': syntax error, unexpected end of file) ----> System.ArgumentException : Invalid predicate: '': syntax error, unexpected end of file
Raw output
System.AggregateException : One or more errors occurred. (Invalid predicate: '': syntax error, unexpected end of file)
  ----> System.ArgumentException : Invalid predicate: '': syntax error, unexpected end of file
   at osu.Framework.Testing.TestScene.UseTestSceneRunnerAttribute.AfterTest(ITest test)
   at NUnit.Framework.Internal.Commands.TestActionCommand.<>c__DisplayClass0_0.<.ctor>b__1(TestExecutionContext context)
   at NUnit.Framework.Internal.Commands.BeforeAndAfterTestCommand.<>c__DisplayClass1_0.<Execute>b__1()
   at NUnit.Framework.Internal.Commands.DelegatingTestCommand.RunTestMethodInThreadAbortSafeZone(TestExecutionContext context, Action action)
--ArgumentException
   at Realms.CollectionHandleBase.GetFilteredResults(String query, QueryArgument[] arguments)
   at Realms.RealmCollectionBase`1.GetFilteredResults(String query, QueryArgument[] arguments)
   at osu.Game.Screens.OnlinePlay.Playlists.AddPlaylistToCollectionButton.<LoadComplete>b__15_0(Realm r) in /home/runner/work/osu/osu/osu.Game/Screens/OnlinePlay/Playlists/AddPlaylistToCollectionButton.cs:line 78
   at osu.Game.Database.RealmAccess.<>c__DisplayClass36_0`1.<RegisterForNotifications>b__0(Realm realm) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 555
   at osu.Game.Database.RealmAccess.registerSubscription(Func`2 action) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 682
   at osu.Game.Database.RealmAccess.<>c__DisplayClass38_0.<RegisterCustomSubscription>b__0(Object _) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 639
   at osu.Framework.Threading.ScheduledDelegate.RunTaskInternal()
   at osu.Framework.Threading.Scheduler.Update()
   at osu.Framework.Threading.GameThreadSynchronizationContext.Send(SendOrPostCallback callback, Object state)
   at osu.Game.Database.RealmAccess.RegisterCustomSubscription(Func`2 action) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 639
   at osu.Game.Database.RealmAccess.RegisterForNotifications[T](Func`2 query, NotificationCallbackDelegate`1 callback) in /home/runner/work/osu/osu/osu.Game/Database/RealmAccess.cs:line 563
   at osu.Game.Screens.OnlinePlay.Playlists.AddPlaylistToCollectionButton.LoadComplete() in /home/runner/work/osu/osu/osu.Game/Screens/OnlinePlay/Playlists/AddPlaylistToCollectionButton.cs:line 78
   at osu.Framework.Graphics.Drawable.loadComplete()
   at osu.Framework.Graphics.Drawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Graphics.Containers.CompositeDrawable.UpdateSubTree()
   at osu.Framework.Platform.GameHost.UpdateFrame()
   at osu.Framework.Threading.GameThread.processFrame()
--- End of stack trace from previous location ---
   at osu.Framework.Platform.GameHost.<>c__DisplayClass143_0.<abortExecutionFromException>b__0()
   at osu.Framework.Threading.ScheduledDelegate.RunTaskInternal()
   at osu.Framework.Threading.Scheduler.Update()
   at osu.Framework.Threading.GameThread.processFrame()
   at osu.Framework.Platform.ThreadRunner.RunMainLoop()
   at osu.Framework.Platform.GameHost.windowUpdate()
   at osu.Framework.Platform.GameHost.Run(Game game)
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
--- End of stack trace from previous location ---
   at System.Threading.ExecutionContext.RunInternal(ExecutionContext executionContext, ContextCallback callback, Object state)
   at System.Threading.Tasks.Task.ExecuteWithThreadLocal(Task& currentTaskSlot, Thread threadPoolThread)

collectionSubscription = realmAccess.RegisterForNotifications(r => r.All<BeatmapCollection>().Where(c => c.Name == room.Name), (sender, _) => collectionExists.Value = sender.Count > 0);

downloadedBeatmapsCount.BindValueChanged(_ => Text = formatButtonText(downloadedBeatmapsCount.Value, collectionExists.Value));

collectionExists.BindValueChanged(_ => Text = formatButtonText(downloadedBeatmapsCount.Value, collectionExists.Value), true);
}

protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);

beatmapSubscription?.Dispose();
collectionSubscription?.Dispose();
}

private string formatFilterQuery(IReadOnlyList<PlaylistItem> playlistItems) => string.Join(" OR ", playlistItems.Select(item => $"(OnlineID == {item.Beatmap.OnlineID})").Distinct());

private string formatButtonText(int count, bool collectionExists) => $"Add {count} {(count == 1 ? "beatmap" : "beatmaps")} to {(collectionExists ? "collection" : "new collection")}";
}
}

0 comments on commit f9bda05

Please sign in to comment.