2020-04-15 16:50:37 +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.
|
|
|
|
|
2023-07-05 16:25:31 +08:00
|
|
|
using System;
|
2020-04-15 16:50:37 +08:00
|
|
|
using osu.Framework.Allocation;
|
2022-11-23 00:22:00 +08:00
|
|
|
using osu.Framework.Bindables;
|
2020-04-15 16:50:37 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Animations;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2022-08-18 16:05:09 +08:00
|
|
|
using osu.Framework.Graphics.Primitives;
|
2022-11-23 00:22:00 +08:00
|
|
|
using osu.Game.Beatmaps;
|
2023-07-05 16:25:31 +08:00
|
|
|
using osu.Game.Beatmaps.ControlPoints;
|
2020-04-15 16:50:37 +08:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
2020-12-13 19:51:10 +08:00
|
|
|
using osu.Game.Rulesets.Taiko.Objects;
|
2022-11-23 00:22:00 +08:00
|
|
|
using osu.Game.Screens.Play;
|
2020-04-15 16:50:37 +08:00
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2020-12-07 11:30:25 +08:00
|
|
|
namespace osu.Game.Rulesets.Taiko.Skinning.Legacy
|
2020-04-15 16:50:37 +08:00
|
|
|
{
|
|
|
|
public partial class LegacyCirclePiece : CompositeDrawable, IHasAccentColour
|
|
|
|
{
|
2022-11-02 16:07:19 +08:00
|
|
|
private Drawable backgroundLayer = null!;
|
2022-11-23 00:22:00 +08:00
|
|
|
private Drawable? foregroundLayer;
|
|
|
|
|
|
|
|
private Bindable<int> currentCombo { get; } = new BindableInt();
|
|
|
|
|
|
|
|
private int animationFrame;
|
2020-04-15 16:50:37 +08:00
|
|
|
|
2022-08-18 16:05:09 +08:00
|
|
|
// required for editor blueprints (not sure why these circle pieces are zero size).
|
|
|
|
public override Quad ScreenSpaceDrawQuad => backgroundLayer.ScreenSpaceDrawQuad;
|
|
|
|
|
2023-07-05 16:25:31 +08:00
|
|
|
private TimingControlPoint timingPoint = TimingControlPoint.DEFAULT;
|
|
|
|
|
2020-04-15 16:50:37 +08:00
|
|
|
public LegacyCirclePiece()
|
|
|
|
{
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
}
|
|
|
|
|
2022-11-23 03:56:07 +08:00
|
|
|
[Resolved(canBeNull: true)]
|
2022-11-23 00:22:00 +08:00
|
|
|
private GameplayState? gameplayState { get; set; }
|
|
|
|
|
2020-04-15 16:50:37 +08:00
|
|
|
[BackgroundDependencyLoader]
|
2023-07-05 16:25:31 +08:00
|
|
|
private void load(ISkinSource skin, DrawableHitObject drawableHitObject, IBeatSyncProvider? beatSyncProvider)
|
2020-04-15 16:50:37 +08:00
|
|
|
{
|
2022-11-02 16:07:19 +08:00
|
|
|
Drawable? getDrawableFor(string lookup)
|
2020-04-15 16:50:37 +08:00
|
|
|
{
|
|
|
|
const string normal_hit = "taikohit";
|
|
|
|
const string big_hit = "taikobig";
|
|
|
|
|
2020-12-15 04:46:02 +08:00
|
|
|
string prefix = ((drawableHitObject.HitObject as TaikoStrongableHitObject)?.IsStrong ?? false) ? big_hit : normal_hit;
|
2020-04-15 16:50:37 +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);
|
|
|
|
}
|
|
|
|
|
|
|
|
// backgroundLayer is guaranteed to exist due to the pre-check in TaikoLegacySkinTransformer.
|
2022-10-19 05:55:02 +08:00
|
|
|
AddInternal(backgroundLayer = new LegacyKiaiFlashingDrawable(() => getDrawableFor("circle")));
|
2020-04-15 16:50:37 +08:00
|
|
|
|
2022-11-23 00:22:00 +08:00
|
|
|
foregroundLayer = getDrawableFor("circleoverlay");
|
2020-04-15 16:50:37 +08:00
|
|
|
if (foregroundLayer != null)
|
|
|
|
AddInternal(foregroundLayer);
|
|
|
|
|
2023-07-05 16:25:31 +08:00
|
|
|
drawableHitObject.StartTimeBindable.BindValueChanged(startTime =>
|
|
|
|
{
|
|
|
|
timingPoint = beatSyncProvider?.ControlPoints?.TimingPointAt(startTime.NewValue) ?? TimingControlPoint.DEFAULT;
|
|
|
|
}, true);
|
|
|
|
|
2020-04-15 16:50:37 +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.
|
|
|
|
foreach (var c in InternalChildren)
|
|
|
|
{
|
|
|
|
(c as IFramedAnimation)?.Stop();
|
|
|
|
|
|
|
|
c.Anchor = Anchor.Centre;
|
|
|
|
c.Origin = Anchor.Centre;
|
|
|
|
}
|
2022-11-23 00:22:00 +08:00
|
|
|
|
|
|
|
if (gameplayState != null)
|
|
|
|
currentCombo.BindTo(gameplayState.ScoreProcessor.Combo);
|
2020-04-15 16:50:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
updateAccentColour();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
{
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
// 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.
|
|
|
|
foreach (var c in InternalChildren)
|
|
|
|
c.Scale = new Vector2(DrawHeight / 128);
|
2022-11-23 00:22:00 +08:00
|
|
|
|
2022-11-23 03:34:43 +08:00
|
|
|
if (foregroundLayer is IFramedAnimation animatableForegroundLayer)
|
|
|
|
animateForegroundLayer(animatableForegroundLayer);
|
|
|
|
}
|
|
|
|
|
|
|
|
private void animateForegroundLayer(IFramedAnimation animatableForegroundLayer)
|
|
|
|
{
|
|
|
|
int multiplier;
|
|
|
|
|
2022-11-23 00:22:00 +08:00
|
|
|
if (currentCombo.Value >= 150)
|
|
|
|
{
|
|
|
|
multiplier = 2;
|
|
|
|
}
|
|
|
|
else if (currentCombo.Value >= 50)
|
|
|
|
{
|
|
|
|
multiplier = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-11-23 03:34:43 +08:00
|
|
|
animatableForegroundLayer.GotoFrame(0);
|
2022-11-23 00:22:00 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-05 16:25:31 +08:00
|
|
|
animationFrame = Math.Abs(Time.Current - timingPoint.Time) % ((timingPoint.BeatLength * 2) / multiplier) >= timingPoint.BeatLength / multiplier ? 0 : 1;
|
|
|
|
animatableForegroundLayer.GotoFrame(animationFrame);
|
2020-04-15 16:50:37 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
private Color4 accentColour;
|
|
|
|
|
|
|
|
public Color4 AccentColour
|
|
|
|
{
|
|
|
|
get => accentColour;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (value == accentColour)
|
|
|
|
return;
|
|
|
|
|
|
|
|
accentColour = value;
|
|
|
|
if (IsLoaded)
|
|
|
|
updateAccentColour();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
private void updateAccentColour()
|
|
|
|
{
|
2020-08-25 14:16:41 +08:00
|
|
|
backgroundLayer.Colour = LegacyColourCompatibility.DisallowZeroAlpha(accentColour);
|
2020-04-15 16:50:37 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|