Skip to content

Commit

Permalink
Merge pull request #29279 from normalid-awa/bugfix/editor/delete-oper…
Browse files Browse the repository at this point in the history
…ation-wont-close-the-menu

Close context menus when deselecting items in editor
  • Loading branch information
bdach authored Aug 7, 2024
2 parents e9a5b62 + aae49d3 commit 437812e
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 18 deletions.
6 changes: 3 additions & 3 deletions osu.Game.Rulesets.Osu.Tests/Editor/TestSceneObjectMerging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public void TestSimpleMerge()
});

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();

Expand Down Expand Up @@ -198,7 +198,7 @@ public void TestIllegalMerge()
});

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));
Expand All @@ -222,7 +222,7 @@ public void TestSameStartTimeMerge()
});

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();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,7 @@ public TestSceneHitObjectComposerDistanceSnapping()
[SetUp]
public void Setup() => Schedule(() =>
{
Children = new Drawable[]
{
composer = new TestHitObjectComposer()
};
Child = composer = new TestHitObjectComposer();
BeatDivisor.Value = 1;
Expand Down
10 changes: 9 additions & 1 deletion osu.Game/Graphics/Cursor/OsuContextMenuContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,24 @@

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();
}
}
}
22 changes: 15 additions & 7 deletions osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -16,6 +14,7 @@
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;
Expand Down Expand Up @@ -50,14 +49,17 @@ public abstract partial class SelectionHandler<T> : CompositeDrawable, IKeyBindi

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; } = null!;

public SelectionRotationHandler RotationHandler { get; private set; }
public SelectionScaleHandler ScaleHandler { get; private set; } = null!;

public SelectionScaleHandler ScaleHandler { get; private set; }
[Resolved(CanBeNull = true)]
protected OsuContextMenuContainer? ContextMenuContainer { get; private set; }

protected SelectionHandler()
{
Expand Down Expand Up @@ -230,7 +232,11 @@ public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
/// <summary>
/// Deselect all selected items.
/// </summary>
protected void DeselectAll() => SelectedItems.Clear();
protected void DeselectAll()
{
SelectedItems.Clear();
ContextMenuContainer?.CloseMenu();
}

/// <summary>
/// Handle a blueprint becoming selected.
Expand All @@ -243,6 +249,8 @@ internal virtual void HandleSelected(SelectionBlueprint<T> blueprint)
SelectedItems.Add(blueprint.Item);

selectedBlueprints.Add(blueprint);

ContextMenuContainer?.CloseMenu();
}

/// <summary>
Expand Down
15 changes: 12 additions & 3 deletions osu.Game/Screens/Edit/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -159,7 +160,7 @@ public bool ReadyForUse

private string lastSavedHash;

private Container<EditorScreen> screenContainer;
private ScreenContainer screenContainer;

[CanBeNull]
private readonly EditorLoader loader;
Expand Down Expand Up @@ -329,7 +330,7 @@ private void load(OsuConfigManager config)
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,
}
Expand Down Expand Up @@ -422,6 +423,7 @@ private void load(OsuConfigManager config)
MutationTracker,
}
});

changeHandler?.CanUndo.BindValueChanged(v => undoMenuItem.Action.Disabled = !v.NewValue, true);
changeHandler?.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true);

Expand Down Expand Up @@ -1007,7 +1009,7 @@ private void onModeChanged(ValueChangedEvent<EditorScreenMode> e)
throw new InvalidOperationException("Editor menu bar switched to an unsupported mode");
}

LoadComponentAsync(currentScreen, newScreen =>
screenContainer.LoadComponentAsync(currentScreen, newScreen =>
{
if (newScreen == currentScreen)
{
Expand Down Expand Up @@ -1385,5 +1387,12 @@ public BeatmapEditorToast(LocalisableString value, string beatmapDisplayName)
{
}
}

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);
}
}
}

0 comments on commit 437812e

Please sign in to comment.