2017-02-07 12:59:30 +08:00
|
|
|
|
// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
2016-12-06 17:56:20 +08:00
|
|
|
|
|
2017-07-14 16:57:01 +08:00
|
|
|
|
using System.Linq;
|
2017-07-13 15:55:48 +08:00
|
|
|
|
using osu.Framework;
|
2016-11-05 07:27:41 +08:00
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2016-11-08 07:04:49 +08:00
|
|
|
|
using osu.Framework.Input;
|
2016-11-09 12:16:04 +08:00
|
|
|
|
using osu.Framework.Threading;
|
2017-02-08 19:14:17 +08:00
|
|
|
|
using osu.Game.Overlays.Toolbar;
|
2016-11-05 07:27:41 +08:00
|
|
|
|
|
2017-05-15 09:55:29 +08:00
|
|
|
|
namespace osu.Game.Overlays.Settings
|
2016-11-05 07:27:41 +08:00
|
|
|
|
{
|
2017-08-14 13:40:48 +08:00
|
|
|
|
public class Sidebar : Container<SidebarButton>, IStateful<ExpandedState>
|
2016-11-05 07:27:41 +08:00
|
|
|
|
{
|
2017-08-14 13:40:48 +08:00
|
|
|
|
private readonly FillFlowContainer<SidebarButton> content;
|
2017-02-08 19:14:17 +08:00
|
|
|
|
internal const float DEFAULT_WIDTH = ToolbarButton.WIDTH;
|
2017-02-07 15:15:45 +08:00
|
|
|
|
internal const int EXPANDED_WIDTH = 200;
|
2017-08-14 13:40:48 +08:00
|
|
|
|
protected override Container<SidebarButton> Content => content;
|
2016-11-08 07:04:49 +08:00
|
|
|
|
|
2017-01-31 18:58:38 +08:00
|
|
|
|
public Sidebar()
|
2016-11-05 07:27:41 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
2016-11-08 07:04:49 +08:00
|
|
|
|
InternalChildren = new Drawable[]
|
2016-11-05 07:27:41 +08:00
|
|
|
|
{
|
2016-11-08 19:07:28 +08:00
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
Colour = Color4.Black,
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
},
|
2016-11-08 18:16:39 +08:00
|
|
|
|
new SidebarScrollContainer
|
2016-11-05 07:27:41 +08:00
|
|
|
|
{
|
2017-06-08 15:27:35 +08:00
|
|
|
|
Children = new[]
|
2016-11-08 18:16:39 +08:00
|
|
|
|
{
|
2017-08-14 13:40:48 +08:00
|
|
|
|
content = new FillFlowContainer<SidebarButton>
|
2016-11-08 18:16:39 +08:00
|
|
|
|
{
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
AutoSizeAxes = Axes.Y,
|
|
|
|
|
RelativeSizeAxes = Axes.X,
|
2017-03-04 18:00:17 +08:00
|
|
|
|
Direction = FillDirection.Vertical,
|
2016-11-08 18:16:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2016-11-05 07:27:41 +08:00
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-09 12:16:04 +08:00
|
|
|
|
private ScheduledDelegate expandEvent;
|
2017-07-13 15:55:48 +08:00
|
|
|
|
private ExpandedState state;
|
2017-04-06 16:21:18 +08:00
|
|
|
|
|
2016-11-09 12:16:04 +08:00
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
2017-07-13 15:55:48 +08:00
|
|
|
|
queueExpandIfHovering();
|
2016-11-09 12:16:04 +08:00
|
|
|
|
return true;
|
|
|
|
|
}
|
2017-04-06 16:21:18 +08:00
|
|
|
|
|
2016-11-09 12:16:04 +08:00
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
expandEvent?.Cancel();
|
2017-07-14 16:57:01 +08:00
|
|
|
|
lastHoveredButton = null;
|
2017-07-13 15:55:48 +08:00
|
|
|
|
State = ExpandedState.Contracted;
|
2017-07-14 16:57:01 +08:00
|
|
|
|
|
2016-11-09 12:16:04 +08:00
|
|
|
|
base.OnHoverLost(state);
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-14 16:57:01 +08:00
|
|
|
|
protected override bool OnMouseMove(InputState state)
|
|
|
|
|
{
|
|
|
|
|
queueExpandIfHovering();
|
|
|
|
|
return base.OnMouseMove(state);
|
|
|
|
|
}
|
|
|
|
|
|
2016-11-08 18:16:39 +08:00
|
|
|
|
private class SidebarScrollContainer : ScrollContainer
|
|
|
|
|
{
|
|
|
|
|
public SidebarScrollContainer()
|
|
|
|
|
{
|
|
|
|
|
Content.Anchor = Anchor.CentreLeft;
|
|
|
|
|
Content.Origin = Anchor.CentreLeft;
|
2017-02-18 21:29:20 +08:00
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
2016-11-08 18:16:39 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2017-07-13 15:55:48 +08:00
|
|
|
|
|
|
|
|
|
public ExpandedState State
|
|
|
|
|
{
|
|
|
|
|
get { return state; }
|
|
|
|
|
set
|
|
|
|
|
{
|
2017-08-16 15:59:16 +08:00
|
|
|
|
expandEvent?.Cancel();
|
|
|
|
|
|
2017-07-13 15:55:48 +08:00
|
|
|
|
if (state == value) return;
|
|
|
|
|
|
|
|
|
|
state = value;
|
|
|
|
|
|
|
|
|
|
switch (state)
|
|
|
|
|
{
|
|
|
|
|
default:
|
2017-07-23 02:50:25 +08:00
|
|
|
|
this.ResizeTo(new Vector2(DEFAULT_WIDTH, Height), 500, Easing.OutQuint);
|
2017-07-13 15:55:48 +08:00
|
|
|
|
break;
|
|
|
|
|
case ExpandedState.Expanded:
|
2017-07-23 02:50:25 +08:00
|
|
|
|
this.ResizeTo(new Vector2(EXPANDED_WIDTH, Height), 500, Easing.OutQuint);
|
2017-07-13 15:55:48 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2017-07-14 16:57:01 +08:00
|
|
|
|
private Drawable lastHoveredButton;
|
|
|
|
|
|
|
|
|
|
private Drawable hoveredButton => content.Children.FirstOrDefault(c => c.IsHovered);
|
|
|
|
|
|
2017-07-13 15:55:48 +08:00
|
|
|
|
private void queueExpandIfHovering()
|
|
|
|
|
{
|
2017-07-14 16:57:01 +08:00
|
|
|
|
// only expand when we hover a different button.
|
|
|
|
|
if (lastHoveredButton == hoveredButton) return;
|
|
|
|
|
|
|
|
|
|
if (!IsHovered) return;
|
|
|
|
|
|
|
|
|
|
if (State != ExpandedState.Expanded)
|
2017-07-13 15:55:48 +08:00
|
|
|
|
{
|
|
|
|
|
expandEvent?.Cancel();
|
|
|
|
|
expandEvent = Scheduler.AddDelayed(() => State = ExpandedState.Expanded, 750);
|
|
|
|
|
}
|
2017-07-14 16:57:01 +08:00
|
|
|
|
|
|
|
|
|
lastHoveredButton = hoveredButton;
|
2017-07-13 15:55:48 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public enum ExpandedState
|
|
|
|
|
{
|
|
|
|
|
Contracted,
|
|
|
|
|
Expanded,
|
2016-11-05 07:27:41 +08:00
|
|
|
|
}
|
|
|
|
|
}
|