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

126 lines
4.1 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-28 18:55:48 +08:00
using System.Collections.Generic;
2016-10-27 10:55:55 +08:00
using System.Linq;
2016-11-01 22:24:14 +08:00
using System.Threading;
using System.Threading.Tasks;
2016-10-27 10:55:55 +08:00
using osu.Framework;
2016-11-01 22:24:14 +08:00
using osu.Framework.Extensions.IEnumerableExtensions;
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;
2016-11-09 07:13:20 +08:00
using osu.Framework.Allocation;
2016-10-27 10:55:55 +08:00
namespace osu.Game.Beatmaps.Drawable
2016-10-14 03:10:00 +08:00
{
class BeatmapGroup : 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;
public BeatmapSetHeader Header;
2016-10-27 12:41:30 +08:00
private BeatmapGroupState state;
2016-10-27 12:41:30 +08:00
public List<BeatmapPanel> BeatmapPanels;
private WorkingBeatmap beatmap;
2016-10-28 18:55:48 +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:
2016-11-01 22:24:14 +08:00
//if (!difficulties.Children.All(d => IsLoaded))
// Task.WhenAll(difficulties.Children.Select(d => d.Preload(Game))).ContinueWith(t => difficulties.Show());
//else
foreach (BeatmapPanel panel in BeatmapPanels)
{
panel.Hidden = false;
panel.FadeIn(250);
}
Header.State = PanelSelectedState.Selected;
if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.Selected;
break;
case BeatmapGroupState.Collapsed:
Header.State = PanelSelectedState.NotSelected;
if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.NotSelected;
foreach (BeatmapPanel panel in BeatmapPanels)
{
panel.Hidden = true;
panel.FadeOut(250);
}
break;
}
2016-10-14 03:10:00 +08:00
}
}
public BeatmapGroup(WorkingBeatmap beatmap)
2016-10-14 03:10:00 +08:00
{
this.beatmap = beatmap;
Header = new BeatmapSetHeader(beatmap)
2016-10-14 03:10:00 +08:00
{
GainedSelection = headerGainedSelection,
RelativeSizeAxes = Axes.X,
2016-10-14 03:10:00 +08:00
};
BeatmapPanels = beatmap.BeatmapSetInfo.Beatmaps.Select(b => new BeatmapPanel(b)
2016-11-01 22:24:14 +08:00
{
GainedSelection = panelGainedSelection,
RelativeSizeAxes = Axes.X,
}).ToList();
2016-11-01 22:24:14 +08:00
}
private void headerGainedSelection(BeatmapSetHeader panel)
2016-10-26 22:52:04 +08:00
{
State = BeatmapGroupState.Expanded;
2016-10-28 22:40:12 +08:00
//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);
2016-10-26 22:52:04 +08:00
}
private void panelGainedSelection(BeatmapPanel panel)
2016-10-14 03:10:00 +08:00
{
try
{
if (SelectedPanel == panel) return;
if (SelectedPanel != null)
SelectedPanel.State = PanelSelectedState.NotSelected;
SelectedPanel = panel;
}
finally
{
State = BeatmapGroupState.Expanded;
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
}
}