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-10-27 16:08:53 +08:00
|
|
|
|
using System.Diagnostics;
|
2016-10-08 18:12:31 +08:00
|
|
|
|
using osu.Framework.Configuration;
|
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;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
2016-10-06 22:32:35 +08:00
|
|
|
|
using osu.Game.GameModes.Backgrounds;
|
2016-10-10 16:17:26 +08:00
|
|
|
|
using osu.Framework;
|
2016-10-14 01:49:44 +08:00
|
|
|
|
using osu.Game.Database;
|
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-10-14 04:25:41 +08:00
|
|
|
|
using System.Linq;
|
2016-10-14 04:55:15 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
2016-10-20 04:37:42 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2016-10-26 04:49:10 +08:00
|
|
|
|
using System.Threading.Tasks;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
using osu.Framework.Audio.Track;
|
2016-10-27 10:55:55 +08:00
|
|
|
|
using osu.Game.Beatmaps.Drawable;
|
2016-10-27 16:08:53 +08:00
|
|
|
|
using osu.Framework.Extensions.IEnumerableExtensions;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
|
|
|
|
using osu.Framework.GameModes;
|
2016-11-09 07:13:20 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
2016-09-29 19:13:58 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.GameModes.Play
|
|
|
|
|
{
|
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-10-27 00:49:16 +08:00
|
|
|
|
private BeatmapGroup selectedBeatmapGroup;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
private BeatmapInfo selectedBeatmapInfo;
|
2016-10-19 22:31:10 +08:00
|
|
|
|
// TODO: use currently selected track as bg
|
2016-10-05 19:03:52 +08:00
|
|
|
|
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
|
2016-10-14 01:49:44 +08:00
|
|
|
|
private ScrollContainer scrollContainer;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
private FlowContainer beatmapSetFlow;
|
|
|
|
|
private TrackManager trackManager;
|
2016-11-01 06:16:11 +08:00
|
|
|
|
private Container wedgeContainer;
|
2016-10-14 09:40:44 +08:00
|
|
|
|
|
2016-10-27 16:53:47 +08:00
|
|
|
|
/// <param name="database">Optionally provide a database to use instead of the OsuGame one.</param>
|
2016-10-27 16:35:00 +08:00
|
|
|
|
public PlaySongSelect(BeatmapDatabase database = null)
|
2016-10-12 02:15:22 +08:00
|
|
|
|
{
|
2016-10-27 16:35:00 +08:00
|
|
|
|
this.database = database;
|
|
|
|
|
|
2016-10-20 23:17:37 +08:00
|
|
|
|
const float scrollWidth = 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-01 06:16:11 +08:00
|
|
|
|
wedgeContainer = new Container
|
2016-10-14 04:55:15 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-10-24 23:01:53 +08:00
|
|
|
|
Size = Vector2.One,
|
2016-10-21 03:16:06 +08:00
|
|
|
|
Padding = new MarginPadding { Right = scrollWidth - 200 },
|
2016-10-20 02:02:03 +08:00
|
|
|
|
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),
|
2016-11-07 02:34:44 +08:00
|
|
|
|
EdgeSmoothness = new Vector2(2, 0),
|
2016-10-20 02:02:03 +08:00
|
|
|
|
},
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-10-20 04:04:02 +08:00
|
|
|
|
RelativePositionAxes = Axes.Y,
|
|
|
|
|
Size = new Vector2(1, -0.5f),
|
|
|
|
|
Position = new Vector2(0, 1),
|
2016-10-20 02:02:03 +08:00
|
|
|
|
Colour = new Color4(0, 0, 0, 0.5f),
|
2016-10-20 04:04:02 +08:00
|
|
|
|
Shear = new Vector2(-0.15f, 0),
|
2016-11-07 02:34:44 +08:00
|
|
|
|
EdgeSmoothness = new Vector2(2, 0),
|
2016-10-20 02:02:03 +08:00
|
|
|
|
},
|
|
|
|
|
}
|
2016-10-14 04:55:15 +08:00
|
|
|
|
},
|
2016-10-14 01:49:44 +08:00
|
|
|
|
scrollContainer = new ScrollContainer
|
2016-10-12 02:15:22 +08:00
|
|
|
|
{
|
2016-10-20 02:02:03 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
Size = new Vector2(scrollWidth, 1),
|
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
|
Origin = Anchor.CentreRight,
|
2016-10-14 08:48:36 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-12 02:15:22 +08:00
|
|
|
|
{
|
2016-10-28 18:55:48 +08:00
|
|
|
|
beatmapSetFlow = new FlowContainer
|
2016-10-12 02:15:22 +08:00
|
|
|
|
{
|
2016-10-24 23:08:48 +08:00
|
|
|
|
Padding = new MarginPadding { Left = 25, Top = 25, Bottom = 25 + bottomToolHeight },
|
2016-10-14 08:48:36 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-10-24 23:08:48 +08:00
|
|
|
|
AutoSizeAxes = Axes.Y,
|
2016-10-12 02:15:22 +08:00
|
|
|
|
Direction = FlowDirection.VerticalOnly,
|
2016-10-21 02:21:33 +08:00
|
|
|
|
Spacing = new Vector2(0, 5),
|
2016-10-12 02:15:22 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
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-09 08:02:42 +08:00
|
|
|
|
BeatmapInfo = selectedBeatmapGroup.SelectedPanel.Beatmap,
|
|
|
|
|
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)]
|
|
|
|
|
private void load(BeatmapDatabase beatmaps, AudioManager audio, OsuGame game)
|
2016-10-06 22:33:28 +08:00
|
|
|
|
{
|
2016-11-12 18:44:16 +08:00
|
|
|
|
if (game != null)
|
2016-10-14 03:10:00 +08:00
|
|
|
|
{
|
2016-11-12 18:44:16 +08:00
|
|
|
|
playMode = game.PlayMode;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
playMode.ValueChanged += playMode_ValueChanged;
|
2016-10-14 03:10:00 +08:00
|
|
|
|
// Temporary:
|
2016-11-09 14:22:54 +08:00
|
|
|
|
scrollContainer.Padding = new MarginPadding { Top = ToolbarPadding };
|
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-10-27 18:52:48 +08:00
|
|
|
|
database.BeatmapSetAdded += s => Schedule(() => addBeatmapSet(s));
|
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-10-26 04:49:10 +08:00
|
|
|
|
Task.Factory.StartNew(addBeatmapSets);
|
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-01 23:22:49 +08:00
|
|
|
|
wedgeContainer.FadeInFromZero(250);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnResuming(GameMode last)
|
|
|
|
|
{
|
|
|
|
|
ensurePlayingSelected();
|
|
|
|
|
base.OnResuming(last);
|
|
|
|
|
}
|
|
|
|
|
|
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-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-10-28 22:35:49 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// The global Beatmap was changed.
|
|
|
|
|
/// </summary>
|
2016-10-28 18:55:48 +08:00
|
|
|
|
protected override void OnBeatmapChanged(WorkingBeatmap beatmap)
|
2016-10-26 22:52:04 +08:00
|
|
|
|
{
|
2016-10-28 18:55:48 +08:00
|
|
|
|
base.OnBeatmapChanged(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)
|
|
|
|
|
{
|
|
|
|
|
if (beatmap.Equals(selectedBeatmapInfo))
|
|
|
|
|
return;
|
|
|
|
|
|
2016-10-28 22:35:49 +08:00
|
|
|
|
//this is VERY temporary logic.
|
2016-10-29 03:29:43 +08:00
|
|
|
|
beatmapSetFlow.Children.Cast<BeatmapGroup>().Any(b =>
|
2016-10-28 18:55:48 +08:00
|
|
|
|
{
|
|
|
|
|
var panel = b.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
|
2016-10-28 22:27:59 +08:00
|
|
|
|
if (panel != null)
|
|
|
|
|
{
|
|
|
|
|
panel.State = PanelSelectedState.Selected;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
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)
|
|
|
|
|
{
|
|
|
|
|
selectedBeatmapInfo = beatmap;
|
|
|
|
|
|
2016-10-28 20:08:32 +08:00
|
|
|
|
if (!beatmap.Equals(Beatmap?.BeatmapInfo))
|
2016-10-28 18:55:48 +08:00
|
|
|
|
{
|
2016-10-28 19:24:14 +08:00
|
|
|
|
Beatmap = database.GetWorkingBeatmap(beatmap, Beatmap);
|
2016-10-28 18:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ensurePlayingSelected();
|
|
|
|
|
|
2016-10-27 00:49:16 +08:00
|
|
|
|
if (selectedBeatmapGroup == group)
|
2016-10-26 22:52:04 +08:00
|
|
|
|
return;
|
2016-10-27 11:31:45 +08:00
|
|
|
|
|
|
|
|
|
if (selectedBeatmapGroup != null)
|
2016-10-27 12:42:37 +08:00
|
|
|
|
selectedBeatmapGroup.State = BeatmapGroupState.Collapsed;
|
2016-10-27 11:31:45 +08:00
|
|
|
|
|
2016-10-27 00:49:16 +08:00
|
|
|
|
selectedBeatmapGroup = group;
|
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-10-26 22:52:04 +08:00
|
|
|
|
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
|
|
|
|
{
|
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
|
|
|
|
|
|
|
|
|
var working = database.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault());
|
|
|
|
|
|
|
|
|
|
var group = new BeatmapGroup(beatmapSet, working) { SelectionChanged = selectionChanged };
|
2016-11-01 22:24:14 +08:00
|
|
|
|
|
|
|
|
|
group.Preload(Game, g =>
|
2016-10-26 22:52:04 +08:00
|
|
|
|
{
|
2016-10-28 18:55:48 +08:00
|
|
|
|
beatmapSetFlow.Add(group);
|
2016-11-01 22:24:14 +08:00
|
|
|
|
|
2016-10-28 22:27:59 +08:00
|
|
|
|
if (Beatmap == null)
|
|
|
|
|
{
|
|
|
|
|
if (beatmapSetFlow.Children.Count() == 1)
|
2016-11-01 22:24:14 +08:00
|
|
|
|
{
|
2016-10-28 22:27:59 +08:00
|
|
|
|
group.State = BeatmapGroupState.Expanded;
|
2016-11-01 22:24:14 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-28 22:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
if (selectedBeatmapInfo?.Equals(Beatmap.BeatmapInfo) != true)
|
|
|
|
|
{
|
|
|
|
|
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(Beatmap.BeatmapInfo));
|
|
|
|
|
if (panel != null)
|
2016-11-01 22:24:14 +08:00
|
|
|
|
{
|
2016-10-28 22:27:59 +08:00
|
|
|
|
panel.State = PanelSelectedState.Selected;
|
2016-11-01 22:24:14 +08:00
|
|
|
|
return;
|
|
|
|
|
}
|
2016-10-28 22:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-01 22:24:14 +08:00
|
|
|
|
|
|
|
|
|
group.State = BeatmapGroupState.Collapsed;
|
2016-10-26 22:52:04 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addBeatmapSets()
|
|
|
|
|
{
|
2016-10-27 16:35:00 +08:00
|
|
|
|
foreach (var beatmapSet in database.Query<BeatmapSetInfo>())
|
2016-10-26 22:52:04 +08:00
|
|
|
|
addBeatmapSet(beatmapSet);
|
|
|
|
|
}
|
2016-09-29 19:13:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|