1
0
mirror of https://github.com/ppy/osu.git synced 2025-03-06 14:37:21 +08:00

137 lines
4.7 KiB
C#
Raw Normal View History

// Copyright (c) 2007-2017 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
2016-09-30 18:45:27 +09:00
2016-10-13 22:57:05 +08:00
using System;
using osu.Framework.Extensions.Color4Extensions;
2016-09-30 18:45:27 +09:00
using osu.Framework.Graphics;
2016-12-01 14:22:29 +09:00
using osu.Framework.Graphics.Colour;
2016-09-30 18:45:27 +09:00
using osu.Framework.Graphics.Containers;
2016-12-01 14:22:29 +09:00
using osu.Framework.Input;
2016-10-13 22:57:05 +08:00
using osu.Game.Graphics;
2016-12-01 14:22:29 +09:00
using OpenTK;
using osu.Framework.Graphics.Shapes;
2016-09-30 18:45:27 +09:00
2016-12-01 14:22:29 +09:00
namespace osu.Game.Overlays.Toolbar
2016-09-30 18:45:27 +09:00
{
public class Toolbar : OverlayContainer
2016-09-30 18:45:27 +09:00
{
public const float HEIGHT = 40;
2017-02-10 16:26:43 +09:00
public const float TOOLTIP_HEIGHT = 30;
public Action OnHome;
private readonly ToolbarUserArea userArea;
2016-09-30 18:45:27 +09:00
protected override bool HideOnEscape => false;
2017-04-18 15:34:53 +09:00
protected override bool BlockPassThroughMouse => false;
private const double transition_time = 500;
private const float alpha_hovering = 0.8f;
private const float alpha_normal = 0.6f;
2016-11-01 23:24:14 +09:00
public Toolbar()
2016-09-30 18:45:27 +09:00
{
Children = new Drawable[]
{
2017-01-30 23:24:30 +09:00
new ToolbarBackground(),
2017-03-01 19:33:01 +01:00
new FillFlowContainer
2016-10-03 20:39:32 +09:00
{
2017-03-04 11:00:17 +01:00
Direction = FillDirection.Horizontal,
2016-10-03 20:39:32 +09:00
RelativeSizeAxes = Axes.Y,
2016-10-22 18:05:46 +09:00
AutoSizeAxes = Axes.X,
Children = new Drawable[]
2016-10-03 20:39:32 +09:00
{
new ToolbarSettingsButton(),
2017-03-07 10:59:19 +09:00
new ToolbarHomeButton
{
2016-11-04 12:27:43 +09:00
Action = () => OnHome?.Invoke()
},
2017-04-21 16:11:24 +09:00
new ToolbarModeSelector()
2016-10-03 20:39:32 +09:00
}
},
new FillFlowContainer
2016-10-03 20:39:32 +09:00
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
2017-03-04 11:00:17 +01:00
Direction = FillDirection.Horizontal,
2016-10-03 20:39:32 +09:00
RelativeSizeAxes = Axes.Y,
2016-10-22 18:05:46 +09:00
AutoSizeAxes = Axes.X,
2017-01-31 16:59:38 +09:00
Children = new Drawable[]
2016-10-03 20:39:32 +09:00
{
new ToolbarSocialButton(),
2017-04-19 19:54:03 +09:00
new ToolbarChatButton(),
new ToolbarMusicButton(),
new ToolbarButton
{
2016-11-07 17:58:32 +09:00
Icon = FontAwesome.fa_search
},
userArea = new ToolbarUserArea(),
2017-02-10 16:26:43 +09:00
new ToolbarNotificationButton(),
2016-10-03 20:39:32 +09:00
}
2016-09-30 18:45:27 +09:00
}
};
2016-11-01 23:24:14 +09:00
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, HEIGHT);
2016-11-01 23:24:14 +09:00
}
2017-01-30 23:24:30 +09:00
public class ToolbarBackground : Container
{
private readonly Box solidBackground;
private readonly Box gradientBackground;
2017-01-30 23:24:30 +09:00
public ToolbarBackground()
{
RelativeSizeAxes = Axes.Both;
Children = new Drawable[]
{
solidBackground = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = OsuColour.Gray(0.1f),
Alpha = alpha_normal,
},
gradientBackground = new Box
{
RelativeSizeAxes = Axes.X,
Anchor = Anchor.BottomLeft,
Alpha = 0,
Height = 90,
ColourInfo = ColourInfo.GradientVertical(
OsuColour.Gray(0.1f).Opacity(0.5f), OsuColour.Gray(0.1f).Opacity(0)),
},
};
}
protected override bool OnHover(InputState state)
{
solidBackground.FadeTo(alpha_hovering, transition_time, EasingTypes.OutQuint);
gradientBackground.FadeIn(transition_time, EasingTypes.OutQuint);
return true;
}
protected override void OnHoverLost(InputState state)
{
solidBackground.FadeTo(alpha_normal, transition_time, EasingTypes.OutQuint);
gradientBackground.FadeOut(transition_time, EasingTypes.OutQuint);
}
}
protected override void PopIn()
{
this.MoveToY(0, transition_time, EasingTypes.OutQuint);
this.FadeIn(transition_time / 2, EasingTypes.OutQuint);
}
protected override void PopOut()
{
userArea?.LoginOverlay.Hide();
this.MoveToY(-DrawSize.Y, transition_time, EasingTypes.OutQuint);
this.FadeOut(transition_time);
}
2016-09-30 18:45:27 +09:00
}
}