From e1f6ab1a4289d77df6ec9625b1657fe5ace4a3a8 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 10:22:38 +0800 Subject: [PATCH 01/48] Create MusicController UI class and visual test. --- .../Tests/TestCaseMusicController.cs | 32 +++++++++++++++++++ .../osu.Desktop.VisualTests.csproj | 1 + osu.Game/Overlays/MusicController.cs | 25 +++++++++++++++ osu.Game/osu.Game.csproj | 1 + 4 files changed, 59 insertions(+) create mode 100644 osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs create mode 100644 osu.Game/Overlays/MusicController.cs diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs new file mode 100644 index 0000000000..d17f99f108 --- /dev/null +++ b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs @@ -0,0 +1,32 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using osu.Framework.Graphics; +using osu.Framework.GameModes.Testing; +using osu.Game.Overlays; + +namespace osu.Desktop.Tests +{ + class TestCaseMusicController : TestCase + { + public override string Name => @"Music Controller"; + public override string Description => @"Tests music controller ui."; + + public override void Reset() + { + base.Reset(); + MusicController mc = new MusicController + { + Origin = Anchor.Centre, + Anchor = Anchor.Centre + }; + Add(mc); + AddToggle(@"Show", mc.ToggleVisibility); + } + } +} diff --git a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj index 65fb72e2a6..a09786f873 100644 --- a/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj +++ b/osu.Desktop.VisualTests/osu.Desktop.VisualTests.csproj @@ -156,6 +156,7 @@ + diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs new file mode 100644 index 0000000000..d727431788 --- /dev/null +++ b/osu.Game/Overlays/MusicController.cs @@ -0,0 +1,25 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using osu.Framework; +using osu.Framework.Graphics.Containers; + +namespace osu.Game.Overlays +{ + public class MusicController : OverlayContainer + { + public override void Load(BaseGame game) + { + base.Load(game); + Width = 400; + Height = 130; + CornerRadius = 5; + Masking = true; + } + + //placeholder for toggling + protected override void PopIn() => FadeIn(500); + + protected override void PopOut() => FadeOut(500); + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 5029d3453d..28297fcca1 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -63,6 +63,7 @@ + From 0f2b5e8370c678786b5411778c572ddb57b84e4c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 10:50:49 +0800 Subject: [PATCH 02/48] Layers. --- osu.Game/Overlays/MusicController.cs | 35 ++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index d727431788..c0ff0ffbd9 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -1,13 +1,18 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using OpenTK.Graphics; using osu.Framework; +using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; namespace osu.Game.Overlays { public class MusicController : OverlayContainer { + private Sprite background; + private Box progress; public override void Load(BaseGame game) { base.Load(game); @@ -15,6 +20,36 @@ namespace osu.Game.Overlays Height = 130; CornerRadius = 5; Masking = true; + Children = new Drawable[] + { + background = new Sprite + { + RelativeSizeAxes = Axes.Both, + Texture = game.Textures.Get(@"Backgrounds/bg4")//placeholder + }, + new Box + { + RelativeSizeAxes = Axes.Both, + Colour = new Color4(0, 0, 0, 127) + }, + new Box + { + RelativeSizeAxes = Axes.X, + Height = 50, + Origin = Anchor.BottomCentre, + Anchor = Anchor.BottomCentre, + Colour = new Color4(0, 0, 0, 127) + }, + progress = new Box + { + RelativeSizeAxes = Axes.X, + Height = 10, + Width = 0.5f,//placeholder + Origin = Anchor.BottomLeft, + Anchor = Anchor.BottomLeft, + Colour = Color4.Orange + } + }; } //placeholder for toggling From b0d72c5f848c8c16548221999f589420a37f785c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 13:00:06 +0800 Subject: [PATCH 03/48] Button and text. --- osu.Game/Overlays/MusicController.cs | 66 ++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index c0ff0ffbd9..e17d33e20c 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -1,11 +1,15 @@ //Copyright (c) 2007-2016 ppy Pty Ltd . //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE +using System; +using OpenTK; using OpenTK.Graphics; using osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; +using osu.Game.Graphics; namespace osu.Game.Overlays { @@ -13,6 +17,7 @@ namespace osu.Game.Overlays { private Sprite background; private Box progress; + private SpriteText title, artist; public override void Load(BaseGame game) { base.Load(game); @@ -32,6 +37,24 @@ namespace osu.Game.Overlays RelativeSizeAxes = Axes.Both, Colour = new Color4(0, 0, 0, 127) }, + title = new SpriteText + { + Origin = Anchor.BottomCentre, + Anchor = Anchor.TopCentre, + Position = new Vector2(0, 40), + TextSize = 20, + Colour = Color4.White, + Text = @"Title Title Title"//placeholder + }, + artist = new SpriteText + { + Origin = Anchor.TopCentre, + Anchor = Anchor.TopCentre, + Position = new Vector2(0, 45), + TextSize = 12, + Colour = Color4.White, + Text = @"Artist Artist Artist"//placeholder + }, new Box { RelativeSizeAxes = Axes.X, @@ -40,6 +63,38 @@ namespace osu.Game.Overlays Anchor = Anchor.BottomCentre, Colour = new Color4(0, 0, 0, 127) }, + new ClickableTextAwesome + { + TextSize = 30, + Icon = FontAwesome.play_circle_o, + Origin = Anchor.Centre, + Anchor = Anchor.BottomCentre, + Position = new Vector2(0, 30) + }, + new ClickableTextAwesome + { + TextSize = 15, + Icon = FontAwesome.step_backward, + Origin = Anchor.Centre, + Anchor = Anchor.BottomCentre, + Position = new Vector2(-30, 30) + }, + new ClickableTextAwesome + { + TextSize = 15, + Icon = FontAwesome.step_forward, + Origin = Anchor.Centre, + Anchor = Anchor.BottomCentre, + Position = new Vector2(30, 30) + }, + new ClickableTextAwesome + { + TextSize = 15, + Icon = FontAwesome.bars, + Origin = Anchor.Centre, + Anchor = Anchor.BottomRight, + Position = new Vector2(20, 30) + }, progress = new Box { RelativeSizeAxes = Axes.X, @@ -57,4 +112,15 @@ namespace osu.Game.Overlays protected override void PopOut() => FadeOut(500); } + + public class ClickableTextAwesome : TextAwesome + { + public Action Action; + + protected override bool OnClick(InputState state) + { + Action?.Invoke(this); + return true; + } + } } From 303bd41765452192a763a14a2d0a2cc4be258890 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 13:13:49 +0800 Subject: [PATCH 04/48] Background scale. --- osu.Game/Overlays/MusicController.cs | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index e17d33e20c..506e33df52 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -8,6 +8,7 @@ using osu.Framework; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; +using osu.Framework.Graphics.Textures; using osu.Framework.Input; using osu.Game.Graphics; @@ -15,7 +16,7 @@ namespace osu.Game.Overlays { public class MusicController : OverlayContainer { - private Sprite background; + private Sprite backgroundSprite; private Box progress; private SpriteText title, artist; public override void Load(BaseGame game) @@ -27,11 +28,7 @@ namespace osu.Game.Overlays Masking = true; Children = new Drawable[] { - background = new Sprite - { - RelativeSizeAxes = Axes.Both, - Texture = game.Textures.Get(@"Backgrounds/bg4")//placeholder - }, + backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4")),//placeholder new Box { RelativeSizeAxes = Axes.Both, @@ -107,6 +104,19 @@ namespace osu.Game.Overlays }; } + 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; + } + //placeholder for toggling protected override void PopIn() => FadeIn(500); From d2495e34fb78288513619a36f0fe986e47f5d4a4 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 13:47:05 +0800 Subject: [PATCH 05/48] Query from beatmap database. --- osu.Game/Overlays/MusicController.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 506e33df52..5bb93289a4 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -2,6 +2,8 @@ //Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using System; +using System.Collections.Generic; +using System.Linq; using OpenTK; using OpenTK.Graphics; using osu.Framework; @@ -10,6 +12,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Input; +using osu.Game.Database; using osu.Game.Graphics; namespace osu.Game.Overlays @@ -19,9 +22,13 @@ namespace osu.Game.Overlays private Sprite backgroundSprite; private Box progress; private SpriteText title, artist; + private List playList; + private BeatmapSetInfo currentPlay; public override void Load(BaseGame game) { base.Load(game); + playList = (game as OsuGameBase).Beatmaps.Query().ToList(); + currentPlay = playList.FirstOrDefault(); Width = 400; Height = 130; CornerRadius = 5; @@ -41,7 +48,7 @@ namespace osu.Game.Overlays Position = new Vector2(0, 40), TextSize = 20, Colour = Color4.White, - Text = @"Title Title Title"//placeholder + Text = currentPlay?.Metadata.TitleUnicode ?? currentPlay?.Metadata.Title ?? @"Nothing to play" }, artist = new SpriteText { @@ -50,7 +57,7 @@ namespace osu.Game.Overlays Position = new Vector2(0, 45), TextSize = 12, Colour = Color4.White, - Text = @"Artist Artist Artist"//placeholder + Text = currentPlay?.Metadata.ArtistUnicode ?? currentPlay?.Metadata.Artist ?? @"Nothing to play" }, new Box { From a32f9eed516e49254b369722f046d9075e2838b6 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 15:34:44 +0800 Subject: [PATCH 06/48] Play control. --- osu.Game/Overlays/MusicController.cs | 93 +++++++++++++++++++++++++--- 1 file changed, 83 insertions(+), 10 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 5bb93289a4..d7ee3ca8fc 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -7,11 +7,14 @@ using System.Linq; using OpenTK; using OpenTK.Graphics; using osu.Framework; +using osu.Framework.Audio.Track; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; +using osu.Framework.Graphics.Transformations; using osu.Framework.Input; +using osu.Game.Beatmaps.IO; using osu.Game.Database; using osu.Game.Graphics; @@ -21,18 +24,23 @@ namespace osu.Game.Overlays { private Sprite backgroundSprite; private Box progress; + private ClickableTextAwesome playButton, listButton; private SpriteText title, artist; + private OsuGameBase osuGame; private List playList; private BeatmapSetInfo currentPlay; + private AudioTrack currentTrack; public override void Load(BaseGame game) { base.Load(game); - playList = (game as OsuGameBase).Beatmaps.Query().ToList(); + osuGame = game as OsuGameBase; + playList = osuGame.Beatmaps.Query().ToList(); currentPlay = playList.FirstOrDefault(); Width = 400; Height = 130; CornerRadius = 5; Masking = true; + Children = new Drawable[] { backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4")),//placeholder @@ -48,7 +56,7 @@ namespace osu.Game.Overlays Position = new Vector2(0, 40), TextSize = 20, Colour = Color4.White, - Text = currentPlay?.Metadata.TitleUnicode ?? currentPlay?.Metadata.Title ?? @"Nothing to play" + Text = @"Nothing to play" }, artist = new SpriteText { @@ -57,7 +65,7 @@ namespace osu.Game.Overlays Position = new Vector2(0, 45), TextSize = 12, Colour = Color4.White, - Text = currentPlay?.Metadata.ArtistUnicode ?? currentPlay?.Metadata.Artist ?? @"Nothing to play" + Text = @"Nothing to play" }, new Box { @@ -67,13 +75,27 @@ namespace osu.Game.Overlays Anchor = Anchor.BottomCentre, Colour = new Color4(0, 0, 0, 127) }, - new ClickableTextAwesome + playButton = new ClickableTextAwesome { TextSize = 30, Icon = FontAwesome.play_circle_o, Origin = Anchor.Centre, Anchor = Anchor.BottomCentre, - Position = new Vector2(0, 30) + Position = new Vector2(0, 30), + Action = () => + { + if (currentTrack == null) return; + if (currentTrack.IsRunning) + { + currentTrack.Stop(); + playButton.Icon = FontAwesome.play_circle_o; + } + else + { + currentTrack.Start(); + playButton.Icon = FontAwesome.pause; + } + } }, new ClickableTextAwesome { @@ -81,7 +103,8 @@ namespace osu.Game.Overlays Icon = FontAwesome.step_backward, Origin = Anchor.Centre, Anchor = Anchor.BottomCentre, - Position = new Vector2(-30, 30) + Position = new Vector2(-30, 30), + Action = prev }, new ClickableTextAwesome { @@ -89,9 +112,10 @@ namespace osu.Game.Overlays Icon = FontAwesome.step_forward, Origin = Anchor.Centre, Anchor = Anchor.BottomCentre, - Position = new Vector2(30, 30) + Position = new Vector2(30, 30), + Action = next }, - new ClickableTextAwesome + listButton = new ClickableTextAwesome { TextSize = 15, Icon = FontAwesome.bars, @@ -109,6 +133,55 @@ namespace osu.Game.Overlays Colour = Color4.Orange } }; + if (currentPlay != null) play(currentPlay, null); + } + + private void prev() + { + int i = playList.IndexOf(currentPlay); + if (i == -1) return; + i = (i - 1 + playList.Count) % playList.Count; + currentPlay = playList[i]; + play(currentPlay, false); + } + + private void next() + { + int i = playList.IndexOf(currentPlay); + if (i == -1) return; + i = (i + 1) % playList.Count; + currentPlay = playList[i]; + play(currentPlay, true); + } + + private void play(BeatmapSetInfo beatmap, bool? isNext) + { + title.Text = beatmap.Metadata.TitleUnicode ?? beatmap.Metadata.Title; + artist.Text = beatmap.Metadata.ArtistUnicode ?? beatmap.Metadata.Artist; + ArchiveReader reader = osuGame.Beatmaps.GetReader(currentPlay); + currentTrack?.Stop(); + currentTrack = new AudioTrackBass(reader.ReadFile(beatmap.Metadata.AudioFile)); + currentTrack.Start(); + Sprite newBackground = getScaledSprite(TextureLoader.FromStream(reader.ReadFile(beatmap.Metadata.BackgroundFile))); + Add(newBackground); + if (isNext == true) + { + newBackground.Position = new Vector2(400, 0); + newBackground.MoveToX(0, 200, EasingTypes.Out); + backgroundSprite.MoveToX(-400, 200, EasingTypes.Out); + backgroundSprite.Expire(); + } + else if (isNext == false) + { + newBackground.Position = new Vector2(-400, 0); + newBackground.MoveToX(0, 200, EasingTypes.Out); + backgroundSprite.MoveToX(400, 200, EasingTypes.Out); + backgroundSprite.Expire(); + } + else + { + Remove(backgroundSprite); + } } private Sprite getScaledSprite(Texture background) @@ -132,11 +205,11 @@ namespace osu.Game.Overlays public class ClickableTextAwesome : TextAwesome { - public Action Action; + public Action Action; protected override bool OnClick(InputState state) { - Action?.Invoke(this); + Action?.Invoke(); return true; } } From 1a3a5c544d1bc68bd99de07b2aa55a8c5a798f95 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 17:19:48 +0800 Subject: [PATCH 07/48] Button behavior fixes. --- osu.Game/Overlays/MusicController.cs | 83 +++++++++++++++++++++------- 1 file changed, 62 insertions(+), 21 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index d7ee3ca8fc..90e9f2bc9e 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -24,7 +24,7 @@ namespace osu.Game.Overlays { private Sprite backgroundSprite; private Box progress; - private ClickableTextAwesome playButton, listButton; + private TextAwesome playButton, listButton; private SpriteText title, artist; private OsuGameBase osuGame; private List playList; @@ -75,10 +75,9 @@ namespace osu.Game.Overlays Anchor = Anchor.BottomCentre, Colour = new Color4(0, 0, 0, 127) }, - playButton = new ClickableTextAwesome + new ClickableContainer { - TextSize = 30, - Icon = FontAwesome.play_circle_o, + AutoSizeAxes = Axes.Both, Origin = Anchor.Centre, Anchor = Anchor.BottomCentre, Position = new Vector2(0, 30), @@ -95,33 +94,70 @@ namespace osu.Game.Overlays currentTrack.Start(); playButton.Icon = FontAwesome.pause; } + }, + Children = new Drawable[] + { + playButton = new TextAwesome + { + TextSize = 30, + Icon = FontAwesome.play_circle_o, + Origin = Anchor.Centre, + Anchor = Anchor.Centre + } } }, - new ClickableTextAwesome + new ClickableContainer { - TextSize = 15, - Icon = FontAwesome.step_backward, + AutoSizeAxes = Axes.Both, Origin = Anchor.Centre, Anchor = Anchor.BottomCentre, Position = new Vector2(-30, 30), - Action = prev + Action = prev, + Children = new Drawable[] + { + new TextAwesome + { + TextSize = 15, + Icon = FontAwesome.step_backward, + Origin = Anchor.Centre, + Anchor = Anchor.Centre + } + } }, - new ClickableTextAwesome + new ClickableContainer { - TextSize = 15, - Icon = FontAwesome.step_forward, + AutoSizeAxes = Axes.Both, Origin = Anchor.Centre, Anchor = Anchor.BottomCentre, Position = new Vector2(30, 30), - Action = next + Action = next, + Children = new Drawable[] + { + new TextAwesome + { + TextSize = 15, + Icon = FontAwesome.step_forward, + Origin = Anchor.Centre, + Anchor = Anchor.Centre + } + } }, - listButton = new ClickableTextAwesome + new ClickableContainer { - TextSize = 15, - Icon = FontAwesome.bars, + AutoSizeAxes = Axes.Both, Origin = Anchor.Centre, Anchor = Anchor.BottomRight, - Position = new Vector2(20, 30) + Position = new Vector2(20, 30), + Children = new Drawable[] + { + listButton = new TextAwesome + { + TextSize = 15, + Icon = FontAwesome.bars, + Origin = Anchor.Centre, + Anchor = Anchor.Centre + } + } }, progress = new Box { @@ -133,7 +169,11 @@ namespace osu.Game.Overlays Colour = Color4.Orange } }; - if (currentPlay != null) play(currentPlay, null); + if (currentPlay != null) + { + playButton.Icon=FontAwesome.pause; + play(currentPlay, null); + } } private void prev() @@ -156,13 +196,14 @@ namespace osu.Game.Overlays private void play(BeatmapSetInfo beatmap, bool? isNext) { - title.Text = beatmap.Metadata.TitleUnicode ?? beatmap.Metadata.Title; - artist.Text = beatmap.Metadata.ArtistUnicode ?? beatmap.Metadata.Artist; + BeatmapMetadata metadata = osuGame.Beatmaps.Query().Where(x => x.ID == beatmap.BeatmapMetadataID).First(); + title.Text = metadata.TitleUnicode ?? metadata.Title; + artist.Text = metadata.ArtistUnicode ?? metadata.Artist; ArchiveReader reader = osuGame.Beatmaps.GetReader(currentPlay); currentTrack?.Stop(); - currentTrack = new AudioTrackBass(reader.ReadFile(beatmap.Metadata.AudioFile)); + currentTrack = new AudioTrackBass(reader.ReadFile(metadata.AudioFile)); currentTrack.Start(); - Sprite newBackground = getScaledSprite(TextureLoader.FromStream(reader.ReadFile(beatmap.Metadata.BackgroundFile))); + Sprite newBackground = getScaledSprite(TextureLoader.FromStream(reader.ReadFile(metadata.BackgroundFile))); Add(newBackground); if (isNext == true) { From 8e766a1f472793b23161b73d6f51e161222bb0fa Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 17:23:30 +0800 Subject: [PATCH 08/48] Show playing progress. --- osu.Game/Overlays/MusicController.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 90e9f2bc9e..70e07d2d74 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -163,7 +163,7 @@ namespace osu.Game.Overlays { RelativeSizeAxes = Axes.X, Height = 10, - Width = 0.5f,//placeholder + Width = 0, Origin = Anchor.BottomLeft, Anchor = Anchor.BottomLeft, Colour = Color4.Orange @@ -176,6 +176,14 @@ namespace osu.Game.Overlays } } + protected override void Update() + { + base.Update(); + if (currentTrack == null) return; + progress.Width = (float)(currentTrack.CurrentTime / currentTrack.Length); + if (currentTrack.HasCompleted) next(); + } + private void prev() { int i = playList.IndexOf(currentPlay); From b671a339114baa21213ccd2138aea03deab7d667 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 18:18:54 +0800 Subject: [PATCH 09/48] Transition fixes and clock for VisualTest. --- .../Tests/TestCaseMusicController.cs | 18 ++++++++++++++++++ osu.Game/Overlays/MusicController.cs | 9 +++++---- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs index d17f99f108..7b22ea956c 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs @@ -9,6 +9,8 @@ using System.Threading.Tasks; using osu.Framework.Graphics; using osu.Framework.GameModes.Testing; using osu.Game.Overlays; +using osu.Framework.Timing; +using osu.Framework; namespace osu.Desktop.Tests { @@ -17,9 +19,19 @@ namespace osu.Desktop.Tests public override string Name => @"Music Controller"; public override string Description => @"Tests music controller ui."; + IFrameBasedClock ourClock; + protected override IFrameBasedClock Clock => ourClock; + + public override void Load(BaseGame game) + { + base.Load(game); + ourClock = new FramedClock(); + } + public override void Reset() { base.Reset(); + ourClock.ProcessFrame(); MusicController mc = new MusicController { Origin = Anchor.Centre, @@ -28,5 +40,11 @@ namespace osu.Desktop.Tests Add(mc); AddToggle(@"Show", mc.ToggleVisibility); } + + protected override void Update() + { + base.Update(); + ourClock.ProcessFrame(); + } } } diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 70e07d2d74..697b0ee286 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -216,21 +216,22 @@ namespace osu.Game.Overlays if (isNext == true) { newBackground.Position = new Vector2(400, 0); - newBackground.MoveToX(0, 200, EasingTypes.Out); - backgroundSprite.MoveToX(-400, 200, EasingTypes.Out); + newBackground.MoveToX(0, 500, EasingTypes.OutCubic); + backgroundSprite.MoveToX(-400, 500, EasingTypes.OutCubic); backgroundSprite.Expire(); } else if (isNext == false) { newBackground.Position = new Vector2(-400, 0); - newBackground.MoveToX(0, 200, EasingTypes.Out); - backgroundSprite.MoveToX(400, 200, EasingTypes.Out); + newBackground.MoveToX(0, 500, EasingTypes.OutCubic); + backgroundSprite.MoveToX(400, 500, EasingTypes.OutCubic); backgroundSprite.Expire(); } else { Remove(backgroundSprite); } + backgroundSprite = newBackground; } private Sprite getScaledSprite(Texture background) From 0da78c19a23aee6cf7d9cbb2f070097ef49cbf38 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 18:26:50 +0800 Subject: [PATCH 10/48] TestCase reset. --- .../Tests/TestCaseMusicController.cs | 5 ++++- osu.Game/Overlays/MusicController.cs | 22 +++++++++---------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs index 7b22ea956c..524768a122 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs @@ -22,6 +22,8 @@ namespace osu.Desktop.Tests IFrameBasedClock ourClock; protected override IFrameBasedClock Clock => ourClock; + protected MusicController mc; + public override void Load(BaseGame game) { base.Load(game); @@ -32,7 +34,8 @@ namespace osu.Desktop.Tests { base.Reset(); ourClock.ProcessFrame(); - MusicController mc = new MusicController + mc?.CurrentTrack?.Stop(); + mc = new MusicController { Origin = Anchor.Centre, Anchor = Anchor.Centre diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 697b0ee286..e8592a852d 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -29,7 +29,7 @@ namespace osu.Game.Overlays private OsuGameBase osuGame; private List playList; private BeatmapSetInfo currentPlay; - private AudioTrack currentTrack; + public AudioTrack CurrentTrack { get; set; }//TODO:gets exterally public override void Load(BaseGame game) { base.Load(game); @@ -83,15 +83,15 @@ namespace osu.Game.Overlays Position = new Vector2(0, 30), Action = () => { - if (currentTrack == null) return; - if (currentTrack.IsRunning) + if (CurrentTrack == null) return; + if (CurrentTrack.IsRunning) { - currentTrack.Stop(); + CurrentTrack.Stop(); playButton.Icon = FontAwesome.play_circle_o; } else { - currentTrack.Start(); + CurrentTrack.Start(); playButton.Icon = FontAwesome.pause; } }, @@ -179,9 +179,9 @@ namespace osu.Game.Overlays protected override void Update() { base.Update(); - if (currentTrack == null) return; - progress.Width = (float)(currentTrack.CurrentTime / currentTrack.Length); - if (currentTrack.HasCompleted) next(); + if (CurrentTrack == null) return; + progress.Width = (float)(CurrentTrack.CurrentTime / CurrentTrack.Length); + if (CurrentTrack.HasCompleted) next(); } private void prev() @@ -208,9 +208,9 @@ namespace osu.Game.Overlays title.Text = metadata.TitleUnicode ?? metadata.Title; artist.Text = metadata.ArtistUnicode ?? metadata.Artist; ArchiveReader reader = osuGame.Beatmaps.GetReader(currentPlay); - currentTrack?.Stop(); - currentTrack = new AudioTrackBass(reader.ReadFile(metadata.AudioFile)); - currentTrack.Start(); + CurrentTrack?.Stop(); + CurrentTrack = new AudioTrackBass(reader.ReadFile(metadata.AudioFile)); + CurrentTrack.Start(); Sprite newBackground = getScaledSprite(TextureLoader.FromStream(reader.ReadFile(metadata.BackgroundFile))); Add(newBackground); if (isNext == true) From d9fc04748e761a5f516109ce8fd2c225220168d1 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 24 Oct 2016 19:02:12 +0800 Subject: [PATCH 11/48] Remove redundant class. --- osu.Game/Overlays/MusicController.cs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index e8592a852d..74c3d3392b 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -252,15 +252,4 @@ namespace osu.Game.Overlays protected override void PopOut() => FadeOut(500); } - - public class ClickableTextAwesome : TextAwesome - { - public Action Action; - - protected override bool OnClick(InputState state) - { - Action?.Invoke(); - return true; - } - } } From fead1d4c6f423183a5f5536b094656a11e2d6dde Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 25 Oct 2016 09:18:47 +0800 Subject: [PATCH 12/48] Seek by clicking and dragging on progress bar. --- osu.Game/Overlays/MusicController.cs | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 74c3d3392b..4d83070ef5 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -247,6 +247,28 @@ namespace osu.Game.Overlays return scaledSprite; } + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + trySeek(state); + return base.OnMouseDown(state, args); + } + + protected override bool OnMouseMove(InputState state) + { + trySeek(state); + return base.OnMouseMove(state); + } + + private void trySeek(InputState state) + { + if (state.Mouse.LeftButton) + { + Vector2 pos = GetLocalPosition(state.Mouse.NativeState.Position); + if (pos.Y > 120) + CurrentTrack?.Seek(CurrentTrack.Length * pos.X / 400f); + } + } + //placeholder for toggling protected override void PopIn() => FadeIn(500); From 6482184a09d6d453df76866321c3d03a0c0c2404 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Tue, 25 Oct 2016 09:33:52 +0800 Subject: [PATCH 13/48] Dispose ArchiveReader. --- osu.Game/Overlays/MusicController.cs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 4d83070ef5..471696e592 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -207,11 +207,14 @@ namespace osu.Game.Overlays BeatmapMetadata metadata = osuGame.Beatmaps.Query().Where(x => x.ID == beatmap.BeatmapMetadataID).First(); title.Text = metadata.TitleUnicode ?? metadata.Title; artist.Text = metadata.ArtistUnicode ?? metadata.Artist; - ArchiveReader reader = osuGame.Beatmaps.GetReader(currentPlay); - CurrentTrack?.Stop(); - CurrentTrack = new AudioTrackBass(reader.ReadFile(metadata.AudioFile)); - CurrentTrack.Start(); - Sprite newBackground = getScaledSprite(TextureLoader.FromStream(reader.ReadFile(metadata.BackgroundFile))); + Sprite newBackground; + using (ArchiveReader reader = osuGame.Beatmaps.GetReader(currentPlay)) + { + CurrentTrack?.Stop(); + CurrentTrack = new AudioTrackBass(reader.ReadFile(metadata.AudioFile)); + CurrentTrack.Start(); + newBackground = getScaledSprite(TextureLoader.FromStream(reader.ReadFile(metadata.BackgroundFile))); + } Add(newBackground); if (isNext == true) { From 3e30935d100f05bac19f6ce1796be6a4750f7b84 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 27 Oct 2016 16:58:40 +0800 Subject: [PATCH 14/48] Allow to set database of music controller. --- osu.Game/Overlays/MusicController.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 471696e592..7a543252dc 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -28,13 +28,20 @@ namespace osu.Game.Overlays private SpriteText title, artist; private OsuGameBase osuGame; private List playList; + private BeatmapDatabase database; private BeatmapSetInfo currentPlay; public AudioTrack CurrentTrack { get; set; }//TODO:gets exterally + + public MusicController(BeatmapDatabase db = null) + { + database = db; + } public override void Load(BaseGame game) { base.Load(game); osuGame = game as OsuGameBase; - playList = osuGame.Beatmaps.Query().ToList(); + if (database == null) database = osuGame.Beatmaps; + playList = database.Query().ToList(); currentPlay = playList.FirstOrDefault(); Width = 400; Height = 130; From 9c2d3990cef747aa51095cb0c553244f93c0c81c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 27 Oct 2016 17:04:41 +0800 Subject: [PATCH 15/48] Add spacing in code. --- osu.Game/Overlays/MusicController.cs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 7a543252dc..4a256eb3ab 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -30,19 +30,23 @@ namespace osu.Game.Overlays private List playList; private BeatmapDatabase database; private BeatmapSetInfo currentPlay; + public AudioTrack CurrentTrack { get; set; }//TODO:gets exterally public MusicController(BeatmapDatabase db = null) { database = db; } + public override void Load(BaseGame game) { base.Load(game); osuGame = game as OsuGameBase; + if (database == null) database = osuGame.Beatmaps; playList = database.Query().ToList(); currentPlay = playList.FirstOrDefault(); + Width = 400; Height = 130; CornerRadius = 5; @@ -176,9 +180,10 @@ namespace osu.Game.Overlays Colour = Color4.Orange } }; + if (currentPlay != null) { - playButton.Icon=FontAwesome.pause; + playButton.Icon = FontAwesome.pause; play(currentPlay, null); } } @@ -214,7 +219,9 @@ namespace osu.Game.Overlays BeatmapMetadata metadata = osuGame.Beatmaps.Query().Where(x => x.ID == beatmap.BeatmapMetadataID).First(); title.Text = metadata.TitleUnicode ?? metadata.Title; artist.Text = metadata.ArtistUnicode ?? metadata.Artist; + Sprite newBackground; + using (ArchiveReader reader = osuGame.Beatmaps.GetReader(currentPlay)) { CurrentTrack?.Stop(); @@ -222,7 +229,9 @@ namespace osu.Game.Overlays CurrentTrack.Start(); newBackground = getScaledSprite(TextureLoader.FromStream(reader.ReadFile(metadata.BackgroundFile))); } + Add(newBackground); + if (isNext == true) { newBackground.Position = new Vector2(400, 0); @@ -241,6 +250,7 @@ namespace osu.Game.Overlays { Remove(backgroundSprite); } + backgroundSprite = newBackground; } From 35b1d0ae508f049da5f9ed212c5058678622fd4b Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 27 Oct 2016 17:58:33 +0800 Subject: [PATCH 16/48] Seperated DragBar class. --- osu.Game/Overlays/DragBar.cs | 69 ++++++++++++++++++++++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 2 files changed, 70 insertions(+) create mode 100644 osu.Game/Overlays/DragBar.cs diff --git a/osu.Game/Overlays/DragBar.cs b/osu.Game/Overlays/DragBar.cs new file mode 100644 index 0000000000..ee54d21d74 --- /dev/null +++ b/osu.Game/Overlays/DragBar.cs @@ -0,0 +1,69 @@ +//Copyright (c) 2007-2016 ppy Pty Ltd . +//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE + +using System; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Framework.Input; + +namespace osu.Game.Overlays +{ + public class DragBar : Container + { + private Box fill; + + public Action SeekRequested; + private bool isDragging; + + public DragBar() + { + RelativeSizeAxes = Axes.X; + + Children = new Drawable[] + { + fill = new Box() + { + Origin = Anchor.CentreLeft, + Anchor = Anchor.CentreLeft, + RelativeSizeAxes = Axes.Both, + Width = 0 + } + }; + } + + public void UpdatePosition(float position) + { + if (isDragging) return; + + fill.Width = position; + } + + private void seek(InputState state) + { + float seekLocation = state.Mouse.Position.X / DrawWidth; + SeekRequested?.Invoke(seekLocation); + fill.Width = seekLocation; + } + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) + { + seek(state); + return true; + } + + protected override bool OnDrag(InputState state) + { + seek(state); + return true; + } + + protected override bool OnDragStart(InputState state) => isDragging = true; + + protected override bool OnDragEnd(InputState state) + { + isDragging = false; + return true; + } + } +} diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 28297fcca1..12436d8673 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -63,6 +63,7 @@ + From 73d1eeb2722408369639a8c1cc30f64571af8b03 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 27 Oct 2016 18:15:43 +0800 Subject: [PATCH 17/48] Update MusicController using DragBar. --- osu.Game/Overlays/MusicController.cs | 39 +++++++--------------------- 1 file changed, 9 insertions(+), 30 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 4a256eb3ab..9d79c0cb37 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -13,7 +13,6 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Transformations; -using osu.Framework.Input; using osu.Game.Beatmaps.IO; using osu.Game.Database; using osu.Game.Graphics; @@ -23,9 +22,10 @@ namespace osu.Game.Overlays public class MusicController : OverlayContainer { private Sprite backgroundSprite; - private Box progress; + private DragBar progress; private TextAwesome playButton, listButton; private SpriteText title, artist; + private OsuGameBase osuGame; private List playList; private BeatmapDatabase database; @@ -170,14 +170,13 @@ namespace osu.Game.Overlays } } }, - progress = new Box + progress = new DragBar { - RelativeSizeAxes = Axes.X, + Origin = Anchor.BottomCentre, + Anchor = Anchor.BottomCentre, Height = 10, - Width = 0, - Origin = Anchor.BottomLeft, - Anchor = Anchor.BottomLeft, - Colour = Color4.Orange + Colour = Color4.Orange, + SeekRequested = seek } }; @@ -192,7 +191,7 @@ namespace osu.Game.Overlays { base.Update(); if (CurrentTrack == null) return; - progress.Width = (float)(CurrentTrack.CurrentTime / CurrentTrack.Length); + progress.UpdatePosition((float)(CurrentTrack.CurrentTime / CurrentTrack.Length)); if (CurrentTrack.HasCompleted) next(); } @@ -267,27 +266,7 @@ namespace osu.Game.Overlays return scaledSprite; } - protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) - { - trySeek(state); - return base.OnMouseDown(state, args); - } - - protected override bool OnMouseMove(InputState state) - { - trySeek(state); - return base.OnMouseMove(state); - } - - private void trySeek(InputState state) - { - if (state.Mouse.LeftButton) - { - Vector2 pos = GetLocalPosition(state.Mouse.NativeState.Position); - if (pos.Y > 120) - CurrentTrack?.Seek(CurrentTrack.Length * pos.X / 400f); - } - } + private void seek(float position) => CurrentTrack?.Seek(CurrentTrack.Length * position); //placeholder for toggling protected override void PopIn() => FadeIn(500); From eab8caaa0cd0b51a79fcc1b36783f6a126f2851c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 27 Oct 2016 19:51:38 +0800 Subject: [PATCH 18/48] Ensure track is playing after seek. --- osu.Game/Overlays/MusicController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 9d79c0cb37..e96050957c 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -266,7 +266,11 @@ namespace osu.Game.Overlays return scaledSprite; } - private void seek(float position) => CurrentTrack?.Seek(CurrentTrack.Length * position); + private void seek(float position) + { + CurrentTrack?.Seek(CurrentTrack.Length * position); + CurrentTrack?.Start(); + } //placeholder for toggling protected override void PopIn() => FadeIn(500); From 7d6e4a8ad233b99bf4245d729ac8f097f1f1fd2b Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 19:39:02 +0800 Subject: [PATCH 19/48] Make music controller uses WorkingBeatmap. --- osu.Game/Overlays/MusicController.cs | 26 +++++++++++--------------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index e96050957c..6692ace775 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -8,11 +8,13 @@ using OpenTK; using OpenTK.Graphics; using osu.Framework; using osu.Framework.Audio.Track; +using osu.Framework.Configuration; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Transformations; +using osu.Game.Beatmaps; using osu.Game.Beatmaps.IO; using osu.Game.Database; using osu.Game.Graphics; @@ -29,9 +31,8 @@ namespace osu.Game.Overlays private OsuGameBase osuGame; private List playList; private BeatmapDatabase database; - private BeatmapSetInfo currentPlay; - - public AudioTrack CurrentTrack { get; set; }//TODO:gets exterally + private Bindable beatmapSource; + private AudioTrack CurrentTrack => beatmapSource.Value?.Track; public MusicController(BeatmapDatabase db = null) { @@ -43,9 +44,9 @@ namespace osu.Game.Overlays base.Load(game); osuGame = game as OsuGameBase; + beatmapSource = osuGame.Beatmap; if (database == null) database = osuGame.Beatmaps; playList = database.Query().ToList(); - currentPlay = playList.FirstOrDefault(); Width = 400; Height = 130; @@ -180,10 +181,10 @@ namespace osu.Game.Overlays } }; - if (currentPlay != null) + if (beatmapSource.Value != null) { playButton.Icon = FontAwesome.pause; - play(currentPlay, null); + updateCurrent(beatmapSource, null); } } @@ -213,21 +214,16 @@ namespace osu.Game.Overlays play(currentPlay, true); } - private void play(BeatmapSetInfo beatmap, bool? isNext) + private void updateCurrent(WorkingBeatmap beatmap, bool? isNext) { - BeatmapMetadata metadata = osuGame.Beatmaps.Query().Where(x => x.ID == beatmap.BeatmapMetadataID).First(); + BeatmapMetadata metadata = beatmap.Beatmap.Metadata; title.Text = metadata.TitleUnicode ?? metadata.Title; artist.Text = metadata.ArtistUnicode ?? metadata.Artist; Sprite newBackground; - using (ArchiveReader reader = osuGame.Beatmaps.GetReader(currentPlay)) - { - CurrentTrack?.Stop(); - CurrentTrack = new AudioTrackBass(reader.ReadFile(metadata.AudioFile)); - CurrentTrack.Start(); - newBackground = getScaledSprite(TextureLoader.FromStream(reader.ReadFile(metadata.BackgroundFile))); - } + + newBackground = getScaledSprite(TextureLoader.FromStream(beatmap.Reader.ReadFile(metadata.BackgroundFile))); Add(newBackground); From 7d14e6e6cf5400c40b441ea3194bde80067ebf5c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 20:08:27 +0800 Subject: [PATCH 20/48] Make prev and next work again. --- .../Tests/TestCaseMusicController.cs | 1 - osu.Game/Overlays/MusicController.cs | 30 +++++++++++++++---- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs index 524768a122..8706990964 100644 --- a/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs +++ b/osu.Desktop.VisualTests/Tests/TestCaseMusicController.cs @@ -34,7 +34,6 @@ namespace osu.Desktop.Tests { base.Reset(); ourClock.ProcessFrame(); - mc?.CurrentTrack?.Stop(); mc = new MusicController { Origin = Anchor.Centre, diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 6692ace775..d19f982e08 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -186,6 +186,10 @@ namespace osu.Game.Overlays playButton.Icon = FontAwesome.pause; updateCurrent(beatmapSource, null); } + else if (playList.Count > 0) + { + play(playList[0].Beatmaps[0], null); + } } protected override void Update() @@ -196,22 +200,36 @@ namespace osu.Game.Overlays if (CurrentTrack.HasCompleted) next(); } + 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; + } + private void prev() { - int i = playList.IndexOf(currentPlay); + int i = findInPlaylist(beatmapSource.Value?.Beatmap); if (i == -1) return; i = (i - 1 + playList.Count) % playList.Count; - currentPlay = playList[i]; - play(currentPlay, false); + play(playList[i].Beatmaps[0], false); } private void next() { - int i = playList.IndexOf(currentPlay); + int i = findInPlaylist(beatmapSource.Value?.Beatmap); if (i == -1) return; i = (i + 1) % playList.Count; - currentPlay = playList[i]; - play(currentPlay, true); + play(playList[i].Beatmaps[0], true); + } + + private void play(BeatmapInfo info, bool? isNext) + { + WorkingBeatmap working = database.GetWorkingBeatmap(info, beatmapSource.Value); + beatmapSource.Value = working; + updateCurrent(working, isNext); } private void updateCurrent(WorkingBeatmap beatmap, bool? isNext) From aa107de1626d6f4db7255a35c5ac5e4f5aa5c191 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 20:21:19 +0800 Subject: [PATCH 21/48] Store a local copy of WorkingBeatmap. --- osu.Game/Overlays/MusicController.cs | 37 ++++++++++++++-------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index d19f982e08..21d9415019 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -32,7 +32,7 @@ namespace osu.Game.Overlays private List playList; private BeatmapDatabase database; private Bindable beatmapSource; - private AudioTrack CurrentTrack => beatmapSource.Value?.Track; + private WorkingBeatmap current; public MusicController(BeatmapDatabase db = null) { @@ -44,7 +44,8 @@ namespace osu.Game.Overlays base.Load(game); osuGame = game as OsuGameBase; - beatmapSource = osuGame.Beatmap; + beatmapSource = osuGame.Beatmap ?? new Bindable(); + current = beatmapSource.Value; if (database == null) database = osuGame.Beatmaps; playList = database.Query().ToList(); @@ -95,15 +96,15 @@ namespace osu.Game.Overlays Position = new Vector2(0, 30), Action = () => { - if (CurrentTrack == null) return; - if (CurrentTrack.IsRunning) + if (current?.Track == null) return; + if (current.Track.IsRunning) { - CurrentTrack.Stop(); + current.Track.Stop(); playButton.Icon = FontAwesome.play_circle_o; } else { - CurrentTrack.Start(); + current.Track.Start(); playButton.Icon = FontAwesome.pause; } }, @@ -181,10 +182,10 @@ namespace osu.Game.Overlays } }; - if (beatmapSource.Value != null) + if (current != null) { playButton.Icon = FontAwesome.pause; - updateCurrent(beatmapSource, null); + updateCurrent(current, null); } else if (playList.Count > 0) { @@ -195,9 +196,9 @@ namespace osu.Game.Overlays protected override void Update() { base.Update(); - if (CurrentTrack == null) return; - progress.UpdatePosition((float)(CurrentTrack.CurrentTime / CurrentTrack.Length)); - if (CurrentTrack.HasCompleted) next(); + if (current?.Track == null) return; + progress.UpdatePosition((float)(current.Track.CurrentTime / current.Track.Length)); + if (current.Track.HasCompleted) next(); } private int findInPlaylist(Beatmap beatmap) @@ -211,7 +212,7 @@ namespace osu.Game.Overlays private void prev() { - int i = findInPlaylist(beatmapSource.Value?.Beatmap); + int i = findInPlaylist(current?.Beatmap); if (i == -1) return; i = (i - 1 + playList.Count) % playList.Count; play(playList[i].Beatmaps[0], false); @@ -219,7 +220,7 @@ namespace osu.Game.Overlays private void next() { - int i = findInPlaylist(beatmapSource.Value?.Beatmap); + int i = findInPlaylist(current?.Beatmap); if (i == -1) return; i = (i + 1) % playList.Count; play(playList[i].Beatmaps[0], true); @@ -227,9 +228,9 @@ namespace osu.Game.Overlays private void play(BeatmapInfo info, bool? isNext) { - WorkingBeatmap working = database.GetWorkingBeatmap(info, beatmapSource.Value); - beatmapSource.Value = working; - updateCurrent(working, isNext); + current = database.GetWorkingBeatmap(info, current); + beatmapSource.Value = current; + updateCurrent(current, isNext); } private void updateCurrent(WorkingBeatmap beatmap, bool? isNext) @@ -282,8 +283,8 @@ namespace osu.Game.Overlays private void seek(float position) { - CurrentTrack?.Seek(CurrentTrack.Length * position); - CurrentTrack?.Start(); + current?.Track?.Seek(current.Track.Length * position); + current?.Track?.Start(); } //placeholder for toggling From 36cefcb9561c8b5d73c757e07c0de26840d1c315 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 20:34:22 +0800 Subject: [PATCH 22/48] Fix to work individually. --- osu.Game/Overlays/MusicController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 21d9415019..73f59f3d4e 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -29,6 +29,7 @@ namespace osu.Game.Overlays private SpriteText title, artist; private OsuGameBase osuGame; + private TrackManager trackManager; private List playList; private BeatmapDatabase database; private Bindable beatmapSource; @@ -47,7 +48,8 @@ namespace osu.Game.Overlays beatmapSource = osuGame.Beatmap ?? new Bindable(); current = beatmapSource.Value; if (database == null) database = osuGame.Beatmaps; - playList = database.Query().ToList(); + trackManager = osuGame.Audio.Track; + playList = database.GetAllWithChildren(); Width = 400; Height = 130; @@ -229,6 +231,8 @@ namespace osu.Game.Overlays private void play(BeatmapInfo info, bool? isNext) { current = database.GetWorkingBeatmap(info, current); + trackManager.SetExclusive(current.Track); + current.Track.Start(); beatmapSource.Value = current; updateCurrent(current, isNext); } From 9b76110605fc9955cafc0d2190697284e2f164f3 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 20:44:59 +0800 Subject: [PATCH 23/48] Interaction with external changes. --- osu.Game/Overlays/MusicController.cs | 27 ++++++++++++--------------- 1 file changed, 12 insertions(+), 15 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 73f59f3d4e..97208a653a 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -46,7 +46,8 @@ namespace osu.Game.Overlays osuGame = game as OsuGameBase; beatmapSource = osuGame.Beatmap ?? new Bindable(); - current = beatmapSource.Value; + beatmapSource.ValueChanged += workingChanged; + workingChanged(); if (database == null) database = osuGame.Beatmaps; trackManager = osuGame.Audio.Track; playList = database.GetAllWithChildren(); @@ -100,15 +101,9 @@ namespace osu.Game.Overlays { if (current?.Track == null) return; if (current.Track.IsRunning) - { current.Track.Stop(); - playButton.Icon = FontAwesome.play_circle_o; - } else - { current.Track.Start(); - playButton.Icon = FontAwesome.pause; - } }, Children = new Drawable[] { @@ -184,25 +179,27 @@ namespace osu.Game.Overlays } }; - if (current != null) - { - playButton.Icon = FontAwesome.pause; - updateCurrent(current, null); - } - else if (playList.Count > 0) - { + if (current == null && playList.Count > 0) play(playList[0].Beatmaps[0], null); - } } protected override void Update() { base.Update(); if (current?.Track == null) return; + progress.UpdatePosition((float)(current.Track.CurrentTime / current.Track.Length)); + playButton.Icon = current.Track.IsRunning ? FontAwesome.pause : FontAwesome.play_circle_o; + if (current.Track.HasCompleted) next(); } + private void workingChanged(object sender = null, EventArgs e = null) + { + if (beatmapSource.Value == current) return; + updateCurrent(current, null); + } + private int findInPlaylist(Beatmap beatmap) { if (beatmap == null) return -1; From 3858c778170b3fa24ac557d6962db3d99c8cd26c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 20:47:14 +0800 Subject: [PATCH 24/48] No longer holds OsuGame reference. --- osu.Game/Overlays/MusicController.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 97208a653a..e9ee3d2918 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -3,7 +3,6 @@ using System; using System.Collections.Generic; -using System.Linq; using OpenTK; using OpenTK.Graphics; using osu.Framework; @@ -15,7 +14,6 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Transformations; using osu.Game.Beatmaps; -using osu.Game.Beatmaps.IO; using osu.Game.Database; using osu.Game.Graphics; @@ -28,7 +26,6 @@ namespace osu.Game.Overlays private TextAwesome playButton, listButton; private SpriteText title, artist; - private OsuGameBase osuGame; private TrackManager trackManager; private List playList; private BeatmapDatabase database; @@ -43,13 +40,17 @@ namespace osu.Game.Overlays public override void Load(BaseGame game) { base.Load(game); - osuGame = game as OsuGameBase; + var osuGame = game as OsuGameBase; - beatmapSource = osuGame.Beatmap ?? new Bindable(); + if (osuGame != null) + { + if (database == null) database = osuGame.Beatmaps; + trackManager = osuGame.Audio.Track; + } + + beatmapSource = osuGame?.Beatmap ?? new Bindable(); beatmapSource.ValueChanged += workingChanged; workingChanged(); - if (database == null) database = osuGame.Beatmaps; - trackManager = osuGame.Audio.Track; playList = database.GetAllWithChildren(); Width = 400; From 6aba03e1cacffc11c5c57357f3e680da34bf7faf Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 21:03:59 +0800 Subject: [PATCH 25/48] OsuGameMode<-WorkingBeatMap->OsuGameBase. --- osu.Game/GameModes/OsuGameMode.cs | 7 +++++++ osu.Game/OsuGameBase.cs | 1 - 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/osu.Game/GameModes/OsuGameMode.cs b/osu.Game/GameModes/OsuGameMode.cs index d8b73f5f07..05a98d0623 100644 --- a/osu.Game/GameModes/OsuGameMode.cs +++ b/osu.Game/GameModes/OsuGameMode.cs @@ -7,6 +7,7 @@ using System.Diagnostics; using System.Linq; using System.Text; using System.Threading.Tasks; +using osu.Framework; using osu.Framework.Configuration; using osu.Framework.GameModes; using osu.Framework.Graphics.Containers; @@ -68,6 +69,12 @@ namespace osu.Game.GameModes OnBeatmapChanged(beatmap.Value); } + public override void Load(BaseGame game) + { + base.Load(game); + beatmap = (game as OsuGameBase)?.Beatmap; + } + public override bool Push(GameMode mode) { OsuGameMode nextOsu = mode as OsuGameMode; diff --git a/osu.Game/OsuGameBase.cs b/osu.Game/OsuGameBase.cs index bfa07d72c8..ccd3026841 100644 --- a/osu.Game/OsuGameBase.cs +++ b/osu.Game/OsuGameBase.cs @@ -52,7 +52,6 @@ namespace osu.Game private void Beatmap_ValueChanged(object sender, EventArgs e) { - throw new NotImplementedException(); } public override void Load(BaseGame game) From 7543d491aee30545d76e25a71a894bf4b86aa32f Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 21:21:47 +0800 Subject: [PATCH 26/48] Add music controller into game. --- osu.Game/OsuGame.cs | 3 +++ osu.Game/Overlays/MusicController.cs | 12 +++++++----- osu.Game/Overlays/Toolbar.cs | 6 ++++++ 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 2515ace38e..936f7c3017 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -25,6 +25,7 @@ namespace osu.Game { public Toolbar Toolbar; public ChatConsole Chat; + public MusicController MusicController; public MainMenu MainMenu => intro?.ChildGameMode as MainMenu; private Intro intro; @@ -74,11 +75,13 @@ namespace osu.Game { Beatmap = Beatmap }, + MusicController = new MusicController(), Toolbar = new Toolbar { OnHome = delegate { MainMenu?.MakeCurrent(); }, OnSettings = Options.ToggleVisibility, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, + OnMusicController = MusicController.ToggleVisibility, }, Chat = new ChatConsole(API), volume = new VolumeControl diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index e9ee3d2918..f2bb7d83dc 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -35,6 +35,13 @@ namespace osu.Game.Overlays public MusicController(BeatmapDatabase db = null) { database = db; + Width = 400; + Height = 130; + CornerRadius = 5; + Masking = true; + Anchor = Anchor.TopRight;//placeholder + Origin = Anchor.TopRight; + Position = new Vector2(10, 50); } public override void Load(BaseGame game) @@ -53,11 +60,6 @@ namespace osu.Game.Overlays workingChanged(); playList = database.GetAllWithChildren(); - Width = 400; - Height = 130; - CornerRadius = 5; - Masking = true; - Children = new Drawable[] { backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4")),//placeholder diff --git a/osu.Game/Overlays/Toolbar.cs b/osu.Game/Overlays/Toolbar.cs index 5e85dd832e..90c73da1e0 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -22,6 +22,7 @@ namespace osu.Game.Overlays public Action OnSettings; public Action OnHome; public Action OnPlayModeChange; + public Action OnMusicController; private ToolbarModeSelector modeSelector; @@ -89,6 +90,11 @@ namespace osu.Game.Overlays AutoSizeAxes = Axes.X, Children = new [] { + new ToolbarButton + { + Icon = FontAwesome.music, + Action = OnMusicController + }, new ToolbarButton { Icon = FontAwesome.search From f1837b482248c329d0e9343ccb9be3676ff029a0 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Fri, 28 Oct 2016 21:57:23 +0800 Subject: [PATCH 27/48] Fix changed event and no longer auto play on load. --- osu.Game/Overlays/MusicController.cs | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index f2bb7d83dc..21a52167a9 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -181,9 +181,6 @@ namespace osu.Game.Overlays SeekRequested = seek } }; - - if (current == null && playList.Count > 0) - play(playList[0].Beatmaps[0], null); } protected override void Update() @@ -200,6 +197,7 @@ namespace osu.Game.Overlays private void workingChanged(object sender = null, EventArgs e = null) { if (beatmapSource.Value == current) return; + current = beatmapSource.Value; updateCurrent(current, null); } @@ -215,7 +213,12 @@ namespace osu.Game.Overlays private void prev() { int i = findInPlaylist(current?.Beatmap); - if (i == -1) return; + if (i == -1) + { + if (playList.Count > 0) + play(playList[0].Beatmaps[0], null); + else return; + } i = (i - 1 + playList.Count) % playList.Count; play(playList[i].Beatmaps[0], false); } @@ -223,7 +226,12 @@ namespace osu.Game.Overlays private void next() { int i = findInPlaylist(current?.Beatmap); - if (i == -1) return; + if (i == -1) + { + if (playList.Count > 0) + play(playList[0].Beatmaps[0], null); + else return; + } i = (i + 1) % playList.Count; play(playList[i].Beatmaps[0], true); } From 9e0fbed748211e3d8c4fd6571813cd6859d32a0a Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Thu, 3 Nov 2016 22:38:10 +0800 Subject: [PATCH 28/48] Use PreLoad on music controller. --- osu.Game/OsuGame.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/osu.Game/OsuGame.cs b/osu.Game/OsuGame.cs index 0c634512ad..f13675799d 100644 --- a/osu.Game/OsuGame.cs +++ b/osu.Game/OsuGame.cs @@ -103,12 +103,14 @@ namespace osu.Game }); (Chat = new ChatConsole(API)).Preload(game, Add); + (MusicController = new MusicController()).Preload(game, Add); (Toolbar = new Toolbar { OnHome = delegate { MainMenu?.MakeCurrent(); }, OnSettings = Options.ToggleVisibility, OnPlayModeChange = delegate (PlayMode m) { PlayMode.Value = m; }, + OnMusicController = MusicController.ToggleVisibility }).Preload(game, t => { PlayMode.ValueChanged += delegate { Toolbar.SetGameMode(PlayMode.Value); }; From 5eed07db57fd83da7d92b5a7f651b4e7c879b920 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 00:13:45 +0800 Subject: [PATCH 29/48] Update access of WorkingBeatmap. --- osu.Game/Overlays/MusicController.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index ff8872cc19..ab6836fd0a 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -251,10 +251,7 @@ namespace osu.Game.Overlays title.Text = metadata.TitleUnicode ?? metadata.Title; artist.Text = metadata.ArtistUnicode ?? metadata.Artist; - Sprite newBackground; - - - newBackground = getScaledSprite(TextureLoader.FromStream(beatmap.Reader.ReadFile(metadata.BackgroundFile))); + Sprite newBackground = getScaledSprite(beatmap.Background); Add(newBackground); From 859a59a8abecb6900a374f7545f671bffa72fc85 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 00:24:03 +0800 Subject: [PATCH 30/48] Set children in constructor. --- osu.Game/Overlays/MusicController.cs | 39 ++++++++++++++-------------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index ab6836fd0a..7ce13f736d 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -42,27 +42,8 @@ namespace osu.Game.Overlays Anchor = Anchor.TopRight;//placeholder Origin = Anchor.TopRight; Position = new Vector2(10, 50); - } - - 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(); - beatmapSource.ValueChanged += workingChanged; - workingChanged(); - playList = database.GetAllWithChildren(); - Children = new Drawable[] { - backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4")),//placeholder new Box { RelativeSizeAxes = Axes.Both, @@ -183,6 +164,26 @@ namespace osu.Game.Overlays }; } + 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(); + beatmapSource.ValueChanged += workingChanged; + workingChanged(); + playList = database.GetAllWithChildren(); + + backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4")); + AddInternal(backgroundSprite); + } + protected override void Update() { base.Update(); From a19bb1270d3ef6a5a4f087832b716be58d1cb5d0 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 00:46:09 +0800 Subject: [PATCH 31/48] Async workflow on music controller. --- osu.Game/Overlays/MusicController.cs | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 7ce13f736d..8f448b68a1 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; +using System.Threading.Tasks; using OpenTK; using OpenTK.Graphics; using osu.Framework; @@ -177,13 +178,18 @@ namespace osu.Game.Overlays beatmapSource = osuGame?.Beatmap ?? new Bindable(); beatmapSource.ValueChanged += workingChanged; - workingChanged(); playList = database.GetAllWithChildren(); backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4")); AddInternal(backgroundSprite); } + protected override void LoadComplete() + { + workingChanged(); + base.LoadComplete(); + } + protected override void Update() { base.Update(); @@ -240,10 +246,13 @@ namespace osu.Game.Overlays private void play(BeatmapInfo info, bool? isNext) { current = database.GetWorkingBeatmap(info, current); - trackManager.SetExclusive(current.Track); - current.Track.Start(); - beatmapSource.Value = current; - updateCurrent(current, isNext); + Task.Factory.StartNew(() => + { + trackManager.SetExclusive(current.Track); + current.Track.Start(); + beatmapSource.Value = current; + updateCurrent(current, isNext); + }); } private void updateCurrent(WorkingBeatmap beatmap, bool? isNext) From 74000f77ad513f3e6aa076d5c343c5a6038e9014 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 01:50:38 +0800 Subject: [PATCH 32/48] Set font in music controller. --- osu.Game/Overlays/MusicController.cs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 8f448b68a1..8485d9d802 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -57,7 +57,8 @@ namespace osu.Game.Overlays Position = new Vector2(0, 40), TextSize = 20, Colour = Color4.White, - Text = @"Nothing to play" + Text = @"Nothing to play", + Font = @"Exo2.0-MediumItalic" }, artist = new SpriteText { @@ -66,7 +67,8 @@ namespace osu.Game.Overlays Position = new Vector2(0, 45), TextSize = 12, Colour = Color4.White, - Text = @"Nothing to play" + Text = @"Nothing to play", + Font = @"Exo2.0-BoldItalic" }, new Box { From c53298a3b1178b7856e0386a18f6cfd4e45a8c83 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 01:53:10 +0800 Subject: [PATCH 33/48] Update font size (*1.25) to follow the design image. --- osu.Game/Overlays/MusicController.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 8485d9d802..0d94b8ead4 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -55,7 +55,7 @@ namespace osu.Game.Overlays Origin = Anchor.BottomCentre, Anchor = Anchor.TopCentre, Position = new Vector2(0, 40), - TextSize = 20, + TextSize = 25, Colour = Color4.White, Text = @"Nothing to play", Font = @"Exo2.0-MediumItalic" @@ -65,7 +65,7 @@ namespace osu.Game.Overlays Origin = Anchor.TopCentre, Anchor = Anchor.TopCentre, Position = new Vector2(0, 45), - TextSize = 12, + TextSize = 15, Colour = Color4.White, Text = @"Nothing to play", Font = @"Exo2.0-BoldItalic" From 2bd447ca56f9ffa4bab187749d91e8242e079f76 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 05:33:44 +0800 Subject: [PATCH 34/48] Update framework. --- osu-framework | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu-framework b/osu-framework index ed33cc4899..7d0cb3b1db 160000 --- a/osu-framework +++ b/osu-framework @@ -1 +1 @@ -Subproject commit ed33cc48996e9b57093c4d057aa0560319495dee +Subproject commit 7d0cb3b1db8f9f684e83000431689c27e3e0f619 From 0c6825bb209ccaff6052dee354670cda2a56a695 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 05:35:35 +0800 Subject: [PATCH 35/48] Adjust visual behavior. --- osu.Game/Overlays/MusicController.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 0d94b8ead4..1984f132c9 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -42,7 +42,7 @@ namespace osu.Game.Overlays Masking = true; Anchor = Anchor.TopRight;//placeholder Origin = Anchor.TopRight; - Position = new Vector2(10, 50); + Position = new Vector2(10, 60); Children = new Drawable[] { new Box @@ -309,8 +309,8 @@ namespace osu.Game.Overlays } //placeholder for toggling - protected override void PopIn() => FadeIn(500); + protected override void PopIn() => FadeIn(100); - protected override void PopOut() => FadeOut(500); + protected override void PopOut() => FadeOut(100); } } From d63e3b67248865ac9e978275b3b2b854eccf0f51 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 05:37:55 +0800 Subject: [PATCH 36/48] Add fallback texture of beatmap when getting null; --- osu.Game/Overlays/MusicController.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 1984f132c9..f3ce453502 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -26,6 +26,7 @@ namespace osu.Game.Overlays private DragBar progress; private TextAwesome playButton, listButton; private SpriteText title, artist; + private Texture fallbackTexture; private TrackManager trackManager; private List playList; @@ -182,7 +183,7 @@ namespace osu.Game.Overlays beatmapSource.ValueChanged += workingChanged; playList = database.GetAllWithChildren(); - backgroundSprite = getScaledSprite(game.Textures.Get(@"Backgrounds/bg4")); + backgroundSprite = getScaledSprite(fallbackTexture = game.Textures.Get(@"Backgrounds/bg4")); AddInternal(backgroundSprite); } @@ -263,7 +264,7 @@ namespace osu.Game.Overlays title.Text = metadata.TitleUnicode ?? metadata.Title; artist.Text = metadata.ArtistUnicode ?? metadata.Artist; - Sprite newBackground = getScaledSprite(beatmap.Background); + Sprite newBackground = getScaledSprite(beatmap.Background ?? fallbackTexture); Add(newBackground); From 000c2218b89742e912b8f9792091df5c4f41158c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 16:34:47 +0800 Subject: [PATCH 37/48] Make background update happens in update thread, and thread-safer. --- osu.Game/Overlays/MusicController.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index f3ce453502..3f025792a9 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -249,13 +249,13 @@ namespace osu.Game.Overlays private void play(BeatmapInfo info, bool? isNext) { current = database.GetWorkingBeatmap(info, current); - Task.Factory.StartNew(() => + Task.Run(() => { trackManager.SetExclusive(current.Track); current.Track.Start(); beatmapSource.Value = current; - updateCurrent(current, isNext); }); + updateCurrent(current, isNext); } private void updateCurrent(WorkingBeatmap beatmap, bool? isNext) @@ -284,7 +284,7 @@ namespace osu.Game.Overlays } else { - Remove(backgroundSprite); + backgroundSprite.Expire(); } backgroundSprite = newBackground; From c8a7bd2ecee41bc43c852bbcf8b22342cfa6d97c Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Sun, 6 Nov 2016 16:42:40 +0800 Subject: [PATCH 38/48] Minor implementation changes. --- osu.Game/Overlays/MusicController.cs | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 3f025792a9..f77d851543 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -180,7 +180,6 @@ namespace osu.Game.Overlays } beatmapSource = osuGame?.Beatmap ?? new Bindable(); - beatmapSource.ValueChanged += workingChanged; playList = database.GetAllWithChildren(); backgroundSprite = getScaledSprite(fallbackTexture = game.Textures.Get(@"Backgrounds/bg4")); @@ -189,6 +188,7 @@ namespace osu.Game.Overlays protected override void LoadComplete() { + beatmapSource.ValueChanged += workingChanged; workingChanged(); base.LoadComplete(); } @@ -201,7 +201,7 @@ namespace osu.Game.Overlays progress.UpdatePosition((float)(current.Track.CurrentTime / current.Track.Length)); playButton.Icon = current.Track.IsRunning ? FontAwesome.pause : FontAwesome.play_circle_o; - if (current.Track.HasCompleted) next(); + if (current.Track.HasCompleted && !current.Track.Looping) next(); } private void workingChanged(object sender = null, EventArgs e = null) @@ -273,19 +273,14 @@ namespace osu.Game.Overlays newBackground.Position = new Vector2(400, 0); newBackground.MoveToX(0, 500, EasingTypes.OutCubic); backgroundSprite.MoveToX(-400, 500, EasingTypes.OutCubic); - backgroundSprite.Expire(); } else if (isNext == false) { newBackground.Position = new Vector2(-400, 0); newBackground.MoveToX(0, 500, EasingTypes.OutCubic); backgroundSprite.MoveToX(400, 500, EasingTypes.OutCubic); - backgroundSprite.Expire(); - } - else - { - backgroundSprite.Expire(); } + backgroundSprite.Expire(); backgroundSprite = newBackground; } From 736079a60da5fb8e948140e5cd283a7f8cf23396 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 19:00:20 +0800 Subject: [PATCH 39/48] Update FontAwesome usage. --- osu.Game/Overlays/MusicController.cs | 10 +++++----- osu.Game/Overlays/Toolbar.cs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index f77d851543..632e643a10 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -98,7 +98,7 @@ namespace osu.Game.Overlays playButton = new TextAwesome { TextSize = 30, - Icon = FontAwesome.play_circle_o, + Icon = FontAwesome.fa_play_circle_o, Origin = Anchor.Centre, Anchor = Anchor.Centre } @@ -116,7 +116,7 @@ namespace osu.Game.Overlays new TextAwesome { TextSize = 15, - Icon = FontAwesome.step_backward, + Icon = FontAwesome.fa_step_backward, Origin = Anchor.Centre, Anchor = Anchor.Centre } @@ -134,7 +134,7 @@ namespace osu.Game.Overlays new TextAwesome { TextSize = 15, - Icon = FontAwesome.step_forward, + Icon = FontAwesome.fa_step_forward, Origin = Anchor.Centre, Anchor = Anchor.Centre } @@ -151,7 +151,7 @@ namespace osu.Game.Overlays listButton = new TextAwesome { TextSize = 15, - Icon = FontAwesome.bars, + Icon = FontAwesome.fa_bars, Origin = Anchor.Centre, Anchor = Anchor.Centre } @@ -199,7 +199,7 @@ namespace osu.Game.Overlays if (current?.Track == null) return; progress.UpdatePosition((float)(current.Track.CurrentTime / current.Track.Length)); - playButton.Icon = current.Track.IsRunning ? FontAwesome.pause : FontAwesome.play_circle_o; + playButton.Icon = current.Track.IsRunning ? FontAwesome.fa_pause_circle_o : FontAwesome.fa_play_circle_o; if (current.Track.HasCompleted && !current.Track.Looping) next(); } diff --git a/osu.Game/Overlays/Toolbar.cs b/osu.Game/Overlays/Toolbar.cs index 2af9466b56..f4c5d356dd 100644 --- a/osu.Game/Overlays/Toolbar.cs +++ b/osu.Game/Overlays/Toolbar.cs @@ -88,7 +88,7 @@ namespace osu.Game.Overlays { new ToolbarButton { - Icon = FontAwesome.music, + Icon = FontAwesome.fa_music, Action = () => OnMusicController?.Invoke() }, new ToolbarButton From c272041f3727dd8eb9bc3808dfed11fd4c782bc3 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 20:07:45 +0800 Subject: [PATCH 40/48] Block click and drag at MusicController level. --- osu.Game/Overlays/MusicController.cs | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 632e643a10..26f335750e 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -14,6 +14,7 @@ using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Transformations; +using osu.Framework.Input; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Graphics; @@ -304,6 +305,12 @@ namespace osu.Game.Overlays current?.Track?.Start(); } + protected override bool OnClick(InputState state) => true; + + protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true; + + protected override bool OnDragStart(InputState state) => true; + //placeholder for toggling protected override void PopIn() => FadeIn(100); From 644e337cf6b6b6e89bcffdebd6a40bfd4268d4ac Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 20:57:33 +0800 Subject: [PATCH 41/48] Add a list for play history. --- osu.Game/Overlays/MusicController.cs | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 26f335750e..43e8b73076 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -29,8 +29,12 @@ namespace osu.Game.Overlays private SpriteText title, artist; private Texture fallbackTexture; - private TrackManager trackManager; private List playList; + private List playHistory; + private int playListIndex; + private int playHistoryIndex; + + private TrackManager trackManager; private BeatmapDatabase database; private Bindable beatmapSource; private WorkingBeatmap current; From ad1dccf6ceca2707c607bc9905add924cc556006 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 21:25:37 +0800 Subject: [PATCH 42/48] Use play history for back and forward. --- osu.Game/Overlays/MusicController.cs | 45 +++++++++++++--------------- 1 file changed, 21 insertions(+), 24 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 43e8b73076..c9099921cf 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -30,9 +30,9 @@ namespace osu.Game.Overlays private Texture fallbackTexture; private List playList; - private List playHistory; + private List playHistory = new List(); private int playListIndex; - private int playHistoryIndex; + private int playHistoryIndex = -1; private TrackManager trackManager; private BeatmapDatabase database; @@ -216,39 +216,36 @@ namespace osu.Game.Overlays updateCurrent(current, null); } - private int findInPlaylist(Beatmap beatmap) + private void appendToHistory(BeatmapInfo 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; + if (playHistoryIndex >= 0) + { + BeatmapInfo stackHead = playHistory[playHistoryIndex]; + if (beatmap.BeatmapSet.Path == stackHead.BeatmapSet.Path && beatmap.Metadata.AudioFile == stackHead.Metadata.AudioFile) + return; + if (playHistoryIndex < playHistory.Count - 1) + playHistory.RemoveRange(playHistoryIndex + 1, playHistory.Count - playHistoryIndex - 1); + } + playHistory.Insert(++playHistoryIndex, beatmap); } private void prev() { - int i = findInPlaylist(current?.Beatmap); - if (i == -1) - { - if (playList.Count > 0) - play(playList[0].Beatmaps[0], null); - else return; - } - i = (i - 1 + playList.Count) % playList.Count; - play(playList[i].Beatmaps[0], false); + if (playHistoryIndex > 0) + play(playHistory[--playHistoryIndex], false); } private void next() { - int i = findInPlaylist(current?.Beatmap); - if (i == -1) + if (playHistoryIndex < playHistory.Count - 1) + play(playHistory[++playHistoryIndex], true); + else { - if (playList.Count > 0) - play(playList[0].Beatmaps[0], null); - else return; + BeatmapInfo nextToPlay = playList[playListIndex++].Beatmaps[0]; + if (playListIndex == playList.Count) playListIndex = 0; + play(nextToPlay, true); + appendToHistory(nextToPlay); } - i = (i + 1) % playList.Count; - play(playList[i].Beatmaps[0], true); } private void play(BeatmapInfo info, bool? isNext) From d1f64cfbfcbe24bd304f754837e6983cb2db5e46 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 21:30:25 +0800 Subject: [PATCH 43/48] Make external changes into history. --- osu.Game/Overlays/MusicController.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index c9099921cf..043ae6e795 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -213,7 +213,8 @@ namespace osu.Game.Overlays { if (beatmapSource.Value == current) return; current = beatmapSource.Value; - updateCurrent(current, null); + updateCurrent(current, true); + appendToHistory(current.BeatmapInfo); } private void appendToHistory(BeatmapInfo beatmap) @@ -248,7 +249,7 @@ namespace osu.Game.Overlays } } - private void play(BeatmapInfo info, bool? isNext) + private void play(BeatmapInfo info, bool isNext) { current = database.GetWorkingBeatmap(info, current); Task.Run(() => @@ -260,7 +261,7 @@ namespace osu.Game.Overlays updateCurrent(current, isNext); } - private void updateCurrent(WorkingBeatmap beatmap, bool? isNext) + private void updateCurrent(WorkingBeatmap beatmap, bool isNext) { BeatmapMetadata metadata = beatmap.Beatmap.Metadata; title.Text = metadata.TitleUnicode ?? metadata.Title; @@ -270,13 +271,13 @@ namespace osu.Game.Overlays Add(newBackground); - if (isNext == true) + if (isNext) { newBackground.Position = new Vector2(400, 0); newBackground.MoveToX(0, 500, EasingTypes.OutCubic); backgroundSprite.MoveToX(-400, 500, EasingTypes.OutCubic); } - else if (isNext == false) + else { newBackground.Position = new Vector2(-400, 0); newBackground.MoveToX(0, 500, EasingTypes.OutCubic); From c59cad247802bab03f507002c9379c00c002a8f1 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 21:52:23 +0800 Subject: [PATCH 44/48] AudioEquals method for BeatmapInfo. --- osu.Game/Beatmaps/WorkingBeatmap.cs | 2 +- osu.Game/Database/BeatmapInfo.cs | 16 +++++++++------- osu.Game/Overlays/MusicController.cs | 3 +-- 3 files changed, 11 insertions(+), 10 deletions(-) diff --git a/osu.Game/Beatmaps/WorkingBeatmap.cs b/osu.Game/Beatmaps/WorkingBeatmap.cs index 417e289b65..63a33c700e 100644 --- a/osu.Game/Beatmaps/WorkingBeatmap.cs +++ b/osu.Game/Beatmaps/WorkingBeatmap.cs @@ -120,7 +120,7 @@ namespace osu.Game.Beatmaps public void TransferTo(WorkingBeatmap working) { - if (track != null && working.BeatmapInfo.Metadata.AudioFile == BeatmapInfo.Metadata.AudioFile && working.BeatmapInfo.BeatmapSet.Path == BeatmapInfo.BeatmapSet.Path) + if (track != null && BeatmapInfo.AudioEquals(working.BeatmapInfo)) working.track = track; } } diff --git a/osu.Game/Database/BeatmapInfo.cs b/osu.Game/Database/BeatmapInfo.cs index 4d18976ef0..f5924bb9eb 100644 --- a/osu.Game/Database/BeatmapInfo.cs +++ b/osu.Game/Database/BeatmapInfo.cs @@ -17,7 +17,7 @@ namespace osu.Game.Database [ManyToOne] public BeatmapSetInfo BeatmapSet { get; set; } - + [ForeignKey(typeof(BeatmapMetadata))] public int BeatmapMetadataID { get; set; } @@ -29,9 +29,9 @@ namespace osu.Game.Database [OneToOne(CascadeOperations = CascadeOperation.All)] public BaseDifficulty BaseDifficulty { get; set; } - + public string Path { get; set; } - + // General public int AudioLeadIn { get; set; } public bool Countdown { get; set; } @@ -41,7 +41,7 @@ namespace osu.Game.Database public PlayMode Mode { get; set; } public bool LetterboxInBreaks { get; set; } public bool WidescreenStoryboard { get; set; } - + // Editor // This bookmarks stuff is necessary because DB doesn't know how to store int[] public string StoredBookmarks { get; internal set; } @@ -61,13 +61,15 @@ namespace osu.Game.Database public int BeatDivisor { get; set; } public int GridSize { get; set; } public double TimelineZoom { get; set; } - + // Metadata public string Version { get; set; } public bool Equals(BeatmapInfo other) { return BeatmapID == other?.BeatmapID; - } + } + + public bool AudioEquals(BeatmapInfo other) => BeatmapSet.Path == other.BeatmapSet.Path && Metadata.AudioFile == other.Metadata.AudioFile; } -} \ No newline at end of file +} diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 043ae6e795..4c30b3e4f3 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -221,8 +221,7 @@ namespace osu.Game.Overlays { if (playHistoryIndex >= 0) { - BeatmapInfo stackHead = playHistory[playHistoryIndex]; - if (beatmap.BeatmapSet.Path == stackHead.BeatmapSet.Path && beatmap.Metadata.AudioFile == stackHead.Metadata.AudioFile) + if (beatmap.AudioEquals(playHistory[playHistoryIndex])) return; if (playHistoryIndex < playHistory.Count - 1) playHistory.RemoveRange(playHistoryIndex + 1, playHistory.Count - playHistoryIndex - 1); From dc347a74f59e5a209ebf5c076b5f6bf698fd92ba Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 21:58:30 +0800 Subject: [PATCH 45/48] Don't play transition if audio equals. --- osu.Game/Overlays/MusicController.cs | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 4c30b3e4f3..77e0a2e667 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -212,8 +212,9 @@ namespace osu.Game.Overlays private void workingChanged(object sender = null, EventArgs e = null) { if (beatmapSource.Value == current) return; + bool audioEquals = current?.BeatmapInfo.AudioEquals(beatmapSource.Value.BeatmapInfo) ?? false; current = beatmapSource.Value; - updateCurrent(current, true); + updateDisplay(current, audioEquals ? null : (bool?)true); appendToHistory(current.BeatmapInfo); } @@ -257,10 +258,10 @@ namespace osu.Game.Overlays current.Track.Start(); beatmapSource.Value = current; }); - updateCurrent(current, isNext); + updateDisplay(current, isNext); } - private void updateCurrent(WorkingBeatmap beatmap, bool isNext) + private void updateDisplay(WorkingBeatmap beatmap, bool? isNext) { BeatmapMetadata metadata = beatmap.Beatmap.Metadata; title.Text = metadata.TitleUnicode ?? metadata.Title; @@ -270,13 +271,13 @@ namespace osu.Game.Overlays Add(newBackground); - if (isNext) + if (isNext == true) { newBackground.Position = new Vector2(400, 0); newBackground.MoveToX(0, 500, EasingTypes.OutCubic); backgroundSprite.MoveToX(-400, 500, EasingTypes.OutCubic); } - else + else if (isNext == false) { newBackground.Position = new Vector2(-400, 0); newBackground.MoveToX(0, 500, EasingTypes.OutCubic); From 02b903f1ea31ac84053a9b57db6370f5b1c4ff48 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 22:12:58 +0800 Subject: [PATCH 46/48] Shuffle playlist. --- osu.Game/Overlays/MusicController.cs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index 77e0a2e667..a1928caf0b 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -15,6 +15,7 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.Textures; using osu.Framework.Graphics.Transformations; using osu.Framework.Input; +using osu.Framework.MathUtils; using osu.Game.Beatmaps; using osu.Game.Database; using osu.Game.Graphics; @@ -242,6 +243,15 @@ namespace osu.Game.Overlays play(playHistory[++playHistoryIndex], true); else { + //shuffle + int j = RNG.Next(playListIndex, playList.Count); + if (j != playListIndex) + { + BeatmapSetInfo temp = playList[playListIndex]; + playList[playListIndex] = playList[j]; + playList[j] = temp; + } + BeatmapInfo nextToPlay = playList[playListIndex++].Beatmaps[0]; if (playListIndex == playList.Count) playListIndex = 0; play(nextToPlay, true); From fd977cacb346c663d5d2a9a3b6da833b2ea47ac3 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 23:06:14 +0800 Subject: [PATCH 47/48] Fix corner case when shuffling. --- osu.Game/Overlays/MusicController.cs | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index a1928caf0b..ba03246842 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -243,17 +243,25 @@ namespace osu.Game.Overlays play(playHistory[++playHistoryIndex], true); else { + if (playList.Count == 0) return; + if (current != null && playList.Count == 1) return; //shuffle - int j = RNG.Next(playListIndex, playList.Count); - if (j != playListIndex) + BeatmapInfo nextToPlay; + do { - BeatmapSetInfo temp = playList[playListIndex]; - playList[playListIndex] = playList[j]; - playList[j] = temp; - } + int j = RNG.Next(playListIndex, playList.Count); + if (j != playListIndex) + { + BeatmapSetInfo temp = playList[playListIndex]; + playList[playListIndex] = playList[j]; + playList[j] = temp; + } + + nextToPlay = playList[playListIndex++].Beatmaps[0]; + if (playListIndex == playList.Count) playListIndex = 0; + } + while (current?.BeatmapInfo.AudioEquals(nextToPlay) == true); - BeatmapInfo nextToPlay = playList[playListIndex++].Beatmaps[0]; - if (playListIndex == playList.Count) playListIndex = 0; play(nextToPlay, true); appendToHistory(nextToPlay); } From ef5968e2434d93ae5b37577e6663a9f0e95af965 Mon Sep 17 00:00:00 2001 From: Huo Yaoyuan Date: Mon, 7 Nov 2016 23:12:49 +0800 Subject: [PATCH 48/48] More robust metadata handling. --- osu.Game/Database/BeatmapInfo.cs | 138 ++++++++++++++------------- osu.Game/Overlays/MusicController.cs | 2 +- 2 files changed, 71 insertions(+), 69 deletions(-) diff --git a/osu.Game/Database/BeatmapInfo.cs b/osu.Game/Database/BeatmapInfo.cs index f5924bb9eb..14bfcb337e 100644 --- a/osu.Game/Database/BeatmapInfo.cs +++ b/osu.Game/Database/BeatmapInfo.cs @@ -1,75 +1,77 @@ -using System; -using System.Linq; -using osu.Game.Beatmaps.Samples; -using osu.Game.GameModes.Play; -using SQLite.Net.Attributes; -using SQLiteNetExtensions.Attributes; - -namespace osu.Game.Database -{ - public class BeatmapInfo : IEquatable - { - [PrimaryKey] +using System; +using System.Linq; +using osu.Game.Beatmaps.Samples; +using osu.Game.GameModes.Play; +using SQLite.Net.Attributes; +using SQLiteNetExtensions.Attributes; + +namespace osu.Game.Database +{ + public class BeatmapInfo : IEquatable + { + [PrimaryKey] public int BeatmapID { get; set; } - [ForeignKey(typeof(BeatmapSetInfo))] - public int BeatmapSetID { get; set; } - - [ManyToOne] - public BeatmapSetInfo BeatmapSet { get; set; } - - [ForeignKey(typeof(BeatmapMetadata))] - public int BeatmapMetadataID { get; set; } - - [OneToOne(CascadeOperations = CascadeOperation.All)] + [ForeignKey(typeof(BeatmapSetInfo))] + public int BeatmapSetID { get; set; } + + [ManyToOne] + public BeatmapSetInfo BeatmapSet { get; set; } + + [ForeignKey(typeof(BeatmapMetadata))] + public int BeatmapMetadataID { get; set; } + + [OneToOne(CascadeOperations = CascadeOperation.All)] public BeatmapMetadata Metadata { get; set; } - [ForeignKey(typeof(BaseDifficulty)), NotNull] - public int BaseDifficultyID { get; set; } - - [OneToOne(CascadeOperations = CascadeOperation.All)] - public BaseDifficulty BaseDifficulty { get; set; } - - public string Path { get; set; } - - // General - public int AudioLeadIn { get; set; } - public bool Countdown { get; set; } - public SampleSet SampleSet { get; set; } - public float StackLeniency { get; set; } - public bool SpecialStyle { get; set; } - public PlayMode Mode { get; set; } - public bool LetterboxInBreaks { get; set; } - public bool WidescreenStoryboard { get; set; } - - // Editor - // This bookmarks stuff is necessary because DB doesn't know how to store int[] - public string StoredBookmarks { get; internal set; } - [Ignore] - public int[] Bookmarks - { - get - { - return StoredBookmarks.Split(',').Select(b => int.Parse(b)).ToArray(); - } - set - { - StoredBookmarks = string.Join(",", value); - } - } - public double DistanceSpacing { get; set; } - public int BeatDivisor { get; set; } - public int GridSize { get; set; } - public double TimelineZoom { get; set; } - - // Metadata - public string Version { get; set; } - - public bool Equals(BeatmapInfo other) - { - return BeatmapID == other?.BeatmapID; + [ForeignKey(typeof(BaseDifficulty)), NotNull] + public int BaseDifficultyID { get; set; } + + [OneToOne(CascadeOperations = CascadeOperation.All)] + public BaseDifficulty BaseDifficulty { get; set; } + + public string Path { get; set; } + + // General + public int AudioLeadIn { get; set; } + public bool Countdown { get; set; } + public SampleSet SampleSet { get; set; } + public float StackLeniency { get; set; } + public bool SpecialStyle { get; set; } + public PlayMode Mode { get; set; } + public bool LetterboxInBreaks { get; set; } + public bool WidescreenStoryboard { get; set; } + + // Editor + // This bookmarks stuff is necessary because DB doesn't know how to store int[] + public string StoredBookmarks { get; internal set; } + [Ignore] + public int[] Bookmarks + { + get + { + return StoredBookmarks.Split(',').Select(b => int.Parse(b)).ToArray(); + } + set + { + StoredBookmarks = string.Join(",", value); + } + } + public double DistanceSpacing { get; set; } + public int BeatDivisor { get; set; } + public int GridSize { get; set; } + public double TimelineZoom { get; set; } + + // Metadata + public string Version { get; set; } + + public bool Equals(BeatmapInfo other) + { + return BeatmapID == other?.BeatmapID; } - public bool AudioEquals(BeatmapInfo other) => BeatmapSet.Path == other.BeatmapSet.Path && Metadata.AudioFile == other.Metadata.AudioFile; - } + public bool AudioEquals(BeatmapInfo other) => other != null && + BeatmapSet.Path == other.BeatmapSet.Path && + (Metadata ?? BeatmapSet.Metadata).AudioFile == (other.Metadata ?? other.BeatmapSet.Metadata).AudioFile; + } } diff --git a/osu.Game/Overlays/MusicController.cs b/osu.Game/Overlays/MusicController.cs index ba03246842..310bae37e4 100644 --- a/osu.Game/Overlays/MusicController.cs +++ b/osu.Game/Overlays/MusicController.cs @@ -260,7 +260,7 @@ namespace osu.Game.Overlays nextToPlay = playList[playListIndex++].Beatmaps[0]; if (playListIndex == playList.Count) playListIndex = 0; } - while (current?.BeatmapInfo.AudioEquals(nextToPlay) == true); + while (nextToPlay.AudioEquals(current?.BeatmapInfo)); play(nextToPlay, true); appendToHistory(nextToPlay);