2019-06-12 04:01:57 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
using osu.Framework.Graphics.Cursor;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics;
|
2019-06-12 04:01:57 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2019-06-12 04:01:57 +08:00
|
|
|
|
using osu.Game.Online;
|
|
|
|
|
using osu.Game.Scoring;
|
2019-06-29 13:25:30 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
|
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2019-06-12 04:01:57 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play
|
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>, IHasTooltip
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
private const int size = 40;
|
|
|
|
|
|
|
|
|
|
[Resolved(canBeNull: true)]
|
2019-06-12 04:01:57 +08:00
|
|
|
|
private OsuGame game { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private ScoreManager scores { get; set; }
|
|
|
|
|
|
2019-06-29 13:25:30 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
|
|
|
|
|
private OsuClickableContainer button;
|
|
|
|
|
private SpriteIcon downloadIcon;
|
|
|
|
|
private SpriteIcon playIcon;
|
|
|
|
|
private ShakeContainer shakeContainer;
|
|
|
|
|
|
|
|
|
|
public string TooltipText
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
if (scores.IsAvailableLocally(Model.Value))
|
|
|
|
|
return @"Watch replay";
|
|
|
|
|
|
|
|
|
|
if (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay)
|
|
|
|
|
return @"Download replay";
|
|
|
|
|
|
|
|
|
|
return @"Replay unavailable";
|
|
|
|
|
}
|
2019-06-12 04:01:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-29 13:25:30 +08:00
|
|
|
|
public ReplayDownloadButton(ScoreInfo score)
|
|
|
|
|
: base(score)
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
Size = new Vector2(size);
|
|
|
|
|
CornerRadius = size / 2;
|
|
|
|
|
Masking = true;
|
2019-06-12 04:01:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-06-29 13:25:30 +08:00
|
|
|
|
private bool hasReplay => (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay) || scores.IsAvailableLocally(Model.Value);
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(true)]
|
|
|
|
|
private void load()
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
Colour = Color4.Black.Opacity(0.4f),
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Radius = 5,
|
|
|
|
|
};
|
2019-06-12 04:01:57 +08:00
|
|
|
|
|
2019-06-29 13:25:30 +08:00
|
|
|
|
InternalChild = shakeContainer = new ShakeContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Child = button = new OsuClickableContainer
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = colours.GrayF,
|
|
|
|
|
},
|
|
|
|
|
playIcon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.Play,
|
|
|
|
|
Size = Vector2.Zero,
|
|
|
|
|
Colour = colours.Gray3,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
downloadIcon = new SpriteIcon
|
|
|
|
|
{
|
|
|
|
|
Icon = FontAwesome.Solid.FileDownload,
|
|
|
|
|
Size = Vector2.Zero,
|
|
|
|
|
Colour = colours.Gray3,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
};
|
2019-06-12 04:01:57 +08:00
|
|
|
|
|
2019-06-29 13:25:30 +08:00
|
|
|
|
button.Action = () =>
|
2019-06-12 04:01:57 +08:00
|
|
|
|
{
|
2019-06-29 13:25:30 +08:00
|
|
|
|
switch (State.Value)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
|
|
|
|
game.PresentScore(Model.Value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.NotDownloaded:
|
|
|
|
|
scores.Download(Model.Value);
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
shakeContainer.Shake();
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-06-12 04:01:57 +08:00
|
|
|
|
};
|
2019-06-29 13:25:30 +08:00
|
|
|
|
|
|
|
|
|
State.BindValueChanged(state =>
|
|
|
|
|
{
|
|
|
|
|
switch (state.NewValue)
|
|
|
|
|
{
|
|
|
|
|
case DownloadState.Downloading:
|
|
|
|
|
FadeEdgeEffectTo(colours.Yellow, 400, Easing.OutQuint);
|
|
|
|
|
button.Enabled.Value = false;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.LocallyAvailable:
|
|
|
|
|
playIcon.ResizeTo(13, 300, Easing.OutQuint);
|
|
|
|
|
downloadIcon.ResizeTo(Vector2.Zero, 300, Easing.OutExpo);
|
|
|
|
|
FadeEdgeEffectTo(Color4.Black.Opacity(0.4f), 400, Easing.OutQuint);
|
|
|
|
|
button.Enabled.Value = true;
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case DownloadState.NotDownloaded:
|
|
|
|
|
playIcon.ResizeTo(Vector2.Zero, 300, Easing.OutQuint);
|
|
|
|
|
downloadIcon.ResizeTo(13, 300, Easing.OutExpo);
|
|
|
|
|
FadeEdgeEffectTo(Color4.Black.Opacity(0.4f), 400, Easing.OutQuint);
|
|
|
|
|
button.Enabled.Value = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}, true);
|
2019-06-12 04:01:57 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|