osu/osu.Game/Overlays/OSD/Toast.cs

88 lines
3.1 KiB
C#
Raw Normal View History

// 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.
using osu.Framework.Graphics;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Shapes;
2019-07-12 06:50:53 +00:00
using osu.Game.Graphics;
using osu.Game.Graphics.Sprites;
using osuTK;
using osuTK.Graphics;
namespace osu.Game.Overlays.OSD
{
2019-07-11 06:15:34 +00:00
public abstract class Toast : Container
{
2019-08-12 10:09:09 +00:00
private const int toast_minimum_width = 240;
private readonly Container content;
protected override Container<Drawable> Content => content;
2019-07-12 18:22:31 +00:00
protected readonly OsuSpriteText ValueText;
2020-11-24 04:43:46 +00:00
protected readonly OsuSpriteText ShortcutText;
2020-11-24 04:43:46 +00:00
protected Toast(string description, string value, string shortcut)
{
Anchor = Anchor.Centre;
Origin = Anchor.Centre;
2019-07-11 06:14:57 +00:00
// A toast's height is decided (and transformed) by the containing OnScreenDisplay.
RelativeSizeAxes = Axes.Y;
2019-08-12 10:09:09 +00:00
AutoSizeAxes = Axes.X;
InternalChildren = new Drawable[]
{
2020-05-05 01:31:11 +00:00
new Container // this container exists just to set a minimum width for the toast
2019-08-12 10:09:09 +00:00
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
Width = toast_minimum_width
},
new Box
{
RelativeSizeAxes = Axes.Both,
Colour = Color4.Black,
Alpha = 0.7f
},
content = new Container
{
Anchor = Anchor.Centre,
Origin = Anchor.Centre,
RelativeSizeAxes = Axes.Both,
2019-07-12 06:50:53 +00:00
},
new OsuSpriteText
{
Padding = new MarginPadding(10),
Name = "Description",
2020-03-16 23:32:25 +00:00
Font = OsuFont.GetFont(size: 14, weight: FontWeight.Bold),
2019-07-12 06:50:53 +00:00
Spacing = new Vector2(1, 0),
Anchor = Anchor.TopCentre,
Origin = Anchor.TopCentre,
Text = description.ToUpperInvariant()
},
2019-07-12 18:22:31 +00:00
ValueText = new OsuSpriteText
2019-07-12 06:50:53 +00:00
{
Font = OsuFont.GetFont(size: 24, weight: FontWeight.Light),
Padding = new MarginPadding { Left = 10, Right = 10 },
Name = "Value",
Anchor = Anchor.Centre,
2019-07-12 18:22:31 +00:00
Origin = Anchor.Centre,
2019-07-12 06:50:53 +00:00
Text = value
},
2020-11-24 04:43:46 +00:00
ShortcutText = new OsuSpriteText
2019-07-12 06:50:53 +00:00
{
Anchor = Anchor.BottomCentre,
Origin = Anchor.BottomCentre,
Name = "Shortcut",
2019-08-10 08:52:37 +00:00
Alpha = 0.3f,
2019-07-12 06:50:53 +00:00
Margin = new MarginPadding { Bottom = 15 },
Font = OsuFont.GetFont(size: 12, weight: FontWeight.Bold),
2020-11-24 04:43:46 +00:00
Text = string.IsNullOrEmpty(shortcut) ? "NO KEY BOUND" : shortcut.ToUpperInvariant()
2019-07-12 06:50:53 +00:00
},
};
}
}
}