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

Improve and combine logic that exists in two classes

This commit is contained in:
Dean Herbert 2023-06-21 17:48:12 +09:00
parent 4bd121d3b8
commit 9ca772421d
2 changed files with 36 additions and 17 deletions

View File

@ -97,6 +97,8 @@ namespace osu.Game.Screens.Play
}, true);
}
#region Export via hotkey logic (also in ReplayDownloadButton)
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
switch (e.Action)
@ -106,12 +108,12 @@ namespace osu.Game.Screens.Play
return true;
case GlobalAction.ExportReplay:
Task.Run(importFailedScore).ContinueWith(t =>
{
importedScore = realm.Run(r => r.Find<ScoreInfo>(t.GetResultSafely().ID)?.Detach());
Schedule(() => state.Value = importedScore != null ? DownloadState.LocallyAvailable : DownloadState.NotDownloaded);
scoreManager.Export(importedScore);
});
state.BindValueChanged(exportWhenReady, true);
// start the import via button
if (state.Value != DownloadState.LocallyAvailable)
button.TriggerClick();
return true;
}
@ -121,5 +123,16 @@ namespace osu.Game.Screens.Play
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
private void exportWhenReady(ValueChangedEvent<DownloadState> state)
{
if (state.NewValue != DownloadState.LocallyAvailable) return;
scoreManager.Export(importedScore);
this.state.ValueChanged -= exportWhenReady;
}
#endregion
}
}

View File

@ -103,6 +103,8 @@ namespace osu.Game.Screens.Ranking
}, true);
}
#region Export via hotkey logic (also in SaveFailedScoreButton)
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
switch (e.Action)
@ -112,18 +114,11 @@ namespace osu.Game.Screens.Ranking
return true;
case GlobalAction.ExportReplay:
if (State.Value == DownloadState.NotDownloaded)
{
State.BindValueChanged(exportWhenReady, true);
// start the import via button
if (State.Value != DownloadState.LocallyAvailable)
button.TriggerClick();
}
State.ValueChanged += importAfterDownload;
void importAfterDownload(ValueChangedEvent<DownloadState> valueChangedEvent)
{
scoreManager.Export(Score.Value);
State.ValueChanged -= importAfterDownload;
}
return true;
}
@ -135,6 +130,17 @@ namespace osu.Game.Screens.Ranking
{
}
private void exportWhenReady(ValueChangedEvent<DownloadState> state)
{
if (state.NewValue != DownloadState.LocallyAvailable) return;
scoreManager.Export(Score.Value);
State.ValueChanged -= exportWhenReady;
}
#endregion
private void updateState()
{
switch (replayAvailability)