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.Collections.Generic;
|
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-12 01:52:16 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2016-10-20 04:04:02 +08:00
|
|
|
|
using osu.Game.Beatmaps.IO;
|
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:04:02 +08:00
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2016-10-20 04:37:42 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
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-14 01:49:44 +08:00
|
|
|
|
private BeatmapDatabase beatmaps;
|
2016-10-19 22:47:23 +08:00
|
|
|
|
private BeatmapSetInfo selectedBeatmapSet;
|
2016-10-20 04:37:42 +08:00
|
|
|
|
private BeatmapInfo selectedBeatmap;
|
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-19 22:31:10 +08:00
|
|
|
|
private FlowContainer setList;
|
2016-10-14 09:40:44 +08:00
|
|
|
|
|
2016-10-19 22:47:23 +08:00
|
|
|
|
private void selectBeatmapSet(BeatmapSetInfo beatmapSet)
|
2016-10-14 06:15:43 +08:00
|
|
|
|
{
|
|
|
|
|
selectedBeatmapSet = beatmapSet;
|
|
|
|
|
foreach (var child in setList.Children)
|
|
|
|
|
{
|
|
|
|
|
var childGroup = child as BeatmapGroup;
|
2016-10-20 04:37:42 +08:00
|
|
|
|
if (childGroup.BeatmapSet == beatmapSet)
|
|
|
|
|
{
|
|
|
|
|
childGroup.Collapsed = false;
|
|
|
|
|
selectedBeatmap = childGroup.SelectedBeatmap;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
childGroup.Collapsed = true;
|
2016-10-14 06:15:43 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-10-20 04:37:42 +08:00
|
|
|
|
|
|
|
|
|
private void selectBeatmap(BeatmapSetInfo set, BeatmapInfo beatmap)
|
|
|
|
|
{
|
|
|
|
|
selectBeatmapSet(set);
|
|
|
|
|
selectedBeatmap = beatmap;
|
|
|
|
|
}
|
2016-10-14 09:40:44 +08:00
|
|
|
|
|
2016-10-19 22:47:23 +08:00
|
|
|
|
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
|
2016-10-14 04:25:41 +08:00
|
|
|
|
{
|
2016-10-20 00:51:18 +08:00
|
|
|
|
beatmapSet = beatmaps.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
|
2016-10-21 03:42:09 +08:00
|
|
|
|
beatmapSet.Beatmaps.ForEach(b => beatmaps.GetChildren(b));
|
|
|
|
|
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty)
|
|
|
|
|
.ToList();
|
2016-10-21 22:52:52 +08:00
|
|
|
|
var group = new BeatmapGroup(beatmapSet);
|
2016-10-20 04:37:42 +08:00
|
|
|
|
group.SetSelected += selectBeatmapSet;
|
|
|
|
|
group.BeatmapSelected += selectBeatmap;
|
2016-10-14 04:25:41 +08:00
|
|
|
|
setList.Add(group);
|
|
|
|
|
}
|
2016-10-19 22:31:10 +08:00
|
|
|
|
|
|
|
|
|
private void addBeatmapSets()
|
|
|
|
|
{
|
2016-10-19 22:47:23 +08:00
|
|
|
|
foreach (var beatmapSet in beatmaps.Query<BeatmapSetInfo>())
|
2016-10-14 04:25:41 +08:00
|
|
|
|
addBeatmapSet(beatmapSet);
|
2016-10-19 22:31:10 +08:00
|
|
|
|
}
|
2016-10-14 09:40:44 +08:00
|
|
|
|
|
2016-10-12 02:15:22 +08:00
|
|
|
|
public PlaySongSelect()
|
|
|
|
|
{
|
2016-10-20 23:17:37 +08:00
|
|
|
|
const float scrollWidth = 640;
|
2016-10-14 04:55:15 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-12 02:15:22 +08:00
|
|
|
|
{
|
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,
|
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),
|
|
|
|
|
},
|
|
|
|
|
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-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
|
|
|
|
{
|
|
|
|
|
setList = new FlowContainer
|
|
|
|
|
{
|
2016-10-20 04:23:07 +08:00
|
|
|
|
Padding = new MarginPadding { Left = 25, Top = 25, Bottom = 25 },
|
2016-10-14 08:48:36 +08:00
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-10-24 23:01:53 +08:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
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,
|
|
|
|
|
Size = new Vector2(1, 50),
|
|
|
|
|
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,
|
|
|
|
|
Size = new Vector2(100, 1),
|
|
|
|
|
Text = "Play",
|
|
|
|
|
Colour = new Color4(238, 51, 153, 255),
|
2016-10-21 23:10:15 +08:00
|
|
|
|
Action = () => Push(new Player { Beatmap = beatmaps.GetBeatmap(selectedBeatmap) }),
|
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-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-10 16:17:26 +08:00
|
|
|
|
OsuGame osu = game as OsuGame;
|
2016-10-14 03:10:00 +08:00
|
|
|
|
if (osu != null)
|
|
|
|
|
{
|
|
|
|
|
playMode = osu.PlayMode;
|
|
|
|
|
playMode.ValueChanged += PlayMode_ValueChanged;
|
|
|
|
|
// Temporary:
|
|
|
|
|
scrollContainer.Padding = new MarginPadding { Top = osu.Toolbar.Height };
|
|
|
|
|
}
|
2016-10-20 04:04:02 +08:00
|
|
|
|
|
2016-10-14 03:10:00 +08:00
|
|
|
|
beatmaps = (game as OsuGameBase).Beatmaps;
|
2016-10-14 04:25:41 +08:00
|
|
|
|
beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset));
|
2016-10-19 22:31:10 +08:00
|
|
|
|
addBeatmapSets();
|
2016-10-14 12:32:08 +08:00
|
|
|
|
var first = setList.Children.FirstOrDefault() as BeatmapGroup;
|
|
|
|
|
if (first != null)
|
|
|
|
|
{
|
|
|
|
|
first.Collapsed = false;
|
|
|
|
|
selectedBeatmapSet = first.BeatmapSet;
|
2016-10-20 04:42:52 +08:00
|
|
|
|
selectedBeatmap = first.SelectedBeatmap;
|
2016-10-14 12:32:08 +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)
|
|
|
|
|
playMode.ValueChanged -= PlayMode_ValueChanged;
|
2016-10-06 22:33:28 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void PlayMode_ValueChanged(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
}
|
2016-09-29 19:13:58 +08:00
|
|
|
|
}
|
|
|
|
|
}
|