1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-15 15:57:51 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/ToolbarOverlayToggleButton.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

78 lines
2.2 KiB
C#
Raw Normal View History

// 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.
2018-04-13 17:19:50 +08:00
2022-06-17 15:37:17 +08:00
#nullable disable
using osu.Framework.Allocation;
using osu.Framework.Bindables;
using osu.Framework.Extensions.Color4Extensions;
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2017-01-11 02:44:40 +08:00
using osu.Game.Graphics;
2018-04-13 17:19:50 +08:00
namespace osu.Game.Overlays.Toolbar
{
public partial class ToolbarOverlayToggleButton : ToolbarButton
{
private Box stateBackground;
2018-04-13 17:19:50 +08:00
private OverlayContainer stateContainer;
2018-04-13 17:19:50 +08:00
private readonly Bindable<Visibility> overlayState = new Bindable<Visibility>();
public OverlayContainer StateContainer
{
get => stateContainer;
set
{
stateContainer = value;
2019-04-01 11:16:05 +08:00
overlayState.UnbindBindings();
if (stateContainer != null)
{
Action = stateContainer.ToggleVisibility;
overlayState.BindTo(stateContainer.State);
}
if (stateContainer is INamedOverlayComponent named)
{
TooltipMain = named.Title;
TooltipSub = named.Description;
SetIcon(named.Icon);
}
}
}
2018-04-13 17:19:50 +08:00
[BackgroundDependencyLoader]
private void load(OsuColour colours)
{
BackgroundContent.Add(stateBackground = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = colours.Carmine.Opacity(180),
2019-08-21 12:29:50 +08:00
Blending = BlendingParameters.Additive,
Depth = float.MaxValue,
Alpha = 0,
});
2018-04-13 17:19:50 +08:00
overlayState.ValueChanged += stateChanged;
}
2018-04-13 17:19:50 +08:00
private void stateChanged(ValueChangedEvent<Visibility> state)
{
switch (state.NewValue)
{
case Visibility.Hidden:
stateBackground.FadeOut(200, Easing.OutQuint);
break;
2019-04-01 11:16:05 +08:00
case Visibility.Visible:
stateBackground.FadeIn(200, Easing.OutQuint);
break;
}
}
}
}