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-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>
|
|
|
|
/// Serialised information governing custom changes to an <see cref="ISkinnableComponent"/>.
|
|
|
|
/// </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; }
|
|
|
|
|
|
|
|
public List<SkinnableInfo> Children { get; } = new List<SkinnableInfo>();
|
|
|
|
|
2021-05-07 18:13:38 +08:00
|
|
|
public SkinnableInfo()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
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-10 21:33:45 +08:00
|
|
|
if (component is Container container)
|
|
|
|
{
|
|
|
|
foreach (var child in container.Children.OfType<ISkinnableComponent>().OfType<Drawable>())
|
|
|
|
Children.Add(child.CreateSerialisedInformation());
|
|
|
|
}
|
|
|
|
}
|
2021-05-07 18:13:38 +08:00
|
|
|
|
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);
|
|
|
|
d.ApplySerialisedInformation(this);
|
2021-05-07 18:13:38 +08:00
|
|
|
return d;
|
|
|
|
}
|
|
|
|
}
|
2021-05-06 14:16:16 +08:00
|
|
|
}
|