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