1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-13 14:12:56 +08:00

Implement beatmap card size tab control

This commit is contained in:
Bartłomiej Dach 2021-11-27 17:25:54 +01:00
parent cd4c1bc678
commit 1876617d8e
No known key found for this signature in database
GPG Key ID: BCECCD4FA41F6497
2 changed files with 189 additions and 0 deletions

View File

@ -0,0 +1,55 @@
// 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 osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Beatmaps.Drawables.Cards;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Overlays;
using osu.Game.Overlays.BeatmapListing;
namespace osu.Game.Tests.Visual.UserInterface
{
public class TestSceneBeatmapListingCardSizeTabControl : OsuTestScene
{
[Cached]
private readonly OverlayColourProvider colourProvider = new OverlayColourProvider(OverlayColourScheme.Blue);
private readonly Bindable<BeatmapCardSize> cardSize = new Bindable<BeatmapCardSize>();
private SpriteText cardSizeText;
[BackgroundDependencyLoader]
private void load()
{
Child = new Container
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
cardSizeText = new OsuSpriteText
{
Font = OsuFont.Default.With(size: 24)
},
new BeatmapListingCardSizeTabControl
{
Current = cardSize,
Anchor = Anchor.Centre,
Origin = Anchor.Centre
}
}
};
}
protected override void LoadComplete()
{
base.LoadComplete();
cardSize.BindValueChanged(size => cardSizeText.Text = $"Current size: {size.NewValue}", true);
}
}
}

View File

@ -0,0 +1,134 @@
// 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;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps.Drawables.Cards;
using osu.Game.Graphics.UserInterface;
using osuTK;
namespace osu.Game.Overlays.BeatmapListing
{
public class BeatmapListingCardSizeTabControl : OsuTabControl<BeatmapCardSize>
{
public BeatmapListingCardSizeTabControl()
{
AutoSizeAxes = Axes.Both;
}
protected override TabFillFlowContainer CreateTabFlow() => new TabFillFlowContainer
{
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(10, 0),
};
protected override Dropdown<BeatmapCardSize> CreateDropdown() => null;
protected override TabItem<BeatmapCardSize> CreateTabItem(BeatmapCardSize value) => new TabItem(value);
private class TabItem : TabItem<BeatmapCardSize>
{
private Box background;
private SpriteIcon icon;
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
public TabItem(BeatmapCardSize value)
: base(value)
{
}
[BackgroundDependencyLoader]
private void load()
{
AutoSizeAxes = Axes.Both;
Masking = true;
CornerRadius = 4;
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colourProvider.Background3
},
new Container
{
AutoSizeAxes = Axes.Both,
Padding = new MarginPadding
{
Horizontal = 10,
Vertical = 5,
},
Child = icon = new SpriteIcon
{
Size = new Vector2(12),
Icon = getIconForCardSize(Value)
}
}
};
}
private static IconUsage getIconForCardSize(BeatmapCardSize cardSize)
{
switch (cardSize)
{
case BeatmapCardSize.Normal:
return FontAwesome.Solid.Th;
case BeatmapCardSize.Extra:
return FontAwesome.Solid.ThLarge;
default:
throw new ArgumentOutOfRangeException(nameof(cardSize), cardSize, "Unsupported card size");
}
}
protected override void LoadComplete()
{
base.LoadComplete();
updateState();
FinishTransforms(true);
}
protected override void OnActivated()
{
if (IsLoaded)
updateState();
}
protected override void OnDeactivated()
{
if (IsLoaded)
updateState();
}
protected override bool OnHover(HoverEvent e)
{
updateState();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateState();
base.OnHoverLost(e);
}
private const double fade_time = 200;
private void updateState()
{
background.FadeTo(IsHovered || Active.Value ? 1 : 0, fade_time, Easing.OutQuint);
icon.FadeColour(Active.Value && !IsHovered ? colourProvider.Light1 : colourProvider.Content1, fade_time, Easing.OutQuint);
}
}
}
}