mirror of
https://github.com/osukey/osukey.git
synced 2025-07-02 00:40:09 +09:00
Hook up a dropdown to show all available sprites for the current skin
This commit is contained in:
@ -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);
|
||||
|
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -351,7 +351,7 @@ namespace osu.Game.Skinning.Editor
|
||||
// place component
|
||||
placeComponent(new SkinSprite
|
||||
{
|
||||
SpriteName = { Value = Path.GetFileNameWithoutExtension(file.Name) }
|
||||
SpriteName = { Value = file.Name }
|
||||
});
|
||||
});
|
||||
|
||||
|
Reference in New Issue
Block a user