mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
General work towards completion + framework updates
This commit is contained in:
parent
2b2cfd91a6
commit
ebf15c6a1c
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using NUnit.Framework;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
@ -15,6 +16,12 @@ namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestScenePlaylistOverlay : OsuTestScene
|
||||
{
|
||||
public override IReadOnlyList<Type> RequiredTypes => new Type[]
|
||||
{
|
||||
typeof(PlaylistOverlay),
|
||||
typeof(PlaylistList)
|
||||
};
|
||||
|
||||
private readonly BindableList<BeatmapSetInfo> beatmapSets = new BindableList<BeatmapSetInfo>();
|
||||
|
||||
[SetUp]
|
||||
|
@ -8,14 +8,23 @@ using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Localisation;
|
||||
using osu.Game.Beatmaps;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays.Music
|
||||
{
|
||||
public class PlaylistList2 : BasicRearrangeableListContainer<PlaylistListItem>
|
||||
public class PlaylistList : RearrangeableListContainer<PlaylistListItem>
|
||||
{
|
||||
public readonly BindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
||||
public Action<BeatmapSetInfo> RequestSelection;
|
||||
|
||||
public readonly Bindable<BeatmapSetInfo> SelectedSet = new Bindable<BeatmapSetInfo>();
|
||||
public readonly IBindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
||||
|
||||
public new MarginPadding Padding
|
||||
{
|
||||
@ -23,21 +32,35 @@ namespace osu.Game.Overlays.Music
|
||||
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 BeatmapSetInfo FirstVisibleSet => ListContainer.FlowingChildren.Cast<DrawablePlaylistListItem>().FirstOrDefault(i => i.MatchingFilter)?.Model.BeatmapSetInfo;
|
||||
|
||||
private void addBeatmapSets(IEnumerable<BeatmapSetInfo> sets) => Schedule(() =>
|
||||
private void addBeatmapSets(IEnumerable<BeatmapSetInfo> sets)
|
||||
{
|
||||
foreach (var item in sets)
|
||||
AddItem(new PlaylistListItem(item));
|
||||
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(() =>
|
||||
@ -46,16 +69,23 @@ namespace osu.Game.Overlays.Music
|
||||
RemoveItem(ListContainer.Children.Select(d => d.Model).FirstOrDefault(m => m.BeatmapSetInfo == item));
|
||||
});
|
||||
|
||||
protected override BasicDrawableRearrangeableListItem CreateBasicItem(PlaylistListItem item) => new DrawablePlaylistListItem(item);
|
||||
|
||||
protected override FillFlowContainer<DrawableRearrangeableListItem> CreateListFillFlowContainer() => new PlaylistListFlowContainer
|
||||
protected override DrawableRearrangeableListItem<PlaylistListItem> CreateDrawable(PlaylistListItem item) => new DrawablePlaylistListItem(item)
|
||||
{
|
||||
SelectedSet = { BindTarget = SelectedSet },
|
||||
RequestSelection = set => RequestSelection?.Invoke(set)
|
||||
};
|
||||
|
||||
protected override ScrollContainer<Drawable> CreateScrollContainer() => new OsuScrollContainer();
|
||||
|
||||
protected override FillFlowContainer<DrawableRearrangeableListItem<PlaylistListItem>> CreateListFillFlowContainer() => new PlaylistListFlowContainer
|
||||
{
|
||||
Spacing = new Vector2(0, 3),
|
||||
LayoutDuration = 200,
|
||||
LayoutEasing = Easing.OutQuint
|
||||
LayoutEasing = Easing.OutQuint,
|
||||
};
|
||||
}
|
||||
|
||||
public class PlaylistListFlowContainer : SearchContainer<RearrangeableListContainer<PlaylistListItem>.DrawableRearrangeableListItem>
|
||||
public class PlaylistListFlowContainer : SearchContainer<DrawableRearrangeableListItem<PlaylistListItem>>
|
||||
{
|
||||
}
|
||||
|
||||
@ -73,14 +103,118 @@ namespace osu.Game.Overlays.Music
|
||||
public bool Equals(PlaylistListItem other) => BeatmapSetInfo.Equals(other?.BeatmapSetInfo);
|
||||
}
|
||||
|
||||
public class DrawablePlaylistListItem : BasicRearrangeableListContainer<PlaylistListItem>.BasicDrawableRearrangeableListItem, IFilterable
|
||||
public class DrawablePlaylistListItem : DrawableRearrangeableListItem<PlaylistListItem>, IFilterable
|
||||
{
|
||||
private const float fade_duration = 100;
|
||||
|
||||
public readonly Bindable<BeatmapSetInfo> SelectedSet = new Bindable<BeatmapSetInfo>();
|
||||
public Action<BeatmapSetInfo> RequestSelection;
|
||||
|
||||
private PlaylistItemHandle handle;
|
||||
private TextFlowContainer text;
|
||||
private IEnumerable<Drawable> titleSprites;
|
||||
private ILocalisedBindableString titleBind;
|
||||
private ILocalisedBindableString artistBind;
|
||||
|
||||
private Color4 hoverColour;
|
||||
private Color4 artistColour;
|
||||
|
||||
public DrawablePlaylistListItem(PlaylistListItem item)
|
||||
: base(item)
|
||||
{
|
||||
RelativeSizeAxes = Axes.X;
|
||||
AutoSizeAxes = Axes.Y;
|
||||
|
||||
Padding = new MarginPadding { Left = 5 };
|
||||
|
||||
FilterTerms = item.BeatmapSetInfo.Metadata.SearchableTerms;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, LocalisationManager localisation)
|
||||
{
|
||||
hoverColour = colours.Yellow;
|
||||
artistColour = colours.Gray9;
|
||||
|
||||
InternalChild = new GridContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Content = new[]
|
||||
{
|
||||
new Drawable[]
|
||||
{
|
||||
handle = new PlaylistItemHandle
|
||||
{
|
||||
Anchor = Anchor.CentreLeft,
|
||||
Origin = Anchor.CentreLeft,
|
||||
Size = new Vector2(12),
|
||||
Colour = colours.Gray5,
|
||||
Alpha = 0
|
||||
},
|
||||
text = new OsuTextFlowContainer
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Padding = new MarginPadding { Left = 5 },
|
||||
},
|
||||
}
|
||||
},
|
||||
ColumnDimensions = new[] { new Dimension(GridSizeMode.AutoSize) },
|
||||
RowDimensions = new[] { new Dimension(GridSizeMode.AutoSize) }
|
||||
};
|
||||
|
||||
titleBind = localisation.GetLocalisedString(new LocalisedString((Model.BeatmapSetInfo.Metadata.TitleUnicode, Model.BeatmapSetInfo.Metadata.Title)));
|
||||
artistBind = localisation.GetLocalisedString(new LocalisedString((Model.BeatmapSetInfo.Metadata.ArtistUnicode, Model.BeatmapSetInfo.Metadata.Artist)));
|
||||
|
||||
artistBind.BindValueChanged(_ => recreateText(), true);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
SelectedSet.BindValueChanged(set =>
|
||||
{
|
||||
if (set.OldValue != Model.BeatmapSetInfo && set.NewValue != Model.BeatmapSetInfo)
|
||||
return;
|
||||
|
||||
foreach (Drawable s in titleSprites)
|
||||
s.FadeColour(set.NewValue == Model.BeatmapSetInfo ? hoverColour : Color4.White, fade_duration);
|
||||
}, true);
|
||||
}
|
||||
|
||||
private void recreateText()
|
||||
{
|
||||
text.Clear();
|
||||
|
||||
//space after the title to put a space between the title and artist
|
||||
titleSprites = text.AddText(titleBind.Value + @" ", sprite => sprite.Font = OsuFont.GetFont(weight: FontWeight.Regular)).OfType<SpriteText>();
|
||||
|
||||
text.AddText(artistBind.Value, sprite =>
|
||||
{
|
||||
sprite.Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold);
|
||||
sprite.Colour = artistColour;
|
||||
sprite.Padding = new MarginPadding { Top = 1 };
|
||||
});
|
||||
}
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
RequestSelection?.Invoke(Model.BeatmapSetInfo);
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override bool IsDraggableAt(Vector2 screenSpacePos) => handle.HandlingDrag;
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
handle.UpdateHoverState(true);
|
||||
return base.OnHover(e);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e) => handle.UpdateHoverState(false);
|
||||
|
||||
public IEnumerable<string> FilterTerms { get; }
|
||||
|
||||
private bool matching = true;
|
||||
@ -99,5 +233,44 @@ namespace osu.Game.Overlays.Music
|
||||
}
|
||||
|
||||
public bool FilteringActive { get; set; }
|
||||
|
||||
private class PlaylistItemHandle : SpriteIcon
|
||||
{
|
||||
public bool HandlingDrag { get; private set; }
|
||||
private bool isHovering;
|
||||
|
||||
public PlaylistItemHandle()
|
||||
{
|
||||
Icon = FontAwesome.Solid.Bars;
|
||||
}
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
base.OnMouseDown(e);
|
||||
|
||||
HandlingDrag = true;
|
||||
UpdateHoverState(isHovering);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void OnMouseUp(MouseUpEvent e)
|
||||
{
|
||||
base.OnMouseUp(e);
|
||||
|
||||
HandlingDrag = false;
|
||||
UpdateHoverState(isHovering);
|
||||
}
|
||||
|
||||
public void UpdateHoverState(bool hovering)
|
||||
{
|
||||
isHovering = hovering;
|
||||
|
||||
if (isHovering || HandlingDrag)
|
||||
this.FadeIn(fade_duration);
|
||||
else
|
||||
this.FadeOut(fade_duration);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -21,14 +21,14 @@ namespace osu.Game.Overlays.Music
|
||||
private const float transition_duration = 600;
|
||||
private const float playlist_height = 510;
|
||||
|
||||
public readonly BindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
||||
public readonly IBindableList<BeatmapSetInfo> BeatmapSets = new BindableList<BeatmapSetInfo>();
|
||||
|
||||
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
||||
private BeatmapManager beatmaps;
|
||||
|
||||
private FilterControl filter;
|
||||
private PlaylistList2 list;
|
||||
|
||||
private PlaylistList list;
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours, Bindable<WorkingBeatmap> beatmap, BeatmapManager beatmaps)
|
||||
{
|
||||
@ -55,11 +55,11 @@ namespace osu.Game.Overlays.Music
|
||||
Colour = colours.Gray3,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
},
|
||||
list = new PlaylistList2
|
||||
list = new PlaylistList
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Padding = new MarginPadding { Top = 95, Bottom = 10, Right = 10 },
|
||||
// Selected = itemSelected,
|
||||
RequestSelection = itemSelected
|
||||
},
|
||||
filter = new FilterControl
|
||||
{
|
||||
@ -84,6 +84,8 @@ namespace osu.Game.Overlays.Music
|
||||
beatmap.Value.Track.Restart();
|
||||
}
|
||||
};
|
||||
|
||||
beatmap.BindValueChanged(working => list.SelectedSet.Value = working.NewValue.BeatmapSetInfo, true);
|
||||
}
|
||||
|
||||
protected override void PopIn()
|
||||
|
@ -183,6 +183,7 @@ namespace osu.Game.Overlays
|
||||
}
|
||||
};
|
||||
|
||||
playlist.BeatmapSets.BindTo(musicController.BeatmapSets);
|
||||
playlist.State.ValueChanged += s => playlistButton.FadeColour(s.NewValue == Visibility.Visible ? colours.Yellow : Color4.White, 200, Easing.OutQuint);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user