1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 18:33:06 +08:00
osu-lazer/osu.Game/Graphics/UserInterfaceV2/OsuPopover.cs

83 lines
2.4 KiB
C#
Raw Normal View History

2021-06-21 01:31:24 +08:00
// 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.
2022-06-17 15:37:17 +08:00
#nullable disable
2021-06-21 01:31:24 +08:00
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
2021-06-21 01:31:24 +08:00
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Bindings;
2021-09-16 17:26:12 +08:00
using osu.Framework.Input.Events;
using osu.Game.Input.Bindings;
2021-06-21 01:31:24 +08:00
using osu.Game.Overlays;
using osuTK;
namespace osu.Game.Graphics.UserInterfaceV2
{
public class OsuPopover : Popover, IKeyBindingHandler<GlobalAction>
2021-06-21 01:31:24 +08:00
{
private const float fade_duration = 250;
2021-07-14 22:23:44 +08:00
private const double scale_duration = 500;
2021-06-21 01:31:24 +08:00
public OsuPopover(bool withPadding = true)
{
Content.Padding = withPadding ? new MarginPadding(20) : new MarginPadding();
2021-07-14 22:23:44 +08:00
2021-06-21 01:31:24 +08:00
Body.Masking = true;
Body.CornerRadius = 10;
Body.Margin = new MarginPadding(10);
Body.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Offset = new Vector2(0, 2),
Radius = 5,
Colour = Colour4.Black.Opacity(0.3f)
};
}
[BackgroundDependencyLoader(true)]
private void load([CanBeNull] OverlayColourProvider colourProvider, OsuColour colours)
2021-06-21 01:31:24 +08:00
{
Background.Colour = Arrow.Colour = colourProvider?.Background4 ?? colours.GreySeaFoamDarker;
2021-06-21 01:31:24 +08:00
}
protected override Drawable CreateArrow() => Empty();
2021-07-14 22:23:44 +08:00
protected override void PopIn()
{
this.ScaleTo(1, scale_duration, Easing.OutElasticHalf);
this.FadeIn(fade_duration, Easing.OutQuint);
}
protected override void PopOut()
{
this.ScaleTo(0.7f, scale_duration, Easing.OutQuint);
this.FadeOut(fade_duration, Easing.OutQuint);
}
2021-09-16 17:26:12 +08:00
public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
{
if (e.Repeat)
return false;
if (State.Value == Visibility.Hidden)
return false;
2021-09-16 17:26:12 +08:00
if (e.Action == GlobalAction.Back)
{
Hide();
return true;
}
return false;
}
2021-09-16 17:26:12 +08:00
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
{
}
2021-06-21 01:31:24 +08:00
}
}