2019-12-26 21:03:21 +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.
|
|
|
|
|
2022-06-17 15:37:17 +08:00
|
|
|
#nullable disable
|
|
|
|
|
2020-03-30 22:17:32 +08:00
|
|
|
using System;
|
2020-06-12 21:22:22 +08:00
|
|
|
using System.Collections.Generic;
|
2023-12-30 10:20:44 +08:00
|
|
|
using System.Linq;
|
2020-06-22 04:44:35 +08:00
|
|
|
using osu.Framework.Audio.Sample;
|
2020-12-07 11:32:52 +08:00
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics;
|
2023-12-30 10:20:44 +08:00
|
|
|
using osu.Framework.Testing;
|
2020-06-22 04:44:35 +08:00
|
|
|
using osu.Game.Audio;
|
2022-10-05 18:21:38 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2020-12-07 11:32:52 +08:00
|
|
|
using osu.Game.Rulesets.Mania.Beatmaps;
|
2020-06-22 04:44:35 +08:00
|
|
|
using osu.Game.Rulesets.Objects.Legacy;
|
2020-12-07 11:32:52 +08:00
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Skinning;
|
2019-12-26 21:03:21 +08:00
|
|
|
|
2020-12-07 11:32:52 +08:00
|
|
|
namespace osu.Game.Rulesets.Mania.Skinning.Legacy
|
2019-12-26 21:03:21 +08:00
|
|
|
{
|
2020-06-22 04:04:10 +08:00
|
|
|
public class ManiaLegacySkinTransformer : LegacySkinTransformer
|
2019-12-26 21:03:21 +08:00
|
|
|
{
|
2022-10-12 16:47:20 +08:00
|
|
|
public override bool IsProvidingLegacyResources => base.IsProvidingLegacyResources || hasKeyTexture.Value;
|
|
|
|
|
2020-06-12 21:22:22 +08:00
|
|
|
/// <summary>
|
2020-06-13 18:47:40 +08:00
|
|
|
/// Mapping of <see cref="HitResult"/> to their corresponding
|
2020-06-12 21:22:22 +08:00
|
|
|
/// <see cref="LegacyManiaSkinConfigurationLookups"/> value.
|
|
|
|
/// </summary>
|
2021-12-10 13:15:00 +08:00
|
|
|
private static readonly IReadOnlyDictionary<HitResult, LegacyManiaSkinConfigurationLookups> hit_result_mapping
|
2020-06-12 21:22:22 +08:00
|
|
|
= new Dictionary<HitResult, LegacyManiaSkinConfigurationLookups>
|
2020-06-13 11:31:34 +08:00
|
|
|
{
|
|
|
|
{ HitResult.Perfect, LegacyManiaSkinConfigurationLookups.Hit300g },
|
|
|
|
{ HitResult.Great, LegacyManiaSkinConfigurationLookups.Hit300 },
|
|
|
|
{ HitResult.Good, LegacyManiaSkinConfigurationLookups.Hit200 },
|
|
|
|
{ HitResult.Ok, LegacyManiaSkinConfigurationLookups.Hit100 },
|
|
|
|
{ HitResult.Meh, LegacyManiaSkinConfigurationLookups.Hit50 },
|
|
|
|
{ HitResult.Miss, LegacyManiaSkinConfigurationLookups.Hit0 }
|
|
|
|
};
|
2020-06-12 21:22:22 +08:00
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
/// Mapping of <see cref="HitResult"/> to their corresponding
|
|
|
|
/// default filenames.
|
|
|
|
/// </summary>
|
2021-12-10 13:15:00 +08:00
|
|
|
private static readonly IReadOnlyDictionary<HitResult, string> default_hit_result_skin_filenames
|
2020-06-12 21:22:22 +08:00
|
|
|
= new Dictionary<HitResult, string>
|
2020-06-13 11:31:34 +08:00
|
|
|
{
|
|
|
|
{ HitResult.Perfect, "mania-hit300g" },
|
|
|
|
{ HitResult.Great, "mania-hit300" },
|
|
|
|
{ HitResult.Good, "mania-hit200" },
|
|
|
|
{ HitResult.Ok, "mania-hit100" },
|
|
|
|
{ HitResult.Meh, "mania-hit50" },
|
|
|
|
{ HitResult.Miss, "mania-hit0" }
|
|
|
|
};
|
2020-06-12 21:22:22 +08:00
|
|
|
|
2021-06-09 18:34:42 +08:00
|
|
|
private readonly Lazy<bool> isLegacySkin;
|
2020-03-30 22:17:32 +08:00
|
|
|
|
2020-04-01 11:04:29 +08:00
|
|
|
/// <summary>
|
|
|
|
/// Whether texture for the keys exists.
|
|
|
|
/// Used to determine if the mania ruleset is skinned.
|
|
|
|
/// </summary>
|
2021-06-09 18:34:42 +08:00
|
|
|
private readonly Lazy<bool> hasKeyTexture;
|
2020-04-01 11:04:29 +08:00
|
|
|
|
2022-10-05 18:21:38 +08:00
|
|
|
private readonly ManiaBeatmap beatmap;
|
|
|
|
|
|
|
|
public ManiaLegacySkinTransformer(ISkin skin, IBeatmap beatmap)
|
2021-06-09 18:34:42 +08:00
|
|
|
: base(skin)
|
2019-12-26 21:03:21 +08:00
|
|
|
{
|
2022-10-05 18:21:38 +08:00
|
|
|
this.beatmap = (ManiaBeatmap)beatmap;
|
|
|
|
|
2021-10-22 13:41:59 +08:00
|
|
|
isLegacySkin = new Lazy<bool>(() => GetConfig<SkinConfiguration.LegacySetting, decimal>(SkinConfiguration.LegacySetting.Version) != null);
|
2021-06-09 18:34:42 +08:00
|
|
|
hasKeyTexture = new Lazy<bool>(() =>
|
|
|
|
{
|
2022-10-06 13:10:39 +08:00
|
|
|
string keyImage = this.GetManiaSkinConfig<string>(LegacyManiaSkinConfigurationLookups.KeyImage, 0)?.Value ?? "mania-key1";
|
2021-06-11 17:44:44 +08:00
|
|
|
return this.GetAnimation(keyImage, true, true) != null;
|
2021-06-09 18:34:42 +08:00
|
|
|
});
|
2019-12-26 21:03:21 +08:00
|
|
|
}
|
|
|
|
|
2022-11-09 15:04:56 +08:00
|
|
|
public override Drawable GetDrawableComponent(ISkinComponentLookup lookup)
|
2019-12-26 21:03:21 +08:00
|
|
|
{
|
2022-11-09 13:11:41 +08:00
|
|
|
switch (lookup)
|
2019-12-26 21:03:21 +08:00
|
|
|
{
|
2024-08-22 17:39:36 +08:00
|
|
|
case GlobalSkinnableContainerLookup containerLookup:
|
2024-08-08 23:19:36 +08:00
|
|
|
// Modifications for global components.
|
|
|
|
if (containerLookup.Ruleset == null)
|
|
|
|
return base.GetDrawableComponent(lookup);
|
|
|
|
|
2024-08-15 15:55:03 +08:00
|
|
|
// we don't have enough assets to display these components (this is especially the case on a "beatmap" skin).
|
|
|
|
if (!IsProvidingLegacyResources)
|
|
|
|
return null;
|
|
|
|
|
2024-08-23 13:48:50 +08:00
|
|
|
switch (containerLookup.Lookup)
|
2023-12-30 10:20:44 +08:00
|
|
|
{
|
2024-08-22 17:45:44 +08:00
|
|
|
case GlobalSkinnableContainers.MainHUDComponents:
|
2024-08-15 15:57:29 +08:00
|
|
|
return new DefaultSkinComponentsContainer(container =>
|
|
|
|
{
|
|
|
|
var combo = container.ChildrenOfType<LegacyManiaComboCounter>().FirstOrDefault();
|
|
|
|
|
|
|
|
if (combo != null)
|
|
|
|
{
|
|
|
|
combo.Anchor = Anchor.TopCentre;
|
|
|
|
combo.Origin = Anchor.Centre;
|
|
|
|
combo.Y = this.GetManiaSkinConfig<float>(LegacyManiaSkinConfigurationLookups.ComboPosition)?.Value ?? 0;
|
|
|
|
}
|
|
|
|
})
|
|
|
|
{
|
|
|
|
new LegacyManiaComboCounter(),
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
2023-12-30 10:20:44 +08:00
|
|
|
|
2024-08-22 17:42:38 +08:00
|
|
|
case SkinComponentLookup<HitResult> resultComponent:
|
2020-06-12 21:22:22 +08:00
|
|
|
return getResult(resultComponent.Component);
|
2020-03-30 22:17:32 +08:00
|
|
|
|
2022-11-09 15:04:56 +08:00
|
|
|
case ManiaSkinComponentLookup maniaComponent:
|
2020-06-13 18:45:06 +08:00
|
|
|
if (!isLegacySkin.Value || !hasKeyTexture.Value)
|
|
|
|
return null;
|
|
|
|
|
2020-03-30 22:14:30 +08:00
|
|
|
switch (maniaComponent.Component)
|
|
|
|
{
|
|
|
|
case ManiaSkinComponents.ColumnBackground:
|
2020-08-25 00:21:27 +08:00
|
|
|
return new LegacyColumnBackground();
|
2020-03-31 14:24:13 +08:00
|
|
|
|
2020-03-31 11:17:44 +08:00
|
|
|
case ManiaSkinComponents.HitTarget:
|
2020-08-25 00:21:27 +08:00
|
|
|
// Legacy skins sandwich the hit target between the column background and the column light.
|
|
|
|
// To preserve this ordering, it's created manually inside LegacyStageBackground.
|
2020-08-24 21:36:37 +08:00
|
|
|
return Drawable.Empty();
|
2020-03-31 14:24:13 +08:00
|
|
|
|
2020-03-31 10:23:33 +08:00
|
|
|
case ManiaSkinComponents.KeyArea:
|
|
|
|
return new LegacyKeyArea();
|
2020-03-31 14:29:25 +08:00
|
|
|
|
|
|
|
case ManiaSkinComponents.Note:
|
|
|
|
return new LegacyNotePiece();
|
|
|
|
|
|
|
|
case ManiaSkinComponents.HoldNoteHead:
|
|
|
|
return new LegacyHoldNoteHeadPiece();
|
|
|
|
|
|
|
|
case ManiaSkinComponents.HoldNoteTail:
|
|
|
|
return new LegacyHoldNoteTailPiece();
|
2020-03-31 15:42:35 +08:00
|
|
|
|
|
|
|
case ManiaSkinComponents.HoldNoteBody:
|
|
|
|
return new LegacyBodyPiece();
|
2020-04-02 13:29:16 +08:00
|
|
|
|
|
|
|
case ManiaSkinComponents.HitExplosion:
|
|
|
|
return new LegacyHitExplosion();
|
2020-04-08 14:08:13 +08:00
|
|
|
|
|
|
|
case ManiaSkinComponents.StageBackground:
|
2022-10-04 17:26:27 +08:00
|
|
|
return new LegacyStageBackground();
|
2020-04-08 15:20:26 +08:00
|
|
|
|
|
|
|
case ManiaSkinComponents.StageForeground:
|
|
|
|
return new LegacyStageForeground();
|
2020-03-30 22:14:30 +08:00
|
|
|
|
2023-08-15 12:33:49 +08:00
|
|
|
case ManiaSkinComponents.BarLine:
|
|
|
|
return null; // Not yet implemented.
|
|
|
|
|
2022-04-23 06:08:53 +08:00
|
|
|
default:
|
2022-11-09 13:11:41 +08:00
|
|
|
throw new UnsupportedSkinComponentException(lookup);
|
2022-04-23 06:08:53 +08:00
|
|
|
}
|
2019-12-27 10:37:05 +08:00
|
|
|
}
|
2021-05-30 18:15:59 +08:00
|
|
|
|
2022-11-09 13:11:41 +08:00
|
|
|
return base.GetDrawableComponent(lookup);
|
2019-12-27 10:37:05 +08:00
|
|
|
}
|
2019-12-26 21:03:21 +08:00
|
|
|
|
2020-06-12 21:22:22 +08:00
|
|
|
private Drawable getResult(HitResult result)
|
2019-12-27 10:37:05 +08:00
|
|
|
{
|
2021-12-10 13:15:00 +08:00
|
|
|
if (!hit_result_mapping.ContainsKey(result))
|
2020-09-29 13:29:43 +08:00
|
|
|
return null;
|
|
|
|
|
2022-10-06 13:10:39 +08:00
|
|
|
string filename = this.GetManiaSkinConfig<string>(hit_result_mapping[result])?.Value
|
2021-12-10 13:15:00 +08:00
|
|
|
?? default_hit_result_skin_filenames[result];
|
2019-12-26 21:03:21 +08:00
|
|
|
|
2023-10-19 19:00:13 +08:00
|
|
|
var animation = this.GetAnimation(filename, true, true, frameLength: 1000 / 20d);
|
2020-12-14 12:07:55 +08:00
|
|
|
return animation == null ? null : new LegacyManiaJudgementPiece(result, animation);
|
2019-12-26 21:03:21 +08:00
|
|
|
}
|
|
|
|
|
2021-02-18 17:32:28 +08:00
|
|
|
public override ISample GetSample(ISampleInfo sampleInfo)
|
2020-06-22 04:44:35 +08:00
|
|
|
{
|
|
|
|
// layered hit sounds never play in mania
|
|
|
|
if (sampleInfo is ConvertHitObjectParser.LegacyHitSampleInfo legacySample && legacySample.IsLayered)
|
2021-01-19 16:11:40 +08:00
|
|
|
return new SampleVirtual();
|
2020-06-22 04:44:35 +08:00
|
|
|
|
2021-06-11 17:44:44 +08:00
|
|
|
return base.GetSample(sampleInfo);
|
2020-06-22 04:44:35 +08:00
|
|
|
}
|
|
|
|
|
2020-06-22 04:04:10 +08:00
|
|
|
public override IBindable<TValue> GetConfig<TLookup, TValue>(TLookup lookup)
|
2020-04-02 17:39:49 +08:00
|
|
|
{
|
|
|
|
if (lookup is ManiaSkinConfigurationLookup maniaLookup)
|
2022-10-05 21:41:20 +08:00
|
|
|
{
|
2022-10-07 15:12:10 +08:00
|
|
|
return base.GetConfig<LegacyManiaSkinConfigurationLookup, TValue>(new LegacyManiaSkinConfigurationLookup(beatmap.TotalColumns, maniaLookup.Lookup, maniaLookup.ColumnIndex));
|
2022-10-05 21:41:20 +08:00
|
|
|
}
|
2020-04-02 17:39:49 +08:00
|
|
|
|
2021-06-11 17:44:44 +08:00
|
|
|
return base.GetConfig<TLookup, TValue>(lookup);
|
2020-04-02 17:39:49 +08:00
|
|
|
}
|
2019-12-26 21:03:21 +08:00
|
|
|
}
|
|
|
|
}
|