mirror of
https://github.com/ppy/osu.git
synced 2025-02-16 14:22:54 +08:00
Add slider control point deletion right-click menu item (#6832)
Add slider control point deletion right-click menu item Co-authored-by: Dean Herbert <pe@ppy.sh>
This commit is contained in:
commit
0f493aebef
@ -14,12 +14,13 @@ using osu.Game.Rulesets.Edit;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osuTK;
|
||||
using osuTK.Graphics;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
public class PathControlPointPiece : BlueprintPiece<Slider>
|
||||
{
|
||||
public Action<int> RequestSelection;
|
||||
public Action<int, MouseButtonEvent> RequestSelection;
|
||||
public Action<Vector2[]> ControlPointsChanged;
|
||||
|
||||
public readonly BindableBool IsSelected = new BindableBool();
|
||||
@ -129,10 +130,19 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
protected override bool OnMouseDown(MouseDownEvent e)
|
||||
{
|
||||
if (RequestSelection != null)
|
||||
if (RequestSelection == null)
|
||||
return false;
|
||||
|
||||
switch (e.Button)
|
||||
{
|
||||
RequestSelection.Invoke(Index);
|
||||
case MouseButton.Left:
|
||||
RequestSelection.Invoke(Index, e);
|
||||
return true;
|
||||
|
||||
case MouseButton.Right:
|
||||
if (!IsSelected.Value)
|
||||
RequestSelection.Invoke(Index, e);
|
||||
return false; // Allow context menu to show
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -142,7 +152,7 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
|
||||
protected override bool OnClick(ClickEvent e) => RequestSelection != null;
|
||||
|
||||
protected override bool OnDragStart(DragStartEvent e) => true;
|
||||
protected override bool OnDragStart(DragStartEvent e) => e.Button == MouseButton.Left;
|
||||
|
||||
protected override bool OnDrag(DragEvent e)
|
||||
{
|
||||
|
@ -3,19 +3,25 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using Humanizer;
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Cursor;
|
||||
using osu.Framework.Graphics.UserInterface;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Bindings;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Screens.Edit.Compose;
|
||||
using osuTK;
|
||||
using osuTK.Input;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
{
|
||||
public class PathControlPointVisualiser : CompositeDrawable, IKeyBindingHandler<PlatformAction>
|
||||
public class PathControlPointVisualiser : CompositeDrawable, IKeyBindingHandler<PlatformAction>, IHasContextMenu
|
||||
{
|
||||
public Action<Vector2[]> ControlPointsChanged;
|
||||
|
||||
@ -73,9 +79,22 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
return false;
|
||||
}
|
||||
|
||||
private void selectPiece(int index)
|
||||
public bool OnPressed(PlatformAction action)
|
||||
{
|
||||
if (inputManager.CurrentState.Keyboard.ControlPressed)
|
||||
switch (action.ActionMethod)
|
||||
{
|
||||
case PlatformActionMethod.Delete:
|
||||
return deleteSelected();
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool OnReleased(PlatformAction action) => action.ActionMethod == PlatformActionMethod.Delete;
|
||||
|
||||
private void selectPiece(int index, MouseButtonEvent e)
|
||||
{
|
||||
if (e.Button == MouseButton.Left && inputManager.CurrentState.Keyboard.ControlPressed)
|
||||
Pieces[index].IsSelected.Toggle();
|
||||
else
|
||||
{
|
||||
@ -84,11 +103,8 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
}
|
||||
}
|
||||
|
||||
public bool OnPressed(PlatformAction action)
|
||||
private bool deleteSelected()
|
||||
{
|
||||
switch (action.ActionMethod)
|
||||
{
|
||||
case PlatformActionMethod.Delete:
|
||||
var newControlPoints = new List<Vector2>();
|
||||
|
||||
foreach (var piece in Pieces)
|
||||
@ -121,13 +137,26 @@ namespace osu.Game.Rulesets.Osu.Edit.Blueprints.Sliders.Components
|
||||
piece.IsSelected.Value = false;
|
||||
|
||||
ControlPointsChanged?.Invoke(newControlPoints.ToArray());
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public MenuItem[] ContextMenuItems
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!Pieces.Any(p => p.IsHovered))
|
||||
return null;
|
||||
|
||||
public bool OnReleased(PlatformAction action) => action.ActionMethod == PlatformActionMethod.Delete;
|
||||
int selectedPoints = Pieces.Count(p => p.IsSelected.Value);
|
||||
|
||||
if (selectedPoints == 0)
|
||||
return null;
|
||||
|
||||
return new MenuItem[]
|
||||
{
|
||||
new OsuMenuItem($"Delete {"control point".ToQuantity(selectedPoints)}", MenuItemType.Destructive, () => deleteSelected())
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -313,14 +313,15 @@ namespace osu.Game.Screens.Edit.Compose.Components
|
||||
/// Attempts to select any hovered blueprints.
|
||||
/// </summary>
|
||||
/// <param name="e">The input event that triggered this selection.</param>
|
||||
private void beginClickSelection(UIEvent e)
|
||||
private void beginClickSelection(MouseButtonEvent e)
|
||||
{
|
||||
Debug.Assert(!clickSelectionBegan);
|
||||
|
||||
// If a select blueprint is already hovered, disallow changes in selection.
|
||||
// Exception is made when holding control, as deselection should still be allowed.
|
||||
if (!e.CurrentState.Keyboard.ControlPressed &&
|
||||
selectionHandler.SelectedBlueprints.Any(s => s.IsHovered))
|
||||
// Deselections are only allowed for control + left clicks
|
||||
bool allowDeselection = e.ControlPressed && e.Button == MouseButton.Left;
|
||||
|
||||
// Todo: This is probably incorrectly disallowing multiple selections on stacked objects
|
||||
if (!allowDeselection && selectionHandler.SelectedBlueprints.Any(s => s.IsHovered))
|
||||
return;
|
||||
|
||||
foreach (SelectionBlueprint blueprint in selectionBlueprints.AliveBlueprints)
|
||||
|
Loading…
Reference in New Issue
Block a user