2016-10-13 19:10:00 +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;
|
2016-10-27 02:55:55 +00:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework;
|
2016-10-13 19:10:00 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-10-13 20:25:41 +00:00
|
|
|
using osu.Framework.Input;
|
2016-10-27 02:55:55 +00:00
|
|
|
using osu.Game.Database;
|
|
|
|
using OpenTK;
|
2016-10-13 20:25:41 +00:00
|
|
|
using OpenTK.Graphics;
|
2016-10-27 02:55:55 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawable
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-10-26 16:49:16 +00:00
|
|
|
class BeatmapGroup : Container, IStateful<BeatmapGroup.GroupState>
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-10-26 16:49:16 +00:00
|
|
|
public enum GroupState
|
|
|
|
{
|
|
|
|
Collapsed,
|
|
|
|
Expanded,
|
|
|
|
}
|
2016-10-27 03:31:45 +00:00
|
|
|
|
2016-10-19 20:23:07 +00:00
|
|
|
private const float collapsedAlpha = 0.5f;
|
2016-10-20 17:55:04 +00:00
|
|
|
private const float collapsedWidth = 0.8f;
|
2016-10-27 03:31:45 +00:00
|
|
|
|
2016-10-27 04:36:04 +00:00
|
|
|
private BeatmapPanel selectedPanel;
|
2016-10-13 20:55:15 +00:00
|
|
|
|
2016-10-27 03:31:45 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Fires when one of our difficulties was selected. Will fire on first expand.
|
|
|
|
/// </summary>
|
|
|
|
public Action<BeatmapGroup, BeatmapInfo> SelectionChanged;
|
|
|
|
|
2016-10-19 14:47:23 +00:00
|
|
|
public BeatmapSetInfo BeatmapSet;
|
2016-10-27 02:55:55 +00:00
|
|
|
private BeatmapSetHeader header;
|
2016-10-13 20:25:41 +00:00
|
|
|
private FlowContainer difficulties;
|
2016-10-27 03:31:45 +00:00
|
|
|
private GroupState state;
|
2016-10-26 16:49:16 +00:00
|
|
|
public GroupState State
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-10-27 03:31:45 +00:00
|
|
|
get { return state; }
|
2016-10-13 19:10:00 +00:00
|
|
|
set
|
|
|
|
{
|
2016-10-27 03:31:45 +00:00
|
|
|
state = value;
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case GroupState.Expanded:
|
|
|
|
FadeTo(1, 250);
|
|
|
|
difficulties.Show();
|
|
|
|
|
|
|
|
//todo: header should probably have a state, with this logic moved inside it.
|
|
|
|
header.Width = 1;
|
|
|
|
header.GlowRadius = 5;
|
|
|
|
header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 255);
|
|
|
|
|
2016-10-27 04:36:04 +00:00
|
|
|
if (selectedPanel == null)
|
2016-10-27 03:31:45 +00:00
|
|
|
(difficulties.Children.FirstOrDefault() as BeatmapPanel).Selected = true;
|
2016-10-27 04:36:04 +00:00
|
|
|
SelectionChanged?.Invoke(this, selectedPanel?.Beatmap);
|
2016-10-27 03:31:45 +00:00
|
|
|
break;
|
|
|
|
case GroupState.Collapsed:
|
|
|
|
FadeTo(collapsedAlpha, 250);
|
|
|
|
difficulties.Hide();
|
|
|
|
|
|
|
|
//todo: header should probably have a state, with this logic moved inside it.
|
|
|
|
header.Width = collapsedWidth;
|
|
|
|
header.GlowRadius = 0;
|
|
|
|
header.BorderColour = new Color4(header.BorderColour.R, header.BorderColour.G, header.BorderColour.B, 0);
|
|
|
|
break;
|
|
|
|
}
|
2016-10-13 19:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-21 14:52:52 +00:00
|
|
|
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-10-13 20:25:41 +00:00
|
|
|
BeatmapSet = beatmapSet;
|
2016-10-27 03:31:45 +00:00
|
|
|
Alpha = 0;
|
2016-10-24 13:58:51 +00:00
|
|
|
AutoSizeAxes = Axes.Y;
|
2016-10-14 00:48:36 +00:00
|
|
|
RelativeSizeAxes = Axes.X;
|
2016-10-13 21:27:08 +00:00
|
|
|
Children = new[]
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-10-26 16:49:16 +00:00
|
|
|
new FlowContainer
|
2016-10-13 20:55:15 +00:00
|
|
|
{
|
2016-10-14 00:48:36 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-10-24 13:58:51 +00:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2016-10-13 20:55:15 +00:00
|
|
|
Direction = FlowDirection.VerticalOnly,
|
2016-10-27 02:55:55 +00:00
|
|
|
Children = new Framework.Graphics.Drawable[]
|
2016-10-20 17:55:04 +00:00
|
|
|
{
|
2016-10-27 02:55:55 +00:00
|
|
|
header = new BeatmapSetHeader(beatmapSet)
|
2016-10-20 17:55:04 +00:00
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-10-24 13:58:51 +00:00
|
|
|
Width = collapsedWidth,
|
2016-10-20 17:55:04 +00:00
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
2016-10-26 14:52:04 +00:00
|
|
|
},
|
|
|
|
difficulties = new FlowContainer
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
Margin = new MarginPadding { Top = 5 },
|
|
|
|
Padding = new MarginPadding { Left = 75 },
|
|
|
|
Spacing = new Vector2(0, 5),
|
|
|
|
Direction = FlowDirection.VerticalOnly,
|
|
|
|
Alpha = 0,
|
2016-10-27 03:31:45 +00:00
|
|
|
Children = BeatmapSet.Beatmaps.Select(b =>
|
|
|
|
new BeatmapPanel(BeatmapSet, b)
|
|
|
|
{
|
|
|
|
GainedSelection = panelGainedSelection,
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
}
|
|
|
|
)
|
2016-10-20 17:55:04 +00:00
|
|
|
}
|
|
|
|
}
|
2016-10-13 20:55:15 +00:00
|
|
|
}
|
2016-10-13 19:10:00 +00:00
|
|
|
};
|
|
|
|
}
|
2016-10-27 03:31:45 +00:00
|
|
|
|
|
|
|
public override void Load(BaseGame game)
|
|
|
|
{
|
|
|
|
base.Load(game);
|
|
|
|
State = GroupState.Collapsed;
|
|
|
|
}
|
|
|
|
|
2016-10-27 04:36:04 +00:00
|
|
|
private void panelGainedSelection(BeatmapPanel panel)
|
2016-10-26 14:52:04 +00:00
|
|
|
{
|
2016-10-27 04:36:04 +00:00
|
|
|
if (selectedPanel != null) selectedPanel.Selected = false;
|
|
|
|
selectedPanel = panel;
|
2016-10-27 03:31:45 +00:00
|
|
|
|
2016-10-27 04:36:04 +00:00
|
|
|
SelectionChanged?.Invoke(this, panel.Beatmap);
|
2016-10-26 14:52:04 +00:00
|
|
|
}
|
2016-10-27 03:31:45 +00:00
|
|
|
|
2016-10-13 20:25:41 +00:00
|
|
|
protected override bool OnClick(InputState state)
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-10-27 03:31:45 +00:00
|
|
|
State = GroupState.Expanded;
|
2016-10-13 20:25:41 +00:00
|
|
|
return true;
|
2016-10-13 19:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|