1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-14 07:33:20 +08:00

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

View File

@ -21,8 +21,6 @@ namespace osu.Game.Rulesets.Osu.Mods
private const float default_flashlight_size = 180; private const float default_flashlight_size = 180;
private int trackingSliders;
private OsuFlashlight flashlight; private OsuFlashlight flashlight;
public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(); public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight();
@ -31,27 +29,30 @@ namespace osu.Game.Rulesets.Osu.Mods
{ {
foreach (DrawableSlider drawable in drawables.OfType<DrawableSlider>()) 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 class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition
{ {
private int trackingSliders;
public OsuFlashlight() public OsuFlashlight()
{ {
FlashlightSize = new Vector2(0, getSizeFor(0)); 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) protected override bool OnMouseMove(MouseMoveEvent e)
{ {
FlashlightPosition = e.MousePosition; FlashlightPosition = e.MousePosition;