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;
|
2017-05-21 00:02:42 +08:00
|
|
|
using osu.Framework.Allocation;
|
2017-05-24 09:01:20 +08:00
|
|
|
using osu.Framework.Audio.Track;
|
2017-05-21 00:02:42 +08:00
|
|
|
using osu.Framework.Configuration;
|
2017-05-22 17:38:21 +08:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-05-21 00:02:42 +08:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2017-06-20 13:54:23 +08:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-05-21 00:02:42 +08:00
|
|
|
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;
|
2017-05-21 00:02:42 +08:00
|
|
|
|
|
|
|
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-21 00:02:42 +08:00
|
|
|
|
2017-05-22 17:53:32 +08:00
|
|
|
private readonly Box leftBox;
|
|
|
|
private readonly Box rightBox;
|
2017-05-21 00:02:42 +08:00
|
|
|
|
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
|
|
|
|
2017-05-21 00:02:42 +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;
|
2017-05-21 00:02:42 +08:00
|
|
|
|
|
|
|
public MenuSideFlashes()
|
|
|
|
{
|
2017-05-24 20:07:12 +08:00
|
|
|
EarlyActivationMilliseconds = box_fade_in_time;
|
|
|
|
|
2017-05-21 00:02:42 +08:00
|
|
|
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,
|
2017-05-21 00:02:42 +08:00
|
|
|
Alpha = 0,
|
2017-09-07 21:46:21 +08:00
|
|
|
Blending = BlendingMode.Additive,
|
2017-05-21 00:02:42 +08:00
|
|
|
},
|
|
|
|
rightBox = new Box
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2017-05-22 18:59:16 +08:00
|
|
|
Width = box_width,
|
2017-05-21 00:02:42 +08:00
|
|
|
Alpha = 0,
|
2017-09-07 21:46:21 +08:00
|
|
|
Blending = BlendingMode.Additive,
|
2017-05-21 00:02:42 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
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-21 00:02:42 +08:00
|
|
|
{
|
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
|
|
|
{
|
2017-07-16 22:37:59 +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-21 00:02:42 +08:00
|
|
|
}
|
|
|
|
}
|
2017-05-23 16:26:28 +08:00
|
|
|
}
|