mirror of
https://github.com/ppy/osu.git
synced 2025-01-26 16:12:54 +08:00
Use alternative workaround
This commit is contained in:
parent
f625c5d744
commit
0d70f2c0fd
@ -13,7 +13,6 @@ using osuTK;
|
|||||||
using osu.Framework.Graphics.Shapes;
|
using osu.Framework.Graphics.Shapes;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Bindables;
|
using osu.Framework.Bindables;
|
||||||
using osu.Framework.Input;
|
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Game.Rulesets;
|
using osu.Game.Rulesets;
|
||||||
using osu.Framework.Input.Bindings;
|
using osu.Framework.Input.Bindings;
|
||||||
@ -66,9 +65,12 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
[BackgroundDependencyLoader(true)]
|
[BackgroundDependencyLoader(true)]
|
||||||
private void load(OsuGame osuGame)
|
private void load(OsuGame osuGame)
|
||||||
{
|
{
|
||||||
|
ToolbarBackground background;
|
||||||
|
HoverInterceptor interceptor;
|
||||||
|
|
||||||
Children = new Drawable[]
|
Children = new Drawable[]
|
||||||
{
|
{
|
||||||
new ToolbarBackground(),
|
background = new ToolbarBackground(),
|
||||||
new GridContainer
|
new GridContainer
|
||||||
{
|
{
|
||||||
RelativeSizeAxes = Axes.Both,
|
RelativeSizeAxes = Axes.Both,
|
||||||
@ -181,9 +183,15 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
interceptor = new HoverInterceptor
|
||||||
|
{
|
||||||
|
RelativeSizeAxes = Axes.Both
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
((IBindable<bool>)background.ShowGradient).BindTo(interceptor.ReceivedHover);
|
||||||
|
|
||||||
if (osuGame != null)
|
if (osuGame != null)
|
||||||
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
|
OverlayActivationMode.BindTo(osuGame.OverlayActivationMode);
|
||||||
}
|
}
|
||||||
@ -197,8 +205,7 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
|
|
||||||
public partial class ToolbarBackground : Container
|
public partial class ToolbarBackground : Container
|
||||||
{
|
{
|
||||||
private InputManager inputManager;
|
public Bindable<bool> ShowGradient { get; } = new BindableBool();
|
||||||
private Bindable<bool> showGradient { get; } = new BindableBool();
|
|
||||||
|
|
||||||
private readonly Box gradientBackground;
|
private readonly Box gradientBackground;
|
||||||
|
|
||||||
@ -228,29 +235,42 @@ namespace osu.Game.Overlays.Toolbar
|
|||||||
{
|
{
|
||||||
base.LoadComplete();
|
base.LoadComplete();
|
||||||
|
|
||||||
inputManager = GetContainingInputManager();
|
ShowGradient.BindValueChanged(_ => updateState(), true);
|
||||||
showGradient.BindValueChanged(_ => updateState(), true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected override void Update()
|
|
||||||
{
|
|
||||||
base.Update();
|
|
||||||
|
|
||||||
var currentMousePosition = inputManager.CurrentState.Mouse.Position;
|
|
||||||
// ensure that the gradient is not shown if the mouse is above the window.
|
|
||||||
// this is relevant when the background is moving due to the toolbar being toggled.
|
|
||||||
showGradient.Value = currentMousePosition.Y >= 0 && Contains(inputManager.CurrentState.Mouse.Position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void updateState()
|
private void updateState()
|
||||||
{
|
{
|
||||||
if (showGradient.Value)
|
if (ShowGradient.Value)
|
||||||
gradientBackground.FadeIn(transition_time, Easing.OutQuint);
|
gradientBackground.FadeIn(transition_time, Easing.OutQuint);
|
||||||
else
|
else
|
||||||
gradientBackground.FadeOut(transition_time, Easing.OutQuint);
|
gradientBackground.FadeOut(transition_time, Easing.OutQuint);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Whenever the mouse cursor is within the bounds of the toolbar, we want the background gradient to show, for toolbar button descriptions to be legible.
|
||||||
|
/// Unfortunately we also need to ensure that the toolbar buttons handle hover, to prevent the possibility of multiple descriptions being shown
|
||||||
|
/// due to hover events passing through multiple buttons.
|
||||||
|
/// This drawable is a workaround, that when placed front-most in the toolbar, allows to see whether hover events have been propagated through it without handling them.
|
||||||
|
/// </summary>
|
||||||
|
private partial class HoverInterceptor : Drawable
|
||||||
|
{
|
||||||
|
public IBindable<bool> ReceivedHover => receivedHover;
|
||||||
|
private readonly Bindable<bool> receivedHover = new BindableBool();
|
||||||
|
|
||||||
|
protected override bool OnHover(HoverEvent e)
|
||||||
|
{
|
||||||
|
receivedHover.Value = true;
|
||||||
|
return base.OnHover(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
|
{
|
||||||
|
receivedHover.Value = false;
|
||||||
|
base.OnHoverLost(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
protected override void UpdateState(ValueChangedEvent<Visibility> state)
|
||||||
{
|
{
|
||||||
bool blockShow = hiddenByUser || OverlayActivationMode.Value == OverlayActivation.Disabled;
|
bool blockShow = hiddenByUser || OverlayActivationMode.Value == OverlayActivation.Disabled;
|
||||||
|
Loading…
Reference in New Issue
Block a user