2019-11-07 07:03:35 +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;
|
2020-03-11 01:18:41 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2019-11-07 07:03:35 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.UserInterface;
|
|
|
|
using osu.Framework.Input.Events;
|
2021-02-22 08:14:00 +00:00
|
|
|
using osu.Framework.Localisation;
|
2019-11-07 07:03:35 +00:00
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
|
|
|
namespace osu.Game.Graphics.UserInterface
|
|
|
|
{
|
|
|
|
public class DrawableOsuMenuItem : Menu.DrawableMenuItem
|
|
|
|
{
|
2019-11-07 13:26:35 +00:00
|
|
|
public const int MARGIN_HORIZONTAL = 17;
|
|
|
|
public const int MARGIN_VERTICAL = 4;
|
2019-11-07 07:03:35 +00:00
|
|
|
private const int text_size = 17;
|
|
|
|
private const int transition_length = 80;
|
|
|
|
|
|
|
|
private TextContainer text;
|
|
|
|
|
|
|
|
public DrawableOsuMenuItem(MenuItem item)
|
|
|
|
: base(item)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2022-01-15 00:06:39 +00:00
|
|
|
private void load()
|
2019-11-07 07:03:35 +00:00
|
|
|
{
|
|
|
|
BackgroundColour = Color4.Transparent;
|
2020-03-11 01:18:41 +00:00
|
|
|
BackgroundColourHover = Color4Extensions.FromHex(@"172023");
|
2019-11-07 07:03:35 +00:00
|
|
|
|
2021-06-11 14:46:42 +00:00
|
|
|
AddInternal(new HoverClickSounds());
|
|
|
|
|
2019-11-07 07:03:35 +00:00
|
|
|
updateTextColour();
|
2020-04-15 06:50:19 +00:00
|
|
|
|
|
|
|
Item.Action.BindDisabledChanged(_ => updateState(), true);
|
2019-11-07 07:03:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
private void updateTextColour()
|
|
|
|
{
|
|
|
|
switch ((Item as OsuMenuItem)?.Type)
|
|
|
|
{
|
|
|
|
default:
|
|
|
|
case MenuItemType.Standard:
|
|
|
|
text.Colour = Color4.White;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MenuItemType.Destructive:
|
|
|
|
text.Colour = Color4.Red;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case MenuItemType.Highlighted:
|
2020-03-11 01:18:41 +00:00
|
|
|
text.Colour = Color4Extensions.FromHex(@"ffcc22");
|
2019-11-07 07:03:35 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
|
|
|
{
|
2020-04-15 06:50:19 +00:00
|
|
|
updateState();
|
2019-11-07 07:03:35 +00:00
|
|
|
return base.OnHover(e);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
|
|
|
{
|
2020-04-15 06:50:19 +00:00
|
|
|
updateState();
|
2019-11-07 07:03:35 +00:00
|
|
|
base.OnHoverLost(e);
|
|
|
|
}
|
|
|
|
|
2020-04-15 06:50:19 +00:00
|
|
|
private void updateState()
|
|
|
|
{
|
|
|
|
Alpha = Item.Action.Disabled ? 0.2f : 1;
|
|
|
|
|
|
|
|
if (IsHovered && !Item.Action.Disabled)
|
|
|
|
{
|
|
|
|
text.BoldText.FadeIn(transition_length, Easing.OutQuint);
|
|
|
|
text.NormalText.FadeOut(transition_length, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
text.BoldText.FadeOut(transition_length, Easing.OutQuint);
|
|
|
|
text.NormalText.FadeIn(transition_length, Easing.OutQuint);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-11-07 07:03:35 +00:00
|
|
|
protected sealed override Drawable CreateContent() => text = CreateTextContainer();
|
|
|
|
protected virtual TextContainer CreateTextContainer() => new TextContainer();
|
|
|
|
|
|
|
|
protected class TextContainer : Container, IHasText
|
|
|
|
{
|
2021-02-22 08:14:00 +00:00
|
|
|
public LocalisableString Text
|
2019-11-07 07:03:35 +00:00
|
|
|
{
|
|
|
|
get => NormalText.Text;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
NormalText.Text = value;
|
|
|
|
BoldText.Text = value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public readonly SpriteText NormalText;
|
|
|
|
public readonly SpriteText BoldText;
|
|
|
|
|
|
|
|
public TextContainer()
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft;
|
|
|
|
Origin = Anchor.CentreLeft;
|
|
|
|
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
NormalText = new OsuSpriteText
|
|
|
|
{
|
2022-01-23 15:36:18 +00:00
|
|
|
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
|
2019-11-07 07:03:35 +00:00
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.GetFont(size: text_size),
|
2019-11-07 13:26:35 +00:00
|
|
|
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
|
2019-11-07 07:03:35 +00:00
|
|
|
},
|
|
|
|
BoldText = new OsuSpriteText
|
|
|
|
{
|
2022-01-23 15:36:18 +00:00
|
|
|
AlwaysPresent = true, // ensures that the menu item does not change width when switching between normal and bold text.
|
2019-11-07 07:03:35 +00:00
|
|
|
Alpha = 0,
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
Font = OsuFont.GetFont(size: text_size, weight: FontWeight.Bold),
|
2019-11-07 13:26:35 +00:00
|
|
|
Margin = new MarginPadding { Horizontal = MARGIN_HORIZONTAL, Vertical = MARGIN_VERTICAL },
|
2019-11-07 07:03:35 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|