1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-13 19:27:31 +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,114 +120,111 @@ namespace osu.Game.Overlays.SkinEditor
{
RelativeSizeAxes = Axes.Both;
InternalChild = new EditorContextMenuContainer
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 Drawable[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
},
Content = new[]
{
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)
{
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,
},
},
},
},
new Drawable[]
{
new SkinEditorSceneLibrary
{
RelativeSizeAxes = Axes.X,
},
},
new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new Drawable[]
{
componentsSidebar = new EditorSidebar(),
content = new Container
{
Depth = float.MaxValue,
RelativeSizeAxes = Axes.Both,
},
settingsSidebar = new EditorSidebar(),
new MenuItem(CommonStrings.MenuBarEdit)
{
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,
},
},
},
},
new Drawable[]
{
new SkinEditorSceneLibrary
{
RelativeSizeAxes = Axes.X,
},
},
new Drawable[]
{
new GridContainer
{
RelativeSizeAxes = Axes.Both,
ColumnDimensions = new[]
{
new Dimension(GridSizeMode.AutoSize),
new Dimension(),
new Dimension(GridSizeMode.AutoSize),
},
Content = new[]
{
new Drawable[]
{
componentsSidebar = new EditorSidebar(),
content = new Container
{
Depth = float.MaxValue,
RelativeSizeAxes = Axes.Both,
},
settingsSidebar = new EditorSidebar(),
}
}
},
}
}
},
}
};
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)
{
case PlatformAction.Delete:
menu.Close();
break;
}
return false;
menu.Show();
}
public void OnReleased(KeyBindingReleaseEvent<PlatformAction> e)
public void CloseMenu()
{
menu.Close();
}
}
}

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,109 +326,108 @@ namespace osu.Game.Screens.Edit
editorTimelineShowTimingChanges = config.GetBindable<bool>(OsuSetting.EditorTimelineShowTimingChanges);
editorTimelineShowTicks = config.GetBindable<bool>(OsuSetting.EditorTimelineShowTicks);
AddInternal(new EditorContextMenuContainer
ContextMenuContainer.AddRange(new Drawable[]
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
new Container
{
new Container
Name = "Screen container",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 40, Bottom = 50 },
Child = screenContainer = new Container<EditorScreen>
{
Name = "Screen container",
RelativeSizeAxes = Axes.Both,
Padding = new MarginPadding { Top = 40, Bottom = 50 },
Child = screenContainer = new Container<EditorScreen>
{
RelativeSizeAxes = Axes.Both,
}
},
new Container
}
},
new Container
{
Name = "Top bar",
RelativeSizeAxes = Axes.X,
Height = 40,
Children = new Drawable[]
{
Name = "Top bar",
RelativeSizeAxes = Axes.X,
Height = 40,
Children = new Drawable[]
new EditorMenuBar
{
new EditorMenuBar
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
MaxHeight = 600,
Items = new[]
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Both,
MaxHeight = 600,
Items = new[]
new MenuItem(CommonStrings.MenuBarFile)
{
new MenuItem(CommonStrings.MenuBarFile)
Items = createFileMenuItems().ToList()
},
new MenuItem(CommonStrings.MenuBarEdit)
{
Items = new[]
{
Items = createFileMenuItems().ToList()
},
new MenuItem(CommonStrings.MenuBarEdit)
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),
}
},
new MenuItem(CommonStrings.MenuBarView)
{
Items = new[]
{
Items = new[]
new MenuItem(EditorStrings.Timeline)
{
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),
}
},
new MenuItem(CommonStrings.MenuBarView)
{
Items = new[]
Items =
[
new WaveformOpacityMenuItem(config.GetBindable<float>(OsuSetting.EditorWaveformOpacity)),
new ToggleMenuItem(EditorStrings.TimelineShowTimingChanges)
{
State = { BindTarget = editorTimelineShowTimingChanges }
},
new ToggleMenuItem(EditorStrings.TimelineShowTicks)
{
State = { BindTarget = editorTimelineShowTicks }
},
]
},
new BackgroundDimMenuItem(editorBackgroundDim),
new ToggleMenuItem(EditorStrings.ShowHitMarkers)
{
new MenuItem(EditorStrings.Timeline)
{
Items =
[
new WaveformOpacityMenuItem(config.GetBindable<float>(OsuSetting.EditorWaveformOpacity)),
new ToggleMenuItem(EditorStrings.TimelineShowTimingChanges)
{
State = { BindTarget = editorTimelineShowTimingChanges }
},
new ToggleMenuItem(EditorStrings.TimelineShowTicks)
{
State = { BindTarget = editorTimelineShowTicks }
},
]
},
new BackgroundDimMenuItem(editorBackgroundDim),
new ToggleMenuItem(EditorStrings.ShowHitMarkers)
{
State = { BindTarget = editorHitMarkers },
},
new ToggleMenuItem(EditorStrings.AutoSeekOnPlacement)
{
State = { BindTarget = editorAutoSeekOnPlacement },
},
new ToggleMenuItem(EditorStrings.LimitedDistanceSnap)
{
State = { BindTarget = editorLimitedDistanceSnap },
}
}
},
new MenuItem(EditorStrings.Timing)
{
Items = new MenuItem[]
State = { BindTarget = editorHitMarkers },
},
new ToggleMenuItem(EditorStrings.AutoSeekOnPlacement)
{
new EditorMenuItem(EditorStrings.SetPreviewPointToCurrent, MenuItemType.Standard, SetPreviewPointToCurrentTime)
State = { BindTarget = editorAutoSeekOnPlacement },
},
new ToggleMenuItem(EditorStrings.LimitedDistanceSnap)
{
State = { BindTarget = editorLimitedDistanceSnap },
}
}
},
new MenuItem(EditorStrings.Timing)
{
Items = new MenuItem[]
{
new EditorMenuItem(EditorStrings.SetPreviewPointToCurrent, MenuItemType.Standard, SetPreviewPointToCurrentTime)
}
}
},
screenSwitcher = new EditorScreenSwitcherControl
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
X = -10,
Current = Mode,
},
}
},
screenSwitcher = new EditorScreenSwitcherControl
{
Anchor = Anchor.BottomRight,
Origin = Anchor.BottomRight,
X = -10,
Current = Mode,
},
},
bottomBar = new BottomBar(),
MutationTracker,
}
},
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);