mirror of
https://github.com/osukey/osukey.git
synced 2025-05-29 17:37:23 +09:00
Improve the feel of hovering toolbox component items
This commit is contained in:
parent
9f9893d93a
commit
5ed038fbb3
@ -2,12 +2,13 @@
|
|||||||
// See the LICENCE file in the repository root for full licence text.
|
// See the LICENCE file in the repository root for full licence text.
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using osu.Framework.Allocation;
|
using osu.Framework.Allocation;
|
||||||
using osu.Framework.Graphics;
|
using osu.Framework.Graphics;
|
||||||
using osu.Framework.Graphics.Containers;
|
using osu.Framework.Graphics.Containers;
|
||||||
using osu.Framework.Input.Events;
|
using osu.Framework.Input.Events;
|
||||||
using osu.Framework.Logging;
|
using osu.Framework.Logging;
|
||||||
using osu.Game.Graphics;
|
using osu.Framework.Threading;
|
||||||
using osu.Game.Graphics.Sprites;
|
using osu.Game.Graphics.Sprites;
|
||||||
using osu.Game.Graphics.UserInterface;
|
using osu.Game.Graphics.UserInterface;
|
||||||
using osu.Game.Localisation;
|
using osu.Game.Localisation;
|
||||||
@ -65,7 +66,8 @@ namespace osu.Game.Overlays.SkinEditor
|
|||||||
|
|
||||||
fill.Add(new ToolboxComponentButton(instance, target)
|
fill.Add(new ToolboxComponentButton(instance, target)
|
||||||
{
|
{
|
||||||
RequestPlacement = t => RequestPlacement?.Invoke(t)
|
RequestPlacement = t => RequestPlacement?.Invoke(t),
|
||||||
|
Expanding = contractOtherButtons,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
catch (DependencyNotRegisteredException)
|
catch (DependencyNotRegisteredException)
|
||||||
@ -79,15 +81,29 @@ namespace osu.Game.Overlays.SkinEditor
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void contractOtherButtons(ToolboxComponentButton obj)
|
||||||
|
{
|
||||||
|
foreach (var b in fill.OfType<ToolboxComponentButton>())
|
||||||
|
{
|
||||||
|
if (b == obj)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
b.Contract();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public partial class ToolboxComponentButton : OsuButton
|
public partial class ToolboxComponentButton : OsuButton
|
||||||
{
|
{
|
||||||
public Action<Type>? RequestPlacement;
|
public Action<Type>? RequestPlacement;
|
||||||
|
public Action<ToolboxComponentButton>? Expanding;
|
||||||
|
|
||||||
private readonly Drawable component;
|
private readonly Drawable component;
|
||||||
private readonly CompositeDrawable? dependencySource;
|
private readonly CompositeDrawable? dependencySource;
|
||||||
|
|
||||||
private Container innerContainer = null!;
|
private Container innerContainer = null!;
|
||||||
|
|
||||||
|
private ScheduledDelegate? expandContractAction;
|
||||||
|
|
||||||
private const float contracted_size = 60;
|
private const float contracted_size = 60;
|
||||||
private const float expanded_size = 120;
|
private const float expanded_size = 120;
|
||||||
|
|
||||||
@ -102,20 +118,44 @@ namespace osu.Game.Overlays.SkinEditor
|
|||||||
Height = contracted_size;
|
Height = contracted_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private const double animation_duration = 500;
|
||||||
|
|
||||||
protected override bool OnHover(HoverEvent e)
|
protected override bool OnHover(HoverEvent e)
|
||||||
{
|
{
|
||||||
this.Delay(300).ResizeHeightTo(expanded_size, 500, Easing.OutQuint);
|
expandContractAction = Scheduler.AddDelayed(() =>
|
||||||
|
{
|
||||||
|
this.ResizeHeightTo(expanded_size, animation_duration, Easing.OutQuint);
|
||||||
|
Expanding?.Invoke(this);
|
||||||
|
}, 100);
|
||||||
|
|
||||||
return base.OnHover(e);
|
return base.OnHover(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override void OnHoverLost(HoverLostEvent e)
|
protected override void OnHoverLost(HoverLostEvent e)
|
||||||
{
|
{
|
||||||
base.OnHoverLost(e);
|
base.OnHoverLost(e);
|
||||||
this.ResizeHeightTo(contracted_size, 500, Easing.OutQuint);
|
|
||||||
|
expandContractAction?.Cancel();
|
||||||
|
// If no other component is selected for too long, force a contract.
|
||||||
|
// Otherwise we will generally contract when Contract() is called from outside.
|
||||||
|
expandContractAction = Scheduler.AddDelayed(Contract, 1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Contract()
|
||||||
|
{
|
||||||
|
// Cheap debouncing to avoid stacking animations.
|
||||||
|
// The only place this is nulled is at the end of this method.
|
||||||
|
if (expandContractAction == null)
|
||||||
|
return;
|
||||||
|
|
||||||
|
this.ResizeHeightTo(contracted_size, animation_duration, Easing.OutQuint);
|
||||||
|
|
||||||
|
expandContractAction?.Cancel();
|
||||||
|
expandContractAction = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
[BackgroundDependencyLoader]
|
[BackgroundDependencyLoader]
|
||||||
private void load(OverlayColourProvider colourProvider, OsuColour colours)
|
private void load(OverlayColourProvider colourProvider)
|
||||||
{
|
{
|
||||||
BackgroundColour = colourProvider.Background3;
|
BackgroundColour = colourProvider.Background3;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user