// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; using System.Diagnostics; using System.Threading.Tasks; using OpenTK; using OpenTK.Graphics; using osu.Framework.Allocation; using osu.Framework.Configuration; using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Primitives; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Input; using osu.Framework.Localisation; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Graphics; using osu.Game.Graphics.Sprites; using osu.Framework.Threading; using osu.Game.Overlays.Music; namespace osu.Game.Overlays { public class MusicController : FocusedOverlayContainer { 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 DragBar progressBar; private Button playButton; private Button playlistButton; private SpriteText title, artist; private PlaylistOverlay playlist; private LocalisationEngine localisation; private readonly Bindable beatmapBacking = new Bindable(); private Container dragContainer; private Container playerContainer; public MusicController() { Width = 400; Margin = new MarginPadding(10); } protected override bool OnDragStart(InputState state) => true; protected override bool OnDrag(InputState state) { Trace.Assert(state.Mouse.PositionMouseDown != null, "state.Mouse.PositionMouseDown != null"); Vector2 change = state.Mouse.Position - state.Mouse.PositionMouseDown.Value; // 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; dragContainer.MoveTo(change); return base.OnDrag(state); } protected override bool OnDragEnd(InputState state) { dragContainer.MoveTo(Vector2.Zero, 800, EasingTypes.OutElastic); return base.OnDragEnd(state); } [BackgroundDependencyLoader] private void load(OsuGameBase game, OsuColour colours, LocalisationEngine localisation) { this.localisation = localisation; Children = new Drawable[] { dragContainer = new Container { 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, }, playerContainer = new Container { RelativeSizeAxes = Axes.X, Height = player_height, Masking = true, CornerRadius = 5, EdgeEffect = new EdgeEffect { Type = EdgeEffectType.Shadow, Colour = Color4.Black.Opacity(40), Radius = 5, }, Children = new[] { currentBackground = new Background(), title = new OsuSpriteText { Origin = Anchor.BottomCentre, Anchor = Anchor.TopCentre, Position = new Vector2(0, 40), TextSize = 25, Colour = Color4.White, Text = @"Nothing to play", Font = @"Exo2.0-MediumItalic" }, artist = new OsuSpriteText { Origin = Anchor.TopCentre, Anchor = Anchor.TopCentre, Position = new Vector2(0, 45), TextSize = 15, Colour = Color4.White, Text = @"Nothing to play", Font = @"Exo2.0-BoldItalic" }, 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