Merge master into netstandard

This commit is contained in:
smoogipoo
2017-12-27 20:48:53 +09:00
287 changed files with 19314 additions and 3538 deletions

View File

@ -7,7 +7,6 @@ using osu.Framework.Graphics.Containers;
using System;
using System.Collections.Generic;
using System.Linq;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Configuration;
using osu.Framework.Input;
using OpenTK.Input;
@ -15,490 +14,308 @@ using osu.Framework.MathUtils;
using System.Diagnostics;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Caching;
using osu.Framework.Threading;
using osu.Framework.Configuration;
using osu.Framework.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Screens.Select.Carousel;
namespace osu.Game.Screens.Select
{
public class BeatmapCarousel : OsuScrollContainer
{
public BeatmapInfo SelectedBeatmap => selectedPanel?.Beatmap;
/// <summary>
/// Triggered when the <see cref="BeatmapSets"/> loaded change and are completely loaded.
/// </summary>
public Action BeatmapSetsChanged;
/// <summary>
/// The currently selected beatmap.
/// </summary>
public BeatmapInfo SelectedBeatmap => selectedBeatmap?.Beatmap;
private CarouselBeatmap selectedBeatmap => selectedBeatmapSet?.Beatmaps.FirstOrDefault(s => s.State == CarouselItemState.Selected);
/// <summary>
/// The currently selected beatmap set.
/// </summary>
public BeatmapSetInfo SelectedBeatmapSet => selectedBeatmapSet?.BeatmapSet;
private CarouselBeatmapSet selectedBeatmapSet;
/// <summary>
/// Raised when the <see cref="SelectedBeatmap"/> is changed.
/// </summary>
public Action<BeatmapInfo> SelectionChanged;
public override bool HandleInput => AllowSelection;
public Action BeatmapsChanged;
private IEnumerable<CarouselBeatmapSet> beatmapSets => root.Children.OfType<CarouselBeatmapSet>();
public IEnumerable<BeatmapSetInfo> Beatmaps
public IEnumerable<BeatmapSetInfo> BeatmapSets
{
get { return groups.Select(g => g.BeatmapSet); }
get { return beatmapSets.Select(g => g.BeatmapSet); }
set
{
scrollableContent.Clear(false);
panels.Clear();
groups.Clear();
List<BeatmapGroup> newGroups = null;
CarouselGroup newRoot = new CarouselGroupEagerSelect();
Task.Run(() =>
{
newGroups = value.Select(createGroup).ToList();
criteria.Filter(newGroups);
}).ContinueWith(t =>
{
Schedule(() =>
{
foreach (var g in newGroups)
if (g != null) addGroup(g);
value.Select(createCarouselSet).Where(g => g != null).ForEach(newRoot.AddChild);
newRoot.Filter(activeCriteria);
computeYPositions();
BeatmapsChanged?.Invoke();
});
});
// preload drawables as the ctor overhead is quite high currently.
var _ = newRoot.Drawables;
}).ContinueWith(_ => Schedule(() =>
{
root = newRoot;
scrollableContent.Clear(false);
itemsCache.Invalidate();
scrollPositionCache.Invalidate();
Schedule(() => BeatmapSetsChanged?.Invoke());
}));
}
}
private readonly List<float> yPositions = new List<float>();
private Cached itemsCache = new Cached();
private Cached scrollPositionCache = new Cached();
/// <summary>
/// Required for now unfortunately.
/// </summary>
private BeatmapManager manager;
private readonly Container<DrawableCarouselItem> scrollableContent;
private readonly Container<Panel> scrollableContent;
public Bindable<RandomSelectAlgorithm> RandomAlgorithm = new Bindable<RandomSelectAlgorithm>();
private readonly List<CarouselBeatmapSet> previouslyVisitedRandomSets = new List<CarouselBeatmapSet>();
private readonly Stack<CarouselBeatmap> randomSelectedBeatmaps = new Stack<CarouselBeatmap>();
private readonly List<BeatmapGroup> groups = new List<BeatmapGroup>();
private Bindable<SelectionRandomType> randomType;
private readonly List<BeatmapGroup> seenGroups = new List<BeatmapGroup>();
private readonly List<Panel> panels = new List<Panel>();
private readonly Stack<KeyValuePair<BeatmapGroup, BeatmapPanel>> randomSelectedBeatmaps = new Stack<KeyValuePair<BeatmapGroup, BeatmapPanel>>();
private BeatmapGroup selectedGroup;
private BeatmapPanel selectedPanel;
protected List<DrawableCarouselItem> Items = new List<DrawableCarouselItem>();
private CarouselGroup root = new CarouselGroupEagerSelect();
public BeatmapCarousel()
{
Add(new OsuContextMenuContainer
Child = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Child = scrollableContent = new Container<Panel>
Child = scrollableContent = new Container<DrawableCarouselItem>
{
RelativeSizeAxes = Axes.X,
}
});
};
}
public void AddBeatmap(BeatmapSetInfo beatmapSet)
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuConfigManager config)
{
config.BindWith(OsuSetting.RandomSelectAlgorithm, RandomAlgorithm);
}
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet)
{
Schedule(() =>
{
var group = createGroup(beatmapSet);
var existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.ID == beatmapSet.ID);
if (group == null)
if (existingSet == null)
return;
addGroup(group);
computeYPositions();
if (selectedGroup == null)
selectGroup(group);
root.RemoveChild(existingSet);
itemsCache.Invalidate();
});
}
public void RemoveBeatmap(BeatmapSetInfo beatmapSet)
public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet)
{
Schedule(() => removeGroup(groups.Find(b => b.BeatmapSet.ID == beatmapSet.ID)));
}
public void UpdateBeatmap(BeatmapInfo beatmap)
{
// todo: this method should not run more than once for the same BeatmapSetInfo.
var set = manager.QueryBeatmapSet(s => s.ID == beatmap.BeatmapSetInfoID);
// todo: this method should be smarter as to not recreate panels that haven't changed, etc.
var group = groups.Find(b => b.BeatmapSet.ID == set.ID);
if (group == null)
return;
int i = groups.IndexOf(group);
groups.RemoveAt(i);
var newGroup = createGroup(set);
if (newGroup != null)
groups.Insert(i, newGroup);
bool hadSelection = selectedGroup == group;
if (hadSelection && newGroup == null)
selectedGroup = null;
Filter(null, false);
//check if we can/need to maintain our current selection.
if (hadSelection && newGroup != null)
Schedule(() =>
{
var newSelection =
newGroup.BeatmapPanels.Find(p => p.Beatmap.ID == selectedPanel?.Beatmap.ID) ??
newGroup.BeatmapPanels[Math.Min(newGroup.BeatmapPanels.Count - 1, group.BeatmapPanels.IndexOf(selectedPanel))];
CarouselBeatmapSet existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.ID == beatmapSet.ID);
selectGroup(newGroup, newSelection);
}
}
bool hadSelection = existingSet?.State?.Value == CarouselItemState.Selected;
public void SelectBeatmap(BeatmapInfo beatmap, bool animated = true)
{
if (beatmap == null || beatmap.Hidden)
{
SelectNext();
return;
}
var newSet = createCarouselSet(beatmapSet);
if (beatmap == SelectedBeatmap) return;
if (existingSet != null)
root.RemoveChild(existingSet);
foreach (BeatmapGroup group in groups)
{
var panel = group.BeatmapPanels.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
if (panel != null)
if (newSet == null)
{
selectGroup(group, panel, animated);
itemsCache.Invalidate();
return;
}
root.AddChild(newSet);
applyActiveCriteria(false, false);
//check if we can/need to maintain our current selection.
if (hadSelection)
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.Beatmap.ID == selectedBeatmap?.Beatmap.ID) ?? newSet);
itemsCache.Invalidate();
Schedule(() => BeatmapSetsChanged?.Invoke());
});
}
public void SelectBeatmap(BeatmapInfo beatmap)
{
if (beatmap?.Hidden != false)
return;
foreach (CarouselBeatmapSet group in beatmapSets)
{
var item = group.Beatmaps.FirstOrDefault(p => p.Beatmap.Equals(beatmap));
if (item != null)
{
select(item);
return;
}
}
}
public Action<BeatmapInfo> SelectionChanged;
public Action StartRequested;
public Action<BeatmapSetInfo> DeleteRequested;
public Action<BeatmapSetInfo> RestoreRequested;
public Action<BeatmapInfo> EditRequested;
public Action<BeatmapInfo> HideDifficultyRequested;
private void selectNullBeatmap()
{
selectedGroup = null;
selectedPanel = null;
SelectionChanged?.Invoke(null);
}
/// <summary>
/// Increment selection in the carousel in a chosen direction.
/// </summary>
/// <param name="direction">The direction to increment. Negative is backwards.</param>
/// <param name="skipDifficulties">Whether to skip individual difficulties and only increment over full groups.</param>
public void SelectNext(int direction = 1, bool skipDifficulties = true)
{
if (groups.All(g => g.State == BeatmapGroupState.Hidden))
{
selectNullBeatmap();
if (!Items.Any())
return;
}
if (!skipDifficulties && selectedGroup != null)
int originalIndex = Items.IndexOf(selectedBeatmap?.Drawables.First());
int currentIndex = originalIndex;
// local function to increment the index in the required direction, wrapping over extremities.
int incrementIndex() => currentIndex = (currentIndex + direction + Items.Count) % Items.Count;
while (incrementIndex() != originalIndex)
{
int i = selectedGroup.BeatmapPanels.IndexOf(selectedPanel) + direction;
var item = Items[currentIndex].Item;
if (i >= 0 && i < selectedGroup.BeatmapPanels.Count)
if (item.Filtered || item.State == CarouselItemState.Selected) continue;
switch (item)
{
//changing difficulty panel, not set.
selectGroup(selectedGroup, selectedGroup.BeatmapPanels[i]);
return;
case CarouselBeatmap beatmap:
if (skipDifficulties) continue;
select(beatmap);
return;
case CarouselBeatmapSet set:
if (skipDifficulties)
select(set);
else
select(direction > 0 ? set.Beatmaps.First(b => !b.Filtered) : set.Beatmaps.Last(b => !b.Filtered));
return;
}
}
int startIndex = Math.Max(0, groups.IndexOf(selectedGroup));
int index = startIndex;
do
{
index = (index + direction + groups.Count) % groups.Count;
if (groups[index].State != BeatmapGroupState.Hidden)
{
if (skipDifficulties)
SelectBeatmap(groups[index].SelectedPanel != null ? groups[index].SelectedPanel.Beatmap : groups[index].BeatmapPanels.First().Beatmap);
else
SelectBeatmap(direction == 1 ? groups[index].BeatmapPanels.First().Beatmap : groups[index].BeatmapPanels.Last().Beatmap);
return;
}
} while (index != startIndex);
}
private IEnumerable<BeatmapGroup> getVisibleGroups() => groups.Where(selectGroup => selectGroup.State != BeatmapGroupState.Hidden);
public void SelectNextRandom()
{
if (groups.Count == 0)
var visible = beatmapSets.Where(s => !s.Filtered).ToList();
if (!visible.Any())
return;
var visibleGroups = getVisibleGroups();
if (!visibleGroups.Any())
return;
if (selectedGroup != null)
randomSelectedBeatmaps.Push(new KeyValuePair<BeatmapGroup, BeatmapPanel>(selectedGroup, selectedGroup.SelectedPanel));
BeatmapGroup group;
if (randomType == SelectionRandomType.RandomPermutation)
if (selectedBeatmap != null)
{
var notSeenGroups = visibleGroups.Except(seenGroups);
if (!notSeenGroups.Any())
randomSelectedBeatmaps.Push(selectedBeatmap);
// when performing a random, we want to add the current set to the previously visited list
// else the user may be "randomised" to the existing selection.
if (previouslyVisitedRandomSets.LastOrDefault() != selectedBeatmapSet)
previouslyVisitedRandomSets.Add(selectedBeatmapSet);
}
CarouselBeatmapSet set;
if (RandomAlgorithm == RandomSelectAlgorithm.RandomPermutation)
{
var notYetVisitedSets = visible.Except(previouslyVisitedRandomSets).ToList();
if (!notYetVisitedSets.Any())
{
seenGroups.Clear();
notSeenGroups = visibleGroups;
previouslyVisitedRandomSets.Clear();
notYetVisitedSets = visible;
}
group = notSeenGroups.ElementAt(RNG.Next(notSeenGroups.Count()));
seenGroups.Add(group);
set = notYetVisitedSets.ElementAt(RNG.Next(notYetVisitedSets.Count));
previouslyVisitedRandomSets.Add(set);
}
else
group = visibleGroups.ElementAt(RNG.Next(visibleGroups.Count()));
set = visible.ElementAt(RNG.Next(visible.Count));
BeatmapPanel panel = group.BeatmapPanels[RNG.Next(group.BeatmapPanels.Count)];
selectGroup(group, panel);
select(set.Beatmaps.Skip(RNG.Next(set.Beatmaps.Count())).FirstOrDefault());
}
public void SelectPreviousRandom()
{
if (!randomSelectedBeatmaps.Any())
return;
var visibleGroups = getVisibleGroups();
if (!visibleGroups.Any())
return;
while (randomSelectedBeatmaps.Any())
{
var beatmapCoordinates = randomSelectedBeatmaps.Pop();
var group = beatmapCoordinates.Key;
if (visibleGroups.Contains(group))
var beatmap = randomSelectedBeatmaps.Pop();
if (!beatmap.Filtered)
{
selectGroup(group, beatmapCoordinates.Value);
if (RandomAlgorithm == RandomSelectAlgorithm.RandomPermutation)
previouslyVisitedRandomSets.Remove(selectedBeatmapSet);
select(beatmap);
break;
}
}
}
private FilterCriteria criteria = new FilterCriteria();
private void select(CarouselItem item)
{
if (item == null) return;
item.State.Value = CarouselItemState.Selected;
}
private ScheduledDelegate filterTask;
private FilterCriteria activeCriteria = new FilterCriteria();
protected ScheduledDelegate FilterTask;
public bool AllowSelection = true;
public void FlushPendingFilters()
public void FlushPendingFilterOperations()
{
if (filterTask?.Completed == false)
Filter(null, false);
if (FilterTask?.Completed == false)
applyActiveCriteria(false, false);
}
public void Filter(FilterCriteria newCriteria = null, bool debounce = true)
public void Filter(FilterCriteria newCriteria, bool debounce = true)
{
if (newCriteria != null)
criteria = newCriteria;
activeCriteria = newCriteria;
if (!IsLoaded) return;
applyActiveCriteria(debounce, true);
}
Action perform = delegate
private void applyActiveCriteria(bool debounce, bool scroll)
{
if (root.Children.Any() != true) return;
void perform()
{
filterTask = null;
FilterTask = null;
criteria.Filter(groups);
root.Filter(activeCriteria);
itemsCache.Invalidate();
if (scroll) scrollPositionCache.Invalidate();
}
var filtered = new List<BeatmapGroup>(groups);
scrollableContent.Clear(false);
panels.Clear();
groups.Clear();
foreach (var g in filtered)
addGroup(g);
computeYPositions();
if (selectedGroup == null || selectedGroup.State == BeatmapGroupState.Hidden)
SelectNext();
else
selectGroup(selectedGroup, selectedPanel);
};
filterTask?.Cancel();
filterTask = null;
FilterTask?.Cancel();
FilterTask = null;
if (debounce)
filterTask = Scheduler.AddDelayed(perform, 250);
FilterTask = Scheduler.AddDelayed(perform, 250);
else
perform();
}
public void ScrollToSelected(bool animated = true)
{
float selectedY = computeYPositions(animated);
ScrollTo(selectedY, animated);
}
private float? scrollTarget;
private BeatmapGroup createGroup(BeatmapSetInfo beatmapSet)
{
if (beatmapSet.Beatmaps.All(b => b.Hidden))
return null;
foreach (var b in beatmapSet.Beatmaps)
{
if (b.Metadata == null)
b.Metadata = beatmapSet.Metadata;
}
return new BeatmapGroup(beatmapSet, manager)
{
SelectionChanged = (g, p) => selectGroup(g, p),
StartRequested = b => StartRequested?.Invoke(),
DeleteRequested = b => DeleteRequested?.Invoke(b),
RestoreHiddenRequested = s => RestoreRequested?.Invoke(s),
EditRequested = b => EditRequested?.Invoke(b),
HideDifficultyRequested = b => HideDifficultyRequested?.Invoke(b),
State = BeatmapGroupState.Collapsed
};
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(BeatmapManager manager, OsuConfigManager config)
{
this.manager = manager;
randomType = config.GetBindable<SelectionRandomType>(OsuSetting.SelectionRandomType);
}
private void addGroup(BeatmapGroup group)
{
groups.Add(group);
panels.Add(group.Header);
panels.AddRange(group.BeatmapPanels);
}
private void removeGroup(BeatmapGroup group)
{
if (group == null)
return;
if (selectedGroup == group)
{
if (getVisibleGroups().Count() == 1)
selectNullBeatmap();
else
SelectNext();
}
groups.Remove(group);
panels.Remove(group.Header);
foreach (var p in group.BeatmapPanels)
panels.Remove(p);
scrollableContent.Remove(group.Header);
scrollableContent.RemoveRange(group.BeatmapPanels);
computeYPositions();
}
/// <summary>
/// Computes the target Y positions for every panel in the carousel.
/// </summary>
/// <returns>The Y position of the currently selected panel.</returns>
private float computeYPositions(bool animated = true)
{
yPositions.Clear();
float currentY = DrawHeight / 2;
float selectedY = currentY;
foreach (BeatmapGroup group in groups)
{
movePanel(group.Header, group.State != BeatmapGroupState.Hidden, animated, ref currentY);
if (group.State == BeatmapGroupState.Expanded)
{
group.Header.MoveToX(-100, 500, Easing.OutExpo);
var headerY = group.Header.Position.Y;
foreach (BeatmapPanel panel in group.BeatmapPanels)
{
if (panel == selectedPanel)
selectedY = currentY + panel.DrawHeight / 2 - DrawHeight / 2;
panel.MoveToX(-50, 500, Easing.OutExpo);
//on first display we want to begin hidden under our group's header.
if (panel.Alpha == 0)
panel.MoveToY(headerY);
movePanel(panel, true, animated, ref currentY);
}
}
else
{
group.Header.MoveToX(0, 500, Easing.OutExpo);
foreach (BeatmapPanel panel in group.BeatmapPanels)
{
panel.MoveToX(0, 500, Easing.OutExpo);
movePanel(panel, false, animated, ref currentY);
}
}
}
currentY += DrawHeight / 2;
scrollableContent.Height = currentY;
return selectedY;
}
private void movePanel(Panel panel, bool advance, bool animated, ref float currentY)
{
yPositions.Add(currentY);
panel.MoveToY(currentY, animated ? 750 : 0, Easing.OutExpo);
if (advance)
currentY += panel.DrawHeight + 5;
}
private void selectGroup(BeatmapGroup group, BeatmapPanel panel = null, bool animated = true)
{
try
{
if (panel == null)
panel = group.BeatmapPanels.First();
if (selectedPanel == panel) return;
Trace.Assert(group.BeatmapPanels.Contains(panel), @"Selected panel must be in provided group");
if (selectedGroup != null && selectedGroup != group && selectedGroup.State != BeatmapGroupState.Hidden)
selectedGroup.State = BeatmapGroupState.Collapsed;
group.State = BeatmapGroupState.Expanded;
group.SelectedPanel = panel;
panel.State = PanelSelectedState.Selected;
if (selectedPanel == panel) return;
selectedPanel = panel;
selectedGroup = group;
SelectionChanged?.Invoke(panel.Beatmap);
}
finally
{
ScrollToSelected(animated);
}
}
public void ScrollToSelected() => scrollPositionCache.Invalidate();
protected override bool OnKeyDown(InputState state, KeyDownEventArgs args)
{
@ -534,68 +351,185 @@ namespace osu.Game.Screens.Select
{
base.Update();
if (!itemsCache.IsValid)
updateItems();
if (!scrollPositionCache.IsValid)
updateScrollPosition();
float drawHeight = DrawHeight;
// Remove all panels that should no longer be on-screen
scrollableContent.RemoveAll(delegate(Panel p)
{
float panelPosY = p.Position.Y;
bool remove = panelPosY < Current - p.DrawHeight || panelPosY > Current + drawHeight || !p.IsPresent;
return remove;
});
// Remove all items that should no longer be on-screen
scrollableContent.RemoveAll(p => p.Y < Current - p.DrawHeight || p.Y > Current + drawHeight || !p.IsPresent);
// Find index range of all panels that should be on-screen
Trace.Assert(panels.Count == yPositions.Count);
// Find index range of all items that should be on-screen
Trace.Assert(Items.Count == yPositions.Count);
int firstIndex = yPositions.BinarySearch(Current - Panel.MAX_HEIGHT);
int firstIndex = yPositions.BinarySearch(Current - DrawableCarouselItem.MAX_HEIGHT);
if (firstIndex < 0) firstIndex = ~firstIndex;
int lastIndex = yPositions.BinarySearch(Current + drawHeight);
if (lastIndex < 0)
{
lastIndex = ~lastIndex;
if (lastIndex < 0) lastIndex = ~lastIndex;
// Add the first panel of the last visible beatmap group to preload its data.
if (lastIndex != 0 && panels[lastIndex - 1] is BeatmapSetHeader)
lastIndex++;
}
int notVisibleCount = 0;
// Add those panels within the previously found index range that should be displayed.
// Add those items within the previously found index range that should be displayed.
for (int i = firstIndex; i < lastIndex; ++i)
{
Panel panel = panels[i];
if (panel.State == PanelSelectedState.Hidden)
DrawableCarouselItem item = Items[i];
if (!item.Item.Visible)
{
if (!item.IsPresent)
notVisibleCount++;
continue;
}
// Only add if we're not already part of the content.
if (!scrollableContent.Contains(panel))
if (!scrollableContent.Contains(item))
{
// Makes sure headers are always _below_ panels,
// Makes sure headers are always _below_ items,
// and depth flows downward.
panel.Depth = i + (panel is BeatmapSetHeader ? panels.Count : 0);
item.Depth = i + (item is DrawableCarouselBeatmapSet ? -Items.Count : 0);
switch (panel.LoadState)
switch (item.LoadState)
{
case LoadState.NotLoaded:
LoadComponentAsync(panel);
LoadComponentAsync(item);
break;
case LoadState.Loading:
break;
default:
scrollableContent.Add(panel);
scrollableContent.Add(item);
break;
}
}
}
// Update externally controlled state of currently visible panels
// this is not actually useful right now, but once we have groups may well be.
if (notVisibleCount > 50)
itemsCache.Invalidate();
// Update externally controlled state of currently visible items
// (e.g. x-offset and opacity).
float halfHeight = drawHeight / 2;
foreach (Panel p in scrollableContent.Children)
updatePanel(p, halfHeight);
foreach (DrawableCarouselItem p in scrollableContent.Children)
updateItem(p, halfHeight);
}
private CarouselBeatmapSet createCarouselSet(BeatmapSetInfo beatmapSet)
{
if (beatmapSet.Beatmaps.All(b => b.Hidden))
return null;
// todo: remove the need for this.
foreach (var b in beatmapSet.Beatmaps)
{
if (b.Metadata == null)
b.Metadata = beatmapSet.Metadata;
}
var set = new CarouselBeatmapSet(beatmapSet);
foreach (var c in set.Beatmaps)
{
c.State.ValueChanged += v =>
{
if (v == CarouselItemState.Selected)
{
selectedBeatmapSet = set;
SelectionChanged?.Invoke(c.Beatmap);
itemsCache.Invalidate();
scrollPositionCache.Invalidate();
}
};
}
return set;
}
/// <summary>
/// Computes the x-offset of currently visible panels. Makes the carousel appear round.
/// Computes the target Y positions for every item in the carousel.
/// </summary>
/// <returns>The Y position of the currently selected item.</returns>
private void updateItems()
{
Items = root.Drawables.ToList();
yPositions.Clear();
float currentY = DrawHeight / 2;
DrawableCarouselBeatmapSet lastSet = null;
scrollTarget = null;
foreach (DrawableCarouselItem d in Items)
{
if (d.IsPresent)
{
switch (d)
{
case DrawableCarouselBeatmapSet set:
lastSet = set;
set.MoveToX(set.Item.State == CarouselItemState.Selected ? -100 : 0, 500, Easing.OutExpo);
set.MoveToY(currentY, 750, Easing.OutExpo);
break;
case DrawableCarouselBeatmap beatmap:
if (beatmap.Item.State.Value == CarouselItemState.Selected)
scrollTarget = currentY + beatmap.DrawHeight / 2 - DrawHeight / 2;
void performMove(float y, float? startY = null)
{
if (startY != null) beatmap.MoveTo(new Vector2(0, startY.Value));
beatmap.MoveToX(beatmap.Item.State == CarouselItemState.Selected ? -50 : 0, 500, Easing.OutExpo);
beatmap.MoveToY(y, 750, Easing.OutExpo);
}
Debug.Assert(lastSet != null);
float? setY = null;
if (!d.IsLoaded || beatmap.Alpha == 0) // can't use IsPresent due to DrawableCarouselItem override.
setY = lastSet.Y + lastSet.DrawHeight + 5;
if (d.IsLoaded)
performMove(currentY, setY);
else
{
float y = currentY;
d.OnLoadComplete = _ => performMove(y, setY);
}
break;
}
}
yPositions.Add(currentY);
if (d.Item.Visible)
currentY += d.DrawHeight + 5;
}
currentY += DrawHeight / 2;
scrollableContent.Height = currentY;
if (selectedBeatmapSet == null || selectedBeatmap == null || selectedBeatmapSet.State.Value != CarouselItemState.Selected)
{
selectedBeatmapSet = null;
SelectionChanged?.Invoke(null);
}
itemsCache.Validate();
}
private void updateScrollPosition()
{
if (scrollTarget != null) ScrollTo(scrollTarget.Value);
scrollPositionCache.Validate();
}
/// <summary>
/// Computes the x-offset of currently visible items. Makes the carousel appear round.
/// </summary>
/// <param name="dist">
/// Vertical distance from the center of the carousel container
@ -613,20 +547,20 @@ namespace osu.Game.Screens.Select
}
/// <summary>
/// Update a panel's x position and multiplicative alpha based on its y position and
/// Update a item'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="p">The item to be updated.</param>
/// <param name="halfHeight">Half the draw height of the carousel container.</param>
private void updatePanel(Panel p, float halfHeight)
private void updateItem(DrawableCarouselItem p, float halfHeight)
{
var height = p.IsPresent ? p.DrawHeight : 0;
float panelDrawY = p.Position.Y - Current + height / 2;
float dist = Math.Abs(1f - panelDrawY / halfHeight);
float itemDrawY = p.Position.Y - Current + height / 2;
float dist = Math.Abs(1f - itemDrawY / halfHeight);
// 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
// local transformation we may want to apply (e.g. when a item gets selected, we
// may want to smoothly transform it leftwards.)
p.OriginPosition = new Vector2(-offsetX(dist, halfHeight), 0);

View File

@ -52,6 +52,7 @@ namespace osu.Game.Screens.Select
default:
Details.Hide();
Leaderboard.Scope = (LeaderboardScope)tab - 1;
Leaderboard.Show();
break;
}

View File

@ -17,6 +17,7 @@ using osu.Framework.Graphics.Shapes;
using osu.Framework.Extensions.Color4Extensions;
using osu.Game.Screens.Select.Details;
using osu.Game.Beatmaps;
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.Select
{
@ -334,7 +335,7 @@ namespace osu.Game.Screens.Select
TextSize = 14,
},
},
textFlow = new TextFlowContainer
textFlow = new OsuTextFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
@ -359,7 +360,7 @@ namespace osu.Game.Screens.Select
private void setTextAsync(string text)
{
LoadComponentAsync(new TextFlowContainer(s => s.TextSize = 14)
LoadComponentAsync(new OsuTextFlowContainer(s => s.TextSize = 14)
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,

View File

@ -19,6 +19,7 @@ using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Types;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Cursor;
namespace osu.Game.Screens.Select
{
@ -26,7 +27,7 @@ namespace osu.Game.Screens.Select
{
private static readonly Vector2 wedged_container_shear = new Vector2(0.15f, 0);
private Drawable info;
protected BufferedWedgeInfo Info;
public BeatmapInfoWedge()
{
@ -34,6 +35,7 @@ namespace osu.Game.Screens.Select
Masking = true;
BorderColour = new Color4(221, 255, 255, 255);
BorderThickness = 2.5f;
Alpha = 0;
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
@ -49,12 +51,14 @@ namespace osu.Game.Screens.Select
{
this.MoveToX(0, 800, Easing.OutQuint);
this.RotateTo(0, 800, Easing.OutQuint);
this.FadeIn(250);
}
protected override void PopOut()
{
this.MoveToX(-100, 800, Easing.InQuint);
this.RotateTo(10, 800, Easing.InQuint);
this.MoveToX(-100, 800, Easing.In);
this.RotateTo(10, 800, Easing.In);
this.FadeOut(500, Easing.In);
}
public void UpdateBeatmap(WorkingBeatmap beatmap)
@ -62,23 +66,30 @@ namespace osu.Game.Screens.Select
LoadComponentAsync(new BufferedWedgeInfo(beatmap)
{
Shear = -Shear,
Depth = info?.Depth + 1 ?? 0,
Depth = Info?.Depth + 1 ?? 0,
}, newInfo =>
{
State = beatmap == null ? Visibility.Hidden : Visibility.Visible;
// ensure we ourselves are visible if not already.
if (!IsPresent)
this.FadeIn(250);
State = Visibility.Visible;
info?.FadeOut(250);
info?.Expire();
Info?.FadeOut(250);
Info?.Expire();
Add(info = newInfo);
Add(Info = newInfo);
});
}
public class BufferedWedgeInfo : BufferedContainer
{
private readonly WorkingBeatmap working;
public OsuSpriteText VersionLabel { get; private set; }
public OsuSpriteText TitleLabel { get; private set; }
public OsuSpriteText ArtistLabel { get; private set; }
public FillFlowContainer MapperContainer { get; private set; }
public FillFlowContainer InfoLabelContainer { get; private set; }
public BufferedWedgeInfo(WorkingBeatmap working)
{
@ -88,34 +99,8 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader]
private void load()
{
BeatmapInfo beatmapInfo = working.BeatmapInfo;
BeatmapMetadata metadata = beatmapInfo.Metadata ?? working.BeatmapSetInfo?.Metadata ?? new BeatmapMetadata();
Beatmap beatmap = working.Beatmap;
List<InfoLabel> labels = new List<InfoLabel>();
if (beatmap != null)
{
HitObject lastObject = beatmap.HitObjects.LastOrDefault();
double endTime = (lastObject as IHasEndTime)?.EndTime ?? lastObject?.StartTime ?? 0;
labels.Add(new InfoLabel(new BeatmapStatistic
{
Name = "Length",
Icon = FontAwesome.fa_clock_o,
Content = beatmap.HitObjects.Count == 0 ? "-" : TimeSpan.FromMilliseconds(endTime - beatmap.HitObjects.First().StartTime).ToString(@"m\:ss"),
}));
labels.Add(new InfoLabel(new BeatmapStatistic
{
Name = "BPM",
Icon = FontAwesome.fa_circle,
Content = getBPMRange(beatmap),
}));
//get statistics from the current ruleset.
labels.AddRange(beatmapInfo.Ruleset.CreateInstance().GetBeatmapStatistics(working).Select(s => new InfoLabel(s)));
}
var beatmapInfo = working.BeatmapInfo;
var metadata = beatmapInfo.Metadata ?? working.BeatmapSetInfo?.Metadata ?? new BeatmapMetadata();
PixelSnapping = true;
CacheDrawnFrameBuffer = true;
@ -164,7 +149,7 @@ namespace osu.Game.Screens.Select
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
VersionLabel = new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
Text = beatmapInfo.Version,
@ -174,101 +159,160 @@ namespace osu.Game.Screens.Select
},
new FillFlowContainer
{
Name = "Bottom-aligned metadata",
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft,
Name = "Centre-aligned metadata",
Anchor = Anchor.CentreLeft,
Origin = Anchor.TopLeft,
Y = -22,
Direction = FillDirection.Vertical,
Margin = new MarginPadding { Top = 15, Left = 25, Right = 10, Bottom = 20 },
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
TitleLabel = new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
Text = !string.IsNullOrEmpty(metadata.Source) ? metadata.Source + " — " + metadata.Title : metadata.Title,
Text = string.IsNullOrEmpty(metadata.Source) ? metadata.Title : metadata.Source + " — " + metadata.Title,
TextSize = 28,
},
new OsuSpriteText
ArtistLabel = new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
Text = metadata.Artist,
TextSize = 17,
},
new FillFlowContainer
MapperContainer = new FillFlowContainer
{
Margin = new MarginPadding { Top = 10 },
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Children = new[]
{
new OsuSpriteText
{
Font = @"Exo2.0-Medium",
Text = "mapped by ",
TextSize = 15,
},
new OsuSpriteText
{
Font = @"Exo2.0-Bold",
Text = metadata.Author.Username,
TextSize = 15,
},
}
Children = getMapper(metadata)
},
new FillFlowContainer
InfoLabelContainer = new FillFlowContainer
{
Margin = new MarginPadding { Top = 20, Left = 10 },
Spacing = new Vector2(40, 0),
Margin = new MarginPadding { Top = 20 },
Spacing = new Vector2(20, 0),
AutoSizeAxes = Axes.Both,
Children = labels
},
Children = getInfoLabels()
}
}
},
}
};
}
private InfoLabel[] getInfoLabels()
{
var beatmap = working.Beatmap;
var info = working.BeatmapInfo;
List<InfoLabel> labels = new List<InfoLabel>();
if (beatmap?.HitObjects?.Count > 0)
{
HitObject lastObject = beatmap.HitObjects.LastOrDefault();
double endTime = (lastObject as IHasEndTime)?.EndTime ?? lastObject?.StartTime ?? 0;
labels.Add(new InfoLabel(new BeatmapStatistic
{
Name = "Length",
Icon = FontAwesome.fa_clock_o,
Content = beatmap.HitObjects.Count == 0 ? "-" : TimeSpan.FromMilliseconds(endTime - beatmap.HitObjects.First().StartTime).ToString(@"m\:ss"),
}));
labels.Add(new InfoLabel(new BeatmapStatistic
{
Name = "BPM",
Icon = FontAwesome.fa_circle,
Content = getBPMRange(beatmap),
}));
//get statistics from the current ruleset.
labels.AddRange(info.Ruleset.CreateInstance().GetBeatmapStatistics(working).Select(s => new InfoLabel(s)));
}
return labels.ToArray();
}
private string getBPMRange(Beatmap beatmap)
{
double bpmMax = beatmap.ControlPointInfo.BPMMaximum;
double bpmMin = beatmap.ControlPointInfo.BPMMinimum;
if (Precision.AlmostEquals(bpmMin, bpmMax)) return $"{bpmMin:0}bpm";
if (Precision.AlmostEquals(bpmMin, bpmMax))
return $"{bpmMin:0}";
return $"{bpmMin:0}-{bpmMax:0}bpm (mostly {beatmap.ControlPointInfo.BPMMode:0}bpm)";
return $"{bpmMin:0}-{bpmMax:0} (mostly {beatmap.ControlPointInfo.BPMMode:0})";
}
public class InfoLabel : Container
private OsuSpriteText[] getMapper(BeatmapMetadata metadata)
{
if (string.IsNullOrEmpty(metadata.Author?.Username))
return Array.Empty<OsuSpriteText>();
return new[]
{
new OsuSpriteText
{
Font = @"Exo2.0-Medium",
Text = "mapped by ",
TextSize = 15,
},
new OsuSpriteText
{
Font = @"Exo2.0-Bold",
Text = metadata.Author.Username,
TextSize = 15,
}
};
}
public class InfoLabel : Container, IHasTooltip
{
public string TooltipText { get; private set; }
public InfoLabel(BeatmapStatistic statistic)
{
TooltipText = statistic.Name;
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
new SpriteIcon
new Container
{
Icon = FontAwesome.fa_square,
Origin = Anchor.Centre,
Colour = new Color4(68, 17, 136, 255),
Rotation = 45,
Size = new Vector2(20),
},
new SpriteIcon
{
Icon = statistic.Icon,
Origin = Anchor.Centre,
Colour = new Color4(255, 221, 85, 255),
Scale = new Vector2(0.8f),
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Size = new Vector2(20),
Children = new[]
{
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.FromHex(@"441288"),
Icon = FontAwesome.fa_square,
Rotation = 45,
},
new SpriteIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Scale = new Vector2(0.8f),
Colour = OsuColour.FromHex(@"f7dd55"),
Icon = statistic.Icon,
},
}
},
new OsuSpriteText
{
Margin = new MarginPadding { Left = 13 },
Font = @"Exo2.0-Bold",
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Colour = new Color4(255, 221, 85, 255),
Font = @"Exo2.0-Bold",
Margin = new MarginPadding { Left = 30 },
Text = statistic.Content,
TextSize = 17,
Origin = Anchor.CentreLeft
},
}
};
}
}

View File

@ -0,0 +1,55 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
using osu.Game.Beatmaps;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Screens.Select.Carousel
{
public class CarouselBeatmap : CarouselItem
{
public readonly BeatmapInfo Beatmap;
public CarouselBeatmap(BeatmapInfo beatmap)
{
Beatmap = beatmap;
State.Value = CarouselItemState.Collapsed;
}
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmap(this);
public override void Filter(FilterCriteria criteria)
{
base.Filter(criteria);
bool match = criteria.Ruleset == null || Beatmap.RulesetID == criteria.Ruleset.ID || Beatmap.RulesetID == 0 && criteria.Ruleset.ID > 0 && criteria.AllowConvertedBeatmaps;
if (!string.IsNullOrEmpty(criteria.SearchText))
match &=
Beatmap.Metadata.SearchableTerms.Any(term => term.IndexOf(criteria.SearchText, StringComparison.InvariantCultureIgnoreCase) >= 0) ||
Beatmap.Version.IndexOf(criteria.SearchText, StringComparison.InvariantCultureIgnoreCase) >= 0;
Filtered.Value = !match;
}
public override int CompareTo(FilterCriteria criteria, CarouselItem other)
{
if (!(other is CarouselBeatmap otherBeatmap))
return base.CompareTo(criteria, other);
switch (criteria.Sort)
{
default:
case SortMode.Difficulty:
var ruleset = Beatmap.RulesetID.CompareTo(otherBeatmap.Beatmap.RulesetID);
if (ruleset != 0) return ruleset;
return Beatmap.StarDifficulty.CompareTo(otherBeatmap.Beatmap.StarDifficulty);
}
}
public override string ToString() => Beatmap.ToString();
}
}

View File

@ -0,0 +1,58 @@
// Copyright (c) 2007-2017 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.Extensions.IEnumerableExtensions;
using osu.Game.Beatmaps;
using osu.Game.Screens.Select.Filter;
namespace osu.Game.Screens.Select.Carousel
{
public class CarouselBeatmapSet : CarouselGroupEagerSelect
{
public IEnumerable<CarouselBeatmap> Beatmaps => InternalChildren.OfType<CarouselBeatmap>();
public BeatmapSetInfo BeatmapSet;
public CarouselBeatmapSet(BeatmapSetInfo beatmapSet)
{
BeatmapSet = beatmapSet ?? throw new ArgumentNullException(nameof(beatmapSet));
beatmapSet.Beatmaps
.Where(b => !b.Hidden)
.Select(b => new CarouselBeatmap(b))
.ForEach(AddChild);
}
protected override DrawableCarouselItem CreateDrawableRepresentation() => new DrawableCarouselBeatmapSet(this);
public override int CompareTo(FilterCriteria criteria, CarouselItem other)
{
if (!(other is CarouselBeatmapSet otherSet))
return base.CompareTo(criteria, other);
switch (criteria.Sort)
{
default:
case SortMode.Artist:
return string.Compare(BeatmapSet.Metadata.Artist, otherSet.BeatmapSet.Metadata.Artist, StringComparison.InvariantCultureIgnoreCase);
case SortMode.Title:
return string.Compare(BeatmapSet.Metadata.Title, otherSet.BeatmapSet.Metadata.Title, StringComparison.InvariantCultureIgnoreCase);
case SortMode.Author:
return string.Compare(BeatmapSet.Metadata.Author.Username, otherSet.BeatmapSet.Metadata.Author.Username, StringComparison.InvariantCultureIgnoreCase);
case SortMode.Difficulty:
return BeatmapSet.MaxStarDifficulty.CompareTo(otherSet.BeatmapSet.MaxStarDifficulty);
}
}
public override void Filter(FilterCriteria criteria)
{
base.Filter(criteria);
Filtered.Value = InternalChildren.All(i => i.Filtered);
}
public override string ToString() => BeatmapSet.ToString();
}
}

View File

@ -0,0 +1,91 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System.Collections.Generic;
namespace osu.Game.Screens.Select.Carousel
{
/// <summary>
/// A group which ensures only one child is selected.
/// </summary>
public class CarouselGroup : CarouselItem
{
private readonly List<CarouselItem> items;
protected override DrawableCarouselItem CreateDrawableRepresentation() => null;
public IReadOnlyList<CarouselItem> Children => InternalChildren;
protected List<CarouselItem> InternalChildren = new List<CarouselItem>();
public override List<DrawableCarouselItem> Drawables
{
get
{
var drawables = base.Drawables;
foreach (var c in InternalChildren)
drawables.AddRange(c.Drawables);
return drawables;
}
}
public virtual void RemoveChild(CarouselItem i)
{
InternalChildren.Remove(i);
// it's important we do the deselection after removing, so any further actions based on
// State.ValueChanged make decisions post-removal.
i.State.Value = CarouselItemState.Collapsed;
}
public virtual void AddChild(CarouselItem i)
{
i.State.ValueChanged += v => ChildItemStateChanged(i, v);
InternalChildren.Add(i);
}
public CarouselGroup(List<CarouselItem> items = null)
{
if (items != null) InternalChildren = items;
State.ValueChanged += v =>
{
switch (v)
{
case CarouselItemState.Collapsed:
case CarouselItemState.NotSelected:
InternalChildren.ForEach(c => c.State.Value = CarouselItemState.Collapsed);
break;
case CarouselItemState.Selected:
InternalChildren.ForEach(c =>
{
if (c.State == CarouselItemState.Collapsed) c.State.Value = CarouselItemState.NotSelected;
});
break;
}
};
}
public override void Filter(FilterCriteria criteria)
{
base.Filter(criteria);
InternalChildren.Sort((x, y) => x.CompareTo(criteria, y));
InternalChildren.ForEach(c => c.Filter(criteria));
}
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
{
// ensure we are the only item selected
if (value == CarouselItemState.Selected)
{
foreach (var b in InternalChildren)
{
if (item == b) continue;
b.State.Value = CarouselItemState.NotSelected;
}
State.Value = CarouselItemState.Selected;
}
}
}
}

View File

@ -0,0 +1,104 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
namespace osu.Game.Screens.Select.Carousel
{
/// <summary>
/// A group which ensures at least one child is selected (if the group itself is selected).
/// </summary>
public class CarouselGroupEagerSelect : CarouselGroup
{
public CarouselGroupEagerSelect()
{
State.ValueChanged += v =>
{
if (v == CarouselItemState.Selected)
attemptSelection();
};
}
/// <summary>
/// We need to keep track of the index for cases where the selection is removed but we want to select a new item based on its old location.
/// </summary>
private int lastSelectedIndex;
private CarouselItem lastSelected;
/// <summary>
/// To avoid overhead during filter operations, we don't attempt any selections until after all
/// children have been filtered. This bool will be true during the base <see cref="Filter(FilterCriteria)"/>
/// operation.
/// </summary>
private bool filteringChildren;
public override void Filter(FilterCriteria criteria)
{
filteringChildren = true;
base.Filter(criteria);
filteringChildren = false;
attemptSelection();
}
public override void RemoveChild(CarouselItem i)
{
base.RemoveChild(i);
if (i != lastSelected)
updateSelectedIndex();
}
public override void AddChild(CarouselItem i)
{
base.AddChild(i);
attemptSelection();
}
protected override void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
{
base.ChildItemStateChanged(item, value);
switch (value)
{
case CarouselItemState.Selected:
updateSelected(item);
break;
case CarouselItemState.NotSelected:
case CarouselItemState.Collapsed:
attemptSelection();
break;
}
}
private void attemptSelection()
{
if (filteringChildren) return;
// we only perform eager selection if we are a currently selected group.
if (State != CarouselItemState.Selected) return;
// we only perform eager selection if none of our children are in a selected state already.
if (Children.Any(i => i.State == CarouselItemState.Selected)) return;
CarouselItem nextToSelect =
Children.Skip(lastSelectedIndex).FirstOrDefault(i => !i.Filtered) ??
Children.Reverse().Skip(InternalChildren.Count - lastSelectedIndex).FirstOrDefault(i => !i.Filtered);
if (nextToSelect != null)
nextToSelect.State.Value = CarouselItemState.Selected;
else
updateSelected(null);
}
private void updateSelected(CarouselItem newSelection)
{
lastSelected = newSelection;
updateSelectedIndex();
}
private void updateSelectedIndex() => lastSelectedIndex = lastSelected == null ? 0 : Math.Max(0, InternalChildren.IndexOf(lastSelected));
}
}

View File

@ -0,0 +1,62 @@
// Copyright (c) 2007-2017 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 osu.Framework.Configuration;
namespace osu.Game.Screens.Select.Carousel
{
public abstract class CarouselItem
{
public readonly BindableBool Filtered = new BindableBool();
public readonly Bindable<CarouselItemState> State = new Bindable<CarouselItemState>(CarouselItemState.NotSelected);
/// <summary>
/// This item is not in a hidden state.
/// </summary>
public bool Visible => State.Value != CarouselItemState.Collapsed && !Filtered;
public virtual List<DrawableCarouselItem> Drawables
{
get
{
var items = new List<DrawableCarouselItem>();
var self = drawableRepresentation.Value;
if (self?.IsPresent == true) items.Add(self);
return items;
}
}
protected CarouselItem()
{
drawableRepresentation = new Lazy<DrawableCarouselItem>(CreateDrawableRepresentation);
Filtered.ValueChanged += v =>
{
if (v && State == CarouselItemState.Selected)
State.Value = CarouselItemState.NotSelected;
};
}
private readonly Lazy<DrawableCarouselItem> drawableRepresentation;
protected abstract DrawableCarouselItem CreateDrawableRepresentation();
public virtual void Filter(FilterCriteria criteria)
{
}
public virtual int CompareTo(FilterCriteria criteria, CarouselItem other) => GetHashCode().CompareTo(other.GetHashCode());
}
public enum CarouselItemState
{
Collapsed,
NotSelected,
Selected,
}
}

View File

@ -0,0 +1,176 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Screens.Select.Carousel
{
public class DrawableCarouselBeatmap : DrawableCarouselItem, IHasContextMenu
{
private readonly BeatmapInfo beatmap;
private Sprite background;
private Action<BeatmapInfo> startRequested;
private Action<BeatmapInfo> editRequested;
private Action<BeatmapInfo> hideRequested;
private Triangles triangles;
private StarCounter starCounter;
public DrawableCarouselBeatmap(CarouselBeatmap panel) : base(panel)
{
beatmap = panel.Beatmap;
Height *= 0.60f;
}
[BackgroundDependencyLoader(true)]
private void load(SongSelect songSelect, BeatmapManager manager)
{
if (songSelect != null)
{
startRequested = songSelect.Start;
editRequested = songSelect.Edit;
}
if (manager != null)
hideRequested = manager.Hide;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
triangles = new Triangles
{
TriangleScale = 2,
RelativeSizeAxes = Axes.Both,
ColourLight = OsuColour.FromHex(@"3a7285"),
ColourDark = OsuColour.FromHex(@"123744")
},
new FillFlowContainer
{
Padding = new MarginPadding(5),
Direction = FillDirection.Horizontal,
AutoSizeAxes = Axes.Both,
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
Children = new Drawable[]
{
new DifficultyIcon(beatmap)
{
Scale = new Vector2(1.8f),
},
new FillFlowContainer
{
Padding = new MarginPadding { Left = 5 },
Direction = FillDirection.Vertical,
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new FillFlowContainer
{
Direction = FillDirection.Horizontal,
Spacing = new Vector2(4, 0),
AutoSizeAxes = Axes.Both,
Children = new[]
{
new OsuSpriteText
{
Font = @"Exo2.0-Medium",
Text = beatmap.Version,
TextSize = 20,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
new OsuSpriteText
{
Font = @"Exo2.0-Medium",
Text = "mapped by",
TextSize = 16,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
new OsuSpriteText
{
Font = @"Exo2.0-MediumItalic",
Text = $"{(beatmap.Metadata ?? beatmap.BeatmapSet.Metadata).Author.Username}",
TextSize = 16,
Anchor = Anchor.BottomLeft,
Origin = Anchor.BottomLeft
},
}
},
starCounter = new StarCounter
{
CountStars = (float)beatmap.StarDifficulty,
Scale = new Vector2(0.8f),
}
}
}
}
}
};
}
protected override void Selected()
{
base.Selected();
background.Colour = ColourInfo.GradientVertical(
new Color4(20, 43, 51, 255),
new Color4(40, 86, 102, 255));
triangles.Colour = Color4.White;
}
protected override void Deselected()
{
base.Deselected();
background.Colour = new Color4(20, 43, 51, 255);
triangles.Colour = OsuColour.Gray(0.5f);
}
protected override bool OnClick(InputState state)
{
if (Item.State == CarouselItemState.Selected)
startRequested?.Invoke(beatmap);
return base.OnClick(state);
}
protected override void ApplyState()
{
if (Item.State.Value != CarouselItemState.Collapsed && Alpha == 0)
starCounter.ReplayAnimation();
base.ApplyState();
}
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem("Play", MenuItemType.Highlighted, () => startRequested?.Invoke(beatmap)),
new OsuMenuItem("Edit", MenuItemType.Standard, () => editRequested?.Invoke(beatmap)),
new OsuMenuItem("Hide", MenuItemType.Destructive, () => hideRequested?.Invoke(beatmap)),
};
}
}

View File

@ -0,0 +1,185 @@
// Copyright (c) 2007-2017 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.Allocation;
using osu.Framework.Configuration;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.Drawables;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Screens.Select.Carousel
{
public class DrawableCarouselBeatmapSet : DrawableCarouselItem, IHasContextMenu
{
private Action<BeatmapSetInfo> deleteRequested;
private Action<BeatmapSetInfo> restoreHiddenRequested;
private Action<int> viewDetails;
private readonly BeatmapSetInfo beatmapSet;
private readonly FillFlowContainer difficultyIcons;
public DrawableCarouselBeatmapSet(CarouselBeatmapSet set)
: base(set)
{
beatmapSet = set.BeatmapSet;
}
[BackgroundDependencyLoader(true)]
private void load(LocalisationEngine localisation, BeatmapManager manager, BeatmapSetOverlay beatmapOverlay)
{
if (localisation == null)
throw new ArgumentNullException(nameof(localisation));
restoreHiddenRequested = s => s.Beatmaps.ForEach(manager.Restore);
deleteRequested = manager.Delete;
if (beatmapOverlay != null)
viewDetails = beatmapOverlay.ShowBeatmapSet;
Children = new Drawable[]
{
new DelayedLoadWrapper(
new PanelBackground(manager.GetWorkingBeatmap(beatmapSet.Beatmaps.FirstOrDefault()))
{
RelativeSizeAxes = Axes.Both,
OnLoadComplete = d => d.FadeInFromZero(1000, Easing.OutQuint),
}, 300
),
new FillFlowContainer
{
Direction = FillDirection.Vertical,
Padding = new MarginPadding { Top = 5, Left = 18, Right = 10, Bottom = 10 },
AutoSizeAxes = Axes.Both,
Children = new Drawable[]
{
new OsuSpriteText
{
Font = @"Exo2.0-BoldItalic",
Current = localisation.GetUnicodePreference(beatmapSet.Metadata.TitleUnicode, beatmapSet.Metadata.Title),
TextSize = 22,
Shadow = true,
},
new OsuSpriteText
{
Font = @"Exo2.0-SemiBoldItalic",
Current = localisation.GetUnicodePreference(beatmapSet.Metadata.ArtistUnicode, beatmapSet.Metadata.Artist),
TextSize = 17,
Shadow = true,
},
new FillFlowContainer<FilterableDifficultyIcon>
{
Margin = new MarginPadding { Top = 5 },
AutoSizeAxes = Axes.Both,
Children = ((CarouselBeatmapSet)Item).Beatmaps.Select(b => new FilterableDifficultyIcon(b)).ToList()
}
}
}
};
}
public MenuItem[] ContextMenuItems
{
get
{
List<MenuItem> items = new List<MenuItem>();
if (Item.State == CarouselItemState.NotSelected)
items.Add(new OsuMenuItem("Expand", MenuItemType.Highlighted, () => Item.State.Value = CarouselItemState.Selected));
if (beatmapSet.OnlineBeatmapSetID != null)
items.Add(new OsuMenuItem("Details...", MenuItemType.Standard, () => viewDetails?.Invoke(beatmapSet.OnlineBeatmapSetID.Value)));
if (beatmapSet.Beatmaps.Any(b => b.Hidden))
items.Add(new OsuMenuItem("Restore all hidden", MenuItemType.Standard, () => restoreHiddenRequested?.Invoke(beatmapSet)));
items.Add(new OsuMenuItem("Delete", MenuItemType.Destructive, () => deleteRequested?.Invoke(beatmapSet)));
return items.ToArray();
}
}
private class PanelBackground : BufferedContainer
{
public PanelBackground(WorkingBeatmap working)
{
CacheDrawnFrameBuffer = true;
Children = new Drawable[]
{
new BeatmapBackgroundSprite(working)
{
RelativeSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
FillMode = FillMode.Fill,
},
new FillFlowContainer
{
Depth = -1,
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Both,
// This makes the gradient not be perfectly horizontal, but diagonal at a ~40° angle
Shear = new Vector2(0.8f, 0),
Alpha = 0.5f,
Children = new[]
{
// The left half with no gradient applied
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Width = 0.4f,
},
// Piecewise-linear gradient with 3 segments to make it appear smoother
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(Color4.Black, new Color4(0f, 0f, 0f, 0.9f)),
Width = 0.05f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.9f), new Color4(0f, 0f, 0f, 0.1f)),
Width = 0.2f,
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = ColourInfo.GradientHorizontal(new Color4(0f, 0f, 0f, 0.1f), new Color4(0, 0, 0, 0)),
Width = 0.05f,
},
}
},
};
}
}
public class FilterableDifficultyIcon : DifficultyIcon
{
private readonly BindableBool filtered = new BindableBool();
public FilterableDifficultyIcon(CarouselBeatmap item)
: base(item.Beatmap)
{
filtered.BindTo(item.Filtered);
filtered.ValueChanged += v => Schedule(() => this.FadeTo(v ? 0.1f : 1, 100));
filtered.TriggerChange();
}
}
}
}

View File

@ -0,0 +1,154 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.MathUtils;
using osu.Game.Graphics;
using OpenTK;
using OpenTK.Graphics;
namespace osu.Game.Screens.Select.Carousel
{
public abstract class DrawableCarouselItem : Container
{
public const float MAX_HEIGHT = 80;
public override bool RemoveWhenNotAlive => false;
public override bool IsPresent => base.IsPresent || Item.Visible;
public readonly CarouselItem Item;
private Container nestedContainer;
private Container borderContainer;
private Box hoverLayer;
protected override Container<Drawable> Content => nestedContainer;
protected DrawableCarouselItem(CarouselItem item)
{
Item = item;
Height = MAX_HEIGHT;
RelativeSizeAxes = Axes.X;
Alpha = 0;
}
private SampleChannel sampleHover;
[BackgroundDependencyLoader]
private void load(AudioManager audio, OsuColour colours)
{
InternalChild = borderContainer = new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
CornerRadius = 10,
BorderColour = new Color4(221, 255, 255, 255),
Children = new Drawable[]
{
nestedContainer = new Container
{
RelativeSizeAxes = Axes.Both,
},
hoverLayer = new Box
{
RelativeSizeAxes = Axes.Both,
Alpha = 0,
Blending = BlendingMode.Additive,
},
}
};
sampleHover = audio.Sample.Get($@"SongSelect/song-ping-variation-{RNG.Next(1, 5)}");
hoverLayer.Colour = colours.Blue.Opacity(0.1f);
}
protected override bool OnHover(InputState state)
{
sampleHover?.Play();
hoverLayer.FadeIn(100, Easing.OutQuint);
return base.OnHover(state);
}
protected override void OnHoverLost(InputState state)
{
hoverLayer.FadeOut(1000, Easing.OutQuint);
base.OnHoverLost(state);
}
public void SetMultiplicativeAlpha(float alpha) => borderContainer.Alpha = alpha;
protected override void LoadComplete()
{
base.LoadComplete();
ApplyState();
Item.Filtered.ValueChanged += _ => Schedule(ApplyState);
Item.State.ValueChanged += _ => Schedule(ApplyState);
}
protected virtual void ApplyState()
{
if (!IsLoaded) return;
switch (Item.State.Value)
{
case CarouselItemState.NotSelected:
Deselected();
break;
case CarouselItemState.Selected:
Selected();
break;
}
if (!Item.Visible)
this.FadeOut(300, Easing.OutQuint);
else
this.FadeIn(250);
}
protected virtual void Selected()
{
Item.State.Value = CarouselItemState.Selected;
borderContainer.BorderThickness = 2.5f;
borderContainer.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Glow,
Colour = new Color4(130, 204, 255, 150),
Radius = 20,
Roundness = 10,
};
}
protected virtual void Deselected()
{
Item.State.Value = CarouselItemState.NotSelected;
borderContainer.BorderThickness = 0;
borderContainer.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(1),
Radius = 10,
Colour = Color4.Black.Opacity(100),
};
}
protected override bool OnClick(InputState state)
{
Item.State.Value = CarouselItemState.Selected;
return true;
}
}
}

View File

@ -1,14 +1,12 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input;
namespace osu.Game.Screens.Select
{
public class EditSongSelect : SongSelect
{
protected override bool ShowFooter => false;
protected override void OnSelected(InputState state) => Exit();
protected override void Start() => Exit();
}
}

View File

@ -75,7 +75,7 @@ namespace osu.Game.Screens.Select
{
Children = new Drawable[]
{
new Box
Background = new Box
{
Colour = Color4.Black,
Alpha = 0.8f,
@ -167,6 +167,8 @@ namespace osu.Game.Screens.Select
private Bindable<bool> showConverted;
public readonly Box Background;
[BackgroundDependencyLoader(permitNulls: true)]
private void load(OsuColour colours, OsuGame osu, OsuConfigManager config)
{

View File

@ -1,10 +1,6 @@
// Copyright (c) 2007-2017 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.Game.Beatmaps.Drawables;
using osu.Game.Rulesets;
using osu.Game.Screens.Select.Filter;
@ -17,47 +13,5 @@ namespace osu.Game.Screens.Select
public string SearchText;
public RulesetInfo Ruleset;
public bool AllowConvertedBeatmaps;
public void Filter(List<BeatmapGroup> groups)
{
foreach (var g in groups)
{
var set = g.BeatmapSet;
bool hasCurrentMode = AllowConvertedBeatmaps || set.Beatmaps.Any(bm => bm.RulesetID == (Ruleset?.ID ?? 0));
bool match = hasCurrentMode;
if (!string.IsNullOrEmpty(SearchText))
match &= set.Metadata.SearchableTerms.Any(term => term.IndexOf(SearchText, StringComparison.InvariantCultureIgnoreCase) >= 0);
switch (g.State)
{
case BeatmapGroupState.Hidden:
if (match) g.State = BeatmapGroupState.Collapsed;
break;
default:
if (!match) g.State = BeatmapGroupState.Hidden;
break;
}
}
switch (Sort)
{
default:
case SortMode.Artist:
groups.Sort((x, y) => string.Compare(x.BeatmapSet.Metadata.Artist, y.BeatmapSet.Metadata.Artist, StringComparison.InvariantCultureIgnoreCase));
break;
case SortMode.Title:
groups.Sort((x, y) => string.Compare(x.BeatmapSet.Metadata.Title, y.BeatmapSet.Metadata.Title, StringComparison.InvariantCultureIgnoreCase));
break;
case SortMode.Author:
groups.Sort((x, y) => string.Compare(x.BeatmapSet.Metadata.Author.Username, y.BeatmapSet.Metadata.Author.Username, StringComparison.InvariantCultureIgnoreCase));
break;
case SortMode.Difficulty:
groups.Sort((x, y) => x.BeatmapSet.MaxStarDifficulty.CompareTo(y.BeatmapSet.MaxStarDifficulty));
break;
}
}
}
}

View File

@ -0,0 +1,33 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Game.Graphics;
using osu.Game.Overlays.Dialog;
namespace osu.Game.Screens.Select
{
public class ImportFromStablePopup : PopupDialog
{
public ImportFromStablePopup(Action importFromStable)
{
HeaderText = @"You have no beatmaps!";
BodyText = "An existing copy of osu! was found, though.\nWould you like to import your beatmaps?";
Icon = FontAwesome.fa_trash_o;
Buttons = new PopupDialogButton[]
{
new PopupDialogOkButton
{
Text = @"Yes please!",
Action = importFromStable
},
new PopupDialogCancelButton
{
Text = @"No, I'd like to start from scratch",
},
};
}
}
}

View File

@ -18,14 +18,23 @@ using osu.Game.Rulesets.Scoring;
using osu.Game.Online.API;
using osu.Game.Online.API.Requests;
using System.Linq;
using osu.Framework.Configuration;
using osu.Framework.Logging;
using osu.Game.Rulesets;
namespace osu.Game.Screens.Select.Leaderboards
{
public class Leaderboard : Container
{
private const double fade_duration = 300;
private readonly ScrollContainer scrollContainer;
private readonly Container placeholderContainer;
private FillFlowContainer<LeaderboardScore> scrollFlow;
private readonly Bindable<RulesetInfo> ruleset = new Bindable<RulesetInfo>();
public Action<Score> ScoreSelected;
private readonly LoadingAnimation loading;
@ -38,15 +47,18 @@ namespace osu.Game.Screens.Select.Leaderboards
set
{
scores = value;
getScoresRequest?.Cancel();
scrollFlow?.FadeOut(200);
scrollFlow?.Expire();
scrollFlow?.FadeOut(fade_duration, Easing.OutQuint).Expire();
scrollFlow = null;
if (scores == null)
loading.Hide();
if (scores == null || !scores.Any())
return;
// ensure placeholder is hidden when displaying scores
PlaceholderState = PlaceholderState.Successful;
// schedule because we may not be loaded yet (LoadComponentAsync complains).
Schedule(() =>
{
@ -74,6 +86,56 @@ namespace osu.Game.Screens.Select.Leaderboards
}
}
private LeaderboardScope scope;
public LeaderboardScope Scope
{
get { return scope; }
set
{
if (value == scope) return;
scope = value;
updateScores();
}
}
private PlaceholderState placeholderState;
protected PlaceholderState PlaceholderState
{
get { return placeholderState; }
set
{
if (value == placeholderState) return;
switch (placeholderState = value)
{
case PlaceholderState.NetworkFailure:
replacePlaceholder(new RetrievalFailurePlaceholder
{
OnRetry = updateScores,
});
break;
case PlaceholderState.Unavailable:
replacePlaceholder(new MessagePlaceholder(@"Leaderboards are not available for this beatmap!"));
break;
case PlaceholderState.NoScores:
replacePlaceholder(new MessagePlaceholder(@"No records yet!"));
break;
case PlaceholderState.NotLoggedIn:
replacePlaceholder(new MessagePlaceholder(@"Please login to view online leaderboards!"));
break;
case PlaceholderState.NotSupporter:
replacePlaceholder(new MessagePlaceholder(@"Please invest in a supporter tag to view this leaderboard!"));
break;
default:
replacePlaceholder(null);
break;
}
}
}
public Leaderboard()
{
Children = new Drawable[]
@ -83,13 +145,17 @@ namespace osu.Game.Screens.Select.Leaderboards
RelativeSizeAxes = Axes.Both,
ScrollbarVisible = false,
},
loading = new LoadingAnimation()
loading = new LoadingAnimation(),
placeholderContainer = new Container
{
RelativeSizeAxes = Axes.Both
},
};
}
private APIAccess api;
private BeatmapInfo beatmap;
private OsuGame osuGame;
private ScheduledDelegate pendingBeatmapSwitch;
@ -109,33 +175,114 @@ namespace osu.Game.Screens.Select.Leaderboards
}
[BackgroundDependencyLoader(permitNulls: true)]
private void load(APIAccess api)
private void load(APIAccess api, OsuGame osuGame)
{
this.api = api;
this.osuGame = osuGame;
if (osuGame != null)
ruleset.BindTo(osuGame.Ruleset);
ruleset.ValueChanged += r => updateScores();
if (api != null)
api.OnStateChange += handleApiStateChange;
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
if (api != null)
api.OnStateChange -= handleApiStateChange;
}
private GetScoresRequest getScoresRequest;
private void handleApiStateChange(APIState oldState, APIState newState)
{
if (Scope == LeaderboardScope.Local)
// No need to respond to API state change while current scope is local
return;
if (newState == APIState.Online)
updateScores();
}
private void updateScores()
{
if (!IsLoaded) return;
Scores = null;
getScoresRequest?.Cancel();
getScoresRequest = null;
Scores = null;
if (api == null || Beatmap?.OnlineBeatmapID == null) return;
if (Scope == LeaderboardScope.Local)
{
// TODO: get local scores from wherever here.
PlaceholderState = PlaceholderState.NoScores;
return;
}
if (Beatmap?.OnlineBeatmapID == null)
{
PlaceholderState = PlaceholderState.Unavailable;
return;
}
if (api?.IsLoggedIn != true)
{
PlaceholderState = PlaceholderState.NotLoggedIn;
return;
}
PlaceholderState = PlaceholderState.Retrieving;
loading.Show();
getScoresRequest = new GetScoresRequest(Beatmap);
if (Scope != LeaderboardScope.Global && !api.LocalUser.Value.IsSupporter)
{
loading.Hide();
PlaceholderState = PlaceholderState.NotSupporter;
return;
}
getScoresRequest = new GetScoresRequest(Beatmap, osuGame?.Ruleset.Value ?? Beatmap.Ruleset, Scope);
getScoresRequest.Success += r =>
{
Scores = r.Scores;
loading.Hide();
PlaceholderState = Scores.Any() ? PlaceholderState.Successful : PlaceholderState.NoScores;
};
getScoresRequest.Failure += onUpdateFailed;
api.Queue(getScoresRequest);
}
private void onUpdateFailed(Exception e)
{
if (e is OperationCanceledException) return;
PlaceholderState = PlaceholderState.NetworkFailure;
Logger.Error(e, @"Couldn't fetch beatmap scores!");
}
private void replacePlaceholder(Placeholder placeholder)
{
var existingPlaceholder = placeholderContainer.Children.LastOrDefault() as Placeholder;
if (placeholder != null && placeholder.Equals(existingPlaceholder))
return;
existingPlaceholder?.FadeOut(150, Easing.OutQuint).Expire();
if (placeholder == null)
return;
Scores = null;
placeholderContainer.Add(placeholder);
placeholder.ScaleTo(0.8f).Then().ScaleTo(1, fade_duration * 3, Easing.OutQuint);
placeholder.FadeInFromZero(fade_duration, Easing.OutQuint);
}
protected override void Update()
{
base.Update();
@ -165,4 +312,23 @@ namespace osu.Game.Screens.Select.Leaderboards
}
}
}
public enum LeaderboardScope
{
Local,
Country,
Global,
Friend,
}
public enum PlaceholderState
{
Successful,
Retrieving,
NetworkFailure,
Unavailable,
NoScores,
NotLoggedIn,
NotSupporter,
}
}

View File

@ -0,0 +1,38 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using OpenTK;
namespace osu.Game.Screens.Select.Leaderboards
{
public class MessagePlaceholder : Placeholder
{
private readonly string message;
public MessagePlaceholder(string message)
{
Direction = FillDirection.Horizontal;
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
new SpriteIcon
{
Icon = FontAwesome.fa_exclamation_circle,
Size = new Vector2(26),
Margin = new MarginPadding { Right = 10 },
},
new OsuSpriteText
{
Text = this.message = message,
TextSize = 22,
},
};
}
public override bool Equals(Placeholder other) => (other as MessagePlaceholder)?.message == message;
}
}

View File

@ -0,0 +1,20 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
namespace osu.Game.Screens.Select.Leaderboards
{
public abstract class Placeholder : FillFlowContainer, IEquatable<Placeholder>
{
protected Placeholder()
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
public virtual bool Equals(Placeholder other) => GetType() == other?.GetType();
}
}

View File

@ -0,0 +1,77 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Sprites;
using OpenTK;
namespace osu.Game.Screens.Select.Leaderboards
{
public class RetrievalFailurePlaceholder : Placeholder
{
public Action OnRetry;
public RetrievalFailurePlaceholder()
{
Direction = FillDirection.Horizontal;
AutoSizeAxes = Axes.Both;
Children = new Drawable[]
{
new RetryButton
{
Action = () => OnRetry?.Invoke(),
Margin = new MarginPadding { Right = 10 },
},
new OsuSpriteText
{
Anchor = Anchor.TopLeft,
Text = @"Couldn't retrieve scores!",
TextSize = 22,
},
};
}
public class RetryButton : OsuHoverContainer
{
private readonly SpriteIcon icon;
public Action Action;
public RetryButton()
{
Height = 26;
Width = 26;
Child = new OsuClickableContainer
{
AutoSizeAxes = Axes.Both,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Action = () => Action?.Invoke(),
Child = icon = new SpriteIcon
{
Icon = FontAwesome.fa_refresh,
Size = new Vector2(26),
Shadow = true,
},
};
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args)
{
icon.ScaleTo(0.8f, 4000, Easing.OutQuint);
return base.OnMouseDown(state, args);
}
protected override bool OnMouseUp(InputState state, MouseUpEventArgs args)
{
icon.ScaleTo(1, 1000, Easing.OutElastic);
return base.OnMouseUp(state, args);
}
}
}
}

View File

@ -1,12 +1,10 @@
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Input;
namespace osu.Game.Screens.Select
{
public class MatchSongSelect : SongSelect
{
protected override void OnSelected(InputState state) => Exit();
protected override void Start() => Exit();
}
}

View File

@ -8,10 +8,10 @@ using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Input;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Graphics;
using osu.Game.Overlays;
using osu.Game.Overlays.Mods;
using osu.Game.Screens.Edit;
using osu.Game.Screens.Play;
@ -46,8 +46,8 @@ namespace osu.Game.Screens.Select
private SampleChannel sampleConfirm;
[BackgroundDependencyLoader]
private void load(OsuColour colours, AudioManager audio)
[BackgroundDependencyLoader(true)]
private void load(OsuColour colours, AudioManager audio, BeatmapManager beatmaps, DialogOverlay dialogOverlay)
{
sampleConfirm = audio.Sample.Get(@"SongSelect/confirm-selection");
@ -60,6 +60,16 @@ namespace osu.Game.Screens.Select
ValidForResume = false;
Push(new Editor());
}, Key.Number3);
if (dialogOverlay != null)
{
Schedule(() =>
{
// if we have no beatmaps but osu-stable is found, let's prompt the user to import.
if (!beatmaps.GetAllUsableBeatmapSets().Any() && beatmaps.StableInstallationAvailable)
dialogOverlay.Push(new ImportFromStablePopup(() => beatmaps.ImportFromStable()));
});
}
}
protected override void UpdateBeatmap(WorkingBeatmap beatmap)
@ -114,11 +124,12 @@ namespace osu.Game.Screens.Select
return false;
}
protected override void OnSelected(InputState state)
protected override void Start()
{
if (player != null) return;
if (state?.Keyboard.ControlPressed == true)
// Ctrl+Enter should start map with autoplay enabled.
if (GetContainingInputManager().CurrentState?.Keyboard.ControlPressed == true)
{
var auto = Ruleset.Value.CreateInstance().GetAutoplayMod();
var autoType = auto.GetType();

View File

@ -27,25 +27,11 @@ namespace osu.Game.Screens.Select
{
public abstract class SongSelect : OsuScreen
{
private BeatmapManager beatmaps;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap();
private readonly BeatmapCarousel carousel;
private DialogOverlay dialogOverlay;
private static readonly Vector2 wedged_container_size = new Vector2(0.5f, 245);
private static readonly Vector2 background_blur = new Vector2(20);
private const float left_area_padding = 20;
private readonly BeatmapInfoWedge beatmapInfoWedge;
protected Container LeftContent;
private static readonly Vector2 background_blur = new Vector2(20);
private CancellationTokenSource initialAddSetsTask;
private SampleChannel sampleChangeDifficulty;
private SampleChannel sampleChangeBeatmap;
public readonly FilterControl FilterControl;
protected virtual bool ShowFooter => true;
@ -65,77 +51,109 @@ namespace osu.Game.Screens.Select
/// </summary>
protected readonly Container FooterPanels;
public readonly FilterControl FilterControl;
protected override BackgroundScreen CreateBackground() => new BackgroundScreenBeatmap();
protected Container LeftContent;
protected readonly BeatmapCarousel Carousel;
private readonly BeatmapInfoWedge beatmapInfoWedge;
private DialogOverlay dialogOverlay;
private BeatmapManager beatmaps;
private SampleChannel sampleChangeDifficulty;
private SampleChannel sampleChangeBeatmap;
private CancellationTokenSource initialAddSetsTask;
private DependencyContainer dependencies;
protected override IReadOnlyDependencyContainer CreateLocalDependencies(IReadOnlyDependencyContainer parent) => dependencies = new DependencyContainer(parent);
protected SongSelect()
{
const float carousel_width = 640;
const float filter_height = 100;
Add(new ParallaxContainer
AddRange(new Drawable[]
{
Padding = new MarginPadding { Top = filter_height },
ParallaxAmount = 0.005f,
RelativeSizeAxes = Axes.Both,
Children = new[]
new ParallaxContainer
{
new WedgeBackground
Padding = new MarginPadding { Top = filter_height },
ParallaxAmount = 0.005f,
RelativeSizeAxes = Axes.Both,
Children = new[]
{
new WedgeBackground
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = carousel_width * 0.76f },
}
}
},
LeftContent = new Container
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(wedged_container_size.X, 1),
Padding = new MarginPadding
{
Bottom = 50,
Top = wedged_container_size.Y + left_area_padding,
Left = left_area_padding,
Right = left_area_padding * 2,
}
},
new Container
{
RelativeSizeAxes = Axes.Both,
Masking = true,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 2, //avoid horizontal masking so the panels don't clip when screen stack is pushed.
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Right = carousel_width * 0.76f },
}
}
});
Add(LeftContent = new Container
{
Origin = Anchor.BottomLeft,
Anchor = Anchor.BottomLeft,
RelativeSizeAxes = Axes.Both,
Size = new Vector2(wedged_container_size.X, 1),
Padding = new MarginPadding
{
Bottom = 50,
Top = wedged_container_size.Y + left_area_padding,
Left = left_area_padding,
Right = left_area_padding * 2,
}
});
Add(carousel = new BeatmapCarousel
{
RelativeSizeAxes = Axes.Y,
Size = new Vector2(carousel_width, 1),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
SelectionChanged = carouselSelectionChanged,
BeatmapsChanged = carouselBeatmapsLoaded,
DeleteRequested = promptDelete,
RestoreRequested = s => { foreach (var b in s.Beatmaps) beatmaps.Restore(b); },
EditRequested = editRequested,
HideDifficultyRequested = b => beatmaps.Hide(b),
StartRequested = () => carouselRaisedStart(),
});
Add(FilterControl = new FilterControl
{
RelativeSizeAxes = Axes.X,
Height = filter_height,
FilterChanged = criteria => filterChanged(criteria),
Exit = Exit,
});
Add(beatmapInfoWedge = new BeatmapInfoWedge
{
Alpha = 0,
Size = wedged_container_size,
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding
{
Top = left_area_padding,
Right = left_area_padding,
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = 0.5f,
Children = new Drawable[]
{
Carousel = new BeatmapCarousel
{
Masking = false,
RelativeSizeAxes = Axes.Y,
Size = new Vector2(carousel_width, 1),
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
SelectionChanged = carouselSelectionChanged,
BeatmapSetsChanged = carouselBeatmapsLoaded,
},
FilterControl = new FilterControl
{
RelativeSizeAxes = Axes.X,
Height = filter_height,
FilterChanged = c => Carousel.Filter(c),
Background = { Width = 2 },
Exit = Exit,
},
}
},
},
});
Add(new ResetScrollContainer(() => carousel.ScrollToSelected())
{
RelativeSizeAxes = Axes.Y,
Width = 250,
beatmapInfoWedge = new BeatmapInfoWedge
{
Size = wedged_container_size,
RelativeSizeAxes = Axes.X,
Margin = new MarginPadding
{
Top = left_area_padding,
Right = left_area_padding,
},
},
new ResetScrollContainer(() => Carousel.ScrollToSelected())
{
RelativeSizeAxes = Axes.Y,
Width = 250,
}
});
if (ShowFooter)
@ -163,12 +181,14 @@ namespace osu.Game.Screens.Select
[BackgroundDependencyLoader(permitNulls: true)]
private void load(BeatmapManager beatmaps, AudioManager audio, DialogOverlay dialog, OsuGame osu, OsuColour colours)
{
dependencies.Cache(this);
if (Footer != null)
{
Footer.AddButton(@"random", colours.Green, triggerRandom, Key.F2);
Footer.AddButton(@"options", colours.Blue, BeatmapOptions, Key.F3);
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, () => promptDelete(Beatmap.Value.BeatmapSetInfo), Key.Number4, float.MaxValue);
BeatmapOptions.AddButton(@"Delete", @"Beatmap", FontAwesome.fa_trash, colours.Pink, () => delete(Beatmap.Value.BeatmapSetInfo), Key.Number4, float.MaxValue);
}
if (this.beatmaps == null)
@ -189,36 +209,31 @@ namespace osu.Game.Screens.Select
initialAddSetsTask = new CancellationTokenSource();
carousel.Beatmaps = this.beatmaps.GetAllUsableBeatmapSets();
Carousel.BeatmapSets = this.beatmaps.GetAllUsableBeatmapSets();
Beatmap.ValueChanged += beatmap_ValueChanged;
Beatmap.DisabledChanged += disabled => Carousel.AllowSelection = !disabled;
Beatmap.TriggerChange();
Beatmap.DisabledChanged += disabled => carousel.AllowSelection = !disabled;
carousel.AllowSelection = !Beatmap.Disabled;
Beatmap.ValueChanged += b =>
{
if (IsCurrentScreen)
Carousel.SelectBeatmap(b?.BeatmapInfo);
};
}
private void editRequested(BeatmapInfo beatmap)
public void Edit(BeatmapInfo beatmap)
{
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap);
Push(new Editor());
}
private void onBeatmapRestored(BeatmapInfo b) => Schedule(() => carousel.UpdateBeatmap(b));
private void onBeatmapHidden(BeatmapInfo b) => Schedule(() => carousel.UpdateBeatmap(b));
private void carouselBeatmapsLoaded()
{
if (Beatmap.Value.BeatmapSetInfo?.DeletePending == false)
carousel.SelectBeatmap(Beatmap.Value.BeatmapInfo, false);
else
carousel.SelectNextRandom();
}
private void carouselRaisedStart(InputState state = null)
public void Start(BeatmapInfo beatmap)
{
// if we have a pending filter operation, we want to run it now.
// it could change selection (ie. if the ruleset has been changed).
carousel.FlushPendingFilters();
Carousel.FlushPendingFilterOperations();
Carousel.SelectBeatmap(beatmap);
if (selectionChangedDebounce?.Completed == false)
{
@ -227,9 +242,14 @@ namespace osu.Game.Screens.Select
selectionChangedDebounce = null;
}
OnSelected(state);
Start();
}
/// <summary>
/// Called when a selection is made.
/// </summary>
protected abstract void Start();
private ScheduledDelegate selectionChangedDebounce;
// We need to keep track of the last selected beatmap ignoring debounce to play the correct selection sounds.
@ -246,7 +266,7 @@ namespace osu.Game.Screens.Select
// In these cases, the other component has already loaded the beatmap, so we don't need to do so again.
if (beatmap?.Equals(Beatmap.Value.BeatmapInfo) != true)
{
bool preview = beatmap?.BeatmapSetInfoID != Beatmap.Value.BeatmapInfo.BeatmapSetInfoID;
bool preview = beatmap?.BeatmapSetInfoID != Beatmap.Value?.BeatmapInfo.BeatmapSetInfoID;
Beatmap.Value = beatmaps.GetWorkingBeatmap(beatmap, Beatmap);
ensurePlayingSelected(preview);
@ -255,18 +275,15 @@ namespace osu.Game.Screens.Select
UpdateBeatmap(Beatmap.Value);
};
selectionChangedDebounce?.Cancel();
if (beatmap?.Equals(beatmapNoDebounce) == true)
return;
selectionChangedDebounce?.Cancel();
beatmapNoDebounce = beatmap;
if (beatmap == null)
{
if (!Beatmap.IsDefault)
performLoad();
}
performLoad();
else
{
if (beatmap.BeatmapSetInfoID == beatmapNoDebounce?.BeatmapSetInfoID)
@ -277,35 +294,23 @@ namespace osu.Game.Screens.Select
if (beatmap == Beatmap.Value.BeatmapInfo)
performLoad();
else
selectionChangedDebounce = Scheduler.AddDelayed(performLoad, 100);
selectionChangedDebounce = Scheduler.AddDelayed(performLoad, 200);
}
}
private void triggerRandom()
{
if (GetContainingInputManager().CurrentState.Keyboard.ShiftPressed)
carousel.SelectPreviousRandom();
Carousel.SelectPreviousRandom();
else
carousel.SelectNextRandom();
Carousel.SelectNextRandom();
}
protected abstract void OnSelected(InputState state);
private void filterChanged(FilterCriteria criteria, bool debounce = true)
{
carousel.Filter(criteria, debounce);
}
private void onBeatmapSetAdded(BeatmapSetInfo s) => Schedule(() => addBeatmapSet(s));
private void onBeatmapSetRemoved(BeatmapSetInfo s) => Schedule(() => removeBeatmapSet(s));
protected override void OnEntering(Screen last)
{
base.OnEntering(last);
Content.FadeInFromZero(250);
FilterControl.Activate();
}
@ -334,7 +339,7 @@ namespace osu.Game.Screens.Select
logo.Action = () =>
{
carouselRaisedStart();
Start();
return false;
};
}
@ -346,13 +351,6 @@ namespace osu.Game.Screens.Select
logo.FadeOut(logo_transition / 2, Easing.Out);
}
private void beatmap_ValueChanged(WorkingBeatmap beatmap)
{
if (!IsCurrentScreen) return;
carousel.SelectBeatmap(beatmap?.BeatmapInfo);
}
protected override void OnResuming(Screen last)
{
if (Beatmap != null && !Beatmap.Value.BeatmapSetInfo.DeletePending)
@ -413,15 +411,13 @@ namespace osu.Game.Screens.Select
/// <param name="beatmap">The working beatmap.</param>
protected virtual void UpdateBeatmap(WorkingBeatmap beatmap)
{
var backgroundModeBeatmap = Background as BackgroundScreenBeatmap;
if (backgroundModeBeatmap != null)
if (Background is BackgroundScreenBeatmap backgroundModeBeatmap)
{
backgroundModeBeatmap.Beatmap = beatmap;
backgroundModeBeatmap.BlurTo(background_blur, 750, Easing.OutQuint);
backgroundModeBeatmap.FadeTo(1, 250);
}
beatmapInfoWedge.State = Visibility.Visible;
beatmapInfoWedge.UpdateBeatmap(beatmap);
}
@ -439,20 +435,22 @@ namespace osu.Game.Screens.Select
}
}
private void addBeatmapSet(BeatmapSetInfo beatmapSet) => carousel.AddBeatmap(beatmapSet);
private void onBeatmapSetAdded(BeatmapSetInfo s) => Carousel.UpdateBeatmapSet(s);
private void onBeatmapSetRemoved(BeatmapSetInfo s) => Carousel.RemoveBeatmapSet(s);
private void onBeatmapRestored(BeatmapInfo b) => Carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
private void onBeatmapHidden(BeatmapInfo b) => Carousel.UpdateBeatmapSet(beatmaps.QueryBeatmapSet(s => s.ID == b.BeatmapSetInfoID));
private void removeBeatmapSet(BeatmapSetInfo beatmapSet)
private void carouselBeatmapsLoaded()
{
carousel.RemoveBeatmap(beatmapSet);
if (carousel.SelectedBeatmap == null)
Beatmap.SetDefault();
if (!Beatmap.IsDefault && Beatmap.Value.BeatmapSetInfo?.DeletePending == false)
Carousel.SelectBeatmap(Beatmap.Value.BeatmapInfo);
else if (Carousel.SelectedBeatmapSet == null)
Carousel.SelectNextRandom();
}
private void promptDelete(BeatmapSetInfo beatmap)
private void delete(BeatmapSetInfo beatmap)
{
if (beatmap == null)
return;
if (beatmap == null) return;
dialogOverlay?.Push(new BeatmapDeleteDialog(beatmap));
}
@ -464,15 +462,16 @@ namespace osu.Game.Screens.Select
{
case Key.KeypadEnter:
case Key.Enter:
carouselRaisedStart(state);
Start();
return true;
case Key.Delete:
if (state.Keyboard.ShiftPressed)
{
if (!Beatmap.IsDefault)
promptDelete(Beatmap.Value.BeatmapSetInfo);
delete(Beatmap.Value.BeatmapSetInfo);
return true;
}
break;
}