mirror of
https://github.com/osukey/osukey.git
synced 2025-08-04 15:16:38 +09:00
Merge branch 'master' into net6
This commit is contained in:
@ -1,141 +0,0 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System;
|
||||
using System.Linq;
|
||||
using osu.Framework;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Containers;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Testing;
|
||||
using osu.Framework.Threading;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public abstract class ExpandingButtonContainer : Container, IStateful<ExpandedState>
|
||||
{
|
||||
private readonly float contractedWidth;
|
||||
private readonly float expandedWidth;
|
||||
|
||||
public event Action<ExpandedState> StateChanged;
|
||||
|
||||
protected override Container<Drawable> Content => FillFlow;
|
||||
|
||||
protected FillFlowContainer FillFlow { get; }
|
||||
|
||||
protected ExpandingButtonContainer(float contractedWidth, float expandedWidth)
|
||||
{
|
||||
this.contractedWidth = contractedWidth;
|
||||
this.expandedWidth = expandedWidth;
|
||||
|
||||
RelativeSizeAxes = Axes.Y;
|
||||
Width = contractedWidth;
|
||||
|
||||
InternalChildren = new Drawable[]
|
||||
{
|
||||
new SidebarScrollContainer
|
||||
{
|
||||
Children = new[]
|
||||
{
|
||||
FillFlow = new FillFlowContainer
|
||||
{
|
||||
Origin = Anchor.CentreLeft,
|
||||
Anchor = Anchor.CentreLeft,
|
||||
AutoSizeAxes = Axes.Y,
|
||||
RelativeSizeAxes = Axes.X,
|
||||
Direction = FillDirection.Vertical,
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
private ScheduledDelegate expandEvent;
|
||||
private ExpandedState state;
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
queueExpandIfHovering();
|
||||
return true;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
expandEvent?.Cancel();
|
||||
hoveredButton = null;
|
||||
State = ExpandedState.Contracted;
|
||||
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
|
||||
protected override bool OnMouseMove(MouseMoveEvent e)
|
||||
{
|
||||
queueExpandIfHovering();
|
||||
return base.OnMouseMove(e);
|
||||
}
|
||||
|
||||
private class SidebarScrollContainer : OsuScrollContainer
|
||||
{
|
||||
public SidebarScrollContainer()
|
||||
{
|
||||
RelativeSizeAxes = Axes.Both;
|
||||
ScrollbarVisible = false;
|
||||
}
|
||||
}
|
||||
|
||||
public ExpandedState State
|
||||
{
|
||||
get => state;
|
||||
set
|
||||
{
|
||||
expandEvent?.Cancel();
|
||||
|
||||
if (state == value) return;
|
||||
|
||||
state = value;
|
||||
|
||||
switch (state)
|
||||
{
|
||||
default:
|
||||
this.ResizeTo(new Vector2(contractedWidth, Height), 500, Easing.OutQuint);
|
||||
break;
|
||||
|
||||
case ExpandedState.Expanded:
|
||||
this.ResizeTo(new Vector2(expandedWidth, Height), 500, Easing.OutQuint);
|
||||
break;
|
||||
}
|
||||
|
||||
StateChanged?.Invoke(State);
|
||||
}
|
||||
}
|
||||
|
||||
private Drawable hoveredButton;
|
||||
|
||||
private void queueExpandIfHovering()
|
||||
{
|
||||
// if the same button is hovered, let the scheduled expand play out..
|
||||
if (hoveredButton?.IsHovered == true)
|
||||
return;
|
||||
|
||||
// ..otherwise check whether a new button is hovered, and if so, queue a new hover operation.
|
||||
|
||||
// usually we wouldn't use ChildrenOfType in implementations, but this is the simplest way
|
||||
// to handle cases like the editor where the buttons may be nested within a child hierarchy.
|
||||
hoveredButton = FillFlow.ChildrenOfType<OsuButton>().FirstOrDefault(c => c.IsHovered);
|
||||
|
||||
expandEvent?.Cancel();
|
||||
|
||||
if (hoveredButton?.IsHovered == true && State != ExpandedState.Expanded)
|
||||
expandEvent = Scheduler.AddDelayed(() => State = ExpandedState.Expanded, 750);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ExpandedState
|
||||
{
|
||||
Contracted,
|
||||
Expanded,
|
||||
}
|
||||
}
|
@ -4,6 +4,7 @@
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Graphics;
|
||||
using osu.Framework.Graphics.Shapes;
|
||||
using osu.Game.Graphics.Containers;
|
||||
|
||||
namespace osu.Game.Overlays.Settings
|
||||
{
|
||||
|
@ -265,7 +265,7 @@ namespace osu.Game.Overlays
|
||||
return;
|
||||
|
||||
SectionsContainer.ScrollTo(section);
|
||||
Sidebar.State = ExpandedState.Contracted;
|
||||
Sidebar.Expanded.Value = false;
|
||||
},
|
||||
};
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using osu.Framework.Allocation;
|
||||
using osu.Framework.Bindables;
|
||||
using osu.Framework.Caching;
|
||||
using osu.Framework.Extensions.EnumExtensions;
|
||||
using osu.Framework.Graphics;
|
||||
@ -11,6 +12,7 @@ using osu.Framework.Graphics.Sprites;
|
||||
using osu.Framework.Input.Events;
|
||||
using osu.Framework.Layout;
|
||||
using osu.Game.Graphics;
|
||||
using osu.Game.Graphics.Containers;
|
||||
using osu.Game.Graphics.Sprites;
|
||||
using osu.Game.Graphics.UserInterface;
|
||||
using osuTK;
|
||||
@ -18,7 +20,7 @@ using osuTK.Graphics;
|
||||
|
||||
namespace osu.Game.Overlays
|
||||
{
|
||||
public abstract class SettingsToolboxGroup : Container
|
||||
public class SettingsToolboxGroup : Container, IExpandable
|
||||
{
|
||||
private const float transition_duration = 250;
|
||||
private const int container_width = 270;
|
||||
@ -34,30 +36,7 @@ namespace osu.Game.Overlays
|
||||
private readonly FillFlowContainer content;
|
||||
private readonly IconButton button;
|
||||
|
||||
private bool expanded = true;
|
||||
|
||||
public bool Expanded
|
||||
{
|
||||
get => expanded;
|
||||
set
|
||||
{
|
||||
if (expanded == value) return;
|
||||
|
||||
expanded = value;
|
||||
|
||||
content.ClearTransforms();
|
||||
|
||||
if (expanded)
|
||||
content.AutoSizeAxes = Axes.Y;
|
||||
else
|
||||
{
|
||||
content.AutoSizeAxes = Axes.None;
|
||||
content.ResizeHeightTo(0, transition_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
updateExpanded();
|
||||
}
|
||||
}
|
||||
public BindableBool Expanded { get; } = new BindableBool(true);
|
||||
|
||||
private Color4 expandedColour;
|
||||
|
||||
@ -67,7 +46,7 @@ namespace osu.Game.Overlays
|
||||
/// Create a new instance.
|
||||
/// </summary>
|
||||
/// <param name="title">The title to be displayed in the header of this group.</param>
|
||||
protected SettingsToolboxGroup(string title)
|
||||
public SettingsToolboxGroup(string title)
|
||||
{
|
||||
AutoSizeAxes = Axes.Y;
|
||||
Width = container_width;
|
||||
@ -115,7 +94,7 @@ namespace osu.Game.Overlays
|
||||
Position = new Vector2(-15, 0),
|
||||
Icon = FontAwesome.Solid.Bars,
|
||||
Scale = new Vector2(0.75f),
|
||||
Action = () => Expanded = !Expanded,
|
||||
Action = () => Expanded.Toggle(),
|
||||
},
|
||||
}
|
||||
},
|
||||
@ -155,23 +134,58 @@ namespace osu.Game.Overlays
|
||||
headerText.FadeTo(headerText.DrawWidth < DrawWidth ? 1 : 0, 150, Easing.OutQuint);
|
||||
}
|
||||
|
||||
[Resolved(canBeNull: true)]
|
||||
private IExpandingContainer expandingContainer { get; set; }
|
||||
|
||||
private bool expandedByContainer;
|
||||
|
||||
protected override void LoadComplete()
|
||||
{
|
||||
base.LoadComplete();
|
||||
|
||||
this.Delay(600).FadeTo(inactive_alpha, fade_duration, Easing.OutQuint);
|
||||
updateExpanded();
|
||||
expandingContainer?.Expanded.BindValueChanged(containerExpanded =>
|
||||
{
|
||||
if (containerExpanded.NewValue && !Expanded.Value)
|
||||
{
|
||||
Expanded.Value = true;
|
||||
expandedByContainer = true;
|
||||
}
|
||||
else if (!containerExpanded.NewValue && expandedByContainer)
|
||||
{
|
||||
Expanded.Value = false;
|
||||
expandedByContainer = false;
|
||||
}
|
||||
|
||||
updateActiveState();
|
||||
}, true);
|
||||
|
||||
Expanded.BindValueChanged(v =>
|
||||
{
|
||||
content.ClearTransforms();
|
||||
|
||||
if (v.NewValue)
|
||||
content.AutoSizeAxes = Axes.Y;
|
||||
else
|
||||
{
|
||||
content.AutoSizeAxes = Axes.None;
|
||||
content.ResizeHeightTo(0, transition_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
button.FadeColour(Expanded.Value ? expandedColour : Color4.White, 200, Easing.InOutQuint);
|
||||
}, true);
|
||||
|
||||
this.Delay(600).Schedule(updateActiveState);
|
||||
}
|
||||
|
||||
protected override bool OnHover(HoverEvent e)
|
||||
{
|
||||
this.FadeIn(fade_duration, Easing.OutQuint);
|
||||
updateActiveState();
|
||||
return false;
|
||||
}
|
||||
|
||||
protected override void OnHoverLost(HoverLostEvent e)
|
||||
{
|
||||
this.FadeTo(inactive_alpha, fade_duration, Easing.OutQuint);
|
||||
updateActiveState();
|
||||
base.OnHoverLost(e);
|
||||
}
|
||||
|
||||
@ -181,7 +195,10 @@ namespace osu.Game.Overlays
|
||||
expandedColour = colours.Yellow;
|
||||
}
|
||||
|
||||
private void updateExpanded() => button.FadeColour(expanded ? expandedColour : Color4.White, 200, Easing.InOutQuint);
|
||||
private void updateActiveState()
|
||||
{
|
||||
this.FadeTo(IsHovered || expandingContainer?.Expanded.Value == true ? 1 : inactive_alpha, fade_duration, Easing.OutQuint);
|
||||
}
|
||||
|
||||
protected override Container<Drawable> Content => content;
|
||||
|
||||
|
Reference in New Issue
Block a user