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;
|
|
|
|
|
|
|
|
namespace osu.Game.Beatmaps.Drawable
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 12:42:37 +08:00
|
|
|
class BeatmapGroup : Container, IStateful<BeatmapGroupState>
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 18:52:48 +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>
|
2016-10-27 11:31:45 +08:00
|
|
|
public Action<BeatmapGroup, BeatmapInfo> SelectionChanged;
|
|
|
|
|
2016-10-27 12:41:30 +08:00
|
|
|
private BeatmapSetInfo beatmapSet;
|
2016-10-27 10:55:55 +08:00
|
|
|
private BeatmapSetHeader header;
|
2016-10-14 04:25:41 +08:00
|
|
|
private FlowContainer difficulties;
|
2016-10-27 12:41:30 +08:00
|
|
|
|
2016-10-27 12:42:37 +08:00
|
|
|
private BeatmapGroupState state;
|
2016-10-27 12:41:30 +08:00
|
|
|
|
2016-10-28 22:27:59 +08:00
|
|
|
public List<BeatmapPanel> BeatmapPanels;
|
2016-10-28 18:55:48 +08:00
|
|
|
|
2016-10-27 12:42:37 +08:00
|
|
|
public BeatmapGroupState State
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 11:31:45 +08:00
|
|
|
get { return state; }
|
2016-10-14 03:10:00 +08:00
|
|
|
set
|
|
|
|
{
|
2016-10-27 11:31:45 +08:00
|
|
|
state = value;
|
|
|
|
switch (state)
|
|
|
|
{
|
2016-10-27 12:42:37 +08:00
|
|
|
case BeatmapGroupState.Expanded:
|
2016-10-27 11:31:45 +08:00
|
|
|
FadeTo(1, 250);
|
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
|
2016-10-27 11:31:45 +08:00
|
|
|
difficulties.Show();
|
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
header.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-05 19:00:14 +08:00
|
|
|
FadeTo(0.8f, 250);
|
2016-10-27 11:31:45 +08:00
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
header.State = PanelSelectedState.NotSelected;
|
|
|
|
difficulties.Hide();
|
2016-10-27 11:31:45 +08:00
|
|
|
break;
|
|
|
|
}
|
2016-10-14 03:10:00 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-11-05 19:00:14 +08:00
|
|
|
public BeatmapGroup(BeatmapSetInfo beatmapSet, WorkingBeatmap working)
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 18:52:48 +08:00
|
|
|
this.beatmapSet = beatmapSet;
|
|
|
|
|
2016-10-27 11:31:45 +08:00
|
|
|
Alpha = 0;
|
2016-10-24 21:58:51 +08:00
|
|
|
AutoSizeAxes = Axes.Y;
|
2016-10-27 18:52:48 +08:00
|
|
|
RelativeSizeAxes = Axes.X;
|
|
|
|
|
2016-10-14 05:27:08 +08:00
|
|
|
Children = new[]
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
2016-10-27 00:49:16 +08:00
|
|
|
new FlowContainer
|
2016-10-14 04:55:15 +08:00
|
|
|
{
|
2016-10-14 08:48:36 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
2016-10-24 21:58:51 +08:00
|
|
|
AutoSizeAxes = Axes.Y,
|
2016-10-14 04:55:15 +08:00
|
|
|
Direction = FlowDirection.VerticalOnly,
|
2016-10-27 10:55:55 +08:00
|
|
|
Children = new Framework.Graphics.Drawable[]
|
2016-10-21 01:55:04 +08:00
|
|
|
{
|
2016-11-05 19:00:14 +08:00
|
|
|
header = new BeatmapSetHeader(beatmapSet, working)
|
2016-10-21 01:55:04 +08:00
|
|
|
{
|
2016-10-27 18:52:48 +08:00
|
|
|
GainedSelection = headerGainedSelection,
|
2016-10-21 01:55:04 +08:00
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
2016-10-26 22:52:04 +08:00
|
|
|
},
|
|
|
|
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,
|
2016-10-21 01:55:04 +08:00
|
|
|
}
|
|
|
|
}
|
2016-10-14 04:55:15 +08:00
|
|
|
}
|
2016-10-14 03:10:00 +08:00
|
|
|
};
|
|
|
|
}
|
2016-10-27 11:31:45 +08:00
|
|
|
|
2016-11-01 22:24:14 +08:00
|
|
|
protected override void Load(BaseGame game)
|
2016-10-27 11:31:45 +08:00
|
|
|
{
|
|
|
|
base.Load(game);
|
2016-11-01 22:24:14 +08:00
|
|
|
|
|
|
|
BeatmapPanels = beatmapSet.Beatmaps.Select(b => new BeatmapPanel(b)
|
|
|
|
{
|
|
|
|
GainedSelection = panelGainedSelection,
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
}).ToList();
|
|
|
|
|
|
|
|
//for the time being, let's completely load the difficulty panels in the background.
|
|
|
|
//this likely won't scale so well, but allows us to completely async the loading flow.
|
|
|
|
Task.WhenAll(BeatmapPanels.Select(panel => panel.Preload(game, p => difficulties.Add(panel)))).Wait();
|
|
|
|
}
|
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
private void headerGainedSelection(BeatmapSetHeader panel)
|
2016-10-26 22:52:04 +08:00
|
|
|
{
|
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);
|
2016-10-26 22:52:04 +08:00
|
|
|
}
|
2016-10-27 11:31:45 +08:00
|
|
|
|
2016-10-27 18:52:48 +08:00
|
|
|
private void panelGainedSelection(BeatmapPanel panel)
|
2016-10-14 03:10:00 +08:00
|
|
|
{
|
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;
|
|
|
|
}
|
|
|
|
finally
|
|
|
|
{
|
|
|
|
State = BeatmapGroupState.Expanded;
|
|
|
|
SelectionChanged?.Invoke(this, panel.Beatmap);
|
|
|
|
}
|
2016-10-14 03:10:00 +08:00
|
|
|
}
|
2016-10-27 12:42:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
public enum BeatmapGroupState
|
|
|
|
{
|
|
|
|
Collapsed,
|
|
|
|
Expanded,
|
2016-10-14 03:10:00 +08:00
|
|
|
}
|
|
|
|
}
|