mirror of
https://github.com/ppy/osu.git
synced 2025-01-13 13:32:54 +08:00
Various refactoring
This commit is contained in:
parent
9235cbff8d
commit
0dd52e4e29
@ -1,4 +1,4 @@
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
||||
// 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<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user