2019-01-24 08:43:03 +00:00
|
|
|
// 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 09:19:50 +00:00
|
|
|
|
2018-11-20 07:51:59 +00:00
|
|
|
using osuTK.Graphics;
|
2017-05-20 16:02:42 +00:00
|
|
|
using osu.Framework.Allocation;
|
2017-05-22 09:38:21 +00:00
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2017-05-20 16:02:42 +00:00
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Colour;
|
2017-06-20 05:54:23 +00:00
|
|
|
using osu.Framework.Graphics.Shapes;
|
2017-05-20 16:02:42 +00:00
|
|
|
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;
|
2019-03-31 12:10:44 +00:00
|
|
|
using osu.Game.Skinning;
|
|
|
|
using osu.Game.Online.API;
|
2017-05-24 01:01:20 +00:00
|
|
|
using System;
|
2020-06-23 04:49:18 +00:00
|
|
|
using osu.Framework.Audio.Track;
|
2019-02-21 10:04:31 +00:00
|
|
|
using osu.Framework.Bindables;
|
2021-11-04 09:02:44 +00:00
|
|
|
using osu.Game.Online.API.Requests.Responses;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-05-20 16:02:42 +00:00
|
|
|
namespace osu.Game.Screens.Menu
|
|
|
|
{
|
|
|
|
public class MenuSideFlashes : BeatSyncedContainer
|
|
|
|
{
|
2018-05-23 08:37:39 +00:00
|
|
|
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2018-06-02 18:26:59 +00:00
|
|
|
private Box leftBox;
|
|
|
|
private Box rightBox;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
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;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-05-20 16:02:42 +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;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2021-11-04 09:02:44 +00:00
|
|
|
private IBindable<APIUser> user;
|
2019-03-31 12:10:44 +00:00
|
|
|
private Bindable<Skin> skin;
|
|
|
|
|
|
|
|
[Resolved]
|
|
|
|
private OsuColour colours { get; set; }
|
|
|
|
|
2017-05-20 16:02:42 +00:00
|
|
|
public MenuSideFlashes()
|
|
|
|
{
|
2017-05-24 12:07:12 +00:00
|
|
|
EarlyActivationMilliseconds = box_fade_in_time;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2017-05-20 16:02:42 +00:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
2018-06-02 18:26:59 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
2019-03-31 12:10:44 +00:00
|
|
|
private void load(IBindable<WorkingBeatmap> beatmap, IAPIProvider api, SkinManager skinManager)
|
2018-06-02 18:26:59 +00:00
|
|
|
{
|
2018-06-06 09:26:51 +00:00
|
|
|
this.beatmap.BindTo(beatmap);
|
2018-06-02 18:26:59 +00:00
|
|
|
|
2019-03-31 12:10:44 +00:00
|
|
|
user = api.LocalUser.GetBoundCopy();
|
|
|
|
skin = skinManager.CurrentSkin.GetBoundCopy();
|
|
|
|
|
2017-05-20 16:02:42 +00:00
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
leftBox = new Box
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2018-06-02 18:26:59 +00:00
|
|
|
Width = box_width * 2,
|
2019-01-04 04:29:37 +00:00
|
|
|
Height = 1.5f,
|
2018-06-02 18:26:59 +00:00
|
|
|
// align off-screen to make sure our edges don't become visible during parallax.
|
|
|
|
X = -box_width,
|
2017-05-20 16:02:42 +00:00
|
|
|
Alpha = 0,
|
2019-08-21 04:29:50 +00:00
|
|
|
Blending = BlendingParameters.Additive
|
2017-05-20 16:02:42 +00:00
|
|
|
},
|
|
|
|
rightBox = new Box
|
|
|
|
{
|
|
|
|
Anchor = Anchor.CentreRight,
|
|
|
|
Origin = Anchor.CentreRight,
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2018-06-02 18:26:59 +00:00
|
|
|
Width = box_width * 2,
|
2019-01-04 04:29:37 +00:00
|
|
|
Height = 1.5f,
|
2018-06-02 18:26:59 +00:00
|
|
|
X = box_width,
|
2017-05-20 16:02:42 +00:00
|
|
|
Alpha = 0,
|
2019-08-21 04:29:50 +00:00
|
|
|
Blending = BlendingParameters.Additive
|
2017-05-20 16:02:42 +00:00
|
|
|
}
|
|
|
|
};
|
2019-03-31 12:10:44 +00:00
|
|
|
|
2019-04-01 04:13:56 +00:00
|
|
|
user.ValueChanged += _ => updateColour();
|
|
|
|
skin.BindValueChanged(_ => updateColour(), true);
|
2017-05-23 08:26:28 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-06-23 04:49:18 +00:00
|
|
|
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
|
2017-05-20 16:02:42 +00:00
|
|
|
{
|
2017-05-24 01:01:20 +00:00
|
|
|
if (beatIndex < 0)
|
2017-05-22 09:38:21 +00:00
|
|
|
return;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2022-01-22 16:27:27 +00:00
|
|
|
if (effectPoint.KiaiMode ? beatIndex % 2 == 0 : beatIndex % timingPoint.TimeSignature.Numerator == 0)
|
2017-05-24 01:01:20 +00:00
|
|
|
flash(leftBox, timingPoint.BeatLength, effectPoint.KiaiMode, amplitudes);
|
2022-01-22 16:27:27 +00:00
|
|
|
if (effectPoint.KiaiMode ? beatIndex % 2 == 1 : beatIndex % timingPoint.TimeSignature.Numerator == 0)
|
2017-05-24 01:01:20 +00:00
|
|
|
flash(rightBox, timingPoint.BeatLength, effectPoint.KiaiMode, amplitudes);
|
2017-05-22 10:59:16 +00:00
|
|
|
}
|
2018-04-13 09:19:50 +00:00
|
|
|
|
2020-06-23 04:49:18 +00:00
|
|
|
private void flash(Drawable d, double beatLength, bool kiai, ChannelAmplitudes amplitudes)
|
2017-05-22 10:59:16 +00:00
|
|
|
{
|
2019-11-13 14:35:50 +00: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 15:28:20 +00:00
|
|
|
.Then()
|
2017-07-22 18:50:25 +00:00
|
|
|
.FadeOut(beatLength, Easing.In);
|
2017-05-20 16:02:42 +00:00
|
|
|
}
|
2019-03-31 12:10:44 +00:00
|
|
|
|
2019-04-01 04:13:56 +00:00
|
|
|
private void updateColour()
|
2019-03-31 12:10:44 +00:00
|
|
|
{
|
2019-04-01 04:13:56 +00:00
|
|
|
Color4 baseColour = colours.Blue;
|
2019-03-31 12:10:44 +00:00
|
|
|
|
|
|
|
if (user.Value?.IsSupporter ?? false)
|
2020-02-07 05:58:07 +00:00
|
|
|
baseColour = skin.Value.GetConfig<GlobalSkinColours, Color4>(GlobalSkinColours.MenuGlow)?.Value ?? baseColour;
|
2019-03-31 12:10:44 +00:00
|
|
|
|
|
|
|
// 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-20 16:02:42 +00:00
|
|
|
}
|
2017-05-23 08:26:28 +00:00
|
|
|
}
|