mirror of
https://github.com/ppy/osu.git
synced 2025-01-15 10:02:59 +08:00
Merge pull request #7647 from peppy/select-tool
Move select tool to an actual tool implementation
This commit is contained in:
commit
e0c3fa0cc1
@ -137,12 +137,12 @@ namespace osu.Game.Rulesets.Edit
|
||||
}
|
||||
};
|
||||
|
||||
toolboxCollection.Items =
|
||||
CompositionTools.Select(t => new RadioButton(t.Name, () => selectTool(t)))
|
||||
.Prepend(new RadioButton("Select", () => selectTool(null)))
|
||||
.ToList();
|
||||
toolboxCollection.Items = CompositionTools
|
||||
.Prepend(new SelectTool())
|
||||
.Select(t => new RadioButton(t.Name, () => toolSelected(t)))
|
||||
.ToList();
|
||||
|
||||
toolboxCollection.Items[0].Select();
|
||||
toolboxCollection.Items.First().Select();
|
||||
|
||||
blueprintContainer.SelectionChanged += selectionChanged;
|
||||
}
|
||||
@ -187,11 +187,11 @@ namespace osu.Game.Rulesets.Edit
|
||||
showGridFor(hitObjects);
|
||||
}
|
||||
|
||||
private void selectTool(HitObjectCompositionTool tool)
|
||||
private void toolSelected(HitObjectCompositionTool tool)
|
||||
{
|
||||
blueprintContainer.CurrentTool = tool;
|
||||
|
||||
if (tool == null)
|
||||
if (tool is SelectTool)
|
||||
distanceSnapGridContainer.Hide();
|
||||
else
|
||||
showGridFor(Enumerable.Empty<HitObject>());
|
||||
|
@ -13,5 +13,7 @@ namespace osu.Game.Rulesets.Edit.Tools
|
||||
}
|
||||
|
||||
public abstract PlacementBlueprint CreatePlacementBlueprint();
|
||||
|
||||
public override string ToString() => Name;
|
||||
}
|
||||
}
|
||||
|
15
osu.Game/Rulesets/Edit/Tools/SelectTool.cs
Normal file
15
osu.Game/Rulesets/Edit/Tools/SelectTool.cs
Normal file
@ -0,0 +1,15 @@
|
||||
// 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.
|
||||
|
||||
namespace osu.Game.Rulesets.Edit.Tools
|
||||
{
|
||||
public class SelectTool : HitObjectCompositionTool
|
||||
{
|
||||
public SelectTool()
|
||||
: base("Select")
|
||||
{
|
||||
}
|
||||
|
||||
public override PlacementBlueprint CreatePlacementBlueprint() => null;
|
||||
}
|
||||
}
|
@ -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,
|
||||
|
@ -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"/>.
|
||||
|
Loading…
Reference in New Issue
Block a user