2016-09-29 19:13:58 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
2016-11-14 16:23:33 +08:00
|
|
|
|
using System.Linq;
|
2016-11-22 15:13:38 +08:00
|
|
|
|
using System.Threading;
|
2016-11-14 16:23:33 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Track;
|
2016-10-08 18:12:31 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
2016-11-14 16:23:33 +08:00
|
|
|
|
using osu.Framework.GameModes;
|
2016-10-12 01:52:16 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
2016-10-19 22:31:10 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-11-14 16:23:33 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-10-19 22:31:10 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-11-14 16:23:33 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
|
using osu.Game.Beatmaps;
|
2016-10-14 01:49:44 +08:00
|
|
|
|
using osu.Game.Database;
|
2016-11-14 17:03:20 +08:00
|
|
|
|
using osu.Game.Modes;
|
2016-11-14 16:23:33 +08:00
|
|
|
|
using osu.Game.Screens.Backgrounds;
|
2016-10-14 04:55:15 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2016-11-21 03:34:16 +08:00
|
|
|
|
using osu.Game.Screens.Play;
|
2016-11-21 03:43:43 +08:00
|
|
|
|
using osu.Framework;
|
2016-11-23 10:59:50 +08:00
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2016-11-23 13:29:20 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2016-09-29 19:13:58 +08:00
|
|
|
|
|
2016-11-21 03:34:16 +08:00
|
|
|
|
namespace osu.Game.Screens.Select
|
2016-09-29 19:13:58 +08:00
|
|
|
|
{
|
2016-10-14 03:10:00 +08:00
|
|
|
|
public class PlaySongSelect : OsuGameMode
|
2016-09-29 19:13:58 +08:00
|
|
|
|
{
|
2016-10-08 18:12:31 +08:00
|
|
|
|
private Bindable<PlayMode> playMode;
|
2016-10-27 16:35:00 +08:00
|
|
|
|
private BeatmapDatabase database;
|
2016-11-20 00:39:43 +08:00
|
|
|
|
protected override BackgroundMode CreateBackground() => new BackgroundModeBeatmap(Beatmap);
|
|
|
|
|
|
2016-11-23 12:28:49 +08:00
|
|
|
|
private CarouselContainer carousel;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
private TrackManager trackManager;
|
2016-11-20 17:02:20 +08:00
|
|
|
|
|
2016-11-23 12:07:35 +08:00
|
|
|
|
private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 225);
|
2016-11-20 17:02:20 +08:00
|
|
|
|
private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0);
|
|
|
|
|
private static readonly Vector2 wedged_container_start_position = new Vector2(0, 50);
|
2016-11-24 12:48:48 +08:00
|
|
|
|
private BeatmapInfoWedge beatmapInfoWedge;
|
2016-10-14 09:40:44 +08:00
|
|
|
|
|
2016-11-20 00:39:43 +08:00
|
|
|
|
private static readonly Vector2 BACKGROUND_BLUR = new Vector2(20);
|
2016-11-22 15:13:38 +08:00
|
|
|
|
private CancellationTokenSource initialAddSetsTask;
|
2016-11-20 00:39:43 +08:00
|
|
|
|
|
2016-11-23 13:29:20 +08:00
|
|
|
|
class WedgeBackground : Container
|
|
|
|
|
{
|
|
|
|
|
public WedgeBackground()
|
|
|
|
|
{
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Size = new Vector2(1, 0.5f),
|
|
|
|
|
Colour = new Color4(0, 0, 0, 0.5f),
|
|
|
|
|
Shear = new Vector2(0.15f, 0),
|
|
|
|
|
EdgeSmoothness = new Vector2(2, 0),
|
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Size = new Vector2(1, -0.5f),
|
|
|
|
|
Position = new Vector2(0, 1),
|
|
|
|
|
Colour = new Color4(0, 0, 0, 0.5f),
|
|
|
|
|
Shear = new Vector2(-0.15f, 0),
|
|
|
|
|
EdgeSmoothness = new Vector2(2, 0),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-23 19:38:33 +08:00
|
|
|
|
public PlaySongSelect()
|
2016-10-12 02:15:22 +08:00
|
|
|
|
{
|
2016-11-23 13:29:20 +08:00
|
|
|
|
const float carouselWidth = 640;
|
2016-10-24 23:08:48 +08:00
|
|
|
|
const float bottomToolHeight = 50;
|
2016-10-14 04:55:15 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-12 02:15:22 +08:00
|
|
|
|
{
|
2016-11-23 13:29:20 +08:00
|
|
|
|
new ParallaxContainer
|
2016-10-14 04:55:15 +08:00
|
|
|
|
{
|
2016-11-23 13:29:20 +08:00
|
|
|
|
ParallaxAmount = 0.005f,
|
2016-10-14 04:55:15 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-11-23 13:29:20 +08:00
|
|
|
|
Children = new []
|
2016-10-20 02:02:03 +08:00
|
|
|
|
{
|
2016-11-23 13:29:20 +08:00
|
|
|
|
new WedgeBackground
|
2016-10-20 02:02:03 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-11-23 13:29:20 +08:00
|
|
|
|
Padding = new MarginPadding { Right = carouselWidth * 0.76f },
|
2016-10-20 02:02:03 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2016-10-14 04:55:15 +08:00
|
|
|
|
},
|
2016-11-23 12:28:49 +08:00
|
|
|
|
carousel = new CarouselContainer
|
2016-10-12 02:15:22 +08:00
|
|
|
|
{
|
2016-10-20 02:02:03 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2016-11-23 13:29:20 +08:00
|
|
|
|
Size = new Vector2(carouselWidth, 1),
|
2016-10-20 02:02:03 +08:00
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
2016-10-21 22:52:52 +08:00
|
|
|
|
},
|
2016-11-24 12:48:48 +08:00
|
|
|
|
beatmapInfoWedge = new BeatmapInfoWedge
|
2016-11-20 17:02:20 +08:00
|
|
|
|
{
|
2016-11-20 19:16:54 +08:00
|
|
|
|
Alpha = 0,
|
2016-11-20 17:02:20 +08:00
|
|
|
|
Position = wedged_container_start_position,
|
|
|
|
|
Size = wedged_container_size,
|
2016-11-23 12:07:35 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-11-23 04:51:42 +08:00
|
|
|
|
Shear = wedged_container_shear,
|
2016-11-20 17:02:20 +08:00
|
|
|
|
Margin = new MarginPadding { Top = 20, Right = 20, },
|
|
|
|
|
Masking = true,
|
|
|
|
|
BorderColour = new Color4(221, 255, 255, 255),
|
|
|
|
|
BorderThickness = 2.5f,
|
|
|
|
|
EdgeEffect = new EdgeEffect
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Glow,
|
|
|
|
|
Colour = new Color4(130, 204, 255, 150),
|
|
|
|
|
Radius = 20,
|
|
|
|
|
Roundness = 15,
|
|
|
|
|
},
|
|
|
|
|
},
|
2016-10-21 22:52:52 +08:00
|
|
|
|
new Container
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-10-24 23:08:48 +08:00
|
|
|
|
Height = bottomToolHeight,
|
2016-10-21 22:52:52 +08:00
|
|
|
|
Anchor = Anchor.BottomCentre,
|
|
|
|
|
Origin = Anchor.BottomCentre,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Size = Vector2.One,
|
|
|
|
|
Colour = new Color4(0, 0, 0, 0.5f),
|
|
|
|
|
},
|
|
|
|
|
new Button
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2016-10-24 23:08:48 +08:00
|
|
|
|
Width = 100,
|
2016-10-21 22:52:52 +08:00
|
|
|
|
Text = "Play",
|
|
|
|
|
Colour = new Color4(238, 51, 153, 255),
|
2016-11-09 08:02:42 +08:00
|
|
|
|
Action = () => Push(new Player
|
2016-11-05 06:18:08 +08:00
|
|
|
|
{
|
2016-11-23 12:28:49 +08:00
|
|
|
|
BeatmapInfo = carousel.SelectedGroup.SelectedPanel.Beatmap,
|
2016-11-09 08:02:42 +08:00
|
|
|
|
PreferredPlayMode = playMode.Value
|
|
|
|
|
})
|
2016-10-21 22:52:52 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2016-10-12 02:15:22 +08:00
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
2016-10-06 22:33:28 +08:00
|
|
|
|
|
2016-11-12 18:44:16 +08:00
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
2016-11-21 03:43:43 +08:00
|
|
|
|
private void load(BeatmapDatabase beatmaps, AudioManager audio, BaseGame game, OsuGame osuGame)
|
2016-10-06 22:33:28 +08:00
|
|
|
|
{
|
2016-11-21 03:43:43 +08:00
|
|
|
|
if (osuGame != null)
|
2016-10-14 03:10:00 +08:00
|
|
|
|
{
|
2016-11-21 03:43:43 +08:00
|
|
|
|
playMode = osuGame.PlayMode;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
playMode.ValueChanged += playMode_ValueChanged;
|
2016-10-14 03:10:00 +08:00
|
|
|
|
}
|
2016-10-27 11:31:45 +08:00
|
|
|
|
|
2016-10-27 16:35:00 +08:00
|
|
|
|
if (database == null)
|
2016-11-09 07:13:20 +08:00
|
|
|
|
database = beatmaps;
|
2016-10-27 16:35:00 +08:00
|
|
|
|
|
2016-11-22 15:13:38 +08:00
|
|
|
|
database.BeatmapSetAdded += onDatabaseOnBeatmapSetAdded;
|
2016-10-27 16:35:00 +08:00
|
|
|
|
|
2016-11-09 07:13:20 +08:00
|
|
|
|
trackManager = audio.Track;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
|
2016-11-22 15:13:38 +08:00
|
|
|
|
initialAddSetsTask = new CancellationTokenSource();
|
|
|
|
|
|
|
|
|
|
Task.Factory.StartNew(() => addBeatmapSets(game, initialAddSetsTask.Token), initialAddSetsTask.Token);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void onDatabaseOnBeatmapSetAdded(BeatmapSetInfo s)
|
|
|
|
|
{
|
|
|
|
|
Schedule(() => addBeatmapSet(s, Game));
|
2016-10-08 18:12:31 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 18:55:48 +08:00
|
|
|
|
protected override void OnEntering(GameMode last)
|
|
|
|
|
{
|
|
|
|
|
base.OnEntering(last);
|
|
|
|
|
ensurePlayingSelected();
|
2016-11-20 00:39:43 +08:00
|
|
|
|
|
2016-11-20 17:02:20 +08:00
|
|
|
|
changeBackground(Beatmap);
|
2016-11-20 19:16:54 +08:00
|
|
|
|
|
|
|
|
|
Content.FadeInFromZero(250);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResuming(GameMode last)
|
|
|
|
|
{
|
2016-11-20 17:02:20 +08:00
|
|
|
|
changeBackground(Beatmap);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
ensurePlayingSelected();
|
|
|
|
|
base.OnResuming(last);
|
2016-11-20 19:16:54 +08:00
|
|
|
|
|
|
|
|
|
Content.FadeIn(250);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnSuspending(GameMode next)
|
|
|
|
|
{
|
|
|
|
|
Content.FadeOut(250);
|
|
|
|
|
base.OnSuspending(next);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnExiting(GameMode next)
|
|
|
|
|
{
|
|
|
|
|
Content.FadeOut(100);
|
|
|
|
|
return base.OnExiting(next);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-08 18:12:31 +08:00
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
|
{
|
|
|
|
|
base.Dispose(isDisposing);
|
2016-10-14 22:47:44 +08:00
|
|
|
|
if (playMode != null)
|
2016-10-28 18:55:48 +08:00
|
|
|
|
playMode.ValueChanged -= playMode_ValueChanged;
|
2016-11-22 15:13:38 +08:00
|
|
|
|
|
|
|
|
|
database.BeatmapSetAdded -= onDatabaseOnBeatmapSetAdded;
|
|
|
|
|
|
|
|
|
|
initialAddSetsTask.Cancel();
|
2016-10-06 22:33:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-10-28 18:55:48 +08:00
|
|
|
|
private void playMode_ValueChanged(object sender, EventArgs e)
|
2016-10-06 22:33:28 +08:00
|
|
|
|
{
|
|
|
|
|
}
|
2016-10-27 11:31:45 +08:00
|
|
|
|
|
2016-11-20 17:02:20 +08:00
|
|
|
|
private void changeBackground(WorkingBeatmap beatmap)
|
2016-10-26 22:52:04 +08:00
|
|
|
|
{
|
2016-11-20 17:02:20 +08:00
|
|
|
|
if (beatmap == null)
|
|
|
|
|
return;
|
2016-11-20 00:39:43 +08:00
|
|
|
|
|
|
|
|
|
var backgroundModeBeatmap = Background as BackgroundModeBeatmap;
|
|
|
|
|
if (backgroundModeBeatmap != null)
|
|
|
|
|
{
|
|
|
|
|
backgroundModeBeatmap.Beatmap = beatmap;
|
|
|
|
|
// TODO: Remove this once we have non-nullable Beatmap
|
|
|
|
|
(Background as BackgroundModeBeatmap)?.BlurTo(BACKGROUND_BLUR, 1000);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 12:48:48 +08:00
|
|
|
|
beatmapInfoWedge.UpdateBeatmap(beatmap);
|
2016-11-20 17:02:20 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The global Beatmap was changed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
protected override void OnBeatmapChanged(WorkingBeatmap beatmap)
|
|
|
|
|
{
|
|
|
|
|
base.OnBeatmapChanged(beatmap);
|
|
|
|
|
|
2016-11-22 21:07:15 +08:00
|
|
|
|
//todo: change background in selectionChanged instead; support per-difficulty backgrounds.
|
2016-11-20 17:02:20 +08:00
|
|
|
|
changeBackground(beatmap);
|
|
|
|
|
|
2016-10-28 20:08:32 +08:00
|
|
|
|
selectBeatmap(beatmap.BeatmapInfo);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void selectBeatmap(BeatmapInfo beatmap)
|
|
|
|
|
{
|
2016-11-23 12:28:49 +08:00
|
|
|
|
carousel.SelectBeatmap(beatmap);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// selection has been changed as the result of interaction with the carousel.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private void selectionChanged(BeatmapGroup group, BeatmapInfo beatmap)
|
|
|
|
|
{
|
2016-10-28 20:08:32 +08:00
|
|
|
|
if (!beatmap.Equals(Beatmap?.BeatmapInfo))
|
2016-10-28 19:24:14 +08:00
|
|
|
|
Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
|
|
|
|
|
ensurePlayingSelected();
|
2016-10-26 22:52:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-01 22:24:14 +08:00
|
|
|
|
private async Task ensurePlayingSelected()
|
2016-10-28 18:55:48 +08:00
|
|
|
|
{
|
2016-11-01 22:24:14 +08:00
|
|
|
|
AudioTrack track = null;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
|
2016-11-01 22:24:14 +08:00
|
|
|
|
await Task.Run(() => track = Beatmap?.Track);
|
|
|
|
|
|
|
|
|
|
Schedule(delegate
|
2016-10-28 18:55:48 +08:00
|
|
|
|
{
|
2016-11-01 22:24:14 +08:00
|
|
|
|
if (track != null)
|
|
|
|
|
{
|
|
|
|
|
trackManager.SetExclusive(track);
|
|
|
|
|
track.Start();
|
|
|
|
|
}
|
|
|
|
|
});
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 03:43:43 +08:00
|
|
|
|
private void addBeatmapSet(BeatmapSetInfo beatmapSet, BaseGame game)
|
2016-10-26 22:52:04 +08:00
|
|
|
|
{
|
2016-10-27 16:35:00 +08:00
|
|
|
|
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
|
|
|
|
beatmapSet.Beatmaps.ForEach(b => database.GetChildren(b));
|
2016-10-27 11:31:45 +08:00
|
|
|
|
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty).ToList();
|
2016-11-05 19:00:14 +08:00
|
|
|
|
|
2016-11-22 21:07:15 +08:00
|
|
|
|
var beatmap = database.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault());
|
2016-11-05 19:00:14 +08:00
|
|
|
|
|
2016-11-22 21:07:15 +08:00
|
|
|
|
var group = new BeatmapGroup(beatmap) { SelectionChanged = selectionChanged };
|
2016-11-01 22:24:14 +08:00
|
|
|
|
|
2016-11-21 03:34:16 +08:00
|
|
|
|
//for the time being, let's completely load the difficulty panels in the background.
|
|
|
|
|
//this likely won't scale so well, but allows us to completely async the loading flow.
|
|
|
|
|
Task.WhenAll(group.BeatmapPanels.Select(panel => panel.Preload(game))).ContinueWith(task => Schedule(delegate
|
2016-10-26 22:52:04 +08:00
|
|
|
|
{
|
2016-11-23 12:28:49 +08:00
|
|
|
|
carousel.AddGroup(group);
|
2016-11-01 22:24:14 +08:00
|
|
|
|
|
2016-10-28 22:27:59 +08:00
|
|
|
|
if (Beatmap == null)
|
2016-11-23 12:28:49 +08:00
|
|
|
|
carousel.SelectBeatmap(beatmapSet.Beatmaps.First());
|
2016-10-28 22:27:59 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
2016-11-21 03:34:16 +08:00
|
|
|
|
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(Beatmap.BeatmapInfo));
|
|
|
|
|
if (panel != null)
|
2016-11-23 12:28:49 +08:00
|
|
|
|
carousel.SelectGroup(group, panel);
|
2016-10-28 22:27:59 +08:00
|
|
|
|
}
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}));
|
2016-10-26 22:52:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-22 15:13:38 +08:00
|
|
|
|
private void addBeatmapSets(BaseGame game, CancellationToken token)
|
2016-10-26 22:52:04 +08:00
|
|
|
|
{
|
2016-10-27 16:35:00 +08:00
|
|
|
|
foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
|
2016-11-22 15:13:38 +08:00
|
|
|
|
{
|
|
|
|
|
if (token.IsCancellationRequested) return;
|
2016-11-21 03:34:16 +08:00
|
|
|
|
addBeatmapSet(beatmapSet, game);
|
2016-11-22 15:13:38 +08:00
|
|
|
|
}
|
2016-10-26 22:52:04 +08:00
|
|
|
|
}
|
2016-09-29 19:13:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|