mirror of
https://github.com/ppy/osu.git
synced 2025-01-27 13:23:05 +08:00
Add base legacy skin transformer
This commit is contained in:
parent
07cbc3e683
commit
ad85c5f538
@ -2,26 +2,21 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using Humanizer;
|
using Humanizer;
|
||||||
using osu.Framework.Audio.Sample;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Game.Audio;
|
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Catch.Skinning
|
namespace osu.Game.Rulesets.Catch.Skinning
|
||||||
{
|
{
|
||||||
public class CatchLegacySkinTransformer : ISkin
|
public class CatchLegacySkinTransformer : LegacySkinTransformer
|
||||||
{
|
{
|
||||||
private readonly ISkin source;
|
public CatchLegacySkinTransformer(ISkinSource source)
|
||||||
|
: base(source)
|
||||||
public CatchLegacySkinTransformer(ISkin source)
|
|
||||||
{
|
{
|
||||||
this.source = source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drawable GetDrawableComponent(ISkinComponent component)
|
public override Drawable GetDrawableComponent(ISkinComponent component)
|
||||||
{
|
{
|
||||||
if (!(component is CatchSkinComponent catchSkinComponent))
|
if (!(component is CatchSkinComponent catchSkinComponent))
|
||||||
return null;
|
return null;
|
||||||
@ -61,19 +56,15 @@ namespace osu.Game.Rulesets.Catch.Skinning
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
||||||
|
|
||||||
public SampleChannel GetSample(ISampleInfo sample) => source.GetSample(sample);
|
|
||||||
|
|
||||||
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
|
||||||
{
|
{
|
||||||
switch (lookup)
|
switch (lookup)
|
||||||
{
|
{
|
||||||
case CatchSkinColour colour:
|
case CatchSkinColour colour:
|
||||||
return source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
|
return Source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
|
||||||
}
|
}
|
||||||
|
|
||||||
return source.GetConfig<TLookup, TValue>(lookup);
|
return Source.GetConfig<TLookup, TValue>(lookup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,11 +3,8 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Framework.Audio.Sample;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Game.Rulesets.Scoring;
|
using osu.Game.Rulesets.Scoring;
|
||||||
using osu.Game.Audio;
|
|
||||||
using osu.Game.Beatmaps;
|
using osu.Game.Beatmaps;
|
||||||
using osu.Game.Rulesets.Mania.Beatmaps;
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
@ -15,9 +12,8 @@ using System.Collections.Generic;
|
|||||||
|
|
||||||
namespace osu.Game.Rulesets.Mania.Skinning
|
namespace osu.Game.Rulesets.Mania.Skinning
|
||||||
{
|
{
|
||||||
public class ManiaLegacySkinTransformer : ISkin
|
public class ManiaLegacySkinTransformer : LegacySkinTransformer
|
||||||
{
|
{
|
||||||
private readonly ISkin source;
|
|
||||||
private readonly ManiaBeatmap beatmap;
|
private readonly ManiaBeatmap beatmap;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -59,23 +55,23 @@ namespace osu.Game.Rulesets.Mania.Skinning
|
|||||||
private Lazy<bool> hasKeyTexture;
|
private Lazy<bool> hasKeyTexture;
|
||||||
|
|
||||||
public ManiaLegacySkinTransformer(ISkinSource source, IBeatmap beatmap)
|
public ManiaLegacySkinTransformer(ISkinSource source, IBeatmap beatmap)
|
||||||
|
: base(source)
|
||||||
{
|
{
|
||||||
this.source = source;
|
|
||||||
this.beatmap = (ManiaBeatmap)beatmap;
|
this.beatmap = (ManiaBeatmap)beatmap;
|
||||||
|
|
||||||
source.SourceChanged += sourceChanged;
|
Source.SourceChanged += sourceChanged;
|
||||||
sourceChanged();
|
sourceChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sourceChanged()
|
private void sourceChanged()
|
||||||
{
|
{
|
||||||
isLegacySkin = new Lazy<bool>(() => source.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null);
|
isLegacySkin = new Lazy<bool>(() => Source.GetConfig<LegacySkinConfiguration.LegacySetting, decimal>(LegacySkinConfiguration.LegacySetting.Version) != null);
|
||||||
hasKeyTexture = new Lazy<bool>(() => source.GetAnimation(
|
hasKeyTexture = new Lazy<bool>(() => Source.GetAnimation(
|
||||||
this.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value
|
this.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value
|
||||||
?? "mania-key1", true, true) != null);
|
?? "mania-key1", true, true) != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drawable GetDrawableComponent(ISkinComponent component)
|
public override Drawable GetDrawableComponent(ISkinComponent component)
|
||||||
{
|
{
|
||||||
switch (component)
|
switch (component)
|
||||||
{
|
{
|
||||||
@ -133,16 +129,12 @@ namespace osu.Game.Rulesets.Mania.Skinning
|
|||||||
return this.GetAnimation(filename, true, true);
|
return this.GetAnimation(filename, true, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
||||||
|
|
||||||
public SampleChannel GetSample(ISampleInfo sample) => source.GetSample(sample);
|
|
||||||
|
|
||||||
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
|
||||||
{
|
{
|
||||||
if (lookup is ManiaSkinConfigurationLookup maniaLookup)
|
if (lookup is ManiaSkinConfigurationLookup maniaLookup)
|
||||||
return source.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.TargetColumn));
|
return Source.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.TargetColumn));
|
||||||
|
|
||||||
return source.GetConfig<TLookup, TValue>(lookup);
|
return Source.GetConfig<TLookup, TValue>(lookup);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -2,20 +2,15 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using osu.Framework.Audio.Sample;
|
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Game.Audio;
|
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
using osuTK;
|
using osuTK;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Skinning
|
namespace osu.Game.Rulesets.Osu.Skinning
|
||||||
{
|
{
|
||||||
public class OsuLegacySkinTransformer : ISkin
|
public class OsuLegacySkinTransformer : LegacySkinTransformer
|
||||||
{
|
{
|
||||||
private readonly ISkin source;
|
|
||||||
|
|
||||||
private Lazy<bool> hasHitCircle;
|
private Lazy<bool> hasHitCircle;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -26,19 +21,18 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
public const float LEGACY_CIRCLE_RADIUS = 64 - 5;
|
public const float LEGACY_CIRCLE_RADIUS = 64 - 5;
|
||||||
|
|
||||||
public OsuLegacySkinTransformer(ISkinSource source)
|
public OsuLegacySkinTransformer(ISkinSource source)
|
||||||
|
: base(source)
|
||||||
{
|
{
|
||||||
this.source = source;
|
Source.SourceChanged += sourceChanged;
|
||||||
|
|
||||||
source.SourceChanged += sourceChanged;
|
|
||||||
sourceChanged();
|
sourceChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void sourceChanged()
|
private void sourceChanged()
|
||||||
{
|
{
|
||||||
hasHitCircle = new Lazy<bool>(() => source.GetTexture("hitcircle") != null);
|
hasHitCircle = new Lazy<bool>(() => Source.GetTexture("hitcircle") != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drawable GetDrawableComponent(ISkinComponent component)
|
public override Drawable GetDrawableComponent(ISkinComponent component)
|
||||||
{
|
{
|
||||||
if (!(component is OsuSkinComponent osuComponent))
|
if (!(component is OsuSkinComponent osuComponent))
|
||||||
return null;
|
return null;
|
||||||
@ -85,13 +79,13 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
return null;
|
return null;
|
||||||
|
|
||||||
case OsuSkinComponents.Cursor:
|
case OsuSkinComponents.Cursor:
|
||||||
if (source.GetTexture("cursor") != null)
|
if (Source.GetTexture("cursor") != null)
|
||||||
return new LegacyCursor();
|
return new LegacyCursor();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
case OsuSkinComponents.CursorTrail:
|
case OsuSkinComponents.CursorTrail:
|
||||||
if (source.GetTexture("cursortrail") != null)
|
if (Source.GetTexture("cursortrail") != null)
|
||||||
return new LegacyCursorTrail();
|
return new LegacyCursorTrail();
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
@ -102,7 +96,7 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
|
|
||||||
return !hasFont(font)
|
return !hasFont(font)
|
||||||
? null
|
? null
|
||||||
: new LegacySpriteText(source, font)
|
: new LegacySpriteText(Source, font)
|
||||||
{
|
{
|
||||||
// stable applies a blanket 0.8x scale to hitcircle fonts
|
// stable applies a blanket 0.8x scale to hitcircle fonts
|
||||||
Scale = new Vector2(0.8f),
|
Scale = new Vector2(0.8f),
|
||||||
@ -113,16 +107,12 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
||||||
|
|
||||||
public SampleChannel GetSample(ISampleInfo sample) => source.GetSample(sample);
|
|
||||||
|
|
||||||
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
|
||||||
{
|
{
|
||||||
switch (lookup)
|
switch (lookup)
|
||||||
{
|
{
|
||||||
case OsuSkinColour colour:
|
case OsuSkinColour colour:
|
||||||
return source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
|
return Source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
|
||||||
|
|
||||||
case OsuSkinConfiguration osuLookup:
|
case OsuSkinConfiguration osuLookup:
|
||||||
switch (osuLookup)
|
switch (osuLookup)
|
||||||
@ -136,16 +126,16 @@ namespace osu.Game.Rulesets.Osu.Skinning
|
|||||||
case OsuSkinConfiguration.HitCircleOverlayAboveNumber:
|
case OsuSkinConfiguration.HitCircleOverlayAboveNumber:
|
||||||
// See https://osu.ppy.sh/help/wiki/Skinning/skin.ini#%5Bgeneral%5D
|
// See https://osu.ppy.sh/help/wiki/Skinning/skin.ini#%5Bgeneral%5D
|
||||||
// HitCircleOverlayAboveNumer (with typo) should still be supported for now.
|
// HitCircleOverlayAboveNumer (with typo) should still be supported for now.
|
||||||
return source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumber) ??
|
return Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumber) ??
|
||||||
source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumer);
|
Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumer);
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return source.GetConfig<TLookup, TValue>(lookup);
|
return Source.GetConfig<TLookup, TValue>(lookup);
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool hasFont(string fontName) => source.GetTexture($"{fontName}-0") != null;
|
private bool hasFont(string fontName) => Source.GetTexture($"{fontName}-0") != null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,23 +6,20 @@ using System.Collections.Generic;
|
|||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Textures;
|
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Rulesets.Taiko.UI;
|
using osu.Game.Rulesets.Taiko.UI;
|
||||||
using osu.Game.Skinning;
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Taiko.Skinning
|
namespace osu.Game.Rulesets.Taiko.Skinning
|
||||||
{
|
{
|
||||||
public class TaikoLegacySkinTransformer : ISkin
|
public class TaikoLegacySkinTransformer : LegacySkinTransformer
|
||||||
{
|
{
|
||||||
private readonly ISkinSource source;
|
|
||||||
|
|
||||||
public TaikoLegacySkinTransformer(ISkinSource source)
|
public TaikoLegacySkinTransformer(ISkinSource source)
|
||||||
|
: base(source)
|
||||||
{
|
{
|
||||||
this.source = source;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drawable GetDrawableComponent(ISkinComponent component)
|
public override Drawable GetDrawableComponent(ISkinComponent component)
|
||||||
{
|
{
|
||||||
if (!(component is TaikoSkinComponent taikoComponent))
|
if (!(component is TaikoSkinComponent taikoComponent))
|
||||||
return null;
|
return null;
|
||||||
@ -100,7 +97,7 @@ namespace osu.Game.Rulesets.Taiko.Skinning
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return source.GetDrawableComponent(component);
|
return Source.GetDrawableComponent(component);
|
||||||
}
|
}
|
||||||
|
|
||||||
private string getHitName(TaikoSkinComponents component)
|
private string getHitName(TaikoSkinComponents component)
|
||||||
@ -120,11 +117,9 @@ namespace osu.Game.Rulesets.Taiko.Skinning
|
|||||||
throw new ArgumentOutOfRangeException(nameof(component), "Invalid result type");
|
throw new ArgumentOutOfRangeException(nameof(component), "Invalid result type");
|
||||||
}
|
}
|
||||||
|
|
||||||
public Texture GetTexture(string componentName) => source.GetTexture(componentName);
|
public override SampleChannel GetSample(ISampleInfo sampleInfo) => Source.GetSample(new LegacyTaikoSampleInfo(sampleInfo));
|
||||||
|
|
||||||
public SampleChannel GetSample(ISampleInfo sampleInfo) => source.GetSample(new LegacyTaikoSampleInfo(sampleInfo));
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => Source.GetConfig<TLookup, TValue>(lookup);
|
||||||
|
|
||||||
public IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup) => source.GetConfig<TLookup, TValue>(lookup);
|
|
||||||
|
|
||||||
private class LegacyTaikoSampleInfo : ISampleInfo
|
private class LegacyTaikoSampleInfo : ISampleInfo
|
||||||
{
|
{
|
||||||
|
35
osu.Game/Skinning/LegacySkinTransformer.cs
Normal file
35
osu.Game/Skinning/LegacySkinTransformer.cs
Normal file
@ -0,0 +1,35 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
|
||||||
|
namespace osu.Game.Skinning
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Transformer used to handle support of legacy features for individual rulesets.
|
||||||
|
/// </summary>
|
||||||
|
public abstract class LegacySkinTransformer : ISkin
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// Source of the <see cref="ISkin"/> which is being transformed.
|
||||||
|
/// </summary>
|
||||||
|
protected ISkinSource Source { get; }
|
||||||
|
|
||||||
|
protected LegacySkinTransformer(ISkinSource source)
|
||||||
|
{
|
||||||
|
Source = source;
|
||||||
|
}
|
||||||
|
|
||||||
|
public abstract Drawable GetDrawableComponent(ISkinComponent component);
|
||||||
|
|
||||||
|
public Texture GetTexture(string componentName) => Source.GetTexture(componentName);
|
||||||
|
|
||||||
|
public virtual SampleChannel GetSample(ISampleInfo sampleInfo) => Source.GetSample(sampleInfo);
|
||||||
|
|
||||||
|
public abstract IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user