Skip to content

Commit 99f57d2

Browse files
authored
Merge pull request #33503 from bdach/rank-change-sample-toggling
Prevent rank display shown in skin editor toolbox from playing samples
2 parents 3335b99 + e02cd28 commit 99f57d2

File tree

3 files changed

+44
-5
lines changed

3 files changed

+44
-5
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// Copyright (c) ppy Pty Ltd <[email protected]>. Licensed under the MIT Licence.
2+
// See the LICENCE file in the repository root for full licence text.
3+
4+
using osu.Framework.Localisation;
5+
6+
namespace osu.Game.Localisation
7+
{
8+
public static class DefaultRankDisplayStrings
9+
{
10+
private const string prefix = @"osu.Game.Resources.Localisation.DefaultRankDisplay";
11+
12+
/// <summary>
13+
/// "Play samples on rank change"
14+
/// </summary>
15+
public static LocalisableString PlaySamplesOnRankChange => new TranslatableString(getKey(@"play_samples_on_rank_change"), @"Play samples on rank change");
16+
17+
private static string getKey(string key) => $@"{prefix}:{key}";
18+
}
19+
}

osu.Game/Overlays/SkinEditor/SkinComponentToolbox.cs

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ protected override bool OnClick(ClickEvent e)
219219
}
220220
}
221221

222-
public partial class DependencyBorrowingContainer : Container
222+
private partial class DependencyBorrowingContainer : Container
223223
{
224224
protected override bool ShouldBeConsideredForInput(Drawable child) => false;
225225

@@ -232,8 +232,19 @@ public DependencyBorrowingContainer(CompositeDrawable? donor)
232232
this.donor = donor;
233233
}
234234

235-
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent) =>
236-
new DependencyContainer(donor?.Dependencies ?? base.CreateChildDependencies(parent));
235+
protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
236+
{
237+
var baseDependencies = base.CreateChildDependencies(parent);
238+
if (donor == null)
239+
return baseDependencies;
240+
241+
var dependencies = new DependencyContainer(donor.Dependencies);
242+
// inject `SkinEditor` again *on top* of the borrowed dependencies.
243+
// this is designed to let components know when they are being displayed in the context of the skin editor
244+
// via attempting to resolve `SkinEditor`.
245+
dependencies.CacheAs(baseDependencies.Get<SkinEditor>());
246+
return dependencies;
247+
}
237248
}
238249
}
239250
}

osu.Game/Screens/Play/HUD/DefaultRankDisplay.cs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@
66
using osu.Framework.Graphics;
77
using osu.Framework.Graphics.Containers;
88
using osu.Game.Audio;
9+
using osu.Game.Configuration;
910
using osu.Game.Online.Leaderboards;
11+
using osu.Game.Overlays.SkinEditor;
1012
using osu.Game.Rulesets.Scoring;
1113
using osu.Game.Scoring;
1214
using osu.Game.Skinning;
1315
using osuTK;
16+
using osu.Game.Localisation;
1417

1518
namespace osu.Game.Screens.Play.HUD
1619
{
@@ -19,6 +22,9 @@ public partial class DefaultRankDisplay : CompositeDrawable, ISerialisableDrawab
1922
[Resolved]
2023
private ScoreProcessor scoreProcessor { get; set; } = null!;
2124

25+
[SettingSource(typeof(DefaultRankDisplayStrings), nameof(DefaultRankDisplayStrings.PlaySamplesOnRankChange))]
26+
public BindableBool PlaySamples { get; set; } = new BindableBool(true);
27+
2228
public bool UsesFixedAnchor { get; set; }
2329

2430
private UpdateableRank rankDisplay = null!;
@@ -34,7 +40,7 @@ public DefaultRankDisplay()
3440
}
3541

3642
[BackgroundDependencyLoader]
37-
private void load()
43+
private void load(SkinEditor? skinEditor)
3844
{
3945
InternalChildren = new Drawable[]
4046
{
@@ -45,6 +51,9 @@ private void load()
4551
RelativeSizeAxes = Axes.Both
4652
},
4753
};
54+
55+
if (skinEditor != null)
56+
PlaySamples.Value = false;
4857
}
4958

5059
protected override void LoadComplete()
@@ -55,7 +64,7 @@ protected override void LoadComplete()
5564
rank.BindValueChanged(r =>
5665
{
5766
// Don't play rank-down sfx on quit/retry
58-
if (r.NewValue != r.OldValue && r.NewValue > ScoreRank.F)
67+
if (r.NewValue != r.OldValue && r.NewValue > ScoreRank.F && PlaySamples.Value)
5968
{
6069
if (r.NewValue > rankDisplay.Rank)
6170
rankUpSample.Play();

0 commit comments

Comments
 (0)