2019-01-24 16:43:03 +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.
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
|
#nullable disable
|
|
|
|
|
|
2021-08-06 19:58:53 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Audio;
|
|
|
|
|
using osu.Framework.Audio.Sample;
|
2017-03-22 06:51:26 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
2017-08-28 14:33:24 +08:00
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2023-11-21 13:24:10 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-03-22 06:51:26 +08:00
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
2023-11-21 13:24:10 +08:00
|
|
|
|
using osu.Framework.Input.Events;
|
2019-06-21 11:33:49 +08:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
2018-11-20 15:51:59 +08:00
|
|
|
|
using osuTK;
|
2023-11-21 13:24:10 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-03-22 06:51:26 +08:00
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
|
{
|
2017-08-28 13:42:52 +08:00
|
|
|
|
public partial class OsuMenu : Menu
|
2017-03-22 06:51:26 +08:00
|
|
|
|
{
|
2021-08-06 19:58:53 +08:00
|
|
|
|
private Sample sampleOpen;
|
|
|
|
|
private Sample sampleClose;
|
|
|
|
|
|
|
|
|
|
// todo: this shouldn't be required after https://github.com/ppy/osu-framework/issues/4519 is fixed.
|
|
|
|
|
private bool wasOpened;
|
|
|
|
|
|
2017-09-07 19:36:32 +08:00
|
|
|
|
public OsuMenu(Direction direction, bool topLevelMenu = false)
|
|
|
|
|
: base(direction, topLevelMenu)
|
2017-03-22 06:51:26 +08:00
|
|
|
|
{
|
2017-08-25 14:09:07 +08:00
|
|
|
|
BackgroundColour = Color4.Black.Opacity(0.5f);
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-04 08:10:04 +08:00
|
|
|
|
MaskingContainer.CornerRadius = 4;
|
|
|
|
|
ItemsContainer.Padding = new MarginPadding(5);
|
2017-03-22 06:51:26 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2021-08-06 19:58:53 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(AudioManager audio)
|
|
|
|
|
{
|
|
|
|
|
sampleOpen = audio.Samples.Get(@"UI/dropdown-open");
|
|
|
|
|
sampleClose = audio.Samples.Get(@"UI/dropdown-close");
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-03 21:32:25 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
2024-10-04 17:25:21 +08:00
|
|
|
|
bool showCheckboxes = false;
|
2024-10-03 21:32:25 +08:00
|
|
|
|
|
2024-10-04 17:25:21 +08:00
|
|
|
|
foreach (var drawableItem in ItemsContainer)
|
|
|
|
|
{
|
|
|
|
|
if (drawableItem.Item is StatefulMenuItem)
|
|
|
|
|
showCheckboxes = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach (var drawableItem in ItemsContainer)
|
|
|
|
|
{
|
|
|
|
|
if (drawableItem is DrawableOsuMenuItem osuItem)
|
|
|
|
|
osuItem.ShowCheckbox.Value = showCheckboxes;
|
|
|
|
|
}
|
2024-10-03 21:32:25 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-08-06 19:58:53 +08:00
|
|
|
|
protected override void AnimateOpen()
|
|
|
|
|
{
|
2021-08-07 20:38:54 +08:00
|
|
|
|
if (!TopLevelMenu && !wasOpened)
|
2021-08-06 19:58:53 +08:00
|
|
|
|
sampleOpen?.Play();
|
|
|
|
|
|
|
|
|
|
this.FadeIn(300, Easing.OutQuint);
|
|
|
|
|
wasOpened = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void AnimateClose()
|
|
|
|
|
{
|
2021-08-07 20:38:54 +08:00
|
|
|
|
if (!TopLevelMenu && wasOpened)
|
2021-08-06 19:58:53 +08:00
|
|
|
|
sampleClose?.Play();
|
|
|
|
|
|
|
|
|
|
this.FadeOut(300, Easing.OutQuint);
|
|
|
|
|
wasOpened = false;
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2017-09-04 08:32:44 +08:00
|
|
|
|
protected override void UpdateSize(Vector2 newSize)
|
2017-03-22 06:51:26 +08:00
|
|
|
|
{
|
2017-09-04 08:32:44 +08:00
|
|
|
|
if (Direction == Direction.Vertical)
|
|
|
|
|
{
|
|
|
|
|
Width = newSize.X;
|
|
|
|
|
this.ResizeHeightTo(newSize.Y, 300, Easing.OutQuint);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
Height = newSize.Y;
|
|
|
|
|
this.ResizeWidthTo(newSize.X, 300, Easing.OutQuint);
|
|
|
|
|
}
|
2017-03-22 06:51:26 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-11-07 21:26:35 +08:00
|
|
|
|
protected override DrawableMenuItem CreateDrawableMenuItem(MenuItem item)
|
|
|
|
|
{
|
|
|
|
|
switch (item)
|
|
|
|
|
{
|
2019-11-08 10:15:03 +08:00
|
|
|
|
case StatefulMenuItem stateful:
|
|
|
|
|
return new DrawableStatefulMenuItem(stateful);
|
2023-11-21 13:24:10 +08:00
|
|
|
|
|
|
|
|
|
case OsuMenuItemSpacer spacer:
|
|
|
|
|
return new DrawableSpacer(spacer);
|
2019-11-07 21:26:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return new DrawableOsuMenuItem(item);
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2022-04-28 17:11:06 +08:00
|
|
|
|
protected override ScrollContainer<Drawable> CreateScrollContainer(Direction direction) => new OsuScrollContainer(direction);
|
2019-06-21 11:33:49 +08:00
|
|
|
|
|
2017-09-06 20:14:29 +08:00
|
|
|
|
protected override Menu CreateSubMenu() => new OsuMenu(Direction.Vertical)
|
|
|
|
|
{
|
|
|
|
|
Anchor = Direction == Direction.Horizontal ? Anchor.BottomLeft : Anchor.TopRight
|
|
|
|
|
};
|
2023-11-21 13:24:10 +08:00
|
|
|
|
|
|
|
|
|
protected partial class DrawableSpacer : DrawableOsuMenuItem
|
|
|
|
|
{
|
|
|
|
|
public DrawableSpacer(MenuItem item)
|
|
|
|
|
: base(item)
|
|
|
|
|
{
|
|
|
|
|
Scale = new Vector2(1, 0.6f);
|
|
|
|
|
|
|
|
|
|
AddInternal(new Box
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
|
Colour = BackgroundColourHover,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
|
|
|
|
Height = 2f,
|
2024-07-18 17:20:22 +08:00
|
|
|
|
Width = 0.9f,
|
2023-11-21 13:24:10 +08:00
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e) => true;
|
|
|
|
|
|
|
|
|
|
protected override bool OnClick(ClickEvent e) => true;
|
|
|
|
|
}
|
2017-03-22 06:51:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|