2019-01-24 08:43:03 +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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK.Graphics;
|
2017-06-12 09:56:07 +00:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
2019-04-02 05:51:28 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2019-11-08 02:13:53 +00:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-06-12 09:56:07 +00:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2017-08-28 05:42:52 +00:00
|
|
|
|
public class OsuContextMenu : OsuMenu
|
2017-06-12 09:56:07 +00:00
|
|
|
|
{
|
2017-08-25 06:10:12 +00:00
|
|
|
|
private const int fade_duration = 250;
|
2021-08-07 12:19:05 +00:00
|
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
|
private OsuContextMenuSamples samples { get; set; }
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-08-06 11:59:26 +00: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;
|
|
|
|
|
|
2021-08-07 12:19:05 +00:00
|
|
|
|
public OsuContextMenu(bool playClickSample = false)
|
2017-09-04 00:10:04 +00:00
|
|
|
|
: base(Direction.Vertical)
|
2017-06-12 09:56:07 +00:00
|
|
|
|
{
|
2017-09-04 00:10:04 +00:00
|
|
|
|
MaskingContainer.CornerRadius = 5;
|
|
|
|
|
MaskingContainer.EdgeEffect = new EdgeEffectParameters
|
2017-08-25 06:10:12 +00:00
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(0.1f),
|
|
|
|
|
Radius = 4,
|
|
|
|
|
};
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-09-04 00:10:04 +00:00
|
|
|
|
ItemsContainer.Padding = new MarginPadding { Vertical = DrawableOsuMenuItem.MARGIN_VERTICAL };
|
2020-09-08 09:55:53 +00:00
|
|
|
|
|
|
|
|
|
MaxHeight = 250;
|
2021-08-06 11:59:26 +00:00
|
|
|
|
|
|
|
|
|
this.playClickSample = playClickSample;
|
2017-08-25 06:10:12 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2017-08-25 06:10:12 +00:00
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 00:06:39 +00:00
|
|
|
|
private void load(OsuColour colours)
|
2017-08-25 06:10:12 +00:00
|
|
|
|
{
|
|
|
|
|
BackgroundColour = colours.ContextMenuGray;
|
2021-08-06 11:59:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AnimateOpen()
|
|
|
|
|
{
|
|
|
|
|
this.FadeIn(fade_duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
if (playClickSample)
|
2021-08-07 12:19:05 +00:00
|
|
|
|
samples.PlayClickSample();
|
2021-08-06 11:59:26 +00:00
|
|
|
|
|
|
|
|
|
if (!wasOpened)
|
2021-08-07 12:19:05 +00:00
|
|
|
|
samples.PlayOpenSample();
|
2021-08-06 11:59:26 +00:00
|
|
|
|
|
|
|
|
|
wasOpened = true;
|
2017-08-25 06:10:12 +00:00
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2021-08-06 11:59:26 +00:00
|
|
|
|
protected override void AnimateClose()
|
|
|
|
|
{
|
|
|
|
|
this.FadeOut(fade_duration, Easing.OutQuint);
|
|
|
|
|
|
|
|
|
|
if (wasOpened)
|
2021-08-07 12:19:05 +00:00
|
|
|
|
samples.PlayCloseSample();
|
2021-08-06 11:59:26 +00:00
|
|
|
|
|
|
|
|
|
wasOpened = false;
|
|
|
|
|
}
|
2019-11-08 02:13:53 +00:00
|
|
|
|
|
2021-08-07 12:19:05 +00:00
|
|
|
|
protected override Menu CreateSubMenu() => new OsuContextMenu();
|
2017-06-12 09:56:07 +00:00
|
|
|
|
}
|
2018-01-05 11:21:19 +00:00
|
|
|
|
}
|