mirror of
https://github.com/ppy/osu.git
synced 2024-11-20 15:02:56 +08:00
148 lines
4.7 KiB
C#
148 lines
4.7 KiB
C#
//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;
|
|
using System.Linq;
|
|
using osu.Framework;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Containers;
|
|
using osu.Framework.Graphics.Primitives;
|
|
using osu.Game.Database;
|
|
using OpenTK;
|
|
|
|
namespace osu.Game.Beatmaps.Drawable
|
|
{
|
|
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
|
|
{
|
|
public BeatmapPanel SelectedPanel;
|
|
|
|
/// <summary>
|
|
/// Fires when one of our difficulties was selected. Will fire on first expand.
|
|
/// </summary>
|
|
public Action<BeatmapGroup, BeatmapInfo> SelectionChanged;
|
|
|
|
private BeatmapSetInfo beatmapSet;
|
|
private BeatmapSetHeader header;
|
|
private FlowContainer difficulties;
|
|
|
|
private BeatmapGroupState state;
|
|
|
|
public List<BeatmapPanel> BeatmapPanels;
|
|
|
|
public BeatmapGroupState State
|
|
{
|
|
get { return state; }
|
|
set
|
|
{
|
|
state = value;
|
|
switch (state)
|
|
{
|
|
case BeatmapGroupState.Expanded:
|
|
FadeTo(1, 250);
|
|
difficulties.Show();
|
|
|
|
header.State = PanelSelectedState.Selected;
|
|
break;
|
|
case BeatmapGroupState.Collapsed:
|
|
FadeTo(0.5f, 250);
|
|
|
|
header.State = PanelSelectedState.NotSelected;
|
|
difficulties.Hide();
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
public BeatmapGroup(BeatmapSetInfo beatmapSet)
|
|
{
|
|
this.beatmapSet = beatmapSet;
|
|
|
|
Alpha = 0;
|
|
AutoSizeAxes = Axes.Y;
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
BeatmapPanels = beatmapSet.Beatmaps.Select(b =>
|
|
new BeatmapPanel(b)
|
|
{
|
|
GainedSelection = panelGainedSelection,
|
|
Anchor = Anchor.TopRight,
|
|
Origin = Anchor.TopRight,
|
|
RelativeSizeAxes = Axes.X,
|
|
}).ToList();
|
|
|
|
|
|
Children = new[]
|
|
{
|
|
new FlowContainer
|
|
{
|
|
RelativeSizeAxes = Axes.X,
|
|
AutoSizeAxes = Axes.Y,
|
|
Direction = FlowDirection.VerticalOnly,
|
|
Children = new Framework.Graphics.Drawable[]
|
|
{
|
|
header = new BeatmapSetHeader(beatmapSet)
|
|
{
|
|
GainedSelection = headerGainedSelection,
|
|
RelativeSizeAxes = Axes.X,
|
|
Anchor = Anchor.TopRight,
|
|
Origin = Anchor.TopRight,
|
|
},
|
|
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,
|
|
Children = BeatmapPanels
|
|
}
|
|
}
|
|
}
|
|
};
|
|
}
|
|
|
|
public override void Load(BaseGame game)
|
|
{
|
|
base.Load(game);
|
|
State = BeatmapGroupState.Collapsed;
|
|
}
|
|
|
|
private void headerGainedSelection(BeatmapSetHeader panel)
|
|
{
|
|
State = BeatmapGroupState.Expanded;
|
|
|
|
//we want to make sure one of our children is selected in the case none have been selected yet.
|
|
if (SelectedPanel == null)
|
|
BeatmapPanels.First().State = PanelSelectedState.Selected;
|
|
else
|
|
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap);
|
|
}
|
|
|
|
private void panelGainedSelection(BeatmapPanel panel)
|
|
{
|
|
try
|
|
{
|
|
if (SelectedPanel == panel) return;
|
|
|
|
if (SelectedPanel != null)
|
|
SelectedPanel.State = PanelSelectedState.NotSelected;
|
|
SelectedPanel = panel;
|
|
}
|
|
finally
|
|
{
|
|
State = BeatmapGroupState.Expanded;
|
|
SelectionChanged?.Invoke(this, panel.Beatmap);
|
|
}
|
|
}
|
|
}
|
|
|
|
public enum BeatmapGroupState
|
|
{
|
|
Collapsed,
|
|
Expanded,
|
|
}
|
|
}
|