2016-10-04 18:41:18 +08:00
|
|
|
|
//Copyright (c) 2007-2016 ppy Pty Ltd <contact@ppy.sh>.
|
|
|
|
|
//Licensed under the MIT Licence - https://raw.githubusercontent.com/ppy/osu/master/LICENCE
|
|
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
|
using osu.Framework.Graphics.Containers;
|
2016-12-01 13:22:29 +08:00
|
|
|
|
using osu.Framework.Graphics.Primitives;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
|
using osu.Framework.Input;
|
|
|
|
|
using osu.Game.Graphics;
|
|
|
|
|
using OpenTK;
|
|
|
|
|
using OpenTK.Graphics;
|
|
|
|
|
|
2016-12-01 13:22:29 +08:00
|
|
|
|
namespace osu.Game.Overlays.Toolbar
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
public class ToolbarButton : Container
|
|
|
|
|
{
|
|
|
|
|
public const float WIDTH = 60;
|
|
|
|
|
|
|
|
|
|
public FontAwesome Icon
|
|
|
|
|
{
|
|
|
|
|
get { return DrawableIcon.Icon; }
|
|
|
|
|
set { DrawableIcon.Icon = value; }
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string Text
|
|
|
|
|
{
|
|
|
|
|
get { return DrawableText.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
DrawableText.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TooltipMain
|
|
|
|
|
{
|
|
|
|
|
get { return tooltip1.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
tooltip1.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public string TooltipSub
|
|
|
|
|
{
|
|
|
|
|
get { return tooltip2.Text; }
|
|
|
|
|
set
|
|
|
|
|
{
|
|
|
|
|
tooltip2.Text = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Action Action;
|
|
|
|
|
protected TextAwesome DrawableIcon;
|
|
|
|
|
protected SpriteText DrawableText;
|
|
|
|
|
protected Box HoverBackground;
|
|
|
|
|
private FlowContainer tooltipContainer;
|
|
|
|
|
private SpriteText tooltip1;
|
|
|
|
|
private SpriteText tooltip2;
|
|
|
|
|
|
|
|
|
|
public ToolbarButton()
|
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
HoverBackground = new Box
|
|
|
|
|
{
|
|
|
|
|
RelativeSizeAxes = Axes.Both,
|
2016-11-05 17:15:37 +08:00
|
|
|
|
BlendingMode = BlendingMode.Additive,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Colour = new Color4(60, 60, 60, 255),
|
|
|
|
|
Alpha = 0,
|
|
|
|
|
},
|
|
|
|
|
new FlowContainer
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Direction = FlowDirection.HorizontalOnly,
|
|
|
|
|
Anchor = Anchor.TopCentre,
|
|
|
|
|
Origin = Anchor.TopCentre,
|
|
|
|
|
Padding = new MarginPadding { Left = 5, Right = 5 },
|
|
|
|
|
RelativeSizeAxes = Axes.Y,
|
2016-10-22 17:05:46 +08:00
|
|
|
|
AutoSizeAxes = Axes.X,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Children = new Drawable[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-10-12 11:22:19 +08:00
|
|
|
|
DrawableIcon = new TextAwesome
|
|
|
|
|
{
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
|
|
|
|
DrawableText = new SpriteText
|
|
|
|
|
{
|
|
|
|
|
Margin = new MarginPadding { Left = 5 },
|
|
|
|
|
Anchor = Anchor.CentreLeft,
|
|
|
|
|
Origin = Anchor.CentreLeft,
|
|
|
|
|
},
|
2016-10-04 18:41:18 +08:00
|
|
|
|
},
|
2016-10-12 11:22:19 +08:00
|
|
|
|
},
|
|
|
|
|
tooltipContainer = new FlowContainer
|
|
|
|
|
{
|
|
|
|
|
Direction = FlowDirection.VerticalOnly,
|
2016-10-22 17:05:46 +08:00
|
|
|
|
AutoSizeAxes = Axes.Both,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Anchor = Anchor.BottomLeft,
|
2016-11-15 00:22:20 +08:00
|
|
|
|
Position = new Vector2(5, 5),
|
2016-10-12 11:22:19 +08:00
|
|
|
|
Alpha = 0,
|
|
|
|
|
Children = new[]
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
2016-11-05 07:27:41 +08:00
|
|
|
|
tooltip1 = new SpriteText
|
2016-10-12 11:22:19 +08:00
|
|
|
|
{
|
2016-11-23 10:35:31 +08:00
|
|
|
|
Shadow = true,
|
2016-10-12 11:22:19 +08:00
|
|
|
|
TextSize = 22,
|
2016-11-09 14:16:34 +08:00
|
|
|
|
Font = @"Exo2.0-Bold",
|
2016-10-12 11:22:19 +08:00
|
|
|
|
},
|
|
|
|
|
tooltip2 = new SpriteText
|
|
|
|
|
{
|
2016-11-23 10:35:31 +08:00
|
|
|
|
Shadow = true,
|
2016-11-09 14:16:34 +08:00
|
|
|
|
TextSize = 16
|
2016-10-12 11:22:19 +08:00
|
|
|
|
}
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
RelativeSizeAxes = Axes.Y;
|
|
|
|
|
Size = new Vector2(WIDTH, 1);
|
|
|
|
|
}
|
|
|
|
|
|
2016-10-05 17:16:16 +08:00
|
|
|
|
protected override void Update()
|
|
|
|
|
{
|
|
|
|
|
base.Update();
|
|
|
|
|
|
|
|
|
|
//todo: find a way to avoid using this (autosize needs to be able to ignore certain drawables.. in this case the tooltip)
|
2016-10-19 00:53:31 +08:00
|
|
|
|
Size = new Vector2(WIDTH + (DrawableText.IsVisible ? DrawableText.DrawSize.X : 0), 1);
|
2016-10-05 17:16:16 +08:00
|
|
|
|
}
|
|
|
|
|
|
2016-11-15 19:35:17 +08:00
|
|
|
|
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
|
|
|
|
|
|
2016-11-15 14:31:48 +08:00
|
|
|
|
protected override bool OnClick(InputState state)
|
2016-10-04 18:41:18 +08:00
|
|
|
|
{
|
|
|
|
|
Action?.Invoke();
|
|
|
|
|
HoverBackground.FlashColour(Color4.White, 400);
|
2016-10-04 19:00:55 +08:00
|
|
|
|
return true;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override bool OnHover(InputState state)
|
|
|
|
|
{
|
|
|
|
|
HoverBackground.FadeTo(0.4f, 200);
|
|
|
|
|
tooltipContainer.FadeIn(100);
|
2016-11-15 15:25:41 +08:00
|
|
|
|
return false;
|
2016-10-04 18:41:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnHoverLost(InputState state)
|
|
|
|
|
{
|
|
|
|
|
HoverBackground.FadeTo(0, 200);
|
|
|
|
|
tooltipContainer.FadeOut(100);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|