From 2b5818a4d7e7cc4940703885e28633a080e859b9 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 16 May 2024 07:21:32 +0300 Subject: [PATCH] Fix DI crash in beatmap options popover --- .../SelectV2/Footer/BeatmapOptionsPopover.cs | 22 +++++++++---------- .../Footer/ScreenFooterButtonOptions.cs | 6 ++++- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/osu.Game/Screens/SelectV2/Footer/BeatmapOptionsPopover.cs b/osu.Game/Screens/SelectV2/Footer/BeatmapOptionsPopover.cs index f73be15a36..11a83f3438 100644 --- a/osu.Game/Screens/SelectV2/Footer/BeatmapOptionsPopover.cs +++ b/osu.Game/Screens/SelectV2/Footer/BeatmapOptionsPopover.cs @@ -20,7 +20,6 @@ using osu.Game.Graphics.UserInterface; using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Localisation; using osu.Game.Overlays; -using osu.Game.Screens.Select; using osuTK; using osuTK.Graphics; using osuTK.Input; @@ -33,18 +32,22 @@ namespace osu.Game.Screens.SelectV2.Footer private FillFlowContainer buttonFlow = null!; private readonly ScreenFooterButtonOptions footerButton; + [Cached] + private readonly OverlayColourProvider colourProvider; + private WorkingBeatmap beatmapWhenOpening = null!; [Resolved] private IBindable beatmap { get; set; } = null!; - public BeatmapOptionsPopover(ScreenFooterButtonOptions footerButton) + public BeatmapOptionsPopover(ScreenFooterButtonOptions footerButton, OverlayColourProvider colourProvider) { this.footerButton = footerButton; + this.colourProvider = colourProvider; } [BackgroundDependencyLoader] - private void load(ManageCollectionsDialog? manageCollectionsDialog, SongSelect? songSelect, OsuColour colours, BeatmapManager? beatmapManager) + private void load(ManageCollectionsDialog? manageCollectionsDialog, OsuColour colours, BeatmapManager? beatmapManager) { Content.Padding = new MarginPadding(5); @@ -61,15 +64,15 @@ namespace osu.Game.Screens.SelectV2.Footer addButton(SongSelectStrings.ManageCollections, FontAwesome.Solid.Book, () => manageCollectionsDialog?.Show()); addHeader(SongSelectStrings.ForAllDifficulties, beatmapWhenOpening.BeatmapSetInfo.ToString()); - addButton(SongSelectStrings.DeleteBeatmap, FontAwesome.Solid.Trash, () => songSelect?.DeleteBeatmap(beatmapWhenOpening.BeatmapSetInfo), colours.Red1); + addButton(SongSelectStrings.DeleteBeatmap, FontAwesome.Solid.Trash, () => { }, colours.Red1); // songSelect?.DeleteBeatmap(beatmapWhenOpening.BeatmapSetInfo); addHeader(SongSelectStrings.ForSelectedDifficulty, beatmapWhenOpening.BeatmapInfo.DifficultyName); // TODO: make work, and make show "unplayed" or "played" based on status. addButton(SongSelectStrings.MarkAsPlayed, FontAwesome.Regular.TimesCircle, null); - addButton(SongSelectStrings.ClearAllLocalScores, FontAwesome.Solid.Eraser, () => songSelect?.ClearScores(beatmapWhenOpening.BeatmapInfo), colours.Red1); + addButton(SongSelectStrings.ClearAllLocalScores, FontAwesome.Solid.Eraser, () => { }, colours.Red1); // songSelect?.ClearScores(beatmapWhenOpening.BeatmapInfo); - if (songSelect != null && songSelect.AllowEditing) - addButton(SongSelectStrings.EditBeatmap, FontAwesome.Solid.PencilAlt, () => songSelect.Edit(beatmapWhenOpening.BeatmapInfo)); + // if (songSelect != null && songSelect.AllowEditing) + addButton(SongSelectStrings.EditBeatmap, FontAwesome.Solid.PencilAlt, () => { }); // songSelect.Edit(beatmapWhenOpening.BeatmapInfo); addButton(WebCommonStrings.ButtonsHide.ToSentence(), FontAwesome.Solid.Magic, () => beatmapManager?.Hide(beatmapWhenOpening.BeatmapInfo)); } @@ -83,9 +86,6 @@ namespace osu.Game.Screens.SelectV2.Footer beatmap.BindValueChanged(_ => Hide()); } - [Resolved] - private OverlayColourProvider overlayColourProvider { get; set; } = null!; - private void addHeader(LocalisableString text, string? context = null) { var textFlow = new OsuTextFlowContainer @@ -102,7 +102,7 @@ namespace osu.Game.Screens.SelectV2.Footer textFlow.NewLine(); textFlow.AddText(context, t => { - t.Colour = overlayColourProvider.Content2; + t.Colour = colourProvider.Content2; t.Font = t.Font.With(size: 13); }); } diff --git a/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonOptions.cs b/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonOptions.cs index 74fe3e3d11..72409b5566 100644 --- a/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonOptions.cs +++ b/osu.Game/Screens/SelectV2/Footer/ScreenFooterButtonOptions.cs @@ -8,12 +8,16 @@ using osu.Framework.Graphics.Sprites; using osu.Framework.Graphics.UserInterface; using osu.Game.Graphics; using osu.Game.Input.Bindings; +using osu.Game.Overlays; using osu.Game.Screens.Footer; namespace osu.Game.Screens.SelectV2.Footer { public partial class ScreenFooterButtonOptions : ScreenFooterButton, IHasPopover { + [Resolved] + private OverlayColourProvider colourProvider { get; set; } = null!; + [BackgroundDependencyLoader] private void load(OsuColour colour) { @@ -25,6 +29,6 @@ namespace osu.Game.Screens.SelectV2.Footer Action = this.ShowPopover; } - public Popover GetPopover() => new BeatmapOptionsPopover(this); + public Popover GetPopover() => new BeatmapOptionsPopover(this, colourProvider); } }