1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-16 02:15:17 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/ShowMoreButton.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

140 lines
4.4 KiB
C#
Raw Normal View History

2019-10-13 19:43:30 +08:00
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
2019-05-31 03:55:59 +08:00
// See the LICENCE file in the repository root for full licence text.
2022-06-17 15:37:17 +08:00
#nullable disable
2020-07-30 09:51:09 +08:00
using osu.Framework.Allocation;
2019-05-31 03:55:59 +08:00
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2020-07-30 09:51:09 +08:00
using osu.Framework.Input.Events;
2019-05-31 03:55:59 +08:00
using osu.Game.Graphics.Sprites;
2020-07-30 09:51:09 +08:00
using osu.Game.Overlays;
2019-05-31 03:55:59 +08:00
using osuTK;
using System.Collections.Generic;
using osu.Framework.Extensions.LocalisationExtensions;
using osu.Framework.Localisation;
using osu.Game.Resources.Localisation.Web;
2019-05-31 03:55:59 +08:00
2019-10-13 19:43:30 +08:00
namespace osu.Game.Graphics.UserInterface
2019-05-31 03:55:59 +08:00
{
2019-10-17 18:57:17 +08:00
public class ShowMoreButton : LoadingButton
2019-05-31 03:55:59 +08:00
{
2019-10-24 22:49:34 +08:00
private const int duration = 200;
public LocalisableString Text
2019-10-13 19:43:30 +08:00
{
get => text.Text;
2019-10-14 22:33:14 +08:00
set => text.Text = value;
2019-10-13 19:43:30 +08:00
}
2019-05-31 03:55:59 +08:00
2019-10-13 19:43:30 +08:00
protected override IEnumerable<Drawable> EffectTargets => new[] { background };
2020-07-30 09:51:09 +08:00
private ChevronIcon leftIcon;
private ChevronIcon rightIcon;
2019-10-17 18:57:17 +08:00
private SpriteText text;
private Box background;
2019-10-24 22:49:34 +08:00
private FillFlowContainer textContainer;
2019-10-17 18:57:17 +08:00
2019-05-31 03:55:59 +08:00
public ShowMoreButton()
{
2020-07-30 09:51:09 +08:00
AutoSizeAxes = Axes.Both;
}
[BackgroundDependencyLoader]
private void load(OverlayColourProvider colourProvider)
{
IdleColour = colourProvider.Background2;
HoverColour = colourProvider.Background1;
2019-05-31 03:55:59 +08:00
}
2019-10-24 22:49:34 +08:00
protected override Drawable CreateContent() => new CircularContainer
2019-05-31 03:55:59 +08:00
{
2019-10-17 18:57:17 +08:00
Masking = true,
2020-07-30 09:51:09 +08:00
AutoSizeAxes = Axes.Both,
2019-10-17 18:57:17 +08:00
Children = new Drawable[]
2019-06-04 09:26:21 +08:00
{
2019-10-24 22:49:34 +08:00
background = new Box
{
RelativeSizeAxes = Axes.Both,
},
textContainer = new FillFlowContainer
2019-10-17 18:57:17 +08:00
{
2020-07-30 09:51:09 +08:00
AlwaysPresent = true,
2019-10-17 18:57:17 +08:00
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2019-10-24 22:49:34 +08:00
AutoSizeAxes = Axes.Both,
Direction = FillDirection.Horizontal,
2020-07-30 09:51:09 +08:00
Spacing = new Vector2(10),
Margin = new MarginPadding
{
Horizontal = 20,
Vertical = 5
},
2019-10-24 22:49:34 +08:00
Children = new Drawable[]
{
2020-07-30 09:51:09 +08:00
leftIcon = new ChevronIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
},
2019-10-24 22:49:34 +08:00
text = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
2020-07-30 09:51:09 +08:00
Font = OsuFont.GetFont(size: 12, weight: FontWeight.SemiBold),
Text = CommonStrings.ButtonsShowMore.ToUpper(),
2019-10-24 22:49:34 +08:00
},
2020-07-30 09:51:09 +08:00
rightIcon = new ChevronIcon
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
}
2019-10-24 22:49:34 +08:00
}
}
2019-06-04 09:26:21 +08:00
}
2019-10-17 18:57:17 +08:00
};
2019-05-31 03:55:59 +08:00
2019-10-24 22:49:34 +08:00
protected override void OnLoadStarted() => textContainer.FadeOut(duration, Easing.OutQuint);
protected override void OnLoadFinished() => textContainer.FadeIn(duration, Easing.OutQuint);
2020-07-30 09:51:09 +08:00
protected override bool OnHover(HoverEvent e)
2019-05-31 03:55:59 +08:00
{
2020-07-30 09:51:09 +08:00
base.OnHover(e);
leftIcon.SetHoveredState(true);
rightIcon.SetHoveredState(true);
2020-07-30 09:51:09 +08:00
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
base.OnHoverLost(e);
leftIcon.SetHoveredState(false);
rightIcon.SetHoveredState(false);
2020-07-30 09:51:09 +08:00
}
public class ChevronIcon : SpriteIcon
{
[Resolved]
private OverlayColourProvider colourProvider { get; set; }
2019-05-31 03:55:59 +08:00
public ChevronIcon()
{
2020-07-30 09:51:09 +08:00
Size = new Vector2(7.5f);
2019-05-31 03:55:59 +08:00
Icon = FontAwesome.Solid.ChevronDown;
}
2020-07-30 09:51:09 +08:00
[BackgroundDependencyLoader]
private void load()
{
Colour = colourProvider.Foreground1;
}
public void SetHoveredState(bool hovered) =>
this.FadeColour(hovered ? colourProvider.Light1 : colourProvider.Foreground1, 200, Easing.OutQuint);
2019-05-31 03:55:59 +08:00
}
}
}