osu/osu.Game/GameModes/Play/PlaySongSelect.cs

154 lines
5.1 KiB
C#
Raw Normal View History

2016-09-29 11:13:58 +00: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 10:12:31 +00:00
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps;
using osu.Game.GameModes.Backgrounds;
2016-10-10 08:17:26 +00:00
using osu.Framework;
using osu.Game.Database;
using osu.Framework.Graphics.Primitives;
2016-10-13 20:55:15 +00:00
using osu.Framework.Graphics.Drawables;
2016-10-13 20:25:41 +00:00
using System.Linq;
2016-10-13 20:55:15 +00:00
using OpenTK;
using OpenTK.Graphics;
2016-09-29 11:13:58 +00:00
namespace osu.Game.GameModes.Play
{
2016-10-13 19:10:00 +00:00
public class PlaySongSelect : OsuGameMode
2016-09-29 11:13:58 +00:00
{
2016-10-08 10:12:31 +00:00
private Bindable<PlayMode> playMode;
private BeatmapDatabase beatmaps;
private BeatmapSet selectedBeatmapSet;
2016-10-08 10:12:31 +00:00
// TODO: use currently selected track as bg
2016-10-05 11:03:52 +00:00
protected override BackgroundMode CreateBackground() => new BackgroundModeCustom(@"Backgrounds/bg4");
private ScrollContainer scrollContainer;
private FlowContainer setList;
private void selectBeatmapSet(BeatmapSet beatmapSet)
{
selectedBeatmapSet = beatmapSet;
foreach (var child in setList.Children)
{
var childGroup = child as BeatmapGroup;
childGroup.Collapsed = childGroup.BeatmapSet != beatmapSet;
}
}
2016-10-13 20:25:41 +00:00
private void addBeatmapSet(BeatmapSet beatmapSet)
{
var group = new BeatmapGroup(beatmapSet);
group.SetSelected += (selectedSet) => selectBeatmapSet(selectedSet);
2016-10-13 20:25:41 +00:00
setList.Add(group);
}
private void addBeatmapSets()
{
var sets = beatmaps.GetBeatmapSets();
foreach (var beatmapSet in sets)
2016-10-13 20:25:41 +00:00
addBeatmapSet(beatmapSet);
}
public PlaySongSelect()
{
2016-10-13 20:55:15 +00:00
const float backgroundWidth = 0.6f;
const float backgroundSlant = 25;
Children = new Drawable[]
{
2016-10-13 20:55:15 +00:00
new BackgroundBox(backgroundSlant)
{
RelativeSizeAxes = Axes.Both,
Size = new Vector2(backgroundWidth, 0.5f),
Colour = new Color4(0, 0, 0, 0.5f),
},
new BackgroundBox(-backgroundSlant)
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Y,
Size = new Vector2(backgroundWidth, 0.5f),
Position = new Vector2(0, 0.5f),
Colour = new Color4(0, 0, 0, 0.5f),
},
scrollContainer = new ScrollContainer
{
2016-10-13 20:55:15 +00:00
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Size = new Vector2(0.5f, 1),
Position = new Vector2(0.5f, 0),
2016-10-14 00:48:36 +00:00
Children = new Drawable[]
{
setList = new FlowContainer
{
Padding = new MarginPadding { Top = 25, Bottom = 25 },
2016-10-14 00:48:36 +00:00
RelativeSizeAxes = Axes.X,
Size = new Vector2(1, 0),
Direction = FlowDirection.VerticalOnly,
2016-10-13 21:27:08 +00:00
Spacing = new Vector2(0, 25),
}
}
}
};
}
2016-10-06 14:33:28 +00:00
2016-10-10 08:17:26 +00:00
public override void Load(BaseGame game)
2016-10-06 14:33:28 +00:00
{
2016-10-10 08:17:26 +00:00
base.Load(game);
2016-10-06 14:33:28 +00:00
2016-10-10 08:17:26 +00:00
OsuGame osu = game as OsuGame;
2016-10-13 19:10:00 +00:00
if (osu != null)
{
playMode = osu.PlayMode;
playMode.ValueChanged += PlayMode_ValueChanged;
// Temporary:
scrollContainer.Padding = new MarginPadding { Top = osu.Toolbar.Height };
}
2016-10-13 19:10:00 +00:00
beatmaps = (game as OsuGameBase).Beatmaps;
2016-10-13 20:25:41 +00:00
beatmaps.BeatmapSetAdded += bset => Scheduler.Add(() => addBeatmapSet(bset));
addBeatmapSets();
var first = setList.Children.First() as BeatmapGroup;
first.Collapsed = false;
selectedBeatmapSet = first.BeatmapSet;
2016-10-08 10:12:31 +00:00
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
playMode.ValueChanged -= PlayMode_ValueChanged;
2016-10-06 14:33:28 +00:00
}
private void PlayMode_ValueChanged(object sender, EventArgs e)
{
}
2016-10-13 20:55:15 +00:00
class BackgroundBox : Box
{
private float wedgeWidth;
public BackgroundBox(float wedgeWidth)
{
this.wedgeWidth = wedgeWidth;
}
protected override Quad DrawQuad
{
get
{
Quad q = base.DrawQuad;
q.TopRight.X += wedgeWidth;
q.BottomRight.X -= wedgeWidth;
return q;
}
}
2016-10-13 20:55:15 +00:00
}
2016-09-29 11:13:58 +00:00
}
}