1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-16 19:07:25 +08:00
osu-lazer/osu.Game/Graphics/UserInterface/OsuContextMenu.cs

76 lines
2.1 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
2022-06-17 15:37:17 +08:00
#nullable disable
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
2019-04-02 13:51:28 +08:00
using osu.Framework.Graphics.Effects;
2019-11-08 10:13:53 +08:00
using osu.Framework.Graphics.UserInterface;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Graphics.UserInterface
{
2022-11-24 13:32:20 +08:00
public partial class OsuContextMenu : OsuMenu
2018-04-13 17:19:50 +08:00
{
private const int fade_duration = 250;
[Resolved]
private OsuContextMenuSamples samples { get; set; }
2018-04-13 17:19:50 +08:00
2021-08-06 19:59:26 +08:00
// todo: this shouldn't be required after https://github.com/ppy/osu-framework/issues/4519 is fixed.
private bool wasOpened;
private readonly bool playClickSample;
public OsuContextMenu(bool playClickSample = false)
2018-04-13 17:19:50 +08:00
: base(Direction.Vertical)
{
MaskingContainer.CornerRadius = 5;
MaskingContainer.EdgeEffect = new EdgeEffectParameters
{
Type = EdgeEffectType.Shadow,
Colour = Color4.Black.Opacity(0.1f),
Radius = 4,
};
ItemsContainer.Padding = new MarginPadding { Vertical = DrawableOsuMenuItem.MARGIN_VERTICAL };
MaxHeight = 250;
2021-08-06 19:59:26 +08:00
this.playClickSample = playClickSample;
2018-04-13 17:19:50 +08:00
}
[BackgroundDependencyLoader]
2022-01-15 08:06:39 +08:00
private void load(OsuColour colours)
2018-04-13 17:19:50 +08:00
{
BackgroundColour = colours.ContextMenuGray;
2021-08-06 19:59:26 +08:00
}
protected override void AnimateOpen()
{
this.FadeIn(fade_duration, Easing.OutQuint);
if (playClickSample)
samples.PlayClickSample();
2021-08-06 19:59:26 +08:00
if (!wasOpened)
samples.PlayOpenSample();
2021-08-06 19:59:26 +08:00
wasOpened = true;
2018-04-13 17:19:50 +08:00
}
2021-08-06 19:59:26 +08:00
protected override void AnimateClose()
{
this.FadeOut(fade_duration, Easing.OutQuint);
if (wasOpened)
samples.PlayCloseSample();
2021-08-06 19:59:26 +08:00
wasOpened = false;
}
2019-11-08 10:13:53 +08:00
protected override Menu CreateSubMenu() => new OsuContextMenu();
2018-04-13 17:19:50 +08:00
}
}