mirror of
https://github.com/ppy/osu.git
synced 2025-01-30 01:32:55 +08:00
Apply refactorings for framework-side changes
This commit is contained in:
parent
ebf15c6a1c
commit
f6ba98eec0
@ -19,12 +19,11 @@ using osuTK.Graphics;
|
|||||||
|
|
||||||
namespace osu.Game.Overlays.Music
|
namespace osu.Game.Overlays.Music
|
||||||
{
|
{
|
||||||
public class PlaylistList : RearrangeableListContainer<PlaylistListItem>
|
public class PlaylistList : RearrangeableListContainer<BeatmapSetInfo>
|
||||||
{
|
{
|
||||||
public Action<BeatmapSetInfo> RequestSelection;
|
public Action<BeatmapSetInfo> RequestSelection;
|
||||||
|
|
||||||
public readonly Bindable<BeatmapSetInfo> SelectedSet = new Bindable<BeatmapSetInfo>();
|
public readonly Bindable<BeatmapSetInfo> SelectedSet = new Bindable<BeatmapSetInfo>();
|
||||||
public readonly IBindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
|
||||||
|
|
||||||
public new MarginPadding Padding
|
public new MarginPadding Padding
|
||||||
{
|
{
|
||||||
@ -32,44 +31,17 @@ namespace osu.Game.Overlays.Music
|
|||||||
set => base.Padding = value;
|
set => base.Padding = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly HashSet<BeatmapSetInfo> existingItems = new HashSet<BeatmapSetInfo>();
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load()
|
|
||||||
{
|
|
||||||
BeatmapSets.ItemsAdded += addBeatmapSets;
|
|
||||||
BeatmapSets.ItemsRemoved += removeBeatmapSets;
|
|
||||||
|
|
||||||
foreach (var item in BeatmapSets)
|
|
||||||
addBeatmapSet(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Filter(string searchTerm) => ((PlaylistListFlowContainer)ListContainer).SearchTerm = searchTerm;
|
public void Filter(string searchTerm) => ((PlaylistListFlowContainer)ListContainer).SearchTerm = searchTerm;
|
||||||
|
|
||||||
public BeatmapSetInfo FirstVisibleSet => ListContainer.FlowingChildren.Cast<DrawablePlaylistListItem>().FirstOrDefault(i => i.MatchingFilter)?.Model.BeatmapSetInfo;
|
public BeatmapSetInfo FirstVisibleSet => ListContainer.FlowingChildren.Cast<DrawablePlaylistListItem>().FirstOrDefault(i => i.MatchingFilter)?.Model;
|
||||||
|
|
||||||
private void addBeatmapSets(IEnumerable<BeatmapSetInfo> sets)
|
|
||||||
{
|
|
||||||
foreach (var set in sets)
|
|
||||||
addBeatmapSet(set);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addBeatmapSet(BeatmapSetInfo set) => Schedule(() =>
|
|
||||||
{
|
|
||||||
if (existingItems.Contains(set))
|
|
||||||
return;
|
|
||||||
|
|
||||||
AddItem(new PlaylistListItem(set));
|
|
||||||
existingItems.Add(set);
|
|
||||||
});
|
|
||||||
|
|
||||||
private void removeBeatmapSets(IEnumerable<BeatmapSetInfo> sets) => Schedule(() =>
|
private void removeBeatmapSets(IEnumerable<BeatmapSetInfo> sets) => Schedule(() =>
|
||||||
{
|
{
|
||||||
foreach (var item in sets)
|
foreach (var item in sets)
|
||||||
RemoveItem(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m.BeatmapSetInfo == item));
|
Items.Remove(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m == item));
|
||||||
});
|
});
|
||||||
|
|
||||||
protected override DrawableRearrangeableListItem<PlaylistListItem> CreateDrawable(PlaylistListItem item) => new DrawablePlaylistListItem(item)
|
protected override DrawableRearrangeableListItem<BeatmapSetInfo> CreateDrawable(BeatmapSetInfo item) => new DrawablePlaylistListItem(item)
|
||||||
{
|
{
|
||||||
SelectedSet = { BindTarget = SelectedSet },
|
SelectedSet = { BindTarget = SelectedSet },
|
||||||
RequestSelection = set => RequestSelection?.Invoke(set)
|
RequestSelection = set => RequestSelection?.Invoke(set)
|
||||||
@ -77,7 +49,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
|
|
||||||
protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer();
|
protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer();
|
||||||
|
|
||||||
protected override FillFlowContainer<DrawableRearrangeableListItem<PlaylistListItem>> CreateListFillFlowContainer() => new PlaylistListFlowContainer
|
protected override FillFlowContainer<DrawableRearrangeableListItem<BeatmapSetInfo>> CreateListFillFlowContainer() => new PlaylistListFlowContainer
|
||||||
{
|
{
|
||||||
Spacing = new Vector2(0, 3),
|
Spacing = new Vector2(0, 3),
|
||||||
LayoutDuration = 200,
|
LayoutDuration = 200,
|
||||||
@ -85,25 +57,11 @@ namespace osu.Game.Overlays.Music
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlaylistListFlowContainer : SearchContainer<DrawableRearrangeableListItem<PlaylistListItem>>
|
public class PlaylistListFlowContainer : SearchContainer<DrawableRearrangeableListItem<BeatmapSetInfo>>
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
public class PlaylistListItem : IEquatable<PlaylistListItem>
|
public class DrawablePlaylistListItem : DrawableRearrangeableListItem<BeatmapSetInfo>, IFilterable
|
||||||
{
|
|
||||||
public readonly BeatmapSetInfo BeatmapSetInfo;
|
|
||||||
|
|
||||||
public PlaylistListItem(BeatmapSetInfo beatmapSetInfo)
|
|
||||||
{
|
|
||||||
BeatmapSetInfo = beatmapSetInfo;
|
|
||||||
}
|
|
||||||
|
|
||||||
public override string ToString() => BeatmapSetInfo.ToString();
|
|
||||||
|
|
||||||
public bool Equals(PlaylistListItem other) => BeatmapSetInfo.Equals(other?.BeatmapSetInfo);
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DrawablePlaylistListItem : DrawableRearrangeableListItem<PlaylistListItem>, IFilterable
|
|
||||||
{
|
{
|
||||||
private const float fade_duration = 100;
|
private const float fade_duration = 100;
|
||||||
|
|
||||||
@ -119,7 +77,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
private Color4 hoverColour;
|
private Color4 hoverColour;
|
||||||
private Color4 artistColour;
|
private Color4 artistColour;
|
||||||
|
|
||||||
public DrawablePlaylistListItem(PlaylistListItem item)
|
public DrawablePlaylistListItem(BeatmapSetInfo item)
|
||||||
: base(item)
|
: base(item)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.X;
|
RelativeSizeAxes = Axes.X;
|
||||||
@ -127,7 +85,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
|
|
||||||
Padding = new MarginPadding { Left = 5 };
|
Padding = new MarginPadding { Left = 5 };
|
||||||
|
|
||||||
FilterTerms = item.BeatmapSetInfo.Metadata.SearchableTerms;
|
FilterTerms = item.Metadata.SearchableTerms;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -164,8 +122,8 @@ namespace osu.Game.Overlays.Music
|
|||||||
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
|
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
|
||||||
};
|
};
|
||||||
|
|
||||||
titleBind = localisation.GetLocalisedString(new LocalisedString((Model.BeatmapSetInfo.Metadata.TitleUnicode, Model.BeatmapSetInfo.Metadata.Title)));
|
titleBind = localisation.GetLocalisedString(new LocalisedString((Model.Metadata.TitleUnicode, Model.Metadata.Title)));
|
||||||
artistBind = localisation.GetLocalisedString(new LocalisedString((Model.BeatmapSetInfo.Metadata.ArtistUnicode, Model.BeatmapSetInfo.Metadata.Artist)));
|
artistBind = localisation.GetLocalisedString(new LocalisedString((Model.Metadata.ArtistUnicode, Model.Metadata.Artist)));
|
||||||
|
|
||||||
artistBind.BindValueChanged(_ => recreateText(), true);
|
artistBind.BindValueChanged(_ => recreateText(), true);
|
||||||
}
|
}
|
||||||
@ -176,11 +134,11 @@ namespace osu.Game.Overlays.Music
|
|||||||
|
|
||||||
SelectedSet.BindValueChanged(set =>
|
SelectedSet.BindValueChanged(set =>
|
||||||
{
|
{
|
||||||
if (set.OldValue != Model.BeatmapSetInfo && set.NewValue != Model.BeatmapSetInfo)
|
if (set.OldValue != Model && set.NewValue != Model)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
foreach (Drawable s in titleSprites)
|
foreach (Drawable s in titleSprites)
|
||||||
s.FadeColour(set.NewValue == Model.BeatmapSetInfo ? hoverColour : Color4.White, fade_duration);
|
s.FadeColour(set.NewValue == Model ? hoverColour : Color4.White, fade_duration);
|
||||||
}, true);
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -201,7 +159,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
RequestSelection?.Invoke(Model.BeatmapSetInfo);
|
RequestSelection?.Invoke(Model);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -21,7 +21,9 @@ namespace osu.Game.Overlays.Music
|
|||||||
private const float transition_duration = 600;
|
private const float transition_duration = 600;
|
||||||
private const float playlist_height = 510;
|
private const float playlist_height = 510;
|
||||||
|
|
||||||
public readonly IBindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
public IBindableList<BeatmapSetInfo> BeatmapSets => beatmapSets;
|
||||||
|
|
||||||
|
private readonly BindableList<BeatmapSetInfo> beatmapSets = new BindableList<BeatmapSetInfo>();
|
||||||
|
|
||||||
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
||||||
private BeatmapManager beatmaps;
|
private BeatmapManager beatmaps;
|
||||||
@ -72,7 +74,7 @@ namespace osu.Game.Overlays.Music
|
|||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
list.BeatmapSets.BindTo(BeatmapSets);
|
list.Items.BindTo(beatmapSets);
|
||||||
|
|
||||||
filter.Search.OnCommit = (sender, newText) =>
|
filter.Search.OnCommit = (sender, newText) =>
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user