1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-30 16:07:31 +08:00
osu-lazer/osu.Game.Rulesets.Mania/Mods/ManiaModFadeIn.cs

133 lines
4.7 KiB
C#
Raw Normal View History

// 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
using System;
2020-07-12 19:57:44 +08:00
using System.Linq;
using osu.Framework.Allocation;
2020-07-12 19:57:44 +08:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Graphics.Sprites;
2018-04-13 17:19:50 +08:00
using osu.Game.Graphics;
using osu.Game.Rulesets.Mania.Configuration;
using osu.Game.Rulesets.Mania.Objects;
2020-07-12 19:57:44 +08:00
using osu.Game.Rulesets.Mania.UI;
2018-04-13 17:19:50 +08:00
using osu.Game.Rulesets.Mods;
2020-07-12 19:57:44 +08:00
using osu.Game.Rulesets.UI;
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Rulesets.Mania.Mods
{
2020-07-12 19:57:44 +08:00
public class ManiaModFadeIn : Mod, IApplicableToDrawableRuleset<ManiaHitObject>
2018-04-13 17:19:50 +08:00
{
public override string Name => "Fade In";
public override string Acronym => "FI";
2020-01-14 21:22:00 +08:00
public override IconUsage? Icon => OsuIcon.ModHidden;
2018-04-13 17:19:50 +08:00
public override ModType Type => ModType.DifficultyIncrease;
public override string Description => @"Keys appear out of nowhere!";
public override double ScoreMultiplier => 1;
public override bool Ranked => true;
public override Type[] IncompatibleMods => new[] { typeof(ModFlashlight<ManiaHitObject>) };
2020-07-12 19:57:44 +08:00
public void ApplyToDrawableRuleset(DrawableRuleset<ManiaHitObject> drawableRuleset)
{
ManiaPlayfield maniaPlayfield = (ManiaPlayfield)drawableRuleset.Playfield;
foreach (Column column in maniaPlayfield.Stages.SelectMany(stage => stage.Columns))
{
HitObjectContainer hoc = column.HitObjectArea.HitObjectContainer;
Container hocParent = (Container)hoc.Parent;
hocParent.Remove(hoc);
hocParent.Add(new BufferedContainer
2020-07-12 19:57:44 +08:00
{
RelativeSizeAxes = Axes.Both,
Children = new Drawable[]
{
hoc,
new LaneCover(0.5f, false)
{
RelativeSizeAxes = Axes.Both
}
}
2020-07-12 19:57:44 +08:00
});
}
}
private class LaneCover : CompositeDrawable
{
private readonly Box gradient;
private readonly Box filled;
public LaneCover(float initialCoverage, bool reversed)
2020-07-12 19:57:44 +08:00
{
Blending = new BlendingParameters
{
RGBEquation = BlendingEquation.Add,
Source = BlendingType.Zero,
Destination = BlendingType.One,
AlphaEquation = BlendingEquation.Add,
SourceAlpha = BlendingType.Zero,
DestinationAlpha = BlendingType.OneMinusSrcAlpha
};
InternalChildren = new Drawable[]
{
gradient = new Box
{
RelativeSizeAxes = Axes.Both,
RelativePositionAxes = Axes.Both,
Height = 0.25f
2020-07-12 19:57:44 +08:00
},
filled = new Box
{
RelativeSizeAxes = Axes.Both
}
};
Coverage = initialCoverage;
Reversed = reversed;
2020-07-12 19:57:44 +08:00
}
private float coverage;
public float Coverage
2020-07-12 19:57:44 +08:00
{
set
{
filled.Height = value;
gradient.Y = reversed ? 1 - value - gradient.Height : value;
coverage = value;
2020-07-12 19:57:44 +08:00
}
}
private bool reversed;
public bool Reversed
2020-07-12 19:57:44 +08:00
{
set
{
filled.Anchor = value ? Anchor.BottomLeft : Anchor.TopLeft;
filled.Origin = value ? Anchor.BottomLeft : Anchor.TopLeft;
gradient.Colour = ColourInfo.GradientVertical(
Color4.White.Opacity(value ? 0f : 1f),
Color4.White.Opacity(value ? 1f : 0f)
);
reversed = value;
Coverage = coverage; //re-apply coverage to update visuals
2020-07-12 19:57:44 +08:00
}
}
[BackgroundDependencyLoader]
private void load(ManiaRulesetConfigManager configManager)
{
var scrollDirection = configManager.GetBindable<ManiaScrollingDirection>(ManiaRulesetSetting.ScrollDirection);
if (scrollDirection.Value == ManiaScrollingDirection.Up)
Reversed = !reversed;
}
2020-07-12 19:57:44 +08:00
}
2018-04-13 17:19:50 +08:00
}
}