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

Move logic into PlaylistOverlay

This commit is contained in:
MrTheMake 2017-06-19 16:30:58 +02:00
parent 9cc5dc6c2b
commit 73f2709a2d
2 changed files with 12 additions and 20 deletions

View File

@ -7,17 +7,18 @@ using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Configuration;
using osu.Framework.Extensions;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Input;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Screens;
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Extensions;
using osu.Framework.Input;
namespace osu.Game.Overlays.Music
{
@ -35,9 +36,13 @@ namespace osu.Game.Overlays.Music
private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
private readonly Bindable<OsuScreen> currentScreenBacking = new Bindable<OsuScreen>();
public IEnumerable<BeatmapSetInfo> BeatmapSets;
private InputManager inputManager;
private bool canChangeBeatmap => currentScreenBacking.Value?.CanChangeBeatmap != false;
[BackgroundDependencyLoader]
private void load(OsuGameBase game, BeatmapDatabase beatmaps, OsuColour colours, UserInputManager inputManager)
{
@ -86,6 +91,7 @@ namespace osu.Game.Overlays.Music
list.BeatmapSets = BeatmapSets = beatmaps.GetAllWithChildren<BeatmapSetInfo>().ToList();
beatmapBacking.BindTo(game.Beatmap);
currentScreenBacking.BindTo(game.CurrentScreen);
filter.Search.OnCommit = (sender, newText) => {
var beatmap = list.FirstVisibleSet?.Beatmaps?.FirstOrDefault();
@ -152,6 +158,9 @@ namespace osu.Game.Overlays.Music
private void playSpecified(BeatmapInfo info)
{
if (!canChangeBeatmap)
return;
beatmapBacking.Value = beatmaps.GetWorkingBeatmap(info, beatmapBacking);
Task.Run(() =>

View File

@ -53,13 +53,9 @@ namespace osu.Game.Overlays
private readonly Bindable<WorkingBeatmap> beatmapBacking = new Bindable<WorkingBeatmap>();
private readonly Bindable<OsuScreen> currentScreenBacking = new Bindable<OsuScreen>();
private Container dragContainer;
private Container playerContainer;
private bool canChangeBeatmap;
public MusicController()
{
Width = 400;
@ -204,7 +200,6 @@ namespace osu.Game.Overlays
};
beatmapBacking.BindTo(game.Beatmap);
currentScreenBacking.BindTo(game.CurrentScreen);
playlist.StateChanged += (c, s) => playlistButton.FadeColour(s == Visibility.Visible ? colours.Yellow : Color4.White, 200, EasingTypes.OutQuint);
}
@ -214,21 +209,9 @@ namespace osu.Game.Overlays
beatmapBacking.ValueChanged += beatmapChanged;
beatmapBacking.TriggerChange();
currentScreenBacking.ValueChanged += screenChanged;
currentScreenBacking.TriggerChange();
base.LoadComplete();
}
private void screenChanged(OsuScreen newScreen)
{
canChangeBeatmap = newScreen?.CanChangeBeatmap ?? true;
prevButton.Enabled = canChangeBeatmap;
nextButton.Enabled = canChangeBeatmap;
playlistButton.Enabled = canChangeBeatmap;
}
protected override void UpdateAfterChildren()
{
base.UpdateAfterChildren();
@ -246,7 +229,7 @@ namespace osu.Game.Overlays
progressBar.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 && canChangeBeatmap) next();
if (track.HasCompleted && !track.Looping) next();
}
else
playButton.Icon = FontAwesome.fa_play_circle_o;