1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-15 19:12:57 +08:00

Fix panel collapse when hovering dropdown menu

This commit is contained in:
Caiyi Shyu 2024-07-27 15:15:14 +08:00
parent bd017aea38
commit b97d96fcb0

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Diagnostics;
using System.Linq; using System.Linq;
using osu.Framework.Allocation; using osu.Framework.Allocation;
using osu.Framework.Bindables; using osu.Framework.Bindables;
@ -11,6 +12,7 @@ using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers; using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Effects; using osu.Framework.Graphics.Effects;
using osu.Framework.Graphics.Shapes; using osu.Framework.Graphics.Shapes;
using osu.Framework.Input;
using osu.Framework.Input.Bindings; using osu.Framework.Input.Bindings;
using osu.Framework.Input.Events; using osu.Framework.Input.Events;
using osu.Game.Configuration; using osu.Game.Configuration;
@ -81,6 +83,7 @@ namespace osu.Game.Overlays.Mods
Colour = Color4.Black.Opacity(0.25f), Colour = Color4.Black.Opacity(0.25f),
}, },
Expanded = { BindTarget = Expanded }, Expanded = { BindTarget = Expanded },
ExpandedByHovering = { BindTarget = ExpandedByHovering },
Children = new Drawable[] Children = new Drawable[]
{ {
new Box new Box
@ -176,20 +179,22 @@ namespace osu.Game.Overlays.Mods
content.FadeOut(400, Easing.OutSine); content.FadeOut(400, Easing.OutSine);
} }
expandedByHovering = false; ExpandedByHovering.Value = false;
} }
private bool expandedByHovering; public readonly BindableBool ExpandedByHovering = new BindableBool();
public void UpdateHoverExpansion(bool hovered) public void UpdateHoverExpansion(bool hovered)
{ {
if (hovered && !Expanded.Value) if (hovered && !Expanded.Value)
{ {
Expanded.Value = true; Expanded.Value = true;
expandedByHovering = true; ExpandedByHovering.Value = true;
} }
else if (!hovered && expandedByHovering) else if (!hovered && ExpandedByHovering.Value)
{ {
Debug.Assert(Expanded.Value);
Expanded.Value = false; Expanded.Value = false;
} }
} }
@ -220,17 +225,35 @@ namespace osu.Game.Overlays.Mods
private partial class FocusGrabbingContainer : InputBlockingContainer private partial class FocusGrabbingContainer : InputBlockingContainer
{ {
public IBindable<bool> Expanded { get; } = new BindableBool(); public IBindable<bool> Expanded { get; } = new BindableBool();
public IBindable<bool> ExpandedByHovering { get; } = new BindableBool();
public override bool RequestsFocus => Expanded.Value; public override bool RequestsFocus => Expanded.Value;
public override bool AcceptsFocus => Expanded.Value; public override bool AcceptsFocus => Expanded.Value;
public new ModCustomisationPanel? Parent => (ModCustomisationPanel?)base.Parent; public new ModCustomisationPanel? Parent => (ModCustomisationPanel?)base.Parent;
private InputManager inputManager = null!;
protected override void LoadComplete()
{
inputManager = GetContainingInputManager();
}
protected override void OnHoverLost(HoverLostEvent e) protected override void OnHoverLost(HoverLostEvent e)
{ {
Parent?.UpdateHoverExpansion(false); if (ExpandedByHovering.Value && !hasHoveredchild())
Parent?.UpdateHoverExpansion(false);
base.OnHoverLost(e); base.OnHoverLost(e);
} }
private bool hasHoveredchild()
{
return inputManager.HoveredDrawables.Any(parentIsThis);
bool parentIsThis(Drawable d)
=> d is not null && (d == this || parentIsThis(d.Parent));
}
} }
} }
} }