From d4a4a059d4a68affe7563d63ede5c9112a919482 Mon Sep 17 00:00:00 2001 From: Salman Ahmed Date: Thu, 11 Jul 2024 15:31:02 +0300 Subject: [PATCH] Fix footer content not accessible by overlay when overriden by a subclass --- osu.Game/Overlays/FirstRunSetupOverlay.cs | 16 ++++++++-------- osu.Game/Overlays/Mods/ModSelectOverlay.cs | 8 ++++---- .../Overlays/Mods/ShearedOverlayContainer.cs | 6 +++++- osu.Game/Screens/Footer/ScreenFooter.cs | 6 ++++-- .../Screens/OnlinePlay/FreeModSelectOverlay.cs | 10 +++++----- 5 files changed, 26 insertions(+), 20 deletions(-) diff --git a/osu.Game/Overlays/FirstRunSetupOverlay.cs b/osu.Game/Overlays/FirstRunSetupOverlay.cs index 2c8ceba82c..1a302cf51d 100644 --- a/osu.Game/Overlays/FirstRunSetupOverlay.cs +++ b/osu.Game/Overlays/FirstRunSetupOverlay.cs @@ -45,7 +45,7 @@ namespace osu.Game.Overlays private ScreenStack? stack; - public ShearedButton? NextButton => currentFooterContent?.NextButton; + public ShearedButton? NextButton => DisplayedFooterContent?.NextButton; private readonly Bindable showFirstRunSetup = new Bindable(); @@ -148,17 +148,17 @@ namespace osu.Game.Overlays [Resolved] private ScreenFooter footer { get; set; } = null!; - private FirstRunSetupFooterContent? currentFooterContent; + public new FirstRunSetupFooterContent? DisplayedFooterContent => base.DisplayedFooterContent as FirstRunSetupFooterContent; public override VisibilityContainer CreateFooterContent() { - currentFooterContent = new FirstRunSetupFooterContent + var footerContent = new FirstRunSetupFooterContent { ShowNextStep = showNextStep, }; - currentFooterContent.OnLoadComplete += _ => updateButtons(); - return currentFooterContent; + footerContent.OnLoadComplete += _ => updateButtons(); + return footerContent; } public override bool OnBackButton() @@ -182,7 +182,7 @@ namespace osu.Game.Overlays switch (e.Action) { case GlobalAction.Select: - currentFooterContent?.NextButton.TriggerClick(); + DisplayedFooterContent?.NextButton.TriggerClick(); return true; case GlobalAction.Back: @@ -287,9 +287,9 @@ namespace osu.Game.Overlays updateButtons(); } - private void updateButtons() => currentFooterContent?.UpdateButtons(currentStepIndex, steps); + private void updateButtons() => DisplayedFooterContent?.UpdateButtons(currentStepIndex, steps); - private partial class FirstRunSetupFooterContent : VisibilityContainer + public partial class FirstRunSetupFooterContent : VisibilityContainer { public ShearedButton NextButton { get; private set; } = null!; diff --git a/osu.Game/Overlays/Mods/ModSelectOverlay.cs b/osu.Game/Overlays/Mods/ModSelectOverlay.cs index 4143a7fe8a..7469590895 100644 --- a/osu.Game/Overlays/Mods/ModSelectOverlay.cs +++ b/osu.Game/Overlays/Mods/ModSelectOverlay.cs @@ -254,9 +254,9 @@ namespace osu.Game.Overlays.Mods }); } - private ModSelectFooterContent? currentFooterContent; + public new ModSelectFooterContent? DisplayedFooterContent => base.DisplayedFooterContent as ModSelectFooterContent; - public override VisibilityContainer CreateFooterContent() => currentFooterContent = new ModSelectFooterContent(this) + public override VisibilityContainer CreateFooterContent() => new ModSelectFooterContent(this) { Beatmap = { BindTarget = Beatmap }, ActiveMods = { BindTarget = ActiveMods }, @@ -270,7 +270,7 @@ namespace osu.Game.Overlays.Mods base.Update(); SearchTextBox.PlaceholderText = SearchTextBox.HasFocus ? input_search_placeholder : tab_to_search_placeholder; - aboveColumnsContent.Padding = aboveColumnsContent.Padding with { Bottom = currentFooterContent?.DisplaysStackedVertically == true ? 75f : 15f }; + aboveColumnsContent.Padding = aboveColumnsContent.Padding with { Bottom = DisplayedFooterContent?.DisplaysStackedVertically == true ? 75f : 15f }; } /// @@ -573,7 +573,7 @@ namespace osu.Game.Overlays.Mods { if (!SearchTextBox.HasFocus && !customisationPanel.Expanded.Value) { - currentFooterContent?.DeselectAllModsButton?.TriggerClick(); + DisplayedFooterContent?.DeselectAllModsButton?.TriggerClick(); return true; } diff --git a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs index 8c6b9e805b..dfa49f3779 100644 --- a/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs +++ b/osu.Game/Overlays/Mods/ShearedOverlayContainer.cs @@ -102,6 +102,8 @@ namespace osu.Game.Overlays.Mods }; } + public VisibilityContainer? DisplayedFooterContent { get; private set; } + /// /// Creates content to be displayed on the game-wide footer. /// @@ -137,7 +139,8 @@ namespace osu.Game.Overlays.Mods if (footer != null) { - activeOverlayRegistration = footer.RegisterActiveOverlayContainer(this); + activeOverlayRegistration = footer.RegisterActiveOverlayContainer(this, out var footerContent); + DisplayedFooterContent = footerContent; if (footer.State.Value == Visibility.Hidden) { @@ -160,6 +163,7 @@ namespace osu.Game.Overlays.Mods { activeOverlayRegistration?.Dispose(); activeOverlayRegistration = null; + DisplayedFooterContent = null; if (hideFooterOnPopOut) { diff --git a/osu.Game/Screens/Footer/ScreenFooter.cs b/osu.Game/Screens/Footer/ScreenFooter.cs index f8d222e510..4c020fc95e 100644 --- a/osu.Game/Screens/Footer/ScreenFooter.cs +++ b/osu.Game/Screens/Footer/ScreenFooter.cs @@ -190,7 +190,7 @@ namespace osu.Game.Screens.Footer private readonly List temporarilyHiddenButtons = new List(); - public IDisposable RegisterActiveOverlayContainer(ShearedOverlayContainer overlay) + public IDisposable RegisterActiveOverlayContainer(ShearedOverlayContainer overlay, out VisibilityContainer? footerContent) { if (activeOverlay != null) { @@ -219,7 +219,9 @@ namespace osu.Game.Screens.Footer updateColourScheme(overlay.ColourProvider.ColourScheme); - var content = overlay.CreateFooterContent() ?? Empty(); + footerContent = overlay.CreateFooterContent(); + + var content = footerContent ?? Empty(); Add(contentContainer = new Container { diff --git a/osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs b/osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs index 2b3ab94916..8937abb775 100644 --- a/osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs +++ b/osu.Game/Screens/OnlinePlay/FreeModSelectOverlay.cs @@ -23,9 +23,7 @@ namespace osu.Game.Screens.OnlinePlay set => base.IsValidMod = m => m.UserPlayable && value.Invoke(m); } - private FreeModSelectFooterContent? currentFooterContent; - - protected override SelectAllModsButton? SelectAllModsButton => currentFooterContent?.SelectAllModsButton; + protected override SelectAllModsButton? SelectAllModsButton => DisplayedFooterContent?.SelectAllModsButton; public FreeModSelectOverlay() : base(OverlayColourScheme.Plum) @@ -35,13 +33,15 @@ namespace osu.Game.Screens.OnlinePlay protected override ModColumn CreateModColumn(ModType modType) => new ModColumn(modType, true); - public override VisibilityContainer CreateFooterContent() => currentFooterContent = new FreeModSelectFooterContent(this) + public new FreeModSelectFooterContent? DisplayedFooterContent => base.DisplayedFooterContent as FreeModSelectFooterContent; + + public override VisibilityContainer CreateFooterContent() => new FreeModSelectFooterContent(this) { Beatmap = { BindTarget = Beatmap }, ActiveMods = { BindTarget = ActiveMods }, }; - private partial class FreeModSelectFooterContent : ModSelectFooterContent + public partial class FreeModSelectFooterContent : ModSelectFooterContent { private readonly FreeModSelectOverlay overlay;