1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-11 11:37:28 +08:00

Combine SkinSprite into SkinnableSprite

This commit is contained in:
Dean Herbert 2022-03-25 17:31:03 +09:00
parent 762de3cc97
commit d1be229d74
6 changed files with 55 additions and 77 deletions

View File

@ -1,66 +0,0 @@
// 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;
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
{
/// <summary>
/// Intended to be a test bed for skinning. May be removed at some point in the future.
/// </summary>
[UsedImplicitly]
public class SkinSprite : CompositeDrawable, ISkinnableDrawable
{
public bool UsesFixedAnchor { get; set; }
[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;
}
protected override void LoadComplete()
{
base.LoadComplete();
SpriteName.BindValueChanged(spriteName =>
{
InternalChildren = new Drawable[]
{
new Sprite
{
Texture = source.GetTexture(SpriteName.Value),
}
};
}, true);
}
public class SpriteSelectorControl : SettingsDropdown<string>
{
public SkinSprite Source { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
Items = Source.AvailableFiles;
}
}
}
}

View File

@ -8,6 +8,7 @@ using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.OpenGL.Textures;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Audio;
using osu.Game.Beatmaps.Formats;
@ -157,6 +158,9 @@ namespace osu.Game.Skinning
break;
}
if (GetTexture(component.LookupName) is Texture t)
return new Sprite { Texture = t };
return null;
}

View File

@ -21,7 +21,6 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Overlays;
using osu.Game.Screens.Edit.Components;
using osu.Game.Screens.Edit.Components.Menus;
using osu.Game.Skinning.Components;
namespace osu.Game.Skinning.Editor
{
@ -349,9 +348,9 @@ namespace osu.Game.Skinning.Editor
});
// place component
placeComponent(new SkinSprite
placeComponent(new SkinnableSprite
{
SpriteName = { Value = file.Name }
SpriteName = { Value = Path.GetFileNameWithoutExtension(file.Name) }
});
});

View File

@ -54,7 +54,7 @@ namespace osu.Game.Skinning
where TLookup : notnull
where TValue : notnull;
private readonly RealmBackedResourceStore<SkinInfo> realmBackedStorage;
private readonly RealmBackedResourceStore<SkinInfo>? realmBackedStorage;
/// <summary>
/// Construct a new skin.

View File

@ -31,7 +31,7 @@ namespace osu.Game.Skinning
set => base.AutoSizeAxes = value;
}
private readonly ISkinComponent component;
protected readonly ISkinComponent Component;
private readonly ConfineMode confineMode;
@ -49,7 +49,7 @@ namespace osu.Game.Skinning
protected SkinnableDrawable(ISkinComponent component, ConfineMode confineMode = ConfineMode.NoScaling)
{
this.component = component;
Component = component;
this.confineMode = confineMode;
RelativeSizeAxes = Axes.Both;
@ -75,13 +75,13 @@ namespace osu.Game.Skinning
protected override void SkinChanged(ISkinSource skin)
{
Drawable = skin.GetDrawableComponent(component);
Drawable = skin.GetDrawableComponent(Component);
isDefault = false;
if (Drawable == null)
{
Drawable = CreateDefault(component);
Drawable = CreateDefault(Component);
isDefault = true;
}

View File

@ -1,10 +1,16 @@
// 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.IO;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Textures;
using osu.Game.Configuration;
using osu.Game.Overlays.Settings;
namespace osu.Game.Skinning
{
@ -18,9 +24,32 @@ namespace osu.Game.Skinning
[Resolved]
private TextureStore textures { get; set; }
[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 => Path.GetFileNameWithoutExtension(f.Filename)).Distinct());
public SkinnableSprite(string textureName, ConfineMode confineMode = ConfineMode.NoScaling)
: base(new SpriteComponent(textureName), confineMode)
{
SpriteName.Value = textureName;
}
public SkinnableSprite()
: base(new SpriteComponent(string.Empty), ConfineMode.NoScaling)
{
RelativeSizeAxes = Axes.None;
AutoSizeAxes = Axes.Both;
SpriteName.BindValueChanged(name =>
{
((SpriteComponent)Component).LookupName = name.NewValue ?? string.Empty;
if (IsLoaded)
SkinChanged(CurrentSkin);
});
}
protected override Drawable CreateDefault(ISkinComponent component)
@ -33,16 +62,28 @@ namespace osu.Game.Skinning
return new Sprite { Texture = texture };
}
public bool UsesFixedAnchor { get; set; }
private class SpriteComponent : ISkinComponent
{
public string LookupName { get; set; }
public SpriteComponent(string textureName)
{
LookupName = textureName;
}
public string LookupName { get; }
}
public bool UsesFixedAnchor { get; set; }
public class SpriteSelectorControl : SettingsDropdown<string>
{
public SkinnableSprite Source { get; set; }
protected override void LoadComplete()
{
base.LoadComplete();
Items = Source.AvailableFiles;
}
}
}
}