1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 16:57:25 +08:00
osu-lazer/osu.Game/Beatmaps/Drawable/BeatmapGroup.cs

135 lines
4.4 KiB
C#
Raw Normal View History

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
{
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
2016-10-14 03:10:00 +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>
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
private BeatmapGroupState state;
2016-10-27 12:41:30 +08:00
public BeatmapGroupState State
2016-10-14 03:10:00 +08:00
{
get { return state; }
2016-10-14 03:10:00 +08:00
set
{
state = value;
switch (state)
{
case BeatmapGroupState.Expanded:
FadeTo(1, 250);
difficulties.Show();
header.State = PanelSelectedState.Selected;
if (SelectedPanel == null)
((BeatmapPanel)difficulties.Children.FirstOrDefault()).State = PanelSelectedState.Selected;
break;
case BeatmapGroupState.Collapsed:
FadeTo(0.5f, 250);
header.State = PanelSelectedState.NotSelected;
difficulties.Hide();
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
{
this.beatmapSet = beatmapSet;
Alpha = 0;
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;
2016-10-14 05:27:08 +08:00
Children = new[]
2016-10-14 03:10:00 +08:00
{
new FlowContainer
2016-10-14 04:55:15 +08:00
{
2016-10-14 08:48:36 +08:00
RelativeSizeAxes = Axes.X,
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
{
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)
{
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
};
}
public override void Load(BaseGame game)
{
base.Load(game);
State = BeatmapGroupState.Collapsed;
}
private void headerGainedSelection(BeatmapSetHeader panel)
2016-10-26 22:52:04 +08:00
{
State = BeatmapGroupState.Expanded;
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap);
2016-10-26 22:52:04 +08:00
}
private void panelGainedSelection(BeatmapPanel panel)
2016-10-14 03:10:00 +08:00
{
State = BeatmapGroupState.Expanded;
if (SelectedPanel != null) SelectedPanel.State = PanelSelectedState.NotSelected;
SelectedPanel = panel;
SelectionChanged?.Invoke(this, panel.Beatmap);
2016-10-14 03:10:00 +08:00
}
}
public enum BeatmapGroupState
{
Collapsed,
Expanded,
2016-10-14 03:10:00 +08:00
}
}