1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-06 09:07:25 +08:00

Merge branch 'master' into HandleInput

This commit is contained in:
Dean Herbert 2017-12-11 15:24:29 +09:00 committed by GitHub
commit 04715f9a51
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 47 additions and 42 deletions

View File

@ -34,7 +34,6 @@ namespace osu.Game.Screens.Select
public IEnumerable<BeatmapSetInfo> Beatmaps
{
get { return groups.Select(g => g.BeatmapSet); }
set
{
scrollableContent.Clear(false);
@ -52,7 +51,7 @@ namespace osu.Game.Screens.Select
Schedule(() =>
{
foreach (var g in newGroups)
if (g != null) addGroup(g);
addGroup(g);
computeYPositions();
BeatmapsChanged?.Invoke();
@ -95,50 +94,31 @@ namespace osu.Game.Screens.Select
});
}
public void AddBeatmap(BeatmapSetInfo beatmapSet)
{
Schedule(() =>
{
var group = createGroup(beatmapSet);
if (group == null)
return;
addGroup(group);
computeYPositions();
if (selectedGroup == null)
selectGroup(group);
});
}
public void RemoveBeatmap(BeatmapSetInfo beatmapSet)
{
Schedule(() => removeGroup(groups.Find(b => b.BeatmapSet.ID == beatmapSet.ID)));
}
public void UpdateBeatmap(BeatmapInfo beatmap)
public void UpdateBeatmapSet(BeatmapSetInfo beatmapSet)
{
// 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);
var oldGroup = groups.Find(b => b.BeatmapSet.ID == beatmapSet.ID);
int i = groups.IndexOf(group);
if (i >= 0)
groups.RemoveAt(i);
var newGroup = createGroup(beatmapSet);
var newGroup = createGroup(set);
int index = groups.IndexOf(oldGroup);
if (index >= 0)
groups.RemoveAt(index);
if (newGroup != null)
{
if (i >= 0)
groups.Insert(i, newGroup);
if (index >= 0)
groups.Insert(index, newGroup);
else
groups.Add(newGroup);
addGroup(newGroup);
}
bool hadSelection = selectedGroup == group;
bool hadSelection = selectedGroup == oldGroup;
if (hadSelection && newGroup == null)
selectedGroup = null;
@ -149,8 +129,10 @@ namespace osu.Game.Screens.Select
if (hadSelection && newGroup != null)
{
var newSelection =
newGroup.BeatmapPanels.Find(p => p.Beatmap.ID == selectedPanel?.Beatmap.ID) ??
newGroup.BeatmapPanels[Math.Min(newGroup.BeatmapPanels.Count - 1, group.BeatmapPanels.IndexOf(selectedPanel))];
newGroup.BeatmapPanels.Find(p => p.Beatmap.ID == selectedPanel?.Beatmap.ID);
if(newSelection == null && oldGroup != null && selectedPanel != null)
newSelection = newGroup.BeatmapPanels[Math.Min(newGroup.BeatmapPanels.Count - 1, oldGroup.BeatmapPanels.IndexOf(selectedPanel))];
selectGroup(newGroup, newSelection);
}
@ -308,8 +290,6 @@ namespace osu.Game.Screens.Select
if (newCriteria != null)
criteria = newCriteria;
if (!IsLoaded) return;
Action perform = delegate
{
filterTask = null;
@ -381,6 +361,10 @@ namespace osu.Game.Screens.Select
private void addGroup(BeatmapGroup group)
{
// prevent duplicates by concurrent independent actions trying to add a group
if (groups.Any(g => g.BeatmapSet.ID == group.BeatmapSet.ID))
return;
groups.Add(group);
panels.Add(group.Header);
panels.AddRange(group.BeatmapPanels);

View File

@ -2,6 +2,7 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using System.Linq;
using System.Threading;
using OpenTK;
using OpenTK.Input;
@ -203,8 +204,23 @@ namespace osu.Game.Screens.Select
Push(new Editor());
}
private void onBeatmapRestored(BeatmapInfo b) => Schedule(() => carousel.UpdateBeatmap(b));
private void onBeatmapHidden(BeatmapInfo b) => Schedule(() => carousel.UpdateBeatmap(b));
private void onBeatmapRestored(BeatmapInfo beatmap)
{
Schedule(() =>
{
var beatmapSet = beatmaps.QueryBeatmapSet(s => s.ID == beatmap.BeatmapSetInfoID);
carousel.UpdateBeatmapSet(beatmapSet);
});
}
private void onBeatmapHidden(BeatmapInfo beatmap)
{
Schedule(() =>
{
var beatmapSet = beatmaps.QueryBeatmapSet(s => s.ID == beatmap.BeatmapSetInfoID);
carousel.UpdateBeatmapSet(beatmapSet);
});
}
private void carouselBeatmapsLoaded()
{
@ -255,11 +271,11 @@ namespace osu.Game.Screens.Select
UpdateBeatmap(Beatmap.Value);
};
selectionChangedDebounce?.Cancel();
if (beatmap?.Equals(beatmapNoDebounce) == true)
return;
selectionChangedDebounce?.Cancel();
beatmapNoDebounce = beatmap;
if (beatmap == null)
@ -293,7 +309,14 @@ namespace osu.Game.Screens.Select
carousel.Filter(criteria, debounce);
}
private void onBeatmapSetAdded(BeatmapSetInfo s) => Schedule(() => addBeatmapSet(s));
private void onBeatmapSetAdded(BeatmapSetInfo s)
{
Schedule(() =>
{
carousel.UpdateBeatmapSet(s);
carousel.SelectBeatmap(s.Beatmaps.First());
});
}
private void onBeatmapSetRemoved(BeatmapSetInfo s) => Schedule(() => removeBeatmapSet(s));
@ -436,8 +459,6 @@ namespace osu.Game.Screens.Select
}
}
private void addBeatmapSet(BeatmapSetInfo beatmapSet) => carousel.AddBeatmap(beatmapSet);
private void removeBeatmapSet(BeatmapSetInfo beatmapSet)
{
carousel.RemoveBeatmap(beatmapSet);