Add disabled state to menu items

This commit is contained in:
smoogipoo
2020-04-15 15:50:19 +09:00
parent 2af2a49f22
commit 102c1d9095
3 changed files with 118 additions and 5 deletions

View File

@ -42,6 +42,8 @@ namespace osu.Game.Graphics.UserInterface
BackgroundColourHover = Color4Extensions.FromHex(@"172023");
updateTextColour();
Item.Action.BindDisabledChanged(_ => updateState(), true);
}
private void updateTextColour()
@ -65,19 +67,33 @@ namespace osu.Game.Graphics.UserInterface
protected override bool OnHover(HoverEvent e)
{
sampleHover.Play();
text.BoldText.FadeIn(transition_length, Easing.OutQuint);
text.NormalText.FadeOut(transition_length, Easing.OutQuint);
updateState();
return base.OnHover(e);
}
protected override void OnHoverLost(HoverLostEvent e)
{
text.BoldText.FadeOut(transition_length, Easing.OutQuint);
text.NormalText.FadeIn(transition_length, Easing.OutQuint);
updateState();
base.OnHoverLost(e);
}
private void updateState()
{
Alpha = Item.Action.Disabled ? 0.2f : 1;
if (IsHovered && !Item.Action.Disabled)
{
sampleHover.Play();
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);
}
}
protected override bool OnClick(ClickEvent e)
{
sampleClick.Play();

View File

@ -2,12 +2,15 @@
// See the LICENCE file in the repository root for full licence text.
using System;
using osu.Framework.Bindables;
using osu.Framework.Graphics.UserInterface;
namespace osu.Game.Graphics.UserInterface
{
public class OsuMenuItem : MenuItem
{
public readonly Bindable<bool> Enabled = new Bindable<bool>(true);
public readonly MenuItemType Type;
public OsuMenuItem(string text, MenuItemType type = MenuItemType.Standard)
@ -19,6 +22,9 @@ namespace osu.Game.Graphics.UserInterface
: base(text, action)
{
Type = type;
Enabled.BindValueChanged(enabled => Action.Disabled = !enabled.NewValue);
Action.BindDisabledChanged(disabled => Enabled.Value = !disabled);
}
}
}