mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 18:32:56 +08:00
I had a bit of a struggle getting header traversal logic to work well. The constraints I had in place were a bit weird: - Group panels should toggle or potentially fall into the prev/next group - Set panels should just traverse around them The current method of using `CheckValidForGroupSelection` return type for traversal did not mesh with the above two cases. Just trust me on this one since it's quite hard to explain in words. After some re-thinking, I've gone with a simpler approach with one important change to UX: Now when group traversing with a beatmap set header currently keyboard focused, the first operation will be to reset keyboard selection to the selected beatmap, rather than traverse. I find this non-offensive – at most it means a user will need to press their group traversal key one extra time. I've also changed group headers to always toggle expansion when doing group traversal with them selected. To make all this work, the meaning of `Activation` has changed somewhat. It is now the primary path for carousel implementations to change selection of an item. It is what the `Drawable` panels call when they are clicked. Selection changes are not performed implicitly by `Carousel` – an implementation should decide when it actually wants to change the selection, usually in `HandleItemActivated`. Having less things mutating `CurrentSelection` is better in my eyes, as we see this variable as only being mutated internally when utmost required (ie the user has requested the change). With this change, `CurrentSelection` can no longer become of a non-`T` type (in the beatmap carousel implementation at least). This might pave a path forward for making `CurrentSelection` typed, but that comes with a few other concerns so I'll look at that as a follow-up.
118 lines
3.3 KiB
C#
118 lines
3.3 KiB
C#
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
|
// See the LICENCE file in the repository root for full licence text.
|
|
|
|
using System.Diagnostics;
|
|
using osu.Framework.Allocation;
|
|
using osu.Framework.Bindables;
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
using osu.Framework.Graphics;
|
|
using osu.Framework.Graphics.Pooling;
|
|
using osu.Framework.Graphics.Shapes;
|
|
using osu.Framework.Input.Events;
|
|
using osu.Game.Graphics.Sprites;
|
|
using osuTK;
|
|
using osuTK.Graphics;
|
|
|
|
namespace osu.Game.Screens.SelectV2
|
|
{
|
|
public partial class GroupPanel : PoolableDrawable, ICarouselPanel
|
|
{
|
|
public const float HEIGHT = CarouselItem.DEFAULT_HEIGHT * 2;
|
|
|
|
[Resolved]
|
|
private BeatmapCarousel carousel { get; set; } = null!;
|
|
|
|
private Box activationFlash = null!;
|
|
private OsuSpriteText text = null!;
|
|
|
|
private Box box = null!;
|
|
|
|
[BackgroundDependencyLoader]
|
|
private void load()
|
|
{
|
|
Size = new Vector2(500, HEIGHT);
|
|
Masking = true;
|
|
|
|
InternalChildren = new Drawable[]
|
|
{
|
|
box = new Box
|
|
{
|
|
Colour = Color4.DarkBlue.Darken(5),
|
|
Alpha = 0.8f,
|
|
RelativeSizeAxes = Axes.Both,
|
|
},
|
|
activationFlash = new Box
|
|
{
|
|
Colour = Color4.White,
|
|
Blending = BlendingParameters.Additive,
|
|
Alpha = 0,
|
|
RelativeSizeAxes = Axes.Both,
|
|
},
|
|
text = new OsuSpriteText
|
|
{
|
|
Padding = new MarginPadding(5),
|
|
Anchor = Anchor.CentreLeft,
|
|
Origin = Anchor.CentreLeft,
|
|
}
|
|
};
|
|
|
|
Selected.BindValueChanged(value =>
|
|
{
|
|
activationFlash.FadeTo(value.NewValue ? 0.2f : 0, 500, Easing.OutQuint);
|
|
});
|
|
|
|
Expanded.BindValueChanged(value =>
|
|
{
|
|
box.FadeColour(value.NewValue ? Color4.SkyBlue : Color4.DarkBlue.Darken(5), 500, Easing.OutQuint);
|
|
});
|
|
|
|
KeyboardSelected.BindValueChanged(value =>
|
|
{
|
|
if (value.NewValue)
|
|
{
|
|
BorderThickness = 5;
|
|
BorderColour = Color4.Pink;
|
|
}
|
|
else
|
|
{
|
|
BorderThickness = 0;
|
|
}
|
|
});
|
|
}
|
|
|
|
protected override void PrepareForUse()
|
|
{
|
|
base.PrepareForUse();
|
|
|
|
Debug.Assert(Item != null);
|
|
|
|
GroupDefinition group = (GroupDefinition)Item.Model;
|
|
|
|
text.Text = group.Title;
|
|
|
|
this.FadeInFromZero(500, Easing.OutQuint);
|
|
}
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
|
{
|
|
carousel.Activate(Item!);
|
|
return true;
|
|
}
|
|
|
|
#region ICarouselPanel
|
|
|
|
public CarouselItem? Item { get; set; }
|
|
public BindableBool Selected { get; } = new BindableBool();
|
|
public BindableBool Expanded { get; } = new BindableBool();
|
|
public BindableBool KeyboardSelected { get; } = new BindableBool();
|
|
|
|
public double DrawYPosition { get; set; }
|
|
|
|
public void Activated()
|
|
{
|
|
}
|
|
|
|
#endregion
|
|
}
|
|
}
|