1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 13:22:55 +08:00
osu-lazer/osu.Game/Screens/Menu/MenuSideFlashes.cs

99 lines
3.8 KiB
C#
Raw Normal View History

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