2021-05-06 14:16:16 +08:00
|
|
|
// 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 System;
|
2021-05-10 21:33:45 +08:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Linq;
|
2021-05-13 11:57:28 +08:00
|
|
|
using Newtonsoft.Json;
|
2021-05-06 14:16:16 +08:00
|
|
|
using osu.Framework.Graphics;
|
2021-05-10 21:33:45 +08:00
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-05-07 18:13:38 +08:00
|
|
|
using osu.Game.Extensions;
|
2021-05-10 14:31:14 +08:00
|
|
|
using osu.Game.IO.Serialization;
|
2021-05-07 18:13:38 +08:00
|
|
|
using osu.Game.Skinning;
|
2021-05-06 14:16:16 +08:00
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Screens.Play.HUD
|
|
|
|
{
|
|
|
|
/// <summary>
|
2021-05-13 16:06:00 +08:00
|
|
|
/// Serialised information governing custom changes to an <see cref="ISkinnableDrawable"/>.
|
2021-05-06 14:16:16 +08:00
|
|
|
/// </summary>
|
2021-05-07 18:13:38 +08:00
|
|
|
[Serializable]
|
2021-05-10 14:31:14 +08:00
|
|
|
public class SkinnableInfo : IJsonSerializable
|
2021-05-06 14:16:16 +08:00
|
|
|
{
|
2021-05-10 21:33:45 +08:00
|
|
|
public Type Type { get; set; }
|
|
|
|
|
|
|
|
public Vector2 Position { get; set; }
|
|
|
|
|
|
|
|
public float Rotation { get; set; }
|
|
|
|
|
|
|
|
public Vector2 Scale { get; set; }
|
|
|
|
|
|
|
|
public Anchor Anchor { get; set; }
|
|
|
|
|
2021-05-11 12:39:32 +08:00
|
|
|
public Anchor Origin { get; set; }
|
|
|
|
|
2021-06-08 20:22:35 +08:00
|
|
|
/// <inheritdoc cref="ISkinnableDrawable.UsesFixedAnchor"/>
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
2021-06-06 19:18:08 +08:00
|
|
|
|
2021-05-10 21:33:45 +08:00
|
|
|
public List<SkinnableInfo> Children { get; } = new List<SkinnableInfo>();
|
|
|
|
|
2021-05-13 11:57:28 +08:00
|
|
|
[JsonConstructor]
|
2021-05-07 18:13:38 +08:00
|
|
|
public SkinnableInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-05-13 11:57:28 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Construct a new instance populating all attributes from the provided drawable.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="component">The drawable which attributes should be sourced from.</param>
|
2021-05-07 18:13:38 +08:00
|
|
|
public SkinnableInfo(Drawable component)
|
2021-05-06 14:16:16 +08:00
|
|
|
{
|
|
|
|
Type = component.GetType();
|
|
|
|
|
|
|
|
Position = component.Position;
|
|
|
|
Rotation = component.Rotation;
|
|
|
|
Scale = component.Scale;
|
|
|
|
Anchor = component.Anchor;
|
2021-05-11 12:39:32 +08:00
|
|
|
Origin = component.Origin;
|
2021-06-07 12:04:53 +08:00
|
|
|
|
2021-06-07 13:08:39 +08:00
|
|
|
if (component is ISkinnableDrawable skinnable)
|
2021-06-08 20:22:35 +08:00
|
|
|
UsesFixedAnchor = skinnable.UsesFixedAnchor;
|
2021-05-06 14:16:16 +08:00
|
|
|
|
2021-05-13 11:57:28 +08:00
|
|
|
if (component is Container<Drawable> container)
|
2021-05-10 21:33:45 +08:00
|
|
|
{
|
2021-05-13 16:06:00 +08:00
|
|
|
foreach (var child in container.OfType<ISkinnableDrawable>().OfType<Drawable>())
|
2021-05-13 12:14:49 +08:00
|
|
|
Children.Add(child.CreateSkinnableInfo());
|
2021-05-10 21:33:45 +08:00
|
|
|
}
|
|
|
|
}
|
2021-05-07 18:13:38 +08:00
|
|
|
|
2021-05-13 11:57:28 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Construct an instance of the drawable with all attributes applied.
|
|
|
|
/// </summary>
|
|
|
|
/// <returns>The new instance.</returns>
|
2021-05-10 14:31:14 +08:00
|
|
|
public Drawable CreateInstance()
|
2021-05-07 18:13:38 +08:00
|
|
|
{
|
2021-05-10 14:31:14 +08:00
|
|
|
Drawable d = (Drawable)Activator.CreateInstance(Type);
|
2021-05-13 12:14:49 +08:00
|
|
|
d.ApplySkinnableInfo(this);
|
2021-05-07 18:13:38 +08:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
}
|
2021-05-06 14:16:16 +08:00
|
|
|
}
|