mirror of
https://github.com/ppy/osu.git
synced 2025-03-06 13:37:46 +08:00
Tidy up implementation and remove unnecessary enum
This commit is contained in:
parent
ab6665d88c
commit
8a48cb701d
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
namespace osu.Game.Online
|
namespace osu.Game.Online
|
||||||
{
|
{
|
||||||
public enum DownloadState
|
public enum DownloadState
|
||||||
|
@ -1,8 +1,6 @@
|
|||||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
@ -18,22 +16,24 @@ namespace osu.Game.Screens.Play
|
|||||||
{
|
{
|
||||||
public class SaveFailedScoreButton : CompositeDrawable
|
public class SaveFailedScoreButton : CompositeDrawable
|
||||||
{
|
{
|
||||||
public Func<Task<ScoreInfo>> ImportFailedScore;
|
private readonly Bindable<DownloadState> state = new Bindable<DownloadState>();
|
||||||
private Task<ScoreInfo> saveFailedScoreTask;
|
|
||||||
private ScoreInfo score;
|
|
||||||
|
|
||||||
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)
|
public SaveFailedScoreButton(Func<Task<ScoreInfo>> requestImportFailedScore)
|
||||||
{
|
{
|
||||||
Size = new Vector2(50, 30);
|
Size = new Vector2(50, 30);
|
||||||
ImportFailedScore = requestImportFailedScore;
|
importFailedScore = requestImportFailedScore;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuGame game)
|
private void load(OsuGame? game)
|
||||||
{
|
{
|
||||||
InternalChild = button = new DownloadButton
|
InternalChild = button = new DownloadButton
|
||||||
{
|
{
|
||||||
@ -42,13 +42,13 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
button.Action = () =>
|
button.Action = () =>
|
||||||
{
|
{
|
||||||
switch (State.Value)
|
switch (state.Value)
|
||||||
{
|
{
|
||||||
case ImportState.Imported:
|
case DownloadState.LocallyAvailable:
|
||||||
game?.PresentScore(score, ScorePresentType.Gameplay);
|
game?.PresentScore(score, ScorePresentType.Gameplay);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImportState.Importing:
|
case DownloadState.Importing:
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -56,24 +56,24 @@ namespace osu.Game.Screens.Play
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
State.BindValueChanged(state =>
|
state.BindValueChanged(state =>
|
||||||
{
|
{
|
||||||
switch (state.NewValue)
|
switch (state.NewValue)
|
||||||
{
|
{
|
||||||
case ImportState.Imported:
|
case DownloadState.LocallyAvailable:
|
||||||
button.State.Value = DownloadState.LocallyAvailable;
|
button.State.Value = DownloadState.LocallyAvailable;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImportState.Importing:
|
case DownloadState.Importing:
|
||||||
button.State.Value = DownloadState.Importing;
|
button.State.Value = DownloadState.Importing;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImportState.Failed:
|
case DownloadState.NotDownloaded:
|
||||||
button.State.Value = DownloadState.NotDownloaded;
|
button.State.Value = DownloadState.NotDownloaded;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}, true);
|
}, true);
|
||||||
State.BindValueChanged(updateState, true);
|
state.BindValueChanged(updateState, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void saveScore()
|
private void saveScore()
|
||||||
@ -83,48 +83,35 @@ namespace osu.Game.Screens.Play
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
State.Value = ImportState.Importing;
|
state.Value = DownloadState.Importing;
|
||||||
|
|
||||||
saveFailedScoreTask = Task.Run(ImportFailedScore);
|
saveFailedScoreTask = Task.Run(importFailedScore);
|
||||||
saveFailedScoreTask.ContinueWith(s => Schedule(() =>
|
saveFailedScoreTask.ContinueWith(s => Schedule(() =>
|
||||||
{
|
{
|
||||||
score = s.GetAwaiter().GetResult();
|
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)
|
switch (state.NewValue)
|
||||||
{
|
{
|
||||||
case ImportState.Imported:
|
case DownloadState.LocallyAvailable:
|
||||||
button.TooltipText = @"Watch replay";
|
button.TooltipText = @"Watch replay";
|
||||||
button.Enabled.Value = true;
|
button.Enabled.Value = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImportState.Importing:
|
case DownloadState.Importing:
|
||||||
button.TooltipText = @"Importing score";
|
button.TooltipText = @"Importing score";
|
||||||
button.Enabled.Value = false;
|
button.Enabled.Value = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case ImportState.Failed:
|
|
||||||
button.TooltipText = @"Import failed, click button to re-import";
|
|
||||||
button.Enabled.Value = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
default:
|
||||||
button.TooltipText = @"Save score";
|
button.TooltipText = @"Save score";
|
||||||
button.Enabled.Value = true;
|
button.Enabled.Value = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public enum ImportState
|
|
||||||
{
|
|
||||||
NotImported,
|
|
||||||
Failed,
|
|
||||||
Importing,
|
|
||||||
Imported
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user