1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 16:47:29 +08:00

Merge pull request #29279 from normalid-awa/bugfix/editor/delete-operation-wont-close-the-menu

Close context menus when deselecting items in editor
This commit is contained in:
Bartłomiej Dach 2024-08-07 13:25:13 +02:00 committed by GitHub
commit 437812eebe
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 40 additions and 18 deletions

View File

@ -34,7 +34,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
});
moveMouseToHitObject(1);
AddAssert("merge option available", () => selectionHandler.ContextMenuItems?.Any(o => o.Text.Value == "Merge selection") == true);
AddAssert("merge option available", () => selectionHandler.ContextMenuItems.Any(o => o.Text.Value == "Merge selection"));
mergeSelection();
@ -198,7 +198,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
});
moveMouseToHitObject(1);
AddAssert("merge option not available", () => selectionHandler.ContextMenuItems?.Length > 0 && selectionHandler.ContextMenuItems.All(o => o.Text.Value != "Merge selection"));
AddAssert("merge option not available", () => selectionHandler.ContextMenuItems.Length > 0 && selectionHandler.ContextMenuItems.All(o => o.Text.Value != "Merge selection"));
mergeSelection();
AddAssert("circles not merged", () => circle1 is not null && circle2 is not null
&& EditorBeatmap.HitObjects.Contains(circle1) && EditorBeatmap.HitObjects.Contains(circle2));
@ -222,7 +222,7 @@ namespace osu.Game.Rulesets.Osu.Tests.Editor
});
moveMouseToHitObject(1);
AddAssert("merge option available", () => selectionHandler.ContextMenuItems?.Any(o => o.Text.Value == "Merge selection") == true);
AddAssert("merge option available", () => selectionHandler.ContextMenuItems.Any(o => o.Text.Value == "Merge selection"));
mergeSelection();

View File

@ -52,10 +52,7 @@ namespace osu.Game.Tests.Editing
[SetUp]
public void Setup() => Schedule(() =>
{
Children = new Drawable[]
{
composer = new TestHitObjectComposer()
};
Child = composer = new TestHitObjectComposer();
BeatDivisor.Value = 1;

View File

@ -8,16 +8,24 @@ using osu.Game.Graphics.UserInterface;
namespace osu.Game.Graphics.Cursor
{
[Cached(typeof(OsuContextMenuContainer))]
public partial class OsuContextMenuContainer : ContextMenuContainer
{
[Cached]
private OsuContextMenuSamples samples = new OsuContextMenuSamples();
private OsuContextMenu menu = null!;
public OsuContextMenuContainer()
{
AddInternal(samples);
}
protected override Menu CreateMenu() => new OsuContextMenu(true);
protected override Menu CreateMenu() => menu = new OsuContextMenu(true);
public void CloseMenu()
{
menu.Close();
}
}
}

View File

@ -1,8 +1,6 @@
// 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.
#nullable disable
using System;
using System.Collections.Generic;
using System.Linq;
@ -16,6 +14,7 @@ using osu.Framework.Graphics.UserInterface;
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Resources.Localisation.Web;
@ -50,14 +49,17 @@ namespace osu.Game.Screens.Edit.Compose.Components
private readonly List<SelectionBlueprint<T>> selectedBlueprints;
protected SelectionBox SelectionBox { get; private set; }
protected SelectionBox SelectionBox { get; private set; } = null!;
[Resolved(CanBeNull = true)]
protected IEditorChangeHandler ChangeHandler { get; private set; }
protected IEditorChangeHandler? ChangeHandler { get; private set; }
public SelectionRotationHandler RotationHandler { get; private set; }
public SelectionRotationHandler RotationHandler { get; private set; } = null!;
public SelectionScaleHandler ScaleHandler { get; private set; }
public SelectionScaleHandler ScaleHandler { get; private set; } = null!;
[Resolved(CanBeNull = true)]
protected OsuContextMenuContainer? ContextMenuContainer { get; private set; }
protected SelectionHandler()
{
@ -230,7 +232,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary>
/// Deselect all selected items.
/// </summary>
protected void DeselectAll() => SelectedItems.Clear();
protected void DeselectAll()
{
SelectedItems.Clear();
ContextMenuContainer?.CloseMenu();
}
/// <summary>
/// Handle a blueprint becoming selected.
@ -243,6 +249,8 @@ namespace osu.Game.Screens.Edit.Compose.Components
SelectedItems.Add(blueprint.Item);
selectedBlueprints.Add(blueprint);
ContextMenuContainer?.CloseMenu();
}
/// <summary>

View File

@ -6,6 +6,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using JetBrains.Annotations;
using osu.Framework;
@ -159,7 +160,7 @@ namespace osu.Game.Screens.Edit
private string lastSavedHash;
private Container<EditorScreen> screenContainer;
private ScreenContainer screenContainer;
[CanBeNull]
private readonly EditorLoader loader;
@ -329,7 +330,7 @@ namespace osu.Game.Screens.Edit
Name = "Screen container",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 40, Bottom = 50 },
Child = screenContainer = new Container<EditorScreen>
Child = screenContainer = new ScreenContainer
{
RelativeSizeAxes = Axes.Both,
}
@ -422,6 +423,7 @@ namespace osu.Game.Screens.Edit
MutationTracker,
}
});
changeHandler?.CanUndo.BindValueChanged(v => undoMenuItem.Action.Disabled = !v.NewValue, true);
changeHandler?.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true);
@ -1007,7 +1009,7 @@ namespace osu.Game.Screens.Edit
throw new InvalidOperationException("Editor menu bar switched to an unsupported mode");
}
LoadComponentAsync(currentScreen, newScreen =>
screenContainer.LoadComponentAsync(currentScreen, newScreen =>
{
if (newScreen == currentScreen)
{
@ -1385,5 +1387,12 @@ namespace osu.Game.Screens.Edit
{
}
}
private partial class ScreenContainer : Container<EditorScreen>
{
public new Task LoadComponentAsync<TLoadable>([NotNull] TLoadable component, Action<TLoadable> onLoaded = null, CancellationToken cancellation = default, Scheduler scheduler = null)
where TLoadable : Drawable
=> base.LoadComponentAsync(component, onLoaded, cancellation, scheduler);
}
}
}