diff --git a/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs b/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs index 879e35057b..bb7fcc2fce 100644 --- a/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs +++ b/osu.Game.Tests/Visual/Online/TestSceneDirectDownloadButton.cs @@ -5,7 +5,6 @@ using System.Linq; using NUnit.Framework; using osu.Framework.Allocation; using osu.Framework.Graphics; -using osu.Framework.Testing; using osu.Game.Beatmaps; using osu.Game.Online; using osu.Game.Online.API.Requests.Responses; @@ -145,7 +144,7 @@ namespace osu.Game.Tests.Visual.Online { public new bool DownloadEnabled => base.DownloadEnabled; - public DownloadState DownloadState => this.ChildrenOfType().First().State.Value; + public DownloadState DownloadState => State.Value; public TestDownloadButton(BeatmapSetInfo beatmapSet) : base(beatmapSet) diff --git a/osu.Game/Online/BeatmapDownloadTracker.cs b/osu.Game/Online/BeatmapDownloadTracker.cs index 6df74efe9c..181968c02f 100644 --- a/osu.Game/Online/BeatmapDownloadTracker.cs +++ b/osu.Game/Online/BeatmapDownloadTracker.cs @@ -34,7 +34,7 @@ namespace osu.Game.Online // Used to interact with manager classes that don't support interface types. Will eventually be replaced. var beatmapSetInfo = new BeatmapSetInfo { OnlineBeatmapSetID = TrackedItem.OnlineID }; - if ((TrackedItem as BeatmapSetInfo)?.ID > 0 || Manager?.IsAvailableLocally(beatmapSetInfo) == true) + if (Manager?.IsAvailableLocally(beatmapSetInfo) == true) UpdateState(DownloadState.LocallyAvailable); else if (Manager != null) attachDownload(Manager.GetExistingDownload(beatmapSetInfo)); @@ -122,10 +122,8 @@ namespace osu.Game.Online { Schedule(() => { - if (!checkEquality(item, TrackedItem)) - return; - - UpdateState(DownloadState.LocallyAvailable); + if (checkEquality(item, TrackedItem)) + UpdateState(DownloadState.LocallyAvailable); }); } } diff --git a/osu.Game/Online/Rooms/OnlinePlayBeatmapAvailabilityTracker.cs b/osu.Game/Online/Rooms/OnlinePlayBeatmapAvailabilityTracker.cs index 6dd1204555..5e09f42aa8 100644 --- a/osu.Game/Online/Rooms/OnlinePlayBeatmapAvailabilityTracker.cs +++ b/osu.Game/Online/Rooms/OnlinePlayBeatmapAvailabilityTracker.cs @@ -4,6 +4,7 @@ using System; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Logging; using osu.Framework.Threading; @@ -17,10 +18,12 @@ namespace osu.Game.Online.Rooms /// This differs from a regular download tracking composite as this accounts for the /// databased beatmap set's checksum, to disallow from playing with an altered version of the beatmap. /// - public class OnlinePlayBeatmapAvailabilityTracker : CompositeDrawable + public sealed class OnlinePlayBeatmapAvailabilityTracker : CompositeDrawable { public readonly IBindable SelectedItem = new Bindable(); + protected override bool RequiresChildrenUpdate => true; + [Resolved] private BeatmapManager beatmapManager { get; set; } @@ -46,9 +49,10 @@ namespace osu.Game.Online.Rooms if (item.NewValue == null) return; - downloadTracker?.Expire(); - downloadTracker = new BeatmapDownloadTracker(item.NewValue.Beatmap.Value.BeatmapSet); + downloadTracker?.RemoveAndDisposeImmediately(); + downloadTracker = new BeatmapDownloadTracker(item.NewValue.Beatmap.Value.BeatmapSet); + downloadTracker.State.BindValueChanged(_ => updateAvailability()); downloadTracker.Progress.BindValueChanged(_ => { if (downloadTracker.State.Value != DownloadState.Downloading) @@ -60,8 +64,6 @@ namespace osu.Game.Online.Rooms progressUpdate = Scheduler.AddDelayed(updateAvailability, progressUpdate == null ? 0 : 500); }); - downloadTracker.State.BindValueChanged(_ => updateAvailability(), true); - AddInternal(downloadTracker); }, true); } diff --git a/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs b/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs index 5c6472cd1b..dd12e8e467 100644 --- a/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs +++ b/osu.Game/Overlays/BeatmapListing/Panels/BeatmapPanelDownloadButton.cs @@ -36,6 +36,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels public BeatmapPanelDownloadButton(BeatmapSetInfo beatmapSet) { this.beatmapSet = beatmapSet; + InternalChildren = new Drawable[] { shakeContainer = new ShakeContainer @@ -44,6 +45,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels Child = button = new DownloadButton { RelativeSizeAxes = Axes.Both, + State = { BindTarget = State } }, }, DownloadTracker = new BeatmapDownloadTracker(beatmapSet) @@ -60,14 +62,6 @@ namespace osu.Game.Overlays.BeatmapListing.Panels }); } - protected override void LoadComplete() - { - base.LoadComplete(); - - ((IBindable)button.State).BindTo(DownloadTracker.State); - FinishTransforms(true); - } - [BackgroundDependencyLoader(true)] private void load(OsuGame game, BeatmapManager beatmaps, OsuConfigManager osuConfig) { @@ -96,7 +90,7 @@ namespace osu.Game.Overlays.BeatmapListing.Panels } }; - DownloadTracker.State.BindValueChanged(state => + State.BindValueChanged(state => { switch (state.NewValue) { @@ -116,5 +110,11 @@ namespace osu.Game.Overlays.BeatmapListing.Panels } }, true); } + + protected override void LoadComplete() + { + base.LoadComplete(); + FinishTransforms(true); + } } } diff --git a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs index e0a09ed520..624d07fb0f 100644 --- a/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs +++ b/osu.Game/Overlays/BeatmapSet/BeatmapSetHeaderContent.cs @@ -233,7 +233,7 @@ namespace osu.Game.Overlays.BeatmapSet Picker.BeatmapSet = rulesetSelector.BeatmapSet = author.BeatmapSet = beatmapAvailability.BeatmapSet = Details.BeatmapSet = setInfo.NewValue; cover.BeatmapSet = setInfo.NewValue; - downloadTracker?.Expire(); + downloadTracker?.RemoveAndDisposeImmediately(); if (setInfo.NewValue == null) { diff --git a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs index 16dd7b498b..5639265617 100644 --- a/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs +++ b/osu.Game/Screens/OnlinePlay/DrawableRoomPlaylistItem.cs @@ -289,7 +289,8 @@ namespace osu.Game.Screens.OnlinePlay [Resolved] private BeatmapManager beatmapManager { get; set; } - public override bool IsPresent => base.IsPresent || Scheduler.HasPendingTasks; + // required for download tracking, as this button hides itself. can probably be removed with a bit of consideration. + public override bool IsPresent => true; public PlaylistDownloadButton(PlaylistItem playlistItem) : base(playlistItem.Beatmap.Value.BeatmapSet) @@ -300,10 +301,8 @@ namespace osu.Game.Screens.OnlinePlay protected override void LoadComplete() { + State.BindValueChanged(stateChanged, true); base.LoadComplete(); - - DownloadTracker.State.BindValueChanged(stateChanged, true); - FinishTransforms(true); } private void stateChanged(ValueChangedEvent state) diff --git a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs index bcb793062b..270d12ec97 100644 --- a/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Match/RoomSubScreen.cs @@ -67,8 +67,6 @@ namespace osu.Game.Screens.OnlinePlay.Match [Cached] protected OnlinePlayBeatmapAvailabilityTracker BeatmapAvailabilityTracker { get; private set; } - protected IBindable BeatmapAvailability => BeatmapAvailabilityTracker.Availability; - public readonly Room Room; private readonly bool allowEdit; diff --git a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs index 544eac4127..0af41c977b 100644 --- a/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs +++ b/osu.Game/Screens/OnlinePlay/Multiplayer/MultiplayerMatchSubScreen.cs @@ -66,7 +66,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer SelectedItem.BindTo(client.CurrentMatchPlayingItem); - BeatmapAvailability.BindValueChanged(updateBeatmapAvailability, true); + BeatmapAvailabilityTracker.Availability.BindValueChanged(updateBeatmapAvailability, true); UserMods.BindValueChanged(onUserModsChanged); client.LoadRequested += onLoadRequested; @@ -362,7 +362,7 @@ namespace osu.Game.Screens.OnlinePlay.Multiplayer private void onLoadRequested() { - if (BeatmapAvailability.Value.State != DownloadState.LocallyAvailable) + if (BeatmapAvailabilityTracker.Availability.Value.State != DownloadState.LocallyAvailable) return; // In the case of spectating, IMultiplayerClient.LoadRequested can be fired while the game is still spectating a previous session. diff --git a/osu.Game/Screens/Ranking/ReplayDownloadButton.cs b/osu.Game/Screens/Ranking/ReplayDownloadButton.cs index f7325d2eb4..66b3c973f5 100644 --- a/osu.Game/Screens/Ranking/ReplayDownloadButton.cs +++ b/osu.Game/Screens/Ranking/ReplayDownloadButton.cs @@ -77,7 +77,7 @@ namespace osu.Game.Screens.Ranking Score.BindValueChanged(score => { - downloadTracker?.Expire(); + downloadTracker?.RemoveAndDisposeImmediately(); if (score.NewValue != null) {