1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-22 03:02:55 +08:00

Make direct panel download and replay buttons share UI

This commit is contained in:
naoey 2019-07-02 15:55:30 +05:30
parent 6539c6da17
commit ee516d2515
No known key found for this signature in database
GPG Key ID: 670DA9BE3DF7EE60
5 changed files with 119 additions and 142 deletions

View File

@ -9,6 +9,7 @@ using osu.Game.Rulesets.Osu;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Play; using osu.Game.Screens.Play;
using osu.Game.Users; using osu.Game.Users;
using osuTK;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
@ -41,6 +42,7 @@ namespace osu.Game.Tests.Visual.Gameplay
{ {
Anchor = Anchor.Centre, Anchor = Anchor.Centre,
Origin = Anchor.Centre, Origin = Anchor.Centre,
Size = new Vector2(80, 40),
}; };
}); });
} }

View File

@ -0,0 +1,87 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Game.Online;
using osuTK;
namespace osu.Game.Graphics.UserInterface
{
public class OsuDownloadButton : OsuAnimatedButton
{
public readonly Bindable<DownloadState> State = new Bindable<DownloadState>();
private readonly SpriteIcon icon;
private readonly SpriteIcon checkmark;
private readonly Box background;
private OsuColour colours;
public OsuDownloadButton()
{
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
},
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(13),
Icon = FontAwesome.Solid.Download,
},
checkmark = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
X = 8,
Size = Vector2.Zero,
Icon = FontAwesome.Solid.Check,
}
};
}
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
this.colours = colours;
State.BindValueChanged(updateState, true);
}
private void updateState(ValueChangedEvent<DownloadState> state)
{
switch (state.NewValue)
{
case DownloadState.NotDownloaded:
background.FadeColour(colours.Gray4, 500, Easing.InOutExpo);
icon.MoveToX(0, 500, Easing.InOutExpo);
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
break;
case DownloadState.Downloading:
background.FadeColour(colours.Blue, 500, Easing.InOutExpo);
icon.MoveToX(0, 500, Easing.InOutExpo);
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
break;
case DownloadState.Downloaded:
background.FadeColour(colours.Yellow, 500, Easing.InOutExpo);
break;
case DownloadState.LocallyAvailable:
background.FadeColour(colours.Green, 500, Easing.InOutExpo);
icon.MoveToX(-8, 500, Easing.InOutExpo);
checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo);
break;
}
}
}
}

View File

@ -1,4 +1,4 @@
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence. // 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. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
@ -10,7 +10,6 @@ using osu.Game.Graphics;
using osu.Game.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.Overlays.Direct namespace osu.Game.Overlays.Direct
{ {
@ -25,7 +24,7 @@ namespace osu.Game.Overlays.Direct
private OsuColour colours; private OsuColour colours;
private readonly ShakeContainer shakeContainer; private readonly ShakeContainer shakeContainer;
private readonly OsuAnimatedButton button; private readonly OsuDownloadButton button;
public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false) public DownloadButton(BeatmapSetInfo beatmapSet, bool noVideo = false)
: base(beatmapSet) : base(beatmapSet)
@ -35,33 +34,10 @@ namespace osu.Game.Overlays.Direct
InternalChild = shakeContainer = new ShakeContainer InternalChild = shakeContainer = new ShakeContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = button = new OsuAnimatedButton Child = button = new OsuDownloadButton
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Children = new Drawable[] },
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Depth = float.MaxValue
},
icon = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Size = new Vector2(13),
Icon = FontAwesome.Solid.Download,
},
checkmark = new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
X = 8,
Size = Vector2.Zero,
Icon = FontAwesome.Solid.Check,
}
}
}
}; };
} }
@ -69,7 +45,7 @@ namespace osu.Game.Overlays.Direct
{ {
base.LoadComplete(); base.LoadComplete();
State.BindValueChanged(state => updateState(state.NewValue), true); button.State.BindTo(State);
FinishTransforms(true); FinishTransforms(true);
} }
@ -105,32 +81,11 @@ namespace osu.Game.Overlays.Direct
}; };
} }
private void updateState(DownloadState state) protected override void Dispose(bool isDisposing)
{ {
switch (state) base.Dispose(isDisposing);
{
case DownloadState.NotDownloaded:
background.FadeColour(colours.Gray4, 500, Easing.InOutExpo);
icon.MoveToX(0, 500, Easing.InOutExpo);
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
break;
case DownloadState.Downloading: button?.State.UnbindAll();
background.FadeColour(colours.Blue, 500, Easing.InOutExpo);
icon.MoveToX(0, 500, Easing.InOutExpo);
checkmark.ScaleTo(Vector2.Zero, 500, Easing.InOutExpo);
break;
case DownloadState.Downloaded:
background.FadeColour(colours.Yellow, 500, Easing.InOutExpo);
break;
case DownloadState.LocallyAvailable:
background.FadeColour(colours.Green, 500, Easing.InOutExpo);
icon.MoveToX(-8, 500, Easing.InOutExpo);
checkmark.ScaleTo(new Vector2(13), 500, Easing.InOutExpo);
break;
}
} }
} }
} }

View File

@ -2,57 +2,28 @@
// See the LICENCE file in the repository root for full licence text. // See the LICENCE file in the repository root for full licence text.
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Online; using osu.Game.Online;
using osu.Game.Scoring; using osu.Game.Scoring;
using osuTK;
using osu.Framework.Graphics.Sprites;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Framework.Graphics.Effects; using osu.Game.Graphics.UserInterface;
using osuTK.Graphics;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Screens.Play namespace osu.Game.Screens.Play
{ {
public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>, IHasTooltip public class ReplayDownloadButton : DownloadTrackingComposite<ScoreInfo, ScoreManager>
{ {
[Resolved] [Resolved]
private ScoreManager scores { get; set; } private ScoreManager scores { get; set; }
private OsuClickableContainer button; private OsuDownloadButton button;
private SpriteIcon downloadIcon;
private SpriteIcon playIcon;
private ShakeContainer shakeContainer; private ShakeContainer shakeContainer;
private CircularContainer circle;
public string TooltipText
{
get
{
switch (replayAvailability)
{
case ReplayAvailability.Local:
return @"Watch replay";
case ReplayAvailability.Online:
return @"Download replay";
default:
return @"Replay unavailable";
}
}
}
private ReplayAvailability replayAvailability private ReplayAvailability replayAvailability
{ {
get get
{ {
if (scores.IsAvailableLocally(Model.Value)) if (State.Value == DownloadState.LocallyAvailable)
return ReplayAvailability.Local; return ReplayAvailability.Local;
if (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay) if (Model.Value is APILegacyScoreInfo apiScore && apiScore.Replay)
@ -65,54 +36,18 @@ namespace osu.Game.Screens.Play
public ReplayDownloadButton(ScoreInfo score) public ReplayDownloadButton(ScoreInfo score)
: base(score) : base(score)
{ {
AutoSizeAxes = Axes.Both;
} }
[BackgroundDependencyLoader(true)] [BackgroundDependencyLoader(true)]
private void load(OsuGame game, OsuColour colours) private void load(OsuGame game)
{ {
InternalChild = shakeContainer = new ShakeContainer InternalChild = shakeContainer = new ShakeContainer
{ {
AutoSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
Child = circle = new CircularContainer Child = button = new OsuDownloadButton
{ {
Masking = true, RelativeSizeAxes = Axes.Both,
Size = new Vector2(40), }
EdgeEffect = new EdgeEffectParameters
{
Colour = Color4.Black.Opacity(0.4f),
Type = EdgeEffectType.Shadow,
Radius = 5,
},
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,
},
},
}
},
}; };
button.Action = () => button.Action = () =>
@ -127,32 +62,29 @@ namespace osu.Game.Screens.Play
scores.Download(Model.Value); scores.Download(Model.Value);
break; break;
case DownloadState.Downloaded:
case DownloadState.Downloading: case DownloadState.Downloading:
shakeContainer.Shake(); shakeContainer.Shake();
break; break;
} }
}; };
State.BindValueChanged(state => State.BindValueChanged((state) =>
{ {
switch (state.NewValue) button.State.Value = state.NewValue;
switch (replayAvailability)
{ {
case DownloadState.Downloading: case ReplayAvailability.Local:
playIcon.ResizeTo(Vector2.Zero, 400, Easing.OutQuint); button.TooltipText = @"Watch replay";
downloadIcon.ResizeTo(13, 400, Easing.OutQuint);
circle.FadeEdgeEffectTo(colours.Yellow, 400, Easing.OutQuint);
break; break;
case DownloadState.LocallyAvailable: case ReplayAvailability.Online:
playIcon.ResizeTo(13, 400, Easing.OutQuint); button.TooltipText = @"Download replay";
downloadIcon.ResizeTo(Vector2.Zero, 400, Easing.OutQuint);
circle.FadeEdgeEffectTo(Color4.Black.Opacity(0.4f), 400, Easing.OutQuint);
break; break;
case DownloadState.NotDownloaded: default:
playIcon.ResizeTo(Vector2.Zero, 400, Easing.OutQuint); button.TooltipText = @"Replay unavailable";
downloadIcon.ResizeTo(13, 400, Easing.OutQuint);
circle.FadeEdgeEffectTo(Color4.Black.Opacity(0.4f), 400, Easing.OutQuint);
break; break;
} }
}, true); }, true);

View File

@ -173,7 +173,8 @@ namespace osu.Game.Screens.Ranking.Pages
{ {
Anchor = Anchor.BottomCentre, Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre, Origin = Anchor.BottomCentre,
Margin = new MarginPadding { Bottom = 5 }, Margin = new MarginPadding { Bottom = 10 },
Size = new Vector2(50, 30),
}, },
}; };