2019-01-24 16:43:03 +08: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 17:19:50 +08:00
|
|
|
|
2018-11-12 01:38:12 +08:00
|
|
|
using System;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using osu.Framework.Allocation;
|
2019-02-21 18:04:31 +08:00
|
|
|
using osu.Framework.Bindables;
|
2018-11-12 01:38:12 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.OpenGL.Vertices;
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
|
|
|
using osu.Framework.Graphics.Shaders;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
|
|
|
using osu.Game.Beatmaps.Timing;
|
2018-04-13 17:19:50 +08:00
|
|
|
using osu.Game.Graphics;
|
2018-11-12 01:38:12 +08:00
|
|
|
using osu.Game.Rulesets.Objects;
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
using osu.Game.Rulesets.UI;
|
2018-11-20 15:51:59 +08:00
|
|
|
using osuTK;
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Mods
|
|
|
|
{
|
2018-11-30 13:48:19 +08:00
|
|
|
public abstract class ModFlashlight : Mod
|
2018-04-13 17:19:50 +08:00
|
|
|
{
|
|
|
|
public override string Name => "Flashlight";
|
2018-11-30 16:16:00 +08:00
|
|
|
public override string Acronym => "FL";
|
2018-04-13 17:19:50 +08:00
|
|
|
public override FontAwesome Icon => FontAwesome.fa_osu_mod_flashlight;
|
|
|
|
public override ModType Type => ModType.DifficultyIncrease;
|
|
|
|
public override string Description => "Restricted view area.";
|
|
|
|
public override bool Ranked => true;
|
2018-11-12 01:38:12 +08:00
|
|
|
|
2018-11-30 13:48:19 +08:00
|
|
|
internal ModFlashlight()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract class ModFlashlight<T> : ModFlashlight, IApplicableToRulesetContainer<T>, IApplicableToScoreProcessor
|
|
|
|
where T : HitObject
|
|
|
|
{
|
2018-11-12 01:38:12 +08:00
|
|
|
public const double FLASHLIGHT_FADE_DURATION = 800;
|
|
|
|
protected readonly BindableInt Combo = new BindableInt();
|
|
|
|
|
|
|
|
public void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
|
|
|
|
{
|
|
|
|
Combo.BindTo(scoreProcessor.Combo);
|
|
|
|
}
|
|
|
|
|
|
|
|
public virtual void ApplyToRulesetContainer(RulesetContainer<T> rulesetContainer)
|
|
|
|
{
|
|
|
|
var flashlight = CreateFlashlight();
|
|
|
|
flashlight.Combo = Combo;
|
|
|
|
flashlight.RelativeSizeAxes = Axes.Both;
|
|
|
|
flashlight.Colour = Color4.Black;
|
|
|
|
rulesetContainer.KeyBindingInputManager.Add(flashlight);
|
|
|
|
|
|
|
|
flashlight.Breaks = rulesetContainer.Beatmap.Breaks;
|
|
|
|
}
|
|
|
|
|
|
|
|
public abstract Flashlight CreateFlashlight();
|
|
|
|
|
|
|
|
public abstract class Flashlight : Drawable
|
|
|
|
{
|
|
|
|
internal BindableInt Combo;
|
|
|
|
private Shader shader;
|
|
|
|
|
|
|
|
protected override DrawNode CreateDrawNode() => new FlashlightDrawNode();
|
|
|
|
|
|
|
|
public override bool RemoveCompletedTransforms => false;
|
|
|
|
|
|
|
|
public List<BreakPeriod> Breaks;
|
|
|
|
|
|
|
|
protected override void ApplyDrawNode(DrawNode node)
|
|
|
|
{
|
|
|
|
base.ApplyDrawNode(node);
|
|
|
|
|
|
|
|
var flashNode = (FlashlightDrawNode)node;
|
|
|
|
|
|
|
|
flashNode.Shader = shader;
|
|
|
|
flashNode.ScreenSpaceDrawQuad = ScreenSpaceDrawQuad;
|
2018-11-16 00:38:38 +08:00
|
|
|
flashNode.FlashlightPosition = Vector2Extensions.Transform(FlashlightPosition, DrawInfo.Matrix);
|
|
|
|
flashNode.FlashlightSize = Vector2Extensions.Transform(FlashlightSize, DrawInfo.Matrix);
|
2018-11-12 01:38:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(ShaderManager shaderManager)
|
|
|
|
{
|
2018-11-15 07:33:13 +08:00
|
|
|
shader = shaderManager.Load("PositionAndColour", FragmentShader);
|
2018-11-12 01:38:12 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
Combo.ValueChanged += OnComboChange;
|
|
|
|
|
|
|
|
this.FadeInFromZero(FLASHLIGHT_FADE_DURATION);
|
|
|
|
|
|
|
|
foreach (var breakPeriod in Breaks)
|
|
|
|
{
|
2018-11-15 07:33:13 +08:00
|
|
|
if (breakPeriod.Duration < FLASHLIGHT_FADE_DURATION * 2) continue;
|
|
|
|
|
2018-11-12 01:38:12 +08:00
|
|
|
this.Delay(breakPeriod.StartTime + FLASHLIGHT_FADE_DURATION).FadeOutFromOne(FLASHLIGHT_FADE_DURATION);
|
|
|
|
this.Delay(breakPeriod.EndTime - FLASHLIGHT_FADE_DURATION).FadeInFromZero(FLASHLIGHT_FADE_DURATION);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-21 17:56:34 +08:00
|
|
|
protected abstract void OnComboChange(ValueChangedEvent<int> e);
|
2018-11-12 01:38:12 +08:00
|
|
|
|
2018-11-15 07:33:13 +08:00
|
|
|
protected abstract string FragmentShader { get; }
|
2018-11-12 01:38:12 +08:00
|
|
|
|
2018-11-15 07:33:13 +08:00
|
|
|
private Vector2 flashlightPosition;
|
|
|
|
protected Vector2 FlashlightPosition
|
|
|
|
{
|
|
|
|
get => flashlightPosition;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (flashlightPosition == value) return;
|
|
|
|
|
|
|
|
flashlightPosition = value;
|
|
|
|
Invalidate(Invalidation.DrawNode);
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 01:38:12 +08:00
|
|
|
|
2018-11-15 07:33:13 +08:00
|
|
|
private Vector2 flashlightSize;
|
|
|
|
protected Vector2 FlashlightSize
|
|
|
|
{
|
|
|
|
get => flashlightSize;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
if (flashlightSize == value) return;
|
|
|
|
|
|
|
|
flashlightSize = value;
|
|
|
|
Invalidate(Invalidation.DrawNode);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-11-12 01:38:12 +08:00
|
|
|
|
|
|
|
private class FlashlightDrawNode : DrawNode
|
|
|
|
{
|
|
|
|
public Shader Shader;
|
|
|
|
public Quad ScreenSpaceDrawQuad;
|
2018-11-16 00:38:38 +08:00
|
|
|
public Vector2 FlashlightPosition;
|
|
|
|
public Vector2 FlashlightSize;
|
2018-11-12 01:38:12 +08:00
|
|
|
|
|
|
|
public override void Draw(Action<TexturedVertex2D> vertexAction)
|
|
|
|
{
|
|
|
|
base.Draw(vertexAction);
|
|
|
|
|
|
|
|
Shader.Bind();
|
|
|
|
|
2018-11-16 00:38:38 +08:00
|
|
|
Shader.GetUniform<Vector2>("flashlightPos").UpdateValue(ref FlashlightPosition);
|
|
|
|
Shader.GetUniform<Vector2>("flashlightSize").UpdateValue(ref FlashlightSize);
|
2018-11-12 01:38:12 +08:00
|
|
|
|
|
|
|
Texture.WhitePixel.DrawQuad(ScreenSpaceDrawQuad, DrawColourInfo.Colour, vertexAction: vertexAction);
|
|
|
|
|
|
|
|
Shader.Unbind();
|
|
|
|
}
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
}
|
|
|
|
}
|