Merge pull request #12763 from peppy/skin-editor-default-placement-location

Give newly added skin components a centered location to make them easier to find
This commit is contained in:
Dan Balasescu 2021-05-13 21:42:02 +09:00 committed by GitHub
commit c519e4f558
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions

View File

@ -165,10 +165,22 @@ namespace osu.Game.Skinning.Editor
private void placeComponent(Type type)
{
var targetContainer = getTarget(SkinnableTarget.MainHUDComponents);
if (targetContainer == null)
return;
if (!(Activator.CreateInstance(type) is ISkinnableDrawable component))
throw new InvalidOperationException($"Attempted to instantiate a component for placement which was not an {typeof(ISkinnableDrawable)}.");
getTarget(SkinnableTarget.MainHUDComponents)?.Add(component);
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;
targetContainer.Add(component);
SelectedComponents.Clear();
SelectedComponents.Add(component);

View File

@ -13,7 +13,7 @@ namespace osu.Game.Skinning
/// <summary>
/// Denotes a container which can house <see cref="ISkinnableDrawable"/>s.
/// </summary>
public interface ISkinnableTarget
public interface ISkinnableTarget : IDrawable
{
/// <summary>
/// The definition of this target.