mirror of
https://github.com/ppy/osu.git
synced 2025-02-22 02:03:20 +08:00
Merge branch 'master' into realm-context-use-update-when-feasible
This commit is contained in:
commit
8f1dfa33a2
@ -26,8 +26,6 @@ namespace osu.Game.Database
|
|||||||
private readonly OsuConfigManager config;
|
private readonly OsuConfigManager config;
|
||||||
private readonly Storage storage;
|
private readonly Storage storage;
|
||||||
|
|
||||||
private bool hasTakenBackup;
|
|
||||||
|
|
||||||
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config, Storage storage)
|
public EFToRealmMigrator(DatabaseContextFactory efContextFactory, RealmContextFactory realmContextFactory, OsuConfigManager config, Storage storage)
|
||||||
{
|
{
|
||||||
this.efContextFactory = efContextFactory;
|
this.efContextFactory = efContextFactory;
|
||||||
@ -38,6 +36,8 @@ namespace osu.Game.Database
|
|||||||
|
|
||||||
public void Run()
|
public void Run()
|
||||||
{
|
{
|
||||||
|
createBackup();
|
||||||
|
|
||||||
using (var ef = efContextFactory.Get())
|
using (var ef = efContextFactory.Get())
|
||||||
{
|
{
|
||||||
migrateSettings(ef);
|
migrateSettings(ef);
|
||||||
@ -77,8 +77,6 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Logger.Log($"Found {count} beatmaps in EF", LoggingTarget.Database);
|
Logger.Log($"Found {count} beatmaps in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
ensureBackup();
|
|
||||||
|
|
||||||
// only migrate data if the realm database is empty.
|
// only migrate data if the realm database is empty.
|
||||||
// note that this cannot be written as: `realm.All<BeatmapSetInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
// note that this cannot be written as: `realm.All<BeatmapSetInfo>().All(s => s.Protected)`, because realm does not support `.All()`.
|
||||||
if (realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
|
if (realm.All<BeatmapSetInfo>().Any(s => !s.Protected))
|
||||||
@ -210,8 +208,6 @@ namespace osu.Game.Database
|
|||||||
{
|
{
|
||||||
Logger.Log($"Found {count} scores in EF", LoggingTarget.Database);
|
Logger.Log($"Found {count} scores in EF", LoggingTarget.Database);
|
||||||
|
|
||||||
ensureBackup();
|
|
||||||
|
|
||||||
// only migrate data if the realm database is empty.
|
// only migrate data if the realm database is empty.
|
||||||
if (realm.All<ScoreInfo>().Any())
|
if (realm.All<ScoreInfo>().Any())
|
||||||
{
|
{
|
||||||
@ -291,8 +287,6 @@ namespace osu.Game.Database
|
|||||||
if (!existingSkins.Any())
|
if (!existingSkins.Any())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
ensureBackup();
|
|
||||||
|
|
||||||
var userSkinChoice = config.GetBindable<string>(OsuSetting.Skin);
|
var userSkinChoice = config.GetBindable<string>(OsuSetting.Skin);
|
||||||
int.TryParse(userSkinChoice.Value, out int userSkinInt);
|
int.TryParse(userSkinChoice.Value, out int userSkinInt);
|
||||||
|
|
||||||
@ -365,7 +359,6 @@ namespace osu.Game.Database
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
Logger.Log("Beginning settings migration to realm", LoggingTarget.Database);
|
Logger.Log("Beginning settings migration to realm", LoggingTarget.Database);
|
||||||
ensureBackup();
|
|
||||||
|
|
||||||
realmContextFactory.Run(realm =>
|
realmContextFactory.Run(realm =>
|
||||||
{
|
{
|
||||||
@ -404,21 +397,16 @@ namespace osu.Game.Database
|
|||||||
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
private string? getRulesetShortNameFromLegacyID(long rulesetId) =>
|
||||||
efContextFactory.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
efContextFactory.Get().RulesetInfo.FirstOrDefault(r => r.ID == rulesetId)?.ShortName;
|
||||||
|
|
||||||
private void ensureBackup()
|
private void createBackup()
|
||||||
{
|
{
|
||||||
if (!hasTakenBackup)
|
string migration = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
||||||
{
|
|
||||||
string migration = $"before_final_migration_{DateTimeOffset.UtcNow.ToUnixTimeSeconds()}";
|
|
||||||
|
|
||||||
efContextFactory.CreateBackup($"client.{migration}.db");
|
efContextFactory.CreateBackup($"client.{migration}.db");
|
||||||
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
realmContextFactory.CreateBackup($"client.{migration}.realm");
|
||||||
|
|
||||||
using (var source = storage.GetStream("collection.db"))
|
using (var source = storage.GetStream("collection.db"))
|
||||||
using (var destination = storage.GetStream($"collection.{migration}.db", FileAccess.Write, FileMode.CreateNew))
|
using (var destination = storage.GetStream($"collection.{migration}.db", FileAccess.Write, FileMode.CreateNew))
|
||||||
source.CopyTo(destination);
|
source.CopyTo(destination);
|
||||||
|
|
||||||
hasTakenBackup = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -420,9 +420,24 @@ namespace osu.Game.Database
|
|||||||
using (BlockAllOperations())
|
using (BlockAllOperations())
|
||||||
{
|
{
|
||||||
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
Logger.Log($"Creating full realm database backup at {backupFilename}", LoggingTarget.Database);
|
||||||
using (var source = storage.GetStream(Filename))
|
|
||||||
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
|
int attempts = 10;
|
||||||
source.CopyTo(destination);
|
|
||||||
|
while (attempts-- > 0)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
using (var source = storage.GetStream(Filename))
|
||||||
|
using (var destination = storage.GetStream(backupFilename, FileAccess.Write, FileMode.CreateNew))
|
||||||
|
source.CopyTo(destination);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
catch (IOException)
|
||||||
|
{
|
||||||
|
// file may be locked during use.
|
||||||
|
Thread.Sleep(500);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,9 +114,10 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
CarouselRoot newRoot = new CarouselRoot(this);
|
CarouselRoot newRoot = new CarouselRoot(this);
|
||||||
|
|
||||||
newRoot.AddChildren(beatmapSets.Select(createCarouselSet).Where(g => g != null));
|
newRoot.AddChildren(beatmapSets.Select(s => createCarouselSet(s.Detach())).Where(g => g != null));
|
||||||
|
|
||||||
root = newRoot;
|
root = newRoot;
|
||||||
|
|
||||||
if (selectedBeatmapSet != null && !beatmapSets.Contains(selectedBeatmapSet.BeatmapSet))
|
if (selectedBeatmapSet != null && !beatmapSets.Contains(selectedBeatmapSet.BeatmapSet))
|
||||||
selectedBeatmapSet = null;
|
selectedBeatmapSet = null;
|
||||||
|
|
||||||
@ -208,7 +209,7 @@ namespace osu.Game.Screens.Select
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (int i in changes.InsertedIndices)
|
foreach (int i in changes.InsertedIndices)
|
||||||
RemoveBeatmapSet(sender[i]);
|
removeBeatmapSet(sender[i].ID);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beatmapSetsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error)
|
private void beatmapSetsChanged(IRealmCollection<BeatmapSetInfo> sender, ChangeSet changes, Exception error)
|
||||||
@ -222,24 +223,21 @@ namespace osu.Game.Screens.Select
|
|||||||
// During initial population, we must manually account for the fact that our original query was done on an async thread.
|
// During initial population, we must manually account for the fact that our original query was done on an async thread.
|
||||||
// Since then, there may have been imports or deletions.
|
// Since then, there may have been imports or deletions.
|
||||||
// Here we manually catch up on any changes.
|
// Here we manually catch up on any changes.
|
||||||
var populatedSets = new HashSet<Guid>();
|
|
||||||
foreach (var s in beatmapSets)
|
|
||||||
populatedSets.Add(s.BeatmapSet.ID);
|
|
||||||
|
|
||||||
var realmSets = new HashSet<Guid>();
|
var realmSets = new HashSet<Guid>();
|
||||||
foreach (var s in sender)
|
|
||||||
realmSets.Add(s.ID);
|
|
||||||
|
|
||||||
foreach (var s in realmSets)
|
for (int i = 0; i < sender.Count; i++)
|
||||||
|
realmSets.Add(sender[i].ID);
|
||||||
|
|
||||||
|
foreach (var id in realmSets)
|
||||||
{
|
{
|
||||||
if (!populatedSets.Contains(s))
|
if (!root.BeatmapSetsByID.ContainsKey(id))
|
||||||
UpdateBeatmapSet(realmFactory.Context.Find<BeatmapSetInfo>(s));
|
UpdateBeatmapSet(realmFactory.Context.Find<BeatmapSetInfo>(id).Detach());
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach (var s in populatedSets)
|
foreach (var id in root.BeatmapSetsByID.Keys)
|
||||||
{
|
{
|
||||||
if (!realmSets.Contains(s))
|
if (!realmSets.Contains(id))
|
||||||
RemoveBeatmapSet(realmFactory.Context.Find<BeatmapSetInfo>(s));
|
removeBeatmapSet(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
signalBeatmapsLoaded();
|
signalBeatmapsLoaded();
|
||||||
@ -247,10 +245,10 @@ namespace osu.Game.Screens.Select
|
|||||||
}
|
}
|
||||||
|
|
||||||
foreach (int i in changes.NewModifiedIndices)
|
foreach (int i in changes.NewModifiedIndices)
|
||||||
UpdateBeatmapSet(sender[i]);
|
UpdateBeatmapSet(sender[i].Detach());
|
||||||
|
|
||||||
foreach (int i in changes.InsertedIndices)
|
foreach (int i in changes.InsertedIndices)
|
||||||
UpdateBeatmapSet(sender[i]);
|
UpdateBeatmapSet(sender[i].Detach());
|
||||||
}
|
}
|
||||||
|
|
||||||
private void beatmapsChanged(IRealmCollection<BeatmapInfo> sender, ChangeSet changes, Exception error)
|
private void beatmapsChanged(IRealmCollection<BeatmapInfo> sender, ChangeSet changes, Exception error)
|
||||||
@ -260,16 +258,30 @@ namespace osu.Game.Screens.Select
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (int i in changes.InsertedIndices)
|
foreach (int i in changes.InsertedIndices)
|
||||||
UpdateBeatmapSet(sender[i].BeatmapSet);
|
{
|
||||||
|
var beatmapInfo = sender[i];
|
||||||
|
var beatmapSet = beatmapInfo.BeatmapSet;
|
||||||
|
|
||||||
|
Debug.Assert(beatmapSet != null);
|
||||||
|
|
||||||
|
// Only require to action here if the beatmap is missing.
|
||||||
|
// This avoids processing these events unnecessarily when new beatmaps are imported, for example.
|
||||||
|
if (root.BeatmapSetsByID.TryGetValue(beatmapSet.ID, out var existingSet)
|
||||||
|
&& existingSet.BeatmapSet.Beatmaps.All(b => b.ID != beatmapInfo.ID))
|
||||||
|
{
|
||||||
|
UpdateBeatmapSet(beatmapSet.Detach());
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private IRealmCollection<BeatmapSetInfo> getBeatmapSets(Realm realm) => realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected).AsRealmCollection();
|
private IRealmCollection<BeatmapSetInfo> getBeatmapSets(Realm realm) => realm.All<BeatmapSetInfo>().Where(s => !s.DeletePending && !s.Protected).AsRealmCollection();
|
||||||
|
|
||||||
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet) => Schedule(() =>
|
public void RemoveBeatmapSet(BeatmapSetInfo beatmapSet) =>
|
||||||
{
|
removeBeatmapSet(beatmapSet.ID);
|
||||||
var existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.Equals(beatmapSet));
|
|
||||||
|
|
||||||
if (existingSet == null)
|
private void removeBeatmapSet(Guid beatmapSetID) => Schedule(() =>
|
||||||
|
{
|
||||||
|
if (!root.BeatmapSetsByID.TryGetValue(beatmapSetID, out var existingSet))
|
||||||
return;
|
return;
|
||||||
|
|
||||||
root.RemoveChild(existingSet);
|
root.RemoveChild(existingSet);
|
||||||
@ -280,35 +292,32 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
Guid? previouslySelectedID = null;
|
Guid? previouslySelectedID = null;
|
||||||
|
|
||||||
CarouselBeatmapSet existingSet = beatmapSets.FirstOrDefault(b => b.BeatmapSet.Equals(beatmapSet));
|
|
||||||
|
|
||||||
// If the selected beatmap is about to be removed, store its ID so it can be re-selected if required
|
// If the selected beatmap is about to be removed, store its ID so it can be re-selected if required
|
||||||
if (existingSet?.State?.Value == CarouselItemState.Selected)
|
if (selectedBeatmapSet?.BeatmapSet.ID == beatmapSet.ID)
|
||||||
previouslySelectedID = selectedBeatmap?.BeatmapInfo.ID;
|
previouslySelectedID = selectedBeatmap?.BeatmapInfo.ID;
|
||||||
|
|
||||||
var newSet = createCarouselSet(beatmapSet);
|
var newSet = createCarouselSet(beatmapSet);
|
||||||
|
|
||||||
if (existingSet != null)
|
root.RemoveChild(beatmapSet.ID);
|
||||||
root.RemoveChild(existingSet);
|
|
||||||
|
|
||||||
if (newSet == null)
|
if (newSet != null)
|
||||||
{
|
{
|
||||||
itemsCache.Invalidate();
|
root.AddChild(newSet);
|
||||||
return;
|
|
||||||
|
// check if we can/need to maintain our current selection.
|
||||||
|
if (previouslySelectedID != null)
|
||||||
|
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.BeatmapInfo.ID == previouslySelectedID) ?? newSet);
|
||||||
}
|
}
|
||||||
|
|
||||||
root.AddChild(newSet);
|
|
||||||
|
|
||||||
// only reset scroll position if already near the scroll target.
|
|
||||||
// without this, during a large beatmap import it is impossible to navigate the carousel.
|
|
||||||
applyActiveCriteria(false, alwaysResetScrollPosition: false);
|
|
||||||
|
|
||||||
// check if we can/need to maintain our current selection.
|
|
||||||
if (previouslySelectedID != null)
|
|
||||||
select((CarouselItem)newSet.Beatmaps.FirstOrDefault(b => b.BeatmapInfo.ID == previouslySelectedID) ?? newSet);
|
|
||||||
|
|
||||||
itemsCache.Invalidate();
|
itemsCache.Invalidate();
|
||||||
Schedule(() => BeatmapSetsChanged?.Invoke());
|
|
||||||
|
Schedule(() =>
|
||||||
|
{
|
||||||
|
if (!Scroll.UserScrolling)
|
||||||
|
ScrollToSelected(true);
|
||||||
|
|
||||||
|
BeatmapSetsChanged?.Invoke();
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -710,8 +719,6 @@ namespace osu.Game.Screens.Select
|
|||||||
|
|
||||||
private CarouselBeatmapSet createCarouselSet(BeatmapSetInfo beatmapSet)
|
private CarouselBeatmapSet createCarouselSet(BeatmapSetInfo beatmapSet)
|
||||||
{
|
{
|
||||||
beatmapSet = beatmapSet.Detach();
|
|
||||||
|
|
||||||
// This can be moved to the realm query if required using:
|
// This can be moved to the realm query if required using:
|
||||||
// .Filter("DeletePending == false && Protected == false && ANY Beatmaps.Hidden == false")
|
// .Filter("DeletePending == false && Protected == false && ANY Beatmaps.Hidden == false")
|
||||||
//
|
//
|
||||||
@ -912,6 +919,8 @@ namespace osu.Game.Screens.Select
|
|||||||
{
|
{
|
||||||
private readonly BeatmapCarousel carousel;
|
private readonly BeatmapCarousel carousel;
|
||||||
|
|
||||||
|
public readonly Dictionary<Guid, CarouselBeatmapSet> BeatmapSetsByID = new Dictionary<Guid, CarouselBeatmapSet>();
|
||||||
|
|
||||||
public CarouselRoot(BeatmapCarousel carousel)
|
public CarouselRoot(BeatmapCarousel carousel)
|
||||||
{
|
{
|
||||||
// root should always remain selected. if not, PerformSelection will not be called.
|
// root should always remain selected. if not, PerformSelection will not be called.
|
||||||
@ -921,6 +930,28 @@ namespace osu.Game.Screens.Select
|
|||||||
this.carousel = carousel;
|
this.carousel = carousel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override void AddChild(CarouselItem i)
|
||||||
|
{
|
||||||
|
CarouselBeatmapSet set = (CarouselBeatmapSet)i;
|
||||||
|
BeatmapSetsByID.Add(set.BeatmapSet.ID, set);
|
||||||
|
|
||||||
|
base.AddChild(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveChild(Guid beatmapSetID)
|
||||||
|
{
|
||||||
|
if (BeatmapSetsByID.TryGetValue(beatmapSetID, out var carouselBeatmapSet))
|
||||||
|
RemoveChild(carouselBeatmapSet);
|
||||||
|
}
|
||||||
|
|
||||||
|
public override void RemoveChild(CarouselItem i)
|
||||||
|
{
|
||||||
|
CarouselBeatmapSet set = (CarouselBeatmapSet)i;
|
||||||
|
BeatmapSetsByID.Remove(set.BeatmapSet.ID);
|
||||||
|
|
||||||
|
base.RemoveChild(i);
|
||||||
|
}
|
||||||
|
|
||||||
protected override void PerformSelection()
|
protected override void PerformSelection()
|
||||||
{
|
{
|
||||||
if (LastSelected == null || LastSelected.Filtered.Value)
|
if (LastSelected == null || LastSelected.Filtered.Value)
|
||||||
|
@ -55,7 +55,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
|
|
||||||
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
match &= !criteria.UserStarDifficulty.HasFilter || criteria.UserStarDifficulty.IsInRange(BeatmapInfo.StarRating);
|
||||||
|
|
||||||
if (match)
|
if (match && criteria.SearchTerms.Length > 0)
|
||||||
{
|
{
|
||||||
string[] terms = BeatmapInfo.GetSearchableTerms();
|
string[] terms = BeatmapInfo.GetSearchableTerms();
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@
|
|||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
|
#nullable enable
|
||||||
|
|
||||||
namespace osu.Game.Screens.Select.Carousel
|
namespace osu.Game.Screens.Select.Carousel
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -11,7 +13,7 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class CarouselGroup : CarouselItem
|
public class CarouselGroup : CarouselItem
|
||||||
{
|
{
|
||||||
public override DrawableCarouselItem CreateDrawableRepresentation() => null;
|
public override DrawableCarouselItem? CreateDrawableRepresentation() => null;
|
||||||
|
|
||||||
public IReadOnlyList<CarouselItem> Children => InternalChildren;
|
public IReadOnlyList<CarouselItem> Children => InternalChildren;
|
||||||
|
|
||||||
@ -23,6 +25,10 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
private ulong currentChildID;
|
private ulong currentChildID;
|
||||||
|
|
||||||
|
private Comparer<CarouselItem>? criteriaComparer;
|
||||||
|
|
||||||
|
private FilterCriteria? lastCriteria;
|
||||||
|
|
||||||
public virtual void RemoveChild(CarouselItem i)
|
public virtual void RemoveChild(CarouselItem i)
|
||||||
{
|
{
|
||||||
InternalChildren.Remove(i);
|
InternalChildren.Remove(i);
|
||||||
@ -36,10 +42,24 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
{
|
{
|
||||||
i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue);
|
i.State.ValueChanged += state => ChildItemStateChanged(i, state.NewValue);
|
||||||
i.ChildID = ++currentChildID;
|
i.ChildID = ++currentChildID;
|
||||||
InternalChildren.Add(i);
|
|
||||||
|
if (lastCriteria != null)
|
||||||
|
{
|
||||||
|
i.Filter(lastCriteria);
|
||||||
|
|
||||||
|
int index = InternalChildren.BinarySearch(i, criteriaComparer);
|
||||||
|
if (index < 0) index = ~index; // BinarySearch hacks multiple return values with 2's complement.
|
||||||
|
|
||||||
|
InternalChildren.Insert(index, i);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// criteria may be null for initial population. the filtering will be applied post-add.
|
||||||
|
InternalChildren.Add(i);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public CarouselGroup(List<CarouselItem> items = null)
|
public CarouselGroup(List<CarouselItem>? items = null)
|
||||||
{
|
{
|
||||||
if (items != null) InternalChildren = items;
|
if (items != null) InternalChildren = items;
|
||||||
|
|
||||||
@ -67,9 +87,12 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
base.Filter(criteria);
|
base.Filter(criteria);
|
||||||
|
|
||||||
InternalChildren.ForEach(c => c.Filter(criteria));
|
InternalChildren.ForEach(c => c.Filter(criteria));
|
||||||
|
|
||||||
// IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability
|
// IEnumerable<T>.OrderBy() is used instead of List<T>.Sort() to ensure sorting stability
|
||||||
var criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y));
|
criteriaComparer = Comparer<CarouselItem>.Create((x, y) => x.CompareTo(criteria, y));
|
||||||
InternalChildren = InternalChildren.OrderBy(c => c, criteriaComparer).ToList();
|
InternalChildren = InternalChildren.OrderBy(c => c, criteriaComparer).ToList();
|
||||||
|
|
||||||
|
lastCriteria = criteria;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
protected virtual void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
||||||
|
@ -55,10 +55,16 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
updateSelectedIndex();
|
updateSelectedIndex();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool addingChildren;
|
||||||
|
|
||||||
public void AddChildren(IEnumerable<CarouselItem> items)
|
public void AddChildren(IEnumerable<CarouselItem> items)
|
||||||
{
|
{
|
||||||
|
addingChildren = true;
|
||||||
|
|
||||||
foreach (var i in items)
|
foreach (var i in items)
|
||||||
base.AddChild(i);
|
AddChild(i);
|
||||||
|
|
||||||
|
addingChildren = false;
|
||||||
|
|
||||||
attemptSelection();
|
attemptSelection();
|
||||||
}
|
}
|
||||||
@ -66,7 +72,8 @@ namespace osu.Game.Screens.Select.Carousel
|
|||||||
public override void AddChild(CarouselItem i)
|
public override void AddChild(CarouselItem i)
|
||||||
{
|
{
|
||||||
base.AddChild(i);
|
base.AddChild(i);
|
||||||
attemptSelection();
|
if (!addingChildren)
|
||||||
|
attemptSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
protected override void ChildItemStateChanged(CarouselItem item, CarouselItemState value)
|
||||||
|
Loading…
Reference in New Issue
Block a user