1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-30 08:42:55 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

194 lines
7.6 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2018-02-11 18:03:01 +08:00
using System;
using System.Diagnostics;
using System.Linq;
using osu.Framework.Graphics;
using osu.Framework.Bindables;
2022-08-11 04:09:11 +08:00
using osu.Framework.Localisation;
using osu.Game.Configuration;
using osu.Game.Beatmaps;
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
using osu.Game.Rulesets.Objects.Drawables;
using osu.Game.Rulesets.Osu.Objects.Drawables;
2018-06-06 12:51:51 +08:00
using osu.Game.Rulesets.Osu.Objects;
using osu.Game.Rulesets.Osu.Skinning;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Osu.Mods
{
public class OsuModHidden : ModHidden, IHidesApproachCircles
{
[SettingSource("Only fade approach circles", "The main object body will not fade when enabled.")]
2021-10-26 18:56:54 +08:00
public Bindable<bool> OnlyFadeApproachCircles { get; } = new BindableBool();
2022-08-11 04:09:11 +08:00
public override LocalisableString Description => @"Play with no approach circles and fading circles/sliders.";
public override double ScoreMultiplier => UsesDefaultConfiguration ? 1.06 : 1;
public override Type[] IncompatibleMods => new[] { typeof(IRequiresApproachCircles), typeof(OsuModSpinIn) };
2022-05-12 16:19:07 +08:00
public const double FADE_IN_DURATION_MULTIPLIER = 0.4;
public const double FADE_OUT_DURATION_MULTIPLIER = 0.3;
protected override bool IsFirstAdjustableObject(HitObject hitObject) => !(hitObject is Spinner || hitObject is SpinnerTick);
public override void ApplyToBeatmap(IBeatmap beatmap)
2018-06-06 12:51:51 +08:00
{
base.ApplyToBeatmap(beatmap);
2018-06-06 12:51:51 +08:00
foreach (var obj in beatmap.HitObjects.OfType<OsuHitObject>())
applyFadeInAdjustment(obj);
static void applyFadeInAdjustment(OsuHitObject osuObject)
{
2022-05-12 16:19:07 +08:00
osuObject.TimeFadeIn = osuObject.TimePreempt * FADE_IN_DURATION_MULTIPLIER;
foreach (var nested in osuObject.NestedHitObjects.OfType<OsuHitObject>())
applyFadeInAdjustment(nested);
}
}
2020-11-05 14:36:44 +08:00
protected override void ApplyIncreasedVisibilityState(DrawableHitObject hitObject, ArmedState state)
{
2021-10-26 10:42:15 +08:00
applyHiddenState(hitObject, true);
2020-11-05 14:36:44 +08:00
}
2020-11-05 14:36:44 +08:00
protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state)
{
2021-10-26 10:42:15 +08:00
applyHiddenState(hitObject, false);
2020-11-05 14:36:44 +08:00
}
2021-10-26 10:42:15 +08:00
private void applyHiddenState(DrawableHitObject drawableObject, bool increaseVisibility)
{
if (!(drawableObject is DrawableOsuHitObject drawableOsuObject))
return;
2018-04-13 17:19:50 +08:00
OsuHitObject hitObject = drawableOsuObject.HitObject;
2018-04-13 17:19:50 +08:00
2021-05-14 21:56:13 +08:00
(double fadeStartTime, double fadeDuration) = getFadeOutParameters(drawableOsuObject);
2018-04-13 17:19:50 +08:00
2021-10-26 10:42:15 +08:00
// process approach circle hiding first (to allow for early return below).
if (!increaseVisibility)
{
if (drawableObject is DrawableHitCircle circle)
{
using (circle.BeginAbsoluteSequence(hitObject.StartTime - hitObject.TimePreempt))
circle.ApproachCircle.Hide();
}
else if (drawableObject is DrawableSpinner spinner)
{
spinner.Body.OnSkinChanged += () => hideSpinnerApproachCircle(spinner);
hideSpinnerApproachCircle(spinner);
}
2021-10-26 10:42:15 +08:00
}
if (OnlyFadeApproachCircles.Value)
return;
switch (drawableObject)
{
2022-06-24 20:25:23 +08:00
case DrawableSliderTail:
using (drawableObject.BeginAbsoluteSequence(fadeStartTime))
drawableObject.FadeOut(fadeDuration);
break;
case DrawableSliderRepeat sliderRepeat:
using (drawableObject.BeginAbsoluteSequence(fadeStartTime))
// only apply to circle piece reverse arrow is not affected by hidden.
sliderRepeat.CirclePiece.FadeOut(fadeDuration);
break;
case DrawableHitCircle circle:
Drawable fadeTarget = circle;
2021-10-26 10:42:15 +08:00
if (increaseVisibility)
{
// only fade the circle piece (not the approach circle) for the increased visibility object.
fadeTarget = circle.CirclePiece;
}
using (drawableObject.BeginAbsoluteSequence(fadeStartTime))
fadeTarget.FadeOut(fadeDuration);
break;
2019-04-01 11:44:46 +08:00
case DrawableSlider slider:
using (slider.BeginAbsoluteSequence(fadeStartTime))
slider.Body.FadeOut(fadeDuration, Easing.Out);
2018-04-13 17:19:50 +08:00
break;
2019-04-01 11:44:46 +08:00
case DrawableSliderTick sliderTick:
using (sliderTick.BeginAbsoluteSequence(fadeStartTime))
sliderTick.FadeOut(fadeDuration);
2018-04-13 17:19:50 +08:00
break;
2019-04-01 11:44:46 +08:00
case DrawableSpinner spinner:
// hide elements we don't care about.
// todo: hide background
2018-04-13 17:19:50 +08:00
using (spinner.BeginAbsoluteSequence(fadeStartTime))
spinner.FadeOut(fadeDuration);
2018-04-13 17:19:50 +08:00
break;
}
}
2021-05-15 11:26:16 +08:00
private (double fadeStartTime, double fadeDuration) getFadeOutParameters(DrawableOsuHitObject drawableObject)
{
switch (drawableObject)
{
case DrawableSliderTail tail:
// Use the same fade sequence as the slider head.
Debug.Assert(tail.Slider != null);
return getParameters(tail.Slider.HeadCircle);
case DrawableSliderRepeat repeat:
// Use the same fade sequence as the slider head.
Debug.Assert(repeat.Slider != null);
return getParameters(repeat.Slider.HeadCircle);
default:
return getParameters(drawableObject.HitObject);
}
2021-05-15 11:26:16 +08:00
static (double fadeStartTime, double fadeDuration) getParameters(OsuHitObject hitObject)
{
double fadeOutStartTime = hitObject.StartTime - hitObject.TimePreempt + hitObject.TimeFadeIn;
2022-05-12 16:19:07 +08:00
double fadeOutDuration = hitObject.TimePreempt * FADE_OUT_DURATION_MULTIPLIER;
// new duration from completed fade in to end (before fading out)
double longFadeDuration = hitObject.GetEndTime() - fadeOutStartTime;
switch (hitObject)
{
2022-06-24 20:25:23 +08:00
case Slider:
return (fadeOutStartTime, longFadeDuration);
2022-06-24 20:25:23 +08:00
case SliderTick:
double tickFadeOutDuration = Math.Min(hitObject.TimePreempt - DrawableSliderTick.ANIM_DURATION, 1000);
return (hitObject.StartTime - tickFadeOutDuration, tickFadeOutDuration);
2022-06-24 20:25:23 +08:00
case Spinner:
return (fadeOutStartTime + longFadeDuration, fadeOutDuration);
default:
return (fadeOutStartTime, fadeOutDuration);
}
}
}
private static void hideSpinnerApproachCircle(DrawableSpinner spinner)
{
var approachCircle = (spinner.Body.Drawable as IHasApproachCircle)?.ApproachCircle;
if (approachCircle == null)
return;
using (spinner.BeginAbsoluteSequence(spinner.HitObject.StartTime - spinner.HitObject.TimePreempt))
approachCircle.Hide();
}
}
}