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
|
2016-12-06 17:56:20 +08:00
|
|
|
|
|
2017-02-02 16:33:39 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Game.Database;
|
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using osu.Game.Beatmaps.Drawables;
|
2016-12-15 21:57:14 +08:00
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using OpenTK.Input;
|
2017-01-18 08:18:15 +08:00
|
|
|
|
using System.Collections;
|
2017-02-02 16:33:39 +08:00
|
|
|
|
using osu.Framework.MathUtils;
|
2017-03-04 15:54:14 +08:00
|
|
|
|
using System.Diagnostics;
|
2017-03-17 18:12:15 +08:00
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using osu.Framework.Allocation;
|
2017-03-17 18:54:51 +08:00
|
|
|
|
using osu.Framework.Threading;
|
2016-11-25 17:14:56 +08:00
|
|
|
|
|
2016-11-21 03:34:16 +08:00
|
|
|
|
namespace osu.Game.Screens.Select
|
|
|
|
|
{
|
2017-03-17 18:12:54 +08:00
|
|
|
|
internal class BeatmapCarousel : ScrollContainer, IEnumerable<BeatmapGroup>
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2017-03-17 18:12:15 +08:00
|
|
|
|
public BeatmapInfo SelectedBeatmap => selectedPanel?.Beatmap;
|
|
|
|
|
|
|
|
|
|
public Action BeatmapsChanged;
|
|
|
|
|
|
|
|
|
|
public IEnumerable<BeatmapSetInfo> Beatmaps
|
|
|
|
|
{
|
|
|
|
|
get
|
|
|
|
|
{
|
|
|
|
|
return groups.Select(g => g.BeatmapSet);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
scrollableContent.Clear(false);
|
|
|
|
|
panels.Clear();
|
|
|
|
|
groups.Clear();
|
|
|
|
|
|
2017-03-17 18:54:51 +08:00
|
|
|
|
List<BeatmapGroup> newGroups = null;
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
|
|
|
|
Task.Run(() =>
|
|
|
|
|
{
|
|
|
|
|
newGroups = value.Select(createGroup).ToList();
|
2017-03-17 18:54:51 +08:00
|
|
|
|
criteria.Filter(newGroups);
|
2017-03-17 18:12:15 +08:00
|
|
|
|
}).ContinueWith(t =>
|
|
|
|
|
{
|
|
|
|
|
Schedule(() =>
|
|
|
|
|
{
|
|
|
|
|
foreach (var g in newGroups)
|
|
|
|
|
addGroup(g);
|
|
|
|
|
|
2017-03-17 18:54:51 +08:00
|
|
|
|
computeYPositions();
|
2017-03-17 18:12:15 +08:00
|
|
|
|
BeatmapsChanged?.Invoke();
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly List<float> yPositions = new List<float>();
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Required for now unfortunately.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private BeatmapDatabase database;
|
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly Container<Panel> scrollableContent;
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly List<BeatmapGroup> groups = new List<BeatmapGroup>();
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
2017-03-23 12:41:50 +08:00
|
|
|
|
private readonly List<Panel> panels = new List<Panel>();
|
2016-11-21 14:59:46 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
private BeatmapGroup selectedGroup;
|
2016-11-23 03:10:04 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
private BeatmapPanel selectedPanel;
|
2017-01-18 08:18:15 +08:00
|
|
|
|
|
2017-03-17 18:12:54 +08:00
|
|
|
|
public BeatmapCarousel()
|
2017-01-18 08:18:15 +08:00
|
|
|
|
{
|
2017-03-04 15:54:14 +08:00
|
|
|
|
Add(scrollableContent = new Container<Panel>
|
2017-01-18 08:18:15 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
public void AddBeatmap(BeatmapSetInfo beatmapSet)
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2017-03-17 18:12:15 +08:00
|
|
|
|
var group = createGroup(beatmapSet);
|
2016-11-25 17:14:56 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
//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.
|
|
|
|
|
Schedule(delegate
|
|
|
|
|
{
|
|
|
|
|
addGroup(group);
|
|
|
|
|
computeYPositions();
|
|
|
|
|
if (selectedGroup == null)
|
|
|
|
|
selectGroup(group);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SelectBeatmap(BeatmapInfo beatmap, bool animated = true)
|
|
|
|
|
{
|
|
|
|
|
if (beatmap == null)
|
|
|
|
|
{
|
|
|
|
|
SelectNext();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (BeatmapGroup group in groups)
|
|
|
|
|
{
|
|
|
|
|
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
|
|
|
|
|
if (panel != null)
|
|
|
|
|
{
|
|
|
|
|
selectGroup(group, panel, animated);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void RemoveBeatmap(BeatmapSetInfo info) => removeGroup(groups.Find(b => b.BeatmapSet.ID == info.ID));
|
|
|
|
|
|
2017-04-28 19:43:42 +08:00
|
|
|
|
public Action<BeatmapInfo> SelectionChanged;
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
|
|
|
|
public Action StartRequested;
|
|
|
|
|
|
|
|
|
|
public void SelectNext(int direction = 1, bool skipDifficulties = true)
|
|
|
|
|
{
|
|
|
|
|
if (groups.Count == 0)
|
|
|
|
|
{
|
|
|
|
|
selectedGroup = null;
|
|
|
|
|
selectedPanel = null;
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!skipDifficulties && selectedGroup != null)
|
|
|
|
|
{
|
|
|
|
|
int i = selectedGroup.BeatmapPanels.IndexOf(selectedPanel) + direction;
|
|
|
|
|
|
|
|
|
|
if (i >= 0 && i < selectedGroup.BeatmapPanels.Count)
|
|
|
|
|
{
|
|
|
|
|
//changing difficulty panel, not set.
|
|
|
|
|
selectGroup(selectedGroup, selectedGroup.BeatmapPanels[i]);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-04-18 09:04:32 +08:00
|
|
|
|
int startIndex = Math.Max(0, groups.IndexOf(selectedGroup));
|
2017-03-17 18:12:15 +08:00
|
|
|
|
int index = startIndex;
|
|
|
|
|
|
|
|
|
|
do
|
|
|
|
|
{
|
|
|
|
|
index = (index + direction + groups.Count) % groups.Count;
|
|
|
|
|
if (groups[index].State != BeatmapGroupState.Hidden)
|
|
|
|
|
{
|
|
|
|
|
SelectBeatmap(groups[index].BeatmapPanels.First().Beatmap);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
} while (index != startIndex);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void SelectRandom()
|
|
|
|
|
{
|
|
|
|
|
List<BeatmapGroup> visibleGroups = groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden).ToList();
|
|
|
|
|
if (visibleGroups.Count < 1)
|
|
|
|
|
return;
|
|
|
|
|
BeatmapGroup group = visibleGroups[RNG.Next(visibleGroups.Count)];
|
|
|
|
|
BeatmapPanel panel = group?.BeatmapPanels.First();
|
|
|
|
|
|
|
|
|
|
if (panel == null)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
selectGroup(group, panel);
|
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 18:54:51 +08:00
|
|
|
|
private FilterCriteria criteria = new FilterCriteria();
|
|
|
|
|
|
|
|
|
|
private ScheduledDelegate filterTask;
|
|
|
|
|
|
|
|
|
|
public void Filter(FilterCriteria newCriteria = null, bool debounce = true)
|
2017-03-17 18:12:15 +08:00
|
|
|
|
{
|
2017-03-29 18:47:53 +08:00
|
|
|
|
if (newCriteria != null)
|
|
|
|
|
criteria = newCriteria;
|
2017-03-17 18:54:51 +08:00
|
|
|
|
|
2017-04-05 16:27:01 +08:00
|
|
|
|
if (!IsLoaded) return;
|
|
|
|
|
|
2017-03-17 18:54:51 +08:00
|
|
|
|
Action perform = delegate
|
2016-11-25 17:14:56 +08:00
|
|
|
|
{
|
2017-03-17 18:54:51 +08:00
|
|
|
|
filterTask = null;
|
|
|
|
|
|
|
|
|
|
criteria.Filter(groups);
|
2016-11-21 03:34:16 +08:00
|
|
|
|
|
2017-03-17 18:54:51 +08:00
|
|
|
|
var filtered = new List<BeatmapGroup>(groups);
|
|
|
|
|
|
|
|
|
|
scrollableContent.Clear(false);
|
|
|
|
|
panels.Clear();
|
|
|
|
|
groups.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var g in filtered)
|
|
|
|
|
addGroup(g);
|
|
|
|
|
|
|
|
|
|
computeYPositions();
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
2017-03-17 19:09:23 +08:00
|
|
|
|
if (selectedGroup == null || selectedGroup.State == BeatmapGroupState.Hidden)
|
2017-03-17 18:54:51 +08:00
|
|
|
|
SelectNext();
|
2017-03-29 19:01:46 +08:00
|
|
|
|
else
|
|
|
|
|
selectGroup(selectedGroup);
|
2017-03-17 18:54:51 +08:00
|
|
|
|
};
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
2017-03-17 18:54:51 +08:00
|
|
|
|
filterTask?.Cancel();
|
|
|
|
|
if (debounce)
|
|
|
|
|
filterTask = Scheduler.AddDelayed(perform, 250);
|
|
|
|
|
else
|
|
|
|
|
perform();
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
public IEnumerator<BeatmapGroup> GetEnumerator() => groups.GetEnumerator();
|
|
|
|
|
|
|
|
|
|
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
|
|
|
|
|
|
|
|
|
private BeatmapGroup createGroup(BeatmapSetInfo beatmapSet)
|
|
|
|
|
{
|
2017-05-06 15:37:53 +08:00
|
|
|
|
foreach(var b in beatmapSet.Beatmaps)
|
2017-04-18 09:04:32 +08:00
|
|
|
|
{
|
|
|
|
|
if (b.Metadata == null)
|
|
|
|
|
b.Metadata = beatmapSet.Metadata;
|
2017-05-06 15:37:53 +08:00
|
|
|
|
}
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
|
|
|
|
return new BeatmapGroup(beatmapSet, database)
|
|
|
|
|
{
|
2017-04-28 19:43:42 +08:00
|
|
|
|
SelectionChanged = (g, p) => selectGroup(g, p),
|
2017-03-17 18:12:15 +08:00
|
|
|
|
StartRequested = b => StartRequested?.Invoke(),
|
|
|
|
|
State = BeatmapGroupState.Collapsed
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader(permitNulls: true)]
|
|
|
|
|
private void load(BeatmapDatabase database)
|
|
|
|
|
{
|
|
|
|
|
this.database = database;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void addGroup(BeatmapGroup group)
|
|
|
|
|
{
|
|
|
|
|
groups.Add(group);
|
|
|
|
|
panels.Add(group.Header);
|
|
|
|
|
panels.AddRange(group.BeatmapPanels);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void removeGroup(BeatmapGroup group)
|
2017-02-24 13:37:54 +08:00
|
|
|
|
{
|
|
|
|
|
groups.Remove(group);
|
2017-03-14 04:35:43 +08:00
|
|
|
|
panels.Remove(group.Header);
|
2017-03-04 16:34:28 +08:00
|
|
|
|
foreach (var p in group.BeatmapPanels)
|
|
|
|
|
panels.Remove(p);
|
|
|
|
|
|
2017-02-24 13:37:54 +08:00
|
|
|
|
scrollableContent.Remove(group.Header);
|
|
|
|
|
scrollableContent.Remove(group.BeatmapPanels);
|
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
if (selectedGroup == group)
|
|
|
|
|
SelectNext();
|
2017-02-24 13:37:54 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
computeYPositions();
|
2016-11-23 03:10:04 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-24 00:42:21 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Computes the target Y positions for every panel in the carousel.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <returns>The Y position of the currently selected panel.</returns>
|
2017-02-02 16:33:39 +08:00
|
|
|
|
private float computeYPositions(bool animated = true)
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2016-11-23 04:40:47 +08:00
|
|
|
|
yPositions.Clear();
|
|
|
|
|
|
2016-11-21 14:59:46 +08:00
|
|
|
|
float currentY = DrawHeight / 2;
|
|
|
|
|
float selectedY = currentY;
|
|
|
|
|
|
2016-11-21 03:34:16 +08:00
|
|
|
|
foreach (BeatmapGroup group in groups)
|
|
|
|
|
{
|
2017-02-02 16:33:39 +08:00
|
|
|
|
movePanel(group.Header, group.State != BeatmapGroupState.Hidden, animated, ref currentY);
|
2016-11-21 03:34:16 +08:00
|
|
|
|
|
|
|
|
|
if (group.State == BeatmapGroupState.Expanded)
|
|
|
|
|
{
|
2016-11-23 03:10:04 +08:00
|
|
|
|
group.Header.MoveToX(-100, 500, EasingTypes.OutExpo);
|
2016-11-25 11:50:18 +08:00
|
|
|
|
var headerY = group.Header.Position.Y;
|
2016-11-23 03:10:04 +08:00
|
|
|
|
|
2016-11-21 03:34:16 +08:00
|
|
|
|
foreach (BeatmapPanel panel in group.BeatmapPanels)
|
|
|
|
|
{
|
2017-03-17 18:12:15 +08:00
|
|
|
|
if (panel == selectedPanel)
|
2016-11-23 04:40:47 +08:00
|
|
|
|
selectedY = currentY + panel.DrawHeight / 2 - DrawHeight / 2;
|
2016-11-21 14:59:46 +08:00
|
|
|
|
|
2016-11-25 03:25:29 +08:00
|
|
|
|
panel.MoveToX(-50, 500, EasingTypes.OutExpo);
|
|
|
|
|
|
2016-11-25 11:50:18 +08:00
|
|
|
|
//on first display we want to begin hidden under our group's header.
|
2017-02-02 08:15:22 +08:00
|
|
|
|
if (panel.Alpha == 0)
|
2016-11-25 11:50:18 +08:00
|
|
|
|
panel.MoveToY(headerY);
|
|
|
|
|
|
2017-02-02 16:33:39 +08:00
|
|
|
|
movePanel(panel, true, animated, ref currentY);
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-23 03:10:04 +08:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
group.Header.MoveToX(0, 500, EasingTypes.OutExpo);
|
2016-11-23 04:40:47 +08:00
|
|
|
|
|
|
|
|
|
foreach (BeatmapPanel panel in group.BeatmapPanels)
|
2016-11-25 03:25:29 +08:00
|
|
|
|
{
|
|
|
|
|
panel.MoveToX(0, 500, EasingTypes.OutExpo);
|
2017-02-02 16:33:39 +08:00
|
|
|
|
movePanel(panel, false, animated, ref currentY);
|
2016-11-25 03:25:29 +08:00
|
|
|
|
}
|
2016-11-23 03:10:04 +08:00
|
|
|
|
}
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
2016-11-21 14:59:46 +08:00
|
|
|
|
|
|
|
|
|
currentY += DrawHeight / 2;
|
|
|
|
|
scrollableContent.Height = currentY;
|
|
|
|
|
|
2016-11-24 00:42:21 +08:00
|
|
|
|
return selectedY;
|
2016-11-21 14:59:46 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
private void movePanel(Panel panel, bool advance, bool animated, ref float currentY)
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2017-03-17 18:12:15 +08:00
|
|
|
|
yPositions.Add(currentY);
|
|
|
|
|
panel.MoveToY(currentY, animated ? 750 : 0, EasingTypes.OutExpo);
|
|
|
|
|
|
|
|
|
|
if (advance)
|
|
|
|
|
currentY += panel.DrawHeight + 5;
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
private void selectGroup(BeatmapGroup group, BeatmapPanel panel = null, bool animated = true)
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2017-04-28 21:17:35 +08:00
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
if (panel == null)
|
|
|
|
|
panel = group.BeatmapPanels.First();
|
2017-03-17 18:12:15 +08:00
|
|
|
|
|
2017-04-28 21:17:35 +08:00
|
|
|
|
if (selectedPanel == panel) return;
|
2017-04-28 19:31:09 +08:00
|
|
|
|
|
2017-04-28 21:17:35 +08:00
|
|
|
|
Trace.Assert(group.BeatmapPanels.Contains(panel), @"Selected panel must be in provided group");
|
2017-03-04 21:05:02 +08:00
|
|
|
|
|
2017-04-28 21:17:35 +08:00
|
|
|
|
if (selectedGroup != null && selectedGroup != group && selectedGroup.State != BeatmapGroupState.Hidden)
|
|
|
|
|
selectedGroup.State = BeatmapGroupState.Collapsed;
|
2016-11-21 03:34:16 +08:00
|
|
|
|
|
2017-04-28 21:17:35 +08:00
|
|
|
|
group.State = BeatmapGroupState.Expanded;
|
|
|
|
|
panel.State = PanelSelectedState.Selected;
|
2016-11-21 03:34:16 +08:00
|
|
|
|
|
2017-05-01 13:13:00 +08:00
|
|
|
|
if (selectedPanel == panel) return;
|
|
|
|
|
|
2017-04-28 21:17:35 +08:00
|
|
|
|
selectedPanel = panel;
|
|
|
|
|
selectedGroup = group;
|
2017-04-28 19:43:42 +08:00
|
|
|
|
|
2017-04-28 21:17:35 +08:00
|
|
|
|
SelectionChanged?.Invoke(panel.Beatmap);
|
|
|
|
|
}
|
|
|
|
|
finally
|
|
|
|
|
{
|
|
|
|
|
float selectedY = computeYPositions(animated);
|
|
|
|
|
ScrollTo(selectedY, animated);
|
|
|
|
|
}
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
|
2017-03-02 21:01:53 +08:00
|
|
|
|
{
|
2017-03-17 18:12:15 +08:00
|
|
|
|
int direction = 0;
|
|
|
|
|
bool skipDifficulties = false;
|
|
|
|
|
|
|
|
|
|
switch (args.Key)
|
2017-03-02 21:01:53 +08:00
|
|
|
|
{
|
2017-03-17 18:12:15 +08:00
|
|
|
|
case Key.Up:
|
|
|
|
|
direction = -1;
|
2017-02-18 00:41:53 +08:00
|
|
|
|
break;
|
2017-03-17 18:12:15 +08:00
|
|
|
|
case Key.Down:
|
|
|
|
|
direction = 1;
|
2017-02-18 00:41:53 +08:00
|
|
|
|
break;
|
2017-03-17 18:12:15 +08:00
|
|
|
|
case Key.Left:
|
|
|
|
|
direction = -1;
|
|
|
|
|
skipDifficulties = true;
|
2017-02-18 00:41:53 +08:00
|
|
|
|
break;
|
2017-03-17 18:12:15 +08:00
|
|
|
|
case Key.Right:
|
|
|
|
|
direction = 1;
|
|
|
|
|
skipDifficulties = true;
|
2017-03-16 08:18:20 +08:00
|
|
|
|
break;
|
2017-02-18 00:41:53 +08:00
|
|
|
|
}
|
2017-02-18 06:32:14 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
if (direction == 0)
|
|
|
|
|
return base.OnKeyDown(state, args);
|
2016-12-10 18:30:22 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
SelectNext(direction, skipDifficulties);
|
|
|
|
|
return true;
|
2016-12-10 18:30:22 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-21 03:34:16 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2016-11-23 04:40:47 +08:00
|
|
|
|
float drawHeight = DrawHeight;
|
2016-11-25 17:14:56 +08:00
|
|
|
|
|
2017-03-04 15:54:14 +08:00
|
|
|
|
// Remove all panels that should no longer be on-screen
|
|
|
|
|
scrollableContent.RemoveAll(delegate (Panel p)
|
2017-01-18 08:18:15 +08:00
|
|
|
|
{
|
|
|
|
|
float panelPosY = p.Position.Y;
|
2017-03-04 15:54:14 +08:00
|
|
|
|
bool remove = panelPosY < Current - p.DrawHeight || panelPosY > Current + drawHeight || !p.IsPresent;
|
|
|
|
|
return remove;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// Find index range of all panels that should be on-screen
|
|
|
|
|
Trace.Assert(panels.Count == yPositions.Count);
|
2016-11-21 03:34:16 +08:00
|
|
|
|
|
2016-11-23 04:40:47 +08:00
|
|
|
|
int firstIndex = yPositions.BinarySearch(Current - Panel.MAX_HEIGHT);
|
|
|
|
|
if (firstIndex < 0) firstIndex = ~firstIndex;
|
|
|
|
|
int lastIndex = yPositions.BinarySearch(Current + drawHeight);
|
|
|
|
|
if (lastIndex < 0) lastIndex = ~lastIndex;
|
2016-11-21 03:34:16 +08:00
|
|
|
|
|
2017-03-04 15:54:14 +08:00
|
|
|
|
// Add those panels within the previously found index range that should be displayed.
|
2016-11-25 17:14:56 +08:00
|
|
|
|
for (int i = firstIndex; i < lastIndex; ++i)
|
2016-11-21 03:34:16 +08:00
|
|
|
|
{
|
2017-03-04 15:54:14 +08:00
|
|
|
|
Panel panel = panels[i];
|
|
|
|
|
if (panel.State == PanelSelectedState.Hidden)
|
|
|
|
|
continue;
|
|
|
|
|
|
2017-03-04 16:34:39 +08:00
|
|
|
|
// Only add if we're not already part of the content.
|
2017-03-04 15:54:14 +08:00
|
|
|
|
if (!scrollableContent.Contains(panel))
|
|
|
|
|
{
|
2017-03-04 16:34:39 +08:00
|
|
|
|
// Makes sure headers are always _below_ panels,
|
|
|
|
|
// and depth flows downward.
|
|
|
|
|
panel.Depth = i + (panel is BeatmapSetHeader ? panels.Count : 0);
|
2017-03-04 15:54:14 +08:00
|
|
|
|
scrollableContent.Add(panel);
|
|
|
|
|
}
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
2017-03-04 15:54:14 +08:00
|
|
|
|
|
2017-03-04 16:34:39 +08:00
|
|
|
|
// Update externally controlled state of currently visible panels
|
|
|
|
|
// (e.g. x-offset and opacity).
|
2017-03-04 15:54:14 +08:00
|
|
|
|
float halfHeight = drawHeight / 2;
|
|
|
|
|
foreach (Panel p in scrollableContent.Children)
|
|
|
|
|
updatePanel(p, halfHeight);
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
2016-12-15 21:57:14 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Computes the x-offset of currently visible panels. Makes the carousel appear round.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="dist">
|
|
|
|
|
/// Vertical distance from the center of the carousel container
|
|
|
|
|
/// ranging from -1 to 1.
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <param name="halfHeight">Half the height of the carousel container.</param>
|
|
|
|
|
private static float offsetX(float dist, float halfHeight)
|
2016-12-15 21:57:14 +08:00
|
|
|
|
{
|
2017-03-17 18:12:15 +08:00
|
|
|
|
// The radius of the circle the carousel moves on.
|
|
|
|
|
const float circle_radius = 3;
|
|
|
|
|
double discriminant = Math.Max(0, circle_radius * circle_radius - dist * dist);
|
|
|
|
|
float x = (circle_radius - (float)Math.Sqrt(discriminant)) * halfHeight;
|
2017-02-02 18:37:35 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
return 125 + x;
|
2017-02-24 13:37:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Update a panel's x position and multiplicative alpha based on its y position and
|
|
|
|
|
/// the current scroll position.
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="p">The panel to be updated.</param>
|
|
|
|
|
/// <param name="halfHeight">Half the draw height of the carousel container.</param>
|
|
|
|
|
private void updatePanel(Panel p, float halfHeight)
|
2017-02-24 13:37:54 +08:00
|
|
|
|
{
|
2017-03-17 18:12:15 +08:00
|
|
|
|
var height = p.IsPresent ? p.DrawHeight : 0;
|
2017-02-02 16:33:39 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
float panelDrawY = p.Position.Y - Current + height / 2;
|
|
|
|
|
float dist = Math.Abs(1f - panelDrawY / halfHeight);
|
2017-03-04 21:05:02 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
// Setting the origin position serves as an additive position on top of potential
|
|
|
|
|
// local transformation we may want to apply (e.g. when a panel gets selected, we
|
|
|
|
|
// may want to smoothly transform it leftwards.)
|
|
|
|
|
p.OriginPosition = new Vector2(-offsetX(dist, halfHeight), 0);
|
2017-03-04 21:05:02 +08:00
|
|
|
|
|
2017-03-17 18:12:15 +08:00
|
|
|
|
// We are applying a multiplicative alpha (which is internally done by nesting an
|
|
|
|
|
// additional container and setting that container's alpha) such that we can
|
|
|
|
|
// layer transformations on top, with a similar reasoning to the previous comment.
|
|
|
|
|
p.SetMultiplicativeAlpha(MathHelper.Clamp(1.75f - 1.5f * dist, 0, 1));
|
2016-12-15 21:57:14 +08:00
|
|
|
|
}
|
2016-11-21 03:34:16 +08:00
|
|
|
|
}
|
|
|
|
|
}
|