Add panel appearance sounds

This commit is contained in:
Jamie Taylor
2022-07-22 19:06:31 +09:00
parent 27ec8f3ae6
commit 6ce8e74e6b
4 changed files with 77 additions and 9 deletions

View File

@ -4,6 +4,8 @@
#nullable disable #nullable disable
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Game.Graphics; using osu.Game.Graphics;
@ -21,13 +23,19 @@ namespace osu.Game.Screens.Ranking.Expanded
{ {
private readonly APIUser user; private readonly APIUser user;
private Sample appearanceSample;
private readonly bool playAppearanceSound;
/// <summary> /// <summary>
/// Creates a new <see cref="ExpandedPanelTopContent"/>. /// Creates a new <see cref="ExpandedPanelTopContent"/>.
/// </summary> /// </summary>
/// <param name="user">The <see cref="APIUser"/> to display.</param> /// <param name="user">The <see cref="APIUser"/> to display.</param>
public ExpandedPanelTopContent(APIUser user) /// <param name="playAppearanceSound">Whether the appearance sample should play</param>
public ExpandedPanelTopContent(APIUser user, bool playAppearanceSound = false)
{ {
this.user = user; this.user = user;
this.playAppearanceSound = playAppearanceSound;
Anchor = Anchor.TopCentre; Anchor = Anchor.TopCentre;
Origin = Anchor.Centre; Origin = Anchor.Centre;
@ -35,8 +43,10 @@ namespace osu.Game.Screens.Ranking.Expanded
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(AudioManager audio)
{ {
appearanceSample = audio.Samples.Get(@"Results/score-panel-top-appear");
InternalChild = new FillFlowContainer InternalChild = new FillFlowContainer
{ {
AutoSizeAxes = Axes.Both, AutoSizeAxes = Axes.Both,
@ -62,5 +72,13 @@ namespace osu.Game.Screens.Ranking.Expanded
} }
}; };
} }
protected override void LoadComplete()
{
base.LoadComplete();
if (playAppearanceSound)
appearanceSample?.Play();
}
} }
} }

View File

@ -7,6 +7,8 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
@ -60,6 +62,8 @@ namespace osu.Game.Screens.Ranking
private readonly bool allowRetry; private readonly bool allowRetry;
private readonly bool allowWatchingReplay; private readonly bool allowWatchingReplay;
private Sample popInSample;
protected ResultsScreen(ScoreInfo score, bool allowRetry, bool allowWatchingReplay = true) protected ResultsScreen(ScoreInfo score, bool allowRetry, bool allowWatchingReplay = true)
{ {
Score = score; Score = score;
@ -70,10 +74,12 @@ namespace osu.Game.Screens.Ranking
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(AudioManager audio)
{ {
FillFlowContainer buttons; FillFlowContainer buttons;
popInSample = audio.Samples.Get(@"UI/overlay-pop-in");
InternalChild = new GridContainer InternalChild = new GridContainer
{ {
RelativeSizeAxes = Axes.Both, RelativeSizeAxes = Axes.Both,
@ -244,6 +250,8 @@ namespace osu.Game.Screens.Ranking
}); });
bottomPanel.FadeTo(1, 250); bottomPanel.FadeTo(1, 250);
popInSample?.Play();
} }
public override bool OnExiting(ScreenExitEvent e) public override bool OnExiting(ScreenExitEvent e)

View File

@ -6,13 +6,16 @@
using System; using System;
using osu.Framework; using osu.Framework;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions; using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Colour; using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Scoring; using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Contracted; using osu.Game.Screens.Ranking.Contracted;
using osu.Game.Screens.Ranking.Expanded; using osu.Game.Screens.Ranking.Expanded;
@ -107,6 +110,8 @@ namespace osu.Game.Screens.Ranking
private Container middleLayerContentContainer; private Container middleLayerContentContainer;
private Drawable middleLayerContent; private Drawable middleLayerContent;
private DrawableSample samplePanelFocus;
public ScorePanel(ScoreInfo score, bool isNewLocalScore = false) public ScorePanel(ScoreInfo score, bool isNewLocalScore = false)
{ {
Score = score; Score = score;
@ -116,7 +121,7 @@ namespace osu.Game.Screens.Ranking
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(AudioManager audio)
{ {
// ScorePanel doesn't include the top extruding area in its own size. // ScorePanel doesn't include the top extruding area in its own size.
// Adding a manual offset here allows the expanded version to take on an "acceptable" vertical centre when at 100% UI scale. // Adding a manual offset here allows the expanded version to take on an "acceptable" vertical centre when at 100% UI scale.
@ -174,7 +179,8 @@ namespace osu.Game.Screens.Ranking
}, },
middleLayerContentContainer = new Container { RelativeSizeAxes = Axes.Both } middleLayerContentContainer = new Container { RelativeSizeAxes = Axes.Both }
} }
} },
samplePanelFocus = new DrawableSample(audio.Samples.Get(@"Results/score-panel-focus"))
} }
}; };
} }
@ -202,12 +208,26 @@ namespace osu.Game.Screens.Ranking
state = value; state = value;
if (IsLoaded) if (IsLoaded)
{
updateState(); updateState();
if (value == PanelState.Expanded)
playAppearSample();
}
StateChanged?.Invoke(value); StateChanged?.Invoke(value);
} }
} }
private void playAppearSample()
{
var channel = samplePanelFocus?.GetChannel();
if (channel == null) return;
channel.Frequency.Value = 0.99 + RNG.NextDouble(0.2);
channel.Play();
}
private void updateState() private void updateState()
{ {
topLayerContent?.FadeOut(content_fade_duration).Expire(); topLayerContent?.FadeOut(content_fade_duration).Expire();
@ -221,7 +241,8 @@ namespace osu.Game.Screens.Ranking
topLayerBackground.FadeColour(expanded_top_layer_colour, RESIZE_DURATION, Easing.OutQuint); topLayerBackground.FadeColour(expanded_top_layer_colour, RESIZE_DURATION, Easing.OutQuint);
middleLayerBackground.FadeColour(expanded_middle_layer_colour, RESIZE_DURATION, Easing.OutQuint); middleLayerBackground.FadeColour(expanded_middle_layer_colour, RESIZE_DURATION, Easing.OutQuint);
topLayerContentContainer.Add(topLayerContent = new ExpandedPanelTopContent(Score.User) { Alpha = 0 }); bool firstLoad = topLayerContent == null;
topLayerContentContainer.Add(topLayerContent = new ExpandedPanelTopContent(Score.User, firstLoad) { Alpha = 0 });
middleLayerContentContainer.Add(middleLayerContent = new ExpandedPanelMiddleContent(Score, displayWithFlair) { Alpha = 0 }); middleLayerContentContainer.Add(middleLayerContent = new ExpandedPanelMiddleContent(Score, displayWithFlair) { Alpha = 0 });
// only the first expanded display should happen with flair. // only the first expanded display should happen with flair.

View File

@ -8,6 +8,8 @@ using System.Linq;
using System.Threading; using System.Threading;
using System.Threading.Tasks; using System.Threading.Tasks;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables; using osu.Framework.Bindables;
using osu.Framework.Graphics; using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
@ -35,6 +37,10 @@ namespace osu.Game.Screens.Ranking.Statistics
private readonly Container content; private readonly Container content;
private readonly LoadingSpinner spinner; private readonly LoadingSpinner spinner;
private bool wasOpened;
private Sample popInSample;
private Sample popOutSample;
public StatisticsPanel() public StatisticsPanel()
{ {
InternalChild = new Container InternalChild = new Container
@ -56,9 +62,12 @@ namespace osu.Game.Screens.Ranking.Statistics
} }
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load() private void load(AudioManager audio)
{ {
Score.BindValueChanged(populateStatistics, true); Score.BindValueChanged(populateStatistics, true);
popInSample = audio.Samples.Get(@"Results/statistics-panel-pop-in");
popOutSample = audio.Samples.Get(@"Results/statistics-panel-pop-out");
} }
private CancellationTokenSource loadCancellation; private CancellationTokenSource loadCancellation;
@ -216,9 +225,21 @@ namespace osu.Game.Screens.Ranking.Statistics
return true; return true;
} }
protected override void PopIn() => this.FadeIn(150, Easing.OutQuint); protected override void PopIn()
{
this.FadeIn(150, Easing.OutQuint);
protected override void PopOut() => this.FadeOut(150, Easing.OutQuint); popInSample?.Play();
wasOpened = true;
}
protected override void PopOut()
{
this.FadeOut(150, Easing.OutQuint);
if (wasOpened)
popOutSample?.Play();
}
protected override void Dispose(bool isDisposing) protected override void Dispose(bool isDisposing)
{ {