1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-21 15:27:24 +08:00

Merge pull request #12008 from Joehuu/user-hide-toolbar-forever

This commit is contained in:
Bartłomiej Dach 2021-03-13 18:03:25 +01:00 committed by GitHub
commit 716b9048c1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 62 additions and 7 deletions

View File

@ -229,6 +229,35 @@ namespace osu.Game.Tests.Visual.Navigation
AddUntilStep("settings displayed", () => Game.Settings.State.Value == Visibility.Visible);
}
[Test]
public void TestToolbarHiddenByUser()
{
AddStep("Enter menu", () => InputManager.Key(Key.Enter));
AddUntilStep("Wait for toolbar to load", () => Game.Toolbar.IsLoaded);
AddStep("Hide toolbar", () =>
{
InputManager.PressKey(Key.ControlLeft);
InputManager.Key(Key.T);
InputManager.ReleaseKey(Key.ControlLeft);
});
pushEscape();
AddStep("Enter menu", () => InputManager.Key(Key.Enter));
AddAssert("Toolbar is hidden", () => Game.Toolbar.State.Value == Visibility.Hidden);
AddStep("Enter song select", () =>
{
InputManager.Key(Key.Enter);
InputManager.Key(Key.Enter);
});
AddAssert("Toolbar is hidden", () => Game.Toolbar.State.Value == Visibility.Hidden);
}
private void pushEscape() =>
AddStep("Press escape", () => InputManager.Key(Key.Escape));

View File

@ -885,10 +885,6 @@ namespace osu.Game
frameworkConfig.GetBindable<ConfineMouseMode>(FrameworkSetting.ConfineMouseMode).SetDefault();
return true;
case GlobalAction.ToggleToolbar:
Toolbar.ToggleVisibility();
return true;
case GlobalAction.ToggleGameplayMouseButtons:
LocalConfig.Set(OsuSetting.MouseDisableButtons, !LocalConfig.Get<bool>(OsuSetting.MouseDisableButtons));
return true;

View File

@ -13,14 +13,22 @@ using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Input.Events;
using osu.Game.Rulesets;
using osu.Framework.Input.Bindings;
using osu.Game.Input.Bindings;
namespace osu.Game.Overlays.Toolbar
{
public class Toolbar : VisibilityContainer
public class Toolbar : VisibilityContainer, IKeyBindingHandler<GlobalAction>
{
public const float HEIGHT = 40;
public const float TOOLTIP_HEIGHT = 30;
/// <summary>
/// Whether the user hid this <see cref="Toolbar"/> with <see cref="GlobalAction.ToggleToolbar"/>.
/// In this state, automatic toggles should not occur, respecting the user's preference to have no toolbar.
/// </summary>
private bool hiddenByUser;
public Action OnHome;
private ToolbarUserButton userButton;
@ -30,7 +38,7 @@ namespace osu.Game.Overlays.Toolbar
protected readonly IBindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
// Toolbar components like RulesetSelector should receive keyboard input events even when the toolbar is hidden.
// Toolbar and its components need keyboard input even when hidden.
public override bool PropagateNonPositionalInputSubTree => true;
public Toolbar()
@ -142,7 +150,9 @@ namespace osu.Game.Overlays.Toolbar
protected override void UpdateState(ValueChangedEvent<Visibility> state)
{
if (state.NewValue == Visibility.Visible && OverlayActivationMode.Value == OverlayActivation.Disabled)
bool blockShow = hiddenByUser || OverlayActivationMode.Value == OverlayActivation.Disabled;
if (state.NewValue == Visibility.Visible && blockShow)
{
State.Value = Visibility.Hidden;
return;
@ -164,5 +174,25 @@ namespace osu.Game.Overlays.Toolbar
this.MoveToY(-DrawSize.Y, transition_time, Easing.OutQuint);
this.FadeOut(transition_time, Easing.InQuint);
}
public bool OnPressed(GlobalAction action)
{
if (OverlayActivationMode.Value == OverlayActivation.Disabled)
return false;
switch (action)
{
case GlobalAction.ToggleToolbar:
hiddenByUser = State.Value == Visibility.Visible; // set before toggling to allow the operation to always succeed.
ToggleVisibility();
return true;
}
return false;
}
public void OnReleased(GlobalAction action)
{
}
}
}