1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-15 06:42:56 +08:00

Shake button when replay already save

This commit is contained in:
cdwcgt 2022-06-22 01:19:20 +09:00
parent f2eb7e0551
commit bff35cb348
No known key found for this signature in database
GPG Key ID: 144396D01095C3A2

View File

@ -4,20 +4,54 @@
using System; using System;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterface;
using osu.Game.Online; using osu.Game.Online;
using osuTK;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class SaveFailedScoreButton : DownloadButton public class SaveFailedScoreButton : CompositeDrawable
{ {
public Action? OnSave; public Action? OnSave;
protected readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
private DownloadButton button;
private ShakeContainer shakeContainer;
public SaveFailedScoreButton()
{
InternalChild = shakeContainer = new ShakeContainer
{
RelativeSizeAxes = Axes.Both,
Child = button = new DownloadButton
{
RelativeSizeAxes = Axes.Both,
}
};
Size = new Vector2(50, 30);
}
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load()
{ {
button.Action = () =>
{
switch (State.Value)
{
case DownloadState.LocallyAvailable:
shakeContainer.Shake();
break;
default:
saveScore();
break;
}
};
State.BindValueChanged(updateTooltip, true); State.BindValueChanged(updateTooltip, true);
Action = saveScore;
} }
private void saveScore() private void saveScore()
@ -26,6 +60,7 @@ namespace osu.Game.Screens.Play
OnSave?.Invoke(); OnSave?.Invoke();
State.Value = DownloadState.LocallyAvailable; State.Value = DownloadState.LocallyAvailable;
button.State.Value = DownloadState.LocallyAvailable;
} }
private void updateTooltip(ValueChangedEvent<DownloadState> state) private void updateTooltip(ValueChangedEvent<DownloadState> state)
@ -33,11 +68,11 @@ namespace osu.Game.Screens.Play
switch (state.NewValue) switch (state.NewValue)
{ {
case DownloadState.LocallyAvailable: case DownloadState.LocallyAvailable:
TooltipText = @"Score saved"; button.TooltipText = @"Score saved";
break; break;
default: default:
TooltipText = @"Save score"; button.TooltipText = @"Save score";
break; break;
} }
} }