1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-19 07:42:58 +08:00

Merge pull request #20189 from peppy/fix-playlist-item-download-button-visibility

Fix playlist items showing download button briefly during initial display
This commit is contained in:
Dan Balasescu 2022-09-08 19:47:35 +09:00 committed by GitHub
commit 4fc03998a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 21 additions and 8 deletions

View File

@ -9,6 +9,7 @@ using osu.Framework.Graphics;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables.Cards.Buttons; using osu.Game.Beatmaps.Drawables.Cards.Buttons;
using osu.Game.Configuration; using osu.Game.Configuration;
using osu.Game.Online;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Resources.Localisation.Web; using osu.Game.Resources.Localisation.Web;
@ -58,6 +59,7 @@ namespace osu.Game.Tests.Visual.Beatmaps
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
State = { Value = DownloadState.NotDownloaded },
Scale = new Vector2(2) Scale = new Vector2(2)
}; };
}); });

View File

@ -81,9 +81,11 @@ namespace osu.Game.Tests.Visual.Gameplay
CreateTest(); CreateTest();
AddUntilStep("fail screen displayed", () => Player.ChildrenOfType<FailOverlay>().First().State.Value == Visibility.Visible); AddUntilStep("fail screen displayed", () => Player.ChildrenOfType<FailOverlay>().First().State.Value == Visibility.Visible);
AddUntilStep("wait for button clickable", () => Player.ChildrenOfType<SaveFailedScoreButton>().First().ChildrenOfType<OsuClickableContainer>().First().Enabled.Value);
AddUntilStep("score not in database", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID) == null)); AddUntilStep("score not in database", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID) == null));
AddStep("click save button", () => Player.ChildrenOfType<SaveFailedScoreButton>().First().ChildrenOfType<OsuClickableContainer>().First().TriggerClick()); AddStep("click save button", () => Player.ChildrenOfType<SaveFailedScoreButton>().First().ChildrenOfType<OsuClickableContainer>().First().TriggerClick());
AddUntilStep("score not in database", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID) != null)); AddUntilStep("score in database", () => Realm.Run(r => r.Find<ScoreInfo>(Player.Score.ScoreInfo.ID) != null));
} }
[Test] [Test]

View File

@ -202,7 +202,7 @@ namespace osu.Game.Tests.Visual.Gameplay
AddUntilStep("wait for load", () => downloadButton.IsLoaded); AddUntilStep("wait for load", () => downloadButton.IsLoaded);
AddAssert("state is not downloaded", () => downloadButton.State.Value == DownloadState.NotDownloaded); AddAssert("state is unknown", () => downloadButton.State.Value == DownloadState.Unknown);
AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value); AddAssert("button is not enabled", () => !downloadButton.ChildrenOfType<DownloadButton>().First().Enabled.Value);
} }

View File

@ -17,8 +17,7 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{ {
public class DownloadButton : BeatmapCardIconButton public class DownloadButton : BeatmapCardIconButton
{ {
public IBindable<DownloadState> State => state; public Bindable<DownloadState> State { get; } = new Bindable<DownloadState>();
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
private readonly APIBeatmapSet beatmapSet; private readonly APIBeatmapSet beatmapSet;
@ -48,14 +47,19 @@ namespace osu.Game.Beatmaps.Drawables.Cards.Buttons
{ {
base.LoadComplete(); base.LoadComplete();
preferNoVideo.BindValueChanged(_ => updateState()); preferNoVideo.BindValueChanged(_ => updateState());
state.BindValueChanged(_ => updateState(), true); State.BindValueChanged(_ => updateState(), true);
FinishTransforms(true); FinishTransforms(true);
} }
private void updateState() private void updateState()
{ {
switch (state.Value) switch (State.Value)
{ {
case DownloadState.Unknown:
Action = null;
TooltipText = string.Empty;
break;
case DownloadState.Downloading: case DownloadState.Downloading:
case DownloadState.Importing: case DownloadState.Importing:
Action = null; Action = null;

View File

@ -5,6 +5,7 @@ namespace osu.Game.Online
{ {
public enum DownloadState public enum DownloadState
{ {
Unknown,
NotDownloaded, NotDownloaded,
Downloading, Downloading,
Importing, Importing,

View File

@ -114,6 +114,7 @@ namespace osu.Game.Online.Rooms
switch (downloadTracker.State.Value) switch (downloadTracker.State.Value)
{ {
case DownloadState.Unknown:
case DownloadState.NotDownloaded: case DownloadState.NotDownloaded:
availability.Value = BeatmapAvailability.NotDownloaded(); availability.Value = BeatmapAvailability.NotDownloaded();
break; break;

View File

@ -561,6 +561,10 @@ namespace osu.Game.Screens.OnlinePlay
{ {
switch (state.NewValue) switch (state.NewValue)
{ {
case DownloadState.Unknown:
// Ignore initial state to ensure the button doesn't briefly appear.
break;
case DownloadState.LocallyAvailable: case DownloadState.LocallyAvailable:
// Perform a local query of the beatmap by beatmap checksum, and reset the state if not matching. // Perform a local query of the beatmap by beatmap checksum, and reset the state if not matching.
if (beatmapManager.QueryBeatmap(b => b.MD5Hash == beatmap.MD5Hash) == null) if (beatmapManager.QueryBeatmap(b => b.MD5Hash == beatmap.MD5Hash) == null)

View File

@ -63,8 +63,7 @@ namespace osu.Game.Screens.Play
if (player != null) if (player != null)
{ {
importedScore = realm.Run(r => r.Find<ScoreInfo>(player.Score.ScoreInfo.ID)?.Detach()); importedScore = realm.Run(r => r.Find<ScoreInfo>(player.Score.ScoreInfo.ID)?.Detach());
if (importedScore != null) state.Value = importedScore != null ? DownloadState.LocallyAvailable : DownloadState.NotDownloaded;
state.Value = DownloadState.LocallyAvailable;
} }
state.BindValueChanged(state => state.BindValueChanged(state =>