mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 06:42:56 +08:00
Refactoring part 2.
This commit is contained in:
parent
37944bb04e
commit
7c2e193db1
@ -4,12 +4,14 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Configuration;
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Primitives;
|
using osu.Framework.Graphics.Primitives;
|
||||||
using osu.Framework.Graphics.Sprites;
|
using osu.Framework.Graphics.Sprites;
|
||||||
using osu.Framework.Graphics.UserInterface;
|
using osu.Framework.Graphics.UserInterface;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Database;
|
using osu.Game.Database;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
@ -26,25 +28,17 @@ namespace osu.Game.Overlays.Music
|
|||||||
|
|
||||||
private const float playlist_height = 510;
|
private const float playlist_height = 510;
|
||||||
|
|
||||||
private readonly Box bg;
|
private FilterControl filter;
|
||||||
private readonly FilterControl filter;
|
private Playlist list;
|
||||||
private readonly Playlist list;
|
|
||||||
|
|
||||||
public BeatmapSetInfo[] List => list.Sets;
|
public BeatmapSetInfo[] List => list.Sets;
|
||||||
|
|
||||||
public Action<BeatmapSetInfo, int> OnSelect
|
private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
|
||||||
{
|
|
||||||
get { return list.OnSelect; }
|
|
||||||
set { list.OnSelect = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public BeatmapSetInfo Current
|
public Action<BeatmapSetInfo, int> OnSelect;
|
||||||
{
|
|
||||||
get { return list.Current; }
|
|
||||||
set { list.Current = value; }
|
|
||||||
}
|
|
||||||
|
|
||||||
public PlaylistController()
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuGameBase game, OsuColour colours, BeatmapDatabase beatmaps)
|
||||||
{
|
{
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -61,8 +55,9 @@ namespace osu.Game.Overlays.Music
|
|||||||
},
|
},
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
bg = new Box
|
new Box
|
||||||
{
|
{
|
||||||
|
Colour = colours.Gray3,
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
},
|
},
|
||||||
list = new Playlist
|
list = new Playlist
|
||||||
@ -80,15 +75,17 @@ namespace osu.Game.Overlays.Music
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
filter.Search.Exit = Hide;
|
list.Sets = beatmaps.GetAllWithChildren<BeatmapSetInfo>().ToArray();
|
||||||
//todo: play the first displayed song on commit when searching is implemented
|
list.OnSelect = (beatmap, index) => OnSelect?.Invoke(beatmap, index);
|
||||||
|
|
||||||
|
beatmapBacking.BindTo(game.Beatmap);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
protected override void LoadComplete()
|
||||||
private void load(OsuColour colours, BeatmapDatabase beatmaps)
|
|
||||||
{
|
{
|
||||||
bg.Colour = colours.Gray3;
|
base.LoadComplete();
|
||||||
list.Sets = beatmaps.GetAllWithChildren<BeatmapSetInfo>().ToArray();
|
beatmapBacking.ValueChanged += b => list.Current = b?.BeatmapSetInfo;
|
||||||
|
beatmapBacking.TriggerChange();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn()
|
||||||
|
@ -32,6 +32,12 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
private const float player_height = 130;
|
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 currentBackground;
|
private Drawable currentBackground;
|
||||||
private DragBar progress;
|
private DragBar progress;
|
||||||
private Button playButton;
|
private Button playButton;
|
||||||
@ -44,18 +50,13 @@ namespace osu.Game.Overlays
|
|||||||
private int playListIndex = -1;
|
private int playListIndex = -1;
|
||||||
|
|
||||||
private TrackManager trackManager;
|
private TrackManager trackManager;
|
||||||
private Bindable<WorkingBeatmap> beatmapSource;
|
private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
|
||||||
private WorkingBeatmap current;
|
|
||||||
private BeatmapDatabase beatmaps;
|
private BeatmapDatabase beatmaps;
|
||||||
private LocalisationEngine localisation;
|
private LocalisationEngine localisation;
|
||||||
|
|
||||||
private Container dragContainer;
|
private Container dragContainer;
|
||||||
private Container playerContainer;
|
private Container playerContainer;
|
||||||
|
|
||||||
private const float progress_height = 10;
|
|
||||||
|
|
||||||
private const float bottom_black_area_height = 55;
|
|
||||||
|
|
||||||
public MusicController()
|
public MusicController()
|
||||||
{
|
{
|
||||||
Width = 400;
|
Width = 400;
|
||||||
@ -109,7 +110,7 @@ namespace osu.Game.Overlays
|
|||||||
current?.Track?.Seek(0);
|
current?.Track?.Seek(0);
|
||||||
|
|
||||||
playListIndex = index;
|
playListIndex = index;
|
||||||
play(set.Beatmaps[0], true);
|
playSpecified(set.Beatmaps[0], true);
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
playerContainer = new Container
|
playerContainer = new Container
|
||||||
@ -173,20 +174,8 @@ namespace osu.Game.Overlays
|
|||||||
{
|
{
|
||||||
Scale = new Vector2(1.4f),
|
Scale = new Vector2(1.4f),
|
||||||
IconScale = new Vector2(1.4f),
|
IconScale = new Vector2(1.4f),
|
||||||
Action = () =>
|
Action = play
|
||||||
{
|
,
|
||||||
if (current?.Track == null)
|
|
||||||
{
|
|
||||||
if (playList.Count > 0)
|
|
||||||
play(playList.First().Beatmaps[0], true);
|
|
||||||
else
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (current?.Track?.IsRunning ?? false)
|
|
||||||
current?.Track?.Stop();
|
|
||||||
else
|
|
||||||
current?.Track?.Start();
|
|
||||||
},
|
|
||||||
Icon = FontAwesome.fa_play_circle_o,
|
Icon = FontAwesome.fa_play_circle_o,
|
||||||
},
|
},
|
||||||
new Button
|
new Button
|
||||||
@ -224,17 +213,40 @@ namespace osu.Game.Overlays
|
|||||||
trackManager = game.Audio.Track;
|
trackManager = game.Audio.Track;
|
||||||
this.localisation = localisation;
|
this.localisation = localisation;
|
||||||
|
|
||||||
beatmapSource = game.Beatmap ?? new Bindable<WorkingBeatmap>();
|
beatmapBacking.BindTo(game.Beatmap);
|
||||||
|
|
||||||
currentBackground = new MusicControllerBackground();
|
currentBackground = new MusicControllerBackground();
|
||||||
playerContainer.Add(currentBackground);
|
playerContainer.Add(currentBackground);
|
||||||
playlist.StateChanged += (c, s) => playlistButton.FadeColour(s == Visibility.Visible? activeColour : Color4.White, 200, EasingTypes.OutQuint);
|
playlist.StateChanged += (c, s) => playlistButton.FadeColour(s == Visibility.Visible ? activeColour : Color4.White, 200, EasingTypes.OutQuint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void play()
|
||||||
|
{
|
||||||
|
var track = current?.Track;
|
||||||
|
|
||||||
|
if (track == null)
|
||||||
|
{
|
||||||
|
if (playList.Count > 0)
|
||||||
|
{
|
||||||
|
playSpecified(playList.First().Beatmaps[0], true);
|
||||||
|
|
||||||
|
if ((track = current?.Track) == null) return;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (track.IsRunning)
|
||||||
|
track.Stop();
|
||||||
|
else
|
||||||
|
track.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void LoadComplete()
|
protected override void LoadComplete()
|
||||||
{
|
{
|
||||||
beatmapSource.ValueChanged += workingChanged;
|
beatmapBacking.ValueChanged += beatmapChanged;
|
||||||
beatmapSource.TriggerChange();
|
beatmapBacking.TriggerChange();
|
||||||
|
|
||||||
playList = playlist.List.ToList();
|
playList = playlist.List.ToList();
|
||||||
|
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
@ -258,60 +270,66 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
if (current?.TrackLoaded ?? false)
|
if (current?.TrackLoaded ?? false)
|
||||||
{
|
{
|
||||||
progress.UpdatePosition(current.Track.Length == 0 ? 0 : (float)(current.Track.CurrentTime / current.Track.Length));
|
var track = current.Track;
|
||||||
playButton.Icon = current.Track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o;
|
|
||||||
|
|
||||||
if (current.Track.HasCompleted && !current.Track.Looping) next();
|
progress.UpdatePosition(track.Length == 0 ? 0 : (float)(track.CurrentTime / track.Length));
|
||||||
|
playButton.Icon = track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o;
|
||||||
|
|
||||||
|
if (track.HasCompleted && !track.Looping) next();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
playButton.Icon = FontAwesome.fa_play_circle_o;
|
playButton.Icon = FontAwesome.fa_play_circle_o;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void workingChanged(WorkingBeatmap beatmap)
|
private WorkingBeatmap current;
|
||||||
|
|
||||||
|
private void beatmapChanged(WorkingBeatmap beatmap)
|
||||||
{
|
{
|
||||||
progress.IsEnabled = beatmap != null;
|
progress.IsEnabled = beatmap != null;
|
||||||
if (beatmap == current) return;
|
|
||||||
bool audioEquals = current?.BeatmapInfo?.AudioEquals(beatmap?.BeatmapInfo) ?? false;
|
bool audioEquals = beatmapBacking.Value?.BeatmapInfo?.AudioEquals(current?.BeatmapInfo) ?? false;
|
||||||
current = beatmap;
|
current = beatmapBacking.Value;
|
||||||
updateDisplay(current, audioEquals ? TransformDirection.None : TransformDirection.Next);
|
|
||||||
|
updateDisplay(beatmapBacking, audioEquals ? TransformDirection.None : TransformDirection.Next);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void prev()
|
private void prev()
|
||||||
{
|
{
|
||||||
if (playList.Count == 0) return;
|
if (playList.Count == 0) return;
|
||||||
if (current != null && playList.Count == 1) return;
|
if (beatmapBacking != null && playList.Count == 1) return;
|
||||||
|
|
||||||
int n = playListIndex - 1;
|
int n = playListIndex - 1;
|
||||||
if (n < 0)
|
if (n < 0)
|
||||||
n = playList.Count - 1;
|
n = playList.Count - 1;
|
||||||
|
|
||||||
play(playList[n].Beatmaps[0], false);
|
playSpecified(playList[n].Beatmaps[0], false);
|
||||||
playListIndex = n;
|
playListIndex = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void next()
|
private void next()
|
||||||
{
|
{
|
||||||
if (playList.Count == 0) return;
|
if (playList.Count == 0) return;
|
||||||
if (current != null && playList.Count == 1) return;
|
if (beatmapBacking != null && playList.Count == 1) return;
|
||||||
|
|
||||||
int n = playListIndex + 1;
|
int n = playListIndex + 1;
|
||||||
if (n >= playList.Count)
|
if (n >= playList.Count)
|
||||||
n = 0;
|
n = 0;
|
||||||
|
|
||||||
play(playList[n].Beatmaps[0], true);
|
playSpecified(playList[n].Beatmaps[0], true);
|
||||||
playListIndex = n;
|
playListIndex = n;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void play(BeatmapInfo info, bool isNext)
|
private void playSpecified(BeatmapInfo info, bool isNext)
|
||||||
{
|
{
|
||||||
current = beatmaps.GetWorkingBeatmap(info, current);
|
beatmapBacking.Value = beatmaps.GetWorkingBeatmap(info, beatmapBacking);
|
||||||
Task.Run(() =>
|
Task.Run(() =>
|
||||||
{
|
{
|
||||||
trackManager.SetExclusive(current.Track);
|
var track = beatmapBacking.Value.Track;
|
||||||
current.Track.Start();
|
trackManager.SetExclusive(track);
|
||||||
beatmapSource.Value = current;
|
track.Start();
|
||||||
|
beatmapBacking.Value = beatmapBacking;
|
||||||
}).ContinueWith(task => Schedule(task.ThrowIfFaulted), TaskContinuationOptions.OnlyOnFaulted);
|
}).ContinueWith(task => Schedule(task.ThrowIfFaulted), TaskContinuationOptions.OnlyOnFaulted);
|
||||||
updateDisplay(current, isNext ? TransformDirection.Next : TransformDirection.Prev);
|
updateDisplay(beatmapBacking, isNext ? TransformDirection.Next : TransformDirection.Prev);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Action pendingBeatmapSwitch;
|
private Action pendingBeatmapSwitch;
|
||||||
@ -337,7 +355,6 @@ namespace osu.Game.Overlays
|
|||||||
BeatmapMetadata metadata = beatmap.Beatmap.BeatmapInfo.Metadata;
|
BeatmapMetadata metadata = beatmap.Beatmap.BeatmapInfo.Metadata;
|
||||||
title.Current = localisation.GetUnicodePreference(metadata.TitleUnicode, metadata.Title);
|
title.Current = localisation.GetUnicodePreference(metadata.TitleUnicode, metadata.Title);
|
||||||
artist.Current = localisation.GetUnicodePreference(metadata.ArtistUnicode, metadata.Artist);
|
artist.Current = localisation.GetUnicodePreference(metadata.ArtistUnicode, metadata.Artist);
|
||||||
playlist.Current = beatmap.BeatmapSetInfo;
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -370,12 +387,10 @@ namespace osu.Game.Overlays
|
|||||||
|
|
||||||
private void seek(float position)
|
private void seek(float position)
|
||||||
{
|
{
|
||||||
current?.Track?.Seek(current.Track.Length * position);
|
var track = current?.Track;
|
||||||
current?.Track?.Start();
|
track?.Seek(track.Length * position);
|
||||||
}
|
}
|
||||||
|
|
||||||
private const float transition_length = 800;
|
|
||||||
|
|
||||||
protected override void PopIn()
|
protected override void PopIn()
|
||||||
{
|
{
|
||||||
base.PopIn();
|
base.PopIn();
|
||||||
|
Loading…
Reference in New Issue
Block a user