// Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. using System.Collections.Generic; using System.Linq; using JetBrains.Annotations; using osu.Framework.Allocation; using osu.Framework.Bindables; using osu.Framework.Graphics; using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Sprites; using osu.Game.Configuration; using osu.Game.Overlays.Settings; namespace osu.Game.Skinning.Components { /// /// Intended to be a test bed for skinning. May be removed at some point in the future. /// [UsedImplicitly] public class SkinSprite : CompositeDrawable, ISkinnableDrawable { public bool UsesFixedAnchor { get; set; } [SettingSource("Sprite name", "The filename of the sprite", SettingControlType = typeof(SpriteSelectorControl))] public Bindable SpriteName { get; } = new Bindable(string.Empty); [Resolved] private ISkinSource source { get; set; } public IEnumerable AvailableFiles => (source.AllSources.First() as Skin)?.SkinInfo.PerformRead(s => s.Files.Select(f => f.Filename)); public SkinSprite() { AutoSizeAxes = Axes.Both; } protected override void LoadComplete() { base.LoadComplete(); SpriteName.BindValueChanged(spriteName => { InternalChildren = new Drawable[] { new Sprite { Texture = source.GetTexture(SpriteName.Value), } }; }, true); } public class SpriteSelectorControl : SettingsDropdown { public SkinSprite Source { get; set; } protected override void LoadComplete() { base.LoadComplete(); Items = Source.AvailableFiles; } } } }