1
0
mirror of https://github.com/ppy/osu.git synced 2024-09-22 14:07:25 +08:00
osu-lazer/osu.Game/Overlays/Toolbar/ToolbarButton.cs

176 lines
5.4 KiB
C#
Raw Normal View History

//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;
using osu.Framework.Graphics.Sprites;
using osu.Framework.Graphics.Transformations;
using osu.Framework.Input;
using osu.Game.Graphics;
using osu.Game.Graphics.Backgrounds;
using OpenTK;
using OpenTK.Graphics;
2016-12-01 13:22:29 +08:00
namespace osu.Game.Overlays.Toolbar
{
public class ToolbarButton : Container
{
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;
protected FlowContainer Flow;
public ToolbarButton()
{
Children = new Drawable[]
{
HoverBackground = new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(80, 80, 80, 180),
BlendingMode = BlendingMode.Additive,
Alpha = 0,
},
Flow = new FlowContainer
{
Direction = FlowDirection.HorizontalOnly,
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Padding = new MarginPadding { Left = 15, Right = 15 },
Spacing = new Vector2(5),
RelativeSizeAxes = Axes.Y,
2016-10-22 17:05:46 +08:00
AutoSizeAxes = Axes.X,
Children = new Drawable[]
{
DrawableIcon = new TextAwesome
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
DrawableText = new SpriteText
{
Anchor = Anchor.CentreLeft,
Origin = Anchor.CentreLeft,
},
},
},
tooltipContainer = new FlowContainer
{
Direction = FlowDirection.VerticalOnly,
2016-10-22 17:05:46 +08:00
AutoSizeAxes = Axes.Both,
Anchor = Anchor.BottomLeft,
Position = new Vector2(5, 5),
Alpha = 0,
Children = new[]
{
2016-11-05 07:27:41 +08:00
tooltip1 = new SpriteText
{
2016-11-23 10:35:31 +08:00
Shadow = true,
TextSize = 22,
Font = @"Exo2.0-Bold",
},
tooltip2 = new SpriteText
{
2016-11-23 10:35:31 +08:00
Shadow = true,
TextSize = 16
}
}
}
};
RelativeSizeAxes = Axes.Y;
}
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)
Size = new Vector2(Flow.DrawSize.X, 1);
}
protected override bool OnMouseDown(InputState state, MouseDownEventArgs args) => true;
protected override bool OnClick(InputState state)
{
Action?.Invoke();
HoverBackground.FlashColour(new Color4(255, 255, 255, 180), 800, EasingTypes.OutQuint);
return true;
}
protected override bool OnHover(InputState state)
{
HoverBackground.FadeIn(200);
tooltipContainer.FadeIn(100);
return false;
}
protected override void OnHoverLost(InputState state)
{
HoverBackground.FadeOut(200);
tooltipContainer.FadeOut(100);
}
}
public class OpaqueBackground : Container
{
public OpaqueBackground()
{
RelativeSizeAxes = Axes.Both;
Masking = true;
Children = new Drawable[]
{
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = new Color4(30, 30, 30, 255)
},
new Triangles
{
RelativeSizeAxes = Axes.Both,
Alpha = 0.05f,
},
};
}
}
}