Skip to content

Instantly share code, notes, and snippets.

@ilsubyeega
Created September 1, 2023 10:03
Show Gist options
  • Select an option

  • Save ilsubyeega/f43cfc8785b50d40b756b08d3e26e0bd to your computer and use it in GitHub Desktop.

Select an option

Save ilsubyeega/f43cfc8785b50d40b756b08d3e26e0bd to your computer and use it in GitHub Desktop.
// 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.
#nullable disable
using System;
using osu.Framework.Allocation;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Logging;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osu.Game.Rulesets.Judgements;
using osu.Game.Rulesets.Scoring;
using osuTK;
namespace osu.Game.Rulesets.Osu.Objects.Drawables
{
public partial class DrawableOsuJudgement : DrawableJudgement
{
internal SkinnableLighting Lighting { get; private set; }
internal FillFlowContainer TextContainer { get; private set; }
[Resolved]
private OsuConfigManager config { get; set; }
[BackgroundDependencyLoader]
private void load()
{
AddInternal(Lighting = new SkinnableLighting
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Blending = BlendingParameters.Additive,
Depth = float.MaxValue,
Alpha = 0
});
}
protected override void PrepareForUse()
{
base.PrepareForUse();
Lighting.ResetAnimation();
Lighting.SetColourFrom(JudgedObject, Result);
if (JudgedObject?.HitObject is OsuHitObject osuObject)
{
Position = osuObject.StackedEndPosition;
Scale = new Vector2(osuObject.Scale);
}
}
protected override void ApplyHitAnimations()
{
bool hitLightingEnabled = config.Get<bool>(OsuSetting.HitLighting);
Lighting.Alpha = 0;
if (hitLightingEnabled)
{
// todo: this animation changes slightly based on new/old legacy skin versions.
Lighting.ScaleTo(0.8f).ScaleTo(1.2f, 600, Easing.Out);
Lighting.FadeIn(200).Then().Delay(200).FadeOut(1000);
// extend the lifetime to cover lighting fade
LifetimeEnd = Lighting.LatestTransformEndTime;
}
createOffsetTextContainer();
base.ApplyHitAnimations();
}
private void createOffsetTextContainer()
{
if (Result.Type == HitResult.Great || Result.Type == HitResult.Perfect) return;
if (TextContainer != null)
RemoveInternal(TextContainer, true);
bool isPostive = Result.TimeOffset >= 0.5;
bool isNegative = Result.TimeOffset < -0.5;
var colour = new OsuColour();
OsuSpriteText differental;
if (isPostive)
{
differental = new OsuSpriteText { Anchor = Anchor.Centre, Origin = Anchor.Centre, Text = "SLOW", Font = OsuFont.GetFont(size: 28, weight: FontWeight.Bold), Colour = colour.Blue, Alpha = 0.8f };
}
else if (isNegative)
{
differental = new OsuSpriteText { Anchor = Anchor.Centre, Origin = Anchor.Centre, Text = "FAST", Font = OsuFont.GetFont(size: 28, weight: FontWeight.Bold), Colour = colour.Red, Alpha = 0.8f };
}
else
{
differental = new OsuSpriteText { Anchor = Anchor.Centre, Origin = Anchor.Centre, Text = "", Font = OsuFont.GetFont(size: 28, weight: FontWeight.Bold), Alpha = 0 };
}
double offset = Math.Round(Result.TimeOffset);
if (offset < 0) offset *= -1;
AddInternal(TextContainer = new FillFlowContainer
{
RelativeSizeAxes = Axes.X,
AutoSizeAxes = Axes.Y,
Direction = FillDirection.Horizontal,
Spacing = new Vector2(24, 0),
Origin = Anchor.Centre,
Anchor = Anchor.Centre,
Children = new Drawable[]
{
differental,
new OsuSpriteText { Anchor = Anchor.Centre, Origin = Anchor.Centre, Text = $"{offset}", Font = OsuFont.GetFont(size: 28, weight: FontWeight.Bold), Alpha = 0.8f }
}
});
//TextContainer.Alpha = 0;
TextContainer.FadeIn(100).Then().Delay(300).FadeOut(100);
}
protected override Drawable CreateDefaultJudgement(HitResult result) => new OsuJudgementPiece(result);
private partial class OsuJudgementPiece : DefaultJudgementPiece
{
public OsuJudgementPiece(HitResult result)
: base(result)
{
}
public override void PlayAnimation()
{
if (Result != HitResult.Miss)
{
JudgementText
.ScaleTo(new Vector2(0.8f, 1))
.ScaleTo(new Vector2(1.2f, 1), 1800, Easing.OutQuint);
}
base.PlayAnimation();
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment