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
|
|
|
|
|
|
|
|
|
using osu.Framework.Extensions.Color4Extensions;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2019-04-02 05:51:28 +00:00
|
|
|
|
using osu.Framework.Graphics.Effects;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using osu.Game.Graphics.Backgrounds;
|
|
|
|
|
using osu.Game.Graphics.Sprites;
|
2018-11-20 07:51:59 +00:00
|
|
|
|
using osuTK;
|
|
|
|
|
using osuTK.Graphics;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Framework.Graphics.Shapes;
|
2018-10-02 03:02:47 +00:00
|
|
|
|
using osu.Framework.Input.Events;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
using osu.Game.Graphics.Containers;
|
|
|
|
|
using osu.Game.Graphics.UserInterface;
|
|
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
|
|
|
|
{
|
|
|
|
|
public class ToolbarButton : OsuClickableContainer
|
|
|
|
|
{
|
|
|
|
|
public const float WIDTH = Toolbar.HEIGHT * 1.4f;
|
|
|
|
|
|
|
|
|
|
public void SetIcon(Drawable icon)
|
|
|
|
|
{
|
|
|
|
|
IconContainer.Icon = icon;
|
|
|
|
|
IconContainer.Show();
|
|
|
|
|
}
|
|
|
|
|
|
2019-03-27 10:29:27 +00:00
|
|
|
|
public void SetIcon(IconUsage icon) => SetIcon(new SpriteIcon
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Size = new Vector2(20),
|
|
|
|
|
Icon = icon
|
|
|
|
|
});
|
|
|
|
|
|
2019-03-27 10:29:27 +00:00
|
|
|
|
public IconUsage Icon
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
set => SetIcon(value);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => DrawableText.Text;
|
|
|
|
|
set => DrawableText.Text = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TooltipMain
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => tooltip1.Text;
|
|
|
|
|
set => tooltip1.Text = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TooltipSub
|
|
|
|
|
{
|
2019-02-28 04:58:19 +00:00
|
|
|
|
get => tooltip2.Text;
|
|
|
|
|
set => tooltip2.Text = value;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected virtual Anchor TooltipAnchor => Anchor.TopLeft;
|
|
|
|
|
|
|
|
|
|
protected ConstrainedIconContainer IconContainer;
|
|
|
|
|
protected SpriteText DrawableText;
|
|
|
|
|
protected Box HoverBackground;
|
|
|
|
|
private readonly FillFlowContainer tooltipContainer;
|
|
|
|
|
private readonly SpriteText tooltip1;
|
|
|
|
|
private readonly SpriteText tooltip2;
|
|
|
|
|
protected FillFlowContainer Flow;
|
|
|
|
|
|
2019-02-28 04:31:40 +00:00
|
|
|
|
public ToolbarButton()
|
|
|
|
|
: base(HoverSampleSet.Loud)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
Width = WIDTH;
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
HoverBackground = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = OsuColour.Gray(80).Opacity(180),
|
2019-08-21 04:29:50 +00:00
|
|
|
|
Blending = BlendingParameters.Additive,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
|
|
|
|
Flow = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
|
Spacing = new Vector2(5),
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Padding = new MarginPadding { Left = Toolbar.HEIGHT / 2, Right = Toolbar.HEIGHT / 2 },
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
|
|
|
|
AutoSizeAxes = Axes.X,
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
IconContainer = new ConstrainedIconContainer
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
Size = new Vector2(20),
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
|
|
|
|
DrawableText = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
tooltipContainer = new FillFlowContainer
|
|
|
|
|
{
|
|
|
|
|
Direction = FillDirection.Vertical,
|
|
|
|
|
RelativeSizeAxes = Axes.Both, //stops us being considered in parent's autosize
|
2018-07-16 07:17:22 +00:00
|
|
|
|
Anchor = TooltipAnchor.HasFlag(Anchor.x0) ? Anchor.BottomLeft : Anchor.BottomRight,
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Origin = TooltipAnchor,
|
2018-07-16 07:17:22 +00:00
|
|
|
|
Position = new Vector2(TooltipAnchor.HasFlag(Anchor.x0) ? 5 : -5, 5),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
Children = new[]
|
|
|
|
|
{
|
|
|
|
|
tooltip1 = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = TooltipAnchor,
|
|
|
|
|
Origin = TooltipAnchor,
|
|
|
|
|
Shadow = true,
|
2019-02-12 04:04:46 +00:00
|
|
|
|
Font = OsuFont.GetFont(size: 22, weight: FontWeight.Bold),
|
2018-04-13 09:19:50 +00:00
|
|
|
|
},
|
|
|
|
|
tooltip2 = new OsuSpriteText
|
|
|
|
|
{
|
|
|
|
|
Anchor = TooltipAnchor,
|
|
|
|
|
Origin = TooltipAnchor,
|
|
|
|
|
Shadow = true,
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnMouseDown(MouseDownEvent e) => true;
|
2018-04-13 09:19:50 +00:00
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnClick(ClickEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
HoverBackground.FlashColour(Color4.White.Opacity(100), 500, Easing.OutQuint);
|
2019-02-28 23:43:04 +00:00
|
|
|
|
tooltipContainer.FadeOut(100);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnClick(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override bool OnHover(HoverEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
HoverBackground.FadeIn(200);
|
|
|
|
|
tooltipContainer.FadeIn(100);
|
2018-10-02 03:02:47 +00:00
|
|
|
|
return base.OnHover(e);
|
2018-04-13 09:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2018-10-02 03:02:47 +00:00
|
|
|
|
protected override void OnHoverLost(HoverLostEvent e)
|
2018-04-13 09:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
HoverBackground.FadeOut(200);
|
|
|
|
|
tooltipContainer.FadeOut(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class OpaqueBackground : Container
|
|
|
|
|
{
|
|
|
|
|
public OpaqueBackground()
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
|
Masking = true;
|
|
|
|
|
MaskingSmoothness = 0;
|
|
|
|
|
EdgeEffect = new EdgeEffectParameters
|
|
|
|
|
{
|
|
|
|
|
Type = EdgeEffectType.Shadow,
|
|
|
|
|
Colour = Color4.Black.Opacity(40),
|
|
|
|
|
Radius = 5,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
Children = new Drawable[]
|
|
|
|
|
{
|
|
|
|
|
new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
Colour = OsuColour.Gray(30)
|
|
|
|
|
},
|
|
|
|
|
new Triangles
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
|
|
|
|
ColourLight = OsuColour.Gray(40),
|
|
|
|
|
ColourDark = OsuColour.Gray(20),
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|