Split collection toggle menu item to own class

This commit is contained in:
Salman Ahmed 2022-07-08 01:39:43 +03:00
parent b9acdcdbe2
commit a94fb62be3
2 changed files with 21 additions and 15 deletions

View File

@ -0,0 +1,20 @@
using osu.Game.Beatmaps;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Collections
{
public class CollectionToggleMenuItem : ToggleMenuItem
{
public CollectionToggleMenuItem(BeatmapCollection collection, IBeatmapInfo beatmap)
: base(collection.Name.Value, MenuItemType.Standard, s =>
{
if (s)
collection.BeatmapHashes.Add(beatmap.MD5Hash);
else
collection.BeatmapHashes.Remove(beatmap.MD5Hash);
})
{
State.Value = collection.BeatmapHashes.Contains(beatmap.MD5Hash);
}
}
}

View File

@ -244,7 +244,7 @@ namespace osu.Game.Screens.Select.Carousel
if (collectionManager != null)
{
var collectionItems = collectionManager.Collections.Select(createCollectionMenuItem).ToList();
var collectionItems = collectionManager.Collections.Select(c => new CollectionToggleMenuItem(c, beatmapInfo)).Cast<OsuMenuItem>().ToList();
if (manageCollectionsDialog != null)
collectionItems.Add(new OsuMenuItem("Manage...", MenuItemType.Standard, manageCollectionsDialog.Show));
@ -258,20 +258,6 @@ namespace osu.Game.Screens.Select.Carousel
}
}
private MenuItem createCollectionMenuItem(BeatmapCollection collection)
{
return new ToggleMenuItem(collection.Name.Value, MenuItemType.Standard, s =>
{
if (s)
collection.BeatmapHashes.Add(beatmapInfo.MD5Hash);
else
collection.BeatmapHashes.Remove(beatmapInfo.MD5Hash);
})
{
State = { Value = collection.BeatmapHashes.Contains(beatmapInfo.MD5Hash) }
};
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);