Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Close context menus when deselecting items in editor #29279

Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
de6d8e7
Add the custom context menu to handle the key event
normalid-awa Aug 4, 2024
83aeb27
Replace original menu container to the custom one
normalid-awa Aug 4, 2024
1ff0c7c
Replace original menu container with custom one
normalid-awa Aug 4, 2024
5c5fcd7
Allow key event pass through selection handler
normalid-awa Aug 4, 2024
27d6c4c
Implement on beatmap editor
normalid-awa Aug 4, 2024
3cc5466
Refactor the code to follow IoC principle and more flexible
normalid-awa Aug 4, 2024
5d31171
Fix code quality
normalid-awa Aug 4, 2024
7c83d6a
Cleanup code
normalid-awa Aug 4, 2024
2145368
Merge `EditorContextMenuContainer` into `OsuContextMenuContainer`
normalid-awa Aug 4, 2024
38dacfe
Fix unit test
normalid-awa Aug 4, 2024
7cebf4c
Fix code quality
normalid-awa Aug 4, 2024
b32d97b
Remove decreapted property
normalid-awa Aug 4, 2024
2720bcf
Fix ruleset unit test
normalid-awa Aug 4, 2024
1b25633
Fix headless test
normalid-awa Aug 4, 2024
2098fb8
Fix code quality
normalid-awa Aug 4, 2024
6d385c6
Remove the meaningless `OpenMenu` method
normalid-awa Aug 5, 2024
75c0c6a
Make the `OsuContextMenu` nullable in `SelectionHandler`
normalid-awa Aug 5, 2024
3c8d0ce
Revert the unit test changes
normalid-awa Aug 5, 2024
59ff549
Remove unused using
normalid-awa Aug 5, 2024
22ab6f5
Add back the sample into `OsuContextMenu`
normalid-awa Aug 6, 2024
cb877b7
Close the menu when selecting other object
normalid-awa Aug 6, 2024
b91461e
Refactor + CI fixes
smoogipoo Aug 6, 2024
c574551
Simplify caching
smoogipoo Aug 6, 2024
c26a664
Use InternalChild directly
smoogipoo Aug 6, 2024
41d84ea
Revert all SkinEditor changes (none required)
smoogipoo Aug 6, 2024
aae49d3
Fix unit test code quality
normalid-awa Aug 6, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 6 additions & 2 deletions osu.Game.Tests/Visual/Editing/TimelineTestScene.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ protected override void LoadComplete()

Composer.Alpha = 0;

Add(new OsuContextMenuContainer
var contextMenuContainer = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
Expand All @@ -75,7 +75,11 @@ protected override void LoadComplete()
Origin = Anchor.Centre,
}
}
});
};

Dependencies.Cache(contextMenuContainer);

Add(contextMenuContainer);
}

[SetUpSteps]
Expand Down
10 changes: 6 additions & 4 deletions osu.Game/Graphics/Cursor/OsuContextMenuContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ public partial class OsuContextMenuContainer : ContextMenuContainer
[Cached]
private OsuContextMenuSamples samples = new OsuContextMenuSamples();

public OsuContextMenuContainer()
private OsuContextMenu menu = null!;

protected override Menu CreateMenu() => menu = new OsuContextMenu(true);

public void CloseMenu()
{
AddInternal(samples);
menu.Close();
}

protected override Menu CreateMenu() => new OsuContextMenu(true);
}
}
169 changes: 86 additions & 83 deletions osu.Game/Overlays/SkinEditor/SkinEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
using osu.Game.Database;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
using osu.Game.Localisation;
using osu.Game.Overlays.Dialog;
Expand All @@ -33,6 +32,7 @@
using osu.Game.Screens.Edit.Components;
using osu.Game.Screens.Edit.Components.Menus;
using osu.Game.Skinning;
using osu.Game.Graphics.Cursor;

namespace osu.Game.Overlays.SkinEditor
{
Expand Down Expand Up @@ -101,6 +101,12 @@ public partial class SkinEditor : VisibilityContainer, ICanAcceptFiles, IKeyBind
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }

[Cached]
public OsuContextMenuContainer ContextMenuContainer { get; private set; } = new OsuContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
};

public SkinEditor()
{
}
Expand All @@ -115,114 +121,111 @@ private void load(EditorClipboard clipboard)
{
RelativeSizeAxes = Axes.Both;

InternalChild = new OsuContextMenuContainer
ContextMenuContainer.Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Child = new GridContainer
RowDimensions = new[]
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
},

Content = new[]
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
},
Content = new[]
{
new Drawable[]
{
new Drawable[]
new Container
{
new Container
Name = @"Menu container",
RelativeSizeAxes = Axes.X,
Depth = float.MinValue,
Height = MENU_HEIGHT,
Children = new Drawable[]
{
Name = @"Menu container",
RelativeSizeAxes = Axes.X,
Depth = float.MinValue,
Height = MENU_HEIGHT,
Children = new Drawable[]
new EditorMenuBar
{
new EditorMenuBar
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
Items = new[]
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
Items = new[]
new MenuItem(CommonStrings.MenuBarFile)
{
new MenuItem(CommonStrings.MenuBarFile)
Items = new OsuMenuItem[]
{
Items = new OsuMenuItem[]
{
new EditorMenuItem(Web.CommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()),
new EditorMenuItem(CommonStrings.Export, MenuItemType.Standard, () => skins.ExportCurrentSkin()) { Action = { Disabled = !RuntimeInfo.IsDesktop } },
new OsuMenuItemSpacer(),
new EditorMenuItem(CommonStrings.RevertToDefault, MenuItemType.Destructive, () => dialogOverlay?.Push(new RevertConfirmDialog(revert))),
new OsuMenuItemSpacer(),
new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, () => skinEditorOverlay?.Hide()),
},
new EditorMenuItem(Web.CommonStrings.ButtonsSave, MenuItemType.Standard, () => Save()),
new EditorMenuItem(CommonStrings.Export, MenuItemType.Standard, () => skins.ExportCurrentSkin()) { Action = { Disabled = !RuntimeInfo.IsDesktop } },
new OsuMenuItemSpacer(),
new EditorMenuItem(CommonStrings.RevertToDefault, MenuItemType.Destructive, () => dialogOverlay?.Push(new RevertConfirmDialog(revert))),
new OsuMenuItemSpacer(),
new EditorMenuItem(CommonStrings.Exit, MenuItemType.Standard, () => skinEditorOverlay?.Hide()),
},
new MenuItem(CommonStrings.MenuBarEdit)
},
new MenuItem(CommonStrings.MenuBarEdit)
{
Items = new OsuMenuItem[]
{
Items = new OsuMenuItem[]
{
undoMenuItem = new EditorMenuItem(CommonStrings.Undo, MenuItemType.Standard, Undo),
redoMenuItem = new EditorMenuItem(CommonStrings.Redo, MenuItemType.Standard, Redo),
new OsuMenuItemSpacer(),
cutMenuItem = new EditorMenuItem(CommonStrings.Cut, MenuItemType.Standard, Cut),
copyMenuItem = new EditorMenuItem(CommonStrings.Copy, MenuItemType.Standard, Copy),
pasteMenuItem = new EditorMenuItem(CommonStrings.Paste, MenuItemType.Standard, Paste),
cloneMenuItem = new EditorMenuItem(CommonStrings.Clone, MenuItemType.Standard, Clone),
}
},
}
},
headerText = new OsuTextFlowContainer
{
TextAnchor = Anchor.TopRight,
Padding = new MarginPadding(5),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
},
undoMenuItem = new EditorMenuItem(CommonStrings.Undo, MenuItemType.Standard, Undo),
redoMenuItem = new EditorMenuItem(CommonStrings.Redo, MenuItemType.Standard, Redo),
new OsuMenuItemSpacer(),
cutMenuItem = new EditorMenuItem(CommonStrings.Cut, MenuItemType.Standard, Cut),
copyMenuItem = new EditorMenuItem(CommonStrings.Copy, MenuItemType.Standard, Copy),
pasteMenuItem = new EditorMenuItem(CommonStrings.Paste, MenuItemType.Standard, Paste),
cloneMenuItem = new EditorMenuItem(CommonStrings.Clone, MenuItemType.Standard, Clone),
}
},
}
},
headerText = new OsuTextFlowContainer
{
TextAnchor = Anchor.TopRight,
Padding = new MarginPadding(5),
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
AutoSizeAxes = Axes.X,
RelativeSizeAxes = Axes.Y,
},
},
},
new Drawable[]
},
new Drawable[]
{
new SkinEditorSceneLibrary
{
new SkinEditorSceneLibrary
{
RelativeSizeAxes = Axes.X,
},
RelativeSizeAxes = Axes.X,
},
new Drawable[]
},
new Drawable[]
{
new GridContainer
{
new GridContainer
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new Drawable[]
{
new Drawable[]
componentsSidebar = new EditorSidebar(),
content = new Container
{
componentsSidebar = new EditorSidebar(),
content = new Container
{
Depth = float.MaxValue,
RelativeSizeAxes = Axes.Both,
},
settingsSidebar = new EditorSidebar(),
}
Depth = float.MaxValue,
RelativeSizeAxes = Axes.Both,
},
settingsSidebar = new EditorSidebar(),
}
}
},
}
}
},
}
};

AddInternal(ContextMenuContainer);

clipboardContent = clipboard.Content.GetBoundCopy();
}

Expand Down
10 changes: 9 additions & 1 deletion osu.Game/Screens/Edit/Compose/Components/SelectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,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 @@ -59,6 +60,9 @@ public abstract partial class SelectionHandler<T> : CompositeDrawable, IKeyBindi

public SelectionScaleHandler ScaleHandler { get; private set; }

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

protected SelectionHandler()
{
selectedBlueprints = new List<SelectionBlueprint<T>>();
Expand Down Expand Up @@ -230,7 +234,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();
}
Comment on lines +235 to +239
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One situation I'm not sure about is that pasting doesn't close the menu even though it selects the newly-pasted hitobjects.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One situation I'm not sure about is that pasting doesn't close the menu even though it selects the newly-pasted hitobjects.

close the menu whatever the selected object changed

        internal virtual void HandleSelected(SelectionBlueprint<T> blueprint)
        {
            // there are potentially multiple SelectionHandlers active, but we only want to add items to the selected list once.
            if (!SelectedItems.Contains(blueprint.Item))
                SelectedItems.Add(blueprint.Item);

            selectedBlueprints.Add(blueprint);

+            ContextMenuContainer?.CloseMenu();
        }


/// <summary>
/// Handle a blueprint becoming selected.
Expand Down
Loading
Loading