2019-01-24 08:43:03 +00:00
|
|
|
// 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.
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-11-11 17:38:12 +00:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2018-11-11 17:38:12 +00:00
|
|
|
using osu.Framework.Graphics;
|
2019-07-23 06:17:02 +00:00
|
|
|
using osu.Framework.Graphics.Batches;
|
2018-11-11 17:38:12 +00:00
|
|
|
using osu.Framework.Graphics.OpenGL.Vertices;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
using osu.Framework.Graphics.Shaders;
|
2019-03-27 10:29:27 +00:00
|
|
|
using osu.Framework.Graphics.Sprites;
|
2018-11-11 17:38:12 +00:00
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
2018-04-13 09:19:50 +00:00
|
|
|
using osu.Game.Graphics;
|
2019-07-23 06:17:02 +00:00
|
|
|
using osu.Game.Graphics.OpenGL.Vertices;
|
2018-11-11 17:38:12 +00:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2019-04-25 10:56:57 +00:00
|
|
|
using osu.Game.Scoring;
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mods
|
|
|
|
{
|
2018-11-30 05:48:19 +00:00
|
|
|
public abstract class ModFlashlight : Mod
|
2018-04-13 09:19:50 +00:00
|
|
|
{
|
|
|
|
public override string Name => "Flashlight";
|
2018-11-30 08:16:00 +00:00
|
|
|
public override string Acronym => "FL";
|
2020-01-14 13:22:00 +00:00
|
|
|
public override IconUsage? Icon => OsuIcon.ModFlashlight;
|
2018-04-13 09:19:50 +00:00
|
|
|
public override ModType Type => ModType.DifficultyIncrease;
|
|
|
|
public override string Description => "Restricted view area.";
|
|
|
|
public override bool Ranked => true;
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2018-11-30 05:48:19 +00:00
|
|
|
internal ModFlashlight()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-03-19 14:44:15 +00:00
|
|
|
public abstract class ModFlashlight<T> : ModFlashlight, IApplicableToDrawableRuleset<T>, IApplicableToScoreProcessor
|
2018-11-30 05:48:19 +00:00
|
|
|
where T : HitObject
|
|
|
|
{
|
2018-11-11 17:38:12 +00:00
|
|
|
public const double FLASHLIGHT_FADE_DURATION = 800;
|
|
|
|
protected readonly BindableInt Combo = new BindableInt();
|
|
|
|
|
|
|
|
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
|
|
|
|
{
|
|
|
|
Combo.BindTo(scoreProcessor.Combo);
|
|
|
|
}
|
|
|
|
|
2019-04-25 10:56:57 +00:00
|
|
|
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
|
|
|
|
|
2019-03-20 02:22:34 +00:00
|
|
|
public virtual void ApplyToDrawableRuleset(DrawableRuleset<T> drawableRuleset)
|
2018-11-11 17:38:12 +00:00
|
|
|
{
|
|
|
|
var flashlight = CreateFlashlight();
|
|
|
|
flashlight.Combo = Combo;
|
|
|
|
flashlight.RelativeSizeAxes = Axes.Both;
|
|
|
|
flashlight.Colour = Color4.Black;
|
2019-03-20 02:22:34 +00:00
|
|
|
drawableRuleset.KeyBindingInputManager.Add(flashlight);
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-03-20 02:22:34 +00:00
|
|
|
flashlight.Breaks = drawableRuleset.Beatmap.Breaks;
|
2018-11-11 17:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Flashlight CreateFlashlight();
|
|
|
|
|
|
|
|
public abstract class Flashlight : Drawable
|
|
|
|
{
|
|
|
|
internal BindableInt Combo;
|
2019-03-07 09:30:18 +00:00
|
|
|
private IShader shader;
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-04-02 02:56:22 +00:00
|
|
|
protected override DrawNode CreateDrawNode() => new FlashlightDrawNode(this);
|
2018-11-11 17:38:12 +00:00
|
|
|
|
|
|
|
public override bool RemoveCompletedTransforms => false;
|
|
|
|
|
|
|
|
public List<BreakPeriod> Breaks;
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ShaderManager shaderManager)
|
|
|
|
{
|
2018-11-14 23:33:13 +00:00
|
|
|
shader = shaderManager.Load("PositionAndColour", FragmentShader);
|
2018-11-11 17:38:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Combo.ValueChanged += OnComboChange;
|
|
|
|
|
2019-04-12 08:39:25 +00:00
|
|
|
using (BeginAbsoluteSequence(0))
|
2018-11-11 17:38:12 +00:00
|
|
|
{
|
2019-04-12 08:39:25 +00:00
|
|
|
foreach (var breakPeriod in Breaks)
|
|
|
|
{
|
|
|
|
if (breakPeriod.Duration < FLASHLIGHT_FADE_DURATION * 2) continue;
|
2018-11-14 23:33:13 +00:00
|
|
|
|
2019-04-12 08:39:25 +00:00
|
|
|
this.Delay(breakPeriod.StartTime + FLASHLIGHT_FADE_DURATION).FadeOutFromOne(FLASHLIGHT_FADE_DURATION);
|
|
|
|
this.Delay(breakPeriod.EndTime - FLASHLIGHT_FADE_DURATION).FadeInFromZero(FLASHLIGHT_FADE_DURATION);
|
|
|
|
}
|
2018-11-11 17:38:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 09:56:34 +00:00
|
|
|
protected abstract void OnComboChange(ValueChangedEvent<int> e);
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2018-11-14 23:33:13 +00:00
|
|
|
protected abstract string FragmentShader { get; }
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2018-11-14 23:33:13 +00:00
|
|
|
private Vector2 flashlightPosition;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
2018-11-14 23:33:13 +00:00
|
|
|
protected Vector2 FlashlightPosition
|
|
|
|
{
|
|
|
|
get => flashlightPosition;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (flashlightPosition == value) return;
|
|
|
|
|
|
|
|
flashlightPosition = value;
|
|
|
|
Invalidate(Invalidation.DrawNode);
|
|
|
|
}
|
|
|
|
}
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2018-11-14 23:33:13 +00:00
|
|
|
private Vector2 flashlightSize;
|
2019-02-28 04:31:40 +00:00
|
|
|
|
2018-11-14 23:33:13 +00:00
|
|
|
protected Vector2 FlashlightSize
|
|
|
|
{
|
|
|
|
get => flashlightSize;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (flashlightSize == value) return;
|
|
|
|
|
|
|
|
flashlightSize = value;
|
|
|
|
Invalidate(Invalidation.DrawNode);
|
|
|
|
}
|
|
|
|
}
|
2019-04-12 01:47:22 +00:00
|
|
|
|
2019-04-12 02:23:40 +00:00
|
|
|
private float flashlightDim;
|
2019-04-12 01:47:22 +00:00
|
|
|
|
2019-04-12 02:23:40 +00:00
|
|
|
public float FlashlightDim
|
2019-04-12 01:47:22 +00:00
|
|
|
{
|
2019-04-12 02:23:40 +00:00
|
|
|
get => flashlightDim;
|
2019-04-12 01:47:22 +00:00
|
|
|
set
|
|
|
|
{
|
2019-04-12 02:23:40 +00:00
|
|
|
if (flashlightDim == value) return;
|
2019-04-12 01:47:22 +00:00
|
|
|
|
2019-04-12 02:23:40 +00:00
|
|
|
flashlightDim = value;
|
2019-04-12 01:47:22 +00:00
|
|
|
Invalidate(Invalidation.DrawNode);
|
|
|
|
}
|
|
|
|
}
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-04-02 02:56:22 +00:00
|
|
|
private class FlashlightDrawNode : DrawNode
|
2018-11-11 17:38:12 +00:00
|
|
|
{
|
2019-04-02 02:56:22 +00:00
|
|
|
protected new Flashlight Source => (Flashlight)base.Source;
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-04-02 02:56:22 +00:00
|
|
|
private IShader shader;
|
|
|
|
private Quad screenSpaceDrawQuad;
|
|
|
|
private Vector2 flashlightPosition;
|
|
|
|
private Vector2 flashlightSize;
|
2019-05-07 03:04:58 +00:00
|
|
|
private float flashlightDim;
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-08-07 08:33:30 +00:00
|
|
|
private readonly VertexBatch<PositionAndColourVertex> quadBatch = new QuadBatch<PositionAndColourVertex>(1, 1);
|
2019-07-23 06:17:02 +00:00
|
|
|
private readonly Action<TexturedVertex2D> addAction;
|
|
|
|
|
2019-04-02 02:56:22 +00:00
|
|
|
public FlashlightDrawNode(Flashlight source)
|
|
|
|
: base(source)
|
|
|
|
{
|
2019-07-23 06:17:02 +00:00
|
|
|
addAction = v => quadBatch.Add(new PositionAndColourVertex
|
|
|
|
{
|
|
|
|
Position = v.Position,
|
|
|
|
Colour = v.Colour
|
|
|
|
});
|
2019-04-02 02:56:22 +00:00
|
|
|
}
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-04-02 02:56:22 +00:00
|
|
|
public override void ApplyState()
|
|
|
|
{
|
|
|
|
base.ApplyState();
|
|
|
|
|
|
|
|
shader = Source.shader;
|
|
|
|
screenSpaceDrawQuad = Source.ScreenSpaceDrawQuad;
|
|
|
|
flashlightPosition = Vector2Extensions.Transform(Source.FlashlightPosition, DrawInfo.Matrix);
|
2019-05-07 03:04:58 +00:00
|
|
|
flashlightSize = Source.FlashlightSize * DrawInfo.Matrix.ExtractScale().Xy;
|
|
|
|
flashlightDim = Source.FlashlightDim;
|
2019-04-02 02:56:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
|
|
|
{
|
|
|
|
base.Draw(vertexAction);
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-04-02 02:56:22 +00:00
|
|
|
shader.Bind();
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-04-02 02:56:22 +00:00
|
|
|
shader.GetUniform<Vector2>("flashlightPos").UpdateValue(ref flashlightPosition);
|
|
|
|
shader.GetUniform<Vector2>("flashlightSize").UpdateValue(ref flashlightSize);
|
2019-05-07 03:07:45 +00:00
|
|
|
shader.GetUniform<float>("flashlightDim").UpdateValue(ref flashlightDim);
|
2018-11-11 17:38:12 +00:00
|
|
|
|
2019-07-23 06:17:02 +00:00
|
|
|
DrawQuad(Texture.WhitePixel, screenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: addAction);
|
2019-04-02 02:56:22 +00:00
|
|
|
|
|
|
|
shader.Unbind();
|
|
|
|
}
|
2019-08-07 08:33:30 +00:00
|
|
|
|
|
|
|
protected override void Dispose(bool isDisposing)
|
|
|
|
{
|
|
|
|
base.Dispose(isDisposing);
|
|
|
|
quadBatch?.Dispose();
|
|
|
|
}
|
2018-11-11 17:38:12 +00:00
|
|
|
}
|
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
}
|
|
|
|
}
|