2019-08-13 13:29:58 +08: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 System.Threading.Tasks;
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Framework.Input.Events;
|
2021-02-22 16:14:13 +08:00
|
|
|
using osu.Framework.Localisation;
|
2019-08-13 13:29:58 +08:00
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
2021-04-21 13:37:11 +08:00
|
|
|
using osu.Game.Localisation;
|
2019-08-13 13:29:58 +08:00
|
|
|
using osu.Game.Overlays.Music;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
{
|
2020-09-03 14:46:56 +08:00
|
|
|
public class NowPlayingOverlay : OsuFocusedOverlayContainer, INamedOverlayComponent
|
2019-08-13 13:29:58 +08:00
|
|
|
{
|
2020-09-03 14:46:56 +08:00
|
|
|
public string IconTexture => "Icons/Hexacons/music";
|
2021-04-21 13:37:11 +08:00
|
|
|
public LocalisableString Title => NowPlayingStrings.HeaderTitle;
|
|
|
|
public LocalisableString Description => NowPlayingStrings.HeaderDescription;
|
2020-09-03 14:46:56 +08:00
|
|
|
|
2019-08-13 13:29:58 +08:00
|
|
|
private const float player_height = 130;
|
|
|
|
private const float transition_length = 800;
|
|
|
|
private const float progress_height = 10;
|
|
|
|
private const float bottom_black_area_height = 55;
|
|
|
|
|
|
|
|
private Drawable background;
|
|
|
|
private ProgressBar progressBar;
|
|
|
|
|
|
|
|
private IconButton prevButton;
|
|
|
|
private IconButton playButton;
|
|
|
|
private IconButton nextButton;
|
|
|
|
private IconButton playlistButton;
|
|
|
|
|
|
|
|
private SpriteText title, artist;
|
|
|
|
|
|
|
|
private PlaylistOverlay playlist;
|
|
|
|
|
|
|
|
private Container dragContainer;
|
|
|
|
private Container playerContainer;
|
|
|
|
|
2021-01-15 13:57:46 +08:00
|
|
|
protected override string PopInSampleName => "UI/now-playing-pop-in";
|
|
|
|
protected override string PopOutSampleName => "UI/now-playing-pop-out";
|
|
|
|
|
2019-08-13 13:29:58 +08:00
|
|
|
[Resolved]
|
|
|
|
private MusicController musicController { get; set; }
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private Bindable<WorkingBeatmap> beatmap { get; set; }
|
|
|
|
|
2020-02-17 15:59:35 +08:00
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2019-08-13 13:29:58 +08:00
|
|
|
public NowPlayingOverlay()
|
|
|
|
{
|
|
|
|
Width = 400;
|
|
|
|
Margin = new MarginPadding(10);
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2020-02-17 15:59:35 +08:00
|
|
|
private void load()
|
2019-08-13 13:29:58 +08:00
|
|
|
{
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
dragContainer = new DragContainer
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
playerContainer = new Container
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = player_height,
|
|
|
|
Masking = true,
|
|
|
|
CornerRadius = 5,
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
{
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
Colour = Color4.Black.Opacity(40),
|
|
|
|
Radius = 5,
|
|
|
|
},
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
background = new Background(),
|
|
|
|
title = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Position = new Vector2(0, 40),
|
|
|
|
Font = OsuFont.GetFont(size: 25, italics: true),
|
|
|
|
Colour = Color4.White,
|
|
|
|
Text = @"Nothing to play",
|
|
|
|
},
|
|
|
|
artist = new OsuSpriteText
|
|
|
|
{
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
Position = new Vector2(0, 45),
|
|
|
|
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Bold, italics: true),
|
|
|
|
Colour = Color4.White,
|
|
|
|
Text = @"Nothing to play",
|
|
|
|
},
|
|
|
|
new Container
|
|
|
|
{
|
|
|
|
Padding = new MarginPadding { Bottom = progress_height },
|
|
|
|
Height = bottom_black_area_height,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
new FillFlowContainer<IconButton>
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Children = new[]
|
|
|
|
{
|
|
|
|
prevButton = new MusicIconButton
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2019-10-24 12:10:17 +08:00
|
|
|
Action = () => musicController.PreviousTrack(),
|
2019-08-13 13:29:58 +08:00
|
|
|
Icon = FontAwesome.Solid.StepBackward,
|
|
|
|
},
|
|
|
|
playButton = new MusicIconButton
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Scale = new Vector2(1.4f),
|
|
|
|
IconScale = new Vector2(1.4f),
|
2019-08-13 13:46:57 +08:00
|
|
|
Action = () => musicController.TogglePause(),
|
2019-08-13 13:29:58 +08:00
|
|
|
Icon = FontAwesome.Regular.PlayCircle,
|
|
|
|
},
|
|
|
|
nextButton = new MusicIconButton
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2019-08-13 13:46:57 +08:00
|
|
|
Action = () => musicController.NextTrack(),
|
2019-08-13 13:29:58 +08:00
|
|
|
Icon = FontAwesome.Solid.StepForward,
|
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
playlistButton = new MusicIconButton
|
|
|
|
{
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Position = new Vector2(-bottom_black_area_height / 2, 0),
|
|
|
|
Icon = FontAwesome.Solid.Bars,
|
2021-02-09 18:46:57 +08:00
|
|
|
Action = togglePlaylist
|
2019-08-13 13:29:58 +08:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
2019-11-06 15:11:47 +08:00
|
|
|
progressBar = new HoverableProgressBar
|
2019-08-13 13:29:58 +08:00
|
|
|
{
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2019-11-06 15:11:47 +08:00
|
|
|
Height = progress_height / 2,
|
2019-08-13 13:29:58 +08:00
|
|
|
FillColour = colours.Yellow,
|
2019-11-06 15:07:05 +08:00
|
|
|
BackgroundColour = colours.YellowDarker.Opacity(0.5f),
|
2019-08-13 13:29:58 +08:00
|
|
|
OnSeek = musicController.SeekTo
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-02-09 18:46:57 +08:00
|
|
|
private void togglePlaylist()
|
|
|
|
{
|
|
|
|
if (playlist == null)
|
|
|
|
{
|
|
|
|
LoadComponentAsync(playlist = new PlaylistOverlay
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Y = player_height + 10,
|
|
|
|
}, _ =>
|
|
|
|
{
|
|
|
|
dragContainer.Add(playlist);
|
|
|
|
|
|
|
|
playlist.BeatmapSets.BindTo(musicController.BeatmapSets);
|
|
|
|
playlist.State.BindValueChanged(s => playlistButton.FadeColour(s.NewValue == Visibility.Visible ? colours.Yellow : Color4.White, 200, Easing.OutQuint), true);
|
|
|
|
|
|
|
|
togglePlaylist();
|
|
|
|
});
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!beatmap.Disabled)
|
|
|
|
playlist.ToggleVisibility();
|
|
|
|
}
|
|
|
|
|
2019-08-13 13:29:58 +08:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
beatmap.BindDisabledChanged(beatmapDisabledChanged, true);
|
|
|
|
|
|
|
|
musicController.TrackChanged += trackChanged;
|
|
|
|
trackChanged(beatmap.Value);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopIn()
|
|
|
|
{
|
|
|
|
base.PopIn();
|
|
|
|
|
|
|
|
this.FadeIn(transition_length, Easing.OutQuint);
|
|
|
|
dragContainer.ScaleTo(1, transition_length, Easing.OutElastic);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
{
|
|
|
|
base.PopOut();
|
|
|
|
|
|
|
|
this.FadeOut(transition_length, Easing.OutQuint);
|
|
|
|
dragContainer.ScaleTo(0.9f, transition_length, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
{
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
|
|
|
Height = dragContainer.Height;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
if (pendingBeatmapSwitch != null)
|
|
|
|
{
|
|
|
|
pendingBeatmapSwitch();
|
|
|
|
pendingBeatmapSwitch = null;
|
|
|
|
}
|
|
|
|
|
2020-08-11 12:53:23 +08:00
|
|
|
var track = musicController.CurrentTrack;
|
2020-08-05 20:10:38 +08:00
|
|
|
|
2020-08-11 23:48:38 +08:00
|
|
|
if (!track.IsDummyDevice)
|
2019-08-13 13:29:58 +08:00
|
|
|
{
|
2020-08-05 20:10:38 +08:00
|
|
|
progressBar.EndTime = track.Length;
|
|
|
|
progressBar.CurrentTime = track.CurrentTime;
|
2019-08-13 13:29:58 +08:00
|
|
|
|
2020-08-05 20:10:38 +08:00
|
|
|
playButton.Icon = track.IsRunning ? FontAwesome.Regular.PauseCircle : FontAwesome.Regular.PlayCircle;
|
2019-08-13 13:29:58 +08:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
progressBar.CurrentTime = 0;
|
|
|
|
progressBar.EndTime = 1;
|
|
|
|
playButton.Icon = FontAwesome.Regular.PlayCircle;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private Action pendingBeatmapSwitch;
|
|
|
|
|
|
|
|
private void trackChanged(WorkingBeatmap beatmap, TrackChangeDirection direction = TrackChangeDirection.None)
|
|
|
|
{
|
|
|
|
// avoid using scheduler as our scheduler may not be run for a long time, holding references to beatmaps.
|
|
|
|
pendingBeatmapSwitch = delegate
|
|
|
|
{
|
|
|
|
// todo: this can likely be replaced with WorkingBeatmap.GetBeatmapAsync()
|
|
|
|
Task.Run(() =>
|
|
|
|
{
|
2020-05-05 09:31:11 +08:00
|
|
|
if (beatmap?.Beatmap == null) // this is not needed if a placeholder exists
|
2019-08-13 13:29:58 +08:00
|
|
|
{
|
|
|
|
title.Text = @"Nothing to play";
|
|
|
|
artist.Text = @"Nothing to play";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
BeatmapMetadata metadata = beatmap.Metadata;
|
2021-02-25 13:12:59 +08:00
|
|
|
title.Text = new RomanisableString(metadata.TitleUnicode, metadata.Title);
|
|
|
|
artist.Text = new RomanisableString(metadata.ArtistUnicode, metadata.Artist);
|
2019-08-13 13:29:58 +08:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
LoadComponentAsync(new Background(beatmap) { Depth = float.MaxValue }, newBackground =>
|
|
|
|
{
|
|
|
|
switch (direction)
|
|
|
|
{
|
|
|
|
case TrackChangeDirection.Next:
|
|
|
|
newBackground.Position = new Vector2(400, 0);
|
|
|
|
newBackground.MoveToX(0, 500, Easing.OutCubic);
|
|
|
|
background.MoveToX(-400, 500, Easing.OutCubic);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case TrackChangeDirection.Prev:
|
|
|
|
newBackground.Position = new Vector2(-400, 0);
|
|
|
|
newBackground.MoveToX(0, 500, Easing.OutCubic);
|
|
|
|
background.MoveToX(400, 500, Easing.OutCubic);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
background.Expire();
|
|
|
|
background = newBackground;
|
|
|
|
|
|
|
|
playerContainer.Add(newBackground);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private void beatmapDisabledChanged(bool disabled)
|
|
|
|
{
|
|
|
|
if (disabled)
|
2021-02-09 18:46:57 +08:00
|
|
|
playlist?.Hide();
|
2019-08-13 13:29:58 +08:00
|
|
|
|
|
|
|
prevButton.Enabled.Value = !disabled;
|
|
|
|
nextButton.Enabled.Value = !disabled;
|
|
|
|
playlistButton.Enabled.Value = !disabled;
|
|
|
|
}
|
|
|
|
|
2019-08-13 14:04:04 +08:00
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (musicController != null)
|
|
|
|
musicController.TrackChanged -= trackChanged;
|
|
|
|
}
|
|
|
|
|
2019-08-13 13:29:58 +08:00
|
|
|
private class MusicIconButton : IconButton
|
|
|
|
{
|
|
|
|
public MusicIconButton()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
{
|
|
|
|
HoverColour = colours.YellowDark.Opacity(0.6f);
|
|
|
|
FlashColour = colours.Yellow;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
// works with AutoSizeAxes above to make buttons autosize with the scale animation.
|
|
|
|
Content.AutoSizeAxes = Axes.None;
|
|
|
|
Content.Size = new Vector2(DEFAULT_BUTTON_SIZE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class Background : BufferedContainer
|
|
|
|
{
|
|
|
|
private readonly Sprite sprite;
|
|
|
|
private readonly WorkingBeatmap beatmap;
|
|
|
|
|
|
|
|
public Background(WorkingBeatmap beatmap = null)
|
2021-11-05 14:54:27 +08:00
|
|
|
: base(cachedFrameBuffer: true)
|
2019-08-13 13:29:58 +08:00
|
|
|
{
|
|
|
|
this.beatmap = beatmap;
|
2019-09-04 18:38:12 +08:00
|
|
|
|
2019-08-13 13:29:58 +08:00
|
|
|
Depth = float.MaxValue;
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
sprite = new Sprite
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
Colour = OsuColour.Gray(150),
|
|
|
|
FillMode = FillMode.Fill,
|
|
|
|
},
|
|
|
|
new Box
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Height = bottom_black_area_height,
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
Colour = Color4.Black.Opacity(0.5f)
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
{
|
|
|
|
sprite.Texture = beatmap?.Background ?? textures.Get(@"Backgrounds/bg4");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private class DragContainer : Container
|
|
|
|
{
|
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
protected override void OnDrag(DragEvent e)
|
2019-08-13 13:29:58 +08:00
|
|
|
{
|
|
|
|
Vector2 change = e.MousePosition - e.MouseDownPosition;
|
|
|
|
|
|
|
|
// Diminish the drag distance as we go further to simulate "rubber band" feeling.
|
2019-11-25 07:45:42 +08:00
|
|
|
change *= change.Length <= 0 ? 0 : MathF.Pow(change.Length, 0.7f) / change.Length;
|
2019-08-13 13:29:58 +08:00
|
|
|
|
|
|
|
this.MoveTo(change);
|
|
|
|
}
|
|
|
|
|
2020-01-20 17:17:21 +08:00
|
|
|
protected override void OnDragEnd(DragEndEvent e)
|
2019-08-13 13:29:58 +08:00
|
|
|
{
|
|
|
|
this.MoveTo(Vector2.Zero, 800, Easing.OutElastic);
|
2020-01-20 17:17:21 +08:00
|
|
|
base.OnDragEnd(e);
|
2019-08-13 13:29:58 +08:00
|
|
|
}
|
|
|
|
}
|
2019-11-06 15:11:47 +08:00
|
|
|
|
|
|
|
private class HoverableProgressBar : ProgressBar
|
|
|
|
{
|
2021-01-18 15:46:48 +08:00
|
|
|
public HoverableProgressBar()
|
|
|
|
: base(true)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2019-11-06 15:11:47 +08:00
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
|
|
|
this.ResizeHeightTo(progress_height, 500, Easing.OutQuint);
|
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
|
|
|
this.ResizeHeightTo(progress_height / 2, 500, Easing.OutQuint);
|
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
}
|
2019-08-13 13:29:58 +08:00
|
|
|
}
|
|
|
|
}
|