2019-08-30 03:59:58 +00:00
|
|
|
// 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;
|
2019-09-03 08:57:34 +00:00
|
|
|
using osu.Framework.Bindables;
|
2019-08-30 03:59:58 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
|
2020-12-07 03:27:12 +00:00
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2020-06-21 20:04:10 +00:00
|
|
|
public class OsuLegacySkinTransformer : LegacySkinTransformer
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
|
|
|
private Lazy<bool> hasHitCircle;
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// On osu-stable, hitcircles have 5 pixels of transparent padding on each side to allow for shadows etc.
|
|
|
|
/// Their hittable area is 128px, but the actual circle portion is 118px.
|
|
|
|
/// We must account for some gameplay elements such as slider bodies, where this padding is not present.
|
|
|
|
/// </summary>
|
2019-12-18 06:39:36 +00:00
|
|
|
public const float LEGACY_CIRCLE_RADIUS = 64 - 5;
|
2019-08-30 03:59:58 +00:00
|
|
|
|
2019-09-03 08:57:34 +00:00
|
|
|
public OsuLegacySkinTransformer(ISkinSource source)
|
2020-06-21 20:04:10 +00:00
|
|
|
: base(source)
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2020-06-21 20:04:10 +00:00
|
|
|
Source.SourceChanged += sourceChanged;
|
2019-08-30 03:59:58 +00:00
|
|
|
sourceChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sourceChanged()
|
|
|
|
{
|
2021-05-31 11:43:01 +00:00
|
|
|
hasHitCircle = new Lazy<bool>(() => FindProvider(s => s.GetTexture("hitcircle") != null) != null);
|
2019-08-30 03:59:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 20:04:10 +00:00
|
|
|
public override Drawable GetDrawableComponent(ISkinComponent component)
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2021-05-30 10:15:59 +00:00
|
|
|
if (component is OsuSkinComponent osuComponent)
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2021-05-30 10:15:59 +00:00
|
|
|
switch (osuComponent.Component)
|
|
|
|
{
|
|
|
|
case OsuSkinComponents.FollowPoint:
|
|
|
|
return this.GetAnimation(component.LookupName, true, false, true, startAtCurrentTime: false);
|
2019-08-30 05:40:36 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.SliderFollowCircle:
|
|
|
|
var followCircle = this.GetAnimation("sliderfollowcircle", true, true, true);
|
|
|
|
if (followCircle != null)
|
|
|
|
// follow circles are 2x the hitcircle resolution in legacy skins (since they are scaled down from >1x
|
|
|
|
followCircle.Scale *= 0.5f;
|
|
|
|
return followCircle;
|
2020-02-07 05:58:29 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.SliderBall:
|
2021-06-08 03:10:14 +00:00
|
|
|
// specular and nd layers must come from the same source as the ball texure.
|
|
|
|
var ballProvider = Source.FindProvider(s => s.GetTexture("sliderb") != null || s.GetTexture("sliderb0") != null);
|
|
|
|
|
|
|
|
var sliderBallContent = ballProvider.GetAnimation("sliderb", true, true, animationSeparator: "");
|
2019-08-30 03:59:58 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
// todo: slider ball has a custom frame delay based on velocity
|
|
|
|
// Math.Max((150 / Velocity) * GameBase.SIXTY_FRAME_TIME, GameBase.SIXTY_FRAME_TIME);
|
2019-08-30 03:59:58 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
if (sliderBallContent != null)
|
2021-06-08 03:10:14 +00:00
|
|
|
return new LegacySliderBall(sliderBallContent, ballProvider);
|
2019-08-30 03:59:58 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
return null;
|
2019-12-17 09:16:25 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.SliderBody:
|
|
|
|
if (hasHitCircle.Value)
|
|
|
|
return new LegacySliderBody();
|
2019-12-17 09:16:25 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
return null;
|
2020-10-02 04:41:22 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.SliderTailHitCircle:
|
|
|
|
if (hasHitCircle.Value)
|
|
|
|
return new LegacyMainCirclePiece("sliderendcircle", false);
|
2020-10-02 04:41:22 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
return null;
|
2020-03-28 04:39:08 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.SliderHeadHitCircle:
|
|
|
|
if (hasHitCircle.Value)
|
|
|
|
return new LegacyMainCirclePiece("sliderstartcircle");
|
2020-03-28 04:39:08 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
return null;
|
2019-08-30 03:59:58 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.HitCircle:
|
|
|
|
if (hasHitCircle.Value)
|
|
|
|
return new LegacyMainCirclePiece();
|
2019-08-30 04:42:29 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
return null;
|
2019-08-30 04:42:29 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.Cursor:
|
2021-06-06 13:26:27 +00:00
|
|
|
var cursorProvider = Source.FindProvider(s => s.GetTexture("cursor") != null);
|
|
|
|
|
|
|
|
if (cursorProvider != null)
|
|
|
|
return new LegacyCursor(cursorProvider);
|
2019-08-30 04:42:29 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
return null;
|
2019-09-09 08:53:51 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.CursorTrail:
|
2021-06-06 13:26:27 +00:00
|
|
|
var trailProvider = Source.FindProvider(s => s.GetTexture("cursortrail") != null);
|
|
|
|
|
|
|
|
if (trailProvider != null)
|
|
|
|
return new LegacyCursorTrail(trailProvider);
|
2019-09-09 08:53:51 +00:00
|
|
|
|
2021-03-06 23:18:31 +00:00
|
|
|
return null;
|
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.HitCircleText:
|
|
|
|
if (!this.HasFont(LegacyFont.HitCircle))
|
|
|
|
return null;
|
2020-07-29 07:25:10 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
return new LegacySpriteText(LegacyFont.HitCircle)
|
|
|
|
{
|
|
|
|
// stable applies a blanket 0.8x scale to hitcircle fonts
|
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
};
|
2020-07-31 15:05:04 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
case OsuSkinComponents.SpinnerBody:
|
|
|
|
bool hasBackground = Source.GetTexture("spinner-background") != null;
|
2020-07-29 07:55:42 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
if (Source.GetTexture("spinner-top") != null && !hasBackground)
|
|
|
|
return new LegacyNewStyleSpinner();
|
|
|
|
else if (hasBackground)
|
|
|
|
return new LegacyOldStyleSpinner();
|
2019-08-30 03:59:58 +00:00
|
|
|
|
2021-05-30 10:15:59 +00:00
|
|
|
return null;
|
|
|
|
}
|
2021-05-27 02:15:29 +00:00
|
|
|
}
|
2021-05-30 10:15:59 +00:00
|
|
|
|
|
|
|
return Source.GetDrawableComponent(component);
|
2019-08-30 03:59:58 +00:00
|
|
|
}
|
|
|
|
|
2020-06-21 20:04:10 +00:00
|
|
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
2019-09-02 03:36:08 +00:00
|
|
|
{
|
2019-09-03 08:57:34 +00:00
|
|
|
switch (lookup)
|
|
|
|
{
|
|
|
|
case OsuSkinColour colour:
|
2020-06-21 20:04:10 +00:00
|
|
|
return Source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
|
2019-09-03 08:57:34 +00:00
|
|
|
|
|
|
|
case OsuSkinConfiguration osuLookup:
|
|
|
|
switch (osuLookup)
|
|
|
|
{
|
|
|
|
case OsuSkinConfiguration.SliderPathRadius:
|
|
|
|
if (hasHitCircle.Value)
|
2019-12-18 06:39:36 +00:00
|
|
|
return SkinUtils.As<TValue>(new BindableFloat(LEGACY_CIRCLE_RADIUS));
|
2019-09-03 08:57:34 +00:00
|
|
|
|
|
|
|
break;
|
2020-04-04 08:13:25 +00:00
|
|
|
|
|
|
|
case OsuSkinConfiguration.HitCircleOverlayAboveNumber:
|
2020-04-05 05:13:06 +00:00
|
|
|
// See https://osu.ppy.sh/help/wiki/Skinning/skin.ini#%5Bgeneral%5D
|
|
|
|
// HitCircleOverlayAboveNumer (with typo) should still be supported for now.
|
2020-06-21 20:04:10 +00:00
|
|
|
return Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumber) ??
|
|
|
|
Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumer);
|
2019-09-03 08:57:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-09-02 03:36:08 +00:00
|
|
|
|
2020-06-21 20:04:10 +00:00
|
|
|
return Source.GetConfig<TLookup, TValue>(lookup);
|
2019-09-02 03:36:08 +00:00
|
|
|
}
|
2019-08-30 03:59:58 +00:00
|
|
|
}
|
|
|
|
}
|