2022-06-21 11:06:38 +00:00
|
|
|
|
// 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;
|
2022-06-21 11:06:38 +00:00
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Online;
|
2022-06-21 16:19:20 +00:00
|
|
|
|
using osuTK;
|
2022-06-21 11:06:38 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2022-06-21 16:19:20 +00:00
|
|
|
|
public class SaveFailedScoreButton : CompositeDrawable
|
2022-06-21 11:06:38 +00:00
|
|
|
|
{
|
|
|
|
|
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);
|
|
|
|
|
}
|
|
|
|
|
|
2022-06-21 11:06:38 +00:00
|
|
|
|
[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;
|
|
|
|
|
}
|
|
|
|
|
};
|
2022-06-21 11:06:38 +00:00
|
|
|
|
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;
|
2022-06-21 11:06:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateTooltip(ValueChangedEvent<DownloadState> state)
|
|
|
|
|
{
|
|
|
|
|
switch (state.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
2022-06-21 16:19:20 +00:00
|
|
|
|
button.TooltipText = @"Score saved";
|
2022-06-21 11:06:38 +00:00
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
default:
|
2022-06-21 16:19:20 +00:00
|
|
|
|
button.TooltipText = @"Save score";
|
2022-06-21 11:06:38 +00:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|