1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 03:02:54 +08:00

Refactor the code to follow IoC principle and more flexible

This commit is contained in:
jkh675 2024-08-04 19:39:06 +08:00
parent 27d6c4cecb
commit 3cc5466774
4 changed files with 196 additions and 190 deletions

View File

@ -23,7 +23,6 @@ using osu.Framework.Testing;
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;
@ -101,6 +100,12 @@ namespace osu.Game.Overlays.SkinEditor
[Resolved]
private IDialogOverlay? dialogOverlay { get; set; }
[Cached]
public EditorContextMenuContainer ContextMenuContainer { get; private set; } = new EditorContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
};
public SkinEditor()
{
}
@ -115,10 +120,7 @@ namespace osu.Game.Overlays.SkinEditor
{
RelativeSizeAxes = Axes.Both;
InternalChild = new EditorContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Child = new GridContainer
ContextMenuContainer.Child = new GridContainer
{
RelativeSizeAxes = Axes.Both,
RowDimensions = new[]
@ -127,7 +129,6 @@ namespace osu.Game.Overlays.SkinEditor
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
},
Content = new[]
{
new Drawable[]
@ -220,9 +221,10 @@ namespace osu.Game.Overlays.SkinEditor
}
},
}
}
};
AddInternal(ContextMenuContainer);
clipboardContent = clipboard.Content.GetBoundCopy();
}

View File

@ -1,15 +1,12 @@
// 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.
using osu.Framework.Input;
using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events;
using osu.Game.Graphics.Cursor;
using osu.Game.Graphics.UserInterface;
namespace osu.Game.Screens.Edit.Components
{
public partial class EditorContextMenuContainer : OsuContextMenuContainer, IKeyBindingHandler<PlatformAction>
public partial class EditorContextMenuContainer : OsuContextMenuContainer
{
public override bool ChangeFocusOnClick => true;
@ -17,20 +14,14 @@ namespace osu.Game.Screens.Edit.Components
protected override Framework.Graphics.UserInterface.Menu CreateMenu() => menu = new OsuContextMenu(true);
public bool OnPressed(KeyBindingPressEvent<PlatformAction> e)
public void ShowMenu()
{
switch (e.Action)
menu.Show();
}
public void CloseMenu()
{
case PlatformAction.Delete:
menu.Close();
break;
}
return false;
}
public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
{
}
}
}

View File

@ -20,6 +20,7 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Input.Bindings;
using osu.Game.Resources.Localisation.Web;
using osu.Game.Rulesets.Edit;
using osu.Game.Screens.Edit.Components;
using osu.Game.Screens.Edit.Compose.Components.Timeline;
using osuTK;
using osuTK.Input;
@ -59,6 +60,9 @@ namespace osu.Game.Screens.Edit.Compose.Components
public SelectionScaleHandler ScaleHandler { get; private set; }
[Resolved]
private EditorContextMenuContainer editorContextMenuContainer { get; set; }
protected SelectionHandler()
{
selectedBlueprints = new List<SelectionBlueprint<T>>();
@ -230,7 +234,11 @@ namespace osu.Game.Screens.Edit.Compose.Components
/// <summary>
/// Deselect all selected items.
/// </summary>
protected void DeselectAll() => SelectedItems.Clear();
protected void DeselectAll()
{
SelectedItems.Clear();
editorContextMenuContainer.CloseMenu();
}
/// <summary>
/// Handle a blueprint becoming selected.

View File

@ -77,6 +77,12 @@ namespace osu.Game.Screens.Edit
/// </remarks>
public const float WAVEFORM_VISUAL_OFFSET = 20;
[Cached]
public EditorContextMenuContainer ContextMenuContainer { get; private set; } = new EditorContextMenuContainer()
{
RelativeSizeAxes = Axes.Both
};
public override float BackgroundParallaxAmount => 0.1f;
public override bool AllowBackButton => false;
@ -320,10 +326,7 @@ namespace osu.Game.Screens.Edit
editorTimelineShowTimingChanges = config.GetBindable<bool>(OsuSetting.EditorTimelineShowTimingChanges);
editorTimelineShowTicks = config.GetBindable<bool>(OsuSetting.EditorTimelineShowTicks);
AddInternal(new EditorContextMenuContainer
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
ContextMenuContainer.AddRange(new Drawable[]
{
new Container
{
@ -421,8 +424,10 @@ namespace osu.Game.Screens.Edit
},
bottomBar = new BottomBar(),
MutationTracker,
}
});
AddInternal(ContextMenuContainer);
changeHandler?.CanUndo.BindValueChanged(v => undoMenuItem.Action.Disabled = !v.NewValue, true);
changeHandler?.CanRedo.BindValueChanged(v => redoMenuItem.Action.Disabled = !v.NewValue, true);