mirror of
https://github.com/ppy/osu.git
synced 2025-03-16 05:37:19 +08:00
Prefer inheriting TriangleButton instead of Container
This commit is contained in:
parent
ebf14c9c93
commit
2a819a53c0
@ -27,12 +27,15 @@ namespace osu.Game.Tests.Visual
|
||||
Origin = Anchor.Centre,
|
||||
LabelText = "Button",
|
||||
};
|
||||
|
||||
AddStep("Enable button", () => circularButton.Enabled.Value = true);
|
||||
AddStep("Disable button", () => circularButton.Enabled.Value = false);
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour osuColour)
|
||||
{
|
||||
circularButton.DefaultColour = osuColour.Blue;
|
||||
circularButton.AccentColour = osuColour.Blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
|
||||
using OpenTK;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Extensions.Color4Extensions;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
@ -10,11 +11,12 @@ using osu.Framework.Graphics.Shapes;
|
||||
using osu.Framework.Input.States;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using System;
|
||||
|
||||
namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
||||
{
|
||||
public class SetupCircularButton : Container, IHasAccentColour
|
||||
public class SetupCircularButton : TriangleButton, IHasAccentColour
|
||||
{
|
||||
private readonly Box fill;
|
||||
private readonly OsuSpriteText label;
|
||||
@ -25,28 +27,6 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
||||
|
||||
public event Action ButtonClicked;
|
||||
|
||||
private bool disabled;
|
||||
public bool Disabled
|
||||
{
|
||||
get => disabled;
|
||||
set
|
||||
{
|
||||
disabled = value;
|
||||
fadeColour();
|
||||
}
|
||||
}
|
||||
|
||||
private Color4 defaultColour;
|
||||
public Color4 DefaultColour
|
||||
{
|
||||
get => defaultColour;
|
||||
set
|
||||
{
|
||||
defaultColour = value;
|
||||
fadeColour();
|
||||
}
|
||||
}
|
||||
|
||||
private Color4 accentColour;
|
||||
public Color4 AccentColour
|
||||
{
|
||||
@ -57,23 +37,16 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
||||
fill.Colour = value;
|
||||
}
|
||||
}
|
||||
|
||||
private string labelText;
|
||||
|
||||
public string LabelText
|
||||
{
|
||||
get => labelText;
|
||||
set
|
||||
{
|
||||
labelText = value;
|
||||
label.Text = value;
|
||||
}
|
||||
get => label.Text;
|
||||
set => label.Text = value;
|
||||
}
|
||||
|
||||
public SetupCircularButton()
|
||||
{
|
||||
Size = new Vector2(SIZE_X, SIZE_Y);
|
||||
CornerRadius = 15;
|
||||
Masking = true;
|
||||
|
||||
Children = new Drawable[]
|
||||
{
|
||||
@ -88,46 +61,25 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
||||
Origin = Anchor.Centre,
|
||||
Colour = Color4.White,
|
||||
TextSize = DEFAULT_LABEL_TEXT_SIZE,
|
||||
Text = LabelText,
|
||||
Font = @"Exo2.0-Bold",
|
||||
}
|
||||
};
|
||||
|
||||
Enabled.Value = true;
|
||||
}
|
||||
|
||||
protected override void LoadComplete()
|
||||
[BackgroundDependencyLoader]
|
||||
private void load(OsuColour colours)
|
||||
{
|
||||
FadeEdgeEffectTo(0);
|
||||
Triangles.Alpha = 0;
|
||||
Content.CornerRadius = 15;
|
||||
}
|
||||
|
||||
protected override bool OnClick(InputState state)
|
||||
{
|
||||
// Effect to indicate the button has been clicked
|
||||
if (!disabled)
|
||||
if (Enabled.Value)
|
||||
ButtonClicked?.Invoke();
|
||||
return base.OnClick(state);
|
||||
}
|
||||
|
||||
protected override bool OnHover(InputState state)
|
||||
{
|
||||
fadeColour();
|
||||
return base.OnHover(state);
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(InputState state)
|
||||
{
|
||||
fadeColour();
|
||||
base.OnHoverLost(state);
|
||||
}
|
||||
|
||||
private void fadeColour()
|
||||
{
|
||||
if (!disabled)
|
||||
{
|
||||
this.FadeAccent(defaultColour.Lighten(IsHovered ? 0.3f : 0), 500, Easing.OutQuint);
|
||||
this.FadeTo(1, 500, Easing.OutQuint);
|
||||
}
|
||||
else
|
||||
this.FadeTo(0.3f, 500, Easing.OutQuint);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user