1
0
mirror of https://github.com/ppy/osu.git synced 2024-12-20 18:32:58 +08:00
osu-lazer/osu.Game/Skinning/FontAdjustableSkinComponent.cs
Dean Herbert 92306b9123 Combine localisations for abstract skinnable components into a single file
Generally we don't want localisation files with only one to two
translations. It makes it harder for translators to handle in crowdin (a
lot of file changes for small results).

So for cases like this I believe we should be grouping translations
where it makes sense.

I've left individual components in their own files as I can see
potential for more settings to be added in the future. Plus it gives a
bit of extra context.
2023-02-03 16:02:18 +09:00

43 lines
1.5 KiB
C#

// 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;
namespace osu.Game.Skinning
{
/// <summary>
/// A skin component that contains text and allows the user to choose its font.
/// </summary>
public abstract partial class FontAdjustableSkinComponent : Container, ISkinnableDrawable
{
public bool UsesFixedAnchor { get; set; }
[SettingSource(typeof(SkinnableComponentStrings), nameof(SkinnableComponentStrings.Font), nameof(SkinnableComponentStrings.FontDescription))]
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Torus);
/// <summary>
/// Implement to apply the user font selection to one or more components.
/// </summary>
protected abstract void SetFont(FontUsage font);
protected override void LoadComplete()
{
base.LoadComplete();
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);
SetFont(f);
}, true);
}
}
}