Skip to content

Commit

Permalink
Menu flashes!
Browse files Browse the repository at this point in the history
  • Loading branch information
mempler committed Oct 20, 2021
1 parent d026f5d commit 3e04390
Show file tree
Hide file tree
Showing 3 changed files with 118 additions and 13 deletions.
1 change: 0 additions & 1 deletion Qsor.Desktop/Qsor.Desktop.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@

<ItemGroup>
<PackageReference Include="ppy.squirrel.windows" Version="1.9.0.5" />
<PackageReference Include="SharpCompress" Version="0.30.0" />
<PackageReference Include="System.Drawing.Common" Version="5.0.2" />
<PackageReference Include="System.IO.Packaging" Version="5.0.0" />
</ItemGroup>
Expand Down
25 changes: 13 additions & 12 deletions Qsor.Game/Screens/MainMenuScreen.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
Expand Down Expand Up @@ -43,6 +43,8 @@ public class MainMenuScreen : Screen
[Resolved]
private GameHost Host { get; set; }

private MenuSideFlashes SideFlashes { get; set; }

[BackgroundDependencyLoader]
private void Load(UpdaterOverlay updaterOverlay, AudioManager audioManager, QsorDbContextFactory ctxFactory, BeatmapManager beatmapManager)
{
Expand Down Expand Up @@ -94,10 +96,9 @@ private void Load(UpdaterOverlay updaterOverlay, AudioManager audioManager, Qsor

AddInternal(parallaxFront);


AddInternal(SideFlashes = new MenuSideFlashes());

AddInternal(_toolbar = new Toolbar());

AddInternal(_bottomBar = new BottomBar());

AddInternal(updaterOverlay);
Expand Down Expand Up @@ -141,7 +142,7 @@ public override bool OnExiting(IScreen next)
this.FadeOutFromOne(2500, Easing.OutExpo);
return true;
}

// Fade clock
private StopwatchClock _clock = new();
public bool IsFading;
Expand All @@ -160,14 +161,14 @@ protected override bool OnMouseMove(MouseMoveEvent e)
{
if (_clock.ElapsedMilliseconds >= 5000)
{
_toolbar.ClearTransforms();
_bottomBar.ClearTransforms();
_toolbar.FadeIn(250);
_bottomBar.FadeIn(250);

IsFading = false;
_clock.Restart();
_toolbar.ClearTransforms();
_bottomBar.ClearTransforms();

_toolbar.FadeIn(250);
_bottomBar.FadeIn(250);
IsFading = false;
_clock.Restart();
}

return true;
Expand Down
105 changes: 105 additions & 0 deletions Qsor.Game/Screens/Menu/MenuSideFlashes.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
// See the LICENCE file in the repository root for full licence text.

using System;
using osu.Framework.Allocation;
using osu.Framework.Audio.Track;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Shapes;
using osuTK.Graphics;
using Qsor.Game.Beatmaps;
using Qsor.Game.Graphics.Containers;

namespace Qsor.Game.Screens.Menu
{
public class MenuSideFlashes : BeatSyncedContainer
{
private readonly IBindable<WorkingBeatmap> _beatmap = new Bindable<WorkingBeatmap>();

private Box _leftBox;
private Box _rightBox;

private const float AmplitudeDeadZone = 0.25f;
private const float AlphaMultiplier = 1.0f;
private const float KiaiMultiplier = 1.0f;

private const int BoxMaxAlpha = 200;
private const double BoxFadeInTime = 65;
private const int BoxWidth = 200;

public MenuSideFlashes()
{
EarlyActivationMilliseconds = BoxFadeInTime;

RelativeSizeAxes = Axes.Both;
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
}

[BackgroundDependencyLoader]
private void Load(BeatmapManager beatmapManager)
{
_beatmap.BindTo(beatmapManager.WorkingBeatmap);

Children = new Drawable[]
{
_leftBox = new Box
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Y,
Width = BoxWidth * 2,
Height = 1.5f,
// align off-screen to make sure our edges don't become visible during parallax.
X = -BoxWidth,
Alpha = 0,
Blending = BlendingParameters.Additive
},
_rightBox = new Box
{
Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Y,
Width = BoxWidth * 2,
Height = 1.5f,
X = BoxWidth,
Alpha = 0,
Blending = BlendingParameters.Additive
}
};

var baseColour = Color4.White;
var gradientDark = baseColour.Opacity(0).ToLinear();
var gradientLight = baseColour.Opacity(0.6f).ToLinear();

_leftBox.Colour = ColourInfo.GradientHorizontal(gradientLight, gradientDark);
_rightBox.Colour = ColourInfo.GradientHorizontal(gradientDark, gradientLight);
}

protected override void OnNewBeat(int beatIndex, TimingPoint timingPoint, ChannelAmplitudes amplitudes)
{
Console.WriteLine(beatIndex);
Console.WriteLine(timingPoint.Meter);

Console.WriteLine(timingPoint.KiaiMode);

if (beatIndex < 0)
return;

if (timingPoint.KiaiMode ? beatIndex % 2 == 0 : beatIndex % timingPoint.Meter == 0)
Flash(_leftBox, timingPoint.MsPerBeat, timingPoint.KiaiMode, amplitudes);
if (timingPoint.KiaiMode ? beatIndex % 2 == 1 : beatIndex % timingPoint.Meter == 0)
Flash(_rightBox, timingPoint.MsPerBeat, timingPoint.KiaiMode, amplitudes);
}

private void Flash(Drawable d, double beatLength, bool kiai, ChannelAmplitudes amplitudes)
{
d.FadeTo(kiai ? KiaiMultiplier : AlphaMultiplier, BoxFadeInTime)
.Then()
.FadeOut(beatLength, Easing.In);
}
}
}

0 comments on commit 3e04390

Please sign in to comment.