Skip to content

Commit

Permalink
Merge pull request #19300 from nekodex/results-screen
Browse files Browse the repository at this point in the history
Add additional SFX to the results screen
  • Loading branch information
peppy authored Jul 22, 2022
2 parents 27ec8f3 + db632c0 commit 9130da3
Show file tree
Hide file tree
Showing 9 changed files with 157 additions and 22 deletions.
4 changes: 2 additions & 2 deletions osu.Android.props
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@
<Reference Include="Java.Interop" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.716.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2022.720.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.722.0" />
<PackageReference Include="ppy.osu.Framework.Android" Version="2022.722.0" />
</ItemGroup>
<ItemGroup Label="Transitive Dependencies">
<!-- Realm needs to be directly referenced in all Xamarin projects, as it will not pull in its transitive dependencies otherwise. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ private void load(BeatmapDifficultyCache beatmapDifficultyCache)
FillMode = FillMode.Fit,
}
},
scoreCounter = new TotalScoreCounter
scoreCounter = new TotalScoreCounter(!withFlair)
{
Margin = new MarginPadding { Top = 0, Bottom = 5 },
Current = { Value = 0 },
Expand Down
22 changes: 20 additions & 2 deletions osu.Game/Screens/Ranking/Expanded/ExpandedPanelTopContent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#nullable disable

using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
Expand All @@ -21,22 +23,30 @@ public class ExpandedPanelTopContent : CompositeDrawable
{
private readonly APIUser user;

private Sample appearanceSample;

private readonly bool playAppearanceSound;

/// <summary>
/// Creates a new <see cref="ExpandedPanelTopContent"/>.
/// </summary>
/// <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.playAppearanceSound = playAppearanceSound;
Anchor = Anchor.TopCentre;
Origin = Anchor.Centre;

AutoSizeAxes = Axes.Both;
}

[BackgroundDependencyLoader]
private void load()
private void load(AudioManager audio)
{
appearanceSample = audio.Samples.Get(@"Results/score-panel-top-appear");

InternalChild = new FillFlowContainer
{
AutoSizeAxes = Axes.Both,
Expand All @@ -62,5 +72,13 @@ private void load()
}
};
}

protected override void LoadComplete()
{
base.LoadComplete();

if (playAppearanceSound)
appearanceSample?.Play();
}
}
}
60 changes: 59 additions & 1 deletion osu.Game/Screens/Ranking/Expanded/TotalScoreCounter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@

#nullable disable

using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Localisation;
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
Expand All @@ -22,11 +26,35 @@ public class TotalScoreCounter : RollingCounter<long>

protected override Easing RollingEasing => AccuracyCircle.ACCURACY_TRANSFORM_EASING;

public TotalScoreCounter()
private readonly bool playSamples;

private readonly Bindable<double> tickPlaybackRate = new Bindable<double>();

private double lastSampleTime;

private DrawableSample sampleTick;

public TotalScoreCounter(bool playSamples = false)
{
// Todo: AutoSize X removed here due to https://github.com/ppy/osu-framework/issues/3369
AutoSizeAxes = Axes.Y;
RelativeSizeAxes = Axes.X;

this.playSamples = playSamples;
}

[BackgroundDependencyLoader]
private void load(AudioManager audio)
{
AddInternal(sampleTick = new DrawableSample(audio.Samples.Get(@"Results/score-tick-lesser")));
}

protected override void LoadComplete()
{
base.LoadComplete();

if (playSamples)
Current.BindValueChanged(_ => startTicking());
}

protected override LocalisableString FormatCount(long count) => count.ToString("N0");
Expand All @@ -39,5 +67,35 @@ protected override OsuSpriteText CreateSpriteText() => base.CreateSpriteText().W
s.Font = OsuFont.Torus.With(size: 60, weight: FontWeight.Light, fixedWidth: true);
s.Spacing = new Vector2(-5, 0);
});

public override long DisplayedCount
{
get => base.DisplayedCount;
set
{
if (base.DisplayedCount == value)
return;

base.DisplayedCount = value;

if (playSamples && Time.Current > lastSampleTime + tickPlaybackRate.Value)
{
sampleTick?.Play();
lastSampleTime = Time.Current;
}
}
}

private void startTicking()
{
const double tick_debounce_rate_start = 10f;
const double tick_debounce_rate_end = 100f;
const double tick_volume_start = 0.5f;
const double tick_volume_end = 1.0f;

this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_start);
this.TransformBindableTo(tickPlaybackRate, tick_debounce_rate_end, RollingDuration, Easing.OutSine);
sampleTick.VolumeTo(tick_volume_start).Then().VolumeTo(tick_volume_end, RollingDuration, Easing.OutSine);
}
}
}
10 changes: 9 additions & 1 deletion osu.Game/Screens/Ranking/ResultsScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
using System.Collections.Generic;
using System.Linq;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
Expand Down Expand Up @@ -60,6 +62,8 @@ public abstract class ResultsScreen : ScreenWithBeatmapBackground, IKeyBindingHa
private readonly bool allowRetry;
private readonly bool allowWatchingReplay;

private Sample popInSample;

protected ResultsScreen(ScoreInfo score, bool allowRetry, bool allowWatchingReplay = true)
{
Score = score;
Expand All @@ -70,10 +74,12 @@ protected ResultsScreen(ScoreInfo score, bool allowRetry, bool allowWatchingRepl
}

[BackgroundDependencyLoader]
private void load()
private void load(AudioManager audio)
{
FillFlowContainer buttons;

popInSample = audio.Samples.Get(@"UI/overlay-pop-in");

InternalChild = new GridContainer
{
RelativeSizeAxes = Axes.Both,
Expand Down Expand Up @@ -244,6 +250,8 @@ public override void OnEntering(ScreenTransitionEvent e)
});

bottomPanel.FadeTo(1, 250);

popInSample?.Play();
}

public override bool OnExiting(ScreenExitEvent e)
Expand Down
44 changes: 37 additions & 7 deletions osu.Game/Screens/Ranking/ScorePanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@
using System;
using osu.Framework;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Audio;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Input.Events;
using osu.Framework.Utils;
using osu.Game.Scoring;
using osu.Game.Screens.Ranking.Contracted;
using osu.Game.Screens.Ranking.Expanded;
Expand Down Expand Up @@ -93,9 +96,12 @@ public class ScorePanel : CompositeDrawable, IStateful<PanelState>

public readonly ScoreInfo Score;

private bool displayWithFlair;
[Resolved]
private OsuGameBase game { get; set; }

private DrawableAudioMixer mixer;

private Container content;
private bool displayWithFlair;

private Container topLayerContainer;
private Drawable topLayerBackground;
Expand All @@ -107,6 +113,8 @@ public class ScorePanel : CompositeDrawable, IStateful<PanelState>
private Container middleLayerContentContainer;
private Drawable middleLayerContent;

private DrawableSample samplePanelFocus;

public ScorePanel(ScoreInfo score, bool isNewLocalScore = false)
{
Score = score;
Expand All @@ -116,13 +124,13 @@ public ScorePanel(ScoreInfo score, bool isNewLocalScore = false)
}

[BackgroundDependencyLoader]
private void load()
private void load(AudioManager audio)
{
// 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.
const float vertical_fudge = 20;

InternalChild = content = new Container
InternalChild = mixer = new DrawableAudioMixer
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Expand Down Expand Up @@ -174,7 +182,8 @@ private void load()
},
middleLayerContentContainer = new Container { RelativeSizeAxes = Axes.Both }
}
}
},
samplePanelFocus = new DrawableSample(audio.Samples.Get(@"Results/score-panel-focus"))
}
};
}
Expand Down Expand Up @@ -202,12 +211,32 @@ public PanelState State
state = value;

if (IsLoaded)
{
updateState();

if (value == PanelState.Expanded)
playAppearSample();
}

StateChanged?.Invoke(value);
}
}

protected override void Update()
{
base.Update();
mixer.Balance.Value = (ScreenSpaceDrawQuad.Centre.X / game.ScreenSpaceDrawQuad.Width) * 2 - 1;
}

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()
{
topLayerContent?.FadeOut(content_fade_duration).Expire();
Expand All @@ -221,7 +250,8 @@ private void updateState()
topLayerBackground.FadeColour(expanded_top_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 });

// only the first expanded display should happen with flair.
Expand All @@ -244,7 +274,7 @@ private void updateState()
break;
}

content.ResizeTo(Size, RESIZE_DURATION, Easing.OutQuint);
mixer.ResizeTo(Size, RESIZE_DURATION, Easing.OutQuint);

bool topLayerExpanded = topLayerContainer.Y < 0;

Expand Down
27 changes: 24 additions & 3 deletions osu.Game/Screens/Ranking/Statistics/StatisticsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
using System.Threading;
using System.Threading.Tasks;
using osu.Framework.Allocation;
using osu.Framework.Audio;
using osu.Framework.Audio.Sample;
using osu.Framework.Bindables;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
Expand Down Expand Up @@ -35,6 +37,10 @@ public class StatisticsPanel : VisibilityContainer
private readonly Container content;
private readonly LoadingSpinner spinner;

private bool wasOpened;
private Sample popInSample;
private Sample popOutSample;

public StatisticsPanel()
{
InternalChild = new Container
Expand All @@ -56,9 +62,12 @@ public StatisticsPanel()
}

[BackgroundDependencyLoader]
private void load()
private void load(AudioManager audio)
{
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;
Expand Down Expand Up @@ -216,9 +225,21 @@ protected override bool OnClick(ClickEvent e)
return true;
}

protected override void PopIn() => this.FadeIn(150, Easing.OutQuint);
protected override void PopIn()
{
this.FadeIn(150, Easing.OutQuint);

popInSample?.Play();
wasOpened = true;
}

protected override void PopOut()
{
this.FadeOut(150, Easing.OutQuint);

protected override void PopOut() => this.FadeOut(150, Easing.OutQuint);
if (wasOpened)
popOutSample?.Play();
}

protected override void Dispose(bool isDisposing)
{
Expand Down
4 changes: 2 additions & 2 deletions osu.Game/osu.Game.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Realm" Version="10.14.0" />
<PackageReference Include="ppy.osu.Framework" Version="2022.720.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.716.0" />
<PackageReference Include="ppy.osu.Framework" Version="2022.722.0" />
<PackageReference Include="ppy.osu.Game.Resources" Version="2022.722.0" />
<PackageReference Include="Sentry" Version="3.19.0" />
<PackageReference Include="SharpCompress" Version="0.32.1" />
<PackageReference Include="NUnit" Version="3.13.3" />
Expand Down
Loading

0 comments on commit 9130da3

Please sign in to comment.