2017-02-07 12:59:30 +08:00
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2017-01-27 10:31:28 +08:00
|
|
|
|
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
|
|
|
using osu.Framework;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawables
|
|
|
|
{
|
2017-03-17 18:54:51 +08:00
|
|
|
public class BeatmapGroup : IStateful<BeatmapGroupState>
|
2017-01-27 10:31:28 +08:00
|
|
|
{
|
2017-09-04 08:10:04 +08:00
|
|
|
public event Action<BeatmapGroupState> StateChanged;
|
|
|
|
|
2017-01-27 10:31:28 +08:00
|
|
|
public BeatmapPanel SelectedPanel;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Fires when one of our difficulties was selected. Will fire on first expand.
|
|
|
|
/// </summary>
|
2017-04-28 19:43:42 +08:00
|
|
|
public Action<BeatmapGroup, BeatmapPanel> SelectionChanged;
|
2017-01-27 10:31:28 +08:00
|
|
|
|
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;
|
|
|
|
|
2017-08-30 19:53:33 +08:00
|
|
|
public Action<BeatmapSetInfo> DeleteRequested;
|
2017-08-30 19:41:41 +08:00
|
|
|
|
2017-08-31 14:49:56 +08:00
|
|
|
public Action<BeatmapSetInfo> RestoreHiddenRequested;
|
|
|
|
|
2017-09-04 06:59:32 +08:00
|
|
|
public Action<BeatmapInfo> HideDifficultyRequested;
|
2017-08-30 20:12:46 +08:00
|
|
|
|
2017-10-06 23:59:14 +08:00
|
|
|
public Action<BeatmapInfo> EditRequested;
|
|
|
|
|
2017-01-27 10:31:28 +08:00
|
|
|
public BeatmapSetHeader Header;
|
2016-10-27 12:41:30 +08:00
|
|
|
|
2017-01-18 08:18:15 +08:00
|
|
|
public List<BeatmapPanel> BeatmapPanels;
|
2017-01-27 10:31:28 +08:00
|
|
|
|
|
|
|
public BeatmapSetInfo BeatmapSet;
|
|
|
|
|
2017-09-05 18:26:28 +08:00
|
|
|
private BeatmapGroupState state;
|
2017-12-11 19:22:10 +08:00
|
|
|
|
2017-01-27 10:31:28 +08:00
|
|
|
public BeatmapGroupState State
|
|
|
|
{
|
|
|
|
get { return state; }
|
|
|
|
set
|
|
|
|
{
|
2017-09-04 08:10:04 +08:00
|
|
|
state = value;
|
2017-12-11 20:31:26 +08:00
|
|
|
UpdateState();
|
2017-09-04 08:10:04 +08:00
|
|
|
StateChanged?.Invoke(state);
|
2017-01-27 10:31:28 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-12-11 20:31:26 +08:00
|
|
|
public void UpdateState()
|
|
|
|
{
|
|
|
|
switch (state)
|
|
|
|
{
|
|
|
|
case BeatmapGroupState.Expanded:
|
|
|
|
Header.State = PanelSelectedState.Selected;
|
|
|
|
foreach (BeatmapPanel panel in BeatmapPanels)
|
2017-12-12 12:07:34 +08:00
|
|
|
if (panel == SelectedPanel)
|
|
|
|
panel.State = PanelSelectedState.Selected;
|
|
|
|
else if (panel.Filtered)
|
|
|
|
panel.State = PanelSelectedState.Hidden;
|
|
|
|
else
|
|
|
|
panel.State = PanelSelectedState.NotSelected;
|
2017-12-11 20:31:26 +08:00
|
|
|
break;
|
|
|
|
case BeatmapGroupState.Collapsed:
|
|
|
|
Header.State = PanelSelectedState.NotSelected;
|
|
|
|
foreach (BeatmapPanel panel in BeatmapPanels)
|
|
|
|
panel.State = PanelSelectedState.Hidden;
|
|
|
|
break;
|
|
|
|
case BeatmapGroupState.Hidden:
|
|
|
|
Header.State = PanelSelectedState.Hidden;
|
|
|
|
foreach (BeatmapPanel panel in BeatmapPanels)
|
|
|
|
panel.State = PanelSelectedState.Hidden;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-07-27 15:56:41 +08:00
|
|
|
public BeatmapGroup(BeatmapSetInfo beatmapSet, BeatmapManager manager)
|
2017-01-27 10:31:28 +08:00
|
|
|
{
|
2017-11-08 06:10:06 +08:00
|
|
|
if (beatmapSet == null)
|
|
|
|
throw new ArgumentNullException(nameof(beatmapSet));
|
|
|
|
if (manager == null)
|
|
|
|
throw new ArgumentNullException(nameof(manager));
|
|
|
|
|
2017-02-25 02:36:17 +08:00
|
|
|
BeatmapSet = beatmapSet;
|
2017-07-27 15:56:41 +08:00
|
|
|
WorkingBeatmap beatmap = manager.GetWorkingBeatmap(BeatmapSet.Beatmaps.FirstOrDefault());
|
2017-02-25 02:36:17 +08:00
|
|
|
|
2017-01-27 10:31:28 +08:00
|
|
|
Header = new BeatmapSetHeader(beatmap)
|
|
|
|
{
|
|
|
|
GainedSelection = headerGainedSelection,
|
2017-08-30 19:41:41 +08:00
|
|
|
DeleteRequested = b => DeleteRequested(b),
|
2017-08-31 14:49:56 +08:00
|
|
|
RestoreHiddenRequested = b => RestoreHiddenRequested(b),
|
2017-01-27 10:31:28 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
};
|
2017-04-06 16:21:18 +08:00
|
|
|
|
2017-12-11 20:35:47 +08:00
|
|
|
BeatmapPanels = BeatmapSet.Beatmaps.Where(b => !b.Hidden).OrderBy(b => b.RulesetID).ThenBy(b => b.StarDifficulty).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,
|
2017-09-04 06:59:32 +08:00
|
|
|
HideRequested = p => HideDifficultyRequested?.Invoke(p),
|
2017-10-06 23:59:14 +08:00
|
|
|
StartRequested = p => StartRequested?.Invoke(p.Beatmap),
|
|
|
|
EditRequested = p => EditRequested?.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
|
|
|
|
2017-01-30 12:35:40 +08:00
|
|
|
Header.AddDifficultyIcons(BeatmapPanels);
|
2016-11-01 22:24:14 +08:00
|
|
|
}
|
|
|
|
|
2017-09-05 18:26:28 +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)
|
2017-12-11 19:22:10 +08:00
|
|
|
BeatmapPanels.First(p => !p.Filtered).State = PanelSelectedState.Selected;
|
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;
|
2017-04-28 19:43:42 +08:00
|
|
|
SelectionChanged?.Invoke(this, SelectedPanel);
|
2017-01-27 10:31:28 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-27 12:42:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum BeatmapGroupState
|
|
|
|
{
|
|
|
|
Collapsed,
|
|
|
|
Expanded,
|
2017-01-31 11:35:09 +08:00
|
|
|
Hidden,
|
2017-01-27 10:31:28 +08:00
|
|
|
}
|
|
|
|
}
|