2016-10-24 10:22:38 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
2016-10-24 13:00:06 +08:00
|
|
|
|
using System;
|
2016-10-24 13:47:05 +08:00
|
|
|
|
using System.Collections.Generic;
|
2016-11-06 00:46:09 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2016-10-24 13:00:06 +08:00
|
|
|
|
using OpenTK;
|
2016-10-24 10:50:49 +08:00
|
|
|
|
using OpenTK.Graphics;
|
2016-10-24 10:22:38 +08:00
|
|
|
|
using osu.Framework;
|
2016-10-24 15:34:44 +08:00
|
|
|
|
using osu.Framework.Audio.Track;
|
2016-10-28 19:39:02 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-10-24 10:50:49 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2016-10-24 10:22:38 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-10-24 10:50:49 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-10-24 13:13:49 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2016-10-24 15:34:44 +08:00
|
|
|
|
using osu.Framework.Graphics.Transformations;
|
2016-10-28 19:39:02 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2016-10-24 13:47:05 +08:00
|
|
|
|
using osu.Game.Database;
|
2016-10-24 13:00:06 +08:00
|
|
|
|
using osu.Game.Graphics;
|
2016-10-24 10:22:38 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
|
{
|
|
|
|
|
public class MusicController : OverlayContainer
|
|
|
|
|
{
|
2016-10-24 13:13:49 +08:00
|
|
|
|
private Sprite backgroundSprite;
|
2016-10-27 18:15:43 +08:00
|
|
|
|
private DragBar progress;
|
2016-10-24 17:19:48 +08:00
|
|
|
|
private TextAwesome playButton, listButton;
|
2016-10-24 13:00:06 +08:00
|
|
|
|
private SpriteText title, artist;
|
2016-10-27 18:15:43 +08:00
|
|
|
|
|
2016-10-28 20:34:22 +08:00
|
|
|
|
private TrackManager trackManager;
|
2016-10-24 13:47:05 +08:00
|
|
|
|
private List<BeatmapSetInfo> playList;
|
2016-10-27 16:58:40 +08:00
|
|
|
|
private BeatmapDatabase database;
|
2016-10-28 19:39:02 +08:00
|
|
|
|
private Bindable<WorkingBeatmap> beatmapSource;
|
2016-10-28 20:21:19 +08:00
|
|
|
|
private WorkingBeatmap current;
|
2016-10-27 16:58:40 +08:00
|
|
|
|
|
|
|
|
|
public MusicController(BeatmapDatabase db = null)
|
|
|
|
|
{
|
|
|
|
|
database = db;
|
2016-10-28 21:21:47 +08:00
|
|
|
|
Width = 400;
|
|
|
|
|
Height = 130;
|
|
|
|
|
CornerRadius = 5;
|
|
|
|
|
Masking = true;
|
|
|
|
|
Anchor = Anchor.TopRight;//placeholder
|
|
|
|
|
Origin = Anchor.TopRight;
|
2016-11-06 05:35:35 +08:00
|
|
|
|
Position = new Vector2(10, 60);
|
2016-10-24 10:50:49 +08:00
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = new Color4(0, 0, 0, 127)
|
|
|
|
|
},
|
2016-10-24 13:00:06 +08:00
|
|
|
|
title = new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Position = new Vector2(0, 40),
|
2016-11-06 01:53:10 +08:00
|
|
|
|
TextSize = 25,
|
2016-10-24 13:00:06 +08:00
|
|
|
|
Colour = Color4.White,
|
2016-11-06 01:50:38 +08:00
|
|
|
|
Text = @"Nothing to play",
|
|
|
|
|
Font = @"Exo2.0-MediumItalic"
|
2016-10-24 13:00:06 +08:00
|
|
|
|
},
|
|
|
|
|
artist = new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Position = new Vector2(0, 45),
|
2016-11-06 01:53:10 +08:00
|
|
|
|
TextSize = 15,
|
2016-10-24 13:00:06 +08:00
|
|
|
|
Colour = Color4.White,
|
2016-11-06 01:50:38 +08:00
|
|
|
|
Text = @"Nothing to play",
|
|
|
|
|
Font = @"Exo2.0-BoldItalic"
|
2016-10-24 13:00:06 +08:00
|
|
|
|
},
|
2016-10-24 10:50:49 +08:00
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 50,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Colour = new Color4(0, 0, 0, 127)
|
|
|
|
|
},
|
2016-10-24 17:19:48 +08:00
|
|
|
|
new ClickableContainer
|
2016-10-24 13:00:06 +08:00
|
|
|
|
{
|
2016-10-24 17:19:48 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2016-10-24 13:00:06 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2016-10-24 15:34:44 +08:00
|
|
|
|
Position = new Vector2(0, 30),
|
|
|
|
|
Action = () =>
|
|
|
|
|
{
|
2016-10-28 20:21:19 +08:00
|
|
|
|
if (current?.Track == null) return;
|
|
|
|
|
if (current.Track.IsRunning)
|
|
|
|
|
current.Track.Stop();
|
2016-10-24 15:34:44 +08:00
|
|
|
|
else
|
2016-10-28 20:21:19 +08:00
|
|
|
|
current.Track.Start();
|
2016-10-24 17:19:48 +08:00
|
|
|
|
},
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
playButton = new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
TextSize = 30,
|
|
|
|
|
Icon = FontAwesome.play_circle_o,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre
|
|
|
|
|
}
|
2016-10-24 15:34:44 +08:00
|
|
|
|
}
|
2016-10-24 13:00:06 +08:00
|
|
|
|
},
|
2016-10-24 17:19:48 +08:00
|
|
|
|
new ClickableContainer
|
2016-10-24 13:00:06 +08:00
|
|
|
|
{
|
2016-10-24 17:19:48 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2016-10-24 13:00:06 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2016-10-24 15:34:44 +08:00
|
|
|
|
Position = new Vector2(-30, 30),
|
2016-10-24 17:19:48 +08:00
|
|
|
|
Action = prev,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
TextSize = 15,
|
|
|
|
|
Icon = FontAwesome.step_backward,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-24 13:00:06 +08:00
|
|
|
|
},
|
2016-10-24 17:19:48 +08:00
|
|
|
|
new ClickableContainer
|
2016-10-24 13:00:06 +08:00
|
|
|
|
{
|
2016-10-24 17:19:48 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2016-10-24 13:00:06 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2016-10-24 15:34:44 +08:00
|
|
|
|
Position = new Vector2(30, 30),
|
2016-10-24 17:19:48 +08:00
|
|
|
|
Action = next,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
TextSize = 15,
|
|
|
|
|
Icon = FontAwesome.step_forward,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-24 13:00:06 +08:00
|
|
|
|
},
|
2016-10-24 17:19:48 +08:00
|
|
|
|
new ClickableContainer
|
2016-10-24 13:00:06 +08:00
|
|
|
|
{
|
2016-10-24 17:19:48 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2016-10-24 13:00:06 +08:00
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.BottomRight,
|
2016-10-24 17:19:48 +08:00
|
|
|
|
Position = new Vector2(20, 30),
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
listButton = new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
TextSize = 15,
|
|
|
|
|
Icon = FontAwesome.bars,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre
|
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-24 13:00:06 +08:00
|
|
|
|
},
|
2016-10-27 18:15:43 +08:00
|
|
|
|
progress = new DragBar
|
2016-10-24 10:50:49 +08:00
|
|
|
|
{
|
2016-10-27 18:15:43 +08:00
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Anchor = Anchor.BottomCentre,
|
2016-10-24 10:50:49 +08:00
|
|
|
|
Height = 10,
|
2016-10-27 18:15:43 +08:00
|
|
|
|
Colour = Color4.Orange,
|
|
|
|
|
SeekRequested = seek
|
2016-10-24 10:50:49 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
2016-10-24 15:34:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-06 00:24:03 +08:00
|
|
|
|
protected override void Load(BaseGame game)
|
|
|
|
|
{
|
|
|
|
|
base.Load(game);
|
|
|
|
|
var osuGame = game as OsuGameBase;
|
|
|
|
|
|
|
|
|
|
if (osuGame != null)
|
|
|
|
|
{
|
|
|
|
|
if (database == null) database = osuGame.Beatmaps;
|
|
|
|
|
trackManager = osuGame.Audio.Track;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
beatmapSource = osuGame?.Beatmap ?? new Bindable<WorkingBeatmap>();
|
|
|
|
|
beatmapSource.ValueChanged += workingChanged;
|
|
|
|
|
playList = database.GetAllWithChildren<BeatmapSetInfo>();
|
|
|
|
|
|
|
|
|
|
backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4"));
|
|
|
|
|
AddInternal(backgroundSprite);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-06 00:46:09 +08:00
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
workingChanged();
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 17:23:30 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
2016-10-28 20:21:19 +08:00
|
|
|
|
if (current?.Track == null) return;
|
2016-10-28 20:44:59 +08:00
|
|
|
|
|
2016-10-28 20:21:19 +08:00
|
|
|
|
progress.UpdatePosition((float)(current.Track.CurrentTime / current.Track.Length));
|
2016-10-28 20:44:59 +08:00
|
|
|
|
playButton.Icon = current.Track.IsRunning ? FontAwesome.pause : FontAwesome.play_circle_o;
|
|
|
|
|
|
2016-10-28 20:21:19 +08:00
|
|
|
|
if (current.Track.HasCompleted) next();
|
2016-10-24 17:23:30 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 20:44:59 +08:00
|
|
|
|
private void workingChanged(object sender = null, EventArgs e = null)
|
|
|
|
|
{
|
|
|
|
|
if (beatmapSource.Value == current) return;
|
2016-10-28 21:57:23 +08:00
|
|
|
|
current = beatmapSource.Value;
|
2016-10-28 20:44:59 +08:00
|
|
|
|
updateCurrent(current, null);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 20:08:27 +08:00
|
|
|
|
private int findInPlaylist(Beatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
if (beatmap == null) return -1;
|
|
|
|
|
for (int i = 0; i < playList.Count; i++)
|
|
|
|
|
if (beatmap.BeatmapInfo.BeatmapSetID == playList[i].BeatmapSetID)
|
|
|
|
|
return i;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 15:34:44 +08:00
|
|
|
|
private void prev()
|
|
|
|
|
{
|
2016-10-28 20:21:19 +08:00
|
|
|
|
int i = findInPlaylist(current?.Beatmap);
|
2016-10-28 21:57:23 +08:00
|
|
|
|
if (i == -1)
|
|
|
|
|
{
|
|
|
|
|
if (playList.Count > 0)
|
|
|
|
|
play(playList[0].Beatmaps[0], null);
|
|
|
|
|
else return;
|
|
|
|
|
}
|
2016-10-24 15:34:44 +08:00
|
|
|
|
i = (i - 1 + playList.Count) % playList.Count;
|
2016-10-28 20:08:27 +08:00
|
|
|
|
play(playList[i].Beatmaps[0], false);
|
2016-10-24 15:34:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void next()
|
|
|
|
|
{
|
2016-10-28 20:21:19 +08:00
|
|
|
|
int i = findInPlaylist(current?.Beatmap);
|
2016-10-28 21:57:23 +08:00
|
|
|
|
if (i == -1)
|
|
|
|
|
{
|
|
|
|
|
if (playList.Count > 0)
|
|
|
|
|
play(playList[0].Beatmaps[0], null);
|
|
|
|
|
else return;
|
|
|
|
|
}
|
2016-10-24 15:34:44 +08:00
|
|
|
|
i = (i + 1) % playList.Count;
|
2016-10-28 20:08:27 +08:00
|
|
|
|
play(playList[i].Beatmaps[0], true);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void play(BeatmapInfo info, bool? isNext)
|
|
|
|
|
{
|
2016-10-28 20:21:19 +08:00
|
|
|
|
current = database.GetWorkingBeatmap(info, current);
|
2016-11-06 00:46:09 +08:00
|
|
|
|
Task.Factory.StartNew(() =>
|
|
|
|
|
{
|
|
|
|
|
trackManager.SetExclusive(current.Track);
|
|
|
|
|
current.Track.Start();
|
|
|
|
|
beatmapSource.Value = current;
|
|
|
|
|
updateCurrent(current, isNext);
|
|
|
|
|
});
|
2016-10-24 15:34:44 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 19:39:02 +08:00
|
|
|
|
private void updateCurrent(WorkingBeatmap beatmap, bool? isNext)
|
2016-10-24 15:34:44 +08:00
|
|
|
|
{
|
2016-10-28 19:39:02 +08:00
|
|
|
|
BeatmapMetadata metadata = beatmap.Beatmap.Metadata;
|
2016-10-24 17:19:48 +08:00
|
|
|
|
title.Text = metadata.TitleUnicode ?? metadata.Title;
|
|
|
|
|
artist.Text = metadata.ArtistUnicode ?? metadata.Artist;
|
2016-10-27 17:04:41 +08:00
|
|
|
|
|
2016-11-06 00:13:45 +08:00
|
|
|
|
Sprite newBackground = getScaledSprite(beatmap.Background);
|
2016-10-27 17:04:41 +08:00
|
|
|
|
|
2016-10-24 15:34:44 +08:00
|
|
|
|
Add(newBackground);
|
2016-10-27 17:04:41 +08:00
|
|
|
|
|
2016-10-24 15:34:44 +08:00
|
|
|
|
if (isNext == true)
|
|
|
|
|
{
|
|
|
|
|
newBackground.Position = new Vector2(400, 0);
|
2016-10-24 18:18:54 +08:00
|
|
|
|
newBackground.MoveToX(0, 500, EasingTypes.OutCubic);
|
|
|
|
|
backgroundSprite.MoveToX(-400, 500, EasingTypes.OutCubic);
|
2016-10-24 15:34:44 +08:00
|
|
|
|
backgroundSprite.Expire();
|
|
|
|
|
}
|
|
|
|
|
else if (isNext == false)
|
|
|
|
|
{
|
|
|
|
|
newBackground.Position = new Vector2(-400, 0);
|
2016-10-24 18:18:54 +08:00
|
|
|
|
newBackground.MoveToX(0, 500, EasingTypes.OutCubic);
|
|
|
|
|
backgroundSprite.MoveToX(400, 500, EasingTypes.OutCubic);
|
2016-10-24 15:34:44 +08:00
|
|
|
|
backgroundSprite.Expire();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Remove(backgroundSprite);
|
|
|
|
|
}
|
2016-10-27 17:04:41 +08:00
|
|
|
|
|
2016-10-24 18:18:54 +08:00
|
|
|
|
backgroundSprite = newBackground;
|
2016-10-24 10:22:38 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-24 13:13:49 +08:00
|
|
|
|
private Sprite getScaledSprite(Texture background)
|
|
|
|
|
{
|
|
|
|
|
Sprite scaledSprite = new Sprite
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Texture = background,
|
|
|
|
|
Depth = float.MinValue
|
|
|
|
|
};
|
|
|
|
|
scaledSprite.Scale = new Vector2(Math.Max(DrawSize.X / scaledSprite.DrawSize.X, DrawSize.Y / scaledSprite.DrawSize.Y));
|
|
|
|
|
return scaledSprite;
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-27 19:51:38 +08:00
|
|
|
|
private void seek(float position)
|
|
|
|
|
{
|
2016-10-28 20:21:19 +08:00
|
|
|
|
current?.Track?.Seek(current.Track.Length * position);
|
|
|
|
|
current?.Track?.Start();
|
2016-10-27 19:51:38 +08:00
|
|
|
|
}
|
2016-10-25 09:18:47 +08:00
|
|
|
|
|
2016-10-24 10:22:38 +08:00
|
|
|
|
//placeholder for toggling
|
2016-11-06 05:35:35 +08:00
|
|
|
|
protected override void PopIn() => FadeIn(100);
|
2016-10-24 10:22:38 +08:00
|
|
|
|
|
2016-11-06 05:35:35 +08:00
|
|
|
|
protected override void PopOut() => FadeOut(100);
|
2016-10-24 10:22:38 +08:00
|
|
|
|
}
|
|
|
|
|
}
|