mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 01:17:35 +09: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,
|
Origin = Anchor.Centre,
|
||||||
LabelText = "Button",
|
LabelText = "Button",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
AddStep("Enable button", () => circularButton.Enabled.Value = true);
|
||||||
|
AddStep("Disable button", () => circularButton.Enabled.Value = false);
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OsuColour osuColour)
|
private void load(OsuColour osuColour)
|
||||||
{
|
{
|
||||||
circularButton.DefaultColour = osuColour.Blue;
|
circularButton.AccentColour = osuColour.Blue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using OpenTK;
|
using OpenTK;
|
||||||
using OpenTK.Graphics;
|
using OpenTK.Graphics;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
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;
|
||||||
@ -10,11 +11,12 @@ using osu.Framework.Graphics.Shapes;
|
|||||||
using osu.Framework.Input.States;
|
using osu.Framework.Input.States;
|
||||||
using osu.Game.Graphics;
|
using osu.Game.Graphics;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics.UserInterface;
|
||||||
using System;
|
using System;
|
||||||
|
|
||||||
namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
||||||
{
|
{
|
||||||
public class SetupCircularButton : Container, IHasAccentColour
|
public class SetupCircularButton : TriangleButton, IHasAccentColour
|
||||||
{
|
{
|
||||||
private readonly Box fill;
|
private readonly Box fill;
|
||||||
private readonly OsuSpriteText label;
|
private readonly OsuSpriteText label;
|
||||||
@ -25,28 +27,6 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
|||||||
|
|
||||||
public event Action ButtonClicked;
|
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;
|
private Color4 accentColour;
|
||||||
public Color4 AccentColour
|
public Color4 AccentColour
|
||||||
{
|
{
|
||||||
@ -57,23 +37,16 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
|||||||
fill.Colour = value;
|
fill.Colour = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private string labelText;
|
|
||||||
public string LabelText
|
public string LabelText
|
||||||
{
|
{
|
||||||
get => labelText;
|
get => label.Text;
|
||||||
set
|
set => label.Text = value;
|
||||||
{
|
|
||||||
labelText = value;
|
|
||||||
label.Text = value;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public SetupCircularButton()
|
public SetupCircularButton()
|
||||||
{
|
{
|
||||||
Size = new Vector2(SIZE_X, SIZE_Y);
|
Size = new Vector2(SIZE_X, SIZE_Y);
|
||||||
CornerRadius = 15;
|
|
||||||
Masking = true;
|
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
@ -88,46 +61,25 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components
|
|||||||
Origin = Anchor.Centre,
|
Origin = Anchor.Centre,
|
||||||
Colour = Color4.White,
|
Colour = Color4.White,
|
||||||
TextSize = DEFAULT_LABEL_TEXT_SIZE,
|
TextSize = DEFAULT_LABEL_TEXT_SIZE,
|
||||||
Text = LabelText,
|
|
||||||
Font = @"Exo2.0-Bold",
|
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)
|
protected override bool OnClick(InputState state)
|
||||||
{
|
{
|
||||||
// Effect to indicate the button has been clicked
|
if (Enabled.Value)
|
||||||
if (!disabled)
|
|
||||||
ButtonClicked?.Invoke();
|
ButtonClicked?.Invoke();
|
||||||
return base.OnClick(state);
|
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