1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 13:27:23 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/Toolbar.cs

153 lines
5.1 KiB
C#
Raw Normal View History

2018-04-13 17:19:50 +08:00
// Copyright (c) 2007-2018 ppy Pty Ltd <contact@ppy.sh>.
// Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
using System;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Colour;
using osu.Framework.Graphics.Containers;
using osu.Game.Graphics;
using OpenTK;
using osu.Framework.Graphics.Shapes;
using osu.Framework.Allocation;
using osu.Framework.Configuration;
2018-07-21 10:38:28 +08:00
using osu.Framework.Input.States;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Toolbar
{
public class Toolbar : OverlayContainer
{
public const float HEIGHT = 40;
public const float TOOLTIP_HEIGHT = 30;
public Action OnHome;
private readonly ToolbarUserArea userArea;
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;
2018-06-06 15:55:16 +08:00
private readonly Bindable<OverlayActivation> overlayActivationMode = new Bindable<OverlayActivation>(OverlayActivation.All);
2018-04-13 17:19:50 +08:00
public Toolbar()
{
Children = new Drawable[]
{
new ToolbarBackground(),
new FillFlowContainer
{
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Children = new Drawable[]
{
new ToolbarSettingsButton(),
new ToolbarHomeButton
{
Action = () => OnHome?.Invoke()
},
2018-07-10 00:20:21 +08:00
new ToolbarRulesetSelector()
2018-04-13 17:19:50 +08:00
}
},
new FillFlowContainer
{
Anchor = Anchor.TopRight,
Origin = Anchor.TopRight,
Direction = FillDirection.Horizontal,
RelativeSizeAxes = Axes.Y,
AutoSizeAxes = Axes.X,
Children = new Drawable[]
{
new ToolbarDirectButton(),
new ToolbarChatButton(),
new ToolbarSocialButton(),
new ToolbarMusicButton(),
//new ToolbarButton
//{
// Icon = FontAwesome.fa_search
//},
userArea = new ToolbarUserArea(),
new ToolbarNotificationButton(),
}
}
};
RelativeSizeAxes = Axes.X;
Size = new Vector2(1, HEIGHT);
}
[BackgroundDependencyLoader(true)]
private void load(OsuGame osuGame)
{
if (osuGame != null)
2018-06-06 15:55:16 +08:00
overlayActivationMode.BindTo(osuGame.OverlayActivationMode);
StateChanged += visibility =>
{
2018-06-06 15:55:16 +08:00
if (overlayActivationMode == OverlayActivation.Disabled)
State = Visibility.Hidden;
};
}
2018-04-13 17:19:50 +08:00
public class ToolbarBackground : Container
{
private readonly Box solidBackground;
private readonly Box gradientBackground;
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,
Colour = 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, Easing.OutQuint);
gradientBackground.FadeIn(transition_time, Easing.OutQuint);
return true;
}
protected override void OnHoverLost(InputState state)
{
solidBackground.FadeTo(alpha_normal, transition_time, Easing.OutQuint);
gradientBackground.FadeOut(transition_time, Easing.OutQuint);
}
}
protected override void PopIn()
{
this.MoveToY(0, transition_time, Easing.OutQuint);
this.FadeIn(transition_time / 2, Easing.OutQuint);
}
protected override void PopOut()
{
userArea?.LoginOverlay.Hide();
this.MoveToY(-DrawSize.Y, transition_time, Easing.OutQuint);
this.FadeOut(transition_time);
}
}
}