mirror of
https://github.com/ppy/osu.git
synced 2024-12-14 07:42:57 +08:00
Implement blinds mod
This commit is contained in:
parent
b011edd85d
commit
b33954d9db
29
osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs
Normal file
29
osu.Game.Rulesets.Osu/Mods/OsuModBlinds.cs
Normal file
@ -0,0 +1,29 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Rulesets.Mods;
|
||||
using osu.Game.Rulesets.Osu.Objects;
|
||||
using osu.Game.Rulesets.Osu.Objects.Drawables;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Mods
|
||||
{
|
||||
public class OsuModBlinds : ModBlinds<OsuHitObject>
|
||||
{
|
||||
public override double ScoreMultiplier => 1.12;
|
||||
private DrawableOsuBlinds flashlight;
|
||||
|
||||
public override void ApplyToRulesetContainer(RulesetContainer<OsuHitObject> rulesetContainer)
|
||||
{
|
||||
rulesetContainer.Overlays.Add(flashlight = new DrawableOsuBlinds(restrictTo: rulesetContainer.Playfield));
|
||||
}
|
||||
|
||||
public override void ApplyToScoreProcessor(ScoreProcessor scoreProcessor)
|
||||
{
|
||||
scoreProcessor.Health.ValueChanged += val => {
|
||||
flashlight.Value = (float)val;
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
96
osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuBlinds.cs
Normal file
96
osu.Game.Rulesets.Osu/Objects/Drawables/DrawableOsuBlinds.cs
Normal file
@ -0,0 +1,96 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using OpenTK.Graphics;
|
||||
using osu.Framework.Allocation;
|
||||
|
||||
namespace osu.Game.Rulesets.Osu.Objects.Drawables
|
||||
{
|
||||
/// <summary>
|
||||
/// Element for the Blinds mod drawing 2 black boxes covering the whole screen which resize inside a restricted area with some leniency.
|
||||
/// </summary>
|
||||
public class DrawableOsuBlinds : Container
|
||||
{
|
||||
private Box box1, box2;
|
||||
private float target = 1;
|
||||
private readonly float easing = 1;
|
||||
private readonly Container restrictTo;
|
||||
|
||||
/// <summary>
|
||||
/// <para>
|
||||
/// Percentage of playfield to extend blinds over. Basically moves the origin points where the blinds start.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// -1 would mean the blinds always cover the whole screen no matter health.
|
||||
/// 0 would mean the blinds will only ever be on the edge of the playfield on 0% health.
|
||||
/// 1 would mean the blinds are fully outside the playfield on 50% health.
|
||||
/// Infinity would mean the blinds are always outside the playfield except on 100% health.
|
||||
/// </para>
|
||||
/// </summary>
|
||||
private const float leniency = 0.2f;
|
||||
|
||||
public DrawableOsuBlinds(Container restrictTo)
|
||||
{
|
||||
this.restrictTo = restrictTo;
|
||||
}
|
||||
|
||||
[BackgroundDependencyLoader]
|
||||
private void load()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
Width = 1;
|
||||
Height = 1;
|
||||
|
||||
Add(box1 = new Box
|
||||
{
|
||||
Anchor = Anchor.TopLeft,
|
||||
Origin = Anchor.TopLeft,
|
||||
Colour = Color4.Black,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Width = 0,
|
||||
Height = 1
|
||||
});
|
||||
Add(box2 = new Box
|
||||
{
|
||||
Anchor = Anchor.TopRight,
|
||||
Origin = Anchor.TopRight,
|
||||
Colour = Color4.Black,
|
||||
RelativeSizeAxes = Axes.Y,
|
||||
Width = 0,
|
||||
Height = 1
|
||||
});
|
||||
}
|
||||
|
||||
protected override void Update()
|
||||
{
|
||||
float start = Parent.ToLocalSpace(restrictTo.ScreenSpaceDrawQuad.TopLeft).X;
|
||||
float end = Parent.ToLocalSpace(restrictTo.ScreenSpaceDrawQuad.TopRight).X;
|
||||
float rawWidth = end - start;
|
||||
start -= rawWidth * leniency * 0.5f;
|
||||
end += rawWidth * leniency * 0.5f;
|
||||
float width = (end - start) * 0.5f * easing;
|
||||
// different values in case the playfield ever moves from center to somewhere else.
|
||||
box1.Width = start + width;
|
||||
box2.Width = DrawWidth - end + width;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Health between 0 and 1 for the blinds to base the width on. Will get animated for 200ms using out-quintic easing.
|
||||
/// </summary>
|
||||
public float Value
|
||||
{
|
||||
set
|
||||
{
|
||||
target = value;
|
||||
this.TransformTo(nameof(easing), target, 200, Easing.OutQuint);
|
||||
}
|
||||
get
|
||||
{
|
||||
return target;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -103,7 +103,7 @@ namespace osu.Game.Rulesets.Osu
|
||||
new MultiMod(new OsuModSuddenDeath(), new OsuModPerfect()),
|
||||
new MultiMod(new OsuModDoubleTime(), new OsuModNightcore()),
|
||||
new OsuModHidden(),
|
||||
new OsuModFlashlight(),
|
||||
new MultiMod(new OsuModFlashlight(), new OsuModBlinds()),
|
||||
};
|
||||
case ModType.Conversion:
|
||||
return new Mod[]
|
||||
|
24
osu.Game/Rulesets/Mods/ModBlinds.cs
Normal file
24
osu.Game/Rulesets/Mods/ModBlinds.cs
Normal file
@ -0,0 +1,24 @@
|
||||
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
||||
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Rulesets.Objects;
|
||||
using osu.Game.Rulesets.Scoring;
|
||||
using osu.Game.Rulesets.UI;
|
||||
|
||||
namespace osu.Game.Rulesets.Mods
|
||||
{
|
||||
public abstract class ModBlinds<T> : Mod, IApplicableToRulesetContainer<T>, IApplicableToScoreProcessor
|
||||
where T : HitObject
|
||||
{
|
||||
public override string Name => "Blinds";
|
||||
public override string ShortenedName => "BL";
|
||||
public override FontAwesome Icon => FontAwesome.fa_osu_mod_flashlight;
|
||||
public override ModType Type => ModType.DifficultyIncrease;
|
||||
public override string Description => "Play with blinds on your screen.";
|
||||
public override bool Ranked => false;
|
||||
|
||||
public abstract void ApplyToRulesetContainer(RulesetContainer<T> rulesetContainer);
|
||||
public abstract void ApplyToScoreProcessor(ScoreProcessor scoreProcessor);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user