1
0
mirror of https://github.com/ppy/osu.git synced 2024-11-14 15:57:24 +08:00
osu-lazer/osu.Game/Skinning/FontAdjustableSkinComponent.cs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

43 lines
1.5 KiB
C#
Raw Normal View History

2022-12-04 03:44:54 +08: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.
using osu.Framework.Bindables;
using osu.Framework.Graphics.Containers;
using osu.Framework.Graphics.Sprites;
using osu.Game.Configuration;
using osu.Game.Graphics;
using osu.Game.Localisation.SkinComponents;
2022-12-04 03:44:54 +08:00
namespace osu.Game.Skinning
2022-12-04 03:44:54 +08:00
{
/// <summary>
/// A skin component that contains text and allows the user to choose its font.
2022-12-04 03:44:54 +08:00
/// </summary>
public abstract partial class FontAdjustableSkinComponent : Container, ISerialisableDrawable
2022-12-04 03:44:54 +08:00
{
public bool UsesFixedAnchor { get; set; }
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))]
2022-12-04 04:32:17 +08:00
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Torus);
2022-12-04 03:44:54 +08:00
/// <summary>
/// Implement to apply the user font selection to one or more components.
/// </summary>
2022-12-04 03:44:54 +08:00
protected abstract void SetFont(FontUsage font);
protected override void LoadComplete()
{
base.LoadComplete();
2022-12-04 03:44:54 +08:00
Font.BindValueChanged(e =>
{
// We only have bold weight for venera, so let's force that.
FontWeight fontWeight = e.NewValue == Typeface.Venera ? FontWeight.Bold : FontWeight.Regular;
FontUsage f = OsuFont.GetFont(e.NewValue, weight: fontWeight);
2022-12-04 03:44:54 +08:00
SetFont(f);
}, true);
}
}
}