1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-05 12:32:58 +08:00

Tidy up implementation and remove unnecessary enum

This commit is contained in:
Dean Herbert 2022-07-15 18:54:19 +09:00
parent ab6665d88c
commit 8a48cb701d
2 changed files with 24 additions and 39 deletions

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
namespace osu.Game.Online
{
public enum DownloadState

View File

@ -1,8 +1,6 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.
#nullable disable
using System;
using System.Threading.Tasks;
using osu.Framework.Allocation;
@ -18,22 +16,24 @@ namespace osu.Game.Screens.Play
{
public class SaveFailedScoreButton : CompositeDrawable
{
public Func<Task<ScoreInfo>> ImportFailedScore;
private Task<ScoreInfo> saveFailedScoreTask;
private ScoreInfo score;
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
protected readonly Bindable<ImportState> State = new Bindable<ImportState>();
private readonly Func<Task<ScoreInfo>> importFailedScore;
private DownloadButton button;
private Task<ScoreInfo>? saveFailedScoreTask;
private ScoreInfo? score;
private DownloadButton button = null!;
public SaveFailedScoreButton(Func<Task<ScoreInfo>> requestImportFailedScore)
{
Size = new Vector2(50, 30);
ImportFailedScore = requestImportFailedScore;
importFailedScore = requestImportFailedScore;
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame game)
[BackgroundDependencyLoader]
private void load(OsuGame? game)
{
InternalChild = button = new DownloadButton
{
@ -42,13 +42,13 @@ namespace osu.Game.Screens.Play
button.Action = () =>
{
switch (State.Value)
switch (state.Value)
{
case ImportState.Imported:
case DownloadState.LocallyAvailable:
game?.PresentScore(score, ScorePresentType.Gameplay);
break;
case ImportState.Importing:
case DownloadState.Importing:
break;
default:
@ -56,24 +56,24 @@ namespace osu.Game.Screens.Play
break;
}
};
State.BindValueChanged(state =>
state.BindValueChanged(state =>
{
switch (state.NewValue)
{
case ImportState.Imported:
case DownloadState.LocallyAvailable:
button.State.Value = DownloadState.LocallyAvailable;
break;
case ImportState.Importing:
case DownloadState.Importing:
button.State.Value = DownloadState.Importing;
break;
case ImportState.Failed:
case DownloadState.NotDownloaded:
button.State.Value = DownloadState.NotDownloaded;
break;
}
}, true);
State.BindValueChanged(updateState, true);
state.BindValueChanged(updateState, true);
}
private void saveScore()
@ -83,48 +83,35 @@ namespace osu.Game.Screens.Play
return;
}
State.Value = ImportState.Importing;
state.Value = DownloadState.Importing;
saveFailedScoreTask = Task.Run(ImportFailedScore);
saveFailedScoreTask = Task.Run(importFailedScore);
saveFailedScoreTask.ContinueWith(s => Schedule(() =>
{
score = s.GetAwaiter().GetResult();
State.Value = score != null ? ImportState.Imported : ImportState.Failed;
state.Value = score != null ? DownloadState.LocallyAvailable : DownloadState.NotDownloaded;
}));
}
private void updateState(ValueChangedEvent<ImportState> state)
private void updateState(ValueChangedEvent<DownloadState> state)
{
switch (state.NewValue)
{
case ImportState.Imported:
case DownloadState.LocallyAvailable:
button.TooltipText = @"Watch replay";
button.Enabled.Value = true;
break;
case ImportState.Importing:
case DownloadState.Importing:
button.TooltipText = @"Importing score";
button.Enabled.Value = false;
break;
case ImportState.Failed:
button.TooltipText = @"Import failed, click button to re-import";
button.Enabled.Value = true;
break;
default:
button.TooltipText = @"Save score";
button.Enabled.Value = true;
break;
}
}
public enum ImportState
{
NotImported,
Failed,
Importing,
Imported
}
}
}