mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 06:52:55 +08:00
Implement flashlight dimming on slider slide
This commit is contained in:
parent
67a03bbc90
commit
664a4ba540
@ -1,23 +1,49 @@
|
||||
// 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.
|
||||
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Input;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Mods
|
||||
{
|
||||
public class OsuModFlashlight : ModFlashlight<OsuHitObject>
|
||||
public class OsuModFlashlight : ModFlashlight<OsuHitObject>, IApplicableToDrawableHitObjects
|
||||
{
|
||||
public override double ScoreMultiplier => 1.12;
|
||||
|
||||
private const float default_flashlight_size = 180;
|
||||
|
||||
public override Flashlight CreateFlashlight() => new OsuFlashlight();
|
||||
private int trackingSliders;
|
||||
|
||||
private OsuFlashlight flashlight;
|
||||
|
||||
public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight();
|
||||
|
||||
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
|
||||
{
|
||||
foreach (DrawableSlider drawable in drawables.OfType<DrawableSlider>())
|
||||
{
|
||||
drawable.Tracking.ValueChanged += updateTrackingSliders;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateTrackingSliders(ValueChangedEvent<bool> value)
|
||||
{
|
||||
if (value.NewValue)
|
||||
trackingSliders++;
|
||||
else
|
||||
trackingSliders--;
|
||||
|
||||
flashlight.FlashlightLightness = trackingSliders > 0 ? 0.2f : 1.0f;
|
||||
}
|
||||
|
||||
private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition
|
||||
{
|
||||
|
@ -44,7 +44,7 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
protected override void CheckForResult(bool userTriggered, double timeOffset)
|
||||
{
|
||||
if (repeatPoint.StartTime <= Time.Current)
|
||||
ApplyResult(r => r.Type = drawableSlider.Tracking ? HitResult.Great : HitResult.Miss);
|
||||
ApplyResult(r => r.Type = drawableSlider.Tracking.Value ? HitResult.Great : HitResult.Miss);
|
||||
}
|
||||
|
||||
protected override void UpdatePreemptState()
|
||||
|
@ -130,13 +130,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
}
|
||||
}
|
||||
|
||||
public bool Tracking;
|
||||
public readonly Bindable<bool> Tracking = new Bindable<bool>();
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
base.Update();
|
||||
|
||||
Tracking = Ball.Tracking;
|
||||
Tracking.Value = Ball.Tracking;
|
||||
|
||||
double completionProgress = MathHelper.Clamp((Time.Current - slider.StartTime) / slider.Duration, 0, 1);
|
||||
|
||||
|
@ -80,6 +80,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
flashNode.ScreenSpaceDrawQuad = ScreenSpaceDrawQuad;
|
||||
flashNode.FlashlightPosition = Vector2Extensions.Transform(FlashlightPosition, DrawInfo.Matrix);
|
||||
flashNode.FlashlightSize = Vector2Extensions.Transform(FlashlightSize, DrawInfo.Matrix);
|
||||
flashNode.FlashlightLightness = FlashlightLightness;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
@ -136,6 +137,20 @@ namespace osu.Game.Rulesets.Mods
|
||||
Invalidate(Invalidation.DrawNode);
|
||||
}
|
||||
}
|
||||
|
||||
private float flashlightLightness = 1.0f;
|
||||
|
||||
public float FlashlightLightness
|
||||
{
|
||||
get => flashlightLightness;
|
||||
set
|
||||
{
|
||||
if (flashlightLightness == value) return;
|
||||
|
||||
flashlightLightness = value;
|
||||
Invalidate(Invalidation.DrawNode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private class FlashlightDrawNode : DrawNode
|
||||
@ -144,6 +159,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
public Quad ScreenSpaceDrawQuad;
|
||||
public Vector2 FlashlightPosition;
|
||||
public Vector2 FlashlightSize;
|
||||
public float FlashlightLightness;
|
||||
|
||||
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
||||
{
|
||||
@ -153,6 +169,7 @@ namespace osu.Game.Rulesets.Mods
|
||||
|
||||
Shader.GetUniform<Vector2>("flashlightPos").UpdateValue(ref FlashlightPosition);
|
||||
Shader.GetUniform<Vector2>("flashlightSize").UpdateValue(ref FlashlightSize);
|
||||
Shader.GetUniform<float>("flashlightLightness").UpdateValue(ref FlashlightLightness);
|
||||
|
||||
Texture.WhitePixel.DrawQuad(ScreenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction);
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user