mirror of
https://github.com/osukey/osukey.git
synced 2025-08-05 15:44:04 +09:00
Add disabled state to menu items
This commit is contained in:
@ -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();
|
||||
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user