2021-06-20 17:31:24 +00: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.
|
|
|
|
|
|
|
|
|
|
using osu.Framework.Allocation;
|
2023-08-17 08:03:45 +00:00
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2023-01-10 22:05:08 +00:00
|
|
|
|
using osu.Framework.Extensions;
|
2021-06-20 17:31:24 +00:00
|
|
|
|
using osu.Framework.Graphics;
|
2021-09-09 17:15:30 +00:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-06-20 17:31:24 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2021-09-09 17:15:30 +00:00
|
|
|
|
using osu.Framework.Input.Bindings;
|
2021-09-16 09:26:12 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2021-09-09 17:15:30 +00:00
|
|
|
|
using osu.Game.Input.Bindings;
|
2021-06-20 17:31:24 +00:00
|
|
|
|
using osu.Game.Overlays;
|
|
|
|
|
using osuTK;
|
2023-01-10 22:05:08 +00:00
|
|
|
|
using osuTK.Input;
|
2021-06-20 17:31:24 +00:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterfaceV2
|
|
|
|
|
{
|
2021-09-09 17:15:30 +00:00
|
|
|
|
public partial class OsuPopover : Popover, IKeyBindingHandler<GlobalAction>
|
2021-06-20 17:31:24 +00:00
|
|
|
|
{
|
|
|
|
|
private const float fade_duration = 250;
|
2021-07-14 14:23:44 +00:00
|
|
|
|
private const double scale_duration = 500;
|
2021-06-20 17:31:24 +00:00
|
|
|
|
|
2023-08-17 08:03:45 +00:00
|
|
|
|
private Sample? samplePopIn;
|
|
|
|
|
private Sample? samplePopOut;
|
|
|
|
|
protected virtual string PopInSampleName => "UI/overlay-pop-in";
|
|
|
|
|
protected virtual string PopOutSampleName => "UI/overlay-pop-out";
|
|
|
|
|
|
2023-08-24 09:20:36 +00:00
|
|
|
|
// required due to LoadAsyncComplete() in `VisibilityContainer` calling PopOut() during load - similar workaround to `OsuDropdownMenu`
|
2023-08-17 08:03:45 +00:00
|
|
|
|
private bool wasOpened;
|
|
|
|
|
|
2021-06-20 17:31:24 +00:00
|
|
|
|
public OsuPopover(bool withPadding = true)
|
|
|
|
|
{
|
|
|
|
|
Content.Padding = withPadding ? new MarginPadding(20) : new MarginPadding();
|
2021-07-14 14:23:44 +00:00
|
|
|
|
|
2021-06-20 17:31:24 +00: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)]
|
2023-08-17 08:03:45 +00:00
|
|
|
|
private void load(OverlayColourProvider? colourProvider, OsuColour colours, AudioManager audio)
|
2021-06-20 17:31:24 +00:00
|
|
|
|
{
|
2021-12-10 05:15:00 +00:00
|
|
|
|
Background.Colour = Arrow.Colour = colourProvider?.Background4 ?? colours.GreySeaFoamDarker;
|
2023-08-17 08:03:45 +00:00
|
|
|
|
samplePopIn = audio.Samples.Get(PopInSampleName);
|
|
|
|
|
samplePopOut = audio.Samples.Get(PopOutSampleName);
|
2021-06-20 17:31:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override Drawable CreateArrow() => Empty();
|
|
|
|
|
|
2021-07-14 14:23:44 +00:00
|
|
|
|
protected override void PopIn()
|
|
|
|
|
{
|
|
|
|
|
this.ScaleTo(1, scale_duration, Easing.OutElasticHalf);
|
|
|
|
|
this.FadeIn(fade_duration, Easing.OutQuint);
|
2023-08-17 08:03:45 +00:00
|
|
|
|
|
2023-08-24 09:04:47 +00:00
|
|
|
|
samplePopIn?.Play();
|
|
|
|
|
wasOpened = true;
|
2021-07-14 14:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void PopOut()
|
|
|
|
|
{
|
|
|
|
|
this.ScaleTo(0.7f, scale_duration, Easing.OutQuint);
|
|
|
|
|
this.FadeOut(fade_duration, Easing.OutQuint);
|
2023-08-17 08:03:45 +00:00
|
|
|
|
|
2023-08-24 09:04:47 +00:00
|
|
|
|
if (wasOpened)
|
2023-08-17 08:03:45 +00:00
|
|
|
|
samplePopOut?.Play();
|
2021-07-14 14:23:44 +00:00
|
|
|
|
}
|
2021-09-09 17:15:30 +00:00
|
|
|
|
|
2023-01-10 22:05:08 +00:00
|
|
|
|
protected override bool OnKeyDown(KeyDownEvent e)
|
|
|
|
|
{
|
|
|
|
|
if (e.Key == Key.Escape)
|
|
|
|
|
return false; // disable the framework-level handling of escape key for conformity (we use GlobalAction.Back).
|
|
|
|
|
|
|
|
|
|
return base.OnKeyDown(e);
|
|
|
|
|
}
|
|
|
|
|
|
2023-07-13 08:49:06 +00:00
|
|
|
|
public virtual bool OnPressed(KeyBindingPressEvent<GlobalAction> e)
|
2021-09-09 17:15:30 +00:00
|
|
|
|
{
|
2021-11-18 03:35:47 +00:00
|
|
|
|
if (e.Repeat)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-09 17:15:30 +00:00
|
|
|
|
if (State.Value == Visibility.Hidden)
|
|
|
|
|
return false;
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
if (e.Action == GlobalAction.Back)
|
2021-09-09 17:15:30 +00:00
|
|
|
|
{
|
2023-01-10 22:05:08 +00:00
|
|
|
|
this.HidePopover();
|
2021-09-09 17:15:30 +00:00
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2021-09-16 09:26:12 +00:00
|
|
|
|
public void OnReleased(KeyBindingReleaseEvent<GlobalAction> e)
|
2021-09-09 17:15:30 +00:00
|
|
|
|
{
|
|
|
|
|
}
|
2021-06-20 17:31:24 +00:00
|
|
|
|
}
|
|
|
|
|
}
|