1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 06:52:56 +08:00
osu-lazer/osu.Game.Rulesets.Osu/Mods/OsuModHidden.cs

165 lines
6.3 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
using System;
using System.Diagnostics;
using System.Linq;
2018-04-13 17:19:50 +08:00
using osu.Framework.Graphics;
using osu.Game.Beatmaps;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Objects;
2018-04-13 17:19:50 +08:00
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;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Osu.Mods
{
2018-06-06 12:51:51 +08:00
public class OsuModHidden : ModHidden
2018-04-13 17:19:50 +08:00
{
public override string Description => @"Play with no approach circles and fading circles/sliders.";
public override double ScoreMultiplier => 1.06;
public override Type[] IncompatibleMods => new[] { typeof(OsuModTraceable), typeof(OsuModSpinIn) };
2018-04-13 17:19:50 +08:00
private const double fade_in_duration_multiplier = 0.4;
private 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)
{
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)
{
applyState(hitObject, true);
}
2020-11-05 14:36:44 +08:00
protected override void ApplyNormalVisibilityState(DrawableHitObject hitObject, ArmedState state)
{
applyState(hitObject, false);
}
private void applyState(DrawableHitObject drawableObject, bool increaseVisibility)
2018-04-13 17:19:50 +08:00
{
if (!(drawableObject is DrawableOsuHitObject drawableOsuObject))
2018-04-13 17:19:50 +08:00
return;
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
switch (drawableObject)
2018-04-13 17:19:50 +08:00
{
case DrawableSliderTail _:
2021-05-14 21:56:13 +08:00
using (drawableObject.BeginAbsoluteSequence(fadeStartTime))
2021-05-14 21:30:58 +08:00
drawableObject.FadeOut(fadeDuration);
break;
case DrawableSliderRepeat sliderRepeat:
2021-05-14 21:56:13 +08:00
using (drawableObject.BeginAbsoluteSequence(fadeStartTime))
// only apply to circle piece reverse arrow is not affected by hidden.
2021-05-14 21:30:58 +08:00
sliderRepeat.CirclePiece.FadeOut(fadeDuration);
break;
2018-04-13 17:19:50 +08:00
case DrawableHitCircle circle:
Drawable fadeTarget = circle;
if (increaseVisibility)
{
// only fade the circle piece (not the approach circle) for the increased visibility object.
fadeTarget = circle.CirclePiece;
}
else
{
// we don't want to see the approach circle
2021-05-14 21:23:56 +08:00
using (circle.BeginAbsoluteSequence(hitObject.StartTime - hitObject.TimePreempt))
circle.ApproachCircle.Hide();
}
2018-04-13 17:19:50 +08:00
2021-05-14 21:56:13 +08:00
using (drawableObject.BeginAbsoluteSequence(fadeStartTime))
2021-05-14 21:30:58 +08:00
fadeTarget.FadeOut(fadeDuration);
2018-04-13 17:19:50 +08:00
break;
2019-04-01 11:44:46 +08:00
2018-04-13 17:19:50 +08:00
case DrawableSlider slider:
2021-05-14 21:56:13 +08:00
using (slider.BeginAbsoluteSequence(fadeStartTime))
2021-05-14 21:30:58 +08:00
slider.Body.FadeOut(fadeDuration, Easing.Out);
2018-04-13 17:19:50 +08:00
break;
2019-04-01 11:44:46 +08:00
2018-04-13 17:19:50 +08:00
case DrawableSliderTick sliderTick:
2021-05-14 21:56:13 +08:00
using (sliderTick.BeginAbsoluteSequence(fadeStartTime))
2021-05-14 21:30:58 +08:00
sliderTick.FadeOut(fadeDuration);
2018-04-13 17:19:50 +08:00
break;
2019-04-01 11:44:46 +08:00
2018-04-13 17:19:50 +08:00
case DrawableSpinner spinner:
// hide elements we don't care about.
// todo: hide background
2018-04-13 17:19:50 +08:00
2021-05-14 21:56:13 +08:00
using (spinner.BeginAbsoluteSequence(fadeStartTime))
2021-05-14 21:30:58 +08:00
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)
{
var fadeOutStartTime = hitObject.StartTime - hitObject.TimePreempt + hitObject.TimeFadeIn;
var fadeOutDuration = hitObject.TimePreempt * fade_out_duration_multiplier;
// new duration from completed fade in to end (before fading out)
var longFadeDuration = hitObject.GetEndTime() - fadeOutStartTime;
switch (hitObject)
{
case Slider _:
return (fadeOutStartTime, longFadeDuration);
case SliderTick _:
var tickFadeOutDuration = Math.Min(hitObject.TimePreempt - DrawableSliderTick.ANIM_DURATION, 1000);
return (hitObject.StartTime - tickFadeOutDuration, tickFadeOutDuration);
case Spinner _:
return (fadeOutStartTime + longFadeDuration, fadeOutDuration);
default:
return (fadeOutStartTime, fadeOutDuration);
}
}
}
2018-04-13 17:19:50 +08:00
}
}