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