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

200 lines
7.4 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.Beatmaps.IO;
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:25:41 +00:00
using System.Linq;
2016-10-13 20:55:15 +00:00
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Graphics.Textures;
2016-10-19 20:37:42 +00:00
using osu.Framework.Graphics.UserInterface;
using System.Threading.Tasks;
using System.Diagnostics;
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;
2016-10-19 14:47:23 +00:00
private BeatmapSetInfo selectedBeatmapSet;
2016-10-19 20:37:42 +00:00
private BeatmapInfo selectedBeatmap;
// 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;
public PlaySongSelect()
{
2016-10-20 15:17:37 +00:00
const float scrollWidth = 640;
2016-10-24 15:08:48 +00:00
const float bottomToolHeight = 50;
2016-10-13 20:55:15 +00:00
Children = new Drawable[]
{
2016-10-19 18:02:03 +00:00
new Container
2016-10-13 20:55:15 +00:00
{
RelativeSizeAxes = Axes.Both,
2016-10-24 15:01:53 +00:00
Size = Vector2.One,
Padding = new MarginPadding { Right = scrollWidth - 200 },
2016-10-19 18:02:03 +00: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-19 18:02:03 +00:00
Colour = new Color4(0, 0, 0, 0.5f),
Shear = new Vector2(-0.15f, 0),
2016-10-19 18:02:03 +00:00
},
}
2016-10-13 20:55:15 +00:00
},
scrollContainer = new ScrollContainer
{
2016-10-19 18:02:03 +00:00
RelativeSizeAxes = Axes.Y,
Size = new Vector2(scrollWidth, 1),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
2016-10-14 00:48:36 +00:00
Children = new Drawable[]
{
setList = new FlowContainer
{
2016-10-24 15:08:48 +00:00
Padding = new MarginPadding { Left = 25, Top = 25, Bottom = 25 + bottomToolHeight },
2016-10-14 00:48:36 +00:00
RelativeSizeAxes = Axes.X,
2016-10-24 15:08:48 +00:00
AutoSizeAxes = Axes.Y,
Direction = FlowDirection.VerticalOnly,
2016-10-20 18:21:33 +00:00
Spacing = new Vector2(0, 5),
}
}
2016-10-21 14:52:52 +00:00
},
new Container
{
RelativeSizeAxes = Axes.X,
2016-10-24 15:08:48 +00:00
Height = bottomToolHeight,
2016-10-21 14:52:52 +00: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 15:08:48 +00:00
Width = 100,
2016-10-21 14:52:52 +00:00
Text = "Play",
Colour = new Color4(238, 51, 153, 255),
2016-10-21 15:10:15 +00:00
Action = () => Push(new Player { Beatmap = beatmaps.GetBeatmap(selectedBeatmap) }),
2016-10-21 14:52:52 +00:00
},
}
}
};
}
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-26 14:52:04 +00:00
OsuGame osuGame = game as OsuGame;
if (osuGame != null)
2016-10-13 19:10:00 +00:00
{
2016-10-26 14:52:04 +00:00
playMode = osuGame.PlayMode;
2016-10-13 19:10:00 +00:00
playMode.ValueChanged += PlayMode_ValueChanged;
// Temporary:
2016-10-26 14:52:04 +00:00
scrollContainer.Padding = new MarginPadding { Top = osuGame.Toolbar.Height };
2016-10-13 19:10:00 +00:00
}
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));
Task.Factory.StartNew(addBeatmapSets);
2016-10-08 10:12:31 +00:00
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (playMode != null)
playMode.ValueChanged -= PlayMode_ValueChanged;
2016-10-06 14:33:28 +00:00
}
private void PlayMode_ValueChanged(object sender, EventArgs e)
{
}
2016-10-26 14:52:04 +00:00
private void selectBeatmapSet(BeatmapSetInfo beatmapSet)
{
if (selectedBeatmapSet == beatmapSet)
return;
selectedBeatmapSet = beatmapSet;
foreach (var child in setList.Children)
{
var childGroup = child as BeatmapGroup;
if (childGroup.BeatmapSet == beatmapSet)
{
childGroup.Collapsed = false;
selectedBeatmap = childGroup.SelectedBeatmap;
}
else
childGroup.Collapsed = true;
}
}
private void selectBeatmap(BeatmapSetInfo set, BeatmapInfo beatmap)
{
if (selectedBeatmap == beatmap)
return;
selectBeatmapSet(set);
selectedBeatmap = beatmap;
}
private void addBeatmapSet(BeatmapSetInfo beatmapSet)
{
beatmapSet = beatmaps.GetWithChildren<BeatmapSetInfo>(beatmapSet.BeatmapSetID);
beatmapSet.Beatmaps.ForEach(b => beatmaps.GetChildren(b));
beatmapSet.Beatmaps = beatmapSet.Beatmaps.OrderBy(b => b.BaseDifficulty.OverallDifficulty)
.ToList();
Scheduler.Add(() =>
{
var group = new BeatmapGroup(beatmapSet)
{
SetSelected = selectBeatmapSet,
BeatmapSelected = selectBeatmap,
};
setList.Add(group);
if (setList.Children.Count() == 1)
{
selectedBeatmapSet = group.BeatmapSet;
selectedBeatmap = group.SelectedBeatmap;
group.Collapsed = false;
}
});
}
private void addBeatmapSets()
{
foreach (var beatmapSet in beatmaps.Query<BeatmapSetInfo>())
addBeatmapSet(beatmapSet);
}
2016-09-29 11:13:58 +00:00
}
}