Merge pull request #9911 from Game4all/fix-toolbar-visibility

Fix toolbar not respecting current overlay activation mode
This commit is contained in:
Dean Herbert 2020-08-19 19:49:55 +09:00 committed by GitHub
commit 33e9e518e3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 36 additions and 10 deletions

View File

@ -4,8 +4,10 @@
using System.Linq;
using NUnit.Framework;
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Testing;
using osu.Game.Overlays;
using osu.Game.Overlays.Toolbar;
using osu.Game.Rulesets;
using osuTK.Input;
@ -15,7 +17,7 @@ namespace osu.Game.Tests.Visual.Menus
[TestFixture]
public class TestSceneToolbar : OsuManualInputManagerTestScene
{
private Toolbar toolbar;
private TestToolbar toolbar;
[Resolved]
private RulesetStore rulesets { get; set; }
@ -23,7 +25,7 @@ namespace osu.Game.Tests.Visual.Menus
[SetUp]
public void SetUp() => Schedule(() =>
{
Child = toolbar = new Toolbar { State = { Value = Visibility.Visible } };
Child = toolbar = new TestToolbar { State = { Value = Visibility.Visible } };
});
[Test]
@ -72,5 +74,24 @@ namespace osu.Game.Tests.Visual.Menus
AddUntilStep("ruleset switched", () => rulesetSelector.Current.Value.Equals(expected));
}
}
[TestCase(OverlayActivation.All)]
[TestCase(OverlayActivation.Disabled)]
public void TestRespectsOverlayActivation(OverlayActivation mode)
{
AddStep($"set activation mode to {mode}", () => toolbar.OverlayActivationMode.Value = mode);
AddStep("hide toolbar", () => toolbar.Hide());
AddStep("try to show toolbar", () => toolbar.Show());
if (mode == OverlayActivation.Disabled)
AddAssert("toolbar still hidden", () => toolbar.State.Value == Visibility.Hidden);
else
AddAssert("toolbar is visible", () => toolbar.State.Value == Visibility.Visible);
}
public class TestToolbar : Toolbar
{
public new Bindable<OverlayActivation> OverlayActivationMode => base.OverlayActivationMode;
}
}
}

View File

@ -28,7 +28,7 @@ namespace osu.Game.Overlays.Toolbar
private const double transition_time = 500;
private readonly Bindable<OverlayActivation> overlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
protected readonly Bindable<OverlayActivation> OverlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
// Toolbar components like RulesetSelector should receive keyboard input events even when the toolbar is hidden.
public override bool PropagateNonPositionalInputSubTree => true;
@ -89,14 +89,8 @@ namespace osu.Game.Overlays.Toolbar
// Bound after the selector is added to the hierarchy to give it a chance to load the available rulesets
rulesetSelector.Current.BindTo(parentRuleset);
State.ValueChanged += visibility =>
{
if (overlayActivationMode.Value == OverlayActivation.Disabled)
Hide();
};
if (osuGame != null)
overlayActivationMode.BindTo(osuGame.OverlayActivationMode);
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
}
public class ToolbarBackground : Container
@ -137,6 +131,17 @@ namespace osu.Game.Overlays.Toolbar
}
}
protected override void UpdateState(ValueChangedEvent<Visibility> state)
{
if (state.NewValue == Visibility.Visible && OverlayActivationMode.Value == OverlayActivation.Disabled)
{
State.Value = Visibility.Hidden;
return;
}
base.UpdateState(state);
}
protected override void PopIn()
{
this.MoveToY(0, transition_time, Easing.OutQuint);