From 664a4ba540677fb6851d7a6c7277bc1eb788928c Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 12 Apr 2019 10:47:22 +0900 Subject: [PATCH 01/17] Implement flashlight dimming on slider slide --- .../Mods/OsuModFlashlight.cs | 30 +++++++++++++++++-- .../Objects/Drawables/DrawableRepeatPoint.cs | 2 +- .../Objects/Drawables/DrawableSlider.cs | 4 +-- osu.Game/Rulesets/Mods/ModFlashlight.cs | 17 +++++++++++ 4 files changed, 48 insertions(+), 5 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index 2c40d18f1b..26c0c26f0f 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -1,23 +1,49 @@ // Copyright (c) ppy Pty Ltd . 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 + public class OsuModFlashlight : ModFlashlight, 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 drawables) + { + foreach (DrawableSlider drawable in drawables.OfType()) + { + drawable.Tracking.ValueChanged += updateTrackingSliders; + } + } + + private void updateTrackingSliders(ValueChangedEvent value) + { + if (value.NewValue) + trackingSliders++; + else + trackingSliders--; + + flashlight.FlashlightLightness = trackingSliders > 0 ? 0.2f : 1.0f; + } private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition { diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableRepeatPoint.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableRepeatPoint.cs index edf2d90c08..bece2a49cd 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableRepeatPoint.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableRepeatPoint.cs @@ -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() diff --git a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs index 57ea0abdd8..c1a4c1981f 100644 --- a/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs +++ b/osu.Game.Rulesets.Osu/Objects/Drawables/DrawableSlider.cs @@ -130,13 +130,13 @@ namespace osu.Game.Rulesets.Osu.Objects.Drawables } } - public bool Tracking; + public readonly Bindable Tracking = new Bindable(); 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); diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index 0ad99d13ff..fa070dc9e8 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -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 vertexAction) { @@ -153,6 +169,7 @@ namespace osu.Game.Rulesets.Mods Shader.GetUniform("flashlightPos").UpdateValue(ref FlashlightPosition); Shader.GetUniform("flashlightSize").UpdateValue(ref FlashlightSize); + Shader.GetUniform("flashlightLightness").UpdateValue(ref FlashlightLightness); Texture.WhitePixel.DrawQuad(ScreenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction); From 846a4835ca3a5915a31318d8b67472eb0ab636d2 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 12 Apr 2019 11:23:40 +0900 Subject: [PATCH 02/17] Invert flashlight dim --- osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs | 2 +- osu.Game/Rulesets/Mods/ModFlashlight.cs | 16 ++++++++-------- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index 26c0c26f0f..6a57e39616 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -42,7 +42,7 @@ namespace osu.Game.Rulesets.Osu.Mods else trackingSliders--; - flashlight.FlashlightLightness = trackingSliders > 0 ? 0.2f : 1.0f; + flashlight.FlashlightDim = trackingSliders > 0 ? 0.8f : 0.0f; } private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index fa070dc9e8..e454c59fab 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -80,7 +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; + flashNode.FlashlightDim = FlashlightDim; } [BackgroundDependencyLoader] @@ -138,16 +138,16 @@ namespace osu.Game.Rulesets.Mods } } - private float flashlightLightness = 1.0f; + private float flashlightDim; - public float FlashlightLightness + public float FlashlightDim { - get => flashlightLightness; + get => flashlightDim; set { - if (flashlightLightness == value) return; + if (flashlightDim == value) return; - flashlightLightness = value; + flashlightDim = value; Invalidate(Invalidation.DrawNode); } } @@ -159,7 +159,7 @@ namespace osu.Game.Rulesets.Mods public Quad ScreenSpaceDrawQuad; public Vector2 FlashlightPosition; public Vector2 FlashlightSize; - public float FlashlightLightness; + public float FlashlightDim; public override void Draw(Action vertexAction) { @@ -169,7 +169,7 @@ namespace osu.Game.Rulesets.Mods Shader.GetUniform("flashlightPos").UpdateValue(ref FlashlightPosition); Shader.GetUniform("flashlightSize").UpdateValue(ref FlashlightSize); - Shader.GetUniform("flashlightLightness").UpdateValue(ref FlashlightLightness); + Shader.GetUniform("flashlightDim").UpdateValue(ref FlashlightDim); Texture.WhitePixel.DrawQuad(ScreenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction); From dba4ccdf74b401f6f07584df67acd4ead0c49c89 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 12 Apr 2019 14:53:23 +0900 Subject: [PATCH 03/17] Add back flashlight testcase --- .../TestCaseFlashlight.cs | 18 ++++++++++++++++++ osu.Game/Tests/Visual/AllPlayersTestCase.cs | 12 +++++------- osu.Game/Tests/Visual/PlayerTestCase.cs | 13 ++++--------- 3 files changed, 27 insertions(+), 16 deletions(-) create mode 100644 osu.Game.Rulesets.Osu.Tests/TestCaseFlashlight.cs diff --git a/osu.Game.Rulesets.Osu.Tests/TestCaseFlashlight.cs b/osu.Game.Rulesets.Osu.Tests/TestCaseFlashlight.cs new file mode 100644 index 0000000000..28a732cc49 --- /dev/null +++ b/osu.Game.Rulesets.Osu.Tests/TestCaseFlashlight.cs @@ -0,0 +1,18 @@ +// Copyright (c) ppy Pty Ltd . 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 TestCaseFlashlight : TestCaseOsuPlayer + { + protected override Player CreatePlayer(Ruleset ruleset) + { + Beatmap.Value.Mods.Value = new Mod[] { new OsuModAutoplay(), new OsuModFlashlight(), }; + return base.CreatePlayer(ruleset); + } + } +} diff --git a/osu.Game/Tests/Visual/AllPlayersTestCase.cs b/osu.Game/Tests/Visual/AllPlayersTestCase.cs index 4ef9b346b0..6747493509 100644 --- a/osu.Game/Tests/Visual/AllPlayersTestCase.cs +++ b/osu.Game/Tests/Visual/AllPlayersTestCase.cs @@ -7,6 +7,7 @@ using osu.Framework.Graphics.Shapes; 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; @@ -26,13 +27,6 @@ namespace osu.Game.Tests.Visual [BackgroundDependencyLoader] private void load(RulesetStore rulesets) { - Add(new Box - { - RelativeSizeAxes = Framework.Graphics.Axes.Both, - Colour = Color4.Black, - Depth = int.MaxValue - }); - foreach (var r in rulesets.AvailableRulesets) { Player p = null; @@ -50,6 +44,10 @@ namespace osu.Game.Tests.Visual AddCheckSteps(); } + + OsuConfigManager manager; + Dependencies.Cache(manager = new OsuConfigManager(LocalStorage)); + manager.GetBindable(OsuSetting.DimLevel).Value = 1.0; } protected abstract void AddCheckSteps(); diff --git a/osu.Game/Tests/Visual/PlayerTestCase.cs b/osu.Game/Tests/Visual/PlayerTestCase.cs index 3bf707fade..8ec822957f 100644 --- a/osu.Game/Tests/Visual/PlayerTestCase.cs +++ b/osu.Game/Tests/Visual/PlayerTestCase.cs @@ -3,15 +3,13 @@ using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Graphics; -using osu.Framework.Graphics.Shapes; 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; using osu.Game.Tests.Beatmaps; -using osuTK.Graphics; namespace osu.Game.Tests.Visual { @@ -29,12 +27,9 @@ namespace osu.Game.Tests.Visual [BackgroundDependencyLoader] private void load() { - Add(new Box - { - RelativeSizeAxes = Axes.Both, - Colour = Color4.Black, - Depth = int.MaxValue - }); + OsuConfigManager manager; + Dependencies.Cache(manager = new OsuConfigManager(LocalStorage)); + manager.GetBindable(OsuSetting.DimLevel).Value = 1.0; } [SetUpSteps] From 69748abedcd1e8e018afd8c55da4e6a36297018d Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 12 Apr 2019 15:09:43 +0900 Subject: [PATCH 04/17] Rename to TestCaseOsuFlashlight --- .../{TestCaseFlashlight.cs => TestCaseOsuFlashlight.cs} | 2 +- osu.Game/Tests/Visual/AllPlayersTestCase.cs | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) rename osu.Game.Rulesets.Osu.Tests/{TestCaseFlashlight.cs => TestCaseOsuFlashlight.cs} (89%) diff --git a/osu.Game.Rulesets.Osu.Tests/TestCaseFlashlight.cs b/osu.Game.Rulesets.Osu.Tests/TestCaseOsuFlashlight.cs similarity index 89% rename from osu.Game.Rulesets.Osu.Tests/TestCaseFlashlight.cs rename to osu.Game.Rulesets.Osu.Tests/TestCaseOsuFlashlight.cs index 28a732cc49..6f198084f5 100644 --- a/osu.Game.Rulesets.Osu.Tests/TestCaseFlashlight.cs +++ b/osu.Game.Rulesets.Osu.Tests/TestCaseOsuFlashlight.cs @@ -7,7 +7,7 @@ using osu.Game.Screens.Play; namespace osu.Game.Rulesets.Osu.Tests { - public class TestCaseFlashlight : TestCaseOsuPlayer + public class TestCaseOsuFlashlight : TestCaseOsuPlayer { protected override Player CreatePlayer(Ruleset ruleset) { diff --git a/osu.Game/Tests/Visual/AllPlayersTestCase.cs b/osu.Game/Tests/Visual/AllPlayersTestCase.cs index 6747493509..882f510b64 100644 --- a/osu.Game/Tests/Visual/AllPlayersTestCase.cs +++ b/osu.Game/Tests/Visual/AllPlayersTestCase.cs @@ -3,7 +3,6 @@ using System.Linq; using osu.Framework.Allocation; -using osu.Framework.Graphics.Shapes; using osu.Framework.Screens; using osu.Framework.Timing; using osu.Game.Beatmaps; @@ -12,7 +11,6 @@ using osu.Game.Rulesets; using osu.Game.Rulesets.Mods; using osu.Game.Screens.Play; using osu.Game.Tests.Beatmaps; -using osuTK.Graphics; namespace osu.Game.Tests.Visual { From d9ed68b18968ce1c1eafd6c3dc466b7119c5e134 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 12 Apr 2019 15:33:31 +0900 Subject: [PATCH 05/17] Add short fade to flashlight dimming --- .../Mods/OsuModFlashlight.cs | 27 ++++++++++--------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index 6a57e39616..5d136e4cbe 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -21,8 +21,6 @@ namespace osu.Game.Rulesets.Osu.Mods private const float default_flashlight_size = 180; - private int trackingSliders; - private OsuFlashlight flashlight; public override Flashlight CreateFlashlight() => flashlight = new OsuFlashlight(); @@ -31,27 +29,30 @@ namespace osu.Game.Rulesets.Osu.Mods { foreach (DrawableSlider drawable in drawables.OfType()) { - drawable.Tracking.ValueChanged += updateTrackingSliders; + drawable.Tracking.ValueChanged += flashlight.OnSliderTrackingChange; } } - private void updateTrackingSliders(ValueChangedEvent 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 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; From e25c7fdb9b5c8de23ef51c39065fbde9c7af2bf1 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Fri, 12 Apr 2019 17:39:25 +0900 Subject: [PATCH 06/17] Use absolute sequence for flashlight breaks --- osu.Game/Rulesets/Mods/ModFlashlight.cs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index e454c59fab..b5a907c0ef 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -95,14 +95,17 @@ 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; + this.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); + 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); + } } } From d1799d197ddc5d0beee07edb14f5bac7537d039a Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Thu, 18 Apr 2019 09:27:30 +0800 Subject: [PATCH 07/17] Update resources and mods usage --- osu.Game.Rulesets.Osu.Tests/TestCaseOsuFlashlight.cs | 3 ++- osu.Game/osu.Game.csproj | 2 +- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/osu.Game.Rulesets.Osu.Tests/TestCaseOsuFlashlight.cs b/osu.Game.Rulesets.Osu.Tests/TestCaseOsuFlashlight.cs index 6f198084f5..1e72591b87 100644 --- a/osu.Game.Rulesets.Osu.Tests/TestCaseOsuFlashlight.cs +++ b/osu.Game.Rulesets.Osu.Tests/TestCaseOsuFlashlight.cs @@ -11,7 +11,8 @@ namespace osu.Game.Rulesets.Osu.Tests { protected override Player CreatePlayer(Ruleset ruleset) { - Beatmap.Value.Mods.Value = new Mod[] { new OsuModAutoplay(), new OsuModFlashlight(), }; + Mods.Value = new Mod[] { new OsuModAutoplay(), new OsuModFlashlight(), }; + return base.CreatePlayer(ruleset); } } diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 1fcbe7c4c1..25a98c9b74 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -15,7 +15,7 @@ - + From dfa5beea89ef6e2f7398723cf60ae386fd2bf738 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 18 Apr 2019 14:24:19 +0900 Subject: [PATCH 08/17] Use the actual scale of Flashlight for FlashlightSize --- osu.Game/Rulesets/Mods/ModFlashlight.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index b5a907c0ef..22c2f6dd51 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -5,6 +5,7 @@ using System; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Bindables; +using osu.Framework.Extensions.MatrixExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.OpenGL.Vertices; using osu.Framework.Graphics.Primitives; @@ -79,7 +80,7 @@ namespace osu.Game.Rulesets.Mods flashNode.Shader = shader; flashNode.ScreenSpaceDrawQuad = ScreenSpaceDrawQuad; flashNode.FlashlightPosition = Vector2Extensions.Transform(FlashlightPosition, DrawInfo.Matrix); - flashNode.FlashlightSize = Vector2Extensions.Transform(FlashlightSize, DrawInfo.Matrix); + flashNode.FlashlightSize = FlashlightSize * DrawInfo.Matrix.ExtractScale().Xy; flashNode.FlashlightDim = FlashlightDim; } From 037e23247f766ce5d0bc71eeeaac4f4787f99dfe Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 18 Apr 2019 14:31:47 +0900 Subject: [PATCH 09/17] Remove unused using --- osu.Game/Rulesets/Mods/ModFlashlight.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index 22c2f6dd51..c0816b2457 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -5,7 +5,6 @@ using System; using System.Collections.Generic; using osu.Framework.Allocation; using osu.Framework.Bindables; -using osu.Framework.Extensions.MatrixExtensions; using osu.Framework.Graphics; using osu.Framework.Graphics.OpenGL.Vertices; using osu.Framework.Graphics.Primitives; From 3c252d79ead8fc1e7a13e8d12b3210bce989d402 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 22 Apr 2019 15:59:47 +0900 Subject: [PATCH 10/17] Use var, rework dim application logic --- .../Mods/OsuModFlashlight.cs | 24 +++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index 5d136e4cbe..b2bc5f4320 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -1,6 +1,7 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. +using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Bindables; @@ -27,9 +28,9 @@ namespace osu.Game.Rulesets.Osu.Mods public void ApplyToDrawableHitObjects(IEnumerable drawables) { - foreach (DrawableSlider drawable in drawables.OfType()) + foreach (var s in drawables.OfType()) { - drawable.Tracking.ValueChanged += flashlight.OnSliderTrackingChange; + s.Tracking.ValueChanged += flashlight.OnSliderTrackingChange; } } @@ -44,13 +45,28 @@ namespace osu.Game.Rulesets.Osu.Mods public void OnSliderTrackingChange(ValueChangedEvent e) { + // If any sliders are in a tracking state, apply a dim to the entire playfield over a brief duration. if (e.NewValue) + { trackingSliders++; + // This check being here ensures we're only applying a dim if and only if a slider begins tracking. + if (trackingSliders == 1) + { + this.TransformTo(nameof(FlashlightDim), 0.8f, 50); + } + } 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); + if (trackingSliders == 0) + { + this.TransformTo(nameof(FlashlightDim), 0.0f, 50); + } + } + + if (trackingSliders < 0) + throw new InvalidOperationException($"The number of {nameof(trackingSliders)} cannot be below 0."); } protected override bool OnMouseMove(MouseMoveEvent e) From 3fbbb7dcf9901fcd5595d5e1a88d22ce667aa94e Mon Sep 17 00:00:00 2001 From: David Zhao Date: Mon, 22 Apr 2019 16:39:28 +0900 Subject: [PATCH 11/17] Move intiial fade outside of absolute sequence --- osu.Game/Rulesets/Mods/ModFlashlight.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index c0816b2457..c3ac00f3ad 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -95,10 +95,10 @@ namespace osu.Game.Rulesets.Mods Combo.ValueChanged += OnComboChange; + this.FadeInFromZero(FLASHLIGHT_FADE_DURATION); + using (BeginAbsoluteSequence(0)) { - this.FadeInFromZero(FLASHLIGHT_FADE_DURATION); - foreach (var breakPeriod in Breaks) { if (breakPeriod.Duration < FLASHLIGHT_FADE_DURATION * 2) continue; From 9890884726181bcb8605a39c5cf3bb2c9be38c6b Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 23 Apr 2019 14:23:09 +0900 Subject: [PATCH 12/17] Remove fade in, update comment --- osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs | 3 ++- osu.Game/Rulesets/Mods/ModFlashlight.cs | 2 -- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index b2bc5f4320..597c430e16 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -49,7 +49,8 @@ namespace osu.Game.Rulesets.Osu.Mods if (e.NewValue) { trackingSliders++; - // This check being here ensures we're only applying a dim if and only if a slider begins tracking. + // The fade should only be applied if tracking sliders is increasing from 0 to 1, and cannot be a result of a slider losing tracking. + // As a result, this logic must be exclusive to when e.NewValue is true. if (trackingSliders == 1) { this.TransformTo(nameof(FlashlightDim), 0.8f, 50); diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index c3ac00f3ad..54331508a0 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -95,8 +95,6 @@ namespace osu.Game.Rulesets.Mods Combo.ValueChanged += OnComboChange; - this.FadeInFromZero(FLASHLIGHT_FADE_DURATION); - using (BeginAbsoluteSequence(0)) { foreach (var breakPeriod in Breaks) From 67382724f633e1f79e4e7f18204de3f49200acf5 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Wed, 24 Apr 2019 16:58:13 +0900 Subject: [PATCH 13/17] Reword and reoganise logic --- .../Mods/OsuModFlashlight.cs | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index 597c430e16..c2d6ec7934 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -36,7 +36,7 @@ namespace osu.Game.Rulesets.Osu.Mods private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition { - private int trackingSliders; + private int slidersCurrentlyTracking; public OsuFlashlight() { @@ -45,29 +45,22 @@ namespace osu.Game.Rulesets.Osu.Mods public void OnSliderTrackingChange(ValueChangedEvent e) { - // If any sliders are in a tracking state, apply a dim to the entire playfield over a brief duration. + // If any sliders are in a tracking state, a further dim should be applied to the (remaining) visible portion of the playfield over a brief duration. if (e.NewValue) { - trackingSliders++; - // The fade should only be applied if tracking sliders is increasing from 0 to 1, and cannot be a result of a slider losing tracking. - // As a result, this logic must be exclusive to when e.NewValue is true. - if (trackingSliders == 1) - { + // The transform should only be applied when the first slider begins tracking. + if (++slidersCurrentlyTracking == 1) this.TransformTo(nameof(FlashlightDim), 0.8f, 50); - } } else { - trackingSliders--; + if (slidersCurrentlyTracking == 0) + throw new InvalidOperationException($"The number of {nameof(slidersCurrentlyTracking)} cannot be below 0."); - if (trackingSliders == 0) - { + // The fade is restored after the last slider exits a tracked state. + if (--slidersCurrentlyTracking == 0) this.TransformTo(nameof(FlashlightDim), 0.0f, 50); - } } - - if (trackingSliders < 0) - throw new InvalidOperationException($"The number of {nameof(trackingSliders)} cannot be below 0."); } protected override bool OnMouseMove(MouseMoveEvent e) From 8f101e4f604bac362799fe8c171b8cdaee4aef28 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 24 Apr 2019 18:25:38 +0900 Subject: [PATCH 14/17] Remove unnecessary multi-slider tracking logic --- .../Mods/OsuModFlashlight.cs | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index c2d6ec7934..8e98a02392 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -36,8 +36,6 @@ namespace osu.Game.Rulesets.Osu.Mods private class OsuFlashlight : Flashlight, IRequireHighFrequencyMousePosition { - private int slidersCurrentlyTracking; - public OsuFlashlight() { FlashlightSize = new Vector2(0, getSizeFor(0)); @@ -45,22 +43,8 @@ namespace osu.Game.Rulesets.Osu.Mods public void OnSliderTrackingChange(ValueChangedEvent e) { - // If any sliders are in a tracking state, a further dim should be applied to the (remaining) visible portion of the playfield over a brief duration. - if (e.NewValue) - { - // The transform should only be applied when the first slider begins tracking. - if (++slidersCurrentlyTracking == 1) - this.TransformTo(nameof(FlashlightDim), 0.8f, 50); - } - else - { - if (slidersCurrentlyTracking == 0) - throw new InvalidOperationException($"The number of {nameof(slidersCurrentlyTracking)} cannot be below 0."); - - // The fade is restored after the last slider exits a tracked state. - if (--slidersCurrentlyTracking == 0) - this.TransformTo(nameof(FlashlightDim), 0.0f, 50); - } + // 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) From 90d5c64cf36df3ab147383b3d8e03ae93e6c44cf Mon Sep 17 00:00:00 2001 From: David Zhao Date: Wed, 24 Apr 2019 18:25:55 +0900 Subject: [PATCH 15/17] Remove unused usings --- osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs index 8e98a02392..c0332fbf60 100644 --- a/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs +++ b/osu.Game.Rulesets.Osu/Mods/OsuModFlashlight.cs @@ -1,7 +1,6 @@ // Copyright (c) ppy Pty Ltd . Licensed under the MIT Licence. // See the LICENCE file in the repository root for full licence text. -using System; using System.Collections.Generic; using System.Linq; using osu.Framework.Bindables; From 9ce7d0416bc4dfdeb865507b5926565488b92970 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Thu, 25 Apr 2019 23:16:08 +0900 Subject: [PATCH 16/17] Fix framework version --- osu.Game/osu.Game.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 25a98c9b74..2f0266ce07 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -16,7 +16,7 @@ - + From abc163fa36fac13a90d732267484b3eeffc94668 Mon Sep 17 00:00:00 2001 From: David Zhao Date: Tue, 7 May 2019 12:07:45 +0900 Subject: [PATCH 17/17] Fix merge --- osu.Game/Rulesets/Mods/ModFlashlight.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/osu.Game/Rulesets/Mods/ModFlashlight.cs b/osu.Game/Rulesets/Mods/ModFlashlight.cs index a477868ad0..e174a25df3 100644 --- a/osu.Game/Rulesets/Mods/ModFlashlight.cs +++ b/osu.Game/Rulesets/Mods/ModFlashlight.cs @@ -177,7 +177,7 @@ namespace osu.Game.Rulesets.Mods shader.GetUniform("flashlightPos").UpdateValue(ref flashlightPosition); shader.GetUniform("flashlightSize").UpdateValue(ref flashlightSize); - shader.GetUniform("flashlightDim").UpdateValue(ref FlashlightDim); + shader.GetUniform("flashlightDim").UpdateValue(ref flashlightDim); Texture.WhitePixel.DrawQuad(screenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction);