1
0
mirror of https://github.com/ppy/osu.git synced 2025-02-21 22:12:53 +08:00

Subclass menu flashes instead of adding local code to it

This commit is contained in:
Dean Herbert 2024-12-20 14:58:45 +09:00
parent 2a720ef200
commit ad4a8a1e0a
No known key found for this signature in database
3 changed files with 39 additions and 12 deletions

View File

@ -161,7 +161,7 @@ namespace osu.Game.Screens.Menu
} }
}, },
logoTarget = new Container { RelativeSizeAxes = Axes.Both, }, logoTarget = new Container { RelativeSizeAxes = Axes.Both, },
sideFlashes = new MenuSideFlashes(), sideFlashes = SeasonalUIConfig.ENABLED ? new SeasonalMenuSideFlashes() : new MenuSideFlashes(),
songTicker = new SongTicker songTicker = new SongTicker
{ {
Anchor = Anchor.TopRight, Anchor = Anchor.TopRight,

View File

@ -11,14 +11,12 @@ using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Utils;
using osu.Game.Beatmaps; using osu.Game.Beatmaps;
using osu.Game.Beatmaps.ControlPoints; using osu.Game.Beatmaps.ControlPoints;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Graphics.Containers; using osu.Game.Graphics.Containers;
using osu.Game.Online.API; using osu.Game.Online.API;
using osu.Game.Online.API.Requests.Responses; using osu.Game.Online.API.Requests.Responses;
using osu.Game.Seasonal;
using osu.Game.Skinning; using osu.Game.Skinning;
using osuTK.Graphics; using osuTK.Graphics;
@ -26,6 +24,10 @@ namespace osu.Game.Screens.Menu
{ {
public partial class MenuSideFlashes : BeatSyncedContainer public partial class MenuSideFlashes : BeatSyncedContainer
{ {
protected virtual bool RefreshColoursEveryFlash => false;
protected virtual float Intensity => 2;
private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>(); private readonly IBindable<WorkingBeatmap> beatmap = new Bindable<WorkingBeatmap>();
private Box leftBox; private Box leftBox;
@ -69,7 +71,7 @@ namespace osu.Game.Screens.Menu
Anchor = Anchor.CentreLeft, Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft, Origin = Anchor.CentreLeft,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = box_width * (SeasonalUIConfig.ENABLED ? 4 : 2), Width = box_width * Intensity,
Height = 1.5f, Height = 1.5f,
// align off-screen to make sure our edges don't become visible during parallax. // align off-screen to make sure our edges don't become visible during parallax.
X = -box_width, X = -box_width,
@ -81,7 +83,7 @@ namespace osu.Game.Screens.Menu
Anchor = Anchor.CentreRight, Anchor = Anchor.CentreRight,
Origin = Anchor.CentreRight, Origin = Anchor.CentreRight,
RelativeSizeAxes = Axes.Y, RelativeSizeAxes = Axes.Y,
Width = box_width * (SeasonalUIConfig.ENABLED ? 4 : 2), Width = box_width * Intensity,
Height = 1.5f, Height = 1.5f,
X = box_width, X = box_width,
Alpha = 0, Alpha = 0,
@ -89,8 +91,11 @@ namespace osu.Game.Screens.Menu
} }
}; };
user.ValueChanged += _ => updateColour(); if (!RefreshColoursEveryFlash)
skin.BindValueChanged(_ => updateColour(), true); {
user.ValueChanged += _ => updateColour();
skin.BindValueChanged(_ => updateColour(), true);
}
} }
protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes) protected override void OnNewBeat(int beatIndex, TimingControlPoint timingPoint, EffectControlPoint effectPoint, ChannelAmplitudes amplitudes)
@ -106,7 +111,7 @@ namespace osu.Game.Screens.Menu
private void flash(Drawable d, double beatLength, bool kiai, ChannelAmplitudes amplitudes) private void flash(Drawable d, double beatLength, bool kiai, ChannelAmplitudes amplitudes)
{ {
if (SeasonalUIConfig.ENABLED) if (RefreshColoursEveryFlash)
updateColour(); updateColour();
d.FadeTo(Math.Clamp(0.1f + ((ReferenceEquals(d, leftBox) ? amplitudes.LeftChannel : amplitudes.RightChannel) - amplitude_dead_zone) / (kiai ? kiai_multiplier : alpha_multiplier), 0.1f, 1), d.FadeTo(Math.Clamp(0.1f + ((ReferenceEquals(d, leftBox) ? amplitudes.LeftChannel : amplitudes.RightChannel) - amplitude_dead_zone) / (kiai ? kiai_multiplier : alpha_multiplier), 0.1f, 1),
@ -115,15 +120,19 @@ namespace osu.Game.Screens.Menu
.FadeOut(beatLength, Easing.In); .FadeOut(beatLength, Easing.In);
} }
private void updateColour() protected virtual Color4 GetBaseColour()
{ {
Color4 baseColour = colours.Blue; Color4 baseColour = colours.Blue;
if (SeasonalUIConfig.ENABLED) if (user.Value?.IsSupporter ?? false)
baseColour = RNG.NextBool() ? SeasonalUIConfig.PRIMARY_COLOUR_1 : SeasonalUIConfig.PRIMARY_COLOUR_2;
else if (user.Value?.IsSupporter ?? false)
baseColour = skin.Value.GetConfig<GlobalSkinColours, Color4>(GlobalSkinColours.MenuGlow)?.Value ?? baseColour; baseColour = skin.Value.GetConfig<GlobalSkinColours, Color4>(GlobalSkinColours.MenuGlow)?.Value ?? baseColour;
return baseColour;
}
private void updateColour()
{
var baseColour = GetBaseColour();
// linear colour looks better in this case, so let's use it for now. // linear colour looks better in this case, so let's use it for now.
Color4 gradientDark = baseColour.Opacity(0).ToLinear(); Color4 gradientDark = baseColour.Opacity(0).ToLinear();
Color4 gradientLight = baseColour.Opacity(0.6f).ToLinear(); Color4 gradientLight = baseColour.Opacity(0.6f).ToLinear();

View File

@ -0,0 +1,18 @@
// 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.
using osu.Framework.Utils;
using osu.Game.Screens.Menu;
using osuTK.Graphics;
namespace osu.Game.Seasonal
{
public partial class SeasonalMenuSideFlashes : MenuSideFlashes
{
protected override bool RefreshColoursEveryFlash => true;
protected override float Intensity => 4;
protected override Color4 GetBaseColour() => RNG.NextBool() ? SeasonalUIConfig.PRIMARY_COLOUR_1 : SeasonalUIConfig.PRIMARY_COLOUR_2;
}
}