mirror of
https://github.com/ppy/osu.git
synced 2024-11-06 06:57:39 +08:00
Merge pull request #16234 from smoogipoo/fix-initial-button-colour
Fix OsuAnimatedButton animating when initially disabled
This commit is contained in:
commit
8ad53138a6
@ -2,6 +2,7 @@
|
||||
// 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.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
@ -9,47 +10,96 @@ using osuTK;
|
||||
|
||||
namespace osu.Game.Tests.Visual.UserInterface
|
||||
{
|
||||
public class TestSceneOsuAnimatedButton : OsuGridTestScene
|
||||
public class TestSceneOsuAnimatedButton : OsuTestScene
|
||||
{
|
||||
public TestSceneOsuAnimatedButton()
|
||||
: base(3, 2)
|
||||
[Test]
|
||||
public void TestRelativeSized()
|
||||
{
|
||||
Cell(0).Add(new BaseContainer("relative sized")
|
||||
AddStep("add button", () => Child = new BaseContainer("relative sized")
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Action = () => { }
|
||||
});
|
||||
}
|
||||
|
||||
Cell(1).Add(new BaseContainer("auto sized")
|
||||
[Test]
|
||||
public void TestAutoSized()
|
||||
{
|
||||
AddStep("add button", () => Child = new BaseContainer("auto sized")
|
||||
{
|
||||
AutoSizeAxes = Axes.Both
|
||||
AutoSizeAxes = Axes.Both,
|
||||
Action = () => { }
|
||||
});
|
||||
}
|
||||
|
||||
Cell(2).Add(new BaseContainer("relative Y auto X")
|
||||
[Test]
|
||||
public void TestRelativeYAutoX()
|
||||
{
|
||||
AddStep("add button", () => Child = new BaseContainer("relative Y auto X")
|
||||
{
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
AutoSizeAxes = Axes.X
|
||||
AutoSizeAxes = Axes.X,
|
||||
Action = () => { }
|
||||
});
|
||||
}
|
||||
|
||||
Cell(3).Add(new BaseContainer("relative X auto Y")
|
||||
[Test]
|
||||
public void TestRelativeXAutoY()
|
||||
{
|
||||
AddStep("add button", () => Child = new BaseContainer("relative X auto Y")
|
||||
{
|
||||
RelativeSizeAxes = Axes.X,
|
||||
AutoSizeAxes = Axes.Y
|
||||
AutoSizeAxes = Axes.Y,
|
||||
Action = () => { }
|
||||
});
|
||||
}
|
||||
|
||||
Cell(4).Add(new BaseContainer("fixed")
|
||||
[Test]
|
||||
public void TestFixed1()
|
||||
{
|
||||
AddStep("add button", () => Child = new BaseContainer("fixed")
|
||||
{
|
||||
Size = new Vector2(100),
|
||||
Action = () => { }
|
||||
});
|
||||
}
|
||||
|
||||
Cell(5).Add(new BaseContainer("fixed")
|
||||
[Test]
|
||||
public void TestFixed2()
|
||||
{
|
||||
AddStep("add button", () => Child = new BaseContainer("fixed")
|
||||
{
|
||||
Size = new Vector2(100, 50),
|
||||
Action = () => { }
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestToggleEnabled()
|
||||
{
|
||||
BaseContainer button = null;
|
||||
|
||||
AddStep("add button", () => Child = button = new BaseContainer("fixed")
|
||||
{
|
||||
Size = new Vector2(200),
|
||||
});
|
||||
|
||||
AddToggleStep("toggle enabled", toggle =>
|
||||
{
|
||||
for (int i = 0; i < 6; i++)
|
||||
((BaseContainer)Cell(i).Child).Action = toggle ? () => { } : (Action)null;
|
||||
button.Action = toggle ? () => { } : (Action)null;
|
||||
});
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void TestInitiallyDisabled()
|
||||
{
|
||||
AddStep("add disabled button", () =>
|
||||
{
|
||||
Child = new BaseContainer("disabled")
|
||||
{
|
||||
Size = new Vector2(100)
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
|
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"
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
@ -38,6 +38,9 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
}
|
||||
|
||||
[Resolved]
|
||||
private OsuColour colours { get; set; }
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
private readonly Container content;
|
||||
@ -73,17 +76,25 @@ namespace osu.Game.Graphics.UserInterface
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
private void load()
|
||||
{
|
||||
if (AutoSizeAxes != Axes.None)
|
||||
{
|
||||
content.RelativeSizeAxes = (Axes.Both & ~AutoSizeAxes);
|
||||
content.AutoSizeAxes = AutoSizeAxes;
|
||||
}
|
||||
|
||||
Enabled.BindValueChanged(enabled => this.FadeColour(enabled.NewValue ? Color4.White : colours.Gray9, 200, Easing.OutQuint), true);
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Colour = dimColour;
|
||||
Enabled.BindValueChanged(_ => this.FadeColour(dimColour, 200, Easing.OutQuint));
|
||||
}
|
||||
|
||||
private Color4 dimColour => Enabled.Value ? Color4.White : colours.Gray9;
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
hover.FadeIn(500, Easing.OutQuint);
|
||||
|
@ -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]
|
||||
@ -94,11 +91,18 @@ namespace osu.Game.Graphics.UserInterface
|
||||
{
|
||||
if (backgroundColour == null)
|
||||
BackgroundColour = colours.BlueDark;
|
||||
|
||||
Enabled.ValueChanged += enabledChanged;
|
||||
Enabled.TriggerChange();
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
Colour = dimColour;
|
||||
Enabled.BindValueChanged(_ => this.FadeColour(dimColour, 200, Easing.OutQuint));
|
||||
}
|
||||
|
||||
private Color4 dimColour => Enabled.Value ? Color4.White : Color4.Gray;
|
||||
|
||||
protected override bool OnClick(ClickEvent e)
|
||||
{
|
||||
if (Enabled.Value)
|
||||
@ -144,10 +148,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user