1
0
mirror of https://github.com/ppy/osu.git synced 2025-01-06 09:03:01 +08:00

Fix DI crash in beatmap options popover

This commit is contained in:
Salman Ahmed 2024-05-16 07:21:32 +03:00
parent 03220598b8
commit 2b5818a4d7
2 changed files with 16 additions and 12 deletions

View File

@ -20,7 +20,6 @@ using osu.Game.Graphics.UserInterface;
using osu.Game.Graphics.UserInterfaceV2; using osu.Game.Graphics.UserInterfaceV2;
using osu.Game.Localisation; using osu.Game.Localisation;
using osu.Game.Overlays; using osu.Game.Overlays;
using osu.Game.Screens.Select;
using osuTK; using osuTK;
using osuTK.Graphics; using osuTK.Graphics;
using osuTK.Input; using osuTK.Input;
@ -33,18 +32,22 @@ namespace osu.Game.Screens.SelectV2.Footer
private FillFlowContainer buttonFlow = null!; private FillFlowContainer buttonFlow = null!;
private readonly ScreenFooterButtonOptions footerButton; private readonly ScreenFooterButtonOptions footerButton;
[Cached]
private readonly OverlayColourProvider colourProvider;
private WorkingBeatmap beatmapWhenOpening = null!; private WorkingBeatmap beatmapWhenOpening = null!;
[Resolved] [Resolved]
private IBindable<WorkingBeatmap> beatmap { get; set; } = null!; private IBindable<WorkingBeatmap> beatmap { get; set; } = null!;
public BeatmapOptionsPopover(ScreenFooterButtonOptions footerButton) public BeatmapOptionsPopover(ScreenFooterButtonOptions footerButton, OverlayColourProvider colourProvider)
{ {
this.footerButton = footerButton; this.footerButton = footerButton;
this.colourProvider = colourProvider;
} }
[BackgroundDependencyLoader] [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); Content.Padding = new MarginPadding(5);
@ -61,15 +64,15 @@ namespace osu.Game.Screens.SelectV2.Footer
addButton(SongSelectStrings.ManageCollections, FontAwesome.Solid.Book, () => manageCollectionsDialog?.Show()); addButton(SongSelectStrings.ManageCollections, FontAwesome.Solid.Book, () => manageCollectionsDialog?.Show());
addHeader(SongSelectStrings.ForAllDifficulties, beatmapWhenOpening.BeatmapSetInfo.ToString()); 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); addHeader(SongSelectStrings.ForSelectedDifficulty, beatmapWhenOpening.BeatmapInfo.DifficultyName);
// TODO: make work, and make show "unplayed" or "played" based on status. // TODO: make work, and make show "unplayed" or "played" based on status.
addButton(SongSelectStrings.MarkAsPlayed, FontAwesome.Regular.TimesCircle, null); 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) // if (songSelect != null && songSelect.AllowEditing)
addButton(SongSelectStrings.EditBeatmap, FontAwesome.Solid.PencilAlt, () => songSelect.Edit(beatmapWhenOpening.BeatmapInfo)); addButton(SongSelectStrings.EditBeatmap, FontAwesome.Solid.PencilAlt, () => { }); // songSelect.Edit(beatmapWhenOpening.BeatmapInfo);
addButton(WebCommonStrings.ButtonsHide.ToSentence(), FontAwesome.Solid.Magic, () => beatmapManager?.Hide(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()); beatmap.BindValueChanged(_ => Hide());
} }
[Resolved]
private OverlayColourProvider overlayColourProvider { get; set; } = null!;
private void addHeader(LocalisableString text, string? context = null) private void addHeader(LocalisableString text, string? context = null)
{ {
var textFlow = new OsuTextFlowContainer var textFlow = new OsuTextFlowContainer
@ -102,7 +102,7 @@ namespace osu.Game.Screens.SelectV2.Footer
textFlow.NewLine(); textFlow.NewLine();
textFlow.AddText(context, t => textFlow.AddText(context, t =>
{ {
t.Colour = overlayColourProvider.Content2; t.Colour = colourProvider.Content2;
t.Font = t.Font.With(size: 13); t.Font = t.Font.With(size: 13);
}); });
} }

View File

@ -8,12 +8,16 @@ using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.UserInterface; using osu.Framework.Graphics.UserInterface;
using osu.Game.Graphics; using osu.Game.Graphics;
using osu.Game.Input.Bindings; using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Screens.Footer; using osu.Game.Screens.Footer;
namespace osu.Game.Screens.SelectV2.Footer namespace osu.Game.Screens.SelectV2.Footer
{ {
public partial class ScreenFooterButtonOptions : ScreenFooterButton, IHasPopover public partial class ScreenFooterButtonOptions : ScreenFooterButton, IHasPopover
{ {
[Resolved]
private OverlayColourProvider colourProvider { get; set; } = null!;
[BackgroundDependencyLoader] [BackgroundDependencyLoader]
private void load(OsuColour colour) private void load(OsuColour colour)
{ {
@ -25,6 +29,6 @@ namespace osu.Game.Screens.SelectV2.Footer
Action = this.ShowPopover; Action = this.ShowPopover;
} }
public Popover GetPopover() => new BeatmapOptionsPopover(this); public Popover GetPopover() => new BeatmapOptionsPopover(this, colourProvider);
} }
} }