1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 10:52:53 +08:00

Disable replay button when replay is unavailable

This commit is contained in:
naoey 2019-06-29 12:49:03 +05:30
parent 7d9e215744
commit d8f6bbc90e
No known key found for this signature in database
GPG Key ID: 670DA9BE3DF7EE60
2 changed files with 44 additions and 14 deletions

View File

@ -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,

View File

@ -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,
}
}
}