2022-12-03 19:44:54 +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.
|
|
|
|
|
|
|
|
using osu.Framework.Bindables;
|
|
|
|
using osu.Framework.Graphics.Containers;
|
|
|
|
using osu.Framework.Graphics.Sprites;
|
|
|
|
using osu.Game.Configuration;
|
|
|
|
using osu.Game.Graphics;
|
2023-02-02 00:46:14 +00:00
|
|
|
using osu.Game.Localisation;
|
2022-12-03 19:44:54 +00:00
|
|
|
|
2023-01-26 07:04:56 +00:00
|
|
|
namespace osu.Game.Skinning
|
2022-12-03 19:44:54 +00:00
|
|
|
{
|
|
|
|
/// <summary>
|
2023-01-26 07:05:07 +00:00
|
|
|
/// A skin component that contains text and allows the user to choose its font.
|
2022-12-03 19:44:54 +00:00
|
|
|
/// </summary>
|
2023-01-26 07:04:56 +00:00
|
|
|
public abstract partial class FontAdjustableSkinComponent : Container, ISkinnableDrawable
|
2022-12-03 19:44:54 +00:00
|
|
|
{
|
|
|
|
public bool UsesFixedAnchor { get; set; }
|
|
|
|
|
2023-02-01 23:44:00 +00:00
|
|
|
[SettingSource(typeof(FontAdjustableSkinComponentStrings), nameof(FontAdjustableSkinComponentStrings.Font), nameof(FontAdjustableSkinComponentStrings.FontDescription))]
|
2022-12-03 20:32:17 +00:00
|
|
|
public Bindable<Typeface> Font { get; } = new Bindable<Typeface>(Typeface.Torus);
|
2022-12-03 19:44:54 +00:00
|
|
|
|
2023-01-26 07:05:07 +00:00
|
|
|
/// <summary>
|
|
|
|
/// Implement to apply the user font selection to one or more components.
|
|
|
|
/// </summary>
|
2022-12-03 19:44:54 +00:00
|
|
|
protected abstract void SetFont(FontUsage font);
|
|
|
|
|
|
|
|
protected override void LoadComplete()
|
|
|
|
{
|
|
|
|
base.LoadComplete();
|
2023-01-26 07:05:07 +00:00
|
|
|
|
2022-12-03 19:44:54 +00:00
|
|
|
Font.BindValueChanged(e =>
|
|
|
|
{
|
2023-01-26 07:05:07 +00: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-03 19:44:54 +00:00
|
|
|
SetFont(f);
|
|
|
|
}, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|