Merge pull request #28707 from bdach/remove-breaks

Add option to remove breaks via timeline context menu
This commit is contained in:
Dean Herbert 2024-07-03 16:29:25 +09:00 committed by GitHub
commit 824a00b018
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 69 additions and 3 deletions

View File

@ -403,6 +403,28 @@ namespace osu.Game.Tests.Visual.Editing
AddAssert("placement committed", () => EditorBeatmap.HitObjects, () => Has.Count.EqualTo(2));
}
[Test]
public void TestBreakRemoval()
{
var addedObjects = new[]
{
new HitCircle { StartTime = 0 },
new HitCircle { StartTime = 5000 },
};
AddStep("add hitobjects", () => EditorBeatmap.AddRange(addedObjects));
AddAssert("beatmap has one break", () => EditorBeatmap.Breaks, () => Has.Count.EqualTo(1));
AddStep("move mouse to break", () => InputManager.MoveMouseTo(this.ChildrenOfType<TimelineBreak>().Single()));
AddStep("right click", () => InputManager.Click(MouseButton.Right));
AddStep("move mouse to delete menu item", () => InputManager.MoveMouseTo(this.ChildrenOfType<OsuContextMenu>().First().ChildrenOfType<DrawableOsuMenuItem>().First()));
AddStep("click", () => InputManager.Click(MouseButton.Left));
AddAssert("beatmap has no breaks", () => EditorBeatmap.Breaks, () => Is.Empty);
AddAssert("break piece went away", () => this.ChildrenOfType<TimelineBreak>().Count(), () => Is.Zero);
}
private void assertSelectionIs(IEnumerable<HitObject> hitObjects)
=> AddAssert("correct hitobjects selected", () => EditorBeatmap.SelectedHitObjects.OrderBy(h => h.StartTime).SequenceEqual(hitObjects));
}

View File

@ -9,20 +9,31 @@ using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input.Events;
using osu.Game.Beatmaps.Timing;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.UserInterface;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Objects;
using osuTK;
namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
public partial class TimelineBreak : CompositeDrawable
public partial class TimelineBreak : CompositeDrawable, IHasContextMenu
{
public Bindable<BreakPeriod> Break { get; } = new Bindable<BreakPeriod>();
public Action<BreakPeriod>? OnDeleted { get; init; }
private Box background = null!;
[Resolved]
private OsuColour colours { get; set; } = null!;
public TimelineBreak(BreakPeriod b)
{
Break.Value = b;
@ -42,7 +53,7 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
{
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Horizontal = 5 },
Child = new Box
Child = background = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Gray5,
@ -77,6 +88,28 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
}, true);
}
protected override bool OnHover(HoverEvent e)
{
updateState();
return true;
}
protected override void OnHoverLost(HoverLostEvent e)
{
updateState();
base.OnHoverLost(e);
}
private void updateState()
{
background.FadeColour(IsHovered ? colours.Gray6 : colours.Gray5, 400, Easing.OutQuint);
}
public MenuItem[] ContextMenuItems => new MenuItem[]
{
new OsuMenuItem(CommonStrings.ButtonsDelete, MenuItemType.Destructive, () => OnDeleted?.Invoke(Break.Value)),
};
private partial class DragHandle : FillFlowContainer
{
public Bindable<BreakPeriod> Break { get; } = new Bindable<BreakPeriod>();

View File

@ -15,6 +15,9 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
[Resolved]
private Timeline timeline { get; set; } = null!;
[Resolved]
private IEditorChangeHandler? editorChangeHandler { get; set; }
/// <summary>
/// The visible time/position range of the timeline.
/// </summary>
@ -71,7 +74,15 @@ namespace osu.Game.Screens.Edit.Compose.Components.Timeline
if (!shouldBeVisible(breakPeriod))
continue;
Add(new TimelineBreak(breakPeriod));
Add(new TimelineBreak(breakPeriod)
{
OnDeleted = b =>
{
editorChangeHandler?.BeginChange();
breaks.Remove(b);
editorChangeHandler?.EndChange();
},
});
}
}