1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-14 05:47:20 +08:00

Merge pull request #17597 from peppy/skin-editor-import-at-cursor

Import new skin editor sprites to the cursor location
This commit is contained in:
Dan Balasescu 2022-04-05 18:09:00 +09:00 committed by GitHub
commit 6b0392f990
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 12 deletions

View File

@ -247,7 +247,7 @@ namespace osu.Game.Skinning.Editor
placeComponent(component);
}
private void placeComponent(ISkinnableDrawable component)
private void placeComponent(ISkinnableDrawable component, bool applyDefaults = true)
{
var targetContainer = getFirstTarget();
@ -256,10 +256,13 @@ namespace osu.Game.Skinning.Editor
var drawableComponent = (Drawable)component;
// give newly added components a sane starting location.
drawableComponent.Origin = Anchor.TopCentre;
drawableComponent.Anchor = Anchor.TopCentre;
drawableComponent.Y = targetContainer.DrawSize.Y / 2;
if (applyDefaults)
{
// give newly added components a sane starting location.
drawableComponent.Origin = Anchor.TopCentre;
drawableComponent.Anchor = Anchor.TopCentre;
drawableComponent.Y = targetContainer.DrawSize.Y / 2;
}
targetContainer.Add(component);
@ -351,10 +354,16 @@ namespace osu.Game.Skinning.Editor
realm.Run(r => r.Refresh());
// place component
placeComponent(new SkinnableSprite
var sprite = new SkinnableSprite
{
SpriteName = { Value = file.Name }
});
SpriteName = { Value = file.Name },
Origin = Anchor.Centre,
Position = getFirstTarget().ToLocalSpace(GetContainingInputManager().CurrentState.Mouse.Position),
};
placeComponent(sprite, false);
SkinSelectionHandler.ApplyClosestAnchor(sprite);
});
return Task.CompletedTask;

View File

@ -157,13 +157,13 @@ namespace osu.Game.Skinning.Editor
if (item.UsesFixedAnchor) continue;
applyClosestAnchor(drawable);
ApplyClosestAnchor(drawable);
}
return true;
}
private static void applyClosestAnchor(Drawable drawable) => applyAnchor(drawable, getClosestAnchor(drawable));
public static void ApplyClosestAnchor(Drawable drawable) => applyAnchor(drawable, getClosestAnchor(drawable));
protected override void OnSelectionChanged()
{
@ -252,7 +252,7 @@ namespace osu.Game.Skinning.Editor
if (item.UsesFixedAnchor) continue;
applyClosestAnchor(drawable);
ApplyClosestAnchor(drawable);
}
}
@ -279,7 +279,7 @@ namespace osu.Game.Skinning.Editor
foreach (var item in SelectedItems)
{
item.UsesFixedAnchor = false;
applyClosestAnchor((Drawable)item);
ApplyClosestAnchor((Drawable)item);
}
}