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;
|
2023-02-03 14:34:57 +08:00
|
|
|
using osu.Game.Localisation.SkinComponents;
|
2022-12-04 03:44:54 +08:00
|
|
|
|
2023-01-26 15:04:56 +08:00
|
|
|
namespace osu.Game.Skinning
|
2022-12-04 03:44:54 +08:00
|
|
|
{
|
|
|
|
/// <summary>
|
2023-01-26 15:05:07 +08:00
|
|
|
/// A skin component that contains text and allows the user to choose its font.
|
2022-12-04 03:44:54 +08:00
|
|
|
/// </summary>
|
2023-01-26 15:04:56 +08:00
|
|
|
public abstract partial class FontAdjustableSkinComponent : Container, ISkinnableDrawable
|
2022-12-04 03:44:54 +08:00
|
|
|
{
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
2023-02-03 15:02:16 +08:00
|
|
|
[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
|
|
|
|
2023-01-26 15:05:07 +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();
|
2023-01-26 15:05:07 +08:00
|
|
|
|
2022-12-04 03:44:54 +08:00
|
|
|
Font.BindValueChanged(e =>
|
|
|
|
{
|
2023-01-26 15:05:07 +08:00
|
|
|
// 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|