1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 22:19:30 +08:00

Add ability to adjust origin in skin editor

This commit is contained in:
Dean Herbert 2021-05-11 14:09:56 +09:00
parent c94df672e5
commit 12684de66e

View File

@ -70,13 +70,18 @@ namespace osu.Game.Skinning.Editor
{ {
yield return new OsuMenuItem("Anchor") yield return new OsuMenuItem("Anchor")
{ {
Items = createAnchorItems().ToArray() Items = createAnchorItems(d => d.Anchor, applyAnchor).ToArray()
};
yield return new OsuMenuItem("Origin")
{
Items = createAnchorItems(d => d.Origin, applyOrigin).ToArray()
}; };
foreach (var item in base.GetContextMenuItemsForSelection(selection)) foreach (var item in base.GetContextMenuItemsForSelection(selection))
yield return item; yield return item;
IEnumerable<AnchorMenuItem> createAnchorItems() IEnumerable<AnchorMenuItem> createAnchorItems(Func<Drawable, Anchor> checkFunction, Action<Anchor> applyFunction)
{ {
var displayableAnchors = new[] var displayableAnchors = new[]
{ {
@ -93,14 +98,20 @@ namespace osu.Game.Skinning.Editor
return displayableAnchors.Select(a => return displayableAnchors.Select(a =>
{ {
return new AnchorMenuItem(a, selection, _ => applyAnchor(a)) return new AnchorMenuItem(a, selection, _ => applyFunction(a))
{ {
State = { Value = GetStateFromSelection(selection, c => ((Drawable)c.Item).Anchor == a) } State = { Value = GetStateFromSelection(selection, c => checkFunction((Drawable)c.Item) == a) }
}; };
}); });
} }
} }
private void applyOrigin(Anchor anchor)
{
foreach (var item in SelectedItems)
((Drawable)item).Origin = anchor;
}
private void applyAnchor(Anchor anchor) private void applyAnchor(Anchor anchor)
{ {
foreach (var item in SelectedItems) foreach (var item in SelectedItems)