From 4e83f12f34c8287a08dcec547ae5251285d55372 Mon Sep 17 00:00:00 2001 From: ColdVolcano Date: Sat, 20 May 2017 11:02:42 -0500 Subject: [PATCH] Initial implementation Note this won't work with the osu!bgm because it is not a beatmap --- osu.Game/Screens/Menu/MainMenu.cs | 3 +- osu.Game/Screens/Menu/MenuSideFlashes.cs | 95 ++++++++++++++++++++++++ osu.Game/osu.Game.csproj | 1 + 3 files changed, 98 insertions(+), 1 deletion(-) create mode 100644 osu.Game/Screens/Menu/MenuSideFlashes.cs diff --git a/osu.Game/Screens/Menu/MainMenu.cs b/osu.Game/Screens/Menu/MainMenu.cs index 71d020b0f2..269c20fff9 100644 --- a/osu.Game/Screens/Menu/MainMenu.cs +++ b/osu.Game/Screens/Menu/MainMenu.cs @@ -54,7 +54,8 @@ namespace osu.Game.Screens.Menu OnSolo = delegate { Push(consumeSongSelect()); }, OnMulti = delegate { Push(new Lobby()); }, OnExit = delegate { Exit(); }, - } + }, + new MenuSideFlashes(), } } }; diff --git a/osu.Game/Screens/Menu/MenuSideFlashes.cs b/osu.Game/Screens/Menu/MenuSideFlashes.cs new file mode 100644 index 0000000000..fa308dc2a6 --- /dev/null +++ b/osu.Game/Screens/Menu/MenuSideFlashes.cs @@ -0,0 +1,95 @@ +using OpenTK.Graphics; +using osu.Framework.Allocation; +using osu.Framework.Configuration; +using osu.Framework.Graphics; +using osu.Framework.Graphics.Colour; +using osu.Game.Graphics.Containers; +using osu.Framework.Graphics.Sprites; +using osu.Game.Beatmaps; +using osu.Game.Beatmaps.Timing; +using System; + +namespace osu.Game.Screens.Menu +{ + public class MenuSideFlashes : BeatSyncedContainer + { + public override bool HandleInput => false; + + private Bindable beatmap = new Bindable(); + + private Box leftBox; + private Box rightBox; + + private const int amplitude_dead_zone = 9000; + private const float alpha_multiplier = (short.MaxValue - amplitude_dead_zone) / 0.55f; + private const int box_max_alpha = 200; + private const double box_fade_in_time = 65; + + public MenuSideFlashes() + { + RelativeSizeAxes = Axes.Both; + Anchor = Anchor.Centre; + Origin = Anchor.Centre; + BlendingMode = BlendingMode.Additive; + Children = new Drawable[] + { + leftBox = new Box + { + Anchor = Anchor.CentreLeft, + Origin = Anchor.CentreLeft, + RelativeSizeAxes = Axes.Y, + Width = 300, + Alpha = 0, + BlendingMode = BlendingMode.Additive, + ColourInfo = ColourInfo.GradientHorizontal(new Color4(255, 255, 255, box_max_alpha), Color4.Transparent), + }, + rightBox = new Box + { + Anchor = Anchor.CentreRight, + Origin = Anchor.CentreRight, + RelativeSizeAxes = Axes.Y, + Width = 300, + Alpha = 0, + BlendingMode = BlendingMode.Additive, + ColourInfo = ColourInfo.GradientHorizontal(Color4.Transparent, new Color4(255, 255, 255, box_max_alpha)), + } + }; + } + + protected override void OnNewBeat(int newBeat, double beatLength, TimeSignatures timeSignature, bool kiai) + { + if (!beatmap?.Value?.Track?.IsRunning ?? false) + { + leftBox.FadeOut(50); + rightBox.FadeOut(50); + } + else if (newBeat >= 0) + { + short[] lev = beatmap.Value.Track.ChannelPeakAmplitudes; + bool nextIsLeft = newBeat % 2 == 0; + if (kiai ? nextIsLeft : newBeat % (int)timeSignature == 0) + { + leftBox.ClearTransforms(); + leftBox.FadeTo(Math.Max(0, (lev[0] - amplitude_dead_zone) / alpha_multiplier), 65); + using (leftBox.BeginDelayedSequence(box_fade_in_time)) + leftBox.FadeOut(beatLength, EasingTypes.In); + leftBox.DelayReset(); + } + if (kiai ? !nextIsLeft : newBeat % (int)timeSignature == 0) + { + rightBox.ClearTransforms(); + rightBox.FadeTo(Math.Max(0, (lev[1] - amplitude_dead_zone) / alpha_multiplier), 65); + using (rightBox.BeginDelayedSequence(box_fade_in_time)) + rightBox.FadeOut(beatLength, EasingTypes.In); + rightBox.DelayReset(); + } + } + } + + [BackgroundDependencyLoader] + private void load(OsuGameBase game) + { + beatmap = game.Beatmap; + } + } +} \ No newline at end of file diff --git a/osu.Game/osu.Game.csproj b/osu.Game/osu.Game.csproj index 18c483fe40..8fd7b398a2 100644 --- a/osu.Game/osu.Game.csproj +++ b/osu.Game/osu.Game.csproj @@ -183,6 +183,7 @@ +