Skip to content

Commit f023d3b

Browse files
authored
Merge pull request #34290 from chris-ehmann/fix-editor-bg
Fix editor background not updating in certain scenarios
2 parents 77f1681 + aeb1941 commit f023d3b

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

osu.Game/Screens/Backgrounds/EditorBackgroundScreen.cs

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ namespace osu.Game.Screens.Backgrounds
1919
{
2020
public partial class EditorBackgroundScreen : BackgroundScreen
2121
{
22-
private readonly WorkingBeatmap beatmap;
2322
private readonly Container dimContainer;
2423

2524
private CancellationTokenSource? cancellationTokenSource;
@@ -31,10 +30,14 @@ public partial class EditorBackgroundScreen : BackgroundScreen
3130

3231
private IFrameBasedClock? clockSource;
3332

34-
public EditorBackgroundScreen(WorkingBeatmap beatmap)
35-
{
36-
this.beatmap = beatmap;
33+
// We retrieve IBindable<WorkingBeatmap> from our dependency cache instead of passing WorkingBeatmap directly into EditorBackgroundScreen.
34+
// Otherwise, DummyWorkingBeatmap will be erroneously passed in whenever creating a new beatmap (since the Schedule() in the Editor that populates
35+
// a new WorkingBeatmap with correct values generally runs after EditorBackgroundScreen is created), which causes any background changes to not be displayed.
36+
[Resolved]
37+
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
3738

39+
public EditorBackgroundScreen()
40+
{
3841
InternalChild = dimContainer = new Container
3942
{
4043
RelativeSizeAxes = Axes.Both,
@@ -54,14 +57,14 @@ private void load(OsuConfigManager config)
5457

5558
private IEnumerable<Drawable> createContent() =>
5659
[
57-
new BeatmapBackground(beatmap) { RelativeSizeAxes = Axes.Both, },
60+
new BeatmapBackground(beatmap.Value) { RelativeSizeAxes = Axes.Both, },
5861
// this kooky container nesting is here because the storyboard needs a custom clock
5962
// but also needs it on an isolated-enough level that doesn't break screen stack expiry logic (which happens if the clock was put on `this`),
6063
// or doesn't make it literally impossible to fade the storyboard in/out in real time (which happens if the fade transforms were to be applied directly to the storyboard).
6164
new Container
6265
{
6366
RelativeSizeAxes = Axes.Both,
64-
Child = new DrawableStoryboard(beatmap.Storyboard)
67+
Child = new DrawableStoryboard(beatmap.Value.Storyboard)
6568
{
6669
Clock = clockSource ?? Clock,
6770
}
@@ -82,7 +85,7 @@ private void updateState(double duration = 500)
8285
storyboardContainer.FadeTo(showStoryboard.Value ? 1 : 0, duration, Easing.OutQuint);
8386
// yes, this causes overdraw, but is also a (crude) fix for bad-looking transitions on screen entry
8487
// caused by the previous background on the background stack poking out from under this one and then instantly fading out
85-
background.FadeColour(beatmap.Storyboard.ReplacesBackground && showStoryboard.Value ? Colour4.Black : Colour4.White, duration, Easing.OutQuint);
88+
background.FadeColour(beatmap.Value.Storyboard.ReplacesBackground && showStoryboard.Value ? Colour4.Black : Colour4.White, duration, Easing.OutQuint);
8689
}
8790

8891
public void ChangeClockSource(IFrameBasedClock frameBasedClock)
@@ -103,7 +106,7 @@ public void RefreshBackground()
103106
background = dimContainer.OfType<BeatmapBackground>().Single();
104107
storyboardContainer = dimContainer.OfType<Container>().Single();
105108
updateState(0);
106-
}, (cancellationTokenSource ??= new CancellationTokenSource()).Token);
109+
}, (cancellationTokenSource = new CancellationTokenSource()).Token);
107110
}
108111

109112
public override bool Equals(BackgroundScreen? other)

osu.Game/Screens/Edit/Editor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ private void load(OsuConfigManager config)
480480
[Resolved]
481481
private MusicController musicController { get; set; }
482482

483-
protected override BackgroundScreen CreateBackground() => new EditorBackgroundScreen(Beatmap.Value);
483+
protected override BackgroundScreen CreateBackground() => new EditorBackgroundScreen();
484484

485485
protected override void LoadComplete()
486486
{

0 commit comments

Comments
 (0)