Fix OsuButton event binding + inital-enablement colour

This commit is contained in:
Dan Balasescu
2021-12-24 11:50:48 +09:00
parent c8073000c5
commit c973739b08
2 changed files with 50 additions and 10 deletions

View File

@ -3,7 +3,6 @@
using System.Diagnostics;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
@ -85,8 +84,6 @@ namespace osu.Game.Graphics.UserInterface
if (hoverSounds.HasValue)
AddInternal(new HoverClickSounds(hoverSounds.Value));
Enabled.BindValueChanged(enabledChanged, true);
}
[BackgroundDependencyLoader]
@ -95,10 +92,12 @@ namespace osu.Game.Graphics.UserInterface
if (backgroundColour == null)
BackgroundColour = colours.BlueDark;
Enabled.ValueChanged += enabledChanged;
Enabled.TriggerChange();
Colour = enablementColour;
Enabled.BindValueChanged(_ => this.FadeColour(enablementColour, 200, Easing.OutQuint));
}
private Color4 enablementColour => Enabled.Value ? Color4.White : Color4.Gray;
protected override bool OnClick(ClickEvent e)
{
if (Enabled.Value)
@ -144,10 +143,5 @@ namespace osu.Game.Graphics.UserInterface
Anchor = Anchor.Centre,
Font = OsuFont.GetFont(weight: FontWeight.Bold)
};
private void enabledChanged(ValueChangedEvent<bool> e)
{
this.FadeColour(e.NewValue ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
}
}
}