Use better design and fix some problem

Let saveReplay async but still void
Make failed score's rank = F
This commit is contained in:
cdwcgt 2022-06-21 19:06:38 +08:00
parent 43ead5820a
commit f2eb7e0551
No known key found for this signature in database
GPG Key ID: 144396D01095C3A2
3 changed files with 92 additions and 8 deletions

View File

@ -5,8 +5,14 @@
using System;
using osu.Game.Graphics;
using osu.Game.Graphics.UserInterface;
using osuTK;
using osuTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
namespace osu.Game.Screens.Play
{
@ -21,7 +27,41 @@ private void load(OsuColour colours)
{
AddButton("Retry", colours.YellowDark, () => OnRetry?.Invoke());
AddButton("Quit", new Color4(170, 27, 39, 255), () => OnQuit?.Invoke());
AddButton("Save replay and Quit", colours.Blue, () => SaveReplay?.Invoke());
// from #10339 maybe this is a better visual effect
Add(new Container
{
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
RelativeSizeAxes = Axes.X,
Height = TwoLayerButton.SIZE_EXTENDED.Y,
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4Extensions.FromHex("#333")
},
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
Spacing = new Vector2(5),
Padding = new MarginPadding(10),
Direction = FillDirection.Horizontal,
Children = new Drawable[]
{
new SaveFailedScoreButton()
{
OnSave = SaveReplay,
RelativeSizeAxes = Axes.Y,
Width = 300
},
}
}
}
});
}
}
}

View File

@ -266,7 +266,7 @@ private void load(AudioManager audio, OsuConfigManager config, OsuGameBase game,
},
FailOverlay = new FailOverlay
{
SaveReplay = saveReplay,
SaveReplay = saveFailedReplay,
OnRetry = Restart,
OnQuit = () => PerformExit(true),
},
@ -1024,8 +1024,7 @@ public override bool OnExiting(ScreenExitEvent e)
if (prepareScoreForDisplayTask == null)
{
Score.ScoreInfo.Passed = false;
// potentially should be ScoreRank.F instead? this is the best alternative for now.
Score.ScoreInfo.Rank = ScoreRank.D;
Score.ScoreInfo.Rank = ScoreRank.F;
}
// EndPlaying() is typically called from ReplayRecorder.Dispose(). Disposal is currently asynchronous.
@ -1044,20 +1043,20 @@ public override bool OnExiting(ScreenExitEvent e)
return base.OnExiting(e);
}
private void saveReplay()
private async void saveFailedReplay()
{
Score.ScoreInfo.Passed = false;
Score.ScoreInfo.Rank = ScoreRank.F;
var scoreCopy = Score.DeepClone();
try
{
ImportScore(scoreCopy).ConfigureAwait(false);
await ImportScore(scoreCopy).ConfigureAwait(false);
}
catch (Exception ex)
{
Logger.Error(ex, @"Score import failed!");
}
PerformExit(true);
}
/// <summary>

View File

@ -0,0 +1,45 @@
// 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.
using System;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
namespace osu.Game.Screens.Play
{
public class SaveFailedScoreButton : DownloadButton
{
public Action? OnSave;
[BackgroundDependencyLoader]
private void load()
{
State.BindValueChanged(updateTooltip, true);
Action = saveScore;
}
private void saveScore()
{
if (State.Value != DownloadState.LocallyAvailable)
OnSave?.Invoke();
State.Value = DownloadState.LocallyAvailable;
}
private void updateTooltip(ValueChangedEvent<DownloadState> state)
{
switch (state.NewValue)
{
case DownloadState.LocallyAvailable:
TooltipText = @"Score saved";
break;
default:
TooltipText = @"Save score";
break;
}
}
}
}