Skip to content

Commit

Permalink
Merge pull request #30863 from frenzibyte/improve-back-button-display
Browse files Browse the repository at this point in the history
Delay back button appearance when performing a quick restart
  • Loading branch information
bdach authored Dec 2, 2024
2 parents 52b8753 + 932afcd commit 6c0ccc5
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 23 deletions.
22 changes: 16 additions & 6 deletions osu.Game/OsuGame.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ public partial class OsuGame : OsuGameBase, IKeyBindingHandler<GlobalAction>, IL
/// </summary>
public readonly IBindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>();

/// <summary>
/// Whether the back button is currently displayed.
/// </summary>
private readonly IBindable<bool> backButtonVisibility = new Bindable<bool>();

IBindable<LocalUserPlayingState> ILocalUserPlayInfo.PlayingState => playingState;

private readonly Bindable<LocalUserPlayingState> playingState = new Bindable<LocalUserPlayingState>();
Expand Down Expand Up @@ -1019,7 +1024,7 @@ protected override void LoadComplete()
if (!(ScreenStack.CurrentScreen is IOsuScreen currentScreen))
return;

if (!((Drawable)currentScreen).IsLoaded || (currentScreen.AllowBackButton && !currentScreen.OnBackButton()))
if (!((Drawable)currentScreen).IsLoaded || (currentScreen.AllowUserExit && !currentScreen.OnBackButton()))
ScreenStack.Exit();
}
},
Expand Down Expand Up @@ -1189,6 +1194,14 @@ protected override void LoadComplete()
if (mode.NewValue != OverlayActivation.All) CloseAllOverlays();
};

backButtonVisibility.ValueChanged += visible =>
{
if (visible.NewValue)
BackButton.Show();
else
BackButton.Hide();
};

// Importantly, this should be run after binding PostNotification to the import handlers so they can present the import after game startup.
handleStartupImport();
}
Expand Down Expand Up @@ -1581,12 +1594,14 @@ private void screenChanged(IScreen current, IScreen newScreen)

if (current is IOsuScreen currentOsuScreen)
{
backButtonVisibility.UnbindFrom(currentOsuScreen.BackButtonVisibility);
OverlayActivationMode.UnbindFrom(currentOsuScreen.OverlayActivationMode);
API.Activity.UnbindFrom(currentOsuScreen.Activity);
}

if (newScreen is IOsuScreen newOsuScreen)
{
backButtonVisibility.BindTo(newOsuScreen.BackButtonVisibility);
OverlayActivationMode.BindTo(newOsuScreen.OverlayActivationMode);
API.Activity.BindTo(newOsuScreen.Activity);

Expand All @@ -1597,11 +1612,6 @@ private void screenChanged(IScreen current, IScreen newScreen)
else
Toolbar.Show();

if (newOsuScreen.AllowBackButton)
BackButton.Show();
else
BackButton.Hide();

if (newOsuScreen.ShowFooter)
{
BackButton.Hide();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public partial class MigrationRunScreen : OsuScreen
[Resolved(canBeNull: true)]
private OsuGame game { get; set; }

public override bool AllowBackButton => false;
public override bool AllowUserExit => false;

public override bool AllowExternalScreenChange => false;

Expand Down
9 changes: 2 additions & 7 deletions osu.Game/Screens/Edit/Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,6 @@ public partial class Editor : ScreenWithBeatmapBackground, IKeyBindingHandler<Gl

public override float BackgroundParallaxAmount => 0.1f;

public override bool AllowBackButton => false;

public override bool HideOverlaysOnEnter => true;

public override bool DisallowExternalBeatmapRulesetChanges => true;
Expand Down Expand Up @@ -194,6 +192,8 @@ protected override UserActivity InitialActivity
}
}

protected override bool InitialBackButtonVisibility => false;

protected override IReadOnlyDependencyContainer CreateChildDependencies(IReadOnlyDependencyContainer parent)
=> dependencies = new DependencyContainer(base.CreateChildDependencies(parent));

Expand Down Expand Up @@ -760,11 +760,6 @@ public bool OnPressed(KeyBindingPressEvent<GlobalAction> e)

switch (e.Action)
{
case GlobalAction.Back:
// as we don't want to display the back button, manual handling of exit action is required.
this.Exit();
return true;

case GlobalAction.EditorCloneSelection:
Clone();
return true;
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Edit/EditorLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public partial class EditorLoader : ScreenWithBeatmapBackground

public override float BackgroundParallaxAmount => 0.1f;

public override bool AllowBackButton => false;
public override bool AllowUserExit => false;

public override bool HideOverlaysOnEnter => true;

Expand Down
18 changes: 15 additions & 3 deletions osu.Game/Screens/IOsuScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using osu.Framework.Bindables;
using osu.Framework.Screens;
using osu.Game.Beatmaps;
using osu.Game.Input.Bindings;
using osu.Game.Overlays;
using osu.Game.Rulesets;
using osu.Game.Screens.Footer;
Expand All @@ -21,15 +22,21 @@ public interface IOsuScreen : IScreen
bool DisallowExternalBeatmapRulesetChanges { get; }

/// <summary>
/// Whether the user can exit this <see cref="IOsuScreen"/> by pressing the back button.
/// Whether the user can exit this <see cref="IOsuScreen"/>.
/// </summary>
bool AllowBackButton { get; }
/// <remarks>
/// When overriden to <c>false</c>,
/// the user is blocked from exiting the screen via the <see cref="GlobalAction.Back"/> action,
/// and the back button is hidden from this screen by the initial state of <see cref="BackButtonVisibility"/> being set to hidden.
/// </remarks>
bool AllowUserExit { get; }

/// <summary>
/// Whether a footer (and a back button) should be displayed underneath the screen.
/// </summary>
/// <remarks>
/// Temporarily, the back button is shown regardless of whether <see cref="AllowBackButton"/> is true.
/// Temporarily, the footer's own back button is shown regardless of whether <see cref="BackButtonVisibility"/> is set to hidden.
/// This will be corrected as the footer becomes used more commonly.
/// </remarks>
bool ShowFooter { get; }

Expand Down Expand Up @@ -59,6 +66,11 @@ public interface IOsuScreen : IScreen
/// </summary>
IBindable<OverlayActivation> OverlayActivationMode { get; }

/// <summary>
/// Whether the back button should be displayed in this screen.
/// </summary>
IBindable<bool> BackButtonVisibility { get; }

/// <summary>
/// The current <see cref="UserActivity"/> for this screen.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Menu/MainMenu.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public partial class MainMenu : OsuScreen, IHandlePresentBeatmap, IKeyBindingHan

public override bool HideOverlaysOnEnter => Buttons == null || Buttons.State == ButtonSystemState.Initial;

public override bool AllowBackButton => false;
public override bool AllowUserExit => false;

public override bool AllowExternalScreenChange => true;

Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/OnlinePlay/OnlinePlayScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ public override bool OnBackButton()
if (!(screenStack.CurrentScreen is IOnlinePlaySubScreen onlineSubScreen))
return false;

if (((Drawable)onlineSubScreen).IsLoaded && onlineSubScreen.AllowBackButton && onlineSubScreen.OnBackButton())
if (((Drawable)onlineSubScreen).IsLoaded && onlineSubScreen.AllowUserExit && onlineSubScreen.OnBackButton())
return true;

if (screenStack.CurrentScreen != null && !(screenStack.CurrentScreen is LoungeSubScreen))
Expand Down
12 changes: 11 additions & 1 deletion osu.Game/Screens/OsuScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public abstract partial class OsuScreen : Screen, IOsuScreen, IHasDescription

public string Description => Title;

public virtual bool AllowBackButton => true;
public virtual bool AllowUserExit => true;

public virtual bool ShowFooter => false;

Expand All @@ -56,6 +56,15 @@ public abstract partial class OsuScreen : Screen, IOsuScreen, IHasDescription

IBindable<OverlayActivation> IOsuScreen.OverlayActivationMode => OverlayActivationMode;

/// <summary>
/// The initial visibility state of the back button when this screen is entered for the first time.
/// </summary>
protected virtual bool InitialBackButtonVisibility => AllowUserExit;

public readonly Bindable<bool> BackButtonVisibility;

IBindable<bool> IOsuScreen.BackButtonVisibility => BackButtonVisibility;

public virtual bool CursorVisible => true;

protected new OsuGameBase Game => base.Game as OsuGameBase;
Expand Down Expand Up @@ -154,6 +163,7 @@ protected OsuScreen()
Origin = Anchor.Centre;

OverlayActivationMode = new Bindable<OverlayActivation>(InitialOverlayActivationMode);
BackButtonVisibility = new Bindable<bool>(InitialBackButtonVisibility);
}

[BackgroundDependencyLoader(true)]
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/Play/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public abstract partial class Player : ScreenWithBeatmapBackground, ISamplePlayb
/// </summary>
public event Action OnGameplayStarted;

public override bool AllowBackButton => false; // handled by HoldForMenuButton
public override bool AllowUserExit => false; // handled by HoldForMenuButton

protected override bool PlayExitSound => !isRestarting;

Expand Down
4 changes: 4 additions & 0 deletions osu.Game/Screens/Play/PlayerLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,8 @@ private void contentIn(double delayBeforeSideDisplays = 0)

if (quickRestart)
{
BackButtonVisibility.Value = false;

// A quick restart starts by triggering a fade to black
AddInternal(quickRestartBlackLayer = new Box
{
Expand All @@ -503,6 +505,8 @@ private void contentIn(double delayBeforeSideDisplays = 0)
.Delay(quick_restart_initial_delay)
.ScaleTo(1)
.FadeInFromZero(500, Easing.OutQuint);

this.Delay(quick_restart_initial_delay).Schedule(() => BackButtonVisibility.Value = true);
}
else
{
Expand Down
2 changes: 1 addition & 1 deletion osu.Game/Screens/StartupScreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ namespace osu.Game.Screens
/// </summary>
public abstract partial class StartupScreen : OsuScreen
{
public override bool AllowBackButton => false;
public override bool AllowUserExit => false;

public override bool HideOverlaysOnEnter => true;

Expand Down

0 comments on commit 6c0ccc5

Please sign in to comment.