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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

128 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
2022-06-17 15:37:17 +08:00
#nullable disable
2018-11-20 15:51:59 +08:00
using osuTK.Graphics;
using osu.Framework.Allocation;
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 osu.Game.Skinning;
using osu.Game.Online.API;
2017-05-24 09:01:20 +08:00
using System;
2020-06-23 12:49:18 +08:00
using osu.Framework.Audio.Track;
2019-02-21 18:04:31 +08:00
using osu.Framework.Bindables;
using osu.Game.Online.API.Requests.Responses;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Screens.Menu
{
public partial 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
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;
2018-04-13 17:19:50 +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;
2018-04-13 17:19:50 +08:00
private IBindable<APIUser> user;
private Bindable<Skin> skin;
[Resolved]
private OsuColour colours { get; set; }
public MenuSideFlashes()
{
EarlyActivationMilliseconds = box_fade_in_time;
2018-04-13 17:19:50 +08:00
RelativeSizeAxes = Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}
[BackgroundDependencyLoader]
private void load(IBindable<WorkingBeatmap> beatmap, IAPIProvider api, SkinManager skinManager)
{
this.beatmap.BindTo(beatmap);
user = api.LocalUser.GetBoundCopy();
skin = skinManager.CurrentSkin.GetBoundCopy();
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,
Alpha = 0,
2019-08-21 12:29:50 +08:00
Blending = BlendingParameters.Additive
},
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,
Alpha = 0,
2019-08-21 12:29:50 +08:00
Blending = BlendingParameters.Additive
}
};
user.ValueChanged += _ => updateColour();
skin.BindValueChanged(_ => updateColour(), true);
2017-05-23 16:26:28 +08:00
}
2018-04-13 17:19:50 +08:00
2020-06-23 12:49:18 +08:00
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
{
2017-05-24 09:01:20 +08:00
if (beatIndex < 0)
2017-05-22 17:38:21 +08:00
return;
2018-04-13 17:19:50 +08:00
if (effectPoint.KiaiMode ? beatIndex % 2 == 0 : beatIndex % timingPoint.TimeSignature.Numerator == 0)
2017-05-24 09:01:20 +08:00
flash(leftBox, timingPoint.BeatLength, effectPoint.KiaiMode, amplitudes);
if (effectPoint.KiaiMode ? beatIndex % 2 == 1 : beatIndex % timingPoint.TimeSignature.Numerator == 0)
2017-05-24 09:01:20 +08:00
flash(rightBox, timingPoint.BeatLength, effectPoint.KiaiMode, amplitudes);
2017-05-22 18:59:16 +08:00
}
2018-04-13 17:19:50 +08:00
2020-06-23 12:49:18 +08:00
private void flash(Drawable d, double beatLength, bool kiai, ChannelAmplitudes amplitudes)
2017-05-22 18:59:16 +08:00
{
2019-11-13 22:35:50 +08:00
d.FadeTo(Math.Max(0, ((ReferenceEquals(d, 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);
}
private void updateColour()
{
Color4 baseColour = colours.Blue;
if (user.Value?.IsSupporter ?? false)
baseColour = skin.Value.GetConfig<GlobalSkinColours, Color4>(GlobalSkinColours.MenuGlow)?.Value ?? baseColour;
// linear colour looks better in this case, so let's use it for now.
Color4 gradientDark = baseColour.Opacity(0).ToLinear();
Color4 gradientLight = baseColour.Opacity(0.6f).ToLinear();
leftBox.Colour = ColourInfo.GradientHorizontal(gradientLight, gradientDark);
rightBox.Colour = ColourInfo.GradientHorizontal(gradientDark, gradientLight);
}
}
2017-05-23 16:26:28 +08:00
}