1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-20 18:32:58 +08:00
osu-lazer/osu.Game.Rulesets.Taiko/Skinning/LegacyHit.cs

92 lines
3.1 KiB
C#
Raw Normal View History

2020-04-11 13:20:09 +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 osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Animations;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Taiko.Objects.Drawables;
2020-04-11 13:20:09 +08:00
using osu.Game.Skinning;
2020-04-11 13:43:57 +08:00
using osuTK;
2020-04-11 13:20:09 +08:00
using osuTK.Graphics;
namespace osu.Game.Rulesets.Taiko.Skinning
{
public class LegacyHit : CompositeDrawable, IHasAccentColour
{
private readonly TaikoSkinComponents component;
private Drawable backgroundLayer;
public LegacyHit(TaikoSkinComponents component)
{
this.component = component;
2020-04-11 13:43:57 +08:00
RelativeSizeAxes = Axes.Both;
2020-04-11 13:20:09 +08:00
}
[BackgroundDependencyLoader]
private void load(ISkinSource skin, DrawableHitObject drawableHitObject)
2020-04-11 13:20:09 +08:00
{
Drawable getDrawableFor(string lookup)
2020-04-11 13:20:09 +08:00
{
const string normal_hit = "taikohit";
const string big_hit = "taikobig";
string prefix = ((drawableHitObject as DrawableTaikoHitObject)?.HitObject.IsStrong ?? false) ? big_hit : normal_hit;
2020-04-11 14:04:58 +08:00
return skin.GetAnimation($"{prefix}{lookup}", true, false) ??
// fallback to regular size if "big" version doesn't exist.
skin.GetAnimation($"{normal_hit}{lookup}", true, false);
}
2020-04-11 14:04:58 +08:00
// backgroundLayer is guaranteed to exist due to the pre-check in TaikoLegacySkinTransformer.
AddInternal(backgroundLayer = getDrawableFor("circle"));
var foregroundLayer = getDrawableFor("circleoverlay");
if (foregroundLayer != null)
AddInternal(foregroundLayer);
2020-04-11 13:20:09 +08:00
2020-04-11 14:04:58 +08:00
// Animations in taiko skins are used in a custom way (>150 combo and animating in time with beat).
// For now just stop at first frame for sanity.
2020-04-11 13:20:09 +08:00
foreach (var c in InternalChildren)
{
(c as IFramedAnimation)?.Stop();
2020-04-11 13:43:57 +08:00
2020-04-11 13:20:09 +08:00
c.Anchor = Anchor.Centre;
c.Origin = Anchor.Centre;
}
AccentColour = component == TaikoSkinComponents.CentreHit
? new Color4(235, 69, 44, 255)
: new Color4(67, 142, 172, 255);
}
2020-04-11 13:43:57 +08:00
protected override void Update()
{
base.Update();
2020-04-11 14:04:58 +08:00
// Not all skins (including the default osu-stable) have similar sizes for "hitcircle" and "hitcircleoverlay".
// This ensures they are scaled relative to each other but also match the expected DrawableHit size.
2020-04-11 13:43:57 +08:00
foreach (var c in InternalChildren)
c.Scale = new Vector2(DrawWidth / 128);
}
2020-04-11 13:20:09 +08:00
private Color4 accentColour;
public Color4 AccentColour
{
get => accentColour;
set
{
if (value == accentColour)
return;
backgroundLayer.Colour = accentColour = value;
}
}
}
}