1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-18 06:43:22 +08:00
osu-lazer/osu.Game/Screens/Menu/MenuSideFlashes.cs

102 lines
3.9 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
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
2018-04-13 17:19:50 +08:00
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics;
using osu.Game.Graphics.Containers;
using System;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Menu
{
public class MenuSideFlashes : BeatSyncedContainer
{
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
2018-04-13 17:19:50 +08:00
private Box leftBox;
private Box rightBox;
2018-04-13 17:19:50 +08:00
private const float amplitude_dead_zone = 0.25f;
private const float alpha_multiplier = (1 - amplitude_dead_zone) / 0.55f;
private const float kiai_multiplier = (1 - amplitude_dead_zone * 0.95f) / 0.8f;
private const int box_max_alpha = 200;
private const double box_fade_in_time = 65;
private const int box_width = 200;
public MenuSideFlashes()
{
EarlyActivationMilliseconds = box_fade_in_time;
RelativeSizeAxes = Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader]
2019-02-01 14:42:15 +08:00
private void load(IBindable<WorkingBeatmap> beatmap, OsuColour colours)
{
this.beatmap.BindTo(beatmap);
// linear colour looks better in this case, so let's use it for now.
Color4 gradientDark = colours.Blue.Opacity(0).ToLinear();
Color4 gradientLight = colours.Blue.Opacity(0.6f).ToLinear();
2018-04-13 17:19:50 +08:00
Children = new Drawable[]
{
leftBox = new Box
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Y,
Width = box_width * 2,
2019-01-04 12:29:37 +08:00
Height = 1.5f,
// align off-screen to make sure our edges don't become visible during parallax.
X = -box_width,
2018-04-13 17:19:50 +08:00
Alpha = 0,
Blending = BlendingMode.Additive,
Colour = ColourInfo.GradientHorizontal(gradientLight, gradientDark)
2018-04-13 17:19:50 +08:00
},
rightBox = new Box
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Y,
Width = box_width * 2,
2019-01-04 12:29:37 +08:00
Height = 1.5f,
X = box_width,
2018-04-13 17:19:50 +08:00
Alpha = 0,
Blending = BlendingMode.Additive,
Colour = ColourInfo.GradientHorizontal(gradientDark, gradientLight)
2018-04-13 17:19:50 +08:00
}
};
}
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
{
if (beatIndex < 0)
return;
if (effectPoint.KiaiMode ? beatIndex % 2 == 0 : beatIndex % (int)timingPoint.TimeSignature == 0)
flash(leftBox, timingPoint.BeatLength, effectPoint.KiaiMode, amplitudes);
if (effectPoint.KiaiMode ? beatIndex % 2 == 1 : beatIndex % (int)timingPoint.TimeSignature == 0)
flash(rightBox, timingPoint.BeatLength, effectPoint.KiaiMode, amplitudes);
}
private void flash(Drawable d, double beatLength, bool kiai, TrackAmplitudes amplitudes)
{
d.FadeTo(Math.Max(0, ((d.Equals(leftBox) ? amplitudes.LeftChannel : amplitudes.RightChannel) - amplitude_dead_zone) / (kiai ? kiai_multiplier : alpha_multiplier)), box_fade_in_time)
.Then()
.FadeOut(beatLength, Easing.In);
}
}
}