1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-13 15:43:21 +08:00

Tidy up naming of collection dropdowns

This commit is contained in:
Dean Herbert 2022-07-28 13:48:15 +09:00
parent 226eefcc5c
commit ad482b8afc
7 changed files with 33 additions and 26 deletions

View File

@ -149,7 +149,7 @@ namespace osu.Game.Tests.Visual.Collections
{
AddStep("add dropdown", () =>
{
Add(new CollectionFilterDropdown
Add(new CollectionDropdown
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,

View File

@ -74,14 +74,14 @@ namespace osu.Game.Tests.Visual.Navigation
AddStep("set filter again", () => songSelect.ChildrenOfType<SearchTextBox>().Single().Current.Value = "test");
AddStep("open collections dropdown", () =>
{
InputManager.MoveMouseTo(songSelect.ChildrenOfType<CollectionFilterDropdown>().Single());
InputManager.MoveMouseTo(songSelect.ChildrenOfType<CollectionDropdown>().Single());
InputManager.Click(MouseButton.Left);
});
AddStep("press back once", () => InputManager.Click(MouseButton.Button1));
AddAssert("still at song select", () => Game.ScreenStack.CurrentScreen == songSelect);
AddAssert("collections dropdown closed", () => songSelect
.ChildrenOfType<CollectionFilterDropdown>().Single()
.ChildrenOfType<CollectionDropdown>().Single()
.ChildrenOfType<Dropdown<CollectionFilterMenuItem>.DropdownMenu>().Single().State == MenuState.Closed);
AddStep("press back a second time", () => InputManager.Click(MouseButton.Button1));

View File

@ -94,7 +94,7 @@ namespace osu.Game.Tests.Visual.SongSelect
AddStep("add collection", () => Realm.Write(r => r.Add(new BeatmapCollection(name: "1"))));
AddStep("select collection", () =>
{
var dropdown = control.ChildrenOfType<CollectionFilterDropdown>().Single();
var dropdown = control.ChildrenOfType<CollectionDropdown>().Single();
dropdown.Current.Value = dropdown.ItemSource.ElementAt(1);
});
@ -210,7 +210,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private void assertCollectionHeaderDisplays(string collectionName, bool shouldDisplay = true)
=> AddAssert($"collection dropdown header displays '{collectionName}'",
() => shouldDisplay == (control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single().ChildrenOfType<SpriteText>().First().Text == collectionName));
() => shouldDisplay == (control.ChildrenOfType<CollectionDropdown.CollectionDropdownHeader>().Single().ChildrenOfType<SpriteText>().First().Text == collectionName));
private void assertCollectionDropdownContains(string collectionName, bool shouldContain = true) =>
AddAssert($"collection dropdown {(shouldContain ? "contains" : "does not contain")} '{collectionName}'",
@ -222,7 +222,7 @@ namespace osu.Game.Tests.Visual.SongSelect
private void addExpandHeaderStep() => AddStep("expand header", () =>
{
InputManager.MoveMouseTo(control.ChildrenOfType<CollectionFilterDropdown.CollectionDropdownHeader>().Single());
InputManager.MoveMouseTo(control.ChildrenOfType<CollectionDropdown.CollectionDropdownHeader>().Single());
InputManager.Click(MouseButton.Left);
});
@ -233,6 +233,6 @@ namespace osu.Game.Tests.Visual.SongSelect
});
private IEnumerable<Dropdown<CollectionFilterMenuItem>.DropdownMenu.DrawableDropdownMenuItem> getCollectionDropdownItems()
=> control.ChildrenOfType<CollectionFilterDropdown>().Single().ChildrenOfType<Dropdown<CollectionFilterMenuItem>.DropdownMenu.DrawableDropdownMenuItem>();
=> control.ChildrenOfType<CollectionDropdown>().Single().ChildrenOfType<Dropdown<CollectionFilterMenuItem>.DropdownMenu.DrawableDropdownMenuItem>();
}
}

View File

@ -21,9 +21,9 @@ using Realms;
namespace osu.Game.Collections
{
/// <summary>
/// A dropdown to select the <see cref="CollectionFilterMenuItem"/> to filter beatmaps using.
/// A dropdown to select the collection to be used to filter results.
/// </summary>
public class CollectionFilterDropdown : OsuDropdown<CollectionFilterMenuItem>
public class CollectionDropdown : OsuDropdown<CollectionFilterMenuItem>
{
/// <summary>
/// Whether to show the "manage collections..." menu item in the dropdown.
@ -40,7 +40,9 @@ namespace osu.Game.Collections
[Resolved]
private RealmAccess realm { get; set; } = null!;
public CollectionFilterDropdown()
private IDisposable? realmSubscription;
public CollectionDropdown()
{
ItemSource = filters;
@ -51,7 +53,7 @@ namespace osu.Game.Collections
{
base.LoadComplete();
realm.RegisterForNotifications(r => r.All<BeatmapCollection>(), collectionsChanged);
realmSubscription = realm.RegisterForNotifications(r => r.All<BeatmapCollection>(), collectionsChanged);
Current.BindValueChanged(selectionChanged);
}
@ -114,6 +116,12 @@ namespace osu.Game.Collections
}
}
protected override void Dispose(bool isDisposing)
{
base.Dispose(isDisposing);
realmSubscription?.Dispose();
}
protected override LocalisableString GenerateItemText(CollectionFilterMenuItem item) => item.CollectionName;
protected sealed override DropdownHeader CreateHeader() => CreateCollectionHeader();
@ -150,18 +158,19 @@ namespace osu.Game.Collections
protected class CollectionDropdownDrawableMenuItem : OsuDropdownMenu.DrawableOsuDropdownMenuItem
{
protected new CollectionFilterMenuItem Item => ((DropdownMenuItem<CollectionFilterMenuItem>)base.Item).Value;
private IconButton addOrRemoveButton = null!;
private bool beatmapInCollection;
private readonly Live<BeatmapCollection>? collection;
[Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
public CollectionDropdownDrawableMenuItem(MenuItem item)
: base(item)
{
collection = ((DropdownMenuItem<CollectionFilterMenuItem>)item).Value.Collection;
}
[BackgroundDependencyLoader]
@ -181,13 +190,11 @@ namespace osu.Game.Collections
{
base.LoadComplete();
if (Item.Collection != null)
if (collection != null)
{
beatmap.BindValueChanged(_ =>
{
Debug.Assert(Item.Collection != null);
beatmapInCollection = Item.Collection.PerformRead(c => c.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash));
beatmapInCollection = collection.PerformRead(c => c.BeatmapMD5Hashes.Contains(beatmap.Value.BeatmapInfo.MD5Hash));
addOrRemoveButton.Enabled.Value = !beatmap.IsDefault;
addOrRemoveButton.Icon = beatmapInCollection ? FontAwesome.Solid.MinusSquare : FontAwesome.Solid.PlusSquare;
@ -220,7 +227,7 @@ namespace osu.Game.Collections
private void updateButtonVisibility()
{
if (Item.Collection == null)
if (collection == null)
addOrRemoveButton.Alpha = 0;
else
addOrRemoveButton.Alpha = IsHovered || IsPreSelected || beatmapInCollection ? 1 : 0;
@ -228,9 +235,9 @@ namespace osu.Game.Collections
private void addOrRemove()
{
Debug.Assert(Item.Collection != null);
Debug.Assert(collection != null);
Item.Collection.PerformWrite(c =>
collection.PerformWrite(c =>
{
if (!c.BeatmapMD5Hashes.Remove(beatmap.Value.BeatmapInfo.MD5Hash))
c.BeatmapMD5Hashes.Add(beatmap.Value.BeatmapInfo.MD5Hash);

View File

@ -18,7 +18,7 @@ namespace osu.Game.Overlays.Music
public Action<FilterCriteria> FilterChanged;
public readonly FilterTextBox Search;
private readonly CollectionDropdown collectionDropdown;
private readonly NowPlayingCollectionDropdown collectionDropdown;
public FilterControl()
{
@ -36,7 +36,7 @@ namespace osu.Game.Overlays.Music
RelativeSizeAxes = Axes.X,
Height = 40,
},
collectionDropdown = new CollectionDropdown { RelativeSizeAxes = Axes.X }
collectionDropdown = new NowPlayingCollectionDropdown { RelativeSizeAxes = Axes.X }
},
},
};

View File

@ -15,9 +15,9 @@ using osu.Game.Graphics;
namespace osu.Game.Overlays.Music
{
/// <summary>
/// A <see cref="CollectionFilterDropdown"/> for use in the <see cref="NowPlayingOverlay"/>.
/// A <see cref="CollectionDropdown"/> for use in the <see cref="NowPlayingOverlay"/>.
/// </summary>
public class CollectionDropdown : CollectionFilterDropdown
public class NowPlayingCollectionDropdown : CollectionDropdown
{
protected override bool ShowManageCollectionsItem => false;

View File

@ -41,7 +41,7 @@ namespace osu.Game.Screens.Select
private SeekLimitedSearchTextBox searchTextBox;
private CollectionFilterDropdown collectionDropdown;
private CollectionDropdown collectionDropdown;
public FilterCriteria CreateCriteria()
{
@ -179,7 +179,7 @@ namespace osu.Game.Screens.Select
RelativeSizeAxes = Axes.Both,
Width = 0.48f,
},
collectionDropdown = new CollectionFilterDropdown
collectionDropdown = new CollectionDropdown
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,