Hook up a dropdown to show all available sprites for the current skin

This commit is contained in:
Dean Herbert
2022-03-24 19:32:34 +09:00
parent fca9faac9b
commit 66f5eae530
4 changed files with 26 additions and 2 deletions

View File

@ -88,6 +88,7 @@ namespace osu.Game.Configuration
throw new InvalidOperationException($"{nameof(SettingSourceAttribute)} had an unsupported custom control type ({controlType.ReadableName()})");
var control = (Drawable)Activator.CreateInstance(controlType);
controlType.GetProperty(nameof(SettingsItem<object>.Source))?.SetValue(control, obj);
controlType.GetProperty(nameof(SettingsItem<object>.LabelText))?.SetValue(control, attr.Label);
controlType.GetProperty(nameof(SettingsItem<object>.TooltipText))?.SetValue(control, attr.Description);
controlType.GetProperty(nameof(SettingsItem<object>.Current))?.SetValue(control, value);

View File

@ -11,6 +11,7 @@ using osu.Framework.Graphics.Cursor;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface;
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Graphics.Containers;
@ -24,6 +25,11 @@ namespace osu.Game.Overlays.Settings
protected Drawable Control { get; }
/// <summary>
/// The source component if this <see cref="SettingsItem{T}"/> was created via <see cref="SettingSourceAttribute"/>.
/// </summary>
public Drawable Source { get; internal set; }
private IHasCurrentValue<T> controlWithCurrent => Control as IHasCurrentValue<T>;
protected override Container<Drawable> Content => FlowContent;

View File

@ -1,6 +1,8 @@
// 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.Collections.Generic;
using System.Linq;
using JetBrains.Annotations;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
@ -8,6 +10,7 @@ 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
{
@ -19,12 +22,14 @@ namespace osu.Game.Skinning.Components
{
public bool UsesFixedAnchor { get; set; }
[SettingSource("Sprite name", "The filename of the sprite")]
[SettingSource("Sprite name", "The filename of the sprite", SettingControlType = typeof(SpriteSelectorControl))]
public Bindable<string> SpriteName { get; } = new Bindable<string>(string.Empty);
[Resolved]
private ISkinSource source { get; set; }
public IEnumerable<string> AvailableFiles => (source.AllSources.First() as Skin)?.SkinInfo.PerformRead(s => s.Files.Select(f => f.Filename));
public SkinSprite()
{
AutoSizeAxes = Axes.Both;
@ -45,5 +50,17 @@ namespace osu.Game.Skinning.Components
};
}, true);
}
public class SpriteSelectorControl : SettingsDropdown<string>
{
public SkinSprite Source { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
Items = Source.AvailableFiles;
}
}
}
}

View File

@ -351,7 +351,7 @@ namespace osu.Game.Skinning.Editor
// place component
placeComponent(new SkinSprite
{
SpriteName = { Value = Path.GetFileNameWithoutExtension(file.Name) }
SpriteName = { Value = file.Name }
});
});