1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 14:17:26 +08:00

Completely reuse TriangleButton

This commit is contained in:
smoogipoo 2018-07-31 15:49:04 +09:00
parent 93cf063c97
commit c5a772bbc8
2 changed files with 5 additions and 68 deletions

View File

@ -1,9 +1,7 @@
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Game.Graphics;
using osu.Game.Screens.Edit.Screens.Setup.Components;
using System;
using System.Collections.Generic;
@ -17,25 +15,20 @@ namespace osu.Game.Tests.Visual
typeof(SetupCircularButton)
};
private readonly SetupCircularButton circularButton;
public TestCaseEditorSetupCircularButton()
{
SetupCircularButton circularButton;
Child = circularButton = new SetupCircularButton
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
LabelText = "Button",
Text = "Button",
Action = () => { }
};
AddStep("Enable button", () => circularButton.Enabled.Value = true);
AddStep("Disable button", () => circularButton.Enabled.Value = false);
}
[BackgroundDependencyLoader]
private void load(OsuColour osuColour)
{
circularButton.AccentColour = osuColour.Blue;
}
}
}

View File

@ -2,68 +2,19 @@
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK;
using OpenTK.Graphics;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
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 : TriangleButton, IHasAccentColour
public class SetupCircularButton : TriangleButton
{
private readonly Box fill;
private readonly OsuSpriteText label;
private const float default_label_text_size = 14;
private const float size_x = 125;
private const float size_y = 30;
public event Action ButtonClicked;
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set
{
accentColour = value;
fill.Colour = value;
}
}
public string LabelText
{
get => label.Text;
set => label.Text = value;
}
public SetupCircularButton()
{
Size = new Vector2(size_x, size_y);
Children = new Drawable[]
{
fill = new Box
{
RelativeSizeAxes = Axes.Both,
AlwaysPresent = true,
},
label = new OsuSpriteText
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Colour = Color4.White,
TextSize = default_label_text_size,
Font = @"Exo2.0-Bold",
}
};
Enabled.Value = true;
}
[BackgroundDependencyLoader]
@ -72,12 +23,5 @@ namespace osu.Game.Screens.Edit.Screens.Setup.Components
Triangles.Alpha = 0;
Content.CornerRadius = 15;
}
protected override bool OnClick(InputState state)
{
if (Enabled.Value)
ButtonClicked?.Invoke();
return base.OnClick(state);
}
}
}