Move select tool to an actual tool implementation

Also tidies up radio button action firing so calling Select actually fires the associated action in all cases.
This commit is contained in:
Dean Herbert
2020-01-28 15:00:45 +09:00
parent 01cf417569
commit e81d3c51ed
5 changed files with 44 additions and 37 deletions

View File

@ -9,7 +9,6 @@ using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Input.Events;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
@ -37,8 +36,8 @@ namespace osu.Game.Screens.Edit.Components.RadioButtons
{
this.button = button;
Text = button.Text;
Action = button.Action;
Text = button.Item.ToString();
Action = button.Select;
RelativeSizeAxes = Axes.X;
@ -100,19 +99,6 @@ namespace osu.Game.Screens.Edit.Components.RadioButtons
bubble.Colour = button.Selected.Value ? selectedBubbleColour : defaultBubbleColour;
}
protected override bool OnClick(ClickEvent e)
{
if (button.Selected.Value)
return true;
if (!Enabled.Value)
return true;
button.Selected.Value = true;
return base.OnClick(e);
}
protected override SpriteText CreateText() => new OsuSpriteText
{
Depth = -1,

View File

@ -15,33 +15,37 @@ namespace osu.Game.Screens.Edit.Components.RadioButtons
public readonly BindableBool Selected;
/// <summary>
/// The text that should be displayed in this button.
/// The item related to this button.
/// </summary>
public string Text;
public object Item;
/// <summary>
/// The <see cref="Action"/> that should be invoked when this button is selected.
/// </summary>
public Action Action;
private readonly Action action;
public RadioButton(string text, Action action)
public RadioButton(object item, Action action)
{
Text = text;
Action = action;
Item = item;
this.action = action;
Selected = new BindableBool();
}
public RadioButton(string text)
: this(text, null)
public RadioButton(string item)
: this(item, null)
{
Text = text;
Action = null;
Item = item;
action = null;
}
/// <summary>
/// Selects this <see cref="RadioButton"/>.
/// </summary>
public void Select() => Selected.Value = true;
public void Select()
{
if (!Selected.Value)
{
Selected.Value = true;
action?.Invoke();
}
}
/// <summary>
/// Deselects this <see cref="RadioButton"/>.