diff --git a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs index 0be848f1d5..e71b2d596e 100644 --- a/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs +++ b/osu.Game.Tests/Visual/Gameplay/TestSceneReplayDownloadButton.cs @@ -26,29 +26,33 @@ namespace osu.Game.Tests.Visual.Gameplay public TestSceneReplayDownloadButton() { - createButton(); + createButton(true); AddStep(@"downloading state", () => downloadButton.SetDownloadState(DownloadState.Downloading)); AddStep(@"locally available state", () => downloadButton.SetDownloadState(DownloadState.LocallyAvailable)); AddStep(@"not downloaded state", () => downloadButton.SetDownloadState(DownloadState.NotDownloaded)); + createButton(false); } - private void createButton() + private void createButton(bool withReplay) { - AddStep(@"create button", () => Child = downloadButton = new TestReplayDownloadButton(getScoreInfo()) + AddStep(withReplay ? @"create button with replay" : "create button without replay", () => { - Anchor = Anchor.Centre, - Origin = Anchor.Centre, + Child = downloadButton = new TestReplayDownloadButton(getScoreInfo(withReplay)) + { + Anchor = Anchor.Centre, + Origin = Anchor.Centre, + }; }); } - private ScoreInfo getScoreInfo() + private ScoreInfo getScoreInfo(bool replayAvailable) { return new APILegacyScoreInfo { ID = 1, OnlineScoreID = 2553163309, Ruleset = new OsuRuleset().RulesetInfo, - Replay = true, + Replay = replayAvailable, User = new User { Id = 39828, diff --git a/osu.Game/Screens/Play/ReplayDownloadButton.cs b/osu.Game/Screens/Play/ReplayDownloadButton.cs index 0d6a159523..d6ded27cdf 100644 --- a/osu.Game/Screens/Play/ReplayDownloadButton.cs +++ b/osu.Game/Screens/Play/ReplayDownloadButton.cs @@ -42,13 +42,17 @@ namespace osu.Game.Screens.Play { get { - if (scores.IsAvailableLocally(Model.Value)) - return @"Watch replay"; + switch (getReplayAvailability()) + { + case ReplayAvailability.Local: + return @"Watch replay"; - if (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay) - return @"Download replay"; + case ReplayAvailability.Online: + return @"Download replay"; - return @"Replay unavailable"; + default: + return @"Replay unavailable"; + } } } @@ -58,8 +62,6 @@ namespace osu.Game.Screens.Play AutoSizeAxes = Axes.Both; } - private bool hasReplay => (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay) || scores.IsAvailableLocally(Model.Value); - [BackgroundDependencyLoader(true)] private void load() { @@ -146,6 +148,30 @@ namespace osu.Game.Screens.Play break; } }, true); + + if (getReplayAvailability() == ReplayAvailability.NotAvailable) + { + button.Enabled.Value = false; + button.Alpha = 0.6f; + } + } + + private ReplayAvailability getReplayAvailability() + { + if (scores.IsAvailableLocally(Model.Value)) + return ReplayAvailability.Local; + + if (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay) + return ReplayAvailability.Online; + + return ReplayAvailability.NotAvailable; + } + + private enum ReplayAvailability + { + Local, + Online, + NotAvailable, } } }