osu/osu.Game/Screens/Menu/MenuSideFlashes.cs

100 lines
3.9 KiB
C#
Raw Normal View History

2018-01-05 11:21:19 +00:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
2017-05-20 16:44:19 +00:00
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using OpenTK.Graphics;
using osu.Framework.Allocation;
2017-05-24 01:01:20 +00:00
using osu.Framework.Audio.Track;
using osu.Framework.Configuration;
2017-05-22 09:38:21 +00:00
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Shapes;
using osu.Game.Beatmaps;
2017-05-24 01:01:20 +00:00
using osu.Game.Beatmaps.ControlPoints;
2017-05-23 08:26:28 +00:00
using osu.Game.Graphics;
2017-05-24 01:01:20 +00:00
using osu.Game.Graphics.Containers;
using System;
namespace osu.Game.Screens.Menu
{
public class MenuSideFlashes : BeatSyncedContainer
{
public override bool HandleKeyboardInput => false;
public override bool HandleMouseInput => false;
2017-05-22 09:38:21 +00:00
private readonly Bindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
2017-05-22 09:53:32 +00:00
private readonly Box leftBox;
private readonly Box rightBox;
2017-05-22 04:47:08 +00:00
private const float amplitude_dead_zone = 0.25f;
private const float alpha_multiplier = (1 - amplitude_dead_zone) / 0.55f;
2017-05-22 09:53:32 +00:00
private const float kiai_multiplier = (1 - amplitude_dead_zone * 0.95f) / 0.8f;
2017-05-23 08:26:28 +00:00
private const int box_max_alpha = 200;
private const double box_fade_in_time = 65;
2017-05-23 08:26:28 +00:00
private const int box_width = 200;
public MenuSideFlashes()
{
EarlyActivationMilliseconds = box_fade_in_time;
RelativeSizeAxes = Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
Children = new Drawable[]
{
leftBox = new Box
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Y,
2017-05-22 10:59:16 +00:00
Width = box_width,
Alpha = 0,
2017-09-07 13:46:21 +00:00
Blending = BlendingMode.Additive,
},
rightBox = new Box
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Y,
2017-05-22 10:59:16 +00:00
Width = box_width,
Alpha = 0,
2017-09-07 13:46:21 +00:00
Blending = BlendingMode.Additive,
}
};
}
2017-05-23 08:26:28 +00:00
[BackgroundDependencyLoader]
private void load(OsuGameBase game, OsuColour colours)
{
beatmap.BindTo(game.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.3f).ToLinear();
2017-07-23 05:30:50 +00:00
leftBox.Colour = ColourInfo.GradientHorizontal(gradientLight, gradientDark);
rightBox.Colour = ColourInfo.GradientHorizontal(gradientDark, gradientLight);
2017-05-23 08:26:28 +00:00
}
2017-05-22 10:59:16 +00:00
2017-05-24 01:01:20 +00:00
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, TrackAmplitudes amplitudes)
{
2017-05-24 01:01:20 +00:00
if (beatIndex < 0)
2017-05-22 09:38:21 +00:00
return;
2017-05-22 09:55:33 +00:00
2017-05-24 01:01:20 +00:00
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);
2017-05-22 10:59:16 +00:00
}
2017-05-24 01:01:20 +00:00
private void flash(Drawable d, double beatLength, bool kiai, TrackAmplitudes amplitudes)
2017-05-22 10:59:16 +00:00
{
d.FadeTo(Math.Max(0, ((d.Equals(leftBox) ? amplitudes.LeftChannel : amplitudes.RightChannel) - amplitude_dead_zone) / (kiai ? kiai_multiplier : alpha_multiplier)), box_fade_in_time)
2017-07-16 15:28:20 +00:00
.Then()
2017-07-22 18:50:25 +00:00
.FadeOut(beatLength, Easing.In);
}
}
2017-05-23 08:26:28 +00:00
}