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-08-05 20:20:56 +08:00
|
|
|
|
|
2019-11-20 20:19:49 +08:00
|
|
|
|
using System;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2022-08-11 04:09:11 +08:00
|
|
|
|
using osu.Framework.Localisation;
|
2021-07-23 05:07:41 +08:00
|
|
|
|
using osu.Framework.Utils;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
using osu.Game.Beatmaps;
|
2018-08-05 20:20:56 +08:00
|
|
|
|
using osu.Game.Rulesets.Mods;
|
|
|
|
|
using osu.Game.Rulesets.Osu.Objects;
|
|
|
|
|
using osu.Game.Rulesets.Scoring;
|
|
|
|
|
using osu.Game.Rulesets.UI;
|
2019-04-25 18:56:57 +08:00
|
|
|
|
using osu.Game.Scoring;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
using osuTK.Graphics;
|
2018-08-05 20:20:56 +08:00
|
|
|
|
|
|
|
|
|
namespace osu.Game.Rulesets.Osu.Mods
|
|
|
|
|
{
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class OsuModBlinds : Mod, IApplicableToDrawableRuleset<OsuHitObject>, IApplicableToHealthProcessor
|
2018-08-05 20:20:56 +08:00
|
|
|
|
{
|
2018-12-07 19:12:56 +08:00
|
|
|
|
public override string Name => "Blinds";
|
2022-08-11 04:09:11 +08:00
|
|
|
|
public override LocalisableString Description => "Play with blinds on your screen.";
|
2018-12-07 19:12:56 +08:00
|
|
|
|
public override string Acronym => "BL";
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
2020-01-14 21:22:00 +08:00
|
|
|
|
public override IconUsage? Icon => FontAwesome.Solid.Adjust;
|
2018-12-07 19:12:56 +08:00
|
|
|
|
public override ModType Type => ModType.DifficultyIncrease;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
2022-07-18 12:22:25 +08:00
|
|
|
|
public override double ScoreMultiplier => UsesDefaultConfiguration ? 1.12 : 1;
|
2022-04-04 01:12:24 +08:00
|
|
|
|
public override Type[] IncompatibleMods => new[] { typeof(OsuModFlashlight) };
|
2024-02-06 20:03:05 +08:00
|
|
|
|
public override bool Ranked => true;
|
2022-04-04 01:12:24 +08:00
|
|
|
|
|
2022-07-31 21:43:16 +08:00
|
|
|
|
private DrawableOsuBlinds blinds = null!;
|
2018-08-05 20:20:56 +08:00
|
|
|
|
|
2019-03-20 10:22:34 +08:00
|
|
|
|
public void ApplyToDrawableRuleset(DrawableRuleset<OsuHitObject> drawableRuleset)
|
2018-08-05 20:20:56 +08:00
|
|
|
|
{
|
2021-07-23 05:07:41 +08:00
|
|
|
|
drawableRuleset.Overlays.Add(blinds = new DrawableOsuBlinds(drawableRuleset.Playfield, drawableRuleset.Beatmap));
|
2018-08-05 20:20:56 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-19 19:03:14 +08:00
|
|
|
|
public void ApplyToHealthProcessor(HealthProcessor healthProcessor)
|
2018-08-05 20:20:56 +08:00
|
|
|
|
{
|
2019-12-19 19:03:14 +08:00
|
|
|
|
healthProcessor.Health.ValueChanged += health => { blinds.AnimateClosedness((float)health.NewValue); };
|
2018-12-07 20:11:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-04-25 18:56:57 +08:00
|
|
|
|
public ScoreRank AdjustRank(ScoreRank rank, double accuracy) => rank;
|
|
|
|
|
|
2018-12-07 20:11:35 +08:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Element for the Blinds mod drawing 2 black boxes covering the whole screen which resize inside a restricted area with some leniency.
|
|
|
|
|
/// </summary>
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class DrawableOsuBlinds : Container
|
2018-12-07 20:11:35 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Black background boxes behind blind panel textures.
|
|
|
|
|
/// </summary>
|
2022-07-10 23:49:38 +08:00
|
|
|
|
private Box blackBoxLeft = null!, blackBoxRight = null!;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
2022-07-27 15:13:40 +08:00
|
|
|
|
private Drawable panelLeft = null!;
|
|
|
|
|
private Drawable panelRight = null!;
|
|
|
|
|
private Drawable bgPanelLeft = null!;
|
|
|
|
|
private Drawable bgPanelRight = null!;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
|
|
|
|
private readonly Beatmap<OsuHitObject> beatmap;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Value between 0 and 1 setting a maximum "closedness" for the blinds.
|
|
|
|
|
/// Useful for animating how far the blinds can be opened while keeping them at the original position if they are wider open than this.
|
|
|
|
|
/// </summary>
|
|
|
|
|
private const float target_clamp = 1;
|
|
|
|
|
|
2020-11-02 03:51:23 +08:00
|
|
|
|
private readonly float targetBreakMultiplier;
|
|
|
|
|
private readonly float easing;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
|
|
|
|
private readonly CompositeDrawable 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.1f;
|
|
|
|
|
|
2021-07-23 05:07:41 +08:00
|
|
|
|
public DrawableOsuBlinds(CompositeDrawable restrictTo, Beatmap<OsuHitObject> beatmap)
|
2018-12-07 20:11:35 +08:00
|
|
|
|
{
|
|
|
|
|
this.restrictTo = restrictTo;
|
|
|
|
|
this.beatmap = beatmap;
|
2020-11-02 03:51:23 +08:00
|
|
|
|
|
|
|
|
|
targetBreakMultiplier = 0;
|
|
|
|
|
easing = 1;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
blackBoxLeft = new Box
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopLeft,
|
|
|
|
|
Origin = Anchor.TopLeft,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
},
|
|
|
|
|
blackBoxRight = new Box
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.TopRight,
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
},
|
|
|
|
|
bgPanelLeft = new ModBlindsPanel
|
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.TopRight,
|
|
|
|
|
Colour = Color4.Gray,
|
|
|
|
|
},
|
2018-12-20 18:46:39 +08:00
|
|
|
|
panelLeft = new ModBlindsPanel { Origin = Anchor.TopRight, },
|
|
|
|
|
bgPanelRight = new ModBlindsPanel { Colour = Color4.Gray },
|
|
|
|
|
panelRight = new ModBlindsPanel()
|
2018-12-07 20:11:35 +08:00
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2019-11-20 20:19:49 +08:00
|
|
|
|
private float calculateGap(float value) => Math.Clamp(value, 0, target_clamp) * targetBreakMultiplier;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
2018-12-20 18:46:39 +08:00
|
|
|
|
// lagrange polinominal for (0,0) (0.6,0.4) (1,1) should make a good curve
|
|
|
|
|
private static float applyAdjustmentCurve(float value) => 0.6f * value * value + 0.4f * value;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
2021-07-22 05:07:00 +08:00
|
|
|
|
float start, end;
|
|
|
|
|
|
2021-07-23 05:07:41 +08:00
|
|
|
|
if (Precision.AlmostEquals(restrictTo.Rotation, 0))
|
|
|
|
|
{
|
2023-10-17 16:40:44 +08:00
|
|
|
|
start = Parent!.ToLocalSpace(restrictTo.ScreenSpaceDrawQuad.TopLeft).X;
|
|
|
|
|
end = Parent!.ToLocalSpace(restrictTo.ScreenSpaceDrawQuad.TopRight).X;
|
2021-07-23 05:07:41 +08:00
|
|
|
|
}
|
|
|
|
|
else
|
2021-07-22 05:07:00 +08:00
|
|
|
|
{
|
2023-10-17 16:40:44 +08:00
|
|
|
|
float center = restrictTo.ToSpaceOfOtherDrawable(restrictTo.OriginPosition, Parent!).X;
|
2021-07-23 05:04:01 +08:00
|
|
|
|
float halfDiagonal = (restrictTo.DrawSize / 2).LengthFast;
|
2021-07-22 05:07:00 +08:00
|
|
|
|
|
2021-07-23 05:01:31 +08:00
|
|
|
|
start = center - halfDiagonal;
|
|
|
|
|
end = center + halfDiagonal;
|
2021-07-22 05:07:00 +08:00
|
|
|
|
}
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
|
|
|
|
float rawWidth = end - start;
|
|
|
|
|
|
|
|
|
|
start -= rawWidth * leniency * 0.5f;
|
|
|
|
|
end += rawWidth * leniency * 0.5f;
|
|
|
|
|
|
2018-12-20 18:46:39 +08:00
|
|
|
|
float width = (end - start) * 0.5f * applyAdjustmentCurve(calculateGap(easing));
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
|
|
|
|
// different values in case the playfield ever moves from center to somewhere else.
|
|
|
|
|
blackBoxLeft.Width = start + width;
|
|
|
|
|
blackBoxRight.Width = DrawWidth - end + width;
|
|
|
|
|
|
|
|
|
|
panelLeft.X = start + width;
|
|
|
|
|
panelRight.X = end - width;
|
|
|
|
|
bgPanelLeft.X = start;
|
|
|
|
|
bgPanelRight.X = end;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
|
{
|
|
|
|
|
const float break_open_early = 500;
|
|
|
|
|
const float break_close_late = 250;
|
|
|
|
|
|
|
|
|
|
base.LoadComplete();
|
|
|
|
|
|
|
|
|
|
var firstObj = beatmap.HitObjects[0];
|
2021-10-27 12:04:41 +08:00
|
|
|
|
double startDelay = firstObj.StartTime - firstObj.TimePreempt;
|
2018-12-07 20:11:35 +08:00
|
|
|
|
|
2021-07-05 23:52:39 +08:00
|
|
|
|
using (BeginAbsoluteSequence(startDelay + break_close_late))
|
2018-12-07 20:11:35 +08:00
|
|
|
|
leaveBreak();
|
|
|
|
|
|
|
|
|
|
foreach (var breakInfo in beatmap.Breaks)
|
|
|
|
|
{
|
|
|
|
|
if (breakInfo.HasEffect)
|
|
|
|
|
{
|
2021-07-05 23:52:39 +08:00
|
|
|
|
using (BeginAbsoluteSequence(breakInfo.StartTime - break_open_early))
|
2018-12-07 20:11:35 +08:00
|
|
|
|
{
|
|
|
|
|
enterBreak();
|
2021-07-05 23:52:39 +08:00
|
|
|
|
using (BeginDelayedSequence(breakInfo.Duration + break_open_early + break_close_late))
|
2018-12-07 20:11:35 +08:00
|
|
|
|
leaveBreak();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void enterBreak() => this.TransformTo(nameof(targetBreakMultiplier), 0f, 1000, Easing.OutSine);
|
|
|
|
|
|
|
|
|
|
private void leaveBreak() => this.TransformTo(nameof(targetBreakMultiplier), 1f, 2500, Easing.OutBounce);
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// 0 is open, 1 is closed.
|
|
|
|
|
/// </summary>
|
|
|
|
|
public void AnimateClosedness(float value) => this.TransformTo(nameof(easing), value, 200, Easing.OutQuint);
|
|
|
|
|
|
2022-11-24 13:32:20 +08:00
|
|
|
|
public partial class ModBlindsPanel : Sprite
|
2018-12-07 20:11:35 +08:00
|
|
|
|
{
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
|
{
|
2019-08-30 14:10:11 +08:00
|
|
|
|
Texture = textures.Get("Gameplay/osu/blinds-panel");
|
2018-12-07 20:11:35 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-08-05 20:20:56 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|