2021-04-28 17:34:34 +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.
2022-03-11 22:27:27 +08:00
using System ;
2023-12-13 13:07:38 +08:00
using System.Globalization ;
2022-03-11 22:27:27 +08:00
using osu.Framework.Bindables ;
using osu.Framework.Extensions.TypeExtensions ;
2021-05-13 16:03:17 +08:00
using osu.Framework.Graphics ;
2022-11-09 15:03:29 +08:00
using osu.Game.Configuration ;
2021-05-13 16:03:17 +08:00
2021-04-30 11:42:32 +08:00
namespace osu.Game.Skinning
2021-04-28 17:34:34 +08:00
{
/// <summary>
2023-02-16 14:31:35 +08:00
/// A drawable which is intended to be serialised to <see cref="SerialisedDrawableInfo"/>.
2021-04-28 17:34:34 +08:00
/// </summary>
2022-11-09 15:03:29 +08:00
/// <remarks>
2023-02-16 14:31:35 +08:00
/// This is currently used exclusively for serialisation to a skin, and leaned on heavily to allow placement and customisation in the skin layout editor.
/// That said, it is intended to be flexible enough to potentially be used in other places we want to serialise drawables in the future.
2023-02-15 14:47:41 +08:00
///
2023-02-16 14:31:35 +08:00
/// Attaching this interface to any <see cref="IDrawable"/> will make it serialisable via <see cref="SerialisableDrawableExtensions.CreateSerialisedInfo"/>.
/// Adding <see cref="SettingSourceAttribute"/> annotated bindables will also allow serialising settings automatically.
2022-11-09 15:03:29 +08:00
/// </remarks>
2023-02-15 15:01:26 +08:00
public interface ISerialisableDrawable : IDrawable
2021-04-28 17:34:34 +08:00
{
2021-05-13 16:03:17 +08:00
/// <summary>
/// Whether this component should be editable by an end user.
/// </summary>
bool IsEditable = > true ;
2021-06-07 11:47:47 +08:00
/// <summary>
2023-02-15 15:01:26 +08:00
/// In the context of the skin layout editor, whether this <see cref="ISerialisableDrawable"/> has a permanent anchor defined.
/// If <see langword="false"/>, this <see cref="ISerialisableDrawable"/>'s <see cref="Drawable.Anchor"/> is automatically determined by proximity,
2021-06-22 15:40:48 +08:00
/// If <see langword="true"/>, a fixed anchor point has been defined.
2021-06-07 11:47:47 +08:00
/// </summary>
2021-06-08 20:22:35 +08:00
bool UsesFixedAnchor { get ; set ; }
2022-03-11 22:27:27 +08:00
void CopyAdjustedSetting ( IBindable target , object source )
{
if ( source is IBindable sourceBindable )
{
// copy including transfer of default values.
target . BindTo ( sourceBindable ) ;
target . UnbindFrom ( sourceBindable ) ;
}
else
{
if ( ! ( target is IParseable parseable ) )
throw new InvalidOperationException ( $"Bindable type {target.GetType().ReadableName()} is not {nameof(IParseable)}." ) ;
2023-12-13 13:07:38 +08:00
parseable . Parse ( source , CultureInfo . InvariantCulture ) ;
2022-03-11 22:27:27 +08:00
}
}
2021-04-28 17:34:34 +08:00
}
}