2019-08-30 11:59:58 +08: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 16:57:34 +08:00
|
|
|
using osu.Framework.Bindables;
|
2019-08-30 11:59:58 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
|
2020-12-07 11:27:12 +08:00
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
2020-06-22 04:04:10 +08:00
|
|
|
public class OsuLegacySkinTransformer : LegacySkinTransformer
|
2019-08-30 11:59:58 +08: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 14:39:36 +08:00
|
|
|
public const float LEGACY_CIRCLE_RADIUS = 64 - 5;
|
2019-08-30 11:59:58 +08:00
|
|
|
|
2019-09-03 16:57:34 +08:00
|
|
|
public OsuLegacySkinTransformer(ISkinSource source)
|
2020-06-22 04:04:10 +08:00
|
|
|
: base(source)
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
2020-06-22 04:04:10 +08:00
|
|
|
Source.SourceChanged += sourceChanged;
|
2019-08-30 11:59:58 +08:00
|
|
|
sourceChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void sourceChanged()
|
|
|
|
{
|
2020-06-22 04:04:10 +08:00
|
|
|
hasHitCircle = new Lazy<bool>(() => Source.GetTexture("hitcircle") != null);
|
2019-08-30 11:59:58 +08:00
|
|
|
}
|
|
|
|
|
2020-06-22 04:04:10 +08:00
|
|
|
public override Drawable GetDrawableComponent(ISkinComponent component)
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
2019-08-30 13:39:02 +08:00
|
|
|
if (!(component is OsuSkinComponent osuComponent))
|
|
|
|
return null;
|
|
|
|
|
|
|
|
switch (osuComponent.Component)
|
2019-08-30 11:59:58 +08:00
|
|
|
{
|
2019-09-11 13:57:42 +08:00
|
|
|
case OsuSkinComponents.FollowPoint:
|
2020-04-06 12:04:46 +08:00
|
|
|
return this.GetAnimation(component.LookupName, true, false, true, startAtCurrentTime: false);
|
2019-09-11 13:57:42 +08:00
|
|
|
|
2019-08-30 13:39:02 +08:00
|
|
|
case OsuSkinComponents.SliderFollowCircle:
|
2020-02-07 13:58:29 +08:00
|
|
|
var followCircle = this.GetAnimation("sliderfollowcircle", true, true, true);
|
2019-12-06 17:53:30 +08:00
|
|
|
if (followCircle != null)
|
2019-12-06 17:54:54 +08:00
|
|
|
// follow circles are 2x the hitcircle resolution in legacy skins (since they are scaled down from >1x
|
2019-12-06 17:53:30 +08:00
|
|
|
followCircle.Scale *= 0.5f;
|
2019-12-06 13:40:45 +08:00
|
|
|
return followCircle;
|
2019-08-30 13:40:36 +08:00
|
|
|
|
2019-08-30 13:39:02 +08:00
|
|
|
case OsuSkinComponents.SliderBall:
|
2020-02-07 13:58:29 +08:00
|
|
|
var sliderBallContent = this.GetAnimation("sliderb", true, true, animationSeparator: "");
|
|
|
|
|
|
|
|
// 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 11:59:58 +08:00
|
|
|
|
|
|
|
if (sliderBallContent != null)
|
2020-04-02 18:30:58 +08:00
|
|
|
return new LegacySliderBall(sliderBallContent);
|
2019-08-30 11:59:58 +08:00
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2019-12-17 17:16:25 +08:00
|
|
|
case OsuSkinComponents.SliderBody:
|
|
|
|
if (hasHitCircle.Value)
|
|
|
|
return new LegacySliderBody();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2020-10-02 12:41:22 +08:00
|
|
|
case OsuSkinComponents.SliderTailHitCircle:
|
|
|
|
if (hasHitCircle.Value)
|
|
|
|
return new LegacyMainCirclePiece("sliderendcircle", false);
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2020-03-28 12:39:08 +08:00
|
|
|
case OsuSkinComponents.SliderHeadHitCircle:
|
|
|
|
if (hasHitCircle.Value)
|
|
|
|
return new LegacyMainCirclePiece("sliderstartcircle");
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2019-08-30 13:39:02 +08:00
|
|
|
case OsuSkinComponents.HitCircle:
|
2019-08-30 11:59:58 +08:00
|
|
|
if (hasHitCircle.Value)
|
|
|
|
return new LegacyMainCirclePiece();
|
|
|
|
|
|
|
|
return null;
|
2019-08-30 12:42:29 +08:00
|
|
|
|
2019-08-30 13:39:02 +08:00
|
|
|
case OsuSkinComponents.Cursor:
|
2020-06-22 04:04:10 +08:00
|
|
|
if (Source.GetTexture("cursor") != null)
|
2019-08-30 12:42:29 +08:00
|
|
|
return new LegacyCursor();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2019-09-09 16:53:51 +08:00
|
|
|
case OsuSkinComponents.CursorTrail:
|
2020-06-22 04:04:10 +08:00
|
|
|
if (Source.GetTexture("cursortrail") != null)
|
2019-09-09 16:53:51 +08:00
|
|
|
return new LegacyCursorTrail();
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
2019-08-30 13:39:02 +08:00
|
|
|
case OsuSkinComponents.HitCircleText:
|
2019-09-10 17:06:24 +08:00
|
|
|
var font = GetConfig<OsuSkinConfiguration, string>(OsuSkinConfiguration.HitCirclePrefix)?.Value ?? "default";
|
2020-07-27 15:29:16 +08:00
|
|
|
var overlap = GetConfig<OsuSkinConfiguration, float>(OsuSkinConfiguration.HitCircleOverlap)?.Value ?? -2;
|
2019-08-30 12:42:29 +08:00
|
|
|
|
2020-08-19 12:58:23 +08:00
|
|
|
return !this.HasFont(font)
|
2019-08-30 12:42:29 +08:00
|
|
|
? null
|
2020-06-22 04:04:10 +08:00
|
|
|
: new LegacySpriteText(Source, font)
|
2019-08-30 12:42:29 +08:00
|
|
|
{
|
2019-09-11 12:39:21 +08:00
|
|
|
// stable applies a blanket 0.8x scale to hitcircle fonts
|
|
|
|
Scale = new Vector2(0.8f),
|
|
|
|
Spacing = new Vector2(-overlap, 0)
|
2019-08-30 12:42:29 +08:00
|
|
|
};
|
2020-07-29 15:25:10 +08:00
|
|
|
|
2020-07-29 21:31:18 +08:00
|
|
|
case OsuSkinComponents.SpinnerBody:
|
2020-07-31 23:05:04 +08:00
|
|
|
bool hasBackground = Source.GetTexture("spinner-background") != null;
|
|
|
|
|
|
|
|
if (Source.GetTexture("spinner-top") != null && !hasBackground)
|
2020-07-29 21:31:18 +08:00
|
|
|
return new LegacyNewStyleSpinner();
|
2020-07-31 23:05:04 +08:00
|
|
|
else if (hasBackground)
|
2020-07-29 21:31:18 +08:00
|
|
|
return new LegacyOldStyleSpinner();
|
2020-07-29 15:55:42 +08:00
|
|
|
|
|
|
|
return null;
|
2019-08-30 11:59:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2020-06-22 04:04:10 +08:00
|
|
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
2019-09-02 11:36:08 +08:00
|
|
|
{
|
2019-09-03 16:57:34 +08:00
|
|
|
switch (lookup)
|
|
|
|
{
|
|
|
|
case OsuSkinColour colour:
|
2020-06-22 04:04:10 +08:00
|
|
|
return Source.GetConfig<SkinCustomColourLookup, TValue>(new SkinCustomColourLookup(colour));
|
2019-09-03 16:57:34 +08:00
|
|
|
|
|
|
|
case OsuSkinConfiguration osuLookup:
|
|
|
|
switch (osuLookup)
|
|
|
|
{
|
|
|
|
case OsuSkinConfiguration.SliderPathRadius:
|
|
|
|
if (hasHitCircle.Value)
|
2019-12-18 14:39:36 +08:00
|
|
|
return SkinUtils.As<TValue>(new BindableFloat(LEGACY_CIRCLE_RADIUS));
|
2019-09-03 16:57:34 +08:00
|
|
|
|
|
|
|
break;
|
2020-04-04 16:13:25 +08:00
|
|
|
|
|
|
|
case OsuSkinConfiguration.HitCircleOverlayAboveNumber:
|
2020-04-05 13:13:06 +08:00
|
|
|
// See https://osu.ppy.sh/help/wiki/Skinning/skin.ini#%5Bgeneral%5D
|
|
|
|
// HitCircleOverlayAboveNumer (with typo) should still be supported for now.
|
2020-06-22 04:04:10 +08:00
|
|
|
return Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumber) ??
|
|
|
|
Source.GetConfig<OsuSkinConfiguration, TValue>(OsuSkinConfiguration.HitCircleOverlayAboveNumer);
|
2019-09-03 16:57:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2019-09-02 11:36:08 +08:00
|
|
|
|
2020-06-22 04:04:10 +08:00
|
|
|
return Source.GetConfig<TLookup, TValue>(lookup);
|
2019-09-02 11:36:08 +08:00
|
|
|
}
|
2019-08-30 11:59:58 +08:00
|
|
|
}
|
|
|
|
}
|