1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-27 19:02:55 +08:00
osu-lazer/osu.Game/Screens/Select/Options/BeatmapOptionsButton.cs

171 lines
5.5 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2018-10-02 11:02:47 +08:00
using osu.Framework.Input.Events;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
2018-11-20 15:51:59 +08:00
using osuTK;
using osuTK.Graphics;
using osuTK.Input;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics.Containers;
namespace osu.Game.Screens.Select.Options
{
public class BeatmapOptionsButton : OsuClickableContainer
{
private const float width = 130;
private readonly Box background;
private readonly Box flash;
private readonly SpriteIcon iconText;
private readonly OsuSpriteText firstLine;
private readonly OsuSpriteText secondLine;
private readonly Container box;
public Color4 ButtonColour
{
get => background.Colour;
set => background.Colour = value;
2018-04-13 17:19:50 +08:00
}
public IconUsage Icon
2018-04-13 17:19:50 +08:00
{
get => iconText.Icon;
set => iconText.Icon = value;
2018-04-13 17:19:50 +08:00
}
public string FirstLineText
{
get => firstLine.Text;
set => firstLine.Text = value;
2018-04-13 17:19:50 +08:00
}
public string SecondLineText
{
get => secondLine.Text;
set => secondLine.Text = value;
2018-04-13 17:19:50 +08:00
}
public Key? HotKey;
2018-10-02 11:02:47 +08:00
protected override bool OnMouseDown(MouseDownEvent e)
2018-04-13 17:19:50 +08:00
{
flash.FadeTo(0.1f, 1000, Easing.OutQuint);
2018-10-02 11:02:47 +08:00
return base.OnMouseDown(e);
2018-04-13 17:19:50 +08:00
}
protected override void OnMouseUp(MouseUpEvent e)
2018-04-13 17:19:50 +08:00
{
flash.FadeTo(0, 1000, Easing.OutQuint);
base.OnMouseUp(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnClick(ClickEvent e)
2018-04-13 17:19:50 +08:00
{
flash.ClearTransforms();
flash.Alpha = 0.9f;
flash.FadeOut(800, Easing.OutExpo);
2018-10-02 11:02:47 +08:00
return base.OnClick(e);
2018-04-13 17:19:50 +08:00
}
2018-10-02 11:02:47 +08:00
protected override bool OnKeyDown(KeyDownEvent e)
2018-04-13 17:19:50 +08:00
{
2018-10-02 11:02:47 +08:00
if (!e.Repeat && e.Key == HotKey)
2018-04-13 17:19:50 +08:00
{
Click();
2018-04-13 17:19:50 +08:00
return true;
}
return false;
}
public override bool ReceivePositionalInputAt(Vector2 screenSpacePos) => box.ReceivePositionalInputAt(screenSpacePos);
2018-04-13 17:19:50 +08:00
public BeatmapOptionsButton()
{
Width = width;
RelativeSizeAxes = Axes.Y;
Children = new Drawable[]
{
box = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
Shear = new Vector2(0.2f, 0f),
Masking = true,
EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.2f),
Roundness = 5,
Radius = 8,
},
Children = new Drawable[]
{
background = new Box
{
RelativeSizeAxes = Axes.Both,
EdgeSmoothness = new Vector2(1.5f, 0),
Colour = Color4.Black,
},
flash = new Box
{
RelativeSizeAxes = Axes.Both,
EdgeSmoothness = new Vector2(1.5f, 0),
2019-08-21 12:29:50 +08:00
Blending = BlendingParameters.Additive,
2018-04-13 17:19:50 +08:00
Colour = Color4.White,
Alpha = 0,
},
},
},
new FillFlowContainer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Vertical,
Children = new Drawable[]
{
iconText = new SpriteIcon
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Size = new Vector2(30),
Shadow = true,
2019-04-02 18:55:24 +08:00
Icon = FontAwesome.Solid.TimesCircle,
2018-04-13 17:19:50 +08:00
Margin = new MarginPadding
{
Bottom = 5,
},
},
firstLine = new OsuSpriteText
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Font = OsuFont.GetFont(weight: FontWeight.Bold),
2018-04-13 17:19:50 +08:00
Text = @"",
},
secondLine = new OsuSpriteText
{
Origin = Anchor.TopCentre,
Anchor = Anchor.TopCentre,
Font = OsuFont.GetFont(weight: FontWeight.Bold),
2018-04-13 17:19:50 +08:00
Text = @"",
},
},
},
};
}
}
}