mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 23:24:04 +09:00
Merge remote-tracking branch 'origin/master' into background-beat
This commit is contained in:
@ -61,7 +61,7 @@ namespace osu.Game.Rulesets.Judgements
|
||||
Anchor = Anchor.Centre,
|
||||
Origin = Anchor.Centre,
|
||||
RelativeSizeAxes = Axes.Both,
|
||||
Child = new SkinnableDrawable($"Play/{Result.Type}", _ => JudgementText = new OsuSpriteText
|
||||
Child = new SkinnableDrawable(new PlaySkinComponent<HitResult>(Result.Type), _ => JudgementText = new OsuSpriteText
|
||||
{
|
||||
Text = Result.Type.GetDescription().ToUpperInvariant(),
|
||||
Font = OsuFont.Numeric.With(size: 12),
|
||||
|
@ -17,7 +17,7 @@ namespace osu.Game.Skinning
|
||||
private readonly Bindable<bool> beatmapHitsounds = new Bindable<bool>();
|
||||
|
||||
protected override bool AllowConfigurationLookup => beatmapSkins.Value;
|
||||
protected override bool AllowDrawableLookup(string componentName) => beatmapSkins.Value;
|
||||
protected override bool AllowDrawableLookup(ISkinComponent component) => beatmapSkins.Value;
|
||||
protected override bool AllowTextureLookup(string componentName) => beatmapSkins.Value;
|
||||
protected override bool AllowSampleLookup(ISampleInfo componentName) => beatmapHitsounds.Value;
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// 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 osu.Framework.Audio.Sample;
|
||||
@ -16,7 +16,7 @@ namespace osu.Game.Skinning
|
||||
Configuration = new DefaultSkinConfiguration();
|
||||
}
|
||||
|
||||
public override Drawable GetDrawableComponent(string componentName) => null;
|
||||
public override Drawable GetDrawableComponent(ISkinComponent component) => null;
|
||||
|
||||
public override Texture GetTexture(string componentName) => null;
|
||||
|
||||
|
@ -14,7 +14,7 @@ namespace osu.Game.Skinning
|
||||
/// </summary>
|
||||
public interface ISkin
|
||||
{
|
||||
Drawable GetDrawableComponent(string componentName);
|
||||
Drawable GetDrawableComponent(ISkinComponent component);
|
||||
|
||||
Texture GetTexture(string componentName);
|
||||
|
||||
|
10
osu.Game/Skinning/ISkinComponent.cs
Normal file
10
osu.Game/Skinning/ISkinComponent.cs
Normal file
@ -0,0 +1,10 @@
|
||||
// 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.
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public interface ISkinComponent
|
||||
{
|
||||
string LookupName { get; }
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@ using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Textures;
|
||||
using osu.Framework.IO.Stores;
|
||||
using osu.Game.Audio;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
@ -47,39 +48,30 @@ namespace osu.Game.Skinning
|
||||
Samples?.Dispose();
|
||||
}
|
||||
|
||||
public override Drawable GetDrawableComponent(string componentName)
|
||||
public override Drawable GetDrawableComponent(ISkinComponent component)
|
||||
{
|
||||
bool animatable = false;
|
||||
bool looping = true;
|
||||
|
||||
switch (componentName)
|
||||
switch (component)
|
||||
{
|
||||
case "Play/Miss":
|
||||
componentName = "hit0";
|
||||
animatable = true;
|
||||
looping = false;
|
||||
break;
|
||||
case PlaySkinComponent<HitResult> resultComponent:
|
||||
switch (resultComponent.Component)
|
||||
{
|
||||
case HitResult.Miss:
|
||||
return this.GetAnimation("hit0", true, false);
|
||||
|
||||
case "Play/Meh":
|
||||
componentName = "hit50";
|
||||
animatable = true;
|
||||
looping = false;
|
||||
break;
|
||||
case HitResult.Meh:
|
||||
return this.GetAnimation("hit50", true, false);
|
||||
|
||||
case "Play/Good":
|
||||
componentName = "hit100";
|
||||
animatable = true;
|
||||
looping = false;
|
||||
break;
|
||||
case HitResult.Good:
|
||||
return this.GetAnimation("hit100", true, false);
|
||||
|
||||
case HitResult.Great:
|
||||
return this.GetAnimation("hit300", true, false);
|
||||
}
|
||||
|
||||
case "Play/Great":
|
||||
componentName = "hit300";
|
||||
animatable = true;
|
||||
looping = false;
|
||||
break;
|
||||
}
|
||||
|
||||
return this.GetAnimation(componentName, animatable, looping);
|
||||
return this.GetAnimation(component.LookupName, false, false);
|
||||
}
|
||||
|
||||
public override Texture GetTexture(string componentName)
|
||||
|
23
osu.Game/Skinning/PlaySkinComponent.cs
Normal file
23
osu.Game/Skinning/PlaySkinComponent.cs
Normal file
@ -0,0 +1,23 @@
|
||||
// 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.Linq;
|
||||
|
||||
namespace osu.Game.Skinning
|
||||
{
|
||||
public class PlaySkinComponent<T> : ISkinComponent where T : struct
|
||||
{
|
||||
public readonly T Component;
|
||||
|
||||
public PlaySkinComponent(T component)
|
||||
{
|
||||
Component = component;
|
||||
}
|
||||
|
||||
protected virtual string RulesetPrefix => string.Empty;
|
||||
protected virtual string ComponentName => Component.ToString();
|
||||
|
||||
public string LookupName =>
|
||||
string.Join("/", new[] { "Play", RulesetPrefix, ComponentName }.Where(s => !string.IsNullOrEmpty(s)));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// 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;
|
||||
@ -15,7 +15,7 @@ namespace osu.Game.Skinning
|
||||
|
||||
public virtual SkinConfiguration Configuration { get; protected set; }
|
||||
|
||||
public abstract Drawable GetDrawableComponent(string componentName);
|
||||
public abstract Drawable GetDrawableComponent(ISkinComponent componentName);
|
||||
|
||||
public abstract SampleChannel GetSample(ISampleInfo sampleInfo);
|
||||
|
||||
|
@ -1,4 +1,4 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// 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;
|
||||
@ -125,7 +125,7 @@ namespace osu.Game.Skinning
|
||||
|
||||
public event Action SourceChanged;
|
||||
|
||||
public Drawable GetDrawableComponent(string componentName) => CurrentSkin.Value.GetDrawableComponent(componentName);
|
||||
public Drawable GetDrawableComponent(ISkinComponent component) => CurrentSkin.Value.GetDrawableComponent(component);
|
||||
|
||||
public Texture GetTexture(string componentName) => CurrentSkin.Value.GetTexture(componentName);
|
||||
|
||||
|
@ -22,7 +22,7 @@ namespace osu.Game.Skinning
|
||||
|
||||
private ISkinSource fallbackSource;
|
||||
|
||||
protected virtual bool AllowDrawableLookup(string componentName) => true;
|
||||
protected virtual bool AllowDrawableLookup(ISkinComponent component) => true;
|
||||
|
||||
protected virtual bool AllowTextureLookup(string componentName) => true;
|
||||
|
||||
@ -37,13 +37,13 @@ namespace osu.Game.Skinning
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
public Drawable GetDrawableComponent(string componentName)
|
||||
public Drawable GetDrawableComponent(ISkinComponent component)
|
||||
{
|
||||
Drawable sourceDrawable;
|
||||
if (AllowDrawableLookup(componentName) && (sourceDrawable = skin?.GetDrawableComponent(componentName)) != null)
|
||||
if (AllowDrawableLookup(component) && (sourceDrawable = skin?.GetDrawableComponent(component)) != null)
|
||||
return sourceDrawable;
|
||||
|
||||
return fallbackSource?.GetDrawableComponent(componentName);
|
||||
return fallbackSource?.GetDrawableComponent(component);
|
||||
}
|
||||
|
||||
public Texture GetTexture(string componentName)
|
||||
|
@ -18,39 +18,39 @@ namespace osu.Game.Skinning
|
||||
/// </summary>
|
||||
public Drawable Drawable { get; private set; }
|
||||
|
||||
private readonly string componentName;
|
||||
private readonly ISkinComponent component;
|
||||
|
||||
private readonly ConfineMode confineMode;
|
||||
|
||||
/// <summary>
|
||||
/// Create a new skinnable drawable.
|
||||
/// </summary>
|
||||
/// <param name="name">The namespace-complete resource name for this skinnable element.</param>
|
||||
/// <param name="component">The namespace-complete resource name for this skinnable element.</param>
|
||||
/// <param name="defaultImplementation">A function to create the default skin implementation of this element.</param>
|
||||
/// <param name="allowFallback">A conditional to decide whether to allow fallback to the default implementation if a skinned element is not present.</param>
|
||||
/// <param name="confineMode">How (if at all) the <see cref="Drawable"/> should be resize to fit within our own bounds.</param>
|
||||
public SkinnableDrawable(string name, Func<string, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: this(name, allowFallback, confineMode)
|
||||
public SkinnableDrawable(ISkinComponent component, Func<ISkinComponent, Drawable> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: this(component, allowFallback, confineMode)
|
||||
{
|
||||
createDefault = defaultImplementation;
|
||||
}
|
||||
|
||||
protected SkinnableDrawable(string name, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
protected SkinnableDrawable(ISkinComponent component, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: base(allowFallback)
|
||||
{
|
||||
componentName = name;
|
||||
this.component = component;
|
||||
this.confineMode = confineMode;
|
||||
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
}
|
||||
|
||||
private readonly Func<string, Drawable> createDefault;
|
||||
private readonly Func<ISkinComponent, Drawable> createDefault;
|
||||
|
||||
private readonly Cached scaling = new Cached();
|
||||
|
||||
private bool isDefault;
|
||||
|
||||
protected virtual Drawable CreateDefault(string name) => createDefault(name);
|
||||
protected virtual Drawable CreateDefault(ISkinComponent component) => createDefault(component);
|
||||
|
||||
/// <summary>
|
||||
/// Whether to apply size restrictions (specified via <see cref="confineMode"/>) to the default implementation.
|
||||
@ -59,13 +59,13 @@ namespace osu.Game.Skinning
|
||||
|
||||
protected override void SkinChanged(ISkinSource skin, bool allowFallback)
|
||||
{
|
||||
Drawable = skin.GetDrawableComponent(componentName);
|
||||
Drawable = skin.GetDrawableComponent(component);
|
||||
|
||||
isDefault = false;
|
||||
|
||||
if (Drawable == null && allowFallback)
|
||||
{
|
||||
Drawable = CreateDefault(componentName);
|
||||
Drawable = CreateDefault(component);
|
||||
isDefault = true;
|
||||
}
|
||||
|
||||
|
@ -19,11 +19,11 @@ namespace osu.Game.Skinning
|
||||
[Resolved]
|
||||
private TextureStore textures { get; set; }
|
||||
|
||||
public SkinnableSprite(string name, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: base(name, allowFallback, confineMode)
|
||||
public SkinnableSprite(ISkinComponent component, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: base(component, allowFallback, confineMode)
|
||||
{
|
||||
}
|
||||
|
||||
protected override Drawable CreateDefault(string name) => new Sprite { Texture = textures.Get(name) };
|
||||
protected override Drawable CreateDefault(ISkinComponent component) => new Sprite { Texture = textures.Get(component.LookupName) };
|
||||
}
|
||||
}
|
||||
|
@ -8,8 +8,8 @@ namespace osu.Game.Skinning
|
||||
{
|
||||
public class SkinnableSpriteText : SkinnableDrawable, IHasText
|
||||
{
|
||||
public SkinnableSpriteText(string name, Func<string, SpriteText> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: base(name, defaultImplementation, allowFallback, confineMode)
|
||||
public SkinnableSpriteText(ISkinComponent component, Func<ISkinComponent, SpriteText> defaultImplementation, Func<ISkinSource, bool> allowFallback = null, ConfineMode confineMode = ConfineMode.ScaleDownToFit)
|
||||
: base(component, defaultImplementation, allowFallback, confineMode)
|
||||
{
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user