1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-28 07:23:14 +08:00

Merge pull request #4617 from nyquillerium/flashlight-dim

Implement dimming for sliding on sliders with flashlight mod
This commit is contained in:
Dan Balasescu 2019-05-08 13:51:47 +09:00 committed by GitHub
commit 6559869880
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 85 additions and 13 deletions

View File

@ -0,0 +1,19 @@
// 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 osu.Game.Rulesets.Mods;
using osu.Game.Rulesets.Osu.Mods;
using osu.Game.Screens.Play;
namespace osu.Game.Rulesets.Osu.Tests
{
public class TestCaseOsuFlashlight : TestCaseOsuPlayer
{
protected override Player CreatePlayer(Ruleset ruleset)
{
Mods.Value = new Mod[] { new OsuModAutoplay(), new OsuModFlashlight(), };
return base.CreatePlayer(ruleset);
}
}
}

View File

@ -1,23 +1,37 @@
// 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 OsuFlashlight flashlight;
public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight();
public void ApplyToDrawableHitObjects(IEnumerable<DrawableHitObject> drawables)
{
foreach (var s in drawables.OfType<DrawableSlider>())
{
s.Tracking.ValueChanged += flashlight.OnSliderTrackingChange;
}
}
private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition
{
@ -26,6 +40,12 @@ namespace osu.Game.Rulesets.Osu.Mods
FlashlightSize = new Vector2(0, getSizeFor(0));
}
public void OnSliderTrackingChange(ValueChangedEvent<bool> e)
{
// If a slider is in a tracking state, a further dim should be applied to the (remaining) visible portion of the playfield over a brief duration.
this.TransformTo(nameof(FlashlightDim), e.NewValue ? 0.8f : 0.0f, 50);
}
protected override bool OnMouseMove(MouseMoveEvent e)
{
FlashlightPosition = e.MousePosition;

View File

@ -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()

View File

@ -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);

View File

@ -85,14 +85,15 @@ namespace osu.Game.Rulesets.Mods
Combo.ValueChanged += OnComboChange;
this.FadeInFromZero(FLASHLIGHT_FADE_DURATION);
foreach (var breakPeriod in Breaks)
using (BeginAbsoluteSequence(0))
{
if (breakPeriod.Duration < FLASHLIGHT_FADE_DURATION * 2) continue;
foreach (var breakPeriod in Breaks)
{
if (breakPeriod.Duration < FLASHLIGHT_FADE_DURATION * 2) continue;
this.Delay(breakPeriod.StartTime + FLASHLIGHT_FADE_DURATION).FadeOutFromOne(FLASHLIGHT_FADE_DURATION);
this.Delay(breakPeriod.EndTime - FLASHLIGHT_FADE_DURATION).FadeInFromZero(FLASHLIGHT_FADE_DURATION);
this.Delay(breakPeriod.StartTime + FLASHLIGHT_FADE_DURATION).FadeOutFromOne(FLASHLIGHT_FADE_DURATION);
this.Delay(breakPeriod.EndTime - FLASHLIGHT_FADE_DURATION).FadeInFromZero(FLASHLIGHT_FADE_DURATION);
}
}
}
@ -128,6 +129,20 @@ namespace osu.Game.Rulesets.Mods
}
}
private float flashlightDim;
public float FlashlightDim
{
get => flashlightDim;
set
{
if (flashlightDim == value) return;
flashlightDim = value;
Invalidate(Invalidation.DrawNode);
}
}
private class FlashlightDrawNode : DrawNode
{
protected new Flashlight Source => (Flashlight)base.Source;
@ -136,6 +151,7 @@ namespace osu.Game.Rulesets.Mods
private Quad screenSpaceDrawQuad;
private Vector2 flashlightPosition;
private Vector2 flashlightSize;
private float flashlightDim;
public FlashlightDrawNode(Flashlight source)
: base(source)
@ -149,7 +165,8 @@ namespace osu.Game.Rulesets.Mods
shader = Source.shader;
screenSpaceDrawQuad = Source.ScreenSpaceDrawQuad;
flashlightPosition = Vector2Extensions.Transform(Source.FlashlightPosition, DrawInfo.Matrix);
flashlightSize = Vector2Extensions.Transform(Source.FlashlightSize, DrawInfo.Matrix);
flashlightSize = Source.FlashlightSize * DrawInfo.Matrix.ExtractScale().Xy;
flashlightDim = Source.FlashlightDim;
}
public override void Draw(Action<TexturedVertex2D> vertexAction)
@ -160,6 +177,7 @@ namespace osu.Game.Rulesets.Mods
shader.GetUniform<Vector2>("flashlightPos").UpdateValue(ref flashlightPosition);
shader.GetUniform<Vector2>("flashlightSize").UpdateValue(ref flashlightSize);
shader.GetUniform<float>("flashlightDim").UpdateValue(ref flashlightDim);
Texture.WhitePixel.DrawQuad(screenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction);

View File

@ -6,6 +6,7 @@ using osu.Framework.Allocation;
using osu.Framework.Screens;
using osu.Framework.Timing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play;
@ -41,6 +42,10 @@ namespace osu.Game.Tests.Visual
AddCheckSteps();
}
OsuConfigManager manager;
Dependencies.Cache(manager = new OsuConfigManager(LocalStorage));
manager.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
}
protected abstract void AddCheckSteps();

View File

@ -2,8 +2,10 @@
// See the LICENCE file in the repository root for full licence text.
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Testing;
using osu.Game.Beatmaps;
using osu.Game.Configuration;
using osu.Game.Rulesets;
using osu.Game.Rulesets.Mods;
using osu.Game.Screens.Play;
@ -22,6 +24,14 @@ namespace osu.Game.Tests.Visual
this.ruleset = ruleset;
}
[BackgroundDependencyLoader]
private void load()
{
OsuConfigManager manager;
Dependencies.Cache(manager = new OsuConfigManager(LocalStorage));
manager.GetBindable<double>(OsuSetting.DimLevel).Value = 1.0;
}
[SetUpSteps]
public void SetUpSteps()
{

View File

@ -14,7 +14,7 @@
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="2.2.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite.Core" Version="2.2.3" />
<PackageReference Include="Newtonsoft.Json" Version="12.0.1" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.128.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2019.417.0" />
<PackageReference Include="ppy.osu.Framework" Version="2019.502.0" />
<PackageReference Include="SharpCompress" Version="0.23.0" />
<PackageReference Include="NUnit" Version="3.11.0" />