Add short fade to flashlight dimming

This commit is contained in:
David Zhao 2019-04-12 15:33:31 +09:00
parent 69748abedc
commit d9ed68b189
1 changed files with 14 additions and 13 deletions

View File

@ -21,8 +21,6 @@ public class OsuModFlashlight : ModFlashlight<OsuHitObject>, IApplicableToDrawab
private const float default_flashlight_size = 180;
private int trackingSliders;
private OsuFlashlight flashlight;
public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight();
@ -31,27 +29,30 @@ public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
{
foreach (DrawableSlider drawable in drawables.OfType<DrawableSlider>())
{
drawable.Tracking.ValueChanged += updateTrackingSliders;
drawable.Tracking.ValueChanged += flashlight.OnSliderTrackingChange;
}
}
private void updateTrackingSliders(ValueChangedEvent<bool> value)
{
if (value.NewValue)
trackingSliders++;
else
trackingSliders--;
flashlight.FlashlightDim = trackingSliders > 0 ? 0.8f : 0.0f;
}
private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition
{
private int trackingSliders;
public OsuFlashlight()
{
FlashlightSize = new Vector2(0, getSizeFor(0));
}
public void OnSliderTrackingChange(ValueChangedEvent<bool> e)
{
if (e.NewValue)
trackingSliders++;
else
trackingSliders--;
// If there are any sliders in a tracking state, apply a dim to the entire playfield over a brief duration.
this.TransformTo(nameof(FlashlightDim), trackingSliders > 0 ? 0.8f : 0.0f, 50);
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
FlashlightPosition = e.MousePosition;