2020-03-24 21:03:38 +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.
|
|
|
|
|
2022-06-17 07:37:17 +00:00
|
|
|
#nullable disable
|
|
|
|
|
2020-03-24 21:03:38 +00:00
|
|
|
using osu.Framework.Allocation;
|
|
|
|
using osu.Framework.Graphics;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Framework.Graphics.Textures;
|
2021-04-21 05:37:11 +00:00
|
|
|
using osu.Framework.Localisation;
|
2020-03-24 21:03:38 +00:00
|
|
|
using osu.Game.Graphics;
|
|
|
|
using osu.Game.Graphics.Sprites;
|
|
|
|
using osuTK;
|
|
|
|
|
|
|
|
namespace osu.Game.Overlays
|
|
|
|
{
|
2020-09-03 06:46:56 +00:00
|
|
|
public abstract partial class OverlayTitle : CompositeDrawable, INamedOverlayComponent
|
2020-03-24 21:03:38 +00:00
|
|
|
{
|
2020-09-17 21:56:08 +00:00
|
|
|
public const float ICON_SIZE = 30;
|
|
|
|
|
2020-09-03 06:46:56 +00:00
|
|
|
private readonly OsuSpriteText titleText;
|
2020-03-24 21:03:38 +00:00
|
|
|
private readonly Container icon;
|
|
|
|
|
2021-04-21 05:37:11 +00:00
|
|
|
private LocalisableString title;
|
2020-09-03 06:46:56 +00:00
|
|
|
|
2021-04-21 05:37:11 +00:00
|
|
|
public LocalisableString Title
|
2020-03-24 21:03:38 +00:00
|
|
|
{
|
2020-09-03 06:46:56 +00:00
|
|
|
get => title;
|
|
|
|
protected set => titleText.Text = title = value;
|
2020-03-24 21:03:38 +00:00
|
|
|
}
|
|
|
|
|
2021-04-21 05:37:11 +00:00
|
|
|
public LocalisableString Description { get; protected set; }
|
2020-09-03 06:46:56 +00:00
|
|
|
|
|
|
|
private string iconTexture;
|
|
|
|
|
|
|
|
public string IconTexture
|
2020-03-24 21:03:38 +00:00
|
|
|
{
|
2020-09-03 06:46:56 +00:00
|
|
|
get => iconTexture;
|
|
|
|
protected set => icon.Child = new OverlayTitleIcon(iconTexture = value);
|
2020-03-24 21:03:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
protected OverlayTitle()
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both;
|
|
|
|
|
|
|
|
InternalChild = new FillFlowContainer
|
|
|
|
{
|
|
|
|
AutoSizeAxes = Axes.Both,
|
|
|
|
Spacing = new Vector2(10, 0),
|
|
|
|
Direction = FillDirection.Horizontal,
|
|
|
|
Children = new Drawable[]
|
|
|
|
{
|
|
|
|
icon = new Container
|
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Margin = new MarginPadding { Horizontal = 5 }, // compensates for osu-web sprites having around 5px of whitespace on each side
|
2020-09-17 21:56:08 +00:00
|
|
|
Size = new Vector2(ICON_SIZE)
|
2020-03-24 21:03:38 +00:00
|
|
|
},
|
2020-09-03 06:46:56 +00:00
|
|
|
titleText = new OsuSpriteText
|
2020-03-24 21:03:38 +00:00
|
|
|
{
|
|
|
|
Anchor = Anchor.Centre,
|
|
|
|
Origin = Anchor.Centre,
|
|
|
|
Font = OsuFont.GetFont(size: 20, weight: FontWeight.Regular),
|
|
|
|
Margin = new MarginPadding { Vertical = 17.5f } // 15px padding + 2.5px line-height difference compensation
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
private partial class OverlayTitleIcon : Sprite
|
|
|
|
{
|
|
|
|
private readonly string textureName;
|
|
|
|
|
|
|
|
public OverlayTitleIcon(string textureName)
|
|
|
|
{
|
|
|
|
this.textureName = textureName;
|
2020-03-24 21:08:20 +00:00
|
|
|
|
2020-03-24 21:03:38 +00:00
|
|
|
RelativeSizeAxes = Axes.Both;
|
|
|
|
Anchor = Anchor.Centre;
|
|
|
|
Origin = Anchor.Centre;
|
|
|
|
FillMode = FillMode.Fit;
|
|
|
|
}
|
|
|
|
|
|
|
|
[BackgroundDependencyLoader]
|
|
|
|
private void load(TextureStore textures)
|
|
|
|
{
|
|
|
|
Texture = textures.Get(textureName);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-03-24 21:08:20 +00:00
|
|
|
}
|