1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 16:27:43 +08:00
osu-lazer/osu.Game/GameModes/Play/PlaySongSelect.cs

179 lines
6.8 KiB
C#
Raw Normal View History

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;
using System.Diagnostics;
2016-10-08 18:12:31 +08:00
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.GameModes.Backgrounds;
2016-10-10 16:17:26 +08:00
using osu.Framework;
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;
using System.Threading.Tasks;
2016-10-27 10:55:55 +08:00
using osu.Game.Beatmaps.Drawable;
using osu.Framework.Extensions.IEnumerableExtensions;
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;
private BeatmapDatabase database;
private BeatmapGroup selectedBeatmapGroup;
// TODO: use currently selected track as bg
2016-10-05 19:03:52 +08:00
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
private ScrollContainer scrollContainer;
private FlowContainer setList;
/// <param name="database">Optionally provide a database to use instead of the OsuGame one.</param>
public PlaySongSelect(BeatmapDatabase database = null)
{
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-20 02:02:03 +08:00
new Container
2016-10-14 04:55:15 +08:00
{
RelativeSizeAxes = Axes.Both,
2016-10-24 23:01:53 +08:00
Size = Vector2.One,
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),
},
new Box
{
RelativeSizeAxes = Axes.Both,
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),
Shear = new Vector2(-0.15f, 0),
2016-10-20 02:02:03 +08:00
},
}
2016-10-14 04:55:15 +08:00
},
scrollContainer = new ScrollContainer
{
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[]
{
setList = new FlowContainer
{
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,
Direction = FlowDirection.VerticalOnly,
2016-10-21 02:21:33 +08:00
Spacing = new Vector2(0, 5),
}
}
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),
Action = () => Push(new Player { BeatmapInfo = selectedBeatmapGroup.SelectedPanel.Beatmap }),
2016-10-21 22:52:52 +08:00
},
}
}
};
}
2016-10-06 22:33:28 +08:00
2016-10-10 16:17:26 +08:00
public override void Load(BaseGame game)
2016-10-06 22:33:28 +08:00
{
2016-10-10 16:17:26 +08:00
base.Load(game);
2016-10-06 22:33:28 +08:00
2016-10-26 22:52:04 +08:00
OsuGame osuGame = game as OsuGame;
if (osuGame != null)
2016-10-14 03:10:00 +08:00
{
2016-10-26 22:52:04 +08:00
playMode = osuGame.PlayMode;
2016-10-14 03:10:00 +08:00
playMode.ValueChanged += PlayMode_ValueChanged;
// Temporary:
2016-10-26 22:52:04 +08:00
scrollContainer.Padding = new MarginPadding { Top = osuGame.Toolbar.Height };
2016-10-14 03:10:00 +08:00
}
if (database == null)
database = (game as OsuGameBase).Beatmaps;
database.BeatmapSetAdded += s => Schedule(() => addBeatmapSet(s));
Task.Factory.StartNew(addBeatmapSets);
2016-10-08 18:12:31 +08:00
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (playMode != null)
playMode.ValueChanged -= PlayMode_ValueChanged;
2016-10-06 22:33:28 +08:00
}
private void PlayMode_ValueChanged(object sender, EventArgs e)
{
}
private void selectBeatmap(BeatmapGroup group, BeatmapInfo beatmap)
2016-10-26 22:52:04 +08:00
{
if (selectedBeatmapGroup == group)
2016-10-26 22:52:04 +08:00
return;
if (selectedBeatmapGroup != null)
selectedBeatmapGroup.State = BeatmapGroupState.Collapsed;
selectedBeatmapGroup = group;
2016-10-26 22:52:04 +08:00
}
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
{
beatmapSet = database.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
beatmapSet.Beatmaps.ForEach(b => database.GetChildren(b));
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty).ToList();
Schedule(() =>
2016-10-26 22:52:04 +08:00
{
var group = new BeatmapGroup(beatmapSet) { SelectionChanged = selectBeatmap };
2016-10-26 22:52:04 +08:00
setList.Add(group);
if (setList.Children.Count() == 1)
group.State = BeatmapGroupState.Expanded;
2016-10-26 22:52:04 +08:00
});
}
private void addBeatmapSets()
{
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
}
}