From 0dd52e4e2930509788aa71a1eaaa47b2082a03d1 Mon Sep 17 00:00:00 2001 From: Dean Herbert Date: Tue, 23 May 2017 17:26:28 +0900 Subject: [PATCH] Various refactoring --- osu.Game/Screens/Menu/MenuSideFlashes.cs | 44 +++++++++++------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/osu.Game/Screens/Menu/MenuSideFlashes.cs b/osu.Game/Screens/Menu/MenuSideFlashes.cs index 61d3ef10a8..ced6d179d6 100644 --- a/osu.Game/Screens/Menu/MenuSideFlashes.cs +++ b/osu.Game/Screens/Menu/MenuSideFlashes.cs @@ -1,4 +1,4 @@ -// Copyright (c) 2007-2017 ppy Pty Ltd . +// Copyright (c) 2007-2017 ppy Pty Ltd . // Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE using OpenTK.Graphics; @@ -12,6 +12,7 @@ using osu.Framework.Graphics.Sprites; using osu.Game.Beatmaps; using osu.Game.Beatmaps.Timing; using System; +using osu.Game.Graphics; using TrackAmplitudes = osu.Framework.Audio.Track.Track.TrackAmplitudes; namespace osu.Game.Screens.Menu @@ -22,25 +23,22 @@ namespace osu.Game.Screens.Menu private readonly Bindable beatmap = new Bindable(); - private static readonly ColourInfo gradient_white_to_transparent_black = ColourInfo.GradientHorizontal(new Color4(255, 255, 255, box_max_alpha), Color4.Black.Opacity(0)); - private static readonly ColourInfo gradient_transparent_black_to_white = ColourInfo.GradientHorizontal(Color4.Black.Opacity(0), new Color4(255, 255, 255, box_max_alpha)); - private readonly Box leftBox; private readonly Box rightBox; private const float amplitude_dead_zone = 0.25f; private const float alpha_multiplier = (1 - amplitude_dead_zone) / 0.55f; private const float kiai_multiplier = (1 - amplitude_dead_zone * 0.95f) / 0.8f; + private const int box_max_alpha = 200; private const double box_fade_in_time = 65; - private const int box_width = 300; + private const int box_width = 200; public MenuSideFlashes() { RelativeSizeAxes = Axes.Both; Anchor = Anchor.Centre; Origin = Anchor.Centre; - BlendingMode = BlendingMode.Additive; Children = new Drawable[] { leftBox = new Box @@ -51,7 +49,6 @@ namespace osu.Game.Screens.Menu Width = box_width, Alpha = 0, BlendingMode = BlendingMode.Additive, - ColourInfo = gradient_white_to_transparent_black, }, rightBox = new Box { @@ -61,40 +58,41 @@ namespace osu.Game.Screens.Menu Width = box_width, Alpha = 0, BlendingMode = BlendingMode.Additive, - ColourInfo = gradient_transparent_black_to_white, } }; } - private bool kiai; - private double beatLength; + [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(); + + leftBox.ColourInfo = ColourInfo.GradientHorizontal(gradientLight, gradientDark); + rightBox.ColourInfo = ColourInfo.GradientHorizontal(gradientDark, gradientLight); + } protected override void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) { if (newBeat < 0) return; - this.kiai = kiai; - this.beatLength = beatLength; - if (kiai ? newBeat % 2 == 0 : newBeat % (int)timeSignature == 0) - flash(leftBox); + flash(leftBox, beatLength, kiai); if (kiai ? newBeat % 2 == 1 : newBeat % (int)timeSignature == 0) - flash(rightBox); + flash(rightBox, beatLength, kiai); } - private void flash(Drawable d) + private void flash(Drawable d, double beatLength, bool kiai) { TrackAmplitudes amp = beatmap.Value.Track.CurrentAmplitudes; + d.FadeTo(Math.Max(0, ((d.Equals(leftBox) ? amp.LeftChannel : amp.RightChannel) - amplitude_dead_zone) / (kiai ? kiai_multiplier : alpha_multiplier)), box_fade_in_time); using (d.BeginDelayedSequence(box_fade_in_time)) d.FadeOut(beatLength, EasingTypes.In); } - - [BackgroundDependencyLoader] - private void load(OsuGameBase game) - { - beatmap.BindTo(game.Beatmap); - } } -} \ No newline at end of file +}