2019-08-30 03:59:58 +00: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-01-10 12:25:53 +00:00
|
|
|
using System;
|
2019-08-30 03:59:58 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Bindables;
|
2022-04-19 05:08:02 +00:00
|
|
|
using osu.Framework.Extensions.ObjectExtensions;
|
2019-08-30 03:59:58 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2021-12-28 14:50:43 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2019-08-30 03:59:58 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osu.Game.Rulesets.Objects.Drawables;
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
2020-11-05 05:40:48 +00:00
|
|
|
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
2019-08-30 03:59:58 +00:00
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
|
|
|
|
2020-12-04 11:21:53 +00:00
|
|
|
namespace osu.Game.Rulesets.Osu.Skinning.Legacy
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2021-06-02 02:46:28 +00:00
|
|
|
public partial class LegacyMainCirclePiece : CompositeDrawable
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2021-06-09 01:53:52 +00:00
|
|
|
public override bool RemoveCompletedTransforms => false;
|
|
|
|
|
2022-04-19 05:06:39 +00:00
|
|
|
/// <summary>
|
|
|
|
/// A prioritised prefix to perform texture lookups with.
|
|
|
|
/// </summary>
|
2022-04-19 16:39:06 +00:00
|
|
|
private readonly string? priorityLookupPrefix;
|
|
|
|
|
|
|
|
private readonly bool hasNumber;
|
2022-04-19 05:06:39 +00:00
|
|
|
|
2022-04-19 21:24:18 +00:00
|
|
|
protected Drawable CircleSprite = null!;
|
|
|
|
protected Drawable OverlaySprite = null!;
|
2021-09-01 10:34:57 +00:00
|
|
|
|
2022-04-19 09:10:10 +00:00
|
|
|
protected Container OverlayLayer { get; private set; } = null!;
|
2020-08-05 17:07:05 +00:00
|
|
|
|
2022-04-19 09:10:10 +00:00
|
|
|
private SkinnableSpriteText hitCircleText = null!;
|
2019-10-01 05:23:41 +00:00
|
|
|
|
2019-08-30 03:59:58 +00:00
|
|
|
private readonly Bindable<Color4> accentColour = new Bindable<Color4>();
|
2019-09-26 07:57:58 +00:00
|
|
|
private readonly IBindable<int> indexInCurrentCombo = new Bindable<int>();
|
2019-10-01 05:23:41 +00:00
|
|
|
|
2022-05-19 04:49:52 +00:00
|
|
|
[Resolved(canBeNull: true)] // Can't really be null but required to handle potential of disposal before DI completes.
|
2022-04-19 09:10:10 +00:00
|
|
|
private DrawableHitObject? drawableObject { get; set; }
|
2020-11-04 08:30:23 +00:00
|
|
|
|
2019-10-03 02:58:20 +00:00
|
|
|
[Resolved]
|
2022-04-19 09:10:10 +00:00
|
|
|
private ISkinSource skin { get; set; } = null!;
|
|
|
|
|
|
|
|
public LegacyMainCirclePiece(string? priorityLookupPrefix = null, bool hasNumber = true)
|
|
|
|
{
|
|
|
|
this.priorityLookupPrefix = priorityLookupPrefix;
|
|
|
|
this.hasNumber = hasNumber;
|
|
|
|
|
|
|
|
Size = new Vector2(OsuHitObject.OBJECT_RADIUS * 2);
|
|
|
|
}
|
2019-10-03 02:58:20 +00:00
|
|
|
|
2019-08-30 03:59:58 +00:00
|
|
|
[BackgroundDependencyLoader]
|
2020-11-04 08:30:23 +00:00
|
|
|
private void load()
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2022-04-19 09:10:10 +00:00
|
|
|
var drawableOsuObject = (DrawableOsuHitObject?)drawableObject;
|
2019-08-30 03:59:58 +00:00
|
|
|
|
2022-04-19 16:39:06 +00:00
|
|
|
// if a base texture for the specified prefix exists, continue using it for subsequent lookups.
|
|
|
|
// otherwise fall back to the default prefix "hitcircle".
|
|
|
|
string circleName = (priorityLookupPrefix != null && skin.GetTexture(priorityLookupPrefix) != null) ? priorityLookupPrefix : @"hitcircle";
|
2020-10-06 04:56:38 +00:00
|
|
|
|
|
|
|
// at this point, any further texture fetches should be correctly using the priority source if the base texture was retrieved using it.
|
2022-04-19 16:39:06 +00:00
|
|
|
// the conditional above handles the case where a sliderendcircle.png is retrieved from the skin, but sliderendcircleoverlay.png doesn't exist.
|
2022-04-19 04:12:05 +00:00
|
|
|
// expected behaviour in this scenario is not showing the overlay, rather than using hitcircleoverlay.png.
|
2020-10-06 04:56:38 +00:00
|
|
|
|
2023-01-10 12:25:53 +00:00
|
|
|
Color4 objectColour = drawableOsuObject!.AccentColour.Value;
|
|
|
|
int add = Math.Max(25, 300 - (int)(objectColour.R * 255) - (int)(objectColour.G * 255) - (int)(objectColour.B * 255));
|
|
|
|
|
|
|
|
Color4 finalColour = new Color4(
|
|
|
|
(byte)Math.Min((byte)(objectColour.R * 255) + add, 255),
|
|
|
|
(byte)Math.Min((byte)(objectColour.G * 255) + add, 255),
|
|
|
|
(byte)Math.Min((byte)(objectColour.B * 255) + add, 255),
|
|
|
|
255);
|
|
|
|
|
2021-09-01 10:34:57 +00:00
|
|
|
InternalChildren = new[]
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2022-10-18 21:53:12 +00:00
|
|
|
CircleSprite = new LegacyKiaiFlashingDrawable(() => new Sprite { Texture = skin.GetTexture(circleName) })
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2021-09-01 10:34:57 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-01-10 12:25:53 +00:00
|
|
|
Colour = finalColour,
|
2021-09-01 10:34:57 +00:00
|
|
|
},
|
2021-10-03 13:40:32 +00:00
|
|
|
OverlayLayer = new Container
|
2021-09-01 10:34:57 +00:00
|
|
|
{
|
2019-08-30 03:59:58 +00:00
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2023-01-10 12:25:53 +00:00
|
|
|
Colour = finalColour,
|
2022-10-18 21:53:12 +00:00
|
|
|
Child = OverlaySprite = new LegacyKiaiFlashingDrawable(() => skin.GetAnimation(@$"{circleName}overlay", true, true, frameLength: 1000 / 2d))
|
2021-10-03 13:40:32 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
},
|
|
|
|
}
|
2020-10-02 04:40:24 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
if (hasNumber)
|
|
|
|
{
|
2022-11-09 07:04:56 +00:00
|
|
|
OverlayLayer.Add(hitCircleText = new SkinnableSpriteText(new OsuSkinComponentLookup(OsuSkinComponents.HitCircleText), _ => new OsuSpriteText
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
|
|
|
Font = OsuFont.Numeric.With(size: 40),
|
|
|
|
UseFullGlyphHeight = false,
|
2019-10-03 03:49:32 +00:00
|
|
|
}, confineMode: ConfineMode.NoScaling)
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
2020-10-02 04:40:24 +00:00
|
|
|
});
|
|
|
|
}
|
2019-08-30 03:59:58 +00:00
|
|
|
|
2020-03-30 10:42:18 +00:00
|
|
|
bool overlayAboveNumber = skin.GetConfig<OsuSkinConfiguration, bool>(OsuSkinConfiguration.HitCircleOverlayAboveNumber)?.Value ?? true;
|
|
|
|
|
2020-08-05 17:07:05 +00:00
|
|
|
if (overlayAboveNumber)
|
2022-04-19 21:24:18 +00:00
|
|
|
OverlayLayer.ChangeChildDepth(OverlaySprite, float.MinValue);
|
2020-03-30 10:42:18 +00:00
|
|
|
|
2022-04-19 00:25:18 +00:00
|
|
|
if (drawableOsuObject != null)
|
|
|
|
{
|
|
|
|
accentColour.BindTo(drawableOsuObject.AccentColour);
|
|
|
|
indexInCurrentCombo.BindTo(drawableOsuObject.IndexInCurrentComboBindable);
|
|
|
|
}
|
2019-08-30 03:59:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-05 17:07:05 +00:00
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
2022-04-19 21:24:18 +00:00
|
|
|
accentColour.BindValueChanged(colour => CircleSprite.Colour = LegacyColourCompatibility.DisallowZeroAlpha(colour.NewValue), true);
|
2020-10-02 04:40:24 +00:00
|
|
|
if (hasNumber)
|
|
|
|
indexInCurrentCombo.BindValueChanged(index => hitCircleText.Text = (index.NewValue + 1).ToString(), true);
|
2021-06-02 02:32:24 +00:00
|
|
|
|
2022-04-19 00:25:18 +00:00
|
|
|
if (drawableObject != null)
|
2022-04-19 05:08:02 +00:00
|
|
|
{
|
2022-04-19 00:25:18 +00:00
|
|
|
drawableObject.ApplyCustomUpdateState += updateStateTransforms;
|
2022-04-19 05:08:02 +00:00
|
|
|
updateStateTransforms(drawableObject, drawableObject.State.Value);
|
|
|
|
}
|
2020-08-05 17:07:05 +00:00
|
|
|
}
|
|
|
|
|
2021-06-09 07:14:55 +00:00
|
|
|
private void updateStateTransforms(DrawableHitObject drawableHitObject, ArmedState state)
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
|
|
|
const double legacy_fade_duration = 240;
|
|
|
|
|
2022-04-19 05:08:02 +00:00
|
|
|
using (BeginAbsoluteSequence(drawableObject.AsNonNull().HitStateUpdateTime))
|
2019-08-30 03:59:58 +00:00
|
|
|
{
|
2021-06-09 07:14:55 +00:00
|
|
|
switch (state)
|
2020-11-04 08:30:23 +00:00
|
|
|
{
|
|
|
|
case ArmedState.Hit:
|
2022-10-18 19:22:53 +00:00
|
|
|
CircleSprite.FadeOut(legacy_fade_duration);
|
2022-04-19 21:24:18 +00:00
|
|
|
CircleSprite.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
2021-09-01 10:34:57 +00:00
|
|
|
|
2022-10-18 19:22:53 +00:00
|
|
|
OverlaySprite.FadeOut(legacy_fade_duration);
|
2022-04-19 21:24:18 +00:00
|
|
|
OverlaySprite.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
2020-10-02 04:40:24 +00:00
|
|
|
|
2020-11-04 08:30:23 +00:00
|
|
|
if (hasNumber)
|
2020-10-02 04:40:24 +00:00
|
|
|
{
|
2021-10-27 21:24:20 +00:00
|
|
|
decimal? legacyVersion = skin.GetConfig<SkinConfiguration.LegacySetting, decimal>(SkinConfiguration.LegacySetting.Version)?.Value;
|
2020-11-04 08:30:23 +00:00
|
|
|
|
|
|
|
if (legacyVersion >= 2.0m)
|
|
|
|
// legacy skins of version 2.0 and newer only apply very short fade out to the number piece.
|
2022-10-18 19:22:53 +00:00
|
|
|
hitCircleText.FadeOut(legacy_fade_duration / 4);
|
2020-11-04 08:30:23 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
// old skins scale and fade it normally along other pieces.
|
2022-10-18 19:22:53 +00:00
|
|
|
hitCircleText.FadeOut(legacy_fade_duration);
|
2020-11-04 08:30:23 +00:00
|
|
|
hitCircleText.ScaleTo(1.4f, legacy_fade_duration, Easing.Out);
|
|
|
|
}
|
2020-10-02 04:40:24 +00:00
|
|
|
}
|
2019-10-03 02:58:20 +00:00
|
|
|
|
2020-11-04 08:30:23 +00:00
|
|
|
break;
|
|
|
|
}
|
2019-08-30 03:59:58 +00:00
|
|
|
}
|
|
|
|
}
|
2021-06-09 07:14:55 +00:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
|
|
|
|
if (drawableObject != null)
|
|
|
|
drawableObject.ApplyCustomUpdateState -= updateStateTransforms;
|
|
|
|
}
|
2019-08-30 03:59:58 +00:00
|
|
|
}
|
|
|
|
}
|