2019-01-24 16:43:03 +08:00
|
|
|
|
// 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
|
|
|
|
|
|
2023-12-28 03:06:29 +08:00
|
|
|
|
using osu.Framework.Allocation;
|
2019-06-11 13:28:52 +08:00
|
|
|
|
using osu.Framework.Bindables;
|
2017-03-05 02:42:37 +08:00
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
2016-12-02 17:43:01 +08:00
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2017-06-20 13:54:23 +08:00
|
|
|
|
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
|
|
|
|
|
2016-12-02 17:43:01 +08:00
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
|
{
|
2017-11-21 10:49:42 +08:00
|
|
|
|
public partial class ToolbarOverlayToggleButton : ToolbarButton
|
2016-12-02 17:43:01 +08:00
|
|
|
|
{
|
2023-12-28 03:06:29 +08:00
|
|
|
|
private Box stateBackground;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2016-12-02 17:43:01 +08:00
|
|
|
|
private OverlayContainer stateContainer;
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-11 13:28:52 +08:00
|
|
|
|
private readonly Bindable<Visibility> overlayState = new Bindable<Visibility>();
|
|
|
|
|
|
2016-12-02 17:43:01 +08:00
|
|
|
|
public OverlayContainer StateContainer
|
|
|
|
|
{
|
2019-02-28 12:58:19 +08:00
|
|
|
|
get => stateContainer;
|
2016-12-02 17:43:01 +08:00
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
stateContainer = value;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2019-06-11 13:28:52 +08:00
|
|
|
|
overlayState.UnbindBindings();
|
|
|
|
|
|
2017-12-26 00:12:46 +08:00
|
|
|
|
if (stateContainer != null)
|
|
|
|
|
{
|
|
|
|
|
Action = stateContainer.ToggleVisibility;
|
2019-06-11 13:28:52 +08:00
|
|
|
|
overlayState.BindTo(stateContainer.State);
|
2017-12-26 00:12:46 +08:00
|
|
|
|
}
|
2020-09-03 14:46:56 +08:00
|
|
|
|
|
|
|
|
|
if (stateContainer is INamedOverlayComponent named)
|
|
|
|
|
{
|
|
|
|
|
TooltipMain = named.Title;
|
|
|
|
|
TooltipSub = named.Description;
|
2023-11-24 12:16:04 +08:00
|
|
|
|
SetIcon(named.Icon);
|
2020-09-03 14:46:56 +08:00
|
|
|
|
}
|
2016-12-02 17:43:01 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2023-12-28 03:06:29 +08:00
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
|
private void load(OsuColour colours)
|
2016-12-02 17:43:01 +08:00
|
|
|
|
{
|
2023-12-28 02:43:38 +08:00
|
|
|
|
BackgroundContent.Add(stateBackground = new Box
|
2016-12-02 17:43:01 +08:00
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2023-12-28 03:06:29 +08:00
|
|
|
|
Colour = colours.Carmine.Opacity(180),
|
2019-08-21 12:29:50 +08:00
|
|
|
|
Blending = BlendingParameters.Additive,
|
2016-12-02 17:43:01 +08:00
|
|
|
|
Depth = 2,
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
});
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-11 13:28:52 +08:00
|
|
|
|
overlayState.ValueChanged += stateChanged;
|
2016-12-02 17:43:01 +08:00
|
|
|
|
}
|
2018-04-13 17:19:50 +08:00
|
|
|
|
|
2019-06-11 13:28:52 +08:00
|
|
|
|
private void stateChanged(ValueChangedEvent<Visibility> state)
|
2016-12-02 17:43:01 +08:00
|
|
|
|
{
|
2019-06-11 13:28:52 +08:00
|
|
|
|
switch (state.NewValue)
|
2016-12-02 17:43:01 +08:00
|
|
|
|
{
|
|
|
|
|
case Visibility.Hidden:
|
2017-02-07 15:15:45 +08:00
|
|
|
|
stateBackground.FadeOut(200);
|
2016-12-02 17:43:01 +08:00
|
|
|
|
break;
|
2019-04-01 11:16:05 +08:00
|
|
|
|
|
2016-12-02 17:43:01 +08:00
|
|
|
|
case Visibility.Visible:
|
2017-02-07 15:15:45 +08:00
|
|
|
|
stateBackground.FadeIn(200);
|
2016-12-02 17:43:01 +08:00
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|