2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
using System;
|
2018-05-14 16:41:35 +08:00
|
|
|
|
using System.Collections.Generic;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 13:51:28 +08:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2018-10-02 11:02:47 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
|
|
|
|
using osu.Framework.Threading;
|
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Overlays.Music;
|
2019-04-08 18:16:34 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class MusicController : OsuFocusedOverlayContainer
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2018-05-23 16:37:39 +08:00
|
|
|
|
private BeatmapManager beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-05-14 16:41:35 +08:00
|
|
|
|
private List<BeatmapSetInfo> beatmapSets;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
private Container dragContainer;
|
|
|
|
|
private Container playerContainer;
|
|
|
|
|
|
2019-04-08 18:16:34 +08:00
|
|
|
|
[Resolved]
|
|
|
|
|
private Bindable<WorkingBeatmap> beatmap { get; set; }
|
|
|
|
|
|
|
|
|
|
[Resolved]
|
2019-04-10 16:13:12 +08:00
|
|
|
|
private IBindable<IReadOnlyList<Mod>> mods { get; set; }
|
2018-05-23 16:37:39 +08:00
|
|
|
|
|
2019-03-28 11:27:26 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Provide a source for the toolbar height.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public Func<float> GetToolbarHeight;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
public MusicController()
|
|
|
|
|
{
|
|
|
|
|
Width = 400;
|
|
|
|
|
Margin = new MarginPadding(10);
|
|
|
|
|
|
|
|
|
|
// required to let MusicController handle beatmap cycling.
|
|
|
|
|
AlwaysPresent = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-02-01 14:42:15 +08:00
|
|
|
|
private void load(Bindable<WorkingBeatmap> beatmap, BeatmapManager beatmaps, OsuColour colours)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-05-14 16:41:35 +08:00
|
|
|
|
this.beatmaps = beatmaps;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
2018-06-15 15:12:11 +08:00
|
|
|
|
dragContainer = new DragContainer
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
playlist = new PlaylistOverlay
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Y = player_height + 10,
|
2018-05-14 16:41:35 +08:00
|
|
|
|
OrderChanged = playlistOrderChanged
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
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),
|
2019-02-20 15:52:36 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 25, italics: true),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Colour = Color4.White,
|
|
|
|
|
Text = @"Nothing to play",
|
|
|
|
|
},
|
|
|
|
|
artist = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Position = new Vector2(0, 45),
|
2019-02-12 12:04:46 +08:00
|
|
|
|
Font = OsuFont.GetFont(size: 15, weight: FontWeight.Bold, italics: true),
|
2018-04-13 17:19:50 +08:00
|
|
|
|
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[]
|
|
|
|
|
{
|
2018-07-13 15:28:18 +08:00
|
|
|
|
prevButton = new MusicIconButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Action = prev,
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.StepBackward,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2018-07-13 15:28:18 +08:00
|
|
|
|
playButton = new MusicIconButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Scale = new Vector2(1.4f),
|
|
|
|
|
IconScale = new Vector2(1.4f),
|
|
|
|
|
Action = play,
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Regular.PlayCircle,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
2018-07-13 15:28:18 +08:00
|
|
|
|
nextButton = new MusicIconButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
2018-05-14 16:41:35 +08:00
|
|
|
|
Action = () => next(),
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.StepForward,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
2018-07-13 15:28:18 +08:00
|
|
|
|
playlistButton = new MusicIconButton
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Position = new Vector2(-bottom_black_area_height / 2, 0),
|
2019-04-02 18:55:24 +08:00
|
|
|
|
Icon = FontAwesome.Solid.Bars,
|
2018-04-13 17:19:50 +08:00
|
|
|
|
Action = () => playlist.ToggleVisibility(),
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
progressBar = new ProgressBar
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Height = progress_height,
|
|
|
|
|
FillColour = colours.Yellow,
|
2018-07-05 03:09:28 +08:00
|
|
|
|
OnSeek = attemptSeek
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2018-05-14 16:41:35 +08:00
|
|
|
|
beatmapSets = beatmaps.GetAllUsableBeatmapSets();
|
|
|
|
|
beatmaps.ItemAdded += handleBeatmapAdded;
|
|
|
|
|
beatmaps.ItemRemoved += handleBeatmapRemoved;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
playlist.StateChanged += s => playlistButton.FadeColour(s == Visibility.Visible ? colours.Yellow : Color4.White, 200, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-09 15:50:29 +08:00
|
|
|
|
private ScheduledDelegate seekDelegate;
|
|
|
|
|
|
2018-07-05 03:09:28 +08:00
|
|
|
|
private void attemptSeek(double progress)
|
2018-05-10 16:15:47 +08:00
|
|
|
|
{
|
2018-10-09 15:50:29 +08:00
|
|
|
|
seekDelegate?.Cancel();
|
|
|
|
|
seekDelegate = Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
if (!beatmap.Disabled)
|
|
|
|
|
current?.Track.Seek(progress);
|
|
|
|
|
});
|
2018-05-10 16:15:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 16:41:35 +08:00
|
|
|
|
private void playlistOrderChanged(BeatmapSetInfo beatmapSetInfo, int index)
|
|
|
|
|
{
|
|
|
|
|
beatmapSets.Remove(beatmapSetInfo);
|
|
|
|
|
beatmapSets.Insert(index, beatmapSetInfo);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-25 17:24:06 +08:00
|
|
|
|
private void handleBeatmapAdded(BeatmapSetInfo obj, bool existing)
|
2018-11-28 19:19:21 +08:00
|
|
|
|
{
|
|
|
|
|
if (existing)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
Schedule(() => beatmapSets.Add(obj));
|
|
|
|
|
}
|
|
|
|
|
|
2018-11-20 17:09:23 +08:00
|
|
|
|
private void handleBeatmapRemoved(BeatmapSetInfo obj) => Schedule(() => beatmapSets.RemoveAll(s => s.ID == obj.ID));
|
2018-05-14 16:41:35 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
2018-06-07 15:46:54 +08:00
|
|
|
|
beatmap.BindValueChanged(beatmapChanged, true);
|
|
|
|
|
beatmap.BindDisabledChanged(beatmapDisabledChanged, true);
|
2019-04-10 11:03:57 +08:00
|
|
|
|
mods.BindValueChanged(_ => updateAudioAdjustments(), true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
base.LoadComplete();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void beatmapDisabledChanged(bool disabled)
|
|
|
|
|
{
|
|
|
|
|
if (disabled)
|
|
|
|
|
playlist.Hide();
|
|
|
|
|
|
2018-05-12 17:55:52 +08:00
|
|
|
|
playButton.Enabled.Value = !disabled;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
prevButton.Enabled.Value = !disabled;
|
|
|
|
|
nextButton.Enabled.Value = !disabled;
|
|
|
|
|
playlistButton.Enabled.Value = !disabled;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void UpdateAfterChildren()
|
|
|
|
|
{
|
|
|
|
|
base.UpdateAfterChildren();
|
|
|
|
|
Height = dragContainer.Height;
|
2019-03-28 11:27:26 +08:00
|
|
|
|
|
|
|
|
|
dragContainer.Padding = new MarginPadding { Top = GetToolbarHeight?.Invoke() ?? 0 };
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2018-11-14 11:05:07 +08:00
|
|
|
|
var track = current?.TrackLoaded ?? false ? current.Track : null;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2018-11-14 10:53:34 +08:00
|
|
|
|
if (track?.IsDummyDevice == false)
|
2018-11-03 07:04:30 +08:00
|
|
|
|
{
|
2018-04-13 17:19:50 +08:00
|
|
|
|
progressBar.EndTime = track.Length;
|
|
|
|
|
progressBar.CurrentTime = track.CurrentTime;
|
|
|
|
|
|
2019-04-02 18:55:24 +08:00
|
|
|
|
playButton.Icon = track.IsRunning ? FontAwesome.Regular.PauseCircle : FontAwesome.Regular.PlayCircle;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
2018-11-03 07:04:30 +08:00
|
|
|
|
{
|
|
|
|
|
progressBar.CurrentTime = 0;
|
|
|
|
|
progressBar.EndTime = 1;
|
2019-04-02 18:55:24 +08:00
|
|
|
|
playButton.Icon = FontAwesome.Regular.PlayCircle;
|
2018-11-03 07:04:30 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void play()
|
|
|
|
|
{
|
|
|
|
|
var track = current?.Track;
|
|
|
|
|
|
|
|
|
|
if (track == null)
|
|
|
|
|
{
|
2018-05-23 16:37:39 +08:00
|
|
|
|
if (!beatmap.Disabled)
|
2018-05-14 16:41:35 +08:00
|
|
|
|
next(true);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (track.IsRunning)
|
|
|
|
|
track.Stop();
|
|
|
|
|
else
|
|
|
|
|
track.Start();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void prev()
|
|
|
|
|
{
|
|
|
|
|
queuedDirection = TransformDirection.Prev;
|
2018-05-14 16:41:35 +08:00
|
|
|
|
|
|
|
|
|
var playable = beatmapSets.TakeWhile(i => i.ID != current.BeatmapSetInfo.ID).LastOrDefault() ?? beatmapSets.LastOrDefault();
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-05-14 16:41:35 +08:00
|
|
|
|
if (playable != null)
|
2018-05-14 16:45:11 +08:00
|
|
|
|
{
|
2018-05-23 16:37:39 +08:00
|
|
|
|
beatmap.Value = beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value);
|
|
|
|
|
beatmap.Value.Track.Restart();
|
2018-05-14 16:45:11 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2018-05-14 16:41:35 +08:00
|
|
|
|
private void next(bool instant = false)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-05-14 16:47:38 +08:00
|
|
|
|
if (!instant)
|
|
|
|
|
queuedDirection = TransformDirection.Next;
|
2018-05-14 16:41:35 +08:00
|
|
|
|
|
|
|
|
|
var playable = beatmapSets.SkipWhile(i => i.ID != current.BeatmapSetInfo.ID).Skip(1).FirstOrDefault() ?? beatmapSets.FirstOrDefault();
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-05-14 16:41:35 +08:00
|
|
|
|
if (playable != null)
|
2018-05-14 16:45:11 +08:00
|
|
|
|
{
|
2018-05-23 16:37:39 +08:00
|
|
|
|
beatmap.Value = beatmaps.GetWorkingBeatmap(playable.Beatmaps.First(), beatmap.Value);
|
|
|
|
|
beatmap.Value.Track.Restart();
|
2018-05-14 16:45:11 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private WorkingBeatmap current;
|
|
|
|
|
private TransformDirection? queuedDirection;
|
|
|
|
|
|
2019-02-25 18:29:09 +08:00
|
|
|
|
private void beatmapChanged(ValueChangedEvent<WorkingBeatmap> beatmap)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
|
|
|
|
TransformDirection direction = TransformDirection.None;
|
|
|
|
|
|
|
|
|
|
if (current != null)
|
|
|
|
|
{
|
2019-02-25 18:29:09 +08:00
|
|
|
|
bool audioEquals = beatmap.NewValue?.BeatmapInfo?.AudioEquals(current.BeatmapInfo) ?? false;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
if (audioEquals)
|
|
|
|
|
direction = TransformDirection.None;
|
|
|
|
|
else if (queuedDirection.HasValue)
|
|
|
|
|
{
|
|
|
|
|
direction = queuedDirection.Value;
|
|
|
|
|
queuedDirection = null;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
//figure out the best direction based on order in playlist.
|
2018-05-14 16:41:35 +08:00
|
|
|
|
var last = beatmapSets.TakeWhile(b => b.ID != current.BeatmapSetInfo?.ID).Count();
|
2019-02-25 18:34:03 +08:00
|
|
|
|
var next = beatmap.NewValue == null ? -1 : beatmapSets.TakeWhile(b => b.ID != beatmap.NewValue.BeatmapSetInfo?.ID).Count();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
direction = last > next ? TransformDirection.Prev : TransformDirection.Next;
|
|
|
|
|
}
|
2018-11-17 20:39:40 +08:00
|
|
|
|
|
|
|
|
|
current.Track.Completed -= currentTrackCompleted;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-02-25 18:29:09 +08:00
|
|
|
|
current = beatmap.NewValue;
|
|
|
|
|
|
2018-11-17 20:39:40 +08:00
|
|
|
|
if (current != null)
|
|
|
|
|
current.Track.Completed += currentTrackCompleted;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
progressBar.CurrentTime = 0;
|
|
|
|
|
|
|
|
|
|
updateDisplay(current, direction);
|
2019-04-08 18:16:34 +08:00
|
|
|
|
updateAudioAdjustments();
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
|
|
queuedDirection = null;
|
|
|
|
|
}
|
|
|
|
|
|
2019-04-08 18:16:34 +08:00
|
|
|
|
private void updateAudioAdjustments()
|
|
|
|
|
{
|
|
|
|
|
var track = current?.Track;
|
|
|
|
|
if (track == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
track.ResetSpeedAdjustments();
|
|
|
|
|
|
2019-04-10 11:03:57 +08:00
|
|
|
|
foreach (var mod in mods.Value.OfType<IApplicableToClock>())
|
2019-04-08 18:16:34 +08:00
|
|
|
|
mod.ApplyToClock(track);
|
|
|
|
|
}
|
|
|
|
|
|
2019-02-27 15:52:34 +08:00
|
|
|
|
private void currentTrackCompleted() => Schedule(() =>
|
2018-11-17 20:39:40 +08:00
|
|
|
|
{
|
2019-02-27 16:03:09 +08:00
|
|
|
|
if (!current.Track.Looping && !beatmap.Disabled && beatmapSets.Any())
|
2018-11-17 20:39:40 +08:00
|
|
|
|
next();
|
2019-02-27 15:52:34 +08:00
|
|
|
|
});
|
2018-11-17 20:39:40 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private ScheduledDelegate pendingBeatmapSwitch;
|
|
|
|
|
|
|
|
|
|
private void updateDisplay(WorkingBeatmap beatmap, TransformDirection direction)
|
|
|
|
|
{
|
|
|
|
|
//we might be off-screen when this update comes in.
|
|
|
|
|
//rather than Scheduling, manually handle this to avoid possible memory contention.
|
|
|
|
|
pendingBeatmapSwitch?.Cancel();
|
|
|
|
|
|
|
|
|
|
pendingBeatmapSwitch = Schedule(delegate
|
|
|
|
|
{
|
|
|
|
|
// todo: this can likely be replaced with WorkingBeatmap.GetBeatmapAsync()
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
if (beatmap?.Beatmap == null) //this is not needed if a placeholder exists
|
|
|
|
|
{
|
|
|
|
|
title.Text = @"Nothing to play";
|
|
|
|
|
artist.Text = @"Nothing to play";
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
BeatmapMetadata metadata = beatmap.Metadata;
|
2018-09-19 13:07:46 +08:00
|
|
|
|
title.Text = new LocalisedString((metadata.TitleUnicode, metadata.Title));
|
|
|
|
|
artist.Text = new LocalisedString((metadata.ArtistUnicode, metadata.Artist));
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
LoadComponentAsync(new Background(beatmap) { Depth = float.MaxValue }, newBackground =>
|
|
|
|
|
{
|
|
|
|
|
switch (direction)
|
|
|
|
|
{
|
|
|
|
|
case TransformDirection.Next:
|
|
|
|
|
newBackground.Position = new Vector2(400, 0);
|
|
|
|
|
newBackground.MoveToX(0, 500, Easing.OutCubic);
|
|
|
|
|
background.MoveToX(-400, 500, Easing.OutCubic);
|
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
case TransformDirection.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);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
|
2018-11-22 18:21:32 +08:00
|
|
|
|
// This is here mostly as a performance fix.
|
|
|
|
|
// If the playlist is not hidden it will update children even when the music controller is hidden (due to AlwaysPresent).
|
2018-11-22 11:12:34 +08:00
|
|
|
|
playlist.State = Visibility.Hidden;
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
this.FadeOut(transition_length, Easing.OutQuint);
|
|
|
|
|
dragContainer.ScaleTo(0.9f, transition_length, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private enum TransformDirection
|
|
|
|
|
{
|
|
|
|
|
None,
|
|
|
|
|
Next,
|
|
|
|
|
Prev
|
|
|
|
|
}
|
|
|
|
|
|
2018-07-13 15:28:18 +08:00
|
|
|
|
private class MusicIconButton : IconButton
|
|
|
|
|
{
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
|
|
|
|
{
|
|
|
|
|
HoverColour = colours.YellowDark.Opacity(0.6f);
|
|
|
|
|
FlashColour = colours.Yellow;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-13 17:19:50 +08:00
|
|
|
|
private class Background : BufferedContainer
|
|
|
|
|
{
|
|
|
|
|
private readonly Sprite sprite;
|
|
|
|
|
private readonly WorkingBeatmap beatmap;
|
|
|
|
|
|
|
|
|
|
public Background(WorkingBeatmap beatmap = null)
|
|
|
|
|
{
|
|
|
|
|
this.beatmap = beatmap;
|
|
|
|
|
CacheDrawnFrameBuffer = true;
|
|
|
|
|
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]
|
2018-08-31 06:04:40 +08:00
|
|
|
|
private void load(TextureStore textures)
|
2018-04-13 17:19:50 +08:00
|
|
|
|
{
|
2018-08-31 06:04:40 +08:00
|
|
|
|
sprite.Texture = beatmap?.Background ?? textures.Get(@"Backgrounds/bg4");
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-06-15 15:12:11 +08:00
|
|
|
|
|
|
|
|
|
private class DragContainer : Container
|
|
|
|
|
{
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnDragStart(DragStartEvent e)
|
2018-06-15 15:12:11 +08:00
|
|
|
|
{
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnDrag(DragEvent e)
|
2018-06-15 15:12:11 +08:00
|
|
|
|
{
|
2018-09-19 19:52:57 +08:00
|
|
|
|
Vector2 change = e.MousePosition - e.MouseDownPosition;
|
2018-06-15 15:12:11 +08:00
|
|
|
|
|
|
|
|
|
// Diminish the drag distance as we go further to simulate "rubber band" feeling.
|
|
|
|
|
change *= change.Length <= 0 ? 0 : (float)Math.Pow(change.Length, 0.7f) / change.Length;
|
|
|
|
|
|
|
|
|
|
this.MoveTo(change);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 11:02:47 +08:00
|
|
|
|
protected override bool OnDragEnd(DragEndEvent e)
|
2018-06-15 15:12:11 +08:00
|
|
|
|
{
|
|
|
|
|
this.MoveTo(Vector2.Zero, 800, Easing.OutElastic);
|
2018-10-02 11:02:47 +08:00
|
|
|
|
return base.OnDragEnd(e);
|
2018-06-15 15:12:11 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
}
|
|
|
|
|
}
|