mirror of
https://github.com/osukey/osukey.git
synced 2025-05-17 03:27:21 +09:00
Fix OsuButton event binding + inital-enablement colour
This commit is contained in:
parent
c8073000c5
commit
c973739b08
46
osu.Game.Tests/Visual/UserInterface/TestSceneOsuButton.cs
Normal file
46
osu.Game.Tests/Visual/UserInterface/TestSceneOsuButton.cs
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
// 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 System;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Tests.Visual.UserInterface
|
||||||
|
{
|
||||||
|
public class TestSceneOsuButton : OsuTestScene
|
||||||
|
{
|
||||||
|
[Test]
|
||||||
|
public void TestToggleEnabled()
|
||||||
|
{
|
||||||
|
OsuButton button = null;
|
||||||
|
|
||||||
|
AddStep("add button", () => Child = button = new OsuButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Size = new Vector2(200),
|
||||||
|
Text = "Button"
|
||||||
|
});
|
||||||
|
|
||||||
|
AddToggleStep("toggle enabled", toggle =>
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 6; i++)
|
||||||
|
button.Action = toggle ? () => { } : (Action)null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestInitiallyDisabled()
|
||||||
|
{
|
||||||
|
AddStep("add button", () => Child = new OsuButton
|
||||||
|
{
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
Size = new Vector2(200),
|
||||||
|
Text = "Button"
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Extensions.Color4Extensions;
|
using osu.Framework.Extensions.Color4Extensions;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
@ -85,8 +84,6 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
|
|
||||||
if (hoverSounds.HasValue)
|
if (hoverSounds.HasValue)
|
||||||
AddInternal(new HoverClickSounds(hoverSounds.Value));
|
AddInternal(new HoverClickSounds(hoverSounds.Value));
|
||||||
|
|
||||||
Enabled.BindValueChanged(enabledChanged, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
@ -95,10 +92,12 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
if (backgroundColour == null)
|
if (backgroundColour == null)
|
||||||
BackgroundColour = colours.BlueDark;
|
BackgroundColour = colours.BlueDark;
|
||||||
|
|
||||||
Enabled.ValueChanged += enabledChanged;
|
Colour = enablementColour;
|
||||||
Enabled.TriggerChange();
|
Enabled.BindValueChanged(_ => this.FadeColour(enablementColour, 200, Easing.OutQuint));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Color4 enablementColour => Enabled.Value ? Color4.White : Color4.Gray;
|
||||||
|
|
||||||
protected override bool OnClick(ClickEvent e)
|
protected override bool OnClick(ClickEvent e)
|
||||||
{
|
{
|
||||||
if (Enabled.Value)
|
if (Enabled.Value)
|
||||||
@ -144,10 +143,5 @@ namespace osu.Game.Graphics.UserInterface
|
|||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
Font = OsuFont.GetFont(weight: FontWeight.Bold)
|
||||||
};
|
};
|
||||||
|
|
||||||
private void enabledChanged(ValueChangedEvent<bool> e)
|
|
||||||
{
|
|
||||||
this.FadeColour(e.NewValue ? Color4.White : Color4.Gray, 200, Easing.OutQuint);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user