mirror of
https://github.com/ppy/osu.git
synced 2024-11-07 15:17:30 +08:00
Merge pull request #5833 from peppy/add-ruleset-legacy-skin
Add ruleset-level legacy skin provider Co-authored-by: Dan Balasescu <smoogipoo@smgi.me>
This commit is contained in:
commit
a5126fd79b
BIN
osu.Game.Rulesets.Osu.Tests/Resources/default-skin/cursor@2x.png
Executable file
BIN
osu.Game.Rulesets.Osu.Tests/Resources/default-skin/cursor@2x.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 27 KiB |
BIN
osu.Game.Rulesets.Osu.Tests/Resources/default-skin/cursormiddle@2x.png
Executable file
BIN
osu.Game.Rulesets.Osu.Tests/Resources/default-skin/cursormiddle@2x.png
Executable file
Binary file not shown.
After Width: | Height: | Size: 7.5 KiB |
@ -37,10 +37,21 @@ namespace osu.Game.Rulesets.Osu.Tests
|
|||||||
|
|
||||||
public void SetContents(Func<Drawable> creationFunction)
|
public void SetContents(Func<Drawable> creationFunction)
|
||||||
{
|
{
|
||||||
Cell(0).Child = new LocalSkinOverrideContainer(null) { RelativeSizeAxes = Axes.Both }.WithChild(creationFunction());
|
Cell(0).Child = createProvider(null, creationFunction);
|
||||||
Cell(1).Child = new LocalSkinOverrideContainer(metricsSkin) { RelativeSizeAxes = Axes.Both }.WithChild(creationFunction());
|
Cell(1).Child = createProvider(metricsSkin, creationFunction);
|
||||||
Cell(2).Child = new LocalSkinOverrideContainer(defaultSkin) { RelativeSizeAxes = Axes.Both }.WithChild(creationFunction());
|
Cell(2).Child = createProvider(defaultSkin, creationFunction);
|
||||||
Cell(3).Child = new LocalSkinOverrideContainer(specialSkin) { RelativeSizeAxes = Axes.Both }.WithChild(creationFunction());
|
Cell(3).Child = createProvider(specialSkin, creationFunction);
|
||||||
|
}
|
||||||
|
|
||||||
|
private Drawable createProvider(Skin skin, Func<Drawable> creationFunction)
|
||||||
|
{
|
||||||
|
var mainProvider = new SkinProvidingContainer(skin);
|
||||||
|
|
||||||
|
return mainProvider
|
||||||
|
.WithChild(new SkinProvidingContainer(Ruleset.Value.CreateInstance().CreateLegacySkinProvider(mainProvider))
|
||||||
|
{
|
||||||
|
Child = creationFunction()
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private class TestLegacySkin : LegacySkin
|
private class TestLegacySkin : LegacySkin
|
||||||
|
@ -6,29 +6,23 @@ using System.Collections.Generic;
|
|||||||
using NUnit.Framework;
|
using NUnit.Framework;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Cursor;
|
|
||||||
using osu.Game.Graphics.Cursor;
|
|
||||||
using osu.Game.Rulesets.Osu.UI.Cursor;
|
using osu.Game.Rulesets.Osu.UI.Cursor;
|
||||||
using osu.Game.Rulesets.UI;
|
|
||||||
using osu.Game.Tests.Visual;
|
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu.Tests
|
namespace osu.Game.Rulesets.Osu.Tests
|
||||||
{
|
{
|
||||||
[TestFixture]
|
[TestFixture]
|
||||||
public class TestSceneGameplayCursor : OsuTestScene, IProvideCursor
|
public class TestSceneGameplayCursor : SkinnableTestScene
|
||||||
{
|
{
|
||||||
private GameplayCursorContainer cursorContainer;
|
|
||||||
|
|
||||||
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(CursorTrail) };
|
public override IReadOnlyList<Type> RequiredTypes => new[] { typeof(CursorTrail) };
|
||||||
|
|
||||||
public CursorContainer Cursor => cursorContainer;
|
|
||||||
|
|
||||||
public bool ProvidingUserCursor => true;
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
Add(cursorContainer = new OsuCursorContainer { RelativeSizeAxes = Axes.Both });
|
SetContents(() => new OsuCursorContainer
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both,
|
||||||
|
Masking = true,
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
157
osu.Game.Rulesets.Osu.Tests/TestSceneSkinFallbacks.cs
Normal file
157
osu.Game.Rulesets.Osu.Tests/TestSceneSkinFallbacks.cs
Normal file
@ -0,0 +1,157 @@
|
|||||||
|
// 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;
|
||||||
|
using System.Linq;
|
||||||
|
using NUnit.Framework;
|
||||||
|
using osu.Framework.Allocation;
|
||||||
|
using osu.Framework.Audio;
|
||||||
|
using osu.Framework.Audio.Sample;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Framework.Timing;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Beatmaps;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||||
|
using osu.Game.Screens.Play;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using osu.Game.Tests.Visual;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Osu.Tests
|
||||||
|
{
|
||||||
|
[TestFixture]
|
||||||
|
public class TestSceneSkinFallbacks : PlayerTestScene
|
||||||
|
{
|
||||||
|
private readonly TestSource testUserSkin;
|
||||||
|
private readonly TestSource testBeatmapSkin;
|
||||||
|
|
||||||
|
public TestSceneSkinFallbacks()
|
||||||
|
: base(new OsuRuleset())
|
||||||
|
{
|
||||||
|
testUserSkin = new TestSource("user");
|
||||||
|
testBeatmapSkin = new TestSource("beatmap");
|
||||||
|
}
|
||||||
|
|
||||||
|
[Test]
|
||||||
|
public void TestBeatmapSkinDefault()
|
||||||
|
{
|
||||||
|
AddStep("enable user provider", () => testUserSkin.Enabled = true);
|
||||||
|
|
||||||
|
AddStep("enable beatmap skin", () => LocalConfig.Set<bool>(OsuSetting.BeatmapSkins, true));
|
||||||
|
checkNextHitObject("beatmap");
|
||||||
|
|
||||||
|
AddStep("disable beatmap skin", () => LocalConfig.Set<bool>(OsuSetting.BeatmapSkins, false));
|
||||||
|
checkNextHitObject("user");
|
||||||
|
|
||||||
|
AddStep("disable user provider", () => testUserSkin.Enabled = false);
|
||||||
|
checkNextHitObject(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void checkNextHitObject(string skin) =>
|
||||||
|
AddUntilStep($"check skin from {skin}", () =>
|
||||||
|
{
|
||||||
|
var firstObject = ((TestPlayer)Player).DrawableRuleset.Playfield.HitObjectContainer.AliveObjects.OfType<DrawableHitCircle>().FirstOrDefault();
|
||||||
|
|
||||||
|
if (firstObject == null)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
var skinnable = firstObject.ApproachCircle.Child as SkinnableDrawable;
|
||||||
|
|
||||||
|
if (skin == null && skinnable?.Drawable is Sprite)
|
||||||
|
// check for default skin provider
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var text = skinnable?.Drawable as SpriteText;
|
||||||
|
|
||||||
|
return text?.Text == skin;
|
||||||
|
});
|
||||||
|
|
||||||
|
[Resolved]
|
||||||
|
private AudioManager audio { get; set; }
|
||||||
|
|
||||||
|
protected override Player CreatePlayer(Ruleset ruleset) => new SkinProvidingPlayer(testUserSkin);
|
||||||
|
|
||||||
|
protected override WorkingBeatmap CreateWorkingBeatmap(IBeatmap beatmap) => new CustomSkinWorkingBeatmap(beatmap, Clock, audio, testBeatmapSkin);
|
||||||
|
|
||||||
|
public class CustomSkinWorkingBeatmap : ClockBackedTestWorkingBeatmap
|
||||||
|
{
|
||||||
|
private readonly ISkinSource skin;
|
||||||
|
|
||||||
|
public CustomSkinWorkingBeatmap(IBeatmap beatmap, IFrameBasedClock frameBasedClock, AudioManager audio, ISkinSource skin)
|
||||||
|
: base(beatmap, frameBasedClock, audio)
|
||||||
|
{
|
||||||
|
this.skin = skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override ISkin GetSkin() => skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public class SkinProvidingPlayer : TestPlayer
|
||||||
|
{
|
||||||
|
private readonly TestSource userSkin;
|
||||||
|
|
||||||
|
public SkinProvidingPlayer(TestSource userSkin)
|
||||||
|
{
|
||||||
|
this.userSkin = userSkin;
|
||||||
|
}
|
||||||
|
|
||||||
|
private DependencyContainer dependencies;
|
||||||
|
|
||||||
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
|
{
|
||||||
|
dependencies = new DependencyContainer(base.CreateChildDependencies(parent));
|
||||||
|
|
||||||
|
dependencies.CacheAs<ISkinSource>(userSkin);
|
||||||
|
|
||||||
|
return dependencies;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public class TestSource : ISkinSource
|
||||||
|
{
|
||||||
|
private readonly string identifier;
|
||||||
|
|
||||||
|
public TestSource(string identifier)
|
||||||
|
{
|
||||||
|
this.identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawable GetDrawableComponent(string componentName)
|
||||||
|
{
|
||||||
|
if (!enabled) return null;
|
||||||
|
|
||||||
|
return new SpriteText
|
||||||
|
{
|
||||||
|
Text = identifier,
|
||||||
|
Font = OsuFont.Default.With(size: 30),
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public Texture GetTexture(string componentName) => null;
|
||||||
|
|
||||||
|
public SampleChannel GetSample(ISampleInfo sampleInfo) => null;
|
||||||
|
|
||||||
|
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration => default;
|
||||||
|
|
||||||
|
public event Action SourceChanged;
|
||||||
|
|
||||||
|
private bool enabled = true;
|
||||||
|
|
||||||
|
public bool Enabled
|
||||||
|
{
|
||||||
|
get => enabled;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value == enabled)
|
||||||
|
return;
|
||||||
|
|
||||||
|
enabled = value;
|
||||||
|
SourceChanged?.Invoke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -23,7 +23,9 @@ using osu.Game.Rulesets.Difficulty;
|
|||||||
using osu.Game.Rulesets.Osu.Beatmaps;
|
using osu.Game.Rulesets.Osu.Beatmaps;
|
||||||
using osu.Game.Rulesets.Osu.Configuration;
|
using osu.Game.Rulesets.Osu.Configuration;
|
||||||
using osu.Game.Rulesets.Osu.Difficulty;
|
using osu.Game.Rulesets.Osu.Difficulty;
|
||||||
|
using osu.Game.Rulesets.Osu.Skinning;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets.Osu
|
namespace osu.Game.Rulesets.Osu
|
||||||
{
|
{
|
||||||
@ -163,6 +165,8 @@ namespace osu.Game.Rulesets.Osu
|
|||||||
|
|
||||||
public override RulesetSettingsSubsection CreateSettings() => new OsuSettingsSubsection(this);
|
public override RulesetSettingsSubsection CreateSettings() => new OsuSettingsSubsection(this);
|
||||||
|
|
||||||
|
public override ISkin CreateLegacySkinProvider(ISkinSource source) => new OsuLegacySkin(source);
|
||||||
|
|
||||||
public override int? LegacyID => 0;
|
public override int? LegacyID => 0;
|
||||||
|
|
||||||
public override IConvertibleReplayFrame CreateConvertibleReplayFrame() => new OsuReplayFrame();
|
public override IConvertibleReplayFrame CreateConvertibleReplayFrame() => new OsuReplayFrame();
|
||||||
|
42
osu.Game.Rulesets.Osu/Skinning/LegacyCursor.cs
Normal file
42
osu.Game.Rulesets.Osu/Skinning/LegacyCursor.cs
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
// 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.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using osuTK;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Osu.Skinning
|
||||||
|
{
|
||||||
|
public class LegacyCursor : CompositeDrawable
|
||||||
|
{
|
||||||
|
public LegacyCursor()
|
||||||
|
{
|
||||||
|
Size = new Vector2(50);
|
||||||
|
|
||||||
|
Anchor = Anchor.Centre;
|
||||||
|
Origin = Anchor.Centre;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(ISkinSource skin)
|
||||||
|
{
|
||||||
|
InternalChildren = new Drawable[]
|
||||||
|
{
|
||||||
|
new NonPlayfieldSprite
|
||||||
|
{
|
||||||
|
Texture = skin.GetTexture("cursormiddle"),
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
},
|
||||||
|
new NonPlayfieldSprite
|
||||||
|
{
|
||||||
|
Texture = skin.GetTexture("cursor"),
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
81
osu.Game.Rulesets.Osu/Skinning/LegacyMainCirclePiece.cs
Normal file
81
osu.Game.Rulesets.Osu/Skinning/LegacyMainCirclePiece.cs
Normal file
@ -0,0 +1,81 @@
|
|||||||
|
// 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.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
|
using osu.Game.Rulesets.Objects.Types;
|
||||||
|
using osu.Game.Rulesets.Osu.Objects;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Osu.Skinning
|
||||||
|
{
|
||||||
|
public class LegacyMainCirclePiece : CompositeDrawable
|
||||||
|
{
|
||||||
|
public LegacyMainCirclePiece()
|
||||||
|
{
|
||||||
|
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
private readonly IBindable<ArmedState> state = new Bindable<ArmedState>();
|
||||||
|
|
||||||
|
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(DrawableHitObject drawableObject, ISkinSource skin)
|
||||||
|
{
|
||||||
|
Sprite hitCircleSprite;
|
||||||
|
|
||||||
|
InternalChildren = new Drawable[]
|
||||||
|
{
|
||||||
|
hitCircleSprite = new Sprite
|
||||||
|
{
|
||||||
|
Texture = skin.GetTexture("hitcircle"),
|
||||||
|
Colour = drawableObject.AccentColour.Value,
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
},
|
||||||
|
new SkinnableSpriteText("Play/osu/number-text", _ => new OsuSpriteText
|
||||||
|
{
|
||||||
|
Font = OsuFont.Numeric.With(size: 40),
|
||||||
|
UseFullGlyphHeight = false,
|
||||||
|
}, confineMode: ConfineMode.NoScaling)
|
||||||
|
{
|
||||||
|
Text = (((IHasComboInformation)drawableObject.HitObject).IndexInCurrentCombo + 1).ToString()
|
||||||
|
},
|
||||||
|
new Sprite
|
||||||
|
{
|
||||||
|
Texture = skin.GetTexture("hitcircleoverlay"),
|
||||||
|
Anchor = Anchor.Centre,
|
||||||
|
Origin = Anchor.Centre,
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
state.BindTo(drawableObject.State);
|
||||||
|
state.BindValueChanged(updateState, true);
|
||||||
|
|
||||||
|
accentColour.BindTo(drawableObject.AccentColour);
|
||||||
|
accentColour.BindValueChanged(colour => hitCircleSprite.Colour = colour.NewValue, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateState(ValueChangedEvent<ArmedState> state)
|
||||||
|
{
|
||||||
|
const double legacy_fade_duration = 240;
|
||||||
|
|
||||||
|
switch (state.NewValue)
|
||||||
|
{
|
||||||
|
case ArmedState.Hit:
|
||||||
|
this.FadeOut(legacy_fade_duration, Easing.Out);
|
||||||
|
this.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
44
osu.Game.Rulesets.Osu/Skinning/LegacySliderBall.cs
Normal file
44
osu.Game.Rulesets.Osu/Skinning/LegacySliderBall.cs
Normal file
@ -0,0 +1,44 @@
|
|||||||
|
// 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.Allocation;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Containers;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Game.Rulesets.Objects.Drawables;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Osu.Skinning
|
||||||
|
{
|
||||||
|
public class LegacySliderBall : CompositeDrawable
|
||||||
|
{
|
||||||
|
private readonly Drawable animationContent;
|
||||||
|
|
||||||
|
public LegacySliderBall(Drawable animationContent)
|
||||||
|
{
|
||||||
|
this.animationContent = animationContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(ISkinSource skin, DrawableHitObject drawableObject)
|
||||||
|
{
|
||||||
|
animationContent.Colour = skin.GetValue<SkinConfiguration, Color4?>(s => s.CustomColours.ContainsKey("SliderBall") ? s.CustomColours["SliderBall"] : (Color4?)null) ?? Color4.White;
|
||||||
|
|
||||||
|
InternalChildren = new[]
|
||||||
|
{
|
||||||
|
new Sprite
|
||||||
|
{
|
||||||
|
Texture = skin.GetTexture("sliderb-nd"),
|
||||||
|
Colour = new Color4(5, 5, 5, 255),
|
||||||
|
},
|
||||||
|
animationContent,
|
||||||
|
new Sprite
|
||||||
|
{
|
||||||
|
Texture = skin.GetTexture("sliderb-spec"),
|
||||||
|
Blending = BlendingParameters.Additive,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
28
osu.Game.Rulesets.Osu/Skinning/NonPlayfieldSprite.cs
Normal file
28
osu.Game.Rulesets.Osu/Skinning/NonPlayfieldSprite.cs
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// 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.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Osu.Skinning
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A sprite which is displayed within the playfield, but historically was not considered part of the playfield.
|
||||||
|
/// Performs scale adjustment to undo the scale applied by <see cref="PlayfieldAdjustmentContainer"/> (osu! ruleset specifically).
|
||||||
|
/// </summary>
|
||||||
|
public class NonPlayfieldSprite : Sprite
|
||||||
|
{
|
||||||
|
public override Texture Texture
|
||||||
|
{
|
||||||
|
get => base.Texture;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
if (value != null)
|
||||||
|
// stable "magic ratio". see OsuPlayfieldAdjustmentContainer for full explanation.
|
||||||
|
value.ScaleAdjust *= 1.6f;
|
||||||
|
base.Texture = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
122
osu.Game.Rulesets.Osu/Skinning/OsuLegacySkin.cs
Normal file
122
osu.Game.Rulesets.Osu/Skinning/OsuLegacySkin.cs
Normal file
@ -0,0 +1,122 @@
|
|||||||
|
// 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;
|
||||||
|
using osu.Framework.Audio.Sample;
|
||||||
|
using osu.Framework.Graphics;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
using osuTK;
|
||||||
|
using osuTK.Graphics;
|
||||||
|
|
||||||
|
namespace osu.Game.Rulesets.Osu.Skinning
|
||||||
|
{
|
||||||
|
public class OsuLegacySkin : ISkin
|
||||||
|
{
|
||||||
|
private readonly ISkin source;
|
||||||
|
|
||||||
|
private Lazy<SkinConfiguration> configuration;
|
||||||
|
|
||||||
|
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>
|
||||||
|
private const float legacy_circle_radius = 64 - 5;
|
||||||
|
|
||||||
|
public OsuLegacySkin(ISkinSource source)
|
||||||
|
{
|
||||||
|
this.source = source;
|
||||||
|
|
||||||
|
source.SourceChanged += sourceChanged;
|
||||||
|
sourceChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sourceChanged()
|
||||||
|
{
|
||||||
|
// these need to be lazy in order to ensure they aren't called before the dependencies have been loaded into our source.
|
||||||
|
configuration = new Lazy<SkinConfiguration>(() =>
|
||||||
|
{
|
||||||
|
var config = new SkinConfiguration();
|
||||||
|
if (hasHitCircle.Value)
|
||||||
|
config.SliderPathRadius = legacy_circle_radius;
|
||||||
|
|
||||||
|
// defaults should only be applied for non-beatmap skins (which are parsed via this constructor).
|
||||||
|
config.CustomColours["SliderBall"] =
|
||||||
|
source.GetValue<SkinConfiguration, Color4?>(s => s.CustomColours.TryGetValue("SliderBall", out var val) ? val : (Color4?)null)
|
||||||
|
?? new Color4(2, 170, 255, 255);
|
||||||
|
|
||||||
|
return config;
|
||||||
|
});
|
||||||
|
|
||||||
|
hasHitCircle = new Lazy<bool>(() => source.GetTexture("hitcircle") != null);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Drawable GetDrawableComponent(string componentName)
|
||||||
|
{
|
||||||
|
switch (componentName)
|
||||||
|
{
|
||||||
|
case "Play/osu/sliderfollowcircle":
|
||||||
|
return this.GetAnimation(componentName, true, true);
|
||||||
|
|
||||||
|
case "Play/osu/sliderball":
|
||||||
|
var sliderBallContent = this.GetAnimation("sliderb", true, true, "");
|
||||||
|
|
||||||
|
if (sliderBallContent != null)
|
||||||
|
{
|
||||||
|
var size = sliderBallContent.Size;
|
||||||
|
|
||||||
|
sliderBallContent.RelativeSizeAxes = Axes.Both;
|
||||||
|
sliderBallContent.Size = Vector2.One;
|
||||||
|
|
||||||
|
return new LegacySliderBall(sliderBallContent)
|
||||||
|
{
|
||||||
|
Size = size
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case "Play/osu/hitcircle":
|
||||||
|
if (hasHitCircle.Value)
|
||||||
|
return new LegacyMainCirclePiece();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case "Play/osu/cursor":
|
||||||
|
if (source.GetTexture("cursor") != null)
|
||||||
|
return new LegacyCursor();
|
||||||
|
|
||||||
|
return null;
|
||||||
|
|
||||||
|
case "Play/osu/number-text":
|
||||||
|
|
||||||
|
string font = GetValue<SkinConfiguration, string>(config => config.HitCircleFont);
|
||||||
|
var overlap = GetValue<SkinConfiguration, float>(config => config.HitCircleOverlap);
|
||||||
|
|
||||||
|
return !hasFont(font)
|
||||||
|
? null
|
||||||
|
: new LegacySpriteText(this, font)
|
||||||
|
{
|
||||||
|
// Spacing value was reverse-engineered from the ratio of the rendered sprite size in the visual inspector vs the actual texture size
|
||||||
|
Scale = new Vector2(0.96f),
|
||||||
|
Spacing = new Vector2(-overlap * 0.89f, 0)
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Texture GetTexture(string componentName) => null;
|
||||||
|
|
||||||
|
public SampleChannel GetSample(ISampleInfo sample) => null;
|
||||||
|
|
||||||
|
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration
|
||||||
|
=> configuration.Value is TConfiguration conf ? query.Invoke(conf) : default;
|
||||||
|
|
||||||
|
private bool hasFont(string fontName) => GetTexture($"{fontName}-0") != null;
|
||||||
|
}
|
||||||
|
}
|
@ -42,9 +42,8 @@ namespace osu.Game.Rulesets.Osu.UI
|
|||||||
},
|
},
|
||||||
// Todo: This should not exist, but currently helps to reduce LOH allocations due to unbinding skin source events on judgement disposal
|
// Todo: This should not exist, but currently helps to reduce LOH allocations due to unbinding skin source events on judgement disposal
|
||||||
// Todo: Remove when hitobjects are properly pooled
|
// Todo: Remove when hitobjects are properly pooled
|
||||||
new LocalSkinOverrideContainer(null)
|
new SkinProvidingContainer(null)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
|
||||||
Child = HitObjectContainer,
|
Child = HitObjectContainer,
|
||||||
},
|
},
|
||||||
approachCircles = new ApproachCircleProxyContainer
|
approachCircles = new ApproachCircleProxyContainer
|
||||||
|
@ -28,7 +28,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
AddStep("setup layout larger source", () =>
|
AddStep("setup layout larger source", () =>
|
||||||
{
|
{
|
||||||
Child = new LocalSkinOverrideContainer(new SizedSource(50))
|
Child = new SkinProvidingContainer(new SizedSource(50))
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = fill = new FillFlowContainer<ExposedSkinnableDrawable>
|
Child = fill = new FillFlowContainer<ExposedSkinnableDrawable>
|
||||||
@ -60,7 +60,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
|
|
||||||
AddStep("setup layout larger source", () =>
|
AddStep("setup layout larger source", () =>
|
||||||
{
|
{
|
||||||
Child = new LocalSkinOverrideContainer(new SizedSource(30))
|
Child = new SkinProvidingContainer(new SizedSource(30))
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = fill = new FillFlowContainer<ExposedSkinnableDrawable>
|
Child = fill = new FillFlowContainer<ExposedSkinnableDrawable>
|
||||||
@ -96,7 +96,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
Child = new SkinSourceContainer
|
Child = new SkinSourceContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = new LocalSkinOverrideContainer(secondarySource)
|
Child = new SkinProvidingContainer(secondarySource)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"), source => true)
|
Child = consumer = new SkinConsumer("test", name => new NamedBox("Default Implementation"), source => true)
|
||||||
@ -121,7 +121,7 @@ namespace osu.Game.Tests.Visual.Gameplay
|
|||||||
Child = new SkinSourceContainer
|
Child = new SkinSourceContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
Child = target = new LocalSkinOverrideContainer(secondarySource)
|
Child = target = new SkinProvidingContainer(secondarySource)
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
}
|
}
|
||||||
|
@ -136,7 +136,7 @@ namespace osu.Game.Beatmaps
|
|||||||
return storyboard;
|
return storyboard;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Skin GetSkin()
|
protected override ISkin GetSkin()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
@ -43,7 +43,7 @@ namespace osu.Game.Beatmaps
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieves the <see cref="Skin"/> which this <see cref="WorkingBeatmap"/> provides.
|
/// Retrieves the <see cref="Skin"/> which this <see cref="WorkingBeatmap"/> provides.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
Skin Skin { get; }
|
ISkin Skin { get; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Constructs a playable <see cref="IBeatmap"/> from <see cref="Beatmap"/> using the applicable converters for a specific <see cref="RulesetInfo"/>.
|
/// Constructs a playable <see cref="IBeatmap"/> from <see cref="Beatmap"/> using the applicable converters for a specific <see cref="RulesetInfo"/>.
|
||||||
|
@ -45,7 +45,7 @@ namespace osu.Game.Beatmaps
|
|||||||
background = new RecyclableLazy<Texture>(GetBackground, BackgroundStillValid);
|
background = new RecyclableLazy<Texture>(GetBackground, BackgroundStillValid);
|
||||||
waveform = new RecyclableLazy<Waveform>(GetWaveform);
|
waveform = new RecyclableLazy<Waveform>(GetWaveform);
|
||||||
storyboard = new RecyclableLazy<Storyboard>(GetStoryboard);
|
storyboard = new RecyclableLazy<Storyboard>(GetStoryboard);
|
||||||
skin = new RecyclableLazy<Skin>(GetSkin);
|
skin = new RecyclableLazy<ISkin>(GetSkin);
|
||||||
|
|
||||||
total_count.Value++;
|
total_count.Value++;
|
||||||
}
|
}
|
||||||
@ -202,10 +202,10 @@ namespace osu.Game.Beatmaps
|
|||||||
private readonly RecyclableLazy<Storyboard> storyboard;
|
private readonly RecyclableLazy<Storyboard> storyboard;
|
||||||
|
|
||||||
public bool SkinLoaded => skin.IsResultAvailable;
|
public bool SkinLoaded => skin.IsResultAvailable;
|
||||||
public Skin Skin => skin.Value;
|
public ISkin Skin => skin.Value;
|
||||||
|
|
||||||
protected virtual Skin GetSkin() => new DefaultSkin();
|
protected virtual ISkin GetSkin() => new DefaultSkin();
|
||||||
private readonly RecyclableLazy<Skin> skin;
|
private readonly RecyclableLazy<ISkin> skin;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Transfer pieces of a beatmap to a new one, where possible, to save on loading.
|
/// Transfer pieces of a beatmap to a new one, where possible, to save on loading.
|
||||||
|
@ -18,6 +18,7 @@ using osu.Game.Configuration;
|
|||||||
using osu.Game.Rulesets.Configuration;
|
using osu.Game.Rulesets.Configuration;
|
||||||
using osu.Game.Rulesets.Difficulty;
|
using osu.Game.Rulesets.Difficulty;
|
||||||
using osu.Game.Scoring;
|
using osu.Game.Scoring;
|
||||||
|
using osu.Game.Skinning;
|
||||||
|
|
||||||
namespace osu.Game.Rulesets
|
namespace osu.Game.Rulesets
|
||||||
{
|
{
|
||||||
@ -44,6 +45,8 @@ namespace osu.Game.Rulesets
|
|||||||
|
|
||||||
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().First();
|
public ModAutoplay GetAutoplayMod() => GetAllMods().OfType<ModAutoplay>().First();
|
||||||
|
|
||||||
|
public virtual ISkin CreateLegacySkinProvider(ISkinSource source) => null;
|
||||||
|
|
||||||
protected Ruleset(RulesetInfo rulesetInfo = null)
|
protected Ruleset(RulesetInfo rulesetInfo = null)
|
||||||
{
|
{
|
||||||
RulesetInfo = rulesetInfo ?? createRulesetInfo();
|
RulesetInfo = rulesetInfo ?? createRulesetInfo();
|
||||||
|
@ -39,7 +39,7 @@ namespace osu.Game.Screens.Edit
|
|||||||
|
|
||||||
public Storyboard Storyboard => workingBeatmap.Storyboard;
|
public Storyboard Storyboard => workingBeatmap.Storyboard;
|
||||||
|
|
||||||
public Skin Skin => workingBeatmap.Skin;
|
public ISkin Skin => workingBeatmap.Skin;
|
||||||
|
|
||||||
public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods) => playableBeatmap;
|
public IBeatmap GetPlayableBeatmap(RulesetInfo ruleset, IReadOnlyList<Mod> mods) => playableBeatmap;
|
||||||
}
|
}
|
||||||
|
@ -60,7 +60,9 @@ namespace osu.Game.Screens.Play
|
|||||||
[Resolved]
|
[Resolved]
|
||||||
private ScoreManager scoreManager { get; set; }
|
private ScoreManager scoreManager { get; set; }
|
||||||
|
|
||||||
private RulesetInfo ruleset;
|
private RulesetInfo rulesetInfo;
|
||||||
|
|
||||||
|
private Ruleset ruleset;
|
||||||
|
|
||||||
private IAPIProvider api;
|
private IAPIProvider api;
|
||||||
|
|
||||||
@ -121,21 +123,53 @@ namespace osu.Game.Screens.Play
|
|||||||
|
|
||||||
InternalChild = GameplayClockContainer = new GameplayClockContainer(working, Mods.Value, DrawableRuleset.GameplayStartTime);
|
InternalChild = GameplayClockContainer = new GameplayClockContainer(working, Mods.Value, DrawableRuleset.GameplayStartTime);
|
||||||
|
|
||||||
GameplayClockContainer.Children = new[]
|
addUnderlayComponents(GameplayClockContainer);
|
||||||
|
addGameplayComponents(GameplayClockContainer, working);
|
||||||
|
addOverlayComponents(GameplayClockContainer, working);
|
||||||
|
|
||||||
|
DrawableRuleset.HasReplayLoaded.BindValueChanged(e => HUDOverlay.HoldToQuit.PauseOnFocusLost = !e.NewValue && PauseOnFocusLost, true);
|
||||||
|
|
||||||
|
// bind clock into components that require it
|
||||||
|
DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused);
|
||||||
|
|
||||||
|
// Bind ScoreProcessor to ourselves
|
||||||
|
ScoreProcessor.AllJudged += onCompletion;
|
||||||
|
ScoreProcessor.Failed += onFail;
|
||||||
|
|
||||||
|
foreach (var mod in Mods.Value.OfType<IApplicableToScoreProcessor>())
|
||||||
|
mod.ApplyToScoreProcessor(ScoreProcessor);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addUnderlayComponents(Container target)
|
||||||
{
|
{
|
||||||
DimmableStoryboard = new DimmableStoryboard(Beatmap.Value.Storyboard) { RelativeSizeAxes = Axes.Both },
|
target.Add(DimmableStoryboard = new DimmableStoryboard(Beatmap.Value.Storyboard) { RelativeSizeAxes = Axes.Both });
|
||||||
new ScalingContainer(ScalingMode.Gameplay)
|
}
|
||||||
|
|
||||||
|
private void addGameplayComponents(Container target, WorkingBeatmap working)
|
||||||
{
|
{
|
||||||
Child = new LocalSkinOverrideContainer(working.Skin)
|
var beatmapSkinProvider = new BeatmapSkinProvidingContainer(working.Skin);
|
||||||
{
|
|
||||||
RelativeSizeAxes = Axes.Both,
|
// the beatmapSkinProvider is used as the fallback source here to allow the ruleset-specific skin implementation
|
||||||
Children = new Drawable[]
|
// full access to all skin sources.
|
||||||
|
var rulesetSkinProvider = new SkinProvidingContainer(ruleset.CreateLegacySkinProvider(beatmapSkinProvider));
|
||||||
|
|
||||||
|
// load the skinning hierarchy first.
|
||||||
|
// this is intentionally done in two stages to ensure things are in a loaded state before exposing the ruleset to skin sources.
|
||||||
|
target.Add(new ScalingContainer(ScalingMode.Gameplay)
|
||||||
|
.WithChild(beatmapSkinProvider
|
||||||
|
.WithChild(target = rulesetSkinProvider)));
|
||||||
|
|
||||||
|
target.AddRange(new Drawable[]
|
||||||
{
|
{
|
||||||
DrawableRuleset,
|
DrawableRuleset,
|
||||||
new ComboEffects(ScoreProcessor)
|
new ComboEffects(ScoreProcessor)
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
},
|
private void addOverlayComponents(Container target, WorkingBeatmap working)
|
||||||
|
{
|
||||||
|
target.AddRange(new[]
|
||||||
|
{
|
||||||
breakOverlay = new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, ScoreProcessor)
|
breakOverlay = new BreakOverlay(working.Beatmap.BeatmapInfo.LetterboxInBreaks, ScoreProcessor)
|
||||||
{
|
{
|
||||||
Anchor = Anchor.Centre,
|
Anchor = Anchor.Centre,
|
||||||
@ -194,19 +228,7 @@ namespace osu.Game.Screens.Play
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, }
|
failAnimation = new FailAnimation(DrawableRuleset) { OnComplete = onFailComplete, }
|
||||||
};
|
});
|
||||||
|
|
||||||
DrawableRuleset.HasReplayLoaded.BindValueChanged(e => HUDOverlay.HoldToQuit.PauseOnFocusLost = !e.NewValue && PauseOnFocusLost, true);
|
|
||||||
|
|
||||||
// bind clock into components that require it
|
|
||||||
DrawableRuleset.IsPaused.BindTo(GameplayClockContainer.IsPaused);
|
|
||||||
|
|
||||||
// Bind ScoreProcessor to ourselves
|
|
||||||
ScoreProcessor.AllJudged += onCompletion;
|
|
||||||
ScoreProcessor.Failed += onFail;
|
|
||||||
|
|
||||||
foreach (var mod in Mods.Value.OfType<IApplicableToScoreProcessor>())
|
|
||||||
mod.ApplyToScoreProcessor(ScoreProcessor);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private WorkingBeatmap loadBeatmap()
|
private WorkingBeatmap loadBeatmap()
|
||||||
@ -222,20 +244,20 @@ namespace osu.Game.Screens.Play
|
|||||||
if (beatmap == null)
|
if (beatmap == null)
|
||||||
throw new InvalidOperationException("Beatmap was not loaded");
|
throw new InvalidOperationException("Beatmap was not loaded");
|
||||||
|
|
||||||
ruleset = Ruleset.Value ?? beatmap.BeatmapInfo.Ruleset;
|
rulesetInfo = Ruleset.Value ?? beatmap.BeatmapInfo.Ruleset;
|
||||||
var rulesetInstance = ruleset.CreateInstance();
|
ruleset = rulesetInfo.CreateInstance();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
DrawableRuleset = rulesetInstance.CreateDrawableRulesetWith(working, Mods.Value);
|
DrawableRuleset = ruleset.CreateDrawableRulesetWith(working, Mods.Value);
|
||||||
}
|
}
|
||||||
catch (BeatmapInvalidForRulesetException)
|
catch (BeatmapInvalidForRulesetException)
|
||||||
{
|
{
|
||||||
// we may fail to create a DrawableRuleset if the beatmap cannot be loaded with the user's preferred ruleset
|
// we may fail to create a DrawableRuleset if the beatmap cannot be loaded with the user's preferred ruleset
|
||||||
// let's try again forcing the beatmap's ruleset.
|
// let's try again forcing the beatmap's ruleset.
|
||||||
ruleset = beatmap.BeatmapInfo.Ruleset;
|
rulesetInfo = beatmap.BeatmapInfo.Ruleset;
|
||||||
rulesetInstance = ruleset.CreateInstance();
|
ruleset = rulesetInfo.CreateInstance();
|
||||||
DrawableRuleset = rulesetInstance.CreateDrawableRulesetWith(Beatmap.Value, Mods.Value);
|
DrawableRuleset = ruleset.CreateDrawableRulesetWith(Beatmap.Value, Mods.Value);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!DrawableRuleset.Objects.Any())
|
if (!DrawableRuleset.Objects.Any())
|
||||||
@ -313,7 +335,7 @@ namespace osu.Game.Screens.Play
|
|||||||
var score = DrawableRuleset.ReplayScore?.ScoreInfo ?? new ScoreInfo
|
var score = DrawableRuleset.ReplayScore?.ScoreInfo ?? new ScoreInfo
|
||||||
{
|
{
|
||||||
Beatmap = Beatmap.Value.BeatmapInfo,
|
Beatmap = Beatmap.Value.BeatmapInfo,
|
||||||
Ruleset = ruleset,
|
Ruleset = rulesetInfo,
|
||||||
Mods = Mods.Value.ToArray(),
|
Mods = Mods.Value.ToArray(),
|
||||||
User = api.LocalUser.Value,
|
User = api.LocalUser.Value,
|
||||||
};
|
};
|
||||||
|
39
osu.Game/Skinning/BeatmapSkinProvidingContainer.cs
Normal file
39
osu.Game/Skinning/BeatmapSkinProvidingContainer.cs
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
// 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.Allocation;
|
||||||
|
using osu.Framework.Bindables;
|
||||||
|
using osu.Game.Audio;
|
||||||
|
using osu.Game.Configuration;
|
||||||
|
|
||||||
|
namespace osu.Game.Skinning
|
||||||
|
{
|
||||||
|
/// <summary>
|
||||||
|
/// A container which overrides existing skin options with beatmap-local values.
|
||||||
|
/// </summary>
|
||||||
|
public class BeatmapSkinProvidingContainer : SkinProvidingContainer
|
||||||
|
{
|
||||||
|
private readonly Bindable<bool> beatmapSkins = new Bindable<bool>();
|
||||||
|
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 AllowTextureLookup(string componentName) => beatmapSkins.Value;
|
||||||
|
protected override bool AllowSampleLookup(ISampleInfo componentName) => beatmapHitsounds.Value;
|
||||||
|
|
||||||
|
public BeatmapSkinProvidingContainer(ISkin skin)
|
||||||
|
: base(skin)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[BackgroundDependencyLoader]
|
||||||
|
private void load(OsuConfigManager config)
|
||||||
|
{
|
||||||
|
config.BindWith(OsuSetting.BeatmapSkins, beatmapSkins);
|
||||||
|
config.BindWith(OsuSetting.BeatmapHitsounds, beatmapHitsounds);
|
||||||
|
|
||||||
|
beatmapSkins.BindValueChanged(_ => TriggerSourceChanged());
|
||||||
|
beatmapHitsounds.BindValueChanged(_ => TriggerSourceChanged());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,30 +1,14 @@
|
|||||||
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Threading.Tasks;
|
|
||||||
using osu.Framework.Allocation;
|
|
||||||
using osu.Framework.Audio;
|
using osu.Framework.Audio;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Animations;
|
|
||||||
using osu.Framework.Graphics.Containers;
|
|
||||||
using osu.Framework.Graphics.Sprites;
|
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Framework.IO.Stores;
|
using osu.Framework.IO.Stores;
|
||||||
using osu.Framework.Text;
|
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Database;
|
|
||||||
using osu.Game.Graphics;
|
|
||||||
using osu.Game.Graphics.Sprites;
|
|
||||||
using osu.Game.Rulesets.Objects.Drawables;
|
|
||||||
using osu.Game.Rulesets.Objects.Types;
|
|
||||||
using osu.Game.Rulesets.UI;
|
|
||||||
using osuTK;
|
|
||||||
using osuTK.Graphics;
|
using osuTK.Graphics;
|
||||||
|
|
||||||
namespace osu.Game.Skinning
|
namespace osu.Game.Skinning
|
||||||
@ -35,13 +19,6 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
protected IResourceStore<SampleChannel> Samples;
|
protected IResourceStore<SampleChannel> Samples;
|
||||||
|
|
||||||
/// <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>
|
|
||||||
private const float legacy_circle_radius = 64 - 5;
|
|
||||||
|
|
||||||
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
|
public LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager)
|
||||||
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini")
|
: this(skin, new LegacySkinResourceStore<SkinFileInfo>(skin, storage), audioManager, "skin.ini")
|
||||||
{
|
{
|
||||||
@ -49,8 +26,6 @@ namespace osu.Game.Skinning
|
|||||||
if (!Configuration.CustomColours.ContainsKey("SliderBall")) Configuration.CustomColours["SliderBall"] = new Color4(2, 170, 255, 255);
|
if (!Configuration.CustomColours.ContainsKey("SliderBall")) Configuration.CustomColours["SliderBall"] = new Color4(2, 170, 255, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly bool hasHitCircle;
|
|
||||||
|
|
||||||
protected LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, string filename)
|
protected LegacySkin(SkinInfo skin, IResourceStore<byte[]> storage, AudioManager audioManager, string filename)
|
||||||
: base(skin)
|
: base(skin)
|
||||||
{
|
{
|
||||||
@ -63,14 +38,6 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
Samples = audioManager.GetSampleStore(storage);
|
Samples = audioManager.GetSampleStore(storage);
|
||||||
Textures = new TextureStore(new TextureLoaderStore(storage));
|
Textures = new TextureStore(new TextureLoaderStore(storage));
|
||||||
|
|
||||||
using (var testStream = storage.GetStream("hitcircle@2x") ?? storage.GetStream("hitcircle"))
|
|
||||||
hasHitCircle |= testStream != null;
|
|
||||||
|
|
||||||
if (hasHitCircle)
|
|
||||||
{
|
|
||||||
Configuration.SliderPathRadius = legacy_circle_radius;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void Dispose(bool isDisposing)
|
protected override void Dispose(bool isDisposing)
|
||||||
@ -80,8 +47,6 @@ namespace osu.Game.Skinning
|
|||||||
Samples?.Dispose();
|
Samples?.Dispose();
|
||||||
}
|
}
|
||||||
|
|
||||||
private const double default_frame_time = 1000 / 60d;
|
|
||||||
|
|
||||||
public override Drawable GetDrawableComponent(string componentName)
|
public override Drawable GetDrawableComponent(string componentName)
|
||||||
{
|
{
|
||||||
bool animatable = false;
|
bool animatable = false;
|
||||||
@ -89,40 +54,6 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
switch (componentName)
|
switch (componentName)
|
||||||
{
|
{
|
||||||
case "Play/osu/cursor":
|
|
||||||
if (GetTexture("cursor") != null)
|
|
||||||
return new LegacyCursor();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
case "Play/osu/sliderball":
|
|
||||||
var sliderBallContent = getAnimation("sliderb", true, true, "");
|
|
||||||
|
|
||||||
if (sliderBallContent != null)
|
|
||||||
{
|
|
||||||
var size = sliderBallContent.Size;
|
|
||||||
|
|
||||||
sliderBallContent.RelativeSizeAxes = Axes.Both;
|
|
||||||
sliderBallContent.Size = Vector2.One;
|
|
||||||
|
|
||||||
return new LegacySliderBall(sliderBallContent)
|
|
||||||
{
|
|
||||||
Size = size
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
case "Play/osu/hitcircle":
|
|
||||||
if (hasHitCircle)
|
|
||||||
return new LegacyMainCirclePiece();
|
|
||||||
|
|
||||||
return null;
|
|
||||||
|
|
||||||
case "Play/osu/sliderfollowcircle":
|
|
||||||
animatable = true;
|
|
||||||
break;
|
|
||||||
|
|
||||||
case "Play/Miss":
|
case "Play/Miss":
|
||||||
componentName = "hit0";
|
componentName = "hit0";
|
||||||
animatable = true;
|
animatable = true;
|
||||||
@ -146,19 +77,9 @@ namespace osu.Game.Skinning
|
|||||||
animatable = true;
|
animatable = true;
|
||||||
looping = false;
|
looping = false;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case "Play/osu/number-text":
|
|
||||||
return !hasFont(Configuration.HitCircleFont)
|
|
||||||
? null
|
|
||||||
: new LegacySpriteText(this, Configuration.HitCircleFont)
|
|
||||||
{
|
|
||||||
Scale = new Vector2(0.96f),
|
|
||||||
// Spacing value was reverse-engineered from the ratio of the rendered sprite size in the visual inspector vs the actual texture size
|
|
||||||
Spacing = new Vector2(-Configuration.HitCircleOverlap * 0.89f, 0)
|
|
||||||
};
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return getAnimation(componentName, animatable, looping);
|
return this.GetAnimation(componentName, animatable, looping);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override Texture GetTexture(string componentName)
|
public override Texture GetTexture(string componentName)
|
||||||
@ -197,298 +118,10 @@ namespace osu.Game.Skinning
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool hasFont(string fontName) => GetTexture($"{fontName}-0") != null;
|
|
||||||
|
|
||||||
private string getFallbackName(string componentName)
|
private string getFallbackName(string componentName)
|
||||||
{
|
{
|
||||||
string lastPiece = componentName.Split('/').Last();
|
string lastPiece = componentName.Split('/').Last();
|
||||||
return componentName.StartsWith("Gameplay/taiko/") ? "taiko-" + lastPiece : lastPiece;
|
return componentName.StartsWith("Gameplay/taiko/") ? "taiko-" + lastPiece : lastPiece;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Drawable getAnimation(string componentName, bool animatable, bool looping, string animationSeparator = "-")
|
|
||||||
{
|
|
||||||
Texture texture;
|
|
||||||
|
|
||||||
Texture getFrameTexture(int frame) => GetTexture($"{componentName}{animationSeparator}{frame}");
|
|
||||||
|
|
||||||
TextureAnimation animation = null;
|
|
||||||
|
|
||||||
if (animatable)
|
|
||||||
{
|
|
||||||
for (int i = 0;; i++)
|
|
||||||
{
|
|
||||||
if ((texture = getFrameTexture(i)) == null)
|
|
||||||
break;
|
|
||||||
|
|
||||||
if (animation == null)
|
|
||||||
animation = new TextureAnimation
|
|
||||||
{
|
|
||||||
DefaultFrameLength = default_frame_time,
|
|
||||||
Repeat = looping
|
|
||||||
};
|
|
||||||
|
|
||||||
animation.AddFrame(texture);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (animation != null)
|
|
||||||
return animation;
|
|
||||||
|
|
||||||
if ((texture = GetTexture(componentName)) != null)
|
|
||||||
return new Sprite { Texture = texture };
|
|
||||||
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected class LegacySkinResourceStore<T> : IResourceStore<byte[]>
|
|
||||||
where T : INamedFileInfo
|
|
||||||
{
|
|
||||||
private readonly IHasFiles<T> source;
|
|
||||||
private readonly IResourceStore<byte[]> underlyingStore;
|
|
||||||
|
|
||||||
private string getPathForFile(string filename)
|
|
||||||
{
|
|
||||||
if (source.Files == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
bool hasExtension = filename.Contains('.');
|
|
||||||
|
|
||||||
var file = source.Files.Find(f =>
|
|
||||||
string.Equals(hasExtension ? f.Filename : Path.ChangeExtension(f.Filename, null), filename, StringComparison.InvariantCultureIgnoreCase));
|
|
||||||
return file?.FileInfo.StoragePath;
|
|
||||||
}
|
|
||||||
|
|
||||||
public LegacySkinResourceStore(IHasFiles<T> source, IResourceStore<byte[]> underlyingStore)
|
|
||||||
{
|
|
||||||
this.source = source;
|
|
||||||
this.underlyingStore = underlyingStore;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Stream GetStream(string name)
|
|
||||||
{
|
|
||||||
string path = getPathForFile(name);
|
|
||||||
return path == null ? null : underlyingStore.GetStream(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
public IEnumerable<string> GetAvailableResources() => source.Files.Select(f => f.Filename);
|
|
||||||
|
|
||||||
byte[] IResourceStore<byte[]>.Get(string name) => GetAsync(name).Result;
|
|
||||||
|
|
||||||
public Task<byte[]> GetAsync(string name)
|
|
||||||
{
|
|
||||||
string path = getPathForFile(name);
|
|
||||||
return path == null ? Task.FromResult<byte[]>(null) : underlyingStore.GetAsync(path);
|
|
||||||
}
|
|
||||||
|
|
||||||
#region IDisposable Support
|
|
||||||
|
|
||||||
private bool isDisposed;
|
|
||||||
|
|
||||||
protected virtual void Dispose(bool disposing)
|
|
||||||
{
|
|
||||||
if (!isDisposed)
|
|
||||||
{
|
|
||||||
isDisposed = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
~LegacySkinResourceStore()
|
|
||||||
{
|
|
||||||
Dispose(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void Dispose()
|
|
||||||
{
|
|
||||||
Dispose(true);
|
|
||||||
GC.SuppressFinalize(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
}
|
|
||||||
|
|
||||||
private class LegacySpriteText : OsuSpriteText
|
|
||||||
{
|
|
||||||
private readonly LegacyGlyphStore glyphStore;
|
|
||||||
|
|
||||||
public LegacySpriteText(ISkin skin, string font)
|
|
||||||
{
|
|
||||||
Shadow = false;
|
|
||||||
UseFullGlyphHeight = false;
|
|
||||||
|
|
||||||
Font = new FontUsage(font, OsuFont.DEFAULT_FONT_SIZE);
|
|
||||||
glyphStore = new LegacyGlyphStore(skin);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
|
|
||||||
|
|
||||||
private class LegacyGlyphStore : ITexturedGlyphLookupStore
|
|
||||||
{
|
|
||||||
private readonly ISkin skin;
|
|
||||||
|
|
||||||
public LegacyGlyphStore(ISkin skin)
|
|
||||||
{
|
|
||||||
this.skin = skin;
|
|
||||||
}
|
|
||||||
|
|
||||||
public ITexturedCharacterGlyph Get(string fontName, char character)
|
|
||||||
{
|
|
||||||
var texture = skin.GetTexture($"{fontName}-{character}");
|
|
||||||
|
|
||||||
if (texture != null)
|
|
||||||
// Approximate value that brings character sizing roughly in-line with stable
|
|
||||||
texture.ScaleAdjust *= 18;
|
|
||||||
|
|
||||||
if (texture == null)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture.Width, null), texture, 1f / texture.ScaleAdjust);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Task<ITexturedCharacterGlyph> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LegacyCursor : CompositeDrawable
|
|
||||||
{
|
|
||||||
public LegacyCursor()
|
|
||||||
{
|
|
||||||
Size = new Vector2(50);
|
|
||||||
|
|
||||||
Anchor = Anchor.Centre;
|
|
||||||
Origin = Anchor.Centre;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(ISkinSource skin)
|
|
||||||
{
|
|
||||||
InternalChildren = new Drawable[]
|
|
||||||
{
|
|
||||||
new NonPlayfieldSprite
|
|
||||||
{
|
|
||||||
Texture = skin.GetTexture("cursormiddle"),
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
},
|
|
||||||
new NonPlayfieldSprite
|
|
||||||
{
|
|
||||||
Texture = skin.GetTexture("cursor"),
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LegacySliderBall : CompositeDrawable
|
|
||||||
{
|
|
||||||
private readonly Drawable animationContent;
|
|
||||||
|
|
||||||
public LegacySliderBall(Drawable animationContent)
|
|
||||||
{
|
|
||||||
this.animationContent = animationContent;
|
|
||||||
}
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(ISkinSource skin, DrawableHitObject drawableObject)
|
|
||||||
{
|
|
||||||
animationContent.Colour = skin.GetValue<SkinConfiguration, Color4?>(s => s.CustomColours.ContainsKey("SliderBall") ? s.CustomColours["SliderBall"] : (Color4?)null) ?? Color4.White;
|
|
||||||
|
|
||||||
InternalChildren = new[]
|
|
||||||
{
|
|
||||||
new Sprite
|
|
||||||
{
|
|
||||||
Texture = skin.GetTexture("sliderb-nd"),
|
|
||||||
Colour = new Color4(5, 5, 5, 255),
|
|
||||||
},
|
|
||||||
animationContent,
|
|
||||||
new Sprite
|
|
||||||
{
|
|
||||||
Texture = skin.GetTexture("sliderb-spec"),
|
|
||||||
Blending = BlendingParameters.Additive,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class LegacyMainCirclePiece : CompositeDrawable
|
|
||||||
{
|
|
||||||
public LegacyMainCirclePiece()
|
|
||||||
{
|
|
||||||
Size = new Vector2(128);
|
|
||||||
}
|
|
||||||
|
|
||||||
private readonly IBindable<ArmedState> state = new Bindable<ArmedState>();
|
|
||||||
|
|
||||||
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
|
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
|
||||||
private void load(DrawableHitObject drawableObject, ISkinSource skin)
|
|
||||||
{
|
|
||||||
Sprite hitCircleSprite;
|
|
||||||
|
|
||||||
InternalChildren = new Drawable[]
|
|
||||||
{
|
|
||||||
hitCircleSprite = new Sprite
|
|
||||||
{
|
|
||||||
Texture = skin.GetTexture("hitcircle"),
|
|
||||||
Colour = drawableObject.AccentColour.Value,
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
},
|
|
||||||
new SkinnableSpriteText("Play/osu/number-text", _ => new OsuSpriteText
|
|
||||||
{
|
|
||||||
Font = OsuFont.Numeric.With(size: 40),
|
|
||||||
UseFullGlyphHeight = false,
|
|
||||||
}, confineMode: ConfineMode.NoScaling)
|
|
||||||
{
|
|
||||||
Text = (((IHasComboInformation)drawableObject.HitObject).IndexInCurrentCombo + 1).ToString()
|
|
||||||
},
|
|
||||||
new Sprite
|
|
||||||
{
|
|
||||||
Texture = skin.GetTexture("hitcircleoverlay"),
|
|
||||||
Anchor = Anchor.Centre,
|
|
||||||
Origin = Anchor.Centre,
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
state.BindTo(drawableObject.State);
|
|
||||||
state.BindValueChanged(updateState, true);
|
|
||||||
|
|
||||||
accentColour.BindTo(drawableObject.AccentColour);
|
|
||||||
accentColour.BindValueChanged(colour => hitCircleSprite.Colour = colour.NewValue, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateState(ValueChangedEvent<ArmedState> state)
|
|
||||||
{
|
|
||||||
const double legacy_fade_duration = 240;
|
|
||||||
|
|
||||||
switch (state.NewValue)
|
|
||||||
{
|
|
||||||
case ArmedState.Hit:
|
|
||||||
this.FadeOut(legacy_fade_duration, Easing.Out);
|
|
||||||
this.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// A sprite which is displayed within the playfield, but historically was not considered part of the playfield.
|
|
||||||
/// Performs scale adjustment to undo the scale applied by <see cref="PlayfieldAdjustmentContainer"/> (osu! ruleset specifically).
|
|
||||||
/// </summary>
|
|
||||||
private class NonPlayfieldSprite : Sprite
|
|
||||||
{
|
|
||||||
public override Texture Texture
|
|
||||||
{
|
|
||||||
get => base.Texture;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
if (value != null)
|
|
||||||
// stable "magic ratio". see OsuPlayfieldAdjustmentContainer for full explanation.
|
|
||||||
value.ScaleAdjust *= 1.6f;
|
|
||||||
base.Texture = value;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
53
osu.Game/Skinning/LegacySkinExtensions.cs
Normal file
53
osu.Game/Skinning/LegacySkinExtensions.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// 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.Graphics;
|
||||||
|
using osu.Framework.Graphics.Animations;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Graphics.Textures;
|
||||||
|
|
||||||
|
namespace osu.Game.Skinning
|
||||||
|
{
|
||||||
|
public static class LegacySkinExtensions
|
||||||
|
{
|
||||||
|
public static Drawable GetAnimation(this ISkin source, string componentName, bool animatable, bool looping, string animationSeparator = "-")
|
||||||
|
{
|
||||||
|
const double default_frame_time = 1000 / 60d;
|
||||||
|
|
||||||
|
Texture texture;
|
||||||
|
|
||||||
|
Texture getFrameTexture(int frame) => source.GetTexture($"{componentName}{animationSeparator}{frame}");
|
||||||
|
|
||||||
|
TextureAnimation animation = null;
|
||||||
|
|
||||||
|
if (animatable)
|
||||||
|
{
|
||||||
|
for (int i = 0;; i++)
|
||||||
|
{
|
||||||
|
if ((texture = getFrameTexture(i)) == null)
|
||||||
|
break;
|
||||||
|
|
||||||
|
if (animation == null)
|
||||||
|
animation = new TextureAnimation
|
||||||
|
{
|
||||||
|
DefaultFrameLength = default_frame_time,
|
||||||
|
Repeat = looping
|
||||||
|
};
|
||||||
|
|
||||||
|
animation.AddFrame(texture);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (animation != null)
|
||||||
|
return animation;
|
||||||
|
|
||||||
|
if ((texture = source.GetTexture(componentName)) != null)
|
||||||
|
return new Sprite
|
||||||
|
{
|
||||||
|
Texture = texture
|
||||||
|
};
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
79
osu.Game/Skinning/LegacySkinResourceStore.cs
Normal file
79
osu.Game/Skinning/LegacySkinResourceStore.cs
Normal file
@ -0,0 +1,79 @@
|
|||||||
|
// 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;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Threading.Tasks;
|
||||||
|
using osu.Framework.IO.Stores;
|
||||||
|
using osu.Game.Database;
|
||||||
|
|
||||||
|
namespace osu.Game.Skinning
|
||||||
|
{
|
||||||
|
public class LegacySkinResourceStore<T> : IResourceStore<byte[]>
|
||||||
|
where T : INamedFileInfo
|
||||||
|
{
|
||||||
|
private readonly IHasFiles<T> source;
|
||||||
|
private readonly IResourceStore<byte[]> underlyingStore;
|
||||||
|
|
||||||
|
private string getPathForFile(string filename)
|
||||||
|
{
|
||||||
|
if (source.Files == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
bool hasExtension = filename.Contains('.');
|
||||||
|
|
||||||
|
var file = source.Files.Find(f =>
|
||||||
|
string.Equals(hasExtension ? f.Filename : Path.ChangeExtension(f.Filename, null), filename, StringComparison.InvariantCultureIgnoreCase));
|
||||||
|
return file?.FileInfo.StoragePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public LegacySkinResourceStore(IHasFiles<T> source, IResourceStore<byte[]> underlyingStore)
|
||||||
|
{
|
||||||
|
this.source = source;
|
||||||
|
this.underlyingStore = underlyingStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Stream GetStream(string name)
|
||||||
|
{
|
||||||
|
string path = getPathForFile(name);
|
||||||
|
return path == null ? null : underlyingStore.GetStream(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<string> GetAvailableResources() => source.Files.Select(f => f.Filename);
|
||||||
|
|
||||||
|
byte[] IResourceStore<byte[]>.Get(string name) => GetAsync(name).Result;
|
||||||
|
|
||||||
|
public Task<byte[]> GetAsync(string name)
|
||||||
|
{
|
||||||
|
string path = getPathForFile(name);
|
||||||
|
return path == null ? Task.FromResult<byte[]>(null) : underlyingStore.GetAsync(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
#region IDisposable Support
|
||||||
|
|
||||||
|
private bool isDisposed;
|
||||||
|
|
||||||
|
protected virtual void Dispose(bool disposing)
|
||||||
|
{
|
||||||
|
if (!isDisposed)
|
||||||
|
{
|
||||||
|
isDisposed = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
~LegacySkinResourceStore()
|
||||||
|
{
|
||||||
|
Dispose(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
Dispose(true);
|
||||||
|
GC.SuppressFinalize(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
}
|
||||||
|
}
|
53
osu.Game/Skinning/LegacySpriteText.cs
Normal file
53
osu.Game/Skinning/LegacySpriteText.cs
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// 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.Threading.Tasks;
|
||||||
|
using osu.Framework.Graphics.Sprites;
|
||||||
|
using osu.Framework.Text;
|
||||||
|
using osu.Game.Graphics;
|
||||||
|
using osu.Game.Graphics.Sprites;
|
||||||
|
|
||||||
|
namespace osu.Game.Skinning
|
||||||
|
{
|
||||||
|
public class LegacySpriteText : OsuSpriteText
|
||||||
|
{
|
||||||
|
private readonly LegacyGlyphStore glyphStore;
|
||||||
|
|
||||||
|
public LegacySpriteText(ISkin skin, string font)
|
||||||
|
{
|
||||||
|
Shadow = false;
|
||||||
|
UseFullGlyphHeight = false;
|
||||||
|
|
||||||
|
Font = new FontUsage(font, OsuFont.DEFAULT_FONT_SIZE);
|
||||||
|
glyphStore = new LegacyGlyphStore(skin);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override TextBuilder CreateTextBuilder(ITexturedGlyphLookupStore store) => base.CreateTextBuilder(glyphStore);
|
||||||
|
|
||||||
|
private class LegacyGlyphStore : ITexturedGlyphLookupStore
|
||||||
|
{
|
||||||
|
private readonly ISkin skin;
|
||||||
|
|
||||||
|
public LegacyGlyphStore(ISkin skin)
|
||||||
|
{
|
||||||
|
this.skin = skin;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ITexturedCharacterGlyph Get(string fontName, char character)
|
||||||
|
{
|
||||||
|
var texture = skin.GetTexture($"{fontName}-{character}");
|
||||||
|
|
||||||
|
if (texture != null)
|
||||||
|
// Approximate value that brings character sizing roughly in-line with stable
|
||||||
|
texture.ScaleAdjust *= 18;
|
||||||
|
|
||||||
|
if (texture == null)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
return new TexturedCharacterGlyph(new CharacterGlyph(character, 0, 0, texture.Width, null), texture, 1f / texture.ScaleAdjust);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Task<ITexturedCharacterGlyph> GetAsync(string fontName, char character) => Task.Run(() => Get(fontName, character));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -4,38 +4,43 @@
|
|||||||
using System;
|
using System;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Audio.Sample;
|
using osu.Framework.Audio.Sample;
|
||||||
using osu.Framework.Bindables;
|
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Graphics.Textures;
|
using osu.Framework.Graphics.Textures;
|
||||||
using osu.Game.Audio;
|
using osu.Game.Audio;
|
||||||
using osu.Game.Configuration;
|
|
||||||
|
|
||||||
namespace osu.Game.Skinning
|
namespace osu.Game.Skinning
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A container which overrides existing skin options with beatmap-local values.
|
/// A container which adds a local <see cref="ISkinSource"/> to the hierarchy.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public class LocalSkinOverrideContainer : Container, ISkinSource
|
public class SkinProvidingContainer : Container, ISkinSource
|
||||||
{
|
{
|
||||||
public event Action SourceChanged;
|
public event Action SourceChanged;
|
||||||
|
|
||||||
private readonly Bindable<bool> beatmapSkins = new Bindable<bool>();
|
|
||||||
private readonly Bindable<bool> beatmapHitsounds = new Bindable<bool>();
|
|
||||||
|
|
||||||
private readonly ISkin skin;
|
private readonly ISkin skin;
|
||||||
|
|
||||||
private ISkinSource fallbackSource;
|
private ISkinSource fallbackSource;
|
||||||
|
|
||||||
public LocalSkinOverrideContainer(ISkin skin)
|
protected virtual bool AllowDrawableLookup(string componentName) => true;
|
||||||
|
|
||||||
|
protected virtual bool AllowTextureLookup(string componentName) => true;
|
||||||
|
|
||||||
|
protected virtual bool AllowSampleLookup(ISampleInfo componentName) => true;
|
||||||
|
|
||||||
|
protected virtual bool AllowConfigurationLookup => true;
|
||||||
|
|
||||||
|
public SkinProvidingContainer(ISkin skin)
|
||||||
{
|
{
|
||||||
this.skin = skin;
|
this.skin = skin;
|
||||||
|
|
||||||
|
RelativeSizeAxes = Axes.Both;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Drawable GetDrawableComponent(string componentName)
|
public Drawable GetDrawableComponent(string componentName)
|
||||||
{
|
{
|
||||||
Drawable sourceDrawable;
|
Drawable sourceDrawable;
|
||||||
if (beatmapSkins.Value && (sourceDrawable = skin?.GetDrawableComponent(componentName)) != null)
|
if (AllowDrawableLookup(componentName) && (sourceDrawable = skin?.GetDrawableComponent(componentName)) != null)
|
||||||
return sourceDrawable;
|
return sourceDrawable;
|
||||||
|
|
||||||
return fallbackSource?.GetDrawableComponent(componentName);
|
return fallbackSource?.GetDrawableComponent(componentName);
|
||||||
@ -44,7 +49,7 @@ namespace osu.Game.Skinning
|
|||||||
public Texture GetTexture(string componentName)
|
public Texture GetTexture(string componentName)
|
||||||
{
|
{
|
||||||
Texture sourceTexture;
|
Texture sourceTexture;
|
||||||
if (beatmapSkins.Value && (sourceTexture = skin?.GetTexture(componentName)) != null)
|
if (AllowTextureLookup(componentName) && (sourceTexture = skin?.GetTexture(componentName)) != null)
|
||||||
return sourceTexture;
|
return sourceTexture;
|
||||||
|
|
||||||
return fallbackSource.GetTexture(componentName);
|
return fallbackSource.GetTexture(componentName);
|
||||||
@ -53,7 +58,7 @@ namespace osu.Game.Skinning
|
|||||||
public SampleChannel GetSample(ISampleInfo sampleInfo)
|
public SampleChannel GetSample(ISampleInfo sampleInfo)
|
||||||
{
|
{
|
||||||
SampleChannel sourceChannel;
|
SampleChannel sourceChannel;
|
||||||
if (beatmapHitsounds.Value && (sourceChannel = skin?.GetSample(sampleInfo)) != null)
|
if (AllowSampleLookup(sampleInfo) && (sourceChannel = skin?.GetSample(sampleInfo)) != null)
|
||||||
return sourceChannel;
|
return sourceChannel;
|
||||||
|
|
||||||
return fallbackSource?.GetSample(sampleInfo);
|
return fallbackSource?.GetSample(sampleInfo);
|
||||||
@ -62,14 +67,13 @@ namespace osu.Game.Skinning
|
|||||||
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration
|
public TValue GetValue<TConfiguration, TValue>(Func<TConfiguration, TValue> query) where TConfiguration : SkinConfiguration
|
||||||
{
|
{
|
||||||
TValue val;
|
TValue val;
|
||||||
if ((skin as Skin)?.Configuration is TConfiguration conf)
|
if (AllowConfigurationLookup && skin != null && (val = skin.GetValue(query)) != null)
|
||||||
if (beatmapSkins.Value && (val = query.Invoke(conf)) != null)
|
|
||||||
return val;
|
return val;
|
||||||
|
|
||||||
return fallbackSource == null ? default : fallbackSource.GetValue(query);
|
return fallbackSource == null ? default : fallbackSource.GetValue(query);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void onSourceChanged() => SourceChanged?.Invoke();
|
protected virtual void TriggerSourceChanged() => SourceChanged?.Invoke();
|
||||||
|
|
||||||
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
|
||||||
{
|
{
|
||||||
@ -77,18 +81,10 @@ namespace osu.Game.Skinning
|
|||||||
|
|
||||||
fallbackSource = dependencies.Get<ISkinSource>();
|
fallbackSource = dependencies.Get<ISkinSource>();
|
||||||
if (fallbackSource != null)
|
if (fallbackSource != null)
|
||||||
fallbackSource.SourceChanged += onSourceChanged;
|
fallbackSource.SourceChanged += TriggerSourceChanged;
|
||||||
|
|
||||||
dependencies.CacheAs<ISkinSource>(this);
|
dependencies.CacheAs<ISkinSource>(this);
|
||||||
|
|
||||||
var config = dependencies.Get<OsuConfigManager>();
|
|
||||||
|
|
||||||
config.BindWith(OsuSetting.BeatmapSkins, beatmapSkins);
|
|
||||||
config.BindWith(OsuSetting.BeatmapHitsounds, beatmapHitsounds);
|
|
||||||
|
|
||||||
beatmapSkins.BindValueChanged(_ => onSourceChanged());
|
|
||||||
beatmapHitsounds.BindValueChanged(_ => onSourceChanged());
|
|
||||||
|
|
||||||
return dependencies;
|
return dependencies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -100,7 +96,7 @@ namespace osu.Game.Skinning
|
|||||||
base.Dispose(isDisposing);
|
base.Dispose(isDisposing);
|
||||||
|
|
||||||
if (fallbackSource != null)
|
if (fallbackSource != null)
|
||||||
fallbackSource.SourceChanged -= onSourceChanged;
|
fallbackSource.SourceChanged -= TriggerSourceChanged;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -16,7 +16,7 @@ namespace osu.Game.Skinning
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// The displayed component.
|
/// The displayed component.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
protected Drawable Drawable { get; private set; }
|
public Drawable Drawable { get; private set; }
|
||||||
|
|
||||||
private readonly string componentName;
|
private readonly string componentName;
|
||||||
|
|
||||||
|
@ -22,12 +22,13 @@ namespace osu.Game.Tests.Visual
|
|||||||
this.ruleset = ruleset;
|
this.ruleset = ruleset;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected OsuConfigManager LocalConfig;
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load()
|
private void load()
|
||||||
{
|
{
|
||||||
OsuConfigManager manager;
|
Dependencies.Cache(LocalConfig = new OsuConfigManager(LocalStorage));
|
||||||
Dependencies.Cache(manager = new OsuConfigManager(LocalStorage));
|
LocalConfig.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
|
||||||
manager.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
[SetUpSteps]
|
[SetUpSteps]
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
// 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.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
|
using osu.Game.Rulesets.UI;
|
||||||
using osu.Game.Screens.Play;
|
using osu.Game.Screens.Play;
|
||||||
|
|
||||||
namespace osu.Game.Tests.Visual
|
namespace osu.Game.Tests.Visual
|
||||||
@ -9,6 +10,8 @@ namespace osu.Game.Tests.Visual
|
|||||||
{
|
{
|
||||||
protected override bool PauseOnFocusLost => false;
|
protected override bool PauseOnFocusLost => false;
|
||||||
|
|
||||||
|
public new DrawableRuleset DrawableRuleset => base.DrawableRuleset;
|
||||||
|
|
||||||
public TestPlayer(bool allowPause = true, bool showResults = true)
|
public TestPlayer(bool allowPause = true, bool showResults = true)
|
||||||
: base(allowPause, showResults)
|
: base(allowPause, showResults)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user