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-28 10:55:48 +00:00
|
|
|
using System.Collections.Generic;
|
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;
|
2016-12-18 08:06:03 +00:00
|
|
|
using osu.Framework.Graphics.Transformations;
|
2016-10-27 02:55:55 +00:00
|
|
|
using osu.Game.Database;
|
2016-11-23 02:59:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-11-20 19:34:16 +00:00
|
|
|
class BeatmapGroup : IStateful<BeatmapGroupState>
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-10-27 10:52:48 +00:00
|
|
|
public BeatmapPanel SelectedPanel;
|
2016-10-13 20:55:15 +00:00
|
|
|
|
2016-10-27 04:41:30 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Fires when one of our difficulties was selected. Will fire on first expand.
|
|
|
|
/// </summary>
|
2016-10-27 03:31:45 +00:00
|
|
|
public Action<BeatmapGroup, BeatmapInfo> SelectionChanged;
|
|
|
|
|
2016-12-18 07:59:13 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Fires when one of our difficulties is clicked when already selected. Should start playing the map.
|
|
|
|
/// </summary>
|
|
|
|
public Action<BeatmapInfo> StartRequested;
|
|
|
|
|
2016-11-20 19:34:16 +00:00
|
|
|
public BeatmapSetHeader Header;
|
2016-10-27 04:41:30 +00:00
|
|
|
|
2016-10-27 04:42:37 +00:00
|
|
|
private BeatmapGroupState state;
|
2016-10-27 04:41:30 +00:00
|
|
|
|
2016-10-28 14:27:59 +00:00
|
|
|
public List<BeatmapPanel> BeatmapPanels;
|
2016-10-28 10:55:48 +00:00
|
|
|
|
2016-10-27 04:42:37 +00:00
|
|
|
public BeatmapGroupState 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)
|
|
|
|
{
|
2016-10-27 04:42:37 +00:00
|
|
|
case BeatmapGroupState.Expanded:
|
2016-11-20 19:34:16 +00:00
|
|
|
foreach (BeatmapPanel panel in BeatmapPanels)
|
2016-11-22 20:40:47 +00:00
|
|
|
panel.FadeIn(250);
|
2016-10-27 03:31:45 +00:00
|
|
|
|
2016-11-20 19:34:16 +00:00
|
|
|
Header.State = PanelSelectedState.Selected;
|
2016-11-13 20:22:06 +00:00
|
|
|
if (SelectedPanel != null)
|
|
|
|
SelectedPanel.State = PanelSelectedState.Selected;
|
2016-10-27 03:31:45 +00:00
|
|
|
break;
|
2016-10-27 04:42:37 +00:00
|
|
|
case BeatmapGroupState.Collapsed:
|
2016-11-20 19:34:16 +00:00
|
|
|
Header.State = PanelSelectedState.NotSelected;
|
2016-11-13 20:22:06 +00:00
|
|
|
if (SelectedPanel != null)
|
|
|
|
SelectedPanel.State = PanelSelectedState.NotSelected;
|
2016-11-20 19:34:16 +00:00
|
|
|
|
|
|
|
foreach (BeatmapPanel panel in BeatmapPanels)
|
2016-12-18 08:06:03 +00:00
|
|
|
panel.FadeOut(300, EasingTypes.OutQuint);
|
2016-10-27 03:31:45 +00:00
|
|
|
break;
|
|
|
|
}
|
2016-10-13 19:10:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-12-15 13:48:35 +00:00
|
|
|
public BeatmapGroup(WorkingBeatmap beatmap, BeatmapSetInfo set = null)
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-11-22 13:07:15 +00:00
|
|
|
Header = new BeatmapSetHeader(beatmap)
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-11-20 19:34:16 +00:00
|
|
|
GainedSelection = headerGainedSelection,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-10-13 19:10:00 +00:00
|
|
|
};
|
2016-10-27 03:31:45 +00:00
|
|
|
|
2016-11-22 13:07:15 +00:00
|
|
|
BeatmapPanels = beatmap.BeatmapSetInfo.Beatmaps.Select(b => new BeatmapPanel(b)
|
2016-11-01 14:24:14 +00:00
|
|
|
{
|
2016-11-25 03:47:58 +00:00
|
|
|
Alpha = 0,
|
2016-11-01 14:24:14 +00:00
|
|
|
GainedSelection = panelGainedSelection,
|
2016-12-18 07:59:13 +00:00
|
|
|
StartRequested = p => { StartRequested?.Invoke(p.Beatmap); },
|
2016-11-01 14:24:14 +00:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-11-20 19:34:16 +00:00
|
|
|
}).ToList();
|
2016-11-01 14:24:14 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 10:52:48 +00:00
|
|
|
private void headerGainedSelection(BeatmapSetHeader panel)
|
2016-10-26 14:52:04 +00:00
|
|
|
{
|
2016-10-27 10:52:48 +00:00
|
|
|
State = BeatmapGroupState.Expanded;
|
|
|
|
|
2016-10-28 14:40:12 +00:00
|
|
|
//we want to make sure one of our children is selected in the case none have been selected yet.
|
2016-10-28 14:27:59 +00:00
|
|
|
if (SelectedPanel == null)
|
|
|
|
BeatmapPanels.First().State = PanelSelectedState.Selected;
|
2016-10-28 18:43:52 +00:00
|
|
|
else
|
|
|
|
SelectionChanged?.Invoke(this, SelectedPanel.Beatmap);
|
2016-10-26 14:52:04 +00:00
|
|
|
}
|
2016-10-27 03:31:45 +00:00
|
|
|
|
2016-10-27 10:52:48 +00:00
|
|
|
private void panelGainedSelection(BeatmapPanel panel)
|
2016-10-13 19:10:00 +00:00
|
|
|
{
|
2016-10-28 14:27:59 +00:00
|
|
|
try
|
|
|
|
{
|
|
|
|
if (SelectedPanel == panel) return;
|
2016-10-27 10:52:48 +00:00
|
|
|
|
2016-10-28 14:27:59 +00:00
|
|
|
if (SelectedPanel != null)
|
|
|
|
SelectedPanel.State = PanelSelectedState.NotSelected;
|
|
|
|
SelectedPanel = panel;
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
State = BeatmapGroupState.Expanded;
|
|
|
|
SelectionChanged?.Invoke(this, panel.Beatmap);
|
|
|
|
}
|
2016-10-13 19:10:00 +00:00
|
|
|
}
|
2016-10-27 04:42:37 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum BeatmapGroupState
|
|
|
|
{
|
|
|
|
Collapsed,
|
|
|
|
Expanded,
|
2016-10-13 19:10:00 +00:00
|
|
|
}
|
|
|
|
}
|