2016-10-14 03:10:00 +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;
|
2016-10-27 10:55:55 +08:00
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework;
|
2016-10-14 03:10:00 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-10-27 10:55:55 +08:00
|
|
|
using osu.Game.Database;
|
|
|
|
using OpenTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawable
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 12:42:37 +08:00
|
|
|
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 18:52:48 +08:00
|
|
|
public BeatmapPanel SelectedPanel;
|
2016-10-14 04:55:15 +08:00
|
|
|
|
2016-10-27 12:41:30 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Fires when one of our difficulties was selected. Will fire on first expand.
|
|
|
|
/// </summary>
|
2016-10-27 11:31:45 +08:00
|
|
|
public Action<BeatmapGroup, BeatmapInfo> SelectionChanged;
|
|
|
|
|
2016-10-27 12:41:30 +08:00
|
|
|
private BeatmapSetInfo beatmapSet;
|
2016-10-27 10:55:55 +08:00
|
|
|
private BeatmapSetHeader header;
|
2016-10-14 04:25:41 +08:00
|
|
|
private FlowContainer difficulties;
|
2016-10-27 12:41:30 +08:00
|
|
|
|
2016-10-27 12:42:37 +08:00
|
|
|
private BeatmapGroupState state;
|
2016-10-27 12:41:30 +08:00
|
|
|
|
2016-10-27 12:42:37 +08:00
|
|
|
public BeatmapGroupState State
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 11:31:45 +08:00
|
|
|
get { return state; }
|
2016-10-14 03:10:00 +08:00
|
|
|
set
|
|
|
|
{
|
2016-10-27 11:31:45 +08:00
|
|
|
state = value;
|
|
|
|
switch (state)
|
|
|
|
{
|
2016-10-27 12:42:37 +08:00
|
|
|
case BeatmapGroupState.Expanded:
|
2016-10-27 11:31:45 +08:00
|
|
|
FadeTo(1, 250);
|
|
|
|
difficulties.Show();
|
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
header.State = PanelSelectedState.Selected;
|
2016-10-27 11:31:45 +08:00
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
if (SelectedPanel == null)
|
|
|
|
((BeatmapPanel)difficulties.Children.FirstOrDefault()).State = PanelSelectedState.Selected;
|
2016-10-27 11:31:45 +08:00
|
|
|
break;
|
2016-10-27 12:42:37 +08:00
|
|
|
case BeatmapGroupState.Collapsed:
|
2016-10-27 18:52:48 +08:00
|
|
|
FadeTo(0.5f, 250);
|
2016-10-27 11:31:45 +08:00
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
header.State = PanelSelectedState.NotSelected;
|
|
|
|
difficulties.Hide();
|
2016-10-27 11:31:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-10-14 03:10:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-21 22:52:52 +08:00
|
|
|
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 18:52:48 +08:00
|
|
|
this.beatmapSet = beatmapSet;
|
|
|
|
|
2016-10-27 11:31:45 +08:00
|
|
|
Alpha = 0;
|
2016-10-24 21:58:51 +08:00
|
|
|
AutoSizeAxes = Axes.Y;
|
2016-10-27 18:52:48 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
2016-10-14 05:27:08 +08:00
|
|
|
Children = new[]
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 00:49:16 +08:00
|
|
|
new FlowContainer
|
2016-10-14 04:55:15 +08:00
|
|
|
{
|
2016-10-14 08:48:36 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-10-24 21:58:51 +08:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2016-10-14 04:55:15 +08:00
|
|
|
Direction = FlowDirection.VerticalOnly,
|
2016-10-27 10:55:55 +08:00
|
|
|
Children = new Framework.Graphics.Drawable[]
|
2016-10-21 01:55:04 +08:00
|
|
|
{
|
2016-10-27 10:55:55 +08:00
|
|
|
header = new BeatmapSetHeader(beatmapSet)
|
2016-10-21 01:55:04 +08:00
|
|
|
{
|
2016-10-27 18:52:48 +08:00
|
|
|
GainedSelection = headerGainedSelection,
|
2016-10-21 01:55:04 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
2016-10-26 22:52:04 +08: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 12:41:30 +08:00
|
|
|
Children = this.beatmapSet.Beatmaps.Select(b =>
|
|
|
|
new BeatmapPanel(this.beatmapSet, b)
|
2016-10-27 11:31:45 +08:00
|
|
|
{
|
|
|
|
GainedSelection = panelGainedSelection,
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
}
|
|
|
|
)
|
2016-10-21 01:55:04 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-14 04:55:15 +08:00
|
|
|
}
|
2016-10-14 03:10:00 +08:00
|
|
|
};
|
|
|
|
}
|
2016-10-27 11:31:45 +08:00
|
|
|
|
|
|
|
public override void Load(BaseGame game)
|
|
|
|
{
|
|
|
|
base.Load(game);
|
2016-10-27 12:42:37 +08:00
|
|
|
State = BeatmapGroupState.Collapsed;
|
2016-10-27 11:31:45 +08:00
|
|
|
}
|
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
private void headerGainedSelection(BeatmapSetHeader panel)
|
2016-10-26 22:52:04 +08:00
|
|
|
{
|
2016-10-27 18:52:48 +08:00
|
|
|
State = BeatmapGroupState.Expanded;
|
|
|
|
|
|
|
|
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap);
|
2016-10-26 22:52:04 +08:00
|
|
|
}
|
2016-10-27 11:31:45 +08:00
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
private void panelGainedSelection(BeatmapPanel panel)
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 12:42:37 +08:00
|
|
|
State = BeatmapGroupState.Expanded;
|
2016-10-27 18:52:48 +08:00
|
|
|
|
|
|
|
if (SelectedPanel != null) SelectedPanel.State = PanelSelectedState.NotSelected;
|
|
|
|
SelectedPanel = panel;
|
|
|
|
|
|
|
|
SelectionChanged?.Invoke(this, panel.Beatmap);
|
2016-10-14 03:10:00 +08:00
|
|
|
}
|
2016-10-27 12:42:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum BeatmapGroupState
|
|
|
|
{
|
|
|
|
Collapsed,
|
|
|
|
Expanded,
|
2016-10-14 03:10:00 +08:00
|
|
|
}
|
|
|
|
}
|