osu/osu.Game/Screens/Play/SaveFailedScoreButton.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.2 KiB
C#
Raw Normal View History

// 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;
2022-06-21 16:19:20 +00:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.UserInterface;
using osu.Game.Online;
2022-06-21 16:19:20 +00:00
using osuTK;
namespace osu.Game.Screens.Play
{
2022-06-21 16:19:20 +00:00
public class SaveFailedScoreButton : CompositeDrawable
{
public Action? OnSave;
2022-06-21 16:19:20 +00:00
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]
private void load()
{
2022-06-21 16:19:20 +00:00
button.Action = () =>
{
switch (State.Value)
{
case DownloadState.LocallyAvailable:
shakeContainer.Shake();
break;
default:
saveScore();
break;
}
};
State.BindValueChanged(updateTooltip, true);
}
private void saveScore()
{
if (State.Value != DownloadState.LocallyAvailable)
OnSave?.Invoke();
State.Value = DownloadState.LocallyAvailable;
2022-06-21 16:19:20 +00:00
button.State.Value = DownloadState.LocallyAvailable;
}
private void updateTooltip(ValueChangedEvent<DownloadState> state)
{
switch (state.NewValue)
{
case DownloadState.LocallyAvailable:
2022-06-21 16:19:20 +00:00
button.TooltipText = @"Score saved";
break;
default:
2022-06-21 16:19:20 +00:00
button.TooltipText = @"Save score";
break;
}
}
}
}